From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <shahafs@mellanox.com>
Received: from EUR01-VE1-obe.outbound.protection.outlook.com
 (mail-eopbgr140059.outbound.protection.outlook.com [40.107.14.59])
 by dpdk.org (Postfix) with ESMTP id B94324CA9
 for <dev@dpdk.org>; Thu, 21 Mar 2019 13:13:53 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com;
 s=selector1;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=g/iOs1jCQxKAgwGcl20it1bmhNUXChDZ/cwhpGROxeM=;
 b=lTL0BWnrmUz07a/vjU7GqCFaV9MPP8mmRZDDTNRM6tvrfatbs0uV+FxlynqDgjR57FhDgm6lM7dzn4BweuUmSV0wi4nIgsxZAcI43at7w2g8AClJ7zApvUWrib2wyUyZXN158N/5NEssXGnbwP6IUr6dUpCxxvAKLV9xznD5e+4=
Received: from AM0PR0502MB3795.eurprd05.prod.outlook.com (52.133.45.150) by
 AM0PR0502MB3827.eurprd05.prod.outlook.com (52.133.47.141) with Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.1730.15; Thu, 21 Mar 2019 12:13:51 +0000
Received: from AM0PR0502MB3795.eurprd05.prod.outlook.com
 ([fe80::84f3:7e92:7a51:1003]) by AM0PR0502MB3795.eurprd05.prod.outlook.com
 ([fe80::84f3:7e92:7a51:1003%2]) with mapi id 15.20.1730.013; Thu, 21 Mar 2019
 12:13:51 +0000
From: Shahaf Shuler <shahafs@mellanox.com>
To: Slava Ovsiienko <viacheslavo@mellanox.com>, "dev@dpdk.org" <dev@dpdk.org>
Thread-Topic: [PATCH 01/14] net/mlx5: add representor recognition on kernels
 5.x
Thread-Index: AQHU373F+LwEC7ZTEE2jFcSz0oFMPaYVyp9A
Date: Thu, 21 Mar 2019 12:13:50 +0000
Message-ID: <AM0PR0502MB3795FFC7899DA81B10BD4946C3420@AM0PR0502MB3795.eurprd05.prod.outlook.com>
References: <1551376985-11096-1-git-send-email-viacheslavo@mellanox.com>
 <1553155888-27498-1-git-send-email-viacheslavo@mellanox.com>
 <1553155888-27498-2-git-send-email-viacheslavo@mellanox.com>
In-Reply-To: <1553155888-27498-2-git-send-email-viacheslavo@mellanox.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
authentication-results: spf=none (sender IP is )
 smtp.mailfrom=shahafs@mellanox.com; 
x-originating-ip: [31.154.10.105]
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: b3729f68-dc52-46ac-06e2-08d6adf6ade1
x-ms-office365-filtering-ht: Tenant
x-microsoft-antispam: BCL:0; PCL:0;
 RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020);
 SRVR:AM0PR0502MB3827; 
x-ms-traffictypediagnostic: AM0PR0502MB3827:
x-ms-exchange-purlcount: 2
x-microsoft-antispam-prvs: <AM0PR0502MB3827A2920D568BC2AB2D8D9AC3420@AM0PR0502MB3827.eurprd05.prod.outlook.com>
x-forefront-prvs: 0983EAD6B2
x-forefront-antispam-report: SFV:NSPM;
 SFS:(10009020)(366004)(396003)(346002)(39860400002)(136003)(376002)(189003)(199004)(81166006)(97736004)(33656002)(68736007)(74316002)(25786009)(7736002)(305945005)(110136005)(316002)(14454004)(2906002)(446003)(2501003)(14444005)(52536014)(11346002)(476003)(71190400001)(256004)(86362001)(486006)(99286004)(186003)(5660300002)(66066001)(26005)(7696005)(53936002)(76176011)(102836004)(55016002)(9686003)(6436002)(71200400001)(229853002)(6306002)(3846002)(966005)(8676002)(8936002)(81156014)(478600001)(6246003)(106356001)(6506007)(6116002)(105586002)(309714004);
 DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0502MB3827;
 H:AM0PR0502MB3795.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en;
 PTR:InfoNoRecords; MX:3; A:1; 
