All of lore.kernel.org
 help / color / mirror / Atom feed
From: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
To: dev@dpdk.org
Cc: shahafs@mellanox.com
Subject: [PATCH v2 01/13] net/mlx5: add representor recognition on kernels 5.x
Date: Mon, 25 Mar 2019 17:03:22 +0000	[thread overview]
Message-ID: <1553533414-9911-2-git-send-email-viacheslavo@mellanox.com> (raw)
In-Reply-To: <1553533414-9911-1-git-send-email-viacheslavo@mellanox.com>

The master device and VF representors were distinguished by
presence of port name, master device did not have one. The new Linux
kernels starting from 5.0 provide the port name for master device
and the implemented representor recognizing method does not work.
The new recognizing method is based on quiering the VF number,
created on the base of the device.

The IFLA_NUM_VF attribute is returned by kernel if IFLA_EXT_MASK
attribute is specified in the Netlink request message.

Also the presence of device symlink in device sysfs folder is
added to distinguish representors with sysfs based method.

Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
---
 drivers/net/mlx5/Makefile      | 10 ++++++++++
 drivers/net/mlx5/meson.build   |  4 ++++
 drivers/net/mlx5/mlx5.c        | 17 ++++++++++++++---
 drivers/net/mlx5/mlx5.h        |  1 +
 drivers/net/mlx5/mlx5_ethdev.c | 14 ++++++++++++--
 drivers/net/mlx5/mlx5_nl.c     | 37 ++++++++++++++++++++++++++++++++++---
 6 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/drivers/net/mlx5/Makefile b/drivers/net/mlx5/Makefile
index 1ed299d..3dd7e38 100644
--- a/drivers/net/mlx5/Makefile
+++ b/drivers/net/mlx5/Makefile
@@ -231,6 +231,16 @@ mlx5_autoconf.h.new: $(RTE_SDK)/buildtools/auto-config-h.sh
 		enum RDMA_NLDEV_ATTR_NDEV_INDEX \
 		$(AUTOCONF_OUTPUT)
 	$Q sh -- '$<' '$@' \
+		HAVE_IFLA_NUM_VF \
+		linux/if_link.h \
+		enum IFLA_NUM_VF \
+		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
+		HAVE_IFLA_EXT_MASK \
+		linux/if_link.h \
+		enum IFLA_EXT_MASK \
+		$(AUTOCONF_OUTPUT)
+	$Q sh -- '$<' '$@' \
 		HAVE_IFLA_PHYS_SWITCH_ID \
 		linux/if_link.h \
 		enum IFLA_PHYS_SWITCH_ID \
diff --git a/drivers/net/mlx5/meson.build b/drivers/net/mlx5/meson.build
index 0cf2f08..e3cb9bc 100644
--- a/drivers/net/mlx5/meson.build
+++ b/drivers/net/mlx5/meson.build
@@ -133,6 +133,10 @@ if build
 		'ETHTOOL_LINK_MODE_50000baseCR2_Full_BIT' ],
 		[ 'HAVE_ETHTOOL_LINK_MODE_100G', 'linux/ethtool.h',
 		'ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT' ],
+		[ 'HAVE_IFLA_NUM_VF', 'linux/if_link.h',
+		'IFLA_NUM_VF' ],
+		[ 'HAVE_IFLA_EXT_MASK', 'linux/if_link.h',
+		'IFLA_EXT_MASK' ],
 		[ 'HAVE_IFLA_PHYS_SWITCH_ID', 'linux/if_link.h',
 		'IFLA_PHYS_SWITCH_ID' ],
 		[ 'HAVE_IFLA_PHYS_PORT_NAME', 'linux/if_link.h',
diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c
index ad1975c..032f1f2 100644
--- a/drivers/net/mlx5/mlx5.c
+++ b/drivers/net/mlx5/mlx5.c
@@ -13,7 +13,6 @@
 #include <errno.h>
 #include <net/if.h>
 #include <sys/mman.h>
-#include <linux/netlink.h>
 #include <linux/rtnetlink.h>
 
 /* Verbs header. */
@@ -1001,9 +1000,21 @@
 	priv->nl_socket_route =	mlx5_nl_init(NETLINK_ROUTE);
 	priv->nl_sn = 0;
 	priv->representor = !!switch_info->representor;
+	priv->master = !!switch_info->master;
 	priv->domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
-	priv->representor_id =
-		switch_info->representor ? switch_info->port_name : -1;
+	/*
+	 * Currently we support sinlge E-Switch per PF configurations
+	 * only and representors_id field contains the vport index for
+	 * corresponding VF, deduced from representor port name.
+	 * For exapmple, let's have the IB device port 10, it has
+	 * attached network device eth0, which has port name attribute
+	 * pf0vf2, we can deduce the VF number as 2, and set vport index
+	 * as 3 (2+1). This assigning schema should be changed if the
+	 * multiple E-Switch instance per PF configurations or/and PCI
+	 * subfunctions dded.
+	 */
+	priv->representor_id = switch_info->representor ?
+			       switch_info->port_name + 1 : -1;
 	/*
 	 * Look for sibling devices in order to reuse their switch domain
 	 * if any, otherwise allocate one.
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index a88cb4a..58bc37f 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -214,6 +214,7 @@ struct mlx5_priv {
 	uint16_t mtu; /* Configured MTU. */
 	unsigned int isolated:1; /* Whether isolated mode is enabled. */
 	unsigned int representor:1; /* Device is a port representor. */
+	unsigned int master:1; /* Device is a E-Switch master. */
 	uint16_t domain_id; /* Switch domain identifier. */
 	int32_t representor_id; /* Port representor identifier. */
 	/* RX/TX queues. */
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index 2e8a296..64c6b6f 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -1362,8 +1362,10 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size)
 		.port_name = 0,
 		.switch_id = 0,
 	};
