]> git.droids-corp.org - dpdk.git/commitdiff
common/mlx5: support PCIe device GUID query
authorRongwei Liu <rongweil@nvidia.com>
Tue, 26 Oct 2021 08:48:29 +0000 (11:48 +0300)
committerRaslan Darawsheh <rasland@nvidia.com>
Tue, 26 Oct 2021 09:26:14 +0000 (11:26 +0200)
sysfs entry "phys_switch_id" holds each PCIe device'
guid.

The devices which reside in the same physical NIC should
have the same guid.

Signed-off-by: Rongwei Liu <rongweil@nvidia.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
drivers/common/mlx5/linux/mlx5_common_os.c
drivers/common/mlx5/linux/mlx5_common_os.h

index 8db3fe790a2e8e104cfdb1604aedf1c44f527d26..b516564b79465b2a519f4c4e6788a9910542e161 100644 (file)
@@ -2,6 +2,7 @@
  * Copyright 2020 Mellanox Technologies, Ltd
  */
 
+#include <sys/types.h>
 #include <unistd.h>
 #include <string.h>
 #include <stdio.h>
@@ -704,3 +705,42 @@ error:
        DRV_LOG(ERR, "Failed to open IB device \"%s\".", ibv->name);
        return -rte_errno;
 }
+int
+mlx5_get_device_guid(const struct rte_pci_addr *dev, uint8_t *guid, size_t len)
+{
+       char tmp[512];
+       char cur_ifname[IF_NAMESIZE + 1];
+       FILE *id_file;
+       DIR *dir;
+       struct dirent *ptr;
+       int ret;
+
+       if (guid == NULL || len < sizeof(u_int64_t) + 1)
+               return -1;
+       memset(guid, 0, len);
+       snprintf(tmp, sizeof(tmp), "/sys/bus/pci/devices/%04x:%02x:%02x.%x/net",
+                       dev->domain, dev->bus, dev->devid, dev->function);
+       dir = opendir(tmp);
+       if (dir == NULL)
+               return -1;
+       /* Traverse to identify PF interface */
+       do {
+               ptr = readdir(dir);
+               if (ptr == NULL || ptr->d_type != DT_DIR) {
+                       closedir(dir);
+                       return -1;
+               }
+       } while (strchr(ptr->d_name, '.') || strchr(ptr->d_name, '_') ||
+                strchr(ptr->d_name, 'v'));
+       snprintf(cur_ifname, sizeof(cur_ifname), "%s", ptr->d_name);
+       closedir(dir);
+       snprintf(tmp + strlen(tmp), sizeof(tmp) - strlen(tmp),
+                       "/%s/phys_switch_id", cur_ifname);
+       /* Older OFED like 5.3 doesn't support read */
+       id_file = fopen(tmp, "r");
+       if (!id_file)
+               return 0;
+       ret = fscanf(id_file, "%16s", guid);
+       fclose(id_file);
+       return ret;
+}
index c2957f91eccbbb1258f1c9c8d948dddc8a69fb56..83066e752d0c6bdf6d7a0fb2672c47655a1e702c 100644 (file)
@@ -284,4 +284,23 @@ mlx5_os_free(void *addr)
 void
 mlx5_set_context_attr(struct rte_device *dev, struct ibv_context *ctx);
 
+/**
+ * This is used to query system_image_guid as describing in PRM.
+ *
+ * @param dev[in]
+ *  Pointer to a device instance as PCIe id.
+ * @param guid[out]
+ *  Pointer to the buffer to hold device guid.
+ *  Guid is uint64_t and corresponding to 17 bytes string.
+ * @param len[in]
+ *  Guid buffer length, 17 bytes at least.
+ *
+ * @return
+ *  -1 if internal failure.
+ *  0 if OFED doesn't support.
+ *  >0 if success.
+ */
+int
+mlx5_get_device_guid(const struct rte_pci_addr *dev, uint8_t *guid, size_t len);
+
 #endif /* RTE_PMD_MLX5_COMMON_OS_H_ */