received-spf: None (protection.outlook.com: mellanox.com does not designate
 permitted sender hosts)
x-ms-exchange-senderadcheck: 1
x-microsoft-antispam-message-info: rCNDU7ZFp/evHlEOnZ3RCsP98w6/TkrAYa5uaiospxIg4L8zkpkrloxoPrTTxT3mLBcDratfYYyU7M/gIPP24ORQOPp/9HFd+uxegVp7ZEOlJr+7r/x5kwQ23si2l1BOvCp9QF/8ei/FDkMuI+aq8thRTEnXzatNcvhbyDoQfWWAH3XTot0cGg2ARGS1Vgen4g78HI/mYmVTRvLL54YZK3J/uzB+ADcAkbw9cm747s7icFZ3h9IabZo8/2sUDcqIUD/2L+uY7fJO3njgby8DR1fE1ai6OdttDhHO1eP92J/N6g7gttrNrE6vEw75znhER0jz+l2vIy9aL+pSbRd1GiPSmx+ESIF+nw4h2tQ5eqJvtuq1nNFJ1ujxnVaZLUm3F1RnXOcy/Bs8REqWb+iJFExk3GSBKB+SNfEMFSl+13c=
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-OriginatorOrg: Mellanox.com
X-MS-Exchange-CrossTenant-Network-Message-Id: b3729f68-dc52-46ac-06e2-08d6adf6ade1
X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Mar 2019 12:13:50.9278 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0502MB3827
Subject: Re: [dpdk-dev] [PATCH 01/14] net/mlx5: add representor recognition
 on kernels 5.x
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
X-List-Received-Date: Thu, 21 Mar 2019 12:13:53 -0000

Hi Slava,

Small comments below. Once fixed you can put my acked-by on the next versio=
n.=20

Thursday, March 21, 2019 10:11 AM, Viacheslav Ovsiienko:
> Subject: [PATCH 01/14] net/mlx5: add representor recognition on kernels 5=
.x
>=20
> 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.
>=20
> The IFLA_NUM_VF attribute is returned by kernel if IFLA_EXT_MASK
> attribute is specified in the Netlink request message.
>=20
> Also the presence of device symlink in device sysfs folder is added to
> distinguish representors with sysfs based method.
>=20
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
>=20
> ---
>=20
> v3: - rebased over new port naming http://patches.dpdk.org/patch/51245/
>     - master recognition is reinforced by checking vport for -1
>       for new port naming schema
>=20
> v2: - fopen replaced with opendir to detect whether directory exists
>=20
> v1: http://patches.dpdk.org/patch/50411/
> ---
>  drivers/net/mlx5/Makefile      | 10 ++++++++++
>  drivers/net/mlx5/meson.build   |  4 ++++
>  drivers/net/mlx5/mlx5.c        |  2 +-
>  drivers/net/mlx5/mlx5.h        |  1 +
>  drivers/net/mlx5/mlx5_ethdev.c | 13 +++++++++++--
>  drivers/net/mlx5/mlx5_nl.c     | 36
> +++++++++++++++++++++++++++++++++---
>  6 files changed, 60 insertions(+), 6 deletions(-)
>=20
> 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..ea3d00c 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>
>=20
>  /* Verbs header. */
> @@ -1001,6 +1000,7 @@
>  	priv->nl_socket_route =3D	mlx5_nl_init(NETLINK_ROUTE);
>  	priv->nl_sn =3D 0;
>  	priv->representor =3D !!switch_info->representor;
> +	priv->master =3D !!switch_info->master;
>  	priv->domain_id =3D RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
>  	priv->representor_id =3D
>  		switch_info->representor ? switch_info->port_name : -1; 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 84d761c..81f2a42 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 =3D 0,
>  		.switch_id =3D 0,
>  	};
> +	DIR *dir;
>  	bool port_name_set =3D false;
>  	bool port_switch_id_set =3D false;
> +	bool device_dir =3D false;
>  	char c;
>=20
>  	if (!if_indextoname(ifindex, ifname)) { @@ -1375,6 +1377,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);
>=20
>  	file =3D fopen(phys_port_name, "rb");
>  	if (file !=3D NULL) {
> @@ -1391,8 +1395,13 @@ 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) =3D=3D 2 &&
>  		c =3D=3D '\n';
>  	fclose(file);
> -	data.master =3D port_switch_id_set && !port_name_set;
> -	data.representor =3D port_switch_id_set && port_name_set;
> +	dir =3D opendir(pci_device);
> +	if (dir !=3D NULL) {
> +		closedir(dir);
> +		device_dir =3D true;
> +	}
> +	data.master =3D port_switch_id_set && (!port_name_set ||
> device_dir);
> +	data.representor =3D port_switch_id_set && port_name_set &&
> !device_dir;

