common/mlx5: share PCI device detection
authorMatan Azrad <matan@mellanox.com>
Wed, 29 Jan 2020 12:38:29 +0000 (12:38 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Wed, 5 Feb 2020 08:51:20 +0000 (09:51 +0100)
Move PCI detection by IB device from mlx5 PMD to the common code.

Signed-off-by: Matan Azrad <matan@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
drivers/common/mlx5/Makefile
drivers/common/mlx5/mlx5_common.c
drivers/common/mlx5/mlx5_common.h
drivers/common/mlx5/rte_common_mlx5_version.map
drivers/net/mlx5/mlx5.c
drivers/net/mlx5/mlx5.h
drivers/net/mlx5/mlx5_ethdev.c
drivers/net/mlx5/mlx5_rxtx.c
drivers/net/mlx5/mlx5_stats.c

index b94d3c0..66585b2 100644 (file)
@@ -41,7 +41,7 @@ else
 LDLIBS += -libverbs -lmlx5
 endif
 
-LDLIBS += -lrte_eal
+LDLIBS += -lrte_eal -lrte_pci
 
 # A few warnings cannot be avoided in external headers.
 CFLAGS += -Wno-error=cast-qual -DNDEBUG -UPEDANTIC
index 9c88a63..5784139 100644 (file)
@@ -5,6 +5,7 @@
 #include <dlfcn.h>
 #include <unistd.h>
 #include <string.h>
+#include <stdio.h>
 
 #include <rte_errno.h>
 
 int mlx5_common_logtype;
 
 
+/**
+ * Get PCI information by sysfs device path.
+ *
+ * @param dev_path
+ *   Pointer to device sysfs folder name.
+ * @param[out] pci_addr
+ *   PCI bus address output buffer.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx5_dev_to_pci_addr(const char *dev_path,
+                    struct rte_pci_addr *pci_addr)
+{
+       FILE *file;
+       char line[32];
+       MKSTR(path, "%s/device/uevent", dev_path);
+
+       file = fopen(path, "rb");
+       if (file == NULL) {
+               rte_errno = errno;
+               return -rte_errno;
+       }
+       while (fgets(line, sizeof(line), file) == line) {
+               size_t len = strlen(line);
+               int ret;
+
+               /* Truncate long lines. */
+               if (len == (sizeof(line) - 1))
+                       while (line[(len - 1)] != '\n') {
+                               ret = fgetc(file);
+                               if (ret == EOF)
+                                       break;
+                               line[(len - 1)] = ret;
+                       }
+               /* Extract information. */
+               if (sscanf(line,
+                          "PCI_SLOT_NAME="
+                          "%" SCNx32 ":%" SCNx8 ":%" SCNx8 ".%" SCNx8 "\n",
+                          &pci_addr->domain,
+                          &pci_addr->bus,
+                          &pci_addr->devid,
+                          &pci_addr->function) == 4) {
+                       ret = 0;
+                       break;
+               }
+       }
+       fclose(file);
+       return 0;
+}
+
 #ifdef RTE_IBVERBS_LINK_DLOPEN
 
 /**
index 9f10def..107ab8d 100644 (file)
@@ -6,7 +6,9 @@
 #define RTE_PMD_MLX5_COMMON_H_
 
 #include <assert.h>
+#include <stdio.h>
 
+#include <rte_pci.h>
 #include <rte_log.h>
 
 
@@ -84,4 +86,6 @@ pmd_drv_log_basename(const char *s)
        \
        snprintf(name, sizeof(name), "" __VA_ARGS__)
 
+int mlx5_dev_to_pci_addr(const char *dev_path, struct rte_pci_addr *pci_addr);
+
 #endif /* RTE_PMD_MLX5_COMMON_H_ */
index e4f85e2..0c01172 100644 (file)
@@ -17,4 +17,6 @@ DPDK_20.02 {
        mlx5_devx_cmd_qp_query_tis_td;
        mlx5_devx_cmd_query_hca_attr;
        mlx5_devx_get_out_command_status;
+
+       mlx5_dev_to_pci_addr;
 };
index 8fbe826..d0fa2da 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <mlx5_glue.h>
 #include <mlx5_devx_cmds.h>
+#include <mlx5_common.h>
 
 #include "mlx5_defs.h"
 #include "mlx5.h"
index 872fccb..261a8fc 100644 (file)
@@ -655,8 +655,6 @@ int mlx5_dev_get_flow_ctrl(struct rte_eth_dev *dev,
                           struct rte_eth_fc_conf *fc_conf);
 int mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev,
                           struct rte_eth_fc_conf *fc_conf);
-int mlx5_dev_to_pci_addr(const char *dev_path,
-                        struct rte_pci_addr *pci_addr);
 void mlx5_dev_link_status_handler(void *arg);
 void mlx5_dev_interrupt_handler(void *arg);
 void mlx5_dev_interrupt_handler_devx(void *arg);
index eddf888..2628e64 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <mlx5_glue.h>
 #include <mlx5_devx_cmds.h>
+#include <mlx5_common.h>
 
 #include "mlx5.h"
 #include "mlx5_rxtx.h"
@@ -1211,58 +1212,6 @@ mlx5_dev_set_flow_ctrl(struct rte_eth_dev *dev, struct rte_eth_fc_conf *fc_conf)
        return 0;
 }
 
-/**
- * Get PCI information by sysfs device path.
- *
- * @param dev_path
- *   Pointer to device sysfs folder name.
- * @param[out] pci_addr
- *   PCI bus address output buffer.
- *
- * @return
- *   0 on success, a negative errno value otherwise and rte_errno is set.
- */
-int
-mlx5_dev_to_pci_addr(const char *dev_path,
-                    struct rte_pci_addr *pci_addr)
-{
-       FILE *file;
-       char line[32];
-       MKSTR(path, "%s/device/uevent", dev_path);
-
-       file = fopen(path, "rb");
-       if (file == NULL) {
-               rte_errno = errno;
-               return -rte_errno;
-       }
-       while (fgets(line, sizeof(line), file) == line) {
-               size_t len = strlen(line);
-               int ret;
-
-               /* Truncate long lines. */
-               if (len == (sizeof(line) - 1))
-                       while (line[(len - 1)] != '\n') {
-                               ret = fgetc(file);
-                               if (ret == EOF)
-                                       break;
-                               line[(len - 1)] = ret;
-                       }
-               /* Extract information. */
-               if (sscanf(line,
-                          "PCI_SLOT_NAME="
-                          "%" SCNx32 ":%" SCNx8 ":%" SCNx8 ".%" SCNx8 "\n",
-                          &pci_addr->domain,
-                          &pci_addr->bus,
-                          &pci_addr->devid,
-                          &pci_addr->function) == 4) {
-                       ret = 0;
-                       break;
-               }
-       }
-       fclose(file);
-       return 0;
-}
-
 /**
  * Handle asynchronous removal event for entire multiport device.
  *
index d8f6671..b14ae31 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <mlx5_devx_cmds.h>
 #include <mlx5_prm.h>
+#include <mlx5_common.h>
 
 #include "mlx5_defs.h"
 #include "mlx5.h"
index 0ed7170..4c69e77 100644 (file)
 #include <rte_common.h>
 #include <rte_malloc.h>
 
+#include <mlx5_common.h>
+
 #include "mlx5_defs.h"
 #include "mlx5.h"
 #include "mlx5_rxtx.h"
 
+
 static const struct mlx5_counter_ctrl mlx5_counters_init[] = {
        {
                .dpdk_name = "rx_port_unicast_bytes",