From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80071.outbound.protection.outlook.com [40.107.8.71]) by dpdk.org (Postfix) with ESMTP id E82A098 for ; Sun, 22 Jul 2018 13:18:35 +0200 (CEST) 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=urd0i/fgIRjYK+0/8dBZTCywD7PSm7J8bA6PWwFMCXc=; b=yN1SWPnrD+ORIsRUAx5joNVvT1aJ/yXpS8ifLK24ssRAtz1D/2ze37l2f/+5rIk06ne9Nyp2lB0zaVg96mFwvLx3ObPE95OparZrpyuf0FzrJuxGMWMQ36NyEXV0fiA+KXzmQJO+hY81FEpU75x8Jh6xtYXfM41gE+gnGugOmtw= Received: from DB7PR05MB4426.eurprd05.prod.outlook.com (52.134.109.15) by DB7PR05MB4265.eurprd05.prod.outlook.com (52.134.108.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.973.21; Sun, 22 Jul 2018 11:18:34 +0000 Received: from DB7PR05MB4426.eurprd05.prod.outlook.com ([fe80::52a:650b:ae10:fc3]) by DB7PR05MB4426.eurprd05.prod.outlook.com ([fe80::52a:650b:ae10:fc3%3]) with mapi id 15.20.0952.022; Sun, 22 Jul 2018 11:18:34 +0000 From: Shahaf Shuler To: =?iso-8859-1?Q?N=E9lio_Laranjeiro?= , "dev@dpdk.org" , Yongseok Koh Thread-Topic: [PATCH] net/mlx5: fix representors detection Thread-Index: AQHUGrD8ndq9lI7Aa0igSr8j6PmiMqSbJFWQ Date: Sun, 22 Jul 2018 11:18:34 +0000 Message-ID: References: In-Reply-To: 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-microsoft-exchange-diagnostics: 1; DB7PR05MB4265; 6:N1lKVh2dBsqhJvP9+rMGQgJF6QE945VCKYZmWFVauXuHWRmHtrm06PBrCBsFy/b8oSx7R7Y9OzWihWQdQcXsHrV664AF6izZBBALWFoeaAf8cucljyFfcuqFXCd37hv80TKR90CCPEd6BnZbCO3G+sAnowpGYwuMM8KYhTP8miJqvBYbB0ATs6QN1txzLKFOEykYcVz8BBpYerbwRlX4ppclCKURrc01O+M7rqTBi2oC2bD3l7fyXZNm9BqNPI6kH9EwyEBHV2H7gtPNxZ4JnQZqHcwYDXiLuwi6umzDiHXpm4Nw12/RtMNYdB1uSqM3LADb9eqPAB1nb602PI4FyA0GCAS+1DmpL1ejQGPCKNCj6gZIU0+rbr2ajPwQg3d+s3IOTEAYcMBYlg4hBDjn/OgB+w+7GrpQUiGSB9sL3p6uFpXZpCBI+oIkFymDBu4eLldzzBMVum7Scl1TYrau4w==; 5:luQkeGYAgVH0HZZHYsi8O4w/hYHvihXGPWo5NgES6kzCbcyVIbVBUdafHmBS7e7SNKj+2soJVnan9EMdjfb1+TY3cC+0ZA0nDbMk17u/717zLRmHv4+z6dySPvJXyQ9xi03E6wx4JL3SI5YaHkh9TFDd5iky7TP8TEuGzF9YlZ0=; 7:EkDL+l8vG/z79n18owhVXeB9UjTbgkWktEgKnrUIixU8pKMgNvws+9p10I+KhF5iYIqSbuW1fwsi7aJcZb0KnnDv5HXZzY9bEtsugRO+aLue/B3llFHBMlbVR+crzqlKGcduOfT6A5ylicMgdVYNMeDr55C8M7ksLh7EuQs4UbQmUDZPG9o1U+J4BYYUE35IJWQg5i2inryGYeoquwBCBgF9WZBpVdYRQGrFp06TE4T8ByqfnESmR/QuicAnzO+i x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 6b9fdbea-0540-41c9-acb2-08d5efc4dd08 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600073)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:DB7PR05MB4265; x-ms-traffictypediagnostic: DB7PR05MB4265: x-ld-processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3231311)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(6055026)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(20161123562045)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:DB7PR05MB4265; BCL:0; PCL:0; RULEID:; SRVR:DB7PR05MB4265; x-forefront-prvs: 0741C77572 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(39860400002)(366004)(136003)(346002)(396003)(189003)(199004)(2501003)(476003)(5660300001)(106356001)(105586002)(3846002)(8936002)(2906002)(55016002)(6116002)(5250100002)(86362001)(110136005)(486006)(256004)(316002)(97736004)(25786009)(68736007)(53936002)(33656002)(99286004)(305945005)(7696005)(76176011)(6246003)(26005)(186003)(102836004)(14444005)(2900100001)(6636002)(6506007)(81166006)(478600001)(446003)(11346002)(6436002)(9686003)(66066001)(7736002)(81156014)(8676002)(229853002)(74316002)(14454004); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR05MB4265; H:DB7PR05MB4426.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: mellanox.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: KcLMeyZXMrt5Sk0+Vhp4e9g9vJmab6AUiP2Cxt/rGFx2hHBvGjh95a/fX9urzaRY6OylaMdK9J9MxzHlC8cwcf3GV8pmEgk8O6x2ji/n28+lX8P4TxNvyZy9kRzgLPu/j21S8lShw7H0Ea9/JwohVMEUJGElTOpQSE8RfCbFDum5cemHhHClrYSM9oLfIknfDnlWFLEHvV5uXHoiljYWcY8dU/G/j/IASc7IOCbA1uyG3w4AHbr2DcokVdeFcm/E+RPb8LqVfJ5RZWgkfQnS1YAuSvhgPruzp+/XBTb9exF5MPtQhEoRU8w4aB6bP0QTp8bYUZp54ZPK5AwpFbnhWCMaSyDqkCla8999Sv6gpX4= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b9fdbea-0540-41c9-acb2-08d5efc4dd08 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Jul 2018 11:18:34.2192 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR05MB4265 Subject: Re: [dpdk-dev] [PATCH] net/mlx5: fix representors detection X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Jul 2018 11:18:36 -0000 Hi Nelio,=20 Friday, July 13, 2018 4:54 PM, Nelio Laranjeiro: > Subject: [PATCH] net/mlx5: fix representors detection >=20 > On systems where the required Netlink commands are not supported but > Mellanox OFED is installed, representors information must be retrieved > through sysfs. >=20 > Fixes: 4c10141488fe ("net/mlx5: add port representor awareness") >=20 > Signed-off-by: Nelio Laranjeiro > Acked-by: Adrien Mazarguil > --- > drivers/net/mlx5/mlx5.c | 7 +++-- > drivers/net/mlx5/mlx5.h | 2 ++ > drivers/net/mlx5/mlx5_ethdev.c | 53 > ++++++++++++++++++++++++++++++++++ > 3 files changed, 60 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index > df7f39844..8174947f3 100644 > --- a/drivers/net/mlx5/mlx5.c > +++ b/drivers/net/mlx5/mlx5.c > @@ -1306,7 +1306,8 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > __rte_unused, > * Netlink calls assuming kernel drivers are recent enough to > * support them. > * > - * In the event of identification failure through Netlink, either: > + * In the event of identification failure through Netlink, try again > + * through sysfs, then either: > * > * 1. No device matches (n =3D=3D 0), complain and bail out. > * 2. A single IB device matches (n =3D=3D 1) and is not a representor,= @@ > -1325,7 +1326,9 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > __rte_unused, > if (nl_route < 0 || > !list[i].ifindex || > mlx5_nl_switch_info(nl_route, list[i].ifindex, > - &list[i].info)) { > + &list[i].info) || > + ((!list[i].info.representor && !list[i].info.master) && > + mlx5_sysfs_switch_info(list[i].ifindex, &list[i].info))) { I find this logic a bit complex to be under a single if statement. Can you = simplify it w/ local variables?=20 > list[i].ifindex =3D 0; > memset(&list[i].info, 0, sizeof(list[i].info)); > continue; > diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index > cc01310e0..fff88b1d6 100644 > --- a/drivers/net/mlx5/mlx5.h > +++ b/drivers/net/mlx5/mlx5.h > @@ -254,6 +254,8 @@ eth_rx_burst_t mlx5_select_rx_function(struct > rte_eth_dev *dev); unsigned int mlx5_dev_to_port_id(const struct > rte_device *dev, > uint16_t *port_list, > unsigned int port_list_n); > +int mlx5_sysfs_switch_info(unsigned int ifindex, > + struct mlx5_switch_info *info); >=20 > /* mlx5_mac.c */ >=20 > diff --git a/drivers/net/mlx5/mlx5_ethdev.c > b/drivers/net/mlx5/mlx5_ethdev.c index 05f66f7b6..101be4791 100644 > --- a/drivers/net/mlx5/mlx5_ethdev.c > +++ b/drivers/net/mlx5/mlx5_ethdev.c > @@ -1296,3 +1296,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 =3D { .master =3D 0, }; > + bool port_name_set =3D false; > + bool port_switch_id_set =3D false; > + char c; > + > + if (!if_indextoname(ifindex, ifname)) { > + rte_errno =3D 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 =3D fopen(phys_port_name, "rb"); > + if (file =3D=3D NULL) > + goto error; This goto is not correct.=20 Representors will indeed be able to read, but PFs will not be able to open = the phys_port_name (as there is none). The phys_switch_id is accessible form both.=20 I pasted a suggestion below[1], let me know what you think.=20 > + port_name_set =3D fscanf(file, "%d%c", &data.port_name, &c) =3D=3D 2 > && > + c =3D=3D '\n'; > + fclose(file); > + file =3D fopen(phys_switch_id, "rb"); > + if (file =3D=3D NULL) > + goto error; > + port_switch_id_set =3D > + 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; > + *info =3D data; > + return 0; > +error: > + rte_errno =3D errno; > + return -rte_errno; > +} > -- > 2.18.0 [1] diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.= c index 6cfe02d..b64eb20 100644 --- a/drivers/net/mlx5/mlx5_ethdev.c +++ b/drivers/net/mlx5/mlx5_ethdev.c @@ -1328,23 +1328,20 @@ struct ethtool_link_settings { ifname); =20 file =3D fopen(phys_port_name, "rb"); - if (file =3D=3D NULL) - goto error; - port_name_set =3D fscanf(file, "%d%c", &data.port_name, &c) =3D=3D = 2 && - c =3D=3D '\n'; - fclose(file); + if (file) { + port_name_set =3D fscanf(file, "%d%c", &data.port_name, &c)= =3D=3D 2 && + c =3D=3D '\n'; + fclose(file); + } file =3D fopen(phys_switch_id, "rb"); - if (file =3D=3D NULL) - goto error; - port_switch_id_set =3D - fscanf(file, "%" SCNx64 "%c", &data.switch_id, &c) =3D=3D 2= && - c =3D=3D '\n'; - fclose(file); + if (file) { + port_switch_id_set =3D + 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;