Add assert that device cannot be both master and representor.=20

>  	*info =3D data;
>  	return 0;
>  }
> diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c inde=
x
> 8a10109..aa49cb4 100644
> --- a/drivers/net/mlx5/mlx5_nl.c
> +++ b/drivers/net/mlx5/mlx5_nl.c
> @@ -65,6 +65,12 @@
>  #endif
>=20
>  /* 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 =3D NLMSG_LENGTH(sizeof(struct ifinfomsg));
>  	bool port_name_set =3D false;
>  	bool switch_id_set =3D false;
> +	bool num_vf_set =3D false;
>=20
>  	if (nh->nlmsg_type !=3D 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 =3D true;
> +			break;
>  		case IFLA_PHYS_PORT_NAME:
>  			port_name_set =3D
>  				mlx5_translate_port_name((char *)payload,
> @@ -864,8 +874,19 @@ struct mlx5_nl_ifindex_data {
>  		}
>  		off +=3D RTA_ALIGN(ra->rta_len);
>  	}
> -	info.master =3D switch_id_set && !port_name_set;
> -	info.representor =3D 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 =3D (info.port_name =3D=3D -1);
> +				info.representor =3D (info.port_name !=3D -1);
> +			}
> +		} else {
> +			/* Legacy representors naming schema. */
> +			info.master =3D (!port_name_set || num_vf_set);
> +			info.representor =3D port_name_set && !num_vf_set;
> +		}
> +	}

Add assert that device cannot be both master and representor.

