diff mbox series

[RFC,07/21] net/mlx5: improve probe function on Windows

Message ID 20210817134441.1966618-8-michaelba@nvidia.com (mailing list archive)
State RFC, archived
Delegated to: Raslan Darawsheh
Headers show
Series mlx5: sharing global MR cache between drivers | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Michael Baum Aug. 17, 2021, 1:44 p.m. UTC
some improvements:
- use aux function to find match device.
- use spawn a local variable instead of pointing to a list with a single
member.

Signed-off-by: Michael Baum <michaelba@nvidia.com>
---
 drivers/common/mlx5/mlx5_common.h            |   2 +
 drivers/common/mlx5/version.map              |   1 +
 drivers/common/mlx5/windows/mlx5_common_os.c |   2 +-
 drivers/net/mlx5/windows/mlx5_os.c           | 196 +++----------------
 4 files changed, 26 insertions(+), 175 deletions(-)
diff mbox series

Patch

diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h
index 609953b70e..10061f364f 100644
--- a/drivers/common/mlx5/mlx5_common.h
+++ b/drivers/common/mlx5/mlx5_common.h
@@ -465,6 +465,8 @@  int mlx5_os_devx_open_device(struct mlx5_dev_ctx *dev_ctx,
 			     struct rte_device *dev, int dbnc,
 			     uint32_t classes);
 int mlx5_os_pd_create(struct mlx5_dev_ctx *dev_ctx);
+__rte_internal
+struct devx_device_bdf *mlx5_os_get_devx_device(struct rte_device *dev);
 
 
 #endif /* RTE_PMD_MLX5_COMMON_H_ */
