DPDK patches and discussions
 help / color / mirror / Atom feed
From: Michael Baum <michaelba@nvidia.com>
To: <dev@dpdk.org>
Cc: Matan Azrad <matan@nvidia.com>,
	Raslan Darawsheh <rasland@nvidia.com>,
	Viacheslav Ovsiienko <viacheslavo@nvidia.com>
Subject: [dpdk-dev] [RFC 15/21] mlx5: share context device structure between drivers
Date: Tue, 17 Aug 2021 16:44:35 +0300	[thread overview]
Message-ID: <20210817134441.1966618-16-michaelba@nvidia.com> (raw)
In-Reply-To: <20210817134441.1966618-1-michaelba@nvidia.com>

Create and initialize context device structure ones in common probing,
and give a pointer to it for each driver.

Signed-off-by: Michael Baum <michaelba@nvidia.com>
---
 drivers/common/mlx5/mlx5_common.c     | 40 +++++++++++++++++++++------
 drivers/common/mlx5/mlx5_common.h     | 30 +-------------------
 drivers/common/mlx5/version.map       |  2 --
 drivers/compress/mlx5/mlx5_compress.c | 31 ++-------------------
 drivers/crypto/mlx5/mlx5_crypto.c     | 34 ++---------------------
 drivers/net/mlx5/linux/mlx5_os.c      | 36 ++++++++----------------
 drivers/net/mlx5/mlx5.c               | 32 ---------------------
 drivers/net/mlx5/windows/mlx5_os.c    | 22 ++-------------
 drivers/regex/mlx5/mlx5_regex.c       | 35 ++++-------------------
 drivers/vdpa/mlx5/mlx5_vdpa.c         | 35 ++++-------------------
 10 files changed, 64 insertions(+), 233 deletions(-)

diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c
index 0870ee0718..b500e7834e 100644
--- a/drivers/common/mlx5/mlx5_common.c
+++ b/drivers/common/mlx5/mlx5_common.c
@@ -319,7 +319,7 @@ mlx5_dev_to_pci_str(const struct rte_device *dev, char *addr, size_t size)
  * @return
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
-void
+static void
 mlx5_dev_ctx_release(struct mlx5_dev_ctx *dev_ctx)
 {
 	if (dev_ctx->pd != NULL) {
@@ -345,7 +345,7 @@ mlx5_dev_ctx_release(struct mlx5_dev_ctx *dev_ctx)
  * @return
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
-int
+static int
 mlx5_dev_ctx_prepare(struct mlx5_dev_ctx *dev_ctx, struct rte_device *dev,
 		     uint32_t classes_loaded)
 {
@@ -386,12 +386,36 @@ mlx5_dev_ctx_prepare(struct mlx5_dev_ctx *dev_ctx, struct rte_device *dev,
 }
 
 static void
-dev_release(struct mlx5_common_device *dev)
+mlx5_common_dev_release(struct mlx5_common_device *dev)
 {
 	TAILQ_REMOVE(&devices_list, dev, next);
+	mlx5_dev_ctx_release(&dev->ctx);
 	rte_free(dev);
 }
 
+static struct mlx5_common_device *
+mlx5_common_dev_create(struct rte_device *eal_dev, uint32_t classes)
+{
+	struct mlx5_common_device *dev;
+	int ret;
+
+	dev = rte_zmalloc("mlx5_common_device", sizeof(*dev), 0);
+	if (!dev) {
+		DRV_LOG(ERR, "Device allocation failure.");
+		rte_errno = ENOMEM;
+		return NULL;
+	}
+	ret = mlx5_dev_ctx_prepare(&dev->ctx, eal_dev, classes);
+	if (ret) {
+		DRV_LOG(ERR, "Failed to create device context.");
+		rte_free(dev);
+		return NULL;
+	}
+	dev->dev = eal_dev;
+	TAILQ_INSERT_HEAD(&devices_list, dev, next);
+	return dev;
+}
+
 static int
 drivers_remove(struct mlx5_common_device *dev, uint32_t enabled_classes)
 {
@@ -477,11 +501,9 @@ mlx5_common_dev_probe(struct rte_device *eal_dev)
 		classes = MLX5_CLASS_ETH;
 	dev = to_mlx5_device(eal_dev);
 	if (!dev) {
-		dev = rte_zmalloc("mlx5_common_device", sizeof(*dev), 0);
+		dev = mlx5_common_dev_create(eal_dev, classes);
 		if (!dev)
-			return -ENOMEM;
-		dev->dev = eal_dev;
-		TAILQ_INSERT_HEAD(&devices_list, dev, next);
+			return -rte_errno;
 		new_device = true;
 	} else {
 		/* Validate combination here. */
@@ -498,7 +520,7 @@ mlx5_common_dev_probe(struct rte_device *eal_dev)
 	return 0;
 class_err:
 	if (new_device)
-		dev_release(dev);
+		mlx5_common_dev_release(dev);
 	return ret;
 }
 
@@ -514,7 +536,7 @@ mlx5_common_dev_remove(struct rte_device *eal_dev)
 	/* Matching device found, cleanup and unload drivers. */
 	ret = drivers_remove(dev, dev->classes_loaded);
 	if (ret != 0)
-		dev_release(dev);
+		mlx5_common_dev_release(dev);
 	return ret;
 }
 
diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h
index c5f2a6285f..644dc58bc9 100644
--- a/drivers/common/mlx5/mlx5_common.h
+++ b/drivers/common/mlx5/mlx5_common.h
@@ -339,37 +339,9 @@ struct mlx5_common_device {
 	struct rte_device *dev;
 	TAILQ_ENTRY(mlx5_common_device) next;
 	uint32_t classes_loaded;
+	struct mlx5_dev_ctx ctx;
 };
 
-/**
- * Uninitialize context device and release all its resources.
- *
- * @param dev_ctx
- *   Pointer to the context device data structure.
- *
- * @return
- *   0 on success, a negative errno value otherwise and rte_errno is set.
- */
-__rte_internal
-void mlx5_dev_ctx_release(struct mlx5_dev_ctx *dev_ctx);
-
-/**
- * Initialize context device and allocate all its resources.
- *
- * @param dev_ctx
- *   Pointer to the context device data structure.
- * @param dev
- *   Pointer to mlx5 device structure.
- * @param classes_loaded
- *   Chosen classes come from device arguments.
- *
- * @return
- *   0 on success, a negative errno value otherwise and rte_errno is set.
- */
-__rte_internal
-int mlx5_dev_ctx_prepare(struct mlx5_dev_ctx *dev_ctx, struct rte_device *dev,
-			 uint32_t classes_loaded);
-
 /**
  * Initialization function for the driver called during device probing.
  */
diff --git a/drivers/common/mlx5/version.map b/drivers/common/mlx5/version.map
index a1a8bae5bd..4b24833ecb 100644
--- a/drivers/common/mlx5/version.map
+++ b/drivers/common/mlx5/version.map
@@ -10,8 +10,6 @@ INTERNAL {
 	mlx5_common_init;
 
 	mlx5_parse_db_map_arg; # WINDOWS_NO_EXPORT
-	mlx5_dev_ctx_release;
-	mlx5_dev_ctx_prepare;
 
 	mlx5_common_verbs_reg_mr; # WINDOWS_NO_EXPORT
 	mlx5_common_verbs_dereg_mr; # WINDOWS_NO_EXPORT
diff --git a/drivers/compress/mlx5/mlx5_compress.c b/drivers/compress/mlx5/mlx5_compress.c
index 8348ea8ea3..93b0cc8ea6 100644
--- a/drivers/compress/mlx5/mlx5_compress.c
+++ b/drivers/compress/mlx5/mlx5_compress.c
@@ -751,43 +751,25 @@ static int
 mlx5_compress_dev_probe(struct mlx5_common_device *dev)
 {
 	struct rte_compressdev *cdev;
-	struct mlx5_dev_ctx *dev_ctx;
+	struct mlx5_dev_ctx *dev_ctx = &dev->ctx;
 	struct mlx5_compress_priv *priv;
 	struct mlx5_hca_attr att = { 0 };
 	struct rte_compressdev_pmd_init_params init_params = {
 		.name = "",
 		.socket_id = dev->dev->numa_node,
 	};
-	const char *ibdev_name;
-	int ret;
+	const char *ibdev_name = mlx5_os_get_ctx_device_name(dev_ctx->ctx);
 
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
 		DRV_LOG(ERR, "Non-primary process type is not supported.");
 		rte_errno = ENOTSUP;
 		return -rte_errno;
 	}
-	dev_ctx = mlx5_malloc(MLX5_MEM_ZERO, sizeof(struct mlx5_dev_ctx),
-			      RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
-	if (dev_ctx == NULL) {
-		DRV_LOG(ERR, "Device context allocation failure.");
-		rte_errno = ENOMEM;
-		return -rte_errno;
-	}
-	ret = mlx5_dev_ctx_prepare(dev_ctx, dev->dev, MLX5_CLASS_COMPRESS);
-	if (ret < 0) {
-		DRV_LOG(ERR, "Failed to create device context.");
-		mlx5_free(dev_ctx);
-		rte_errno = ENODEV;
-		return -rte_errno;
-	}
-	ibdev_name = mlx5_os_get_ctx_device_name(dev_ctx->ctx);
 	if (mlx5_devx_cmd_query_hca_attr(dev_ctx->ctx, &att) != 0 ||
 	    att.mmo_compress_en == 0 || att.mmo_decompress_en == 0 ||
 	    att.mmo_dma_en == 0) {
 		DRV_LOG(ERR, "Not enough capabilities to support compress "
 			"operations, maybe old FW/OFED version?");
-		mlx5_dev_ctx_release(dev_ctx);
-		mlx5_free(dev_ctx);
 		rte_errno = ENOTSUP;
 		return -ENOTSUP;
 	}
@@ -795,8 +777,6 @@ mlx5_compress_dev_probe(struct mlx5_common_device *dev)
 					  sizeof(*priv), &init_params);
 	if (cdev == NULL) {
 		DRV_LOG(ERR, "Failed to create device \"%s\".", ibdev_name);
-		mlx5_dev_ctx_release(dev_ctx);
-		mlx5_free(dev_ctx);
 		return -ENODEV;
 	}
 	DRV_LOG(INFO,
@@ -812,8 +792,6 @@ mlx5_compress_dev_probe(struct mlx5_common_device *dev)
 	priv->sq_ts_format = att.sq_ts_format;
 	if (mlx5_compress_hw_global_prepare(priv) != 0) {
 		rte_compressdev_pmd_destroy(priv->cdev);
-		mlx5_dev_ctx_release(priv->dev_ctx);
-		mlx5_free(priv->dev_ctx);
 		return -1;
 	}
 	if (mlx5_mr_btree_init(&priv->mr_scache.cache,
@@ -821,8 +799,6 @@ mlx5_compress_dev_probe(struct mlx5_common_device *dev)
 		DRV_LOG(ERR, "Failed to allocate shared cache MR memory.");
 		mlx5_compress_hw_global_release(priv);
 		rte_compressdev_pmd_destroy(priv->cdev);
-		mlx5_dev_ctx_release(priv->dev_ctx);
-		mlx5_free(priv->dev_ctx);
 		rte_errno = ENOMEM;
 		return -rte_errno;
 	}
@@ -858,8 +834,7 @@ mlx5_compress_dev_remove(struct mlx5_common_device *dev)
 		mlx5_mr_release_cache(&priv->mr_scache);
 		mlx5_compress_hw_global_release(priv);
 		rte_compressdev_pmd_destroy(priv->cdev);
-		mlx5_dev_ctx_release(priv->dev_ctx);
-		mlx5_free(priv->dev_ctx);
+		priv->dev_ctx = NULL;
 	}
 	return 0;
 }
diff --git a/drivers/crypto/mlx5/mlx5_crypto.c b/drivers/crypto/mlx5/mlx5_crypto.c
index 44656225d2..4f390c8bf4 100644
--- a/drivers/crypto/mlx5/mlx5_crypto.c
+++ b/drivers/crypto/mlx5/mlx5_crypto.c
@@ -945,7 +945,7 @@ static int
 mlx5_crypto_dev_probe(struct mlx5_common_device *dev)
 {
 	struct rte_cryptodev *crypto_dev;
-	struct mlx5_dev_ctx *dev_ctx;
+	struct mlx5_dev_ctx *dev_ctx = &dev->ctx;
 	struct mlx5_devx_obj *login;
 	struct mlx5_crypto_priv *priv;
 	struct mlx5_crypto_devarg_params devarg_prms = { 0 };
@@ -957,7 +957,7 @@ mlx5_crypto_dev_probe(struct mlx5_common_device *dev)
 		.max_nb_queue_pairs =
 				RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS,
 	};
-	const char *ibdev_name;
+	const char *ibdev_name = mlx5_os_get_ctx_device_name(dev_ctx->ctx);
 	uint16_t rdmw_wqe_size;
 	int ret;
 
@@ -966,51 +966,28 @@ mlx5_crypto_dev_probe(struct mlx5_common_device *dev)
 		rte_errno = ENOTSUP;
 		return -rte_errno;
 	}
-	dev_ctx = mlx5_malloc(MLX5_MEM_ZERO, sizeof(struct mlx5_dev_ctx),
-			      RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
-	if (dev_ctx == NULL) {
-		DRV_LOG(ERR, "Device context allocation failure.");
-		rte_errno = ENOMEM;
-		return -rte_errno;
-	}
-	ret = mlx5_dev_ctx_prepare(dev_ctx, dev->dev, MLX5_CLASS_CRYPTO);
-	if (ret < 0) {
-		DRV_LOG(ERR, "Failed to create device context.");
-		mlx5_free(dev_ctx);
-		rte_errno = ENODEV;
-		return -rte_errno;
-	}
-	ibdev_name = mlx5_os_get_ctx_device_name(dev_ctx->ctx);
 	if (mlx5_devx_cmd_query_hca_attr(dev_ctx->ctx, &attr) != 0 ||
 	    attr.crypto == 0 || attr.aes_xts == 0) {
 		DRV_LOG(ERR, "Not enough capabilities to support crypto "
 			"operations, maybe old FW/OFED version?");
-		mlx5_dev_ctx_release(dev_ctx);
-		mlx5_free(dev_ctx);
 		rte_errno = ENOTSUP;
 		return -ENOTSUP;
 	}
 	ret = mlx5_crypto_parse_devargs(dev->dev->devargs, &devarg_prms);
 	if (ret) {
 		DRV_LOG(ERR, "Failed to parse devargs.");
-		mlx5_dev_ctx_release(dev_ctx);
-		mlx5_free(dev_ctx);
 		return -rte_errno;
 	}
 	login = mlx5_devx_cmd_create_crypto_login_obj(dev_ctx->ctx,
 						      &devarg_prms.login_attr);
 	if (login == NULL) {
 		DRV_LOG(ERR, "Failed to configure login.");
-		mlx5_dev_ctx_release(dev_ctx);
-		mlx5_free(dev_ctx);
 		return -rte_errno;
 	}
 	crypto_dev = rte_cryptodev_pmd_create(ibdev_name, dev->dev,
 					      &init_params);
 	if (crypto_dev == NULL) {
 		DRV_LOG(ERR, "Failed to create device \"%s\".", ibdev_name);
-		mlx5_dev_ctx_release(dev_ctx);
-		mlx5_free(dev_ctx);
 		return -ENODEV;
 	}
 	DRV_LOG(INFO, "Crypto device %s was created successfully.", ibdev_name);
@@ -1025,8 +1002,6 @@ mlx5_crypto_dev_probe(struct mlx5_common_device *dev)
 	priv->crypto_dev = crypto_dev;
 	if (mlx5_crypto_hw_global_prepare(priv) != 0) {
 		rte_cryptodev_pmd_destroy(priv->crypto_dev);
-		mlx5_dev_ctx_release(priv->dev_ctx);
-		mlx5_free(priv->dev_ctx);
 		return -1;
 	}
 	if (mlx5_mr_btree_init(&priv->mr_scache.cache,
@@ -1034,8 +1009,6 @@ mlx5_crypto_dev_probe(struct mlx5_common_device *dev)
 		DRV_LOG(ERR, "Failed to allocate shared cache MR memory.");
 		mlx5_crypto_hw_global_release(priv);
 		rte_cryptodev_pmd_destroy(priv->crypto_dev);
-		mlx5_dev_ctx_release(priv->dev_ctx);
-		mlx5_free(priv->dev_ctx);
 		rte_errno = ENOMEM;
 		return -rte_errno;
 	}
@@ -1085,8 +1058,7 @@ mlx5_crypto_dev_remove(struct mlx5_common_device *dev)
 		mlx5_crypto_hw_global_release(priv);
 		rte_cryptodev_pmd_destroy(priv->crypto_dev);
 		claim_zero(mlx5_devx_cmd_destroy(priv->login_obj));
-		mlx5_dev_ctx_release(priv->dev_ctx);
-		mlx5_free(priv->dev_ctx);
+		priv->dev_ctx = NULL;
 	}
 	return 0;
 }
diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index 812aadaaa4..c8134f064f 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -2882,31 +2882,24 @@ mlx5_verbs_dev_ctx_prepare(struct mlx5_dev_ctx *dev_ctx, struct rte_device *dev)
 int
 mlx5_os_net_probe(struct mlx5_common_device *dev)
 {
-	struct mlx5_dev_ctx *dev_ctx;
+	struct mlx5_dev_ctx *dev_ctx = &dev->ctx;
 	uint8_t devx = 0;
 	int ret;
 
-	dev_ctx = mlx5_malloc(MLX5_MEM_ZERO, sizeof(struct mlx5_dev_ctx),
-			      RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
-	if (dev_ctx == NULL) {
-		DRV_LOG(ERR, "Device context allocation failure.");
-		rte_errno = ENOMEM;
-		return -rte_errno;
-	}
 	/*
-	 * Initialize context device and allocate all its resources.
-	 * Try to do it with DV first, then usual Verbs.
+	 * Context device and all its resources are created and initialized
+	 * while common probing, using DevX API. When DevX isn't supported,
+	 * we are trying to create them by Verbs only for net driver.
+	 * Here, we check if the ctx creates successfully, and if not try to
+	 * create it by Verbs.
 	 */
-	ret = mlx5_dev_ctx_prepare(dev_ctx, dev->dev, MLX5_CLASS_ETH);
-	if (ret < 0) {
-		goto error;
-	} else if (dev_ctx->ctx) {
+	if (dev_ctx->ctx) {
 		devx = 1;
 		DRV_LOG(DEBUG, "DevX is supported.");
 	} else {
 		ret = mlx5_verbs_dev_ctx_prepare(dev_ctx, dev->dev);
 		if (ret < 0)
-			goto error;
+			return -rte_errno;
 		DRV_LOG(DEBUG, "DevX is NOT supported.");
 	}
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
@@ -2915,19 +2908,12 @@ mlx5_os_net_probe(struct mlx5_common_device *dev)
 	if (ret) {
 		DRV_LOG(ERR, "unable to init PMD global data: %s",
 			strerror(rte_errno));
-		goto error;
+		return -rte_errno;
 	}
 	if (mlx5_dev_is_pci(dev->dev))
-		ret = mlx5_os_pci_probe(dev, dev_ctx, devx);
+		return mlx5_os_pci_probe(dev, dev_ctx, devx);
 	else
-		ret = mlx5_os_auxiliary_probe(dev->dev, dev_ctx, devx);
-	if (ret)
-		goto error;
-	return ret;
-error:
-	mlx5_dev_ctx_release(dev_ctx);
-	mlx5_free(dev_ctx);
-	return ret;
+		return mlx5_os_auxiliary_probe(dev->dev, dev_ctx, devx);
 }
 
 /**
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index e0b180e83c..085bf87abc 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -2355,33 +2355,6 @@ mlx5_eth_find_next(uint16_t port_id, struct rte_device *odev)
 	return port_id;
 }
 
-/**
- * Finds the device context that match the device.
- * The existence of multiple ethdev per pci device is only with representors.
- * On such case, it is enough to get only one of the ports as they all share
- * the same device context.
- *
- * @param dev
- *   Pointer to the device.
- *
- * @return
- *   Pointer to the device context if found, NULL otherwise.
- */
-static struct mlx5_dev_ctx *
-mlx5_get_dev_ctx(struct rte_device *dev)
-{
-	struct mlx5_priv *priv;
-	uint16_t port_id;
-
-	port_id = rte_eth_find_next_of(0, dev);
-	if (port_id == RTE_MAX_ETHPORTS)
-		return NULL;
-	priv = rte_eth_devices[port_id].data->dev_private;
-	if (priv == NULL)
-		return NULL;
-	return priv->sh->dev_ctx;
-}
-
 /**
  * Callback to remove a device.
  *
@@ -2396,7 +2369,6 @@ mlx5_get_dev_ctx(struct rte_device *dev)
 int
 mlx5_net_remove(struct mlx5_common_device *dev)
 {
-	struct mlx5_dev_ctx *dev_ctx = mlx5_get_dev_ctx(dev->dev);
 	uint16_t port_id;
 	int ret = 0;
 
@@ -2411,10 +2383,6 @@ mlx5_net_remove(struct mlx5_common_device *dev)
 			ret |= rte_eth_dev_close(port_id);
 	}
 
-	if (dev_ctx) {
-		mlx5_dev_ctx_release(dev_ctx);
-		mlx5_free(dev_ctx);
-	}
 	return ret == 0 ? 0 : -EIO;
 }
 
diff --git a/drivers/net/mlx5/windows/mlx5_os.c b/drivers/net/mlx5/windows/mlx5_os.c
index f21fb60272..d269cf2f74 100644
--- a/drivers/net/mlx5/windows/mlx5_os.c
+++ b/drivers/net/mlx5/windows/mlx5_os.c
@@ -878,7 +878,7 @@ int
 mlx5_os_net_probe(struct mlx5_common_device *dev)
 {
 	struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->dev);
-	struct mlx5_dev_ctx *dev_ctx;
+	struct mlx5_dev_ctx *dev_ctx = &dev->ctx;
 	struct mlx5_dev_spawn_data spawn = { .pf_bond = -1 };
 	struct mlx5_dev_config dev_config;
 	unsigned int dev_config_vf;
@@ -895,16 +895,6 @@ mlx5_os_net_probe(struct mlx5_common_device *dev)
 			strerror(rte_errno));
 		return -rte_errno;
 	}
-	dev_ctx = mlx5_malloc(MLX5_MEM_ZERO, sizeof(struct mlx5_dev_ctx),
-			      RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
-	if (dev_ctx == NULL) {
-		DRV_LOG(ERR, "Device context allocation failure.");
-		rte_errno = ENOMEM;
-		return -rte_errno;
-	}
-	ret = mlx5_dev_ctx_prepare(dev_ctx, dev->dev, MLX5_CLASS_ETH);
-	if (ret < 0)
-		goto error;
 	memset(&spawn.info, 0, sizeof(spawn.info));
 	spawn.max_port = 1;
 	spawn.phys_port = 1;
@@ -955,20 +945,14 @@ mlx5_os_net_probe(struct mlx5_common_device *dev)
 	dev_config.decap_en = 0;
 	dev_config.log_hp_size = MLX5_ARG_UNSET;
 	spawn.eth_dev = mlx5_dev_spawn(dev->dev, dev_ctx, &spawn, &dev_config);
-	if (!spawn.eth_dev) {
-		ret = -rte_errno;
-		goto error;
-	}
+	if (!spawn.eth_dev)
+		return -rte_errno;
 	restore = spawn.eth_dev->data->dev_flags;
 	rte_eth_copy_pci_info(spawn.eth_dev, pci_dev);
 	/* Restore non-PCI flags cleared by the above call. */
 	spawn.eth_dev->data->dev_flags |= restore;
 	rte_eth_dev_probing_finish(spawn.eth_dev);
 	return 0;
-error:
-	mlx5_dev_ctx_release(dev_ctx);
-	mlx5_free(dev_ctx);
-	return ret;
 }
 
 /**
diff --git a/drivers/regex/mlx5/mlx5_regex.c b/drivers/regex/mlx5/mlx5_regex.c
index 78fa90797c..3772007d24 100644
--- a/drivers/regex/mlx5/mlx5_regex.c
+++ b/drivers/regex/mlx5/mlx5_regex.c
@@ -125,51 +125,36 @@ static int
 mlx5_regex_dev_probe(struct mlx5_common_device *mlx5_dev)
 {
 	struct mlx5_regex_priv *priv = NULL;
-	struct mlx5_dev_ctx *dev_ctx = NULL;
+	struct mlx5_dev_ctx *dev_ctx = &mlx5_dev->ctx;
 	struct mlx5_hca_attr attr;
 	char name[RTE_REGEXDEV_NAME_MAX_LEN];
-	const char *ibdev_name;
+	const char *ibdev_name = mlx5_os_get_ctx_device_name(dev_ctx->ctx);
 	int ret;
 	uint32_t val;
 
-	dev_ctx = rte_zmalloc("mlx5 context device", sizeof(*dev_ctx),
-			      RTE_CACHE_LINE_SIZE);
-	if (dev_ctx == NULL) {
-		DRV_LOG(ERR, "Device context allocation failure.");
-		rte_errno = ENOMEM;
-		return -rte_errno;
-	}
-	ret = mlx5_dev_ctx_prepare(dev_ctx, mlx5_dev->dev, MLX5_CLASS_REGEX);
-	if (ret < 0) {
-		DRV_LOG(ERR, "Failed to create device context.");
-		rte_free(dev_ctx);
-		rte_errno = ENODEV;
-		return -rte_errno;
-	}
-	ibdev_name = mlx5_os_get_ctx_device_name(dev_ctx->ctx);
 	DRV_LOG(INFO, "Probe device \"%s\".", ibdev_name);
 	ret = mlx5_devx_cmd_query_hca_attr(dev_ctx->ctx, &attr);
 	if (ret) {
 		DRV_LOG(ERR, "Unable to read HCA capabilities.");
 		rte_errno = ENOTSUP;
-		goto dev_error;
+		return -rte_errno;
 	} else if (!attr.regex || attr.regexp_num_of_engines == 0) {
 		DRV_LOG(ERR, "Not enough capabilities to support RegEx, maybe "
 			"old FW/OFED version?");
 		rte_errno = ENOTSUP;
-		goto dev_error;
+		return -rte_errno;
 	}
 	if (mlx5_regex_engines_status(dev_ctx->ctx, 2)) {
 		DRV_LOG(ERR, "RegEx engine error.");
 		rte_errno = ENOMEM;
-		goto dev_error;
+		return -rte_errno;
 	}
 	priv = rte_zmalloc("mlx5 regex device private", sizeof(*priv),
 			   RTE_CACHE_LINE_SIZE);
 	if (!priv) {
 		DRV_LOG(ERR, "Failed to allocate private memory.");
 		rte_errno = ENOMEM;
-		goto dev_error;
+		return -rte_errno;
 	}
 	priv->sq_ts_format = attr.sq_ts_format;
 	priv->dev_ctx = dev_ctx;
@@ -244,10 +229,6 @@ mlx5_regex_dev_probe(struct mlx5_common_device *mlx5_dev)
 	if (priv->regexdev)
 		rte_regexdev_unregister(priv->regexdev);
 dev_error:
-	if (dev_ctx) {
-		mlx5_dev_ctx_release(dev_ctx);
-		rte_free(dev_ctx);
-	}
 	if (priv)
 		rte_free(priv);
 	return -rte_errno;
@@ -279,10 +260,6 @@ mlx5_regex_dev_remove(struct mlx5_common_device *mlx5_dev)
 			mlx5_glue->devx_free_uar(priv->uar);
 		if (priv->regexdev)
 			rte_regexdev_unregister(priv->regexdev);
-		if (priv->dev_ctx) {
-			mlx5_dev_ctx_release(priv->dev_ctx);
-			rte_free(priv->dev_ctx);
-		}
 		rte_free(priv);
 	}
 	return 0;
diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c
index 6771445582..2b1b521313 100644
--- a/drivers/vdpa/mlx5/mlx5_vdpa.c
+++ b/drivers/vdpa/mlx5/mlx5_vdpa.c
@@ -506,34 +506,19 @@ static int
 mlx5_vdpa_dev_probe(struct mlx5_common_device *dev)
 {
 	struct mlx5_vdpa_priv *priv = NULL;
-	struct mlx5_dev_ctx *dev_ctx = NULL;
 	struct mlx5_hca_attr attr;
 	int ret;
 
-	dev_ctx = mlx5_malloc(MLX5_MEM_ZERO, sizeof(struct mlx5_dev_ctx),
-			      RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
-	if (dev_ctx == NULL) {
-		DRV_LOG(ERR, "Device context allocation failure.");
-		rte_errno = ENOMEM;
-		return -rte_errno;
-	}
-	ret = mlx5_dev_ctx_prepare(dev_ctx, dev->dev, MLX5_CLASS_VDPA);
-	if (ret < 0) {
-		DRV_LOG(ERR, "Failed to create device context.");
-		mlx5_free(dev_ctx);
-		rte_errno = ENODEV;
-		return -rte_errno;
-	}
-	ret = mlx5_devx_cmd_query_hca_attr(dev_ctx->ctx, &attr);
+	ret = mlx5_devx_cmd_query_hca_attr(dev->ctx.ctx, &attr);
 	if (ret) {
 		DRV_LOG(ERR, "Unable to read HCA capabilities.");
 		rte_errno = ENOTSUP;
-		goto error;
+		return -rte_errno;
 	} else if (!attr.vdpa.valid || !attr.vdpa.max_num_virtio_queues) {
 		DRV_LOG(ERR, "Not enough capabilities to support vdpa, maybe "
 			"old FW/OFED version?");
 		rte_errno = ENOTSUP;
-		goto error;
+		return -rte_errno;
 	}
 	if (!attr.vdpa.queue_counters_valid)
 		DRV_LOG(DEBUG, "No capability to support virtq statistics.");
@@ -544,7 +529,7 @@ mlx5_vdpa_dev_probe(struct mlx5_common_device *dev)
 	if (!priv) {
 		DRV_LOG(ERR, "Failed to allocate private memory.");
 		rte_errno = ENOMEM;
-		goto error;
+		return -rte_errno;
 	}
 	priv->caps = attr.vdpa;
 	priv->log_max_rqt_size = attr.log_max_rqt_size;
@@ -552,8 +537,8 @@ mlx5_vdpa_dev_probe(struct mlx5_common_device *dev)
 	priv->qp_ts_format = attr.qp_ts_format;
 	if (attr.num_lag_ports == 0)
 		priv->num_lag_ports = 1;
-	priv->dev_ctx = dev_ctx;
-	priv->var = mlx5_glue->dv_alloc_var(dev_ctx->ctx, 0);
+	priv->dev_ctx = &dev->ctx;
+	priv->var = mlx5_glue->dv_alloc_var(priv->dev_ctx->ctx, 0);
 	if (!priv->var) {
 		DRV_LOG(ERR, "Failed to allocate VAR %u.", errno);
 		goto error;
@@ -578,10 +563,6 @@ mlx5_vdpa_dev_probe(struct mlx5_common_device *dev)
 			mlx5_glue->dv_free_var(priv->var);
 		rte_free(priv);
 	}
-	if (dev_ctx) {
-		mlx5_dev_ctx_release(dev_ctx);
-		mlx5_free(dev_ctx);
-	}
 	return -rte_errno;
 }
 
@@ -610,10 +591,6 @@ mlx5_vdpa_dev_remove(struct mlx5_common_device *dev)
 		}
 		if (priv->vdev)
 			rte_vdpa_unregister_device(priv->vdev);
-		if (priv->dev_ctx) {
-			mlx5_dev_ctx_release(priv->dev_ctx);
-			mlx5_free(priv->dev_ctx);
-		}
 		pthread_mutex_destroy(&priv->vq_config_lock);
 		rte_free(priv);
 	}
-- 
2.25.1


  parent reply	other threads:[~2021-08-17 13:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17 13:44 [dpdk-dev] [RFC 00/21] mlx5: sharing global MR cache " Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 01/21] net/mlx5: fix shared device context creation error flow Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 02/21] net/mlx5: fix PCI probing " Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 03/21] common/mlx5: add context device structure Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 04/21] compress/mlx5: use " Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 05/21] crypto/mlx5: " Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 06/21] regex/mlx5: " Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 07/21] net/mlx5: improve probe function on Windows Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 08/21] net/mlx5: improve probe function on Linux Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 09/21] net/mlx5: improve spawn function Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 10/21] net/mlx5: use context device structure Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 11/21] net/mlx5: move NUMA node field to context device Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 12/21] common/mlx5: add ROCE disable in context device creation Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 13/21] vdpa/mlx5: use context device structure Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 14/21] mlx5: update device sent to probing Michael Baum
2021-08-17 13:44 ` Michael Baum [this message]
2021-08-17 13:44 ` [dpdk-dev] [RFC 16/21] common/mlx5: add HCA attributes to context device structure Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 17/21] regex/mlx5: use HCA attributes from context device Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 18/21] vdpa/mlx5: " Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 19/21] compress/mlx5: " Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 20/21] crypto/mlx5: " Michael Baum
2021-08-17 13:44 ` [dpdk-dev] [RFC 21/21] net/mlx5: " Michael Baum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210817134441.1966618-16-michaelba@nvidia.com \
    --to=michaelba@nvidia.com \
    --cc=dev@dpdk.org \
    --cc=matan@nvidia.com \
    --cc=rasland@nvidia.com \
    --cc=viacheslavo@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).