>  	memcpy(arg, &info, sizeof(info));
>  	return 0;
>  error:
> @@ -893,9 +914,13 @@ struct mlx5_nl_ifindex_data {
>  	struct {
>  		struct nlmsghdr nh;
>  		struct ifinfomsg info;
> +		struct rtattr rta;
> +		uint32_t extmask;
>  	} req =3D {
>  		.nh =3D {
> -			.nlmsg_len =3D NLMSG_LENGTH(sizeof(req.info)),
> +			.nlmsg_len =3D NLMSG_LENGTH
> +					(sizeof(req.info) +
> +					 RTA_LENGTH(sizeof(uint32_t))),
>  			.nlmsg_type =3D RTM_GETLINK,
>  			.nlmsg_flags =3D NLM_F_REQUEST | NLM_F_ACK,
>  		},
> @@ -903,6 +928,11 @@ struct mlx5_nl_ifindex_data {
>  			.ifi_family =3D AF_UNSPEC,
>  			.ifi_index =3D ifindex,
>  		},
> +		.rta =3D {
> +			.rta_type =3D IFLA_EXT_MASK,
> +			.rta_len =3D RTA_LENGTH(sizeof(int32_t)),
> +		},
> +		.extmask =3D RTE_LE32(1),
>  	};
>  	int ret;
>=20
> --
> 1.8.3.1

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by dpdk.space (Postfix) with ESMTP id DAEC7A00E6
	for <public@inbox.dpdk.org>; Thu, 21 Mar 2019 13:13:55 +0100 (CET)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 96C501B4B8;
	Thu, 21 Mar 2019 13:13:55 +0100 (CET)
Received: from EUR01-VE1-obe.outbound.protection.outlook.com
 (mail-eopbgr140059.outbound.protection.outlook.com [40.107.14.59])
 by dpdk.org (Postfix) with ESMTP id B94324CA9
 for <dev@dpdk.org>; Thu, 21 Mar 2019 13:13:53 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com;
 s=selector1;
 h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
 bh=g/iOs1jCQxKAgwGcl20it1bmhNUXChDZ/cwhpGROxeM=;
 b=lTL0BWnrmUz07a/vjU7GqCFaV9MPP8mmRZDDTNRM6tvrfatbs0uV+FxlynqDgjR57FhDgm6lM7dzn4BweuUmSV0wi4nIgsxZAcI43at7w2g8AClJ7zApvUWrib2wyUyZXN158N/5NEssXGnbwP6IUr6dUpCxxvAKLV9xznD5e+4=
Received: from AM0PR0502MB3795.eurprd05.prod.outlook.com (52.133.45.150) by
 AM0PR0502MB3827.eurprd05.prod.outlook.com (52.133.47.141) with Microsoft SMTP
 Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.1730.15; Thu, 21 Mar 2019 12:13:51 +0000
Received: from AM0PR0502MB3795.eurprd05.prod.outlook.com
 ([fe80::84f3:7e92:7a51:1003]) by AM0PR0502MB3795.eurprd05.prod.outlook.com
 ([fe80::84f3:7e92:7a51:1003%2]) with mapi id 15.20.1730.013; Thu, 21 Mar 2019
 12:13:51 +0000
From: Shahaf Shuler <shahafs@mellanox.com>
To: Slava Ovsiienko <viacheslavo@mellanox.com>, "dev@dpdk.org" <dev@dpdk.org>
Thread-Topic: [PATCH 01/14] net/mlx5: add representor recognition on kernels
 5.x
Thread-Index: AQHU373F+LwEC7ZTEE2jFcSz0oFMPaYVyp9A
Date: Thu, 21 Mar 2019 12:13:50 +0000
Message-ID:
 <AM0PR0502MB3795FFC7899DA81B10BD4946C3420@AM0PR0502MB3795.eurprd05.prod.outlook.com>
References: <1551376985-11096-1-git-send-email-viacheslavo@mellanox.com>
 <1553155888-27498-1-git-send-email-viacheslavo@mellanox.com>
 <1553155888-27498-2-git-send-email-viacheslavo@mellanox.com>
In-Reply-To: <1553155888-27498-2-git-send-email-viacheslavo@mellanox.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach: 
X-MS-TNEF-Correlator: 
authentication-results: spf=none (sender IP is )
 smtp.mailfrom=shahafs@mellanox.com; 
x-originating-ip: [31.154.10.105]
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: b3729f68-dc52-46ac-06e2-08d6adf6ade1
x-ms-office365-filtering-ht: Tenant
x-microsoft-antispam: BCL:0; PCL:0;
 RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(4618075)(2017052603328)(7153060)(7193020);
 SRVR:AM0PR0502MB3827; 
x-ms-traffictypediagnostic: AM0PR0502MB3827:
x-ms-exchange-purlcount: 2
x-microsoft-antispam-prvs: <AM0PR0502MB3827A2920D568BC2AB2D8D9AC3420@AM0PR0502MB3827.eurprd05.prod.outlook.com>
x-forefront-prvs: 0983EAD6B2
x-forefront-antispam-report: SFV:NSPM;
 SFS:(10009020)(366004)(396003)(346002)(39860400002)(136003)(376002)(189003)(199004)(81166006)(97736004)(33656002)(68736007)(74316002)(25786009)(7736002)(305945005)(110136005)(316002)(14454004)(2906002)(446003)(2501003)(14444005)(52536014)(11346002)(476003)(71190400001)(256004)(86362001)(486006)(99286004)(186003)(5660300002)(66066001)(26005)(7696005)(53936002)(76176011)(102836004)(55016002)(9686003)(6436002)(71200400001)(229853002)(6306002)(3846002)(966005)(8676002)(8936002)(81156014)(478600001)(6246003)(106356001)(6506007)(6116002)(105586002)(309714004);
 DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR0502MB3827;
 H:AM0PR0502MB3795.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en;
 PTR:InfoNoRecords; MX:3; A:1; 
received-spf: None (protection.outlook.com: mellanox.com does not designate
 permitted sender hosts)
x-ms-exchange-senderadcheck: 1
x-microsoft-antispam-message-info: rCNDU7ZFp/evHlEOnZ3RCsP98w6/TkrAYa5uaiospxIg4L8zkpkrloxoPrTTxT3mLBcDratfYYyU7M/gIPP24ORQOPp/9HFd+uxegVp7ZEOlJr+7r/x5kwQ23si2l1BOvCp9QF/8ei/FDkMuI+aq8thRTEnXzatNcvhbyDoQfWWAH3XTot0cGg2ARGS1Vgen4g78HI/mYmVTRvLL54YZK3J/uzB+ADcAkbw9cm747s7icFZ3h9IabZo8/2sUDcqIUD/2L+uY7fJO3njgby8DR1fE1ai6OdttDhHO1eP92J/N6g7gttrNrE6vEw75znhER0jz+l2vIy9aL+pSbRd1GiPSmx+ESIF+nw4h2tQ5eqJvtuq1nNFJ1ujxnVaZLUm3F1RnXOcy/Bs8REqWb+iJFExk3GSBKB+SNfEMFSl+13c=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-OriginatorOrg: Mellanox.com
X-MS-Exchange-CrossTenant-Network-Message-Id: b3729f68-dc52-46ac-06e2-08d6adf6ade1
X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Mar 2019 12:13:50.9278 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR0502MB3827
Subject: Re: [dpdk-dev] [PATCH 01/14] net/mlx5: add representor recognition
 on kernels 5.x
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>
Message-ID: <20190321121350.j5siTCp8EBP5oVyTTw0InEULUrCvaCq7qZ8w22YXldw@z>

Hi Slava,

Small comments below. Once fixed you can put my acked-by on the next versio=
n.=20

Thursday, March 21, 2019 10:11 AM, Viacheslav Ovsiienko:
> Subject: [PATCH 01/14] net/mlx5: add representor recognition on kernels 5=
.x
>=20
> 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.
>=20
> The IFLA_NUM_VF attribute is returned by kernel if IFLA_EXT_MASK
> attribute is specified in the Netlink request message.
>=20
> Also the presence of device symlink in device sysfs folder is added to
> distinguish representors with sysfs based method.
>=20
> Signed-off-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
>=20
> ---
>=20
> v3: - rebased over new port naming http://patches.dpdk.org/patch/51245/
>     - master recognition is reinforced by checking vport for -1
>       for new port naming schema
>=20
> v2: - fopen replaced with opendir to detect whether directory exists
>=20
> v1: http://patches.dpdk.org/patch/50411/
> ---
>  drivers/net/mlx5/Makefile      | 10 ++++++++++
>  drivers/net/mlx5/meson.build   |  4 ++++
>  drivers/net/mlx5/mlx5.c        |  2 +-
>  drivers/net/mlx5/mlx5.h        |  1 +
>  drivers/net/mlx5/mlx5_ethdev.c | 13 +++++++++++--
>  drivers/net/mlx5/mlx5_nl.c     | 36
> +++++++++++++++++++++++++++++++++---
>  6 files changed, 60 insertions(+), 6 deletions(-)
>=20
> 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..ea3d00c 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>
>=20
>  /* Verbs header. */
> @@ -1001,6 +1000,7 @@
>  	priv->nl_socket_route =3D	mlx5_nl_init(NETLINK_ROUTE);
>  	priv->nl_sn =3D 0;
>  	priv->representor =3D !!switch_info->representor;
> +	priv->master =3D !!switch_info->master;
>  	priv->domain_id =3D RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
>  	priv->representor_id =3D
>  		switch_info->representor ? switch_info->port_name : -1; 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 84d761c..81f2a42 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 =3D 0,
>  		.switch_id =3D 0,
>  	};
> +	DIR *dir;
>  	bool port_name_set =3D false;
>  	bool port_switch_id_set =3D false;
> +	bool device_dir =3D false;
>  	char c;
>=20
>  	if (!if_indextoname(ifindex, ifname)) { @@ -1375,6 +1377,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);
>=20
>  	file =3D fopen(phys_port_name, "rb");
>  	if (file !=3D NULL) {
> @@ -1391,8 +1395,13 @@ 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) =3D=3D 2 &&
>  		c =3D=3D '\n';
>  	fclose(file);
> -	data.master =3D port_switch_id_set && !port_name_set;
> -	data.representor =3D port_switch_id_set && port_name_set;
> +	dir =3D opendir(pci_device);
> +	if (dir !=3D NULL) {
> +		closedir(dir);
> +		device_dir =3D true;
> +	}
> +	data.master =3D port_switch_id_set && (!port_name_set ||
> device_dir);
> +	data.representor =3D port_switch_id_set && port_name_set &&
> !device_dir;

