summaryrefslogtreecommitdiff
path: root/drivers/net/mlx5/mlx5_ethdev.c
diff options
context:
space:
mode:
authorDekel Peled <dekelp@mellanox.com>2019-03-17 08:23:03 +0200
committerFerruh Yigit <ferruh.yigit@intel.com>2019-03-20 18:15:42 +0100
commitb2f3a38101255ac6970eb055831588091bd7aba2 (patch)
treef06e7df8e2080a8f5fba123943b450610757184c /drivers/net/mlx5/mlx5_ethdev.c
parent761186fc7ba7fff191f2916734da82e134a9d0a1 (diff)
downloaddpdk-next-eventdev-b2f3a38101255ac6970eb055831588091bd7aba2.zip
dpdk-next-eventdev-b2f3a38101255ac6970eb055831588091bd7aba2.tar.gz
dpdk-next-eventdev-b2f3a38101255ac6970eb055831588091bd7aba2.tar.xz
net/mlx5: support new representor naming format
Kernel update [1] introduce new format of representors names. This patch implements RFC [2], updating MLX5 PMD to support the new format, while maintaining support of the existing format. [1] https://github.com/torvalds/linux/commit/c12ecc2 [2] http://mails.dpdk.org/archives/dev/2019-March/125676.html Signed-off-by: Dekel Peled <dekelp@mellanox.com> Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.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.c54
1 files changed, 50 insertions, 4 deletions
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index f84f7cf..84d761c 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -1353,8 +1353,15 @@ int
mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info)
{
char ifname[IF_NAMESIZE];
+ char port_name[IF_NAMESIZE];
FILE *file;
- struct mlx5_switch_info data = { .master = 0, };
+ struct mlx5_switch_info data = {
+ .master = 0,
+ .representor = 0,
+ .port_name_new = 0,
+ .port_name = 0,
+ .switch_id = 0,
+ };
bool port_name_set = false;
bool port_switch_id_set = false;
char c;
@@ -1371,10 +1378,9 @@ mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info)
file = fopen(phys_port_name, "rb");
if (file != NULL) {
- port_name_set =
- fscanf(file, "%d%c", &data.port_name, &c) == 2 &&
- c == '\n';
+ fscanf(file, "%s", port_name);
fclose(file);
+ port_name_set = mlx5_translate_port_name(port_name, &data);
}
file = fopen(phys_switch_id, "rb");
if (file == NULL) {
@@ -1390,3 +1396,43 @@ mlx5_sysfs_switch_info(unsigned int ifindex, struct mlx5_switch_info *info)
*info = data;
return 0;
}
+
+/**
+ * Extract port name, as a number, from sysfs or netlink information.
+ *
+ * @param[in] port_name_in
+ * String representing the port name.
+ * @param[out] port_info_out
+ * Port information, including port name as a number.
+ *
+ * @return
+ * true on success, false otherwise.
+ */
+bool
+mlx5_translate_port_name(const char *port_name_in,
+ struct mlx5_switch_info *port_info_out)
+{
+ char pf_c1, pf_c2, vf_c1, vf_c2;
+ char *end;
+ int32_t pf_num;
+ bool port_name_set = false;
+
+ /*
+ * Check for port-name as a string of the form pf0vf0
+ * (support kernel ver >= 5.0)
+ */
+ port_name_set = (sscanf(port_name_in, "%c%c%d%c%c%d", &pf_c1, &pf_c2,
+ &pf_num, &vf_c1, &vf_c2,
+ &port_info_out->port_name) == 6);
+ if (port_name_set) {
+ port_info_out->port_name_new = 1;
+ } else {
+ /* Check for port-name as a number (support kernel ver < 5.0 */
+ errno = 0;
+ port_info_out->port_name = strtol(port_name_in, &end, 0);
+ if (!errno &&
+ (size_t)(end - port_name_in) == strlen(port_name_in))
+ port_name_set = true;
+ }
+ return port_name_set;
+}