[dpdk-dev] [PATCH 1/4] net/mlx5: add DV/DR flow data alloc/free routines

Viacheslav Ovsiienko viacheslavo at mellanox.com
Tue Apr 2 08:22:34 CEST 2019


We are going to share the DR/DV flow device data structures
between master and representors in the E-Switch configurations
over multiport IB device.

The code of initializing and destroying these data is
moved to dedicated routines, this is just a preparation
step for actual data sharing.

Signed-off-by: Viacheslav Ovsiienko <viacheslavo at mellanox.com>
---
 drivers/net/mlx5/mlx5.c | 90 ++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 77 insertions(+), 13 deletions(-)

diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index b59fc58..9de122d 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -296,6 +296,73 @@ struct mlx5_dev_spawn_data {
 	pthread_mutex_unlock(&mlx5_ibv_list_mutex);
 }
 
+#ifdef HAVE_MLX5DV_DR
+/**
+ * Initialize DV/DR related data within private structure.
+ * This is preparation step for the data sharing.
+ *
+ * @param[in] priv
+ *   Pointer to the private device data structure.
+ *
+ * @return
+ *   Zero on success, positive error code otherwise.
+ */
+static int
+mlx5_alloc_shared_dv(struct mlx5_priv *priv)
+{
+	struct mlx5_ibv_shared *sh = priv->sh;
+	int err = 0;
+	void *ns;
+
+	ns = mlx5dv_dr_create_ns(sh->ctx, MLX5DV_DR_NS_DOMAIN_INGRESS_BYPASS);
+	if (!ns) {
+		DRV_LOG(ERR, "ingress mlx5dv_dr_create_ns failed");
+		err = errno;
+		goto error;
+	}
+	priv->rx_ns = ns;
+	ns = mlx5dv_dr_create_ns(sh->ctx, MLX5DV_DR_NS_DOMAIN_EGRESS_BYPASS);
+	if (!ns) {
+		DRV_LOG(ERR, "egress mlx5dv_dr_create_ns failed");
+		err = errno;
+		goto error;
+	}
+	priv->tx_ns = ns;
+	return 0;
+
+error:
+       /* Rollback the created objects. */
+	if (priv->rx_ns) {
+		mlx5dv_dr_destroy_ns(priv->rx_ns);
+		priv->rx_ns = NULL;
+	}
+	if (priv->tx_ns) {
+		mlx5dv_dr_destroy_ns(priv->tx_ns);
+		priv->tx_ns = NULL;
+	}
+	return err;
+}
+
+/**
+ * Destroy DV/DR related structures within private structure.
+ *
+ * @param[in] priv
+ *   Pointer to the private device data structure.
+ */
+static void
+mlx5_free_shared_dv(struct mlx5_priv *priv)
+{
+	if (priv->rx_ns) {
+		mlx5dv_dr_destroy_ns(priv->rx_ns);
+		priv->rx_ns = NULL;
+	}
+	if (priv->tx_ns) {
+		mlx5dv_dr_destroy_ns(priv->tx_ns);
+		priv->tx_ns = NULL;
+	}
+}
+#endif
+
 /**
  * Prepare shared data between primary and secondary process.
  */
@@ -446,6 +513,9 @@ struct mlx5_dev_spawn_data {
 	mlx5_mprq_free_mp(dev);
 	mlx5_mr_release(dev);
 	assert(priv->sh);
+#ifdef HAVE_MLX5DV_DR
+	mlx5_free_shared_dv(priv);
+#endif
 	if (priv->sh)
 		mlx5_free_shared_ibctx(priv->sh);
 	priv->sh = NULL;
@@ -1363,20 +1433,11 @@ struct mlx5_dev_spawn_data {
 		}
 	}
 #ifdef HAVE_MLX5DV_DR
-		priv->rx_ns = mlx5dv_dr_create_ns
-			(sh->ctx, MLX5DV_DR_NS_DOMAIN_INGRESS_BYPASS);
-		if (priv->rx_ns == NULL) {
-			DRV_LOG(ERR, "mlx5dv_dr_create_ns failed");
-			err = errno;
-			goto error;
-		}
-		priv->tx_ns = mlx5dv_dr_create_ns(sh->ctx,
-					 MLX5DV_DR_NS_DOMAIN_EGRESS_BYPASS);
-		if (priv->tx_ns == NULL) {
-			DRV_LOG(ERR, "mlx5dv_dr_create_ns failed");
-			err = errno;
+	if (config.dv_flow_en) {
+		err = mlx5_alloc_shared_dv(priv);
+		if (err)
 			goto error;
-		}
+	}
 #endif
 	TAILQ_INIT(&priv->flows);
 	TAILQ_INIT(&priv->ctrl_flows);
@@ -1429,6 +1490,9 @@ struct mlx5_dev_spawn_data {
 	return eth_dev;
 error:
 	if (priv) {
+#ifdef HAVE_MLX5DV_DR
+		mlx5_free_shared_dv(priv);
+#endif
 		if (priv->nl_socket_route >= 0)
 			close(priv->nl_socket_route);
 		if (priv->nl_socket_rdma >= 0)
-- 
1.8.3.1



More information about the dev mailing list