From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130044.outbound.protection.outlook.com [40.107.13.44]) by dpdk.org (Postfix) with ESMTP id 571CB152A for ; Mon, 18 Mar 2019 07:29:20 +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=u1fp5EqId3MWR8/m+Gdl40eUkZKrEmH1rUx2Wf8UnzY=; b=PWBecsnrwI6JBKe6ylDs181rGolRs9p/HipLY76A7ej7AtAPUr/iT796ucwABqND4xIKmc0VbzFk90RkCbznO7JR78XF/YJkSygTRL3Paqo+BHAKHXyLxonwhKMAWKOC6oBEFnF3JAE7VYAJigXsc74v4dnp3TooMd7Kdcp0lWE= Received: from AM4PR05MB3265.eurprd05.prod.outlook.com (10.171.188.154) by AM4PR05MB3281.eurprd05.prod.outlook.com (10.171.188.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.13; Mon, 18 Mar 2019 06:29:19 +0000 Received: from AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::11b0:de86:8d93:8b02]) by AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::11b0:de86:8d93:8b02%3]) with mapi id 15.20.1709.015; Mon, 18 Mar 2019 06:29:18 +0000 From: Slava Ovsiienko To: Dekel Peled , Yongseok Koh , Shahaf Shuler CC: "dev@dpdk.org" , Ori Kam , Dekel Peled Thread-Topic: [dpdk-dev] [PATCH v5] net/mlx5: support new representor naming format Thread-Index: AQHU3IoN2ybFBCWcKUOCWk/QUUnRTKYQ7rOg Date: Mon, 18 Mar 2019 06:29:18 +0000 Message-ID: References: <1552234001-49438-1-git-send-email-dekelp@mellanox.com> <1552803783-55056-1-git-send-email-dekelp@mellanox.com> In-Reply-To: <1552803783-55056-1-git-send-email-dekelp@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=viacheslavo@mellanox.com; x-originating-ip: [95.67.35.250] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b1720228-9319-494e-7c15-08d6ab6b0cf3 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:AM4PR05MB3281; x-ms-traffictypediagnostic: AM4PR05MB3281: x-ms-exchange-purlcount: 2 x-microsoft-antispam-prvs: x-forefront-prvs: 098076C36C x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(396003)(136003)(39860400002)(346002)(366004)(13464003)(189003)(199004)(256004)(6436002)(55016002)(9686003)(6306002)(68736007)(81156014)(81166006)(45080400002)(6246003)(6636002)(106356001)(186003)(3846002)(229853002)(5660300002)(53936002)(6116002)(105586002)(66066001)(8936002)(52536014)(26005)(71200400001)(14444005)(110136005)(316002)(2906002)(71190400001)(54906003)(53546011)(6506007)(86362001)(102836004)(486006)(11346002)(446003)(14454004)(7696005)(97736004)(76176011)(305945005)(74316002)(25786009)(478600001)(4326008)(7736002)(476003)(99286004)(966005)(33656002)(107886003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB3281; H:AM4PR05MB3265.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-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: k61Jcn+kRA68+CVcsVEDCnlLgnWxTy3kzTwdEkYxAR9skZIzdyFVH5yaqvdJgI9A1FAkZkGFb+R4gFo3OWjyjAGzBopxsfiNSPedaMd/FX9L92wF5pSQnsWhK1PVZC9WN77zOhnVb7xaju7x7326vXGjmtI+3qp1I+mxnbQoXo1H2RxtMyjYgU5BOHpVHRao6g08oXaVkCuoca16rq7YEU37Ff56Qkq3Y4uInLM/qQwwl1+MfNhN9r23H53tccAwstKvR98ht1ZF9BSPp2iskvdzHiS8CkuZwK+lkqU08vmoVQDy6OcyrfaNX/b3Cuql4wVay0R08vzdqphivl7OWwUbcbwFWWWccDSG35UBJLcKgdIakWYPCZF8T6QPvlXdsT6t0bJFHzjDtxEQu+KiK4DRKe/uxtXnQiEeYvXYxhE= 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: b1720228-9319-494e-7c15-08d6ab6b0cf3 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Mar 2019 06:29:18.5266 (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: AM4PR05MB3281 Subject: Re: [dpdk-dev] [PATCH v5] net/mlx5: support new representor naming format 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: Mon, 18 Mar 2019 06:29:20 -0000 > -----Original Message----- > From: dev On Behalf Of Dekel Peled > Sent: Sunday, March 17, 2019 8:23 > To: Yongseok Koh ; Shahaf Shuler > > Cc: dev@dpdk.org; Ori Kam ; Dekel Peled > > Subject: [dpdk-dev] [PATCH v5] net/mlx5: support new representor naming > format >=20 > 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. >=20 > [1] > https://eur03.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fgithu= b > .com%2Ftorvalds%2Flinux%2Fcommit%2Fc12ecc2&data=3D02%7C01%7Cvi > acheslavo%40mellanox.com%7C17dec02b64014892fa4a08d6aaa12e04%7Ca > 652971c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C636884006586825444&a > mp;sdata=3DYFOOhRcJ2qb19nRUA9aRUqHP8HChHLX7VP1tlWZ5OLk%3D& > reserved=3D0 > [2] > https://eur03.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fmails.= d > pdk.org%2Farchives%2Fdev%2F2019- > March%2F125676.html&data=3D02%7C01%7Cviacheslavo%40mellanox.co > m%7C17dec02b64014892fa4a08d6aaa12e04%7Ca652971c7d2e4d9ba6a4d14 > 9256f461b%7C0%7C0%7C636884006586825444&sdata=3DEWWcj5GANyC > 5nKdNaCuqUeRZmXIEgH4HHRbc52h5cto%3D&reserved=3D0 >=20 > Signed-off-by: Dekel Peled >=20 Acked-by: Viacheslav Ovsiienko > --- > v5: Add flag to indicate if rep. port name is in new format. > v4: Remove redundant clear of errno. > v3: Add utility function with common logic, call it from sysfs and nl. > v2: Use public link to kernel patch, add link to RFC. > --- > --- > drivers/net/mlx5/mlx5.h | 3 +++ > drivers/net/mlx5/mlx5_ethdev.c | 54 > ++++++++++++++++++++++++++++++++++++++---- > drivers/net/mlx5/mlx5_nl.c | 11 ++++----- > 3 files changed, 57 insertions(+), 11 deletions(-) >=20 > diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index > 5384453..88ffb19 100644 > --- a/drivers/net/mlx5/mlx5.h > +++ b/drivers/net/mlx5/mlx5.h > @@ -60,6 +60,7 @@ enum { > struct mlx5_switch_info { > uint32_t master:1; /**< Master device. */ > uint32_t representor:1; /**< Representor device. */ > + uint32_t port_name_new:1; /**< Rep. port name is in new format. > */ > int32_t port_name; /**< Representor port name. */ > uint64_t switch_id; /**< Switch identifier. */ }; @@ -300,6 +301,8 > @@ unsigned int mlx5_dev_to_port_id(const struct rte_device *dev, > unsigned int port_list_n); > int mlx5_sysfs_switch_info(unsigned int ifindex, > struct mlx5_switch_info *info); > +bool mlx5_translate_port_name(const char *port_name_in, > + struct mlx5_switch_info *port_info_out); >=20 > /* mlx5_mac.c */ >=20 > diff --git a/drivers/net/mlx5/mlx5_ethdev.c > b/drivers/net/mlx5/mlx5_ethdev.c index 795c9c7..428a465 100644 > --- a/drivers/net/mlx5/mlx5_ethdev.c > +++ b/drivers/net/mlx5/mlx5_ethdev.c > @@ -1353,9 +1353,16 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, > char *fw_ver, size_t fw_size) mlx5_sysfs_switch_info(unsigned int ifinde= x, > struct mlx5_switch_info *info) { > char ifname[IF_NAMESIZE]; > + char port_name[IF_NAMESIZE]; > FILE *file; > DIR *dir; > - struct mlx5_switch_info data =3D { .master =3D 0, }; > + struct mlx5_switch_info data =3D { > + .master =3D 0, > + .representor =3D 0, > + .port_name_new =3D 0, > + .port_name =3D 0, > + .switch_id =3D 0, > + }; > bool port_name_set =3D false; > bool port_switch_id_set =3D false; > bool device_dir =3D false; > @@ -1375,10 +1382,9 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, > char *fw_ver, size_t fw_size) >=20 > 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'; > + fscanf(file, "%s", port_name); > fclose(file); > + port_name_set =3D mlx5_translate_port_name(port_name, > &data); > } > file =3D fopen(phys_switch_id, "rb"); > if (file =3D=3D NULL) { > @@ -1399,3 +1405,43 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, > char *fw_ver, size_t fw_size) > *info =3D 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 =3D false; > + > + /* > + * Check for port-name as a string of the form pf0vf0 > + * (support kernel ver >=3D 5.0) > + */ > + port_name_set =3D (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) =3D=3D 6); > + if (port_name_set) { > + port_info_out->port_name_new =3D 1; > + } else { > + /* Check for port-name as a number (support kernel ver < > 5.0 */ > + errno =3D 0; > + port_info_out->port_name =3D strtol(port_name_in, &end, 0); > + if (!errno && > + (size_t)(end - port_name_in) =3D=3D strlen(port_name_in)) > + port_name_set =3D true; > + } > + return port_name_set; > +} > diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c inde= x > 0bf6845..cb34de3 100644 > --- a/drivers/net/mlx5/mlx5_nl.c > +++ b/drivers/net/mlx5/mlx5_nl.c > @@ -836,6 +836,7 @@ struct mlx5_nl_ifindex_data { > struct mlx5_switch_info info =3D { > .master =3D 0, > .representor =3D 0, > + .port_name_new =3D 0, > .port_name =3D 0, > .switch_id =3D 0, > }; > @@ -849,7 +850,6 @@ struct mlx5_nl_ifindex_data { > while (off < nh->nlmsg_len) { > struct rtattr *ra =3D (void *)((uintptr_t)nh + off); > void *payload =3D RTA_DATA(ra); > - char *end; > unsigned int i; >=20 > if (ra->rta_len > nh->nlmsg_len - off) @@ -859,12 +859,9 @@ > struct mlx5_nl_ifindex_data { > num_vf_set =3D true; > break; > case IFLA_PHYS_PORT_NAME: > - errno =3D 0; > - info.port_name =3D strtol(payload, &end, 0); > - if (errno || > - (size_t)(end - (char *)payload) !=3D strlen(payload)) > - goto error; > - port_name_set =3D true; > + port_name_set =3D > + mlx5_translate_port_name((char *)payload, > + &info); > break; > case IFLA_PHYS_SWITCH_ID: > info.switch_id =3D 0; > -- > 1.8.3.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id A5F04A00E6 for ; Mon, 18 Mar 2019 07:29:22 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 8106D1DBD; Mon, 18 Mar 2019 07:29:21 +0100 (CET) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130044.outbound.protection.outlook.com [40.107.13.44]) by dpdk.org (Postfix) with ESMTP id 571CB152A for ; Mon, 18 Mar 2019 07:29:20 +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=u1fp5EqId3MWR8/m+Gdl40eUkZKrEmH1rUx2Wf8UnzY=; b=PWBecsnrwI6JBKe6ylDs181rGolRs9p/HipLY76A7ej7AtAPUr/iT796ucwABqND4xIKmc0VbzFk90RkCbznO7JR78XF/YJkSygTRL3Paqo+BHAKHXyLxonwhKMAWKOC6oBEFnF3JAE7VYAJigXsc74v4dnp3TooMd7Kdcp0lWE= Received: from AM4PR05MB3265.eurprd05.prod.outlook.com (10.171.188.154) by AM4PR05MB3281.eurprd05.prod.outlook.com (10.171.188.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.13; Mon, 18 Mar 2019 06:29:19 +0000 Received: from AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::11b0:de86:8d93:8b02]) by AM4PR05MB3265.eurprd05.prod.outlook.com ([fe80::11b0:de86:8d93:8b02%3]) with mapi id 15.20.1709.015; Mon, 18 Mar 2019 06:29:18 +0000 From: Slava Ovsiienko To: Dekel Peled , Yongseok Koh , Shahaf Shuler CC: "dev@dpdk.org" , Ori Kam , Dekel Peled Thread-Topic: [dpdk-dev] [PATCH v5] net/mlx5: support new representor naming format Thread-Index: AQHU3IoN2ybFBCWcKUOCWk/QUUnRTKYQ7rOg Date: Mon, 18 Mar 2019 06:29:18 +0000 Message-ID: References: <1552234001-49438-1-git-send-email-dekelp@mellanox.com> <1552803783-55056-1-git-send-email-dekelp@mellanox.com> In-Reply-To: <1552803783-55056-1-git-send-email-dekelp@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=viacheslavo@mellanox.com; x-originating-ip: [95.67.35.250] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b1720228-9319-494e-7c15-08d6ab6b0cf3 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:AM4PR05MB3281; x-ms-traffictypediagnostic: AM4PR05MB3281: x-ms-exchange-purlcount: 2 x-microsoft-antispam-prvs: x-forefront-prvs: 098076C36C x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(396003)(136003)(39860400002)(346002)(366004)(13464003)(189003)(199004)(256004)(6436002)(55016002)(9686003)(6306002)(68736007)(81156014)(81166006)(45080400002)(6246003)(6636002)(106356001)(186003)(3846002)(229853002)(5660300002)(53936002)(6116002)(105586002)(66066001)(8936002)(52536014)(26005)(71200400001)(14444005)(110136005)(316002)(2906002)(71190400001)(54906003)(53546011)(6506007)(86362001)(102836004)(486006)(11346002)(446003)(14454004)(7696005)(97736004)(76176011)(305945005)(74316002)(25786009)(478600001)(4326008)(7736002)(476003)(99286004)(966005)(33656002)(107886003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM4PR05MB3281; H:AM4PR05MB3265.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-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: k61Jcn+kRA68+CVcsVEDCnlLgnWxTy3kzTwdEkYxAR9skZIzdyFVH5yaqvdJgI9A1FAkZkGFb+R4gFo3OWjyjAGzBopxsfiNSPedaMd/FX9L92wF5pSQnsWhK1PVZC9WN77zOhnVb7xaju7x7326vXGjmtI+3qp1I+mxnbQoXo1H2RxtMyjYgU5BOHpVHRao6g08oXaVkCuoca16rq7YEU37Ff56Qkq3Y4uInLM/qQwwl1+MfNhN9r23H53tccAwstKvR98ht1ZF9BSPp2iskvdzHiS8CkuZwK+lkqU08vmoVQDy6OcyrfaNX/b3Cuql4wVay0R08vzdqphivl7OWwUbcbwFWWWccDSG35UBJLcKgdIakWYPCZF8T6QPvlXdsT6t0bJFHzjDtxEQu+KiK4DRKe/uxtXnQiEeYvXYxhE= 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: b1720228-9319-494e-7c15-08d6ab6b0cf3 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Mar 2019 06:29:18.5266 (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: AM4PR05MB3281 Subject: Re: [dpdk-dev] [PATCH v5] net/mlx5: support new representor naming format 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Message-ID: <20190318062918._Ne5U1G5HUgS6zEJftcrTeEnyVm8j1n5R-mGXB6ZlJs@z> > -----Original Message----- > From: dev On Behalf Of Dekel Peled > Sent: Sunday, March 17, 2019 8:23 > To: Yongseok Koh ; Shahaf Shuler > > Cc: dev@dpdk.org; Ori Kam ; Dekel Peled > > Subject: [dpdk-dev] [PATCH v5] net/mlx5: support new representor naming > format >=20 > 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. >=20 > [1] > https://eur03.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fgithu= b > .com%2Ftorvalds%2Flinux%2Fcommit%2Fc12ecc2&data=3D02%7C01%7Cvi > acheslavo%40mellanox.com%7C17dec02b64014892fa4a08d6aaa12e04%7Ca > 652971c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C636884006586825444&a > mp;sdata=3DYFOOhRcJ2qb19nRUA9aRUqHP8HChHLX7VP1tlWZ5OLk%3D& > reserved=3D0 > [2] > https://eur03.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fmails.= d > pdk.org%2Farchives%2Fdev%2F2019- > March%2F125676.html&data=3D02%7C01%7Cviacheslavo%40mellanox.co > m%7C17dec02b64014892fa4a08d6aaa12e04%7Ca652971c7d2e4d9ba6a4d14 > 9256f461b%7C0%7C0%7C636884006586825444&sdata=3DEWWcj5GANyC > 5nKdNaCuqUeRZmXIEgH4HHRbc52h5cto%3D&reserved=3D0 >=20 > Signed-off-by: Dekel Peled >=20 Acked-by: Viacheslav Ovsiienko > --- > v5: Add flag to indicate if rep. port name is in new format. > v4: Remove redundant clear of errno. > v3: Add utility function with common logic, call it from sysfs and nl. > v2: Use public link to kernel patch, add link to RFC. > --- > --- > drivers/net/mlx5/mlx5.h | 3 +++ > drivers/net/mlx5/mlx5_ethdev.c | 54 > ++++++++++++++++++++++++++++++++++++++---- > drivers/net/mlx5/mlx5_nl.c | 11 ++++----- > 3 files changed, 57 insertions(+), 11 deletions(-) >=20 > diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index > 5384453..88ffb19 100644 > --- a/drivers/net/mlx5/mlx5.h > +++ b/drivers/net/mlx5/mlx5.h > @@ -60,6 +60,7 @@ enum { > struct mlx5_switch_info { > uint32_t master:1; /**< Master device. */ > uint32_t representor:1; /**< Representor device. */ > + uint32_t port_name_new:1; /**< Rep. port name is in new format. > */ > int32_t port_name; /**< Representor port name. */ > uint64_t switch_id; /**< Switch identifier. */ }; @@ -300,6 +301,8 > @@ unsigned int mlx5_dev_to_port_id(const struct rte_device *dev, > unsigned int port_list_n); > int mlx5_sysfs_switch_info(unsigned int ifindex, > struct mlx5_switch_info *info); > +bool mlx5_translate_port_name(const char *port_name_in, > + struct mlx5_switch_info *port_info_out); >=20 > /* mlx5_mac.c */ >=20 > diff --git a/drivers/net/mlx5/mlx5_ethdev.c > b/drivers/net/mlx5/mlx5_ethdev.c index 795c9c7..428a465 100644 > --- a/drivers/net/mlx5/mlx5_ethdev.c > +++ b/drivers/net/mlx5/mlx5_ethdev.c > @@ -1353,9 +1353,16 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, > char *fw_ver, size_t fw_size) mlx5_sysfs_switch_info(unsigned int ifinde= x, > struct mlx5_switch_info *info) { > char ifname[IF_NAMESIZE]; > + char port_name[IF_NAMESIZE]; > FILE *file; > DIR *dir; > - struct mlx5_switch_info data =3D { .master =3D 0, }; > + struct mlx5_switch_info data =3D { > + .master =3D 0, > + .representor =3D 0, > + .port_name_new =3D 0, > + .port_name =3D 0, > + .switch_id =3D 0, > + }; > bool port_name_set =3D false; > bool port_switch_id_set =3D false; > bool device_dir =3D false; > @@ -1375,10 +1382,9 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, > char *fw_ver, size_t fw_size) >=20 > 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'; > + fscanf(file, "%s", port_name); > fclose(file); > + port_name_set =3D mlx5_translate_port_name(port_name, > &data); > } > file =3D fopen(phys_switch_id, "rb"); > if (file =3D=3D NULL) { > @@ -1399,3 +1405,43 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, > char *fw_ver, size_t fw_size) > *info =3D 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 =3D false; > + > + /* > + * Check for port-name as a string of the form pf0vf0 > + * (support kernel ver >=3D 5.0) > + */ > + port_name_set =3D (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) =3D=3D 6); > + if (port_name_set) { > + port_info_out->port_name_new =3D 1; > + } else { > + /* Check for port-name as a number (support kernel ver < > 5.0 */ > + errno =3D 0; > + port_info_out->port_name =3D strtol(port_name_in, &end, 0); > + if (!errno && > + (size_t)(end - port_name_in) =3D=3D strlen(port_name_in)) > + port_name_set =3D true; > + } > + return port_name_set; > +} > diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c inde= x > 0bf6845..cb34de3 100644 > --- a/drivers/net/mlx5/mlx5_nl.c > +++ b/drivers/net/mlx5/mlx5_nl.c > @@ -836,6 +836,7 @@ struct mlx5_nl_ifindex_data { > struct mlx5_switch_info info =3D { > .master =3D 0, > .representor =3D 0, > + .port_name_new =3D 0, > .port_name =3D 0, > .switch_id =3D 0, > }; > @@ -849,7 +850,6 @@ struct mlx5_nl_ifindex_data { > while (off < nh->nlmsg_len) { > struct rtattr *ra =3D (void *)((uintptr_t)nh + off); > void *payload =3D RTA_DATA(ra); > - char *end; > unsigned int i; >=20 > if (ra->rta_len > nh->nlmsg_len - off) @@ -859,12 +859,9 @@ > struct mlx5_nl_ifindex_data { > num_vf_set =3D true; > break; > case IFLA_PHYS_PORT_NAME: > - errno =3D 0; > - info.port_name =3D strtol(payload, &end, 0); > - if (errno || > - (size_t)(end - (char *)payload) !=3D strlen(payload)) > - goto error; > - port_name_set =3D true; > + port_name_set =3D > + mlx5_translate_port_name((char *)payload, > + &info); > break; > case IFLA_PHYS_SWITCH_ID: > info.switch_id =3D 0; > -- > 1.8.3.1