diff --git a/drivers/common/mlx5/version.map b/drivers/common/mlx5/version.map
index 6a88105d02..18856c198e 100644
--- a/drivers/common/mlx5/version.map
+++ b/drivers/common/mlx5/version.map
@@ -145,6 +145,7 @@  INTERNAL {
 	mlx5_os_dealloc_pd;
 	mlx5_os_dereg_mr;
 	mlx5_os_get_ibv_dev; # WINDOWS_NO_EXPORT
+	mlx5_os_get_devx_device;
 	mlx5_os_reg_mr;
 	mlx5_os_umem_dereg;
 	mlx5_os_umem_reg;
diff --git a/drivers/common/mlx5/windows/mlx5_common_os.c b/drivers/common/mlx5/windows/mlx5_common_os.c
index 5d178b0452..12819383c1 100644
--- a/drivers/common/mlx5/windows/mlx5_common_os.c
+++ b/drivers/common/mlx5/windows/mlx5_common_os.c
@@ -144,7 +144,7 @@  mlx5_match_devx_devices_to_addr(struct devx_device_bdf *devx_bdf,
  * @return
  *   A device match on success, NULL otherwise and rte_errno is set.
  */
-static struct devx_device_bdf *
+struct devx_device_bdf *
 mlx5_os_get_devx_device(struct rte_device *dev)
 {
 	int n;
diff --git a/drivers/net/mlx5/windows/mlx5_os.c b/drivers/net/mlx5/windows/mlx5_os.c
index 7e1df1c751..0ff9e70d96 100644
--- a/drivers/net/mlx5/windows/mlx5_os.c
+++ b/drivers/net/mlx5/windows/mlx5_os.c
@@ -904,68 +904,6 @@  mlx5_os_set_allmulti(struct rte_eth_dev *dev, int enable)
 	return -ENOTSUP;
 }
 
-/**
- * Detect if a devx_device_bdf object has identical DBDF values to the
- * rte_pci_addr found in bus/pci probing
- *
- * @param[in] devx_bdf
- *   Pointer to the devx_device_bdf structure.
- * @param[in] addr
- *   Pointer to the rte_pci_addr structure.
- *
- * @return
- *   1 on Device match, 0 on mismatch.
- */
-static int
-mlx5_match_devx_bdf_to_addr(struct devx_device_bdf *devx_bdf,
-			    struct rte_pci_addr *addr)
-{
-	if (addr->domain != (devx_bdf->bus_id >> 8) ||
-	    addr->bus != (devx_bdf->bus_id & 0xff) ||
-	    addr->devid != devx_bdf->dev_id ||
-	    addr->function != devx_bdf->fnc_id) {
-		return 0;
-	}
-	return 1;
-}
-
-/**
- * Detect if a devx_device_bdf object matches the rte_pci_addr
- * found in bus/pci probing
- * Compare both the Native/PF BDF and the raw_bdf representing a VF BDF.
- *
- * @param[in] devx_bdf
- *   Pointer to the devx_device_bdf structure.
- * @param[in] addr
- *   Pointer to the rte_pci_addr structure.
- *
- * @return
- *   1 on Device match, 0 on mismatch, rte_errno code on failure.
- */
-static int
-mlx5_match_devx_devices_to_addr(struct devx_device_bdf *devx_bdf,
-				struct rte_pci_addr *addr)
-{
-	int err;
-	struct devx_device mlx5_dev;
-
-	if (mlx5_match_devx_bdf_to_addr(devx_bdf, addr))
-		return 1;
-	/**
-	 * Didn't match on Native/PF BDF, could still
-	 * Match a VF BDF, check it next
-	 */
-	err = mlx5_glue->query_device(devx_bdf, &mlx5_dev);
-	if (err) {
-		DRV_LOG(ERR, "query_device failed");
-		rte_errno = err;
-		return rte_errno;
-	}
-	if (mlx5_match_devx_bdf_to_addr(&mlx5_dev.raw_bdf, addr))
-		return 1;
-	return 0;
-}
-
 /**
  * DPDK callback to register a PCI device.
  *
@@ -981,39 +919,15 @@  int
 mlx5_os_net_probe(struct rte_device *dev)
 {
 	struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev);
-	struct devx_device_bdf *devx_bdf_devs, *orig_devx_bdf_devs;
-	/*
-	 * Number of found IB Devices matching with requested PCI BDF.
-	 * nd != 1 means there are multiple IB devices over the same
-	 * PCI device and we have representors and master.
-	 */
-	unsigned int nd = 0;
-	/*
-	 * Number of found IB device Ports. nd = 1 and np = 1..n means
-	 * we have the single multiport IB device, and there may be
-	 * representors attached to some of found ports.
-	 * Currently not supported.
-	 * unsigned int np = 0;
-	 */
-
-	/*
-	 * Number of DPDK ethernet devices to Spawn - either over
-	 * multiple IB devices or multiple ports of single IB device.
-	 * Actually this is the number of iterations to spawn.
-	 */
-	unsigned int ns = 0;
-	/*
-	 * Bonding device
-	 *   < 0 - no bonding device (single one)
-	 *  >= 0 - bonding device (value is slave PF index)
-	 */
-	int bd = -1;
-	struct mlx5_dev_spawn_data *list = NULL;
+	struct mlx5_dev_spawn_data spawn = { .pf_bond = -1 };
+	struct devx_device_bdf *devx_bdf_match = mlx5_os_get_devx_device(dev);
 	struct mlx5_dev_config dev_config;
 	unsigned int dev_config_vf;
-	int ret, err;
+	int ret;
 	uint32_t restore;
 
+	if (devx_bdf_match == NULL)
+		return -rte_errno;
 	if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
 		DRV_LOG(ERR, "Secondary process is not supported on Windows.");
 		return -ENOTSUP;
@@ -1024,67 +938,14 @@  mlx5_os_net_probe(struct rte_device *dev)
 			strerror(rte_errno));
 		return -rte_errno;
 	}
