From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0060.outbound.protection.outlook.com [104.47.2.60]) by dpdk.org (Postfix) with ESMTP id 5D6B61DA4 for ; Tue, 24 Jul 2018 15:47:36 +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=f6fmvckyNnmF+6wHsxseo2uRYRGfxns/puzJMOBocDw=; b=esKxeMxRnodLUJpvT1w4UJOFH6C0eTZEqK7gR4n/GAKpQ+vuTG2pGaWzfvqaA28sPihhVjgDgqhhc0wo3zSqJ9P1z4lB0AmHeEPcgfBNCm0BJt24nZa8AdAOf1096C8N2WWLG4M5tj4HodmX/vSCmlDOUSbG+nDZirWIlkhANVk= Received: from DB7PR05MB4426.eurprd05.prod.outlook.com (52.134.109.15) by DB7PR05MB4444.eurprd05.prod.outlook.com (52.134.109.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.973.22; Tue, 24 Jul 2018 13:47: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; Tue, 24 Jul 2018 13:47:33 +0000 From: Shahaf Shuler To: =?iso-8859-1?Q?N=E9lio_Laranjeiro?= , "dev@dpdk.org" , Yongseok Koh CC: Wisam Monther , Raslan Darawsheh Thread-Topic: [PATCH v2] net/mlx5: fix representors detection Thread-Index: AQHUIyl8zch3g69gA0SNw69dEo8xTKSeY0Bg Date: Tue, 24 Jul 2018 13:47:33 +0000 Message-ID: References: <262388487b03db7d31ca2bc398d530d5a90902d8.1532421340.git.nelio.laranjeiro@6wind.com> In-Reply-To: <262388487b03db7d31ca2bc398d530d5a90902d8.1532421340.git.nelio.laranjeiro@6wind.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: [193.47.165.251] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; DB7PR05MB4444; 6:eB6tz8u0WztOfrDuwJIy37uDDRncfbJmgX7Xqz6dFCX6uPhAkFoA0JisxIn/v5eW+lIsIZqaUnkjcF8ZYXgShDsi3RIz7OWvhlCiSZgZHtSx0A0BN5mCadPZgjkGt0pd7PMHN67uvQ2n+g+Qol/UovuvaNqs3FhHXvPIeB2rOv0sbhDrCTBIR7xXeUs6tS57lJAXFO9U05nldvGlcLgCXykzrVDpbX9/+m5aZNM831xjWwHsoLYTygS1RAPOrFsjHWL+K8Mj2yhecU8Sub9m/Mupp61eTtbrCQz6lMm5U63I1warw39N++Put41XZMzFVMIqckG1uyePRfaH1CT8XeO6TT88b8zIMGvDcgzLVjJLvlOO+8bgJq8IAoJvQd9DTDgHb6aQnEvmE2vJA//VwPEzFS/n5gxXsU1baOkVAxlCr8ggZTSjKE1KYIu76r1vdrnv5Am0soKvPj4fm3kMYg==; 5:zgTj7q8aTnVfYRAiPdSrU1woMzD67LUJJRC9j4FDQtct8wiRFQ19J0OX/laWI4LY1GagFEb0H5VTDUgHOH1Q3CE/I4bwJYy6S5sYBj8qbMVFGav0EHzpzZLl8Kjk7h83ftJQCwBv/efnHlkiCcwl70I58n8Sm6apOe8l+FKMaq4=; 7:ayE5eOOlPjdzahsIJnqu6qi3EVtPczf9UX5K3zaUD8nmtQM/Z6t4Xprv22F0qEZ9A32UXQPt3fg2Ey8NWvnRgR+3R7Fool/eEXEt4N8PEcpk02ulRGnzjQyrzITw7NKg0RveH7nCCXpEDE9NUoqaE/s34cM+GPAl0bak7G1MGuLdwx6XtJy5E6jSMgN/KQkASloHBx8K85ugQqcMORZRL8oopen50qzOvKHGcAz6pnSV+2S7edV00Dh+kmt94ujs x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 00daa3f5-43f7-435c-d1d0-08d5f16c0246 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(5600073)(711020)(4618075)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020); SRVR:DB7PR05MB4444; x-ms-traffictypediagnostic: DB7PR05MB4444: 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)(5005006)(8121501046)(3002001)(10201501046)(93006095)(93001095)(3231311)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:DB7PR05MB4444; BCL:0; PCL:0; RULEID:; SRVR:DB7PR05MB4444; x-forefront-prvs: 0743E8D0A6 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(366004)(136003)(39860400002)(346002)(376002)(189003)(199004)(81166006)(186003)(8936002)(6246003)(8676002)(99286004)(2900100001)(11346002)(446003)(53936002)(81156014)(107886003)(33656002)(6116002)(3846002)(14454004)(6636002)(2906002)(55016002)(7696005)(229853002)(5250100002)(316002)(2501003)(74316002)(478600001)(6436002)(4326008)(97736004)(102836004)(106356001)(256004)(14444005)(486006)(7736002)(26005)(105586002)(66066001)(476003)(110136005)(9686003)(6506007)(68736007)(86362001)(76176011)(305945005)(575784001)(54906003)(5660300001)(25786009); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR05MB4444; 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: dHqRZ13dvc+K0sStU2kWUweNEv9oeLR5VPdl9e5HgLTkLzSm86mew+do36tZUKKUjBcuaMME85b0GvMPOfl8rEjiUjdRabo6RS0tdeKpfDX/a8w8LnrYmLFSA+sij80SCuKXOy6rWgMK5c/0bH6zuTWzMq9sGRDAB4UnMduZEWk5ffFfmYWtjqj/yC/hUaH2o32spRIC4Y63Zd52z6k8uBdljwi8YwuAs1qKBRUsAwk8KVd6cgVTloRwfqwTXTsa3bZKoiSz5a0GmI6isPXngwm52K5JNe82eu5KxeYZdnhnifPuGyqJbWzFnhwHz2lCfLjvSt1W4DtR+GZguj9jeKBCTB9fXfc99wu54X2Y3Pw= 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: 00daa3f5-43f7-435c-d1d0-08d5f16c0246 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jul 2018 13:47:33.9282 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR05MB4444 Subject: Re: [dpdk-dev] [PATCH v2] 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: Tue, 24 Jul 2018 13:47:36 -0000 Tuesday, July 24, 2018 11:37 AM, Nelio Laranjeiro: > Subject: [PATCH v2] 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 >=20 Applied to next-net-mlx, thanks.=20 > --- >=20 > Changes in v2: >=20 > On some distribution, the PF may not be able to open the sysfs file, such > issue should not be handled as an error. > --- > 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 > 78a69228e..a1c0ad70a 100644 > --- a/drivers/net/mlx5/mlx5.c > +++ b/drivers/net/mlx5/mlx5.c > @@ -1330,7 +1330,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,= @@ > -1349,7 +1350,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))) { > 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 > db8a5fa01..a7f50b31f 100644 > --- a/drivers/net/mlx5/mlx5.h > +++ b/drivers/net/mlx5/mlx5.h > @@ -273,6 +273,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 9cf2dc5f1..4a24f8021 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 =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 NULL) { > + 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) { > + rte_errno =3D errno; > + return -rte_errno; > + } > + 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; > +} > -- > 2.18.0