+	DIR *dir;
 	bool port_name_set = false;
 	bool port_switch_id_set = false;
+	bool device_dir = false;
 	char c;
 	int ret;
 
@@ -1376,6 +1378,8 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size)
 	      ifname);
 	MKSTR(phys_switch_id, "/sys/class/net/%s/phys_switch_id",
 	      ifname);
+	MKSTR(pci_device, "/sys/class/net/%s/device",
+	      ifname);
 
 	file = fopen(phys_port_name, "rb");
 	if (file != NULL) {
@@ -1394,8 +1398,14 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size)
 		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;
+	dir = opendir(pci_device);
+	if (dir != NULL) {
+		closedir(dir);
+		device_dir = true;
+	}
+	data.master = port_switch_id_set && (!port_name_set || device_dir);
+	data.representor = port_switch_id_set && port_name_set && !device_dir;
+	assert(!(data.master && data.representor));
 	*info = data;
 	return 0;
 }
diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c
index 8a10109..9d0fcba 100644
--- a/drivers/net/mlx5/mlx5_nl.c
+++ b/drivers/net/mlx5/mlx5_nl.c
@@ -65,6 +65,12 @@
 #endif
 
 /* These are normally found in linux/if_link.h. */
+#ifndef HAVE_IFLA_NUM_VF
+#define IFLA_NUM_VF 21
+#endif
+#ifndef HAVE_IFLA_EXT_MASK
+#define IFLA_EXT_MASK 29
+#endif
 #ifndef HAVE_IFLA_PHYS_SWITCH_ID
 #define IFLA_PHYS_SWITCH_ID 36
 #endif
