summaryrefslogtreecommitdiff
path: root/drivers/net/mlx5/mlx5_ethdev.c
diff options
context:
space:
mode:
authorNelio Laranjeiro <nelio.laranjeiro@6wind.com>2018-07-24 10:36:45 +0200
committerThomas Monjalon <thomas@monjalon.net>2018-07-26 14:05:52 +0200
commitf872b4b99d2cb55933ff2172f5f6e346545bc27b (patch)
tree27ebd9b884f4f4dafcbe3675a2a61285d8286e1d /drivers/net/mlx5/mlx5_ethdev.c
parent2bc98393ac3ab980557187257369ec436a8f9eeb (diff)
downloaddpdk-next-eventdev-f872b4b99d2cb55933ff2172f5f6e346545bc27b.zip
dpdk-next-eventdev-f872b4b99d2cb55933ff2172f5f6e346545bc27b.tar.gz
dpdk-next-eventdev-f872b4b99d2cb55933ff2172f5f6e346545bc27b.tar.xz
net/mlx5: fix representors detection
On systems where the required Netlink commands are not supported but Mellanox OFED is installed, representors information must be retrieved through sysfs. Fixes: 26c08b979d26 ("net/mlx5: add port representor awareness") Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com> Acked-by: Shahaf Shuler <shahafs@mellanox.com>
Diffstat (limited to 'drivers/net/mlx5/mlx5_ethdev.c')
-rw-r--r--drivers/net/mlx5/mlx5_ethdev.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index 9cf2dc5..4a24f80 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -1321,3 +1321,56 @@ mlx5_dev_to_port_id(const struct rte_device *dev, uint16_t *port_list,
}
return n;
}
+
+/**
+ * Get switch information associated with network interface.
+ *
+ * @param ifindex
+ * Network interface index.
+ * @param[out] info
+ * Switch information object, populated in case of success.
+ *
+ * @return
+ * 0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+int
+mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info)
+{
+ char ifname[IF_NAMESIZE];
+ FILE *file;
+ struct mlx5_switch_info data = { .master = 0, };
+ bool port_name_set = false;
+ bool port_switch_id_set = false;
+ char c;
+
+ if (!if_indextoname(ifindex, ifname)) {
+ rte_errno = errno;
+ return -rte_errno;
+ }
+
+ MKSTR(phys_port_name, "/sys/class/net/%s/phys_port_name",
+ ifname);
+ MKSTR(phys_switch_id, "/sys/class/net/%s/phys_switch_id",
+ ifname);
+
+ file = fopen(phys_port_name, "rb");
+ if (file != NULL) {
+ port_name_set =
+ fscanf(file, "%d%c", &data.port_name, &c) == 2 &&
+ c == '\n';
+ fclose(file);
+ }
+ file = fopen(phys_switch_id, "rb");
+ if (file == NULL) {
+ rte_errno = errno;
+ return -rte_errno;
+ }
+ port_switch_id_set =
+ fscanf(file, "%" SCNx64 "%c", &data.switch_id, &c) == 2 &&
+ c == '\n';
+ fclose(file);
+ data.master = port_switch_id_set && !port_name_set;
+ data.representor = port_switch_id_set && port_name_set;
+ *info = data;
+ return 0;
+}