From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on0069.outbound.protection.outlook.com [104.47.0.69]) by dpdk.org (Postfix) with ESMTP id BAB811B58C for ; Sun, 17 Jun 2018 12:14:03 +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=7Iv5MciN+H9EWD3Mybo450locxC/a4dxacI+jszYuuE=; b=kKyHtUjijrYiQgrMaUW1v5ZuFcfgyuEv3/QyvmEgiTBBNThdKOxHe0i16xnWIHJT3SZCFjcIIYErnK/z257T717B5WVpZdSOCWEteVwahva71HCPr2FVsq2t7OUTlHK1/kmm5qaypNGkU9mtzXYjP2qR/qOG1a1EbmD+tU8eNq0= Received: from DB7PR05MB4426.eurprd05.prod.outlook.com (52.134.109.15) by DB7PR05MB4170.eurprd05.prod.outlook.com (52.134.107.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.863.19; Sun, 17 Jun 2018 10:14:01 +0000 Received: from DB7PR05MB4426.eurprd05.prod.outlook.com ([fe80::4c94:2db9:b8c5:cc6b]) by DB7PR05MB4426.eurprd05.prod.outlook.com ([fe80::4c94:2db9:b8c5:cc6b%4]) with mapi id 15.20.0863.016; Sun, 17 Jun 2018 10:14:01 +0000 From: Shahaf Shuler To: Adrien Mazarguil CC: "dev@dpdk.org" Thread-Topic: [PATCH v2 2/7] net/mlx5: remove redundant objects in probe code Thread-Index: AQHUA7qbccOyVQKXvEmKPqz0ep2kl6RkJhJw Date: Sun, 17 Jun 2018 10:14:01 +0000 Message-ID: References: <20180525161814.13873-1-adrien.mazarguil@6wind.com> <20180614083047.10812-1-adrien.mazarguil@6wind.com> <20180614083047.10812-3-adrien.mazarguil@6wind.com> In-Reply-To: <20180614083047.10812-3-adrien.mazarguil@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; DB7PR05MB4170; 7:6KXhQFzvlTEcpp2UcNeh2TDO2V3qb5ewA9WekjmUKIGRfBoGs0bcySK5Q7NO3Lr+73FA2x+N6oXdaP6FN2/DPCvyl6XFYHJHUNamvJBayHBh/HpxLBL6ODA4xBTOiRMmMjEgzwZg4YEqV3HT5tzKNBo9bXDhRiAN2GkzHaSPpX2Gwv9M/ZwJ8k4CwJPPK7d73vJATCZsY8g7NdIAE5YZQ5tnVMre0DEgFWjQRa3twH3AowQpobO7v/yY9DCRdnjL x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-correlation-id: 0d9eeecb-3939-484d-9e98-08d5d43b0c6b x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(711020)(48565401081)(2017052603328)(7153060)(7193020); SRVR:DB7PR05MB4170; x-ms-traffictypediagnostic: DB7PR05MB4170: 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)(10201501046)(3002001)(93006095)(93001095)(3231254)(944501410)(52105095)(6055026)(149027)(150027)(6041310)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(6072148)(201708071742011)(7699016); SRVR:DB7PR05MB4170; BCL:0; PCL:0; RULEID:; SRVR:DB7PR05MB4170; x-forefront-prvs: 07063A0A30 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(979002)(39860400002)(346002)(39380400002)(396003)(376002)(366004)(199004)(189003)(53936002)(6916009)(81166006)(81156014)(6436002)(8936002)(86362001)(6246003)(229853002)(8676002)(478600001)(105586002)(305945005)(106356001)(316002)(9686003)(97736004)(74316002)(5660300001)(55016002)(14454004)(7736002)(5890100001)(25786009)(26005)(33656002)(4326008)(2900100001)(76176011)(6506007)(3660700001)(476003)(11346002)(486006)(2906002)(102836004)(59450400001)(66066001)(7696005)(6116002)(3280700002)(68736007)(446003)(5250100002)(186003)(99286004)(3846002)(309714004)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:DB7PR05MB4170; H:DB7PR05MB4426.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-microsoft-antispam-message-info: 5ekYr8beUHq9oMLz1jLB+fYlpQV10DXml/KJndDuChYbe0ouebMB8U1fog4rHMHWC1xH4l9BJGkNOp36YiNZqBb0CUIRbNAMF2xGxCFool/NOC3fILZuoEVeN+tSRVpk6iC8f6tm788qgYBaqIK1BlQQ9LO/ancAP4t+WnGyUzAihqcgLrxwZvGRyRqgmkDw spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM 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: 0d9eeecb-3939-484d-9e98-08d5d43b0c6b X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jun 2018 10:14:01.8550 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a652971c-7d2e-4d9b-a6a4-d149256f461b X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB7PR05MB4170 Subject: Re: [dpdk-dev] [PATCH v2 2/7] net/mlx5: remove redundant objects in probe code 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, 17 Jun 2018 10:14:04 -0000 Hi Adrien,=20 Small nit,=20 Thursday, June 14, 2018 11:35 AM, Adrien Mazarguil: > Subject: [PATCH v2 2/7] net/mlx5: remove redundant objects in probe code >=20 > This patch gets rid of redundant calls to open the device and query its > attributes in order to simplify the code. >=20 > Signed-off-by: Adrien Mazarguil > -- > v2 changes: >=20 > - Minor indent fix on existing code. > --- > drivers/net/mlx5/mlx5.c | 64 +++++++++++++++++++++----------------------= - > 1 file changed, 30 insertions(+), 34 deletions(-) >=20 > diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index > 3bdcb3970..1a5391e63 100644 > --- a/drivers/net/mlx5/mlx5.c > +++ b/drivers/net/mlx5/mlx5.c > @@ -654,10 +654,10 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > __rte_unused, { > struct ibv_device **list =3D NULL; > struct ibv_device *ibv_dev; > + struct ibv_context *ctx =3D NULL; > + struct ibv_device_attr_ex attr; > struct mlx5dv_context dv_attr =3D { .comp_mask =3D 0 }; > int err =3D 0; > - struct ibv_context *attr_ctx =3D NULL; > - struct ibv_device_attr_ex device_attr; > unsigned int vf =3D 0; > unsigned int mps; > unsigned int cqe_comp; > @@ -714,12 +714,12 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > __rte_unused, > PCI_DEVICE_ID_MELLANOX_CONNECTX5VF) || > (pci_dev->id.device_id =3D=3D > PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF)); > - attr_ctx =3D mlx5_glue->open_device(list[i]); > + ctx =3D mlx5_glue->open_device(list[i]); > rte_errno =3D errno; > err =3D rte_errno; > break; > } > - if (attr_ctx =3D=3D NULL) { > + if (ctx =3D=3D NULL) { > switch (err) { > case 0: > DRV_LOG(ERR, > @@ -748,7 +748,7 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > __rte_unused, #ifdef HAVE_IBV_DEVICE_STRIDING_RQ_SUPPORT > dv_attr.comp_mask |=3D MLX5DV_CONTEXT_MASK_STRIDING_RQ; > #endif > - mlx5_glue->dv_query_device(attr_ctx, &dv_attr); > + mlx5_glue->dv_query_device(ctx, &dv_attr); > if (dv_attr.flags & MLX5DV_CONTEXT_FLAGS_MPW_ALLOWED) { > if (dv_attr.flags & > MLX5DV_CONTEXT_FLAGS_ENHANCED_MPW) { > DRV_LOG(DEBUG, "enhanced MPW is supported"); > @@ -822,23 +822,20 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > __rte_unused, > DRV_LOG(WARNING, "MPLS over GRE/UDP tunnel offloading > disabled due to" > " old OFED/rdma-core version or firmware configuration"); > #endif > - err =3D mlx5_glue->query_device_ex(attr_ctx, NULL, &device_attr); > + err =3D mlx5_glue->query_device_ex(ctx, NULL, &attr); > if (err) { > DEBUG("ibv_query_device_ex() failed"); > goto error; > } > - DRV_LOG(INFO, "%u port(s) detected", > - device_attr.orig_attr.phys_port_cnt); > - for (i =3D 0; i < device_attr.orig_attr.phys_port_cnt; i++) { > + DRV_LOG(INFO, "%u port(s) detected", > attr.orig_attr.phys_port_cnt); > + for (i =3D 0; i < attr.orig_attr.phys_port_cnt; i++) { > char name[RTE_ETH_NAME_MAX_LEN]; > int len; > uint32_t port =3D i + 1; /* ports are indexed from one */ > - struct ibv_context *ctx =3D NULL; > struct ibv_port_attr port_attr; > struct ibv_pd *pd =3D NULL; > struct priv *priv =3D NULL; > struct rte_eth_dev *eth_dev =3D NULL; > - struct ibv_device_attr_ex device_attr_ex; > struct ether_addr mac; > struct mlx5_dev_config config =3D { > .cqe_comp =3D cqe_comp, > @@ -865,7 +862,7 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > __rte_unused, > len =3D snprintf(name, sizeof(name), PCI_PRI_FMT, > pci_dev->addr.domain, pci_dev->addr.bus, > pci_dev->addr.devid, pci_dev->addr.function); > - if (device_attr.orig_attr.phys_port_cnt > 1) > + if (attr.orig_attr.phys_port_cnt > 1) > snprintf(name + len, sizeof(name), " port %u", i); > if (rte_eal_process_type() =3D=3D RTE_PROC_SECONDARY) { > eth_dev =3D rte_eth_dev_attach_secondary(name); > @@ -907,7 +904,8 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > __rte_unused, > continue; > } > DRV_LOG(DEBUG, "using port %u", port); > - ctx =3D mlx5_glue->open_device(ibv_dev); > + if (!ctx) Is it really possible for ctx to be NULL on this stage?=20 Maybe assert is preferable?=20 > + ctx =3D mlx5_glue->open_device(ibv_dev); > if (ctx =3D=3D NULL) { > err =3D ENODEV; > goto port_error; > @@ -949,7 +947,7 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > __rte_unused, > priv->ctx =3D ctx; > strncpy(priv->ibdev_path, priv->ctx->device->ibdev_path, > sizeof(priv->ibdev_path)); > - priv->device_attr =3D device_attr; > + priv->device_attr =3D attr; > priv->port =3D port; > priv->pd =3D pd; > priv->mtu =3D ETHER_MTU; > @@ -960,17 +958,12 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > __rte_unused, > strerror(rte_errno)); > goto port_error; > } > - err =3D mlx5_glue->query_device_ex(ctx, NULL, > &device_attr_ex); > - if (err) { > - DRV_LOG(ERR, "ibv_query_device_ex() failed"); > - goto port_error; > - } > - config.hw_csum =3D !!(device_attr_ex.device_cap_flags_ex & > + config.hw_csum =3D !!(attr.device_cap_flags_ex & > IBV_DEVICE_RAW_IP_CSUM); > DRV_LOG(DEBUG, "checksum offloading is %ssupported", > (config.hw_csum ? "" : "not ")); > #ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT > - config.flow_counter_en =3D > !!(device_attr.max_counter_sets); > + config.flow_counter_en =3D !!attr.max_counter_sets; > mlx5_glue->describe_counter_set(ctx, 0, &cs_desc); > DRV_LOG(DEBUG, > "counter type =3D %d, num of cs =3D %ld, attributes =3D > %d", @@ -978,7 +971,7 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > __rte_unused, > cs_desc.attributes); > #endif > config.ind_table_max_size =3D > - > device_attr_ex.rss_caps.max_rwq_indirection_table_size; > + attr.rss_caps.max_rwq_indirection_table_size; > /* Remove this check once DPDK supports larger/variable > * indirection tables. */ > if (config.ind_table_max_size > > @@ -986,29 +979,28 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > __rte_unused, > config.ind_table_max_size =3D > ETH_RSS_RETA_SIZE_512; > DRV_LOG(DEBUG, "maximum Rx indirection table size is %u", > config.ind_table_max_size); > - config.hw_vlan_strip =3D !!(device_attr_ex.raw_packet_caps & > + config.hw_vlan_strip =3D !!(attr.raw_packet_caps & >=20 > IBV_RAW_PACKET_CAP_CVLAN_STRIPPING); > DRV_LOG(DEBUG, "VLAN stripping is %ssupported", > (config.hw_vlan_strip ? "" : "not ")); >=20 > - config.hw_fcs_strip =3D !!(device_attr_ex.raw_packet_caps & > + config.hw_fcs_strip =3D !!(attr.raw_packet_caps & >=20 > IBV_RAW_PACKET_CAP_SCATTER_FCS); > DRV_LOG(DEBUG, "FCS stripping configuration is > %ssupported", > (config.hw_fcs_strip ? "" : "not ")); >=20 > #ifdef HAVE_IBV_WQ_FLAG_RX_END_PADDING > - config.hw_padding =3D > !!device_attr_ex.rx_pad_end_addr_align; > + config.hw_padding =3D !!attr.rx_pad_end_addr_align; > #endif > DRV_LOG(DEBUG, > "hardware Rx end alignment padding is > %ssupported", > (config.hw_padding ? "" : "not ")); > config.vf =3D vf; > - config.tso =3D ((device_attr_ex.tso_caps.max_tso > 0) && > - (device_attr_ex.tso_caps.supported_qpts & > - (1 << IBV_QPT_RAW_PACKET))); > + config.tso =3D (attr.tso_caps.max_tso > 0 && > + (attr.tso_caps.supported_qpts & > + (1 << IBV_QPT_RAW_PACKET))); > if (config.tso) > - config.tso_max_payload_sz =3D > - device_attr_ex.tso_caps.max_tso; > + config.tso_max_payload_sz =3D attr.tso_caps.max_tso; > if (config.mps && !mps) { > DRV_LOG(ERR, > "multi-packet send not supported on this > device" > @@ -1168,14 +1160,18 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > __rte_unused, > priv, mem_event_cb); > rte_rwlock_write_unlock(&mlx5_shared_data- > >mem_event_rwlock); > rte_eth_dev_probing_finish(eth_dev); > + /* > + * Each eth_dev instance is assigned its own Verbs context, > + * since this one is consumed, let the next iteration open > + * another. > + */ > + ctx =3D NULL; > continue; > port_error: > if (priv) > rte_free(priv); > if (pd) > claim_zero(mlx5_glue->dealloc_pd(pd)); > - if (ctx) > - claim_zero(mlx5_glue->close_device(ctx)); > if (eth_dev && rte_eal_process_type() =3D=3D > RTE_PROC_PRIMARY) > rte_eth_dev_release_port(eth_dev); > break; > @@ -1187,8 +1183,8 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv > __rte_unused, > * way to enumerate the registered ethdevs to free the previous > ones. > */ > error: > - if (attr_ctx) > - claim_zero(mlx5_glue->close_device(attr_ctx)); > + if (ctx) > + claim_zero(mlx5_glue->close_device(ctx)); > if (list) > mlx5_glue->free_device_list(list); > if (err) { > -- > 2.11.0