From patchwork Wed Jul 4 17:27:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrien Mazarguil X-Patchwork-Id: 42257 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6622D1BF30; Wed, 4 Jul 2018 19:27:55 +0200 (CEST) Received: from mail-wm0-f53.google.com (mail-wm0-f53.google.com [74.125.82.53]) by dpdk.org (Postfix) with ESMTP id CEC1F1BF27 for ; Wed, 4 Jul 2018 19:27:53 +0200 (CEST) Received: by mail-wm0-f53.google.com with SMTP id s12-v6so7142793wmc.1 for ; Wed, 04 Jul 2018 10:27:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=LZ7BxY/4owWBpMHTwS+IFzwvWnorKYfJ62epOi5lr6Y=; b=DGA2jEZWDggaVnYO8WKgcLLq766NiYudcElzs8rZ52aF4G3VNjslx+2va75Qr6KY/z o+zxvJtAAdkm53g9WI35rqvtPZioT2e8E/dTiJK49zqeycDFBZMsRo2rjb+lXREBuKY2 SArLMa1wCKMWAQWIZEgxruC3+qMvjSSRooPd6MPe9Kfk1qDwBx0+iPJkES8AiQrUGMEh ZSFAURXyAnlFUledXGstzvAqIsV5Jx2AguVYiH4sx7Yx2cDyFdMRy1BYd/36wj07G7s6 082+eCtY0PaNnNOWT3QSkN4TmInjMLgKgELo+jkZ+3YteqIcDzbxBh5vW4L2YEUMa8Uj qAoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=LZ7BxY/4owWBpMHTwS+IFzwvWnorKYfJ62epOi5lr6Y=; b=F/r7aS3byYpW6nWTqBGyr8ZduebGm43flHRCe75t5N5e/CK3A/9w/Mbr0ivHxMBZkJ lm+jkz2TwN8gzXPg87zZbaAUyzpTfHOjsZk8gqgv2EexOyT5wqLiAfvIbvx5J93qpf84 9uQc08oyBQkeV3d9X2+dfY2T58C888GoZlGG1t9S4UmWMw81C32ZncXVR3aHRHu1hM// p1pv/CMbfp81QcllfJuF4Wx0j/JkjYLjFWvCTJ0wQNiMuLzBatwQsPqRSkfKR8U5lIAA Lgai2nwiBUlMaKma/Wi/VP+/jo4WAIeIWScdtnHFUKpELbTlllA90unFsMLXEVLbqthb 9nug== X-Gm-Message-State: APt69E1Nc9zsvcYD69XvXz8tNpVR0Spvd6/7R8JR+/xYfXiZp4eMg2Gw tLBGZqnclQUog5R9V4VfBtQ+3U94 X-Google-Smtp-Source: AAOMgpf3+w8CxSfO8FZzaQIaXP4TAfYUp6Fn3PNQd+JhEnVVtD0ArsfSmIwnFlHG9lXS3KG/01BkQQ== X-Received: by 2002:a1c:c91a:: with SMTP id f26-v6mr2273416wmb.140.1530725273508; Wed, 04 Jul 2018 10:27:53 -0700 (PDT) Received: from 6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id x10-v6sm4125032wrn.25.2018.07.04.10.27.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Jul 2018 10:27:52 -0700 (PDT) Date: Wed, 4 Jul 2018 19:27:36 +0200 From: Adrien Mazarguil To: Shahaf Shuler Cc: dev@dpdk.org Message-ID: <20180704172322.22571-3-adrien.mazarguil@6wind.com> References: <20180614083047.10812-1-adrien.mazarguil@6wind.com> <20180704172322.22571-1-adrien.mazarguil@6wind.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20180704172322.22571-1-adrien.mazarguil@6wind.com> X-Mailer: git-send-email 2.11.0 Subject: [dpdk-dev] [PATCH v3 02/10] 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch gets rid of redundant calls to open the device and query its attributes in order to simplify the code. Signed-off-by: Adrien Mazarguil Reviewed-by: Xueming Li --- v2 changes: - Minor indent fix on existing code. --- drivers/net/mlx5/mlx5.c | 64 +++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 22cbce8d5..4e7f29f5b 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 = NULL; struct ibv_device *ibv_dev; + struct ibv_context *ctx = NULL; + struct ibv_device_attr_ex attr; struct mlx5dv_context dv_attr = { .comp_mask = 0 }; int err = 0; - struct ibv_context *attr_ctx = NULL; - struct ibv_device_attr_ex device_attr; unsigned int vf = 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 == PCI_DEVICE_ID_MELLANOX_CONNECTX5EXVF)); - attr_ctx = mlx5_glue->open_device(list[i]); + ctx = mlx5_glue->open_device(list[i]); rte_errno = errno; err = rte_errno; break; } - if (attr_ctx == NULL) { + if (ctx == 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 |= 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 = mlx5_glue->query_device_ex(attr_ctx, NULL, &device_attr); + err = 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 = 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 = 0; i < attr.orig_attr.phys_port_cnt; i++) { char name[RTE_ETH_NAME_MAX_LEN]; int len; uint32_t port = i + 1; /* ports are indexed from one */ - struct ibv_context *ctx = NULL; struct ibv_port_attr port_attr; struct ibv_pd *pd = NULL; struct priv *priv = NULL; struct rte_eth_dev *eth_dev = NULL; - struct ibv_device_attr_ex device_attr_ex; struct ether_addr mac; struct mlx5_dev_config config = { .cqe_comp = cqe_comp, @@ -865,7 +862,7 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, len = 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() == RTE_PROC_SECONDARY) { eth_dev = 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 = mlx5_glue->open_device(ibv_dev); + if (!ctx) + ctx = mlx5_glue->open_device(ibv_dev); if (ctx == NULL) { err = ENODEV; goto port_error; @@ -949,7 +947,7 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, priv->ctx = ctx; strncpy(priv->ibdev_path, priv->ctx->device->ibdev_path, sizeof(priv->ibdev_path)); - priv->device_attr = device_attr; + priv->device_attr = attr; priv->port = port; priv->pd = pd; priv->mtu = ETHER_MTU; @@ -960,17 +958,12 @@ mlx5_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, strerror(rte_errno)); goto port_error; } - err = 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 = !!(device_attr_ex.device_cap_flags_ex & + config.hw_csum = !!(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 = !!(device_attr.max_counter_sets); + config.flow_counter_en = !!attr.max_counter_sets; mlx5_glue->describe_counter_set(ctx, 0, &cs_desc); DRV_LOG(DEBUG, "counter type = %d, num of cs = %ld, attributes = %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 = - 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 = ETH_RSS_RETA_SIZE_512; DRV_LOG(DEBUG, "maximum Rx indirection table size is %u", config.ind_table_max_size); - config.hw_vlan_strip = !!(device_attr_ex.raw_packet_caps & + config.hw_vlan_strip = !!(attr.raw_packet_caps & IBV_RAW_PACKET_CAP_CVLAN_STRIPPING); DRV_LOG(DEBUG, "VLAN stripping is %ssupported", (config.hw_vlan_strip ? "" : "not ")); - config.hw_fcs_strip = !!(device_attr_ex.raw_packet_caps & + config.hw_fcs_strip = !!(attr.raw_packet_caps & IBV_RAW_PACKET_CAP_SCATTER_FCS); DRV_LOG(DEBUG, "FCS stripping configuration is %ssupported", (config.hw_fcs_strip ? "" : "not ")); #ifdef HAVE_IBV_WQ_FLAG_RX_END_PADDING - config.hw_padding = !!device_attr_ex.rx_pad_end_addr_align; + config.hw_padding = !!attr.rx_pad_end_addr_align; #endif DRV_LOG(DEBUG, "hardware Rx end alignment padding is %ssupported", (config.hw_padding ? "" : "not ")); config.vf = vf; - config.tso = ((device_attr_ex.tso_caps.max_tso > 0) && - (device_attr_ex.tso_caps.supported_qpts & - (1 << IBV_QPT_RAW_PACKET))); + config.tso = (attr.tso_caps.max_tso > 0 && + (attr.tso_caps.supported_qpts & + (1 << IBV_QPT_RAW_PACKET))); if (config.tso) - config.tso_max_payload_sz = - device_attr_ex.tso_caps.max_tso; + config.tso_max_payload_sz = attr.tso_caps.max_tso; if (config.mps && !mps) { DRV_LOG(ERR, "multi-packet send not supported on this device" @@ -1170,14 +1162,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 = 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() == RTE_PROC_PRIMARY) rte_eth_dev_release_port(eth_dev); break; @@ -1189,8 +1185,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) {