common/mlx5: share Verbs device match function
authorShiri Kuzin <shirik@nvidia.com>
Tue, 4 May 2021 17:54:56 +0000 (20:54 +0300)
committerThomas Monjalon <thomas@monjalon.net>
Tue, 4 May 2021 20:49:37 +0000 (22:49 +0200)
The get_ib_device_match function iterates over the list of ib devices
returned by the get_device_list glue function and returns the ib device
matching the provided address.

Since this function is in use by several drivers, in this patch we
share the function in common part.

Signed-off-by: Shiri Kuzin <shirik@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
drivers/common/mlx5/linux/mlx5_common_os.c
drivers/common/mlx5/linux/mlx5_common_os.h
drivers/common/mlx5/mlx5_common.h
drivers/common/mlx5/version.map
drivers/compress/mlx5/mlx5_compress.c
drivers/regex/mlx5/mlx5_regex.c
drivers/vdpa/mlx5/mlx5_vdpa.c

index fba8245..ea0b71e 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "mlx5_common.h"
 #include "mlx5_common_log.h"
+#include "mlx5_common_os.h"
 #include "mlx5_glue.h"
 
 #ifdef MLX5_GLUE
@@ -423,3 +424,30 @@ glue_error:
        mlx5_glue = NULL;
 }
 
+struct ibv_device *
+mlx5_os_get_ibv_device(struct rte_pci_addr *addr)
+{
+       int n;
+       struct ibv_device **ibv_list = mlx5_glue->get_device_list(&n);
+       struct ibv_device *ibv_match = NULL;
+
+       if (ibv_list == NULL) {
+               rte_errno = ENOSYS;
+               return NULL;
+       }
+       while (n-- > 0) {
+               struct rte_pci_addr paddr;
+
+               DRV_LOG(DEBUG, "Checking device \"%s\"..", ibv_list[n]->name);
+               if (mlx5_dev_to_pci_addr(ibv_list[n]->ibdev_path, &paddr) != 0)
+                       continue;
+               if (rte_pci_addr_cmp(addr, &paddr) != 0)
+                       continue;
+               ibv_match = ibv_list[n];
+               break;
+       }
+       if (ibv_match == NULL)
+               rte_errno = ENOENT;
+       mlx5_glue->free_device_list(ibv_list);
+       return ibv_match;
+}
index d1c7e3d..72d6bf8 100644 (file)
@@ -288,4 +288,9 @@ mlx5_os_free(void *addr)
 {
        free(addr);
 }
+
+__rte_internal
+struct ibv_device *
+mlx5_os_get_ibv_device(struct rte_pci_addr *addr);
+
 #endif /* RTE_PMD_MLX5_COMMON_OS_H_ */
index f3c6beb..1fbefe0 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "mlx5_prm.h"
 #include "mlx5_devx_cmds.h"
+#include "mlx5_common_os.h"
 
 /* Reported driver name. */
 #define MLX5_PCI_DRIVER_NAME "mlx5_pci"