Add assert that device cannot be both master and representor.=20

>  	*info =3D data;
>  	return 0;
>  }
> diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c inde=
x
> 8a10109..aa49cb4 100644
> --- a/drivers/net/mlx5/mlx5_nl.c
> +++ b/drivers/net/mlx5/mlx5_nl.c
> @@ -65,6 +65,12 @@
>  #endif
>=20
>  /* 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 =3D NLMSG_LENGTH(sizeof(struct ifinfomsg));
>  	bool port_name_set =3D false;
>  	bool switch_id_set =3D false;
> +	bool num_vf_set =3D false;
>=20
>  	if (nh->nlmsg_type !=3D 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 =3D true;
> +			break;
>  		case IFLA_PHYS_PORT_NAME:
>  			port_name_set =3D
>  				mlx5_translate_port_name((char *)payload,
> @@ -864,8 +874,19 @@ struct mlx5_nl_ifindex_data {
>  		}
>  		off +=3D RTA_ALIGN(ra->rta_len);
>  	}
> -	info.master =3D switch_id_set && !port_name_set;
> -	info.representor =3D 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 =3D (info.port_name =3D=3D -1);
> +				info.representor =3D (info.port_name !=3D -1);
> +			}
> +		} else {
> +			/* Legacy representors naming schema. */
> +			info.master =3D (!port_name_set || num_vf_set);
> +			info.representor =3D port_name_set && !num_vf_set;
> +		}
> +	}

