Using syctl call the PCI addr is derived
dev.mlx5_core.0.%location: slot=8 function=0 dbsf=pci0:0:8:0
Signed-off-by: Srikanth Kaka <srikanth.k@oneconvergence.com>
Signed-off-by: Vag Singh <vag.singh@oneconvergence.com>
Signed-off-by: Anand Thulasiram <avelu@juniper.net>
---
drivers/common/mlx5/freebsd/mlx5_common_os.c | 48 ++++++++++++++++++++
1 file changed, 48 insertions(+)
@@ -14,6 +14,54 @@
#include "mlx5_common_os.h"
#include "mlx5_glue.h"
+/**
+ * Derive PCI address from devpath
+ */
+int
+mlx5_get_pci_addr(const char *dev_path, struct rte_pci_addr *pci_addr)
+{
+ char id[10];
+ char searchstr[MLX5_SYSCTL_BY_NAME_SIZE];
+ size_t length = MLX5_SYSCTL_BY_NAME_SIZE;
+ char name[MLX5_SYSCTL_BY_NAME_SIZE];
+ int traverse = 0;
+
+ strncpy(id, &dev_path[strlen("/sys/class/infiniband/mlx5_")],
+ strlen(dev_path) - strlen("/sys/class/infiniband/mlx5_"));
+ sprintf(searchstr, "dev.mlx5_core.%s.%slocation", id, "%");
+ sysctlbyname(searchstr, &name, &length, NULL, 0);
+
+ while (name[traverse]) {
+ if (name[traverse] == 'p' && name[traverse + 1] == 'c' &&
+ name[traverse + 2] == 'i')
+ break;
+ ++traverse;
+ }
+ traverse += 3;
+
+ int end = traverse;
+
+ while (name[end] != ' ')
+ ++end;
+
+ char address[end - traverse + 1];
+
+ memcpy(address, &name[traverse], end - traverse);
+ address[end - traverse] = '\0';
+
+ char *ptr = strtok(address, " :");
+
+ pci_addr->domain = (uint32_t)atoi(ptr);
+ ptr = strtok(NULL, " :");
+ pci_addr->bus = (uint8_t)atoi(ptr);
+ ptr = strtok(NULL, " :");
+ pci_addr->devid = (uint8_t)atoi(ptr);
+ ptr = strtok(NULL, " :");
+ pci_addr->function = (uint8_t)atoi(ptr);
+
+ return 0;
+}
+
/**
* Derive IB dev index from devpath
*/