-	errno = 0;
-	devx_bdf_devs = mlx5_glue->get_device_list(&ret);
-	orig_devx_bdf_devs = devx_bdf_devs;
-	if (!devx_bdf_devs) {
-		rte_errno = errno ? errno : ENOSYS;
-		DRV_LOG(ERR, "cannot list devices, is ib_uverbs loaded?");
-		return -rte_errno;
-	}
-	/*
-	 * First scan the list of all Infiniband devices to find
-	 * matching ones, gathering into the list.
-	 */
-	struct devx_device_bdf *devx_bdf_match[ret + 1];
-
-	while (ret-- > 0) {
-		err = mlx5_match_devx_devices_to_addr(devx_bdf_devs,
-		    &pci_dev->addr);
-		if (!err) {
-			devx_bdf_devs++;
-			continue;
-		}
-		if (err != 1) {
-			ret = -err;
-			goto exit;
-		}
-		devx_bdf_match[nd++] = devx_bdf_devs;
-	}
-	devx_bdf_match[nd] = NULL;
-	if (!nd) {
-		/* No device matches, just complain and bail out. */
-		DRV_LOG(WARNING,
-			"no DevX device matches PCI device " PCI_PRI_FMT ","
-			" is DevX Configured?",
-			pci_dev->addr.domain, pci_dev->addr.bus,
-			pci_dev->addr.devid, pci_dev->addr.function);
-		rte_errno = ENOENT;
-		ret = -rte_errno;
-		goto exit;
-	}
-	/*
-	 * Now we can determine the maximal
-	 * amount of devices to be spawned.
-	 */
-	list = mlx5_malloc(MLX5_MEM_ZERO,
-			   sizeof(struct mlx5_dev_spawn_data),
-			   RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
-	if (!list) {
-		DRV_LOG(ERR, "spawn data array allocation failure");
-		rte_errno = ENOMEM;
-		ret = -rte_errno;
-		goto exit;
-	}
-	memset(&list[ns].info, 0, sizeof(list[ns].info));
-	list[ns].max_port = 1;
-	list[ns].phys_port = 1;
-	list[ns].phys_dev = devx_bdf_match[ns];
-	list[ns].eth_dev = NULL;
-	list[ns].pci_dev = pci_dev;
-	list[ns].pf_bond = bd;
-	list[ns].ifindex = -1; /* Spawn will assign */
-	list[ns].info =
+	memset(&spawn.info, 0, sizeof(spawn.info));
+	spawn.max_port = 1;
+	spawn.phys_port = 1;
+	spawn.phys_dev = devx_bdf_match;
+	spawn.eth_dev = NULL;
+	spawn.pci_dev = pci_dev;
+	spawn.ifindex = -1; /* Spawn will assign */
+	spawn.info =
 		(struct mlx5_switch_info){
 			.master = 0,
 			.representor = 0,
@@ -1125,29 +986,16 @@  mlx5_os_net_probe(struct rte_device *dev)
 	dev_config.dv_flow_en = 1;
 	dev_config.decap_en = 0;
 	dev_config.log_hp_size = MLX5_ARG_UNSET;
-	list[ns].numa_node = pci_dev->device.numa_node;
-	list[ns].eth_dev = mlx5_dev_spawn(&pci_dev->device,
-					  &list[ns],
-					  &dev_config);
-	if (!list[ns].eth_dev)
-		goto exit;
-	restore = list[ns].eth_dev->data->dev_flags;
-	rte_eth_copy_pci_info(list[ns].eth_dev, pci_dev);
+	spawn.numa_node = pci_dev->device.numa_node;
+	spawn.eth_dev = mlx5_dev_spawn(dev, &spawn, &dev_config);
+	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. */
-	list[ns].eth_dev->data->dev_flags |= restore;
-	rte_eth_dev_probing_finish(list[ns].eth_dev);
-	ret = 0;
-exit:
-	/*
-	 * Do the routine cleanup:
-	 * - free allocated spawn data array
-	 * - free the device list
-	 */
-	if (list)
-		mlx5_free(list);
-	MLX5_ASSERT(orig_devx_bdf_devs);
-	mlx5_glue->free_device_list(orig_devx_bdf_devs);
-	return ret;
+	spawn.eth_dev->data->dev_flags |= restore;
+	rte_eth_dev_probing_finish(spawn.eth_dev);
+	return 0;
 }
 
 /**