Add assert that device cannot be both master and representor.

>  	memcpy(arg, &info, sizeof(info));
>  	return 0;
>  error:
> @@ -893,9 +914,13 @@ struct mlx5_nl_ifindex_data {
>  	struct {
>  		struct nlmsghdr nh;
>  		struct ifinfomsg info;
> +		struct rtattr rta;
> +		uint32_t extmask;
>  	} req =3D {
>  		.nh =3D {
> -			.nlmsg_len =3D NLMSG_LENGTH(sizeof(req.info)),
> +			.nlmsg_len =3D NLMSG_LENGTH
> +					(sizeof(req.info) +
> +					 RTA_LENGTH(sizeof(uint32_t))),
>  			.nlmsg_type =3D RTM_GETLINK,
>  			.nlmsg_flags =3D NLM_F_REQUEST | NLM_F_ACK,
>  		},
> @@ -903,6 +928,11 @@ struct mlx5_nl_ifindex_data {
>  			.ifi_family =3D AF_UNSPEC,
>  			.ifi_index =3D ifindex,
>  		},
> +		.rta =3D {
> +			.rta_type =3D IFLA_EXT_MASK,
> +			.rta_len =3D RTA_LENGTH(sizeof(int32_t)),
> +		},
> +		.extmask =3D RTE_LE32(1),
>  	};
>  	int ret;
>=20
> --
> 1.8.3.1