@@ -837,6 +843,7 @@ struct mlx5_nl_ifindex_data {
 	size_t off = NLMSG_LENGTH(sizeof(struct ifinfomsg));
 	bool port_name_set = false;
 	bool switch_id_set = false;
+	bool num_vf_set = false;
 
 	if (nh->nlmsg_type != RTM_NEWLINK)
 		goto error;
@@ -848,6 +855,9 @@ struct mlx5_nl_ifindex_data {
 		if (ra->rta_len > nh->nlmsg_len - off)
 			goto error;
 		switch (ra->rta_type) {
+		case IFLA_NUM_VF:
+			num_vf_set = true;
+			break;
 		case IFLA_PHYS_PORT_NAME:
 			port_name_set =
 				mlx5_translate_port_name((char *)payload,
@@ -864,8 +874,20 @@ struct mlx5_nl_ifindex_data {
 		}
 		off += RTA_ALIGN(ra->rta_len);
 	}
-	info.master = switch_id_set && !port_name_set;
-	info.representor = switch_id_set && port_name_set;
+	if (switch_id_set) {
+		if (info.port_name_new) {
+			/* New representors naming schema. */
+			if (port_name_set) {
+				info.master = (info.port_name == -1);
+				info.representor = (info.port_name != -1);
+			}
+		} else {
+			/* Legacy representors naming schema. */
+			info.master = (!port_name_set || num_vf_set);
+			info.representor = port_name_set && !num_vf_set;
+		}
+	}
+	assert(!(data.master && data.representor));
 	memcpy(arg, &info, sizeof(info));
 	return 0;
 error:
@@ -893,9 +915,13 @@ struct mlx5_nl_ifindex_data {
 	struct {
 		struct nlmsghdr nh;
 		struct ifinfomsg info;
+		struct rtattr rta;
+		uint32_t extmask;
 	} req = {
 		.nh = {
-			.nlmsg_len = NLMSG_LENGTH(sizeof(req.info)),
+			.nlmsg_len = NLMSG_LENGTH
+					(sizeof(req.info) +
+					 RTA_LENGTH(sizeof(uint32_t))),
 			.nlmsg_type = RTM_GETLINK,
 			.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
 		},
@@ -903,6 +929,11 @@ struct mlx5_nl_ifindex_data {
 			.ifi_family = AF_UNSPEC,
 			.ifi_index = ifindex,
 		},
+		.rta = {
+			.rta_type = IFLA_EXT_MASK,
+			.rta_len = RTA_LENGTH(sizeof(int32_t)),
+		},
+		.extmask = RTE_LE32(1),
 	};
 	int ret;
 
-- 
1.8.3.1

  reply	other threads:[~2019-03-25 17:03 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-28 18:02 [RFC 00/10] net/mlx5: add support for multiport IB devices Viacheslav Ovsiienko
2019-02-28 18:02 ` [RFC 01/10] net/mlx5: add multiport IB device port structure Viacheslav Ovsiienko
2019-02-28 18:02 ` [RFC 02/10] net/mlx5: modify get ifindex routine for multiport IB Viacheslav Ovsiienko
2019-02-28 18:02 ` [RFC 03/10] net/mlx5: add getting IB ports number " Viacheslav Ovsiienko
2019-02-28 18:02 ` [RFC 04/10] net/mlx5: add multiport IB device support to probing Viacheslav Ovsiienko
2019-02-28 18:03 ` [RFC 05/10] net/mlx5: add IB shared context alloc/free functions Viacheslav Ovsiienko
2019-02-28 18:03 ` [RFC 06/10] net/mlx5: switch to the names in the shared IB context Viacheslav Ovsiienko
2019-02-28 18:03 ` [RFC 07/10] net/mlx5: switch to the shared Protection Domain Viacheslav Ovsiienko
2019-02-28 18:03 ` [RFC 08/10] net/mlx5: switch to the shared context IB attributes Viacheslav Ovsiienko
2019-02-28 18:03 ` [RFC 09/10] net/mlx5: switch to the shared IB device context Viacheslav Ovsiienko
2019-02-28 18:03 ` [RFC 10/10] net/mlx5: provide IB port for the object being created Viacheslav Ovsiienko
2019-03-21  8:11 ` [PATCH 00/14] net/mlx5: add support for multiport IB devices Viacheslav Ovsiienko
2019-03-21  8:11   ` [PATCH 01/14] net/mlx5: add representor recognition on kernels 5.x Viacheslav Ovsiienko
2019-03-21 12:13     ` Shahaf Shuler
2019-03-21 15:08       ` Stephen Hemminger
2019-03-21 15:31         ` Slava Ovsiienko
2019-03-21 19:08           ` Stephen Hemminger
2019-03-22  8:15             ` Slava Ovsiienko
2019-03-21  8:11   ` [PATCH 02/14] net/mlx5: introduce multiport IB device shared structure Viacheslav Ovsiienko
2019-03-21  8:11   ` [PATCH 03/14] net/mlx5: modify get ifindex routine for multiport IB Viacheslav Ovsiienko
2019-03-21 12:14     ` Shahaf Shuler
2019-03-21 12:58       ` Slava Ovsiienko
2019-03-21  8:11   ` [PATCH 04/14] net/mlx5: add getting IB ports number " Viacheslav Ovsiienko
2019-03-21 12:14     ` Shahaf Shuler
2019-03-21  8:11   ` [PATCH 05/14] net/mlx5: add multiport IB device support to probing Viacheslav Ovsiienko
2019-03-21 12:14     ` Shahaf Shuler
2019-03-21 12:54       ` Slava Ovsiienko
2019-03-21 12:57         ` Slava Ovsiienko
2019-03-24  9:00           ` Shahaf Shuler
2019-03-21  8:11   ` [PATCH 06/14] net/mlx5: add IB shared context alloc/free functions Viacheslav Ovsiienko
2019-03-21 12:14     ` Shahaf Shuler
2019-03-21  8:11   ` [PATCH 07/14] net/mlx5: switch to the names in the shared IB context Viacheslav Ovsiienko
2019-03-21 12:14     ` Shahaf Shuler
2019-03-21  8:11   ` [PATCH 08/14] net/mlx5: switch to the shared Protection Domain Viacheslav Ovsiienko
2019-03-21 12:14     ` Shahaf Shuler
2019-03-21  8:11   ` [PATCH 09/14] net/mlx5: switch to the shared context IB attributes Viacheslav Ovsiienko
2019-03-21 12:14     ` Shahaf Shuler
2019-03-21  8:11   ` [PATCH 10/14] net/mlx5: switch to the shared IB device context Viacheslav Ovsiienko
2019-03-21 12:14     ` Shahaf Shuler
2019-03-21  8:11   ` [PATCH 11/14] net/mlx5: provide IB port for the object being created Viacheslav Ovsiienko
2019-03-21 12:15     ` Shahaf Shuler
2019-03-21  8:11   ` [PATCH 12/14] net/mlx5: update install/uninstall int handler routines Viacheslav Ovsiienko
2019-03-21 12:15     ` Shahaf Shuler
2019-03-21 14:01       ` Slava Ovsiienko
2019-03-24  9:07         ` Shahaf Shuler
2019-03-21  8:11   ` [PATCH 13/14] net/mlx5: update event handler for multiport IB devices Viacheslav Ovsiienko
2019-03-21 12:15     ` Shahaf Shuler
2019-03-21 14:08       ` Slava Ovsiienko
2019-03-21  8:11   ` [PATCH 14/14] net/mlx5: add source vport match to the ingress rules Viacheslav Ovsiienko
2019-03-21 12:15     ` Shahaf Shuler
2019-03-21 14:11       ` Slava Ovsiienko
2019-03-24  9:13         ` Shahaf Shuler
2019-03-25  7:44           ` Slava Ovsiienko
2019-03-21 12:13   ` [PATCH 00/14] net/mlx5: add support for multiport IB devices Shahaf Shuler
2019-03-21 12:58     ` Slava Ovsiienko
2019-03-25 17:03   ` [PATCH v2 " Viacheslav Ovsiienko
2019-03-25 17:03     ` Viacheslav Ovsiienko [this message]
2019-03-25 18:06       ` [PATCH v2 01/13] net/mlx5: add representor recognition on kernels 5.x Stephen Hemminger
2019-03-25 18:07       ` Stephen Hemminger
2019-03-26  7:33         ` Slava Ovsiienko
2019-03-26 12:20       ` Shahaf Shuler
2019-03-25 17:03     ` [PATCH v2 02/13] net/mlx5: modify get ifindex routine for multiport IB Viacheslav Ovsiienko
2019-03-26 11:47       ` Shahaf Shuler
2019-03-25 17:03     ` [PATCH v2 03/13] net/mlx5: add getting IB ports number " Viacheslav Ovsiienko
2019-03-25 17:03     ` [PATCH v2 04/13] net/mlx5: add multiport IB device support to probing Viacheslav Ovsiienko
2019-03-26 12:02       ` Shahaf Shuler
2019-03-25 17:03     ` [PATCH v2 05/13] net/mlx5: add IB shared context alloc/free functions Viacheslav Ovsiienko
2019-03-26 12:10       ` Shahaf Shuler
2019-03-25 17:03     ` [PATCH v2 06/13] net/mlx5: switch to the names in the shared IB context Viacheslav Ovsiienko
2019-03-25 17:03     ` [PATCH v2 07/13] net/mlx5: switch to the shared Protection Domain Viacheslav Ovsiienko
2019-03-25 17:03     ` [PATCH v2 08/13] net/mlx5: switch to the shared context IB attributes Viacheslav Ovsiienko
2019-03-25 17:03     ` [PATCH v2 09/13] net/mlx5: switch to the shared IB device context Viacheslav Ovsiienko
2019-03-25 17:03     ` [PATCH v2 10/13] net/mlx5: provide IB port for the object being created Viacheslav Ovsiienko
2019-03-25 17:03     ` [PATCH v2 11/13] net/mlx5: update install/uninstall int handler routines Viacheslav Ovsiienko
2019-03-26 12:14       ` Shahaf Shuler
2019-03-25 17:03     ` [PATCH v2 12/13] net/mlx5: update event handler for multiport IB devices Viacheslav Ovsiienko
2019-03-26 12:16       ` Shahaf Shuler
2019-03-25 17:03     ` [PATCH v2 13/13] net/mlx5: add source vport match to the ingress rules Viacheslav Ovsiienko
2019-03-26 12:21       ` Shahaf Shuler
2019-03-26 15:35     ` [PATCH v3 00/14] net/mlx5: add support for multiport IB devices Viacheslav Ovsiienko
2019-03-26 15:35       ` [PATCH v3 01/13] net/mlx5: add representor recognition on kernels 5.x Viacheslav Ovsiienko
2019-03-26 19:37         ` Shahaf Shuler
2019-03-26 15:35       ` [PATCH v3 02/13] net/mlx5: modify get ifindex routine for multiport IB Viacheslav Ovsiienko
2019-03-26 15:35       ` [PATCH v3 03/13] net/mlx5: add getting IB ports number " Viacheslav Ovsiienko
2019-03-26 15:35       ` [PATCH v3 04/13] net/mlx5: add multiport IB device support to probing Viacheslav Ovsiienko
2019-03-26 15:35       ` [PATCH v3 05/13] net/mlx5: add IB shared context alloc/free functions Viacheslav Ovsiienko
2019-03-26 19:35         ` Shahaf Shuler
2019-03-26 15:35       ` [PATCH v3 06/13] net/mlx5: switch to the names in the shared IB context Viacheslav Ovsiienko
2019-03-26 15:35       ` [PATCH v3 07/13] net/mlx5: switch to the shared Protection Domain Viacheslav Ovsiienko
2019-03-26 15:35       ` [PATCH v3 08/13] net/mlx5: switch to the shared context IB attributes Viacheslav Ovsiienko
2019-03-26 15:35       ` [PATCH v3 09/13] net/mlx5: switch to the shared IB device context Viacheslav Ovsiienko
2019-03-26 15:35       ` [PATCH v3 10/13] net/mlx5: provide IB port for the object being created Viacheslav Ovsiienko
2019-03-26 15:35       ` [PATCH v3 11/13] net/mlx5: update install/uninstall int handler routines Viacheslav Ovsiienko
2019-03-26 15:35       ` [PATCH v3 12/13] net/mlx5: update event handler for multiport IB devices Viacheslav Ovsiienko
2019-03-26 15:35       ` [PATCH v3 13/13] net/mlx5: add source vport match to the ingress rules Viacheslav Ovsiienko
2019-03-26 19:38         ` Shahaf Shuler
2019-03-27  6:00       ` [PATCH v3 00/14] net/mlx5: add support for multiport IB devices Shahaf Shuler
2019-03-27  7:31         ` Slava Ovsiienko
2019-03-27 13:15       ` [PATCH v4 " Viacheslav Ovsiienko
2019-03-27 13:15         ` [PATCH v4 01/13] net/mlx5: add representor recognition on kernels 5.x Viacheslav Ovsiienko
2019-03-27 13:15         ` [PATCH v4 02/13] net/mlx5: modify get ifindex routine for multiport IB Viacheslav Ovsiienko
2019-03-27 13:15         ` [PATCH v4 03/13] net/mlx5: add getting IB ports number " Viacheslav Ovsiienko
2019-03-27 13:15         ` [PATCH v4 04/13] net/mlx5: add multiport IB device support to probing Viacheslav Ovsiienko
2019-03-27 13:15         ` [PATCH v4 05/13] net/mlx5: add IB shared context alloc/free functions Viacheslav Ovsiienko
2019-03-27 13:15         ` [PATCH v4 06/13] net/mlx5: switch to the names in the shared IB context Viacheslav Ovsiienko
2019-03-27 13:15         ` [PATCH v4 07/13] net/mlx5: switch to the shared Protection Domain Viacheslav Ovsiienko
2019-03-27 13:15         ` [PATCH v4 08/13] net/mlx5: switch to the shared context IB attributes Viacheslav Ovsiienko
2019-03-27 13:15         ` [PATCH v4 09/13] net/mlx5: switch to the shared IB device context Viacheslav Ovsiienko
2019-04-02  4:49           ` Shahaf Shuler
2019-03-27 13:15         ` [PATCH v4 10/13] net/mlx5: provide IB port for the object being created Viacheslav Ovsiienko
2019-03-27 13:15         ` [PATCH v4 11/13] net/mlx5: update install/uninstall int handler routines Viacheslav Ovsiienko
2019-03-27 13:15         ` [PATCH v4 12/13] net/mlx5: update event handler for multiport IB devices Viacheslav Ovsiienko
2019-03-27 13:15         ` [PATCH v4 13/13] net/mlx5: add source vport match to the ingress rules Viacheslav Ovsiienko
2019-03-28  9:21         ` [PATCH v4 00/14] net/mlx5: add support for multiport IB devices Shahaf Shuler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1553533414-9911-2-git-send-email-viacheslavo@mellanox.com \
    --to=viacheslavo@mellanox.com \
    --cc=dev@dpdk.org \
    --cc=shahafs@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.