From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140048.outbound.protection.outlook.com [40.107.14.48]) by dpdk.org (Postfix) with ESMTP id 8890A3256 for ; Thu, 18 Apr 2019 16:26:46 +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=MPK1M+3EXK33IMFy+f5VYWIqi17tT+vpF3FNemsoXhY=; b=m6KyOo8Jst16VvJM16JEN1woIgBE73qYnsouK3bDTy6uqCM1sXtiipJTN3Ht91dmYEFXiQPV3mTrV6QRAbf9m2JAV4ZUpHR/EAjS/sxIM6Tra26lowKIi/hg81vCBOtNWvhxeVzpBW4nYYk8aq9JnkfKVdunozMwRV2sSdmsk68= Received: from VI1PR05MB4224.eurprd05.prod.outlook.com (52.133.12.13) by VI1PR05MB5550.eurprd05.prod.outlook.com (20.177.201.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1813.12; Thu, 18 Apr 2019 14:26:44 +0000 Received: from VI1PR05MB4224.eurprd05.prod.outlook.com ([fe80::a511:20b2:5fb2:3a5d]) by VI1PR05MB4224.eurprd05.prod.outlook.com ([fe80::a511:20b2:5fb2:3a5d%2]) with mapi id 15.20.1792.022; Thu, 18 Apr 2019 14:26:44 +0000 From: Dekel Peled To: Slava Ovsiienko CC: "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v2] net/mlx5: add support for PF representor Thread-Index: AQHU9F41k7R4uelDeUGasQxN6wBp76ZB+lJw Date: Thu, 18 Apr 2019 14:26:43 +0000 Message-ID: References: <1555084107-24692-1-git-send-email-viacheslavo@mellanox.com> <1555423828-31859-1-git-send-email-viacheslavo@mellanox.com> In-Reply-To: <1555423828-31859-1-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=dekelp@mellanox.com; x-originating-ip: [193.47.165.251] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1209386f-4acf-4cfe-3db2-08d6c409e1c9 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VI1PR05MB5550; x-ms-traffictypediagnostic: VI1PR05MB5550: x-ms-exchange-purlcount: 3 x-microsoft-antispam-prvs: x-forefront-prvs: 0011612A55 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(376002)(346002)(136003)(39860400002)(366004)(199004)(189003)(13464003)(14454004)(9686003)(6862004)(53936002)(99286004)(81166006)(81156014)(446003)(11346002)(68736007)(33656002)(6246003)(6116002)(26005)(3846002)(97736004)(186003)(305945005)(55016002)(76176011)(8936002)(478600001)(966005)(45080400002)(7736002)(74316002)(2906002)(4326008)(5660300002)(86362001)(229853002)(6436002)(6306002)(5024004)(6506007)(256004)(52536014)(316002)(102836004)(66066001)(53546011)(25786009)(6636002)(8676002)(7696005)(476003)(486006)(71200400001)(71190400001)(30864003); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR05MB5550; H:VI1PR05MB4224.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX: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: rEOyZ0crfd4v8XZy8FZU1h7w/eli1m/qolvXnoc8Bc+ZzbW16QefoCKPsdMsXNpHkaLz4H3ZrsR4S3nLdGFaFpUIZ5Qgw28A4HuygsGDBKm29w7ODAvgW/w7QrqUAZ0Hm+lTmCIxf/U5ETz/ASnfdt54gAjIefv8NTwvi0TmkndwRpOcW/khajfgdOVNZxC+ACMXu9qcR/3p2WBvOwXNs7lSMAPMcU2zwbnBataztlomn7lLEqtQmC93BaZfGWIdxU2vc04yzGpwuL75tkf4fVzKY83iItCY669IpQawMB3PFY/aS5F1pectku6eioO0xqHnJjuYu6qSBd850CQ8fZod0iaNDvAC+NUkPU6X9TReqQzxWpmE2PGMf8QyglSWSrbQJ4DZG0Ew6O2Leu0ttAAoHYHA3rDMrgZaqCWAN/M= 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: 1209386f-4acf-4cfe-3db2-08d6c409e1c9 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Apr 2019 14:26:43.9904 (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: VI1PR05MB5550 Subject: Re: [dpdk-dev] [PATCH v2] net/mlx5: add support for PF representor 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: Thu, 18 Apr 2019 14:26:46 -0000 PSB minor comments. > -----Original Message----- > From: dev On Behalf Of Viacheslav Ovsiienko > Sent: Tuesday, April 16, 2019 5:10 PM > To: dev@dpdk.org > Cc: Shahaf Shuler > Subject: [dpdk-dev] [PATCH v2] net/mlx5: add support for PF representor >=20 > On BlueField platform we have the new entity - PF representor. > This one represents the PCI PF attached to external host on the side of A= RM. > The traffic sent by the external host to the NIC via PF will be seem by A= RM on > this PF representor. >=20 > This patch refactors port recognizing capability on the base of physical = port > name. We have two groups of name formats. Legacy name formats are > supported by kernels before ver 5.0 (being more precise - before the patc= h > [1]) or before Mellanox OFED 4.6, and new naming formats added by the > patch [1]. >=20 > Legacy naming formats are supported: >=20 > - missing physical port name (no sysfs/netlink key) at all, > master is assumed >=20 > - decimal digits (for example "12"), representor is assumed, > the value is the index of attached VF >=20 > New naming formats are supported: >=20 > - "p" followed by decimal digits, for example "p2", master > is assumed >=20 > - "pf" followed by PF index concatenated with "vf" followed by > VF index, for example "pf0vf1", representor is assumed. > If index of VF is "-1" it is a special case of host PF > representor, this representor must be indexed in devargs > as 65535, for example representor=3D[0-3,65535] will > allow representors for VF0, VF1, VF2, VF3 and for host PF. >=20 > Note: do not specify representor=3D[0-65535], it causes devargs > processing error, because number of ports (rte_eth_dev) is > limited. >=20 > Applications should distinguish representors and master devices exclusive= ly > by device flag RTE_ETH_DEV_REPRESENTOR and do not rely on switch > port_id (mlx5 PMD deduces ones from representor_id) values returned by > dev_infos_get() API. >=20 > [1] > https://eur03.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fwww > .spinics.net%2Flists%2Fnetdev%2Fmsg547007.html&data=3D02%7C01%7C > dekelp%40mellanox.com%7C1bb595beee23451f97ec08d6c275566b%7Ca6529 > 71c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C636910206560409734&sd > ata=3DhdO9GhbFdoVt4pQND5ROXhTeDBhVhrNA1HyQbchsgvg%3D&rese > rved=3D0 > Linux-tree: c12ecc23 (Or Gerlitz 2018-04-25 17:32 +0300) > "net/mlx5e: Move to use common phys port names for vport > representors" >=20 I suggest to use this link instead: https://github.com/torvalds/linux/commit/c12ecc2 > Signed-off-by: Viacheslav Ovsiienko >=20 > --- > v2: - clarified commit log message > - separated port attributes analyzing routines > - port name format related routines are gathered together >=20 > v1: > https://eur03.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fpatch > es.dpdk.org%2Fpatch%2F52725%2F&data=3D02%7C01%7Cdekelp%40mell > anox.com%7C1bb595beee23451f97ec08d6c275566b%7Ca652971c7d2e4d9ba6 > a4d149256f461b%7C0%7C0%7C636910206560409734&sdata=3DpB9vIdQ4s > VzLcKNL0flg8SnDP%2F%2BtisSJVCbj1RkkPwg%3D&reserved=3D0 >=20 > drivers/net/mlx5/mlx5.h | 18 ++++- > drivers/net/mlx5/mlx5_ethdev.c | 163 > ++++++++++++++++++++++++++++++++++------- > drivers/net/mlx5/mlx5_nl.c | 20 +---- > 3 files changed, 158 insertions(+), 43 deletions(-) >=20 > diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index > 14c7f3c..2069fad 100644 > --- a/drivers/net/mlx5/mlx5.h > +++ b/drivers/net/mlx5/mlx5.h > @@ -80,11 +80,21 @@ struct mlx5_mp_param { > /** Key string for IPC. */ > #define MLX5_MP_NAME "net_mlx5_mp" >=20 > +/* Recognized Infiniband device physical port name types. */ enum > +mlx5_phys_port_name_type { > + MLX5_PHYS_PORT_NAME_TYPE_NOTSET =3D 0, /* Not set. */ > + MLX5_PHYS_PORT_NAME_TYPE_LEGACY, /* before kernel ver < 5.0 > */ > + MLX5_PHYS_PORT_NAME_TYPE_UPLINK, /* p0, kernel ver >=3D 5.0 */ > + MLX5_PHYS_PORT_NAME_TYPE_PFVF, /* pf0vf0, kernel ver >=3D 5.0 > */ > + MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN, /* Unrecognized. */ }; > + > /** Switch information returned by mlx5_nl_switch_info(). */ 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. > */ > + enum mlx5_phys_port_name_type name_type; /** < Port name > type. */ > + int32_t pf_num; /**< PF number (valid for pfxvfx format only). */ > int32_t port_name; /**< Representor port name. */ > uint64_t switch_id; /**< Switch identifier. */ }; @@ -404,7 +414,11 > @@ 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, > +void mlx5_sysfs_check_switch_info(bool device_dir, > + struct mlx5_switch_info *switch_info); void > +mlx5_nl_check_switch_info(bool nun_vf_set, > + struct mlx5_switch_info *switch_info); void > +mlx5_translate_port_name(const char *port_name_in, > struct mlx5_switch_info *port_info_out); >=20 > /* mlx5_mac.c */ > diff --git a/drivers/net/mlx5/mlx5_ethdev.c > b/drivers/net/mlx5/mlx5_ethdev.c index 3992918..9c24462 100644 > --- a/drivers/net/mlx5/mlx5_ethdev.c > +++ b/drivers/net/mlx5/mlx5_ethdev.c > @@ -1395,12 +1395,11 @@ int mlx5_fw_version_get(struct rte_eth_dev > *dev, char *fw_ver, size_t fw_size) > struct mlx5_switch_info data =3D { > .master =3D 0, > .representor =3D 0, > - .port_name_new =3D 0, > + .name_type =3D MLX5_PHYS_PORT_NAME_TYPE_NOTSET, > .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; > @@ -1423,8 +1422,7 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, > char *fw_ver, size_t fw_size) > ret =3D fscanf(file, "%s", port_name); > fclose(file); > if (ret =3D=3D 1) > - port_name_set =3D > mlx5_translate_port_name(port_name, > - &data); > + mlx5_translate_port_name(port_name, &data); > } > file =3D fopen(phys_switch_id, "rb"); > if (file =3D=3D NULL) { > @@ -1440,8 +1438,10 @@ int mlx5_fw_version_get(struct rte_eth_dev > *dev, char *fw_ver, size_t fw_size) > 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; > + if (port_switch_id_set) { > + /* We have some E-Switch configuration. */ > + mlx5_sysfs_check_switch_info(device_dir, &data); > + } > *info =3D data; > assert(!(data.master && data.representor)); > if (data.master && data.representor) { @@ -1454,41 +1454,154 @@ > int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t > fw_size) } >=20 > /** > + * Analyze gathered port parameters via Netlink to recognize master > + * and representor devices for E-Switch configuration. > + * > + * @param[in] num_vf_set > + * flag of presence of number of VFs port attribute. > + * @param[inout] switch_info > + * Port information, including port name as a number and port name > + * type if recognized > + * > + * @return > + * master and representor flags are set in switch_info according to > + * recognized parameters (if any). > + */ > +void > +mlx5_nl_check_switch_info(bool num_vf_set, > + struct mlx5_switch_info *switch_info) { > + switch (switch_info->name_type) { > + case MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN: > + /* > + * Name is not recognized, assume the master, > + * check the number of VFs key presence. > + */ > + switch_info->master =3D num_vf_set; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_NOTSET: > + /* > + * Name is not set, this assumes the legacy naming > + * schema for master, just check if there is a > + * number of VFs key. > + */ > + switch_info->master =3D num_vf_set; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_UPLINK: > + /* New uplink naming schema recognized. */ > + switch_info->master =3D 1; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_LEGACY: > + /* Legacy representors naming schema. */ > + switch_info->representor =3D !num_vf_set; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_PFVF: > + /* New representors naming schema. */ > + switch_info->representor =3D 1; > + break; Suggest to add default for clarity. > + } > +} > + > +/** > + * Analyze gathered port parameters via sysfs to recognize master > + * and representor devices for E-Switch configuration. > + * > + * @param[in] device_dir > + * flag of presence of "device" directory under port device key. > + * @param[inout] switch_info > + * Port information, including port name as a number and port name > + * type if recognized > + * > + * @return > + * master and representor flags are set in switch_info according to > + * recognized parameters (if any). > + */ > +void > +mlx5_sysfs_check_switch_info(bool device_dir, > + struct mlx5_switch_info *switch_info) { > + switch (switch_info->name_type) { > + case MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN: > + /* > + * Name is not recognized, assume the master, > + * check the device directory presence. > + */ > + switch_info->master =3D device_dir; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_NOTSET: > + /* > + * Name is not set, this assumes the legacy naming > + * schema for master, just check if there is > + * a device directory. > + */ > + switch_info->master =3D device_dir; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_UPLINK: > + /* New uplink naming schema recognized. */ > + switch_info->master =3D 1; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_LEGACY: > + /* Legacy representors naming schema. */ > + switch_info->representor =3D !device_dir; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_PFVF: > + /* New representors naming schema. */ > + switch_info->representor =3D 1; > + break; Suggest to add default for clarity. > + } > +} > + > +/** > * 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. > + * Port information, including port name as a number and port name > + * type if recognized > * > * @return > - * true on success, false otherwise. > + * port_name field set according to recognized name format. > */ > -bool > +void > 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; > + int sc_items; >=20 > /* > * Check for port-name as a string of the form pf0vf0 > - * (support kernel ver >=3D 5.0) > + * (support kernel ver >=3D 5.0 or OFED ver >=3D 4.6). > */ > - 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; > + sc_items =3D sscanf(port_name_in, "%c%c%d%c%c%d", > + &pf_c1, &pf_c2, &port_info_out->pf_num, > + &vf_c1, &vf_c2, &port_info_out->port_name); > + if (sc_items =3D=3D 6 && > + pf_c1 =3D=3D 'p' && pf_c2 =3D=3D 'f' && > + vf_c1 =3D=3D 'v' && vf_c2 =3D=3D 'f') { > + port_info_out->name_type =3D > MLX5_PHYS_PORT_NAME_TYPE_PFVF; > + return; > + } > + /* > + * Check for port-name as a string of the form p0 > + * (support kernel ver >=3D 5.0, or OFED ver >=3D 4.6). > + */ > + sc_items =3D sscanf(port_name_in, "%c%d", > + &pf_c1, &port_info_out->port_name); > + if (sc_items =3D=3D 2 && pf_c1 =3D=3D 'p') { > + port_info_out->name_type =3D > MLX5_PHYS_PORT_NAME_TYPE_UPLINK; > + return; > + } > + /* 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_info_out->name_type =3D > MLX5_PHYS_PORT_NAME_TYPE_LEGACY; > + return; > } > - return port_name_set; > + port_info_out->name_type =3D > MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN; > + return; > } > diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c inde= x > fd9226b..0ff9667 100644 > --- a/drivers/net/mlx5/mlx5_nl.c > +++ b/drivers/net/mlx5/mlx5_nl.c > @@ -887,12 +887,11 @@ struct mlx5_nl_ifindex_data { > struct mlx5_switch_info info =3D { > .master =3D 0, > .representor =3D 0, > - .port_name_new =3D 0, > + .name_type =3D MLX5_PHYS_PORT_NAME_TYPE_NOTSET, > .port_name =3D 0, > .switch_id =3D 0, > }; > 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 > @@ -910,9 +909,7 @@ struct mlx5_nl_ifindex_data { > num_vf_set =3D true; > break; > case IFLA_PHYS_PORT_NAME: > - port_name_set =3D > - mlx5_translate_port_name((char *)payload, > - &info); > + mlx5_translate_port_name((char *)payload, &info); > break; > case IFLA_PHYS_SWITCH_ID: > info.switch_id =3D 0; > @@ -926,17 +923,8 @@ struct mlx5_nl_ifindex_data { > off +=3D RTA_ALIGN(ra->rta_len); > } > 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; > - } > + /* We have some E-Switch configuration. */ > + mlx5_nl_check_switch_info(num_vf_set, &info); > } > assert(!(info.master && info.representor)); > memcpy(arg, &info, sizeof(info)); > -- > 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 3A5E3A00E6 for ; Thu, 18 Apr 2019 16:26:48 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E01261B120; Thu, 18 Apr 2019 16:26:47 +0200 (CEST) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140048.outbound.protection.outlook.com [40.107.14.48]) by dpdk.org (Postfix) with ESMTP id 8890A3256 for ; Thu, 18 Apr 2019 16:26:46 +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=MPK1M+3EXK33IMFy+f5VYWIqi17tT+vpF3FNemsoXhY=; b=m6KyOo8Jst16VvJM16JEN1woIgBE73qYnsouK3bDTy6uqCM1sXtiipJTN3Ht91dmYEFXiQPV3mTrV6QRAbf9m2JAV4ZUpHR/EAjS/sxIM6Tra26lowKIi/hg81vCBOtNWvhxeVzpBW4nYYk8aq9JnkfKVdunozMwRV2sSdmsk68= Received: from VI1PR05MB4224.eurprd05.prod.outlook.com (52.133.12.13) by VI1PR05MB5550.eurprd05.prod.outlook.com (20.177.201.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1813.12; Thu, 18 Apr 2019 14:26:44 +0000 Received: from VI1PR05MB4224.eurprd05.prod.outlook.com ([fe80::a511:20b2:5fb2:3a5d]) by VI1PR05MB4224.eurprd05.prod.outlook.com ([fe80::a511:20b2:5fb2:3a5d%2]) with mapi id 15.20.1792.022; Thu, 18 Apr 2019 14:26:44 +0000 From: Dekel Peled To: Slava Ovsiienko CC: "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH v2] net/mlx5: add support for PF representor Thread-Index: AQHU9F41k7R4uelDeUGasQxN6wBp76ZB+lJw Date: Thu, 18 Apr 2019 14:26:43 +0000 Message-ID: References: <1555084107-24692-1-git-send-email-viacheslavo@mellanox.com> <1555423828-31859-1-git-send-email-viacheslavo@mellanox.com> In-Reply-To: <1555423828-31859-1-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=dekelp@mellanox.com; x-originating-ip: [193.47.165.251] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 1209386f-4acf-4cfe-3db2-08d6c409e1c9 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VI1PR05MB5550; x-ms-traffictypediagnostic: VI1PR05MB5550: x-ms-exchange-purlcount: 3 x-microsoft-antispam-prvs: x-forefront-prvs: 0011612A55 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(376002)(346002)(136003)(39860400002)(366004)(199004)(189003)(13464003)(14454004)(9686003)(6862004)(53936002)(99286004)(81166006)(81156014)(446003)(11346002)(68736007)(33656002)(6246003)(6116002)(26005)(3846002)(97736004)(186003)(305945005)(55016002)(76176011)(8936002)(478600001)(966005)(45080400002)(7736002)(74316002)(2906002)(4326008)(5660300002)(86362001)(229853002)(6436002)(6306002)(5024004)(6506007)(256004)(52536014)(316002)(102836004)(66066001)(53546011)(25786009)(6636002)(8676002)(7696005)(476003)(486006)(71200400001)(71190400001)(30864003); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR05MB5550; H:VI1PR05MB4224.eurprd05.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX: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: rEOyZ0crfd4v8XZy8FZU1h7w/eli1m/qolvXnoc8Bc+ZzbW16QefoCKPsdMsXNpHkaLz4H3ZrsR4S3nLdGFaFpUIZ5Qgw28A4HuygsGDBKm29w7ODAvgW/w7QrqUAZ0Hm+lTmCIxf/U5ETz/ASnfdt54gAjIefv8NTwvi0TmkndwRpOcW/khajfgdOVNZxC+ACMXu9qcR/3p2WBvOwXNs7lSMAPMcU2zwbnBataztlomn7lLEqtQmC93BaZfGWIdxU2vc04yzGpwuL75tkf4fVzKY83iItCY669IpQawMB3PFY/aS5F1pectku6eioO0xqHnJjuYu6qSBd850CQ8fZod0iaNDvAC+NUkPU6X9TReqQzxWpmE2PGMf8QyglSWSrbQJ4DZG0Ew6O2Leu0ttAAoHYHA3rDMrgZaqCWAN/M= 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: 1209386f-4acf-4cfe-3db2-08d6c409e1c9 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Apr 2019 14:26:43.9904 (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: VI1PR05MB5550 Subject: Re: [dpdk-dev] [PATCH v2] net/mlx5: add support for PF representor 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: <20190418142643.5DAdvP-I2y07jxmkTOAErmMPUvgnyx3tj0uEg2tfr_4@z> PSB minor comments. > -----Original Message----- > From: dev On Behalf Of Viacheslav Ovsiienko > Sent: Tuesday, April 16, 2019 5:10 PM > To: dev@dpdk.org > Cc: Shahaf Shuler > Subject: [dpdk-dev] [PATCH v2] net/mlx5: add support for PF representor >=20 > On BlueField platform we have the new entity - PF representor. > This one represents the PCI PF attached to external host on the side of A= RM. > The traffic sent by the external host to the NIC via PF will be seem by A= RM on > this PF representor. >=20 > This patch refactors port recognizing capability on the base of physical = port > name. We have two groups of name formats. Legacy name formats are > supported by kernels before ver 5.0 (being more precise - before the patc= h > [1]) or before Mellanox OFED 4.6, and new naming formats added by the > patch [1]. >=20 > Legacy naming formats are supported: >=20 > - missing physical port name (no sysfs/netlink key) at all, > master is assumed >=20 > - decimal digits (for example "12"), representor is assumed, > the value is the index of attached VF >=20 > New naming formats are supported: >=20 > - "p" followed by decimal digits, for example "p2", master > is assumed >=20 > - "pf" followed by PF index concatenated with "vf" followed by > VF index, for example "pf0vf1", representor is assumed. > If index of VF is "-1" it is a special case of host PF > representor, this representor must be indexed in devargs > as 65535, for example representor=3D[0-3,65535] will > allow representors for VF0, VF1, VF2, VF3 and for host PF. >=20 > Note: do not specify representor=3D[0-65535], it causes devargs > processing error, because number of ports (rte_eth_dev) is > limited. >=20 > Applications should distinguish representors and master devices exclusive= ly > by device flag RTE_ETH_DEV_REPRESENTOR and do not rely on switch > port_id (mlx5 PMD deduces ones from representor_id) values returned by > dev_infos_get() API. >=20 > [1] > https://eur03.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fwww > .spinics.net%2Flists%2Fnetdev%2Fmsg547007.html&data=3D02%7C01%7C > dekelp%40mellanox.com%7C1bb595beee23451f97ec08d6c275566b%7Ca6529 > 71c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C636910206560409734&sd > ata=3DhdO9GhbFdoVt4pQND5ROXhTeDBhVhrNA1HyQbchsgvg%3D&rese > rved=3D0 > Linux-tree: c12ecc23 (Or Gerlitz 2018-04-25 17:32 +0300) > "net/mlx5e: Move to use common phys port names for vport > representors" >=20 I suggest to use this link instead: https://github.com/torvalds/linux/commit/c12ecc2 > Signed-off-by: Viacheslav Ovsiienko >=20 > --- > v2: - clarified commit log message > - separated port attributes analyzing routines > - port name format related routines are gathered together >=20 > v1: > https://eur03.safelinks.protection.outlook.com/?url=3Dhttp%3A%2F%2Fpatch > es.dpdk.org%2Fpatch%2F52725%2F&data=3D02%7C01%7Cdekelp%40mell > anox.com%7C1bb595beee23451f97ec08d6c275566b%7Ca652971c7d2e4d9ba6 > a4d149256f461b%7C0%7C0%7C636910206560409734&sdata=3DpB9vIdQ4s > VzLcKNL0flg8SnDP%2F%2BtisSJVCbj1RkkPwg%3D&reserved=3D0 >=20 > drivers/net/mlx5/mlx5.h | 18 ++++- > drivers/net/mlx5/mlx5_ethdev.c | 163 > ++++++++++++++++++++++++++++++++++------- > drivers/net/mlx5/mlx5_nl.c | 20 +---- > 3 files changed, 158 insertions(+), 43 deletions(-) >=20 > diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index > 14c7f3c..2069fad 100644 > --- a/drivers/net/mlx5/mlx5.h > +++ b/drivers/net/mlx5/mlx5.h > @@ -80,11 +80,21 @@ struct mlx5_mp_param { > /** Key string for IPC. */ > #define MLX5_MP_NAME "net_mlx5_mp" >=20 > +/* Recognized Infiniband device physical port name types. */ enum > +mlx5_phys_port_name_type { > + MLX5_PHYS_PORT_NAME_TYPE_NOTSET =3D 0, /* Not set. */ > + MLX5_PHYS_PORT_NAME_TYPE_LEGACY, /* before kernel ver < 5.0 > */ > + MLX5_PHYS_PORT_NAME_TYPE_UPLINK, /* p0, kernel ver >=3D 5.0 */ > + MLX5_PHYS_PORT_NAME_TYPE_PFVF, /* pf0vf0, kernel ver >=3D 5.0 > */ > + MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN, /* Unrecognized. */ }; > + > /** Switch information returned by mlx5_nl_switch_info(). */ 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. > */ > + enum mlx5_phys_port_name_type name_type; /** < Port name > type. */ > + int32_t pf_num; /**< PF number (valid for pfxvfx format only). */ > int32_t port_name; /**< Representor port name. */ > uint64_t switch_id; /**< Switch identifier. */ }; @@ -404,7 +414,11 > @@ 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, > +void mlx5_sysfs_check_switch_info(bool device_dir, > + struct mlx5_switch_info *switch_info); void > +mlx5_nl_check_switch_info(bool nun_vf_set, > + struct mlx5_switch_info *switch_info); void > +mlx5_translate_port_name(const char *port_name_in, > struct mlx5_switch_info *port_info_out); >=20 > /* mlx5_mac.c */ > diff --git a/drivers/net/mlx5/mlx5_ethdev.c > b/drivers/net/mlx5/mlx5_ethdev.c index 3992918..9c24462 100644 > --- a/drivers/net/mlx5/mlx5_ethdev.c > +++ b/drivers/net/mlx5/mlx5_ethdev.c > @@ -1395,12 +1395,11 @@ int mlx5_fw_version_get(struct rte_eth_dev > *dev, char *fw_ver, size_t fw_size) > struct mlx5_switch_info data =3D { > .master =3D 0, > .representor =3D 0, > - .port_name_new =3D 0, > + .name_type =3D MLX5_PHYS_PORT_NAME_TYPE_NOTSET, > .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; > @@ -1423,8 +1422,7 @@ int mlx5_fw_version_get(struct rte_eth_dev *dev, > char *fw_ver, size_t fw_size) > ret =3D fscanf(file, "%s", port_name); > fclose(file); > if (ret =3D=3D 1) > - port_name_set =3D > mlx5_translate_port_name(port_name, > - &data); > + mlx5_translate_port_name(port_name, &data); > } > file =3D fopen(phys_switch_id, "rb"); > if (file =3D=3D NULL) { > @@ -1440,8 +1438,10 @@ int mlx5_fw_version_get(struct rte_eth_dev > *dev, char *fw_ver, size_t fw_size) > 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; > + if (port_switch_id_set) { > + /* We have some E-Switch configuration. */ > + mlx5_sysfs_check_switch_info(device_dir, &data); > + } > *info =3D data; > assert(!(data.master && data.representor)); > if (data.master && data.representor) { @@ -1454,41 +1454,154 @@ > int mlx5_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t > fw_size) } >=20 > /** > + * Analyze gathered port parameters via Netlink to recognize master > + * and representor devices for E-Switch configuration. > + * > + * @param[in] num_vf_set > + * flag of presence of number of VFs port attribute. > + * @param[inout] switch_info > + * Port information, including port name as a number and port name > + * type if recognized > + * > + * @return > + * master and representor flags are set in switch_info according to > + * recognized parameters (if any). > + */ > +void > +mlx5_nl_check_switch_info(bool num_vf_set, > + struct mlx5_switch_info *switch_info) { > + switch (switch_info->name_type) { > + case MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN: > + /* > + * Name is not recognized, assume the master, > + * check the number of VFs key presence. > + */ > + switch_info->master =3D num_vf_set; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_NOTSET: > + /* > + * Name is not set, this assumes the legacy naming > + * schema for master, just check if there is a > + * number of VFs key. > + */ > + switch_info->master =3D num_vf_set; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_UPLINK: > + /* New uplink naming schema recognized. */ > + switch_info->master =3D 1; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_LEGACY: > + /* Legacy representors naming schema. */ > + switch_info->representor =3D !num_vf_set; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_PFVF: > + /* New representors naming schema. */ > + switch_info->representor =3D 1; > + break; Suggest to add default for clarity. > + } > +} > + > +/** > + * Analyze gathered port parameters via sysfs to recognize master > + * and representor devices for E-Switch configuration. > + * > + * @param[in] device_dir > + * flag of presence of "device" directory under port device key. > + * @param[inout] switch_info > + * Port information, including port name as a number and port name > + * type if recognized > + * > + * @return > + * master and representor flags are set in switch_info according to > + * recognized parameters (if any). > + */ > +void > +mlx5_sysfs_check_switch_info(bool device_dir, > + struct mlx5_switch_info *switch_info) { > + switch (switch_info->name_type) { > + case MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN: > + /* > + * Name is not recognized, assume the master, > + * check the device directory presence. > + */ > + switch_info->master =3D device_dir; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_NOTSET: > + /* > + * Name is not set, this assumes the legacy naming > + * schema for master, just check if there is > + * a device directory. > + */ > + switch_info->master =3D device_dir; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_UPLINK: > + /* New uplink naming schema recognized. */ > + switch_info->master =3D 1; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_LEGACY: > + /* Legacy representors naming schema. */ > + switch_info->representor =3D !device_dir; > + break; > + case MLX5_PHYS_PORT_NAME_TYPE_PFVF: > + /* New representors naming schema. */ > + switch_info->representor =3D 1; > + break; Suggest to add default for clarity. > + } > +} > + > +/** > * 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. > + * Port information, including port name as a number and port name > + * type if recognized > * > * @return > - * true on success, false otherwise. > + * port_name field set according to recognized name format. > */ > -bool > +void > 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; > + int sc_items; >=20 > /* > * Check for port-name as a string of the form pf0vf0 > - * (support kernel ver >=3D 5.0) > + * (support kernel ver >=3D 5.0 or OFED ver >=3D 4.6). > */ > - 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; > + sc_items =3D sscanf(port_name_in, "%c%c%d%c%c%d", > + &pf_c1, &pf_c2, &port_info_out->pf_num, > + &vf_c1, &vf_c2, &port_info_out->port_name); > + if (sc_items =3D=3D 6 && > + pf_c1 =3D=3D 'p' && pf_c2 =3D=3D 'f' && > + vf_c1 =3D=3D 'v' && vf_c2 =3D=3D 'f') { > + port_info_out->name_type =3D > MLX5_PHYS_PORT_NAME_TYPE_PFVF; > + return; > + } > + /* > + * Check for port-name as a string of the form p0 > + * (support kernel ver >=3D 5.0, or OFED ver >=3D 4.6). > + */ > + sc_items =3D sscanf(port_name_in, "%c%d", > + &pf_c1, &port_info_out->port_name); > + if (sc_items =3D=3D 2 && pf_c1 =3D=3D 'p') { > + port_info_out->name_type =3D > MLX5_PHYS_PORT_NAME_TYPE_UPLINK; > + return; > + } > + /* 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_info_out->name_type =3D > MLX5_PHYS_PORT_NAME_TYPE_LEGACY; > + return; > } > - return port_name_set; > + port_info_out->name_type =3D > MLX5_PHYS_PORT_NAME_TYPE_UNKNOWN; > + return; > } > diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c inde= x > fd9226b..0ff9667 100644 > --- a/drivers/net/mlx5/mlx5_nl.c > +++ b/drivers/net/mlx5/mlx5_nl.c > @@ -887,12 +887,11 @@ struct mlx5_nl_ifindex_data { > struct mlx5_switch_info info =3D { > .master =3D 0, > .representor =3D 0, > - .port_name_new =3D 0, > + .name_type =3D MLX5_PHYS_PORT_NAME_TYPE_NOTSET, > .port_name =3D 0, > .switch_id =3D 0, > }; > 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 > @@ -910,9 +909,7 @@ struct mlx5_nl_ifindex_data { > num_vf_set =3D true; > break; > case IFLA_PHYS_PORT_NAME: > - port_name_set =3D > - mlx5_translate_port_name((char *)payload, > - &info); > + mlx5_translate_port_name((char *)payload, &info); > break; > case IFLA_PHYS_SWITCH_ID: > info.switch_id =3D 0; > @@ -926,17 +923,8 @@ struct mlx5_nl_ifindex_data { > off +=3D RTA_ALIGN(ra->rta_len); > } > 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; > - } > + /* We have some E-Switch configuration. */ > + mlx5_nl_check_switch_info(num_vf_set, &info); > } > assert(!(info.master && info.representor)); > memcpy(arg, &info, sizeof(info)); > -- > 1.8.3.1