index 40b0d71..5706c6b 100644 (file)
@@ -126,6 +126,7 @@ INTERNAL {
        mlx5_os_alloc_pd;
        mlx5_os_dealloc_pd;
        mlx5_os_dereg_mr;
+       mlx5_os_get_ibv_device; # WINDOWS_NO_EXPORT
        mlx5_os_reg_mr;
        mlx5_os_umem_dereg;
        mlx5_os_umem_reg;
index ec3c237..0581dee 100644 (file)
@@ -647,34 +647,6 @@ mlx5_compress_dequeue_burst(void *queue_pair, struct rte_comp_op **ops,
        return i;
 }
 
-static struct ibv_device *
-mlx5_compress_get_ib_device_match(struct rte_pci_addr *addr)
-{
-       int n;
-       struct ibv_device **ibv_list = mlx5_glue->get_device_list(&n);
-       struct ibv_device *ibv_match = NULL;
-
-       if (ibv_list == NULL) {
-               rte_errno = ENOSYS;
-               return NULL;
-       }
-       while (n-- > 0) {
-               struct rte_pci_addr paddr;
-
-               DRV_LOG(DEBUG, "Checking device \"%s\"..", ibv_list[n]->name);
-               if (mlx5_dev_to_pci_addr(ibv_list[n]->ibdev_path, &paddr) != 0)
-                       continue;
-               if (rte_pci_addr_cmp(addr, &paddr) != 0)
-                       continue;
-               ibv_match = ibv_list[n];
-               break;
-       }
-       if (ibv_match == NULL)
-               rte_errno = ENOENT;
-       mlx5_glue->free_device_list(ibv_list);
-       return ibv_match;
-}
-
 static void
 mlx5_compress_hw_global_release(struct mlx5_compress_priv *priv)
 {
@@ -774,7 +746,7 @@ mlx5_compress_pci_probe(struct rte_pci_driver *pci_drv,
                rte_errno = ENOTSUP;
                return -rte_errno;
        }
-       ibv = mlx5_compress_get_ib_device_match(&pci_dev->addr);
+       ibv = mlx5_os_get_ibv_device(&pci_dev->addr);
        if (ibv == NULL) {
                DRV_LOG(ERR, "No matching IB device for PCI slot "
                        PCI_PRI_FMT ".", pci_dev->addr.domain,
index 82c485e..dd96436 100644 (file)
@@ -11,6 +11,7 @@
 #include <rte_regexdev_driver.h>
 
 #include <mlx5_common_pci.h>
+#include <mlx5_common.h>
 #include <mlx5_glue.h>
 #include <mlx5_devx_cmds.h>
 #include <mlx5_prm.h>
@@ -52,33 +53,6 @@ mlx5_regex_close(struct rte_regexdev *dev __rte_unused)
        return 0;
 }
 
-static struct ibv_device *
-mlx5_regex_get_ib_device_match(struct rte_pci_addr *addr)
-{
-       int n;
-       struct ibv_device **ibv_list = mlx5_glue->get_device_list(&n);
-       struct ibv_device *ibv_match = NULL;
-
-       if (!ibv_list) {
-               rte_errno = ENOSYS;
-               return NULL;
-       }
-       while (n-- > 0) {
-               struct rte_pci_addr pci_addr;
-
-               DRV_LOG(DEBUG, "Checking device \"%s\"..", ibv_list[n]->name);
-               if (mlx5_dev_to_pci_addr(ibv_list[n]->ibdev_path, &pci_addr))
-                       continue;
-               if (rte_pci_addr_cmp(addr, &pci_addr))
-                       continue;
-               ibv_match = ibv_list[n];
-               break;
-       }
-       if (!ibv_match)
-               rte_errno = ENOENT;
-       mlx5_glue->free_device_list(ibv_list);
-       return ibv_match;
-}
 static int
 mlx5_regex_engines_status(struct ibv_context *ctx, int num_engines)
 {
@@ -121,7 +95,7 @@ mlx5_regex_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
        int ret;
        uint32_t val;
 
-       ibv = mlx5_regex_get_ib_device_match(&pci_dev->addr);
+       ibv = mlx5_os_get_ibv_device(&pci_dev->addr);
        if (!ibv) {
                DRV_LOG(ERR, "No matching IB device for PCI slot "
                        PCI_PRI_FMT ".", pci_dev->addr.domain,
index 898e50f..17753ae 100644 (file)
@@ -472,34 +472,6 @@ static struct rte_vdpa_dev_ops mlx5_vdpa_ops = {
        .reset_stats = mlx5_vdpa_reset_stats,
 };
 
-static struct ibv_device *
-mlx5_vdpa_get_ib_device_match(struct rte_pci_addr *addr)
-{
-       int n;
-       struct ibv_device **ibv_list = mlx5_glue->get_device_list(&n);
-       struct ibv_device *ibv_match = NULL;
-
-       if (!ibv_list) {
-               rte_errno = ENOSYS;
-               return NULL;
-       }
-       while (n-- > 0) {
-               struct rte_pci_addr pci_addr;
-
-               DRV_LOG(DEBUG, "Checking device \"%s\"..", ibv_list[n]->name);
-               if (mlx5_dev_to_pci_addr(ibv_list[n]->ibdev_path, &pci_addr))
-                       continue;
-               if (rte_pci_addr_cmp(addr, &pci_addr))
-                       continue;
-               ibv_match = ibv_list[n];
-               break;
-       }
-       if (!ibv_match)
-               rte_errno = ENOENT;
-       mlx5_glue->free_device_list(ibv_list);
-       return ibv_match;
-}
-
 /* Try to disable ROCE by Netlink\Devlink. */
 static int
 mlx5_vdpa_nl_roce_disable(const char *addr)
@@ -595,7 +567,7 @@ mlx5_vdpa_roce_disable(struct rte_pci_addr *addr, struct ibv_device **ibv)
                struct ibv_device *ibv_new;
 
                for (r = MLX5_VDPA_MAX_RETRIES; r; r--) {
-                       ibv_new = mlx5_vdpa_get_ib_device_match(addr);
+                       ibv_new = mlx5_os_get_ibv_device(addr);
                        if (ibv_new) {
                                *ibv = ibv_new;
                                return 0;
@@ -698,7 +670,7 @@ mlx5_vdpa_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
        struct mlx5_hca_attr attr;
        int ret;
 
-       ibv = mlx5_vdpa_get_ib_device_match(&pci_dev->addr);
+       ibv = mlx5_os_get_ibv_device(&pci_dev->addr);
        if (!ibv) {
                DRV_LOG(ERR, "No matching IB device for PCI slot "
                        PCI_PRI_FMT ".", pci_dev->addr.domain,