From patchwork Tue Aug 17 13:44:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Baum X-Patchwork-Id: 97006 X-Patchwork-Delegate: rasland@nvidia.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D6C2AA0548; Tue, 17 Aug 2021 15:47:30 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A5FD441220; Tue, 17 Aug 2021 15:45:44 +0200 (CEST) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1anam02on2055.outbound.protection.outlook.com [40.107.96.55]) by mails.dpdk.org (Postfix) with ESMTP id 0B2194123F for ; Tue, 17 Aug 2021 15:45:43 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bBh66MppsPRyncd8m2R3bB73raRK7NL1m7RkAE/h+O71GgI1vmTWYJccwB029twnC0c6M/1jALSfYsUktVnClAfw+1g8UpFZkV/Iew1hj2pZTTKAU/xOyF3NzAyRnB2zCab0y3P0xTbYcDJhQiGv4tFo6fQsfaPLdhRFI/aFxqW1XTxlhidNaQ2abVy1fXtgua5d+BqNlmhBD2GsZKACsiFVtrpgtO52P1zRRD1efQJSCCU47dpV22YWV61HQq4XRFelFXf0qIyWEntELtm8I7Ff2knBcNNe2GPOxmK3DJBVHXQwrgzo3CIRbyvfKIDAA+wKYge1INcynqd8ZpajWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/29qP/xMolmUxuiUQn90BxKebbd5RlbqJhraKg+Sj/M=; b=kOHnmGCQYBZ3VIqW0pLWT9FtjfpM8mym7XcIr8OfQomsZJs8x7xVUto9dNzLrLymwdXCrexS0YWKyOfJ/iFM3MCrR0HwTsoyCVrPkAUt2C/0POPnOhl3KmmmeWSaVSKpCbdEMVGeQO6BAFn5kGMrKB1XFMiHrIOSW8XOWF/uPi7DlYyYJM0S+DEnEzGVZ2xqJZRKW2B1VthBlKGv86P8d9mM9rm8rJEf+Az522iVNzl6zBG9GcKVjwgRAcIzHQ4z0SfQBdI43TWmEBgLcEAPOSSxOFGTPqQs+4WhmouOqi2Xs3jh06JmFwQ1tkIM7yWroFt5RJcl+LF7TO4XTG847A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/29qP/xMolmUxuiUQn90BxKebbd5RlbqJhraKg+Sj/M=; b=C4/KMwoRP3sPaMR+1zopMfM1WCZ9uWFFFm1Dy649+/g4R3xVpdPb/xwbK4t0t8n3LFbQ6j5tUhXB6AWe1NAFeRH9y1wtUELxE5lpdMi2ghN5mRD6aPHGpieTRIZsjgy+QIJh6/OramhzaJnBY7DYaxM0G1w01hBsALKo7SFWVy+xKxOMZa8Guxq9V6qTxBIsvlVrNn7dJfabdQolbr8OSXKo/umF4qFaGGN+TnjvqwhtFVd06xZrKSvmYca237BIyqkwq+mwZyjmUgzI87s7UYG78CbKoft8oHPimMkVEuaXwwyZ5kQ/d/5D0l1OVAe1Jw5OFwyRfy9KWmZcv1mw/w== Received: from BN6PR13CA0023.namprd13.prod.outlook.com (2603:10b6:404:10a::33) by BN9PR12MB5211.namprd12.prod.outlook.com (2603:10b6:408:11c::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.17; Tue, 17 Aug 2021 13:45:41 +0000 Received: from BN8NAM11FT065.eop-nam11.prod.protection.outlook.com (2603:10b6:404:10a:cafe::32) by BN6PR13CA0023.outlook.office365.com (2603:10b6:404:10a::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.8 via Frontend Transport; Tue, 17 Aug 2021 13:45:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; dpdk.org; dkim=none (message not signed) header.d=none;dpdk.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by BN8NAM11FT065.mail.protection.outlook.com (10.13.177.63) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4415.14 via Frontend Transport; Tue, 17 Aug 2021 13:45:40 +0000 Received: from DRHQMAIL107.nvidia.com (10.27.9.16) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 17 Aug 2021 13:45:39 +0000 Received: from nvidia.com (172.20.187.6) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 17 Aug 2021 13:45:37 +0000 From: Michael Baum To: CC: Matan Azrad , Raslan Darawsheh , Viacheslav Ovsiienko Date: Tue, 17 Aug 2021 16:44:35 +0300 Message-ID: <20210817134441.1966618-16-michaelba@nvidia.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210817134441.1966618-1-michaelba@nvidia.com> References: <20210817134441.1966618-1-michaelba@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To DRHQMAIL107.nvidia.com (10.27.9.16) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 45ff0919-9fec-4adc-cd5a-08d961854d5a X-MS-TrafficTypeDiagnostic: BN9PR12MB5211: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:142; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: moKG4Q6r1T0OiEBxGLOB7H2D2gaF1vXM4NxHKDqVygyfZQOlqVBmnL3GPByYuvFSj8uV2+d/zFgkW+ePpG5evSEBhFBecWyjfil2CnLNiEgvH5HZw054zFzGmM3UcSjcS8qSae0fTuI/71sFTF5TFKamrThF3VEvd+uhkeDVnCqxwkid6yY9nDBwCP6q17dkNPOgz8zVohTXe3+KgH9X2s6BsvbqmgiIU08tHig7ZSFOwKu7g9N14epKgcSJbBifWFEW9aHM9bNcDMk7/9E4jV9X0LBYk8f64E8BFOEakvRoPGITyJSIg4n059cNAOlSLAiBkBsMytGkvX97ABnRSBtuuI+4R5tNCi49FcPfzI0UOM8BFm83eR+aspa7ZH3mWqKaJ0MaUsqku1ssgGfnUC7eiuKGxc3kbdf7jqz/HZStW5BN5LX4dOppiKj7y5Md41VAW2iiKj6rwDiPMdUTZgzZ2f1YVi3qdW7qo+0/3EdwJWFH1fjCfKz6avdvsEvLPdBZEQ7nIRKVq21pznYbYROVTwMJDu6ehwC/tJEFBsGODWKwQNAyRAyHP0U/b5JXsqeiA+Iso1dDAmbhjjhfq9lngKpDlMrv+v92OEJaJ54BMgSvi0uZWYZKUKKxNFgkbiimHBp0mP/szB7dHaSLqnBa4RH4Y4Ik4rTf4yK4TvLKr8MQKYPZRZmE1fuV3McA4ArmJSLqbUlgFGWGJjzCQQ== X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid04.nvidia.com; CAT:NONE; SFS:(4636009)(46966006)(36840700001)(2906002)(336012)(83380400001)(6286002)(4326008)(5660300002)(426003)(508600001)(82310400003)(7636003)(55016002)(356005)(8936002)(7696005)(6916009)(70586007)(2616005)(30864003)(70206006)(36756003)(36860700001)(1076003)(47076005)(107886003)(16526019)(186003)(26005)(86362001)(8676002)(316002)(54906003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Aug 2021 13:45:40.3848 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 45ff0919-9fec-4adc-cd5a-08d961854d5a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT065.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5211 Subject: [dpdk-dev] [RFC 15/21] mlx5: share context device structure between drivers X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Create and initialize context device structure ones in common probing, and give a pointer to it for each driver. Signed-off-by: Michael Baum --- drivers/common/mlx5/mlx5_common.c | 40 +++++++++++++++++++++------ drivers/common/mlx5/mlx5_common.h | 30 +------------------- drivers/common/mlx5/version.map | 2 -- drivers/compress/mlx5/mlx5_compress.c | 31 ++------------------- drivers/crypto/mlx5/mlx5_crypto.c | 34 ++--------------------- drivers/net/mlx5/linux/mlx5_os.c | 36 ++++++++---------------- drivers/net/mlx5/mlx5.c | 32 --------------------- drivers/net/mlx5/windows/mlx5_os.c | 22 ++------------- drivers/regex/mlx5/mlx5_regex.c | 35 ++++------------------- drivers/vdpa/mlx5/mlx5_vdpa.c | 35 ++++------------------- 10 files changed, 64 insertions(+), 233 deletions(-) diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c index 0870ee0718..b500e7834e 100644 --- a/drivers/common/mlx5/mlx5_common.c +++ b/drivers/common/mlx5/mlx5_common.c @@ -319,7 +319,7 @@ mlx5_dev_to_pci_str(const struct rte_device *dev, char *addr, size_t size) * @return * 0 on success, a negative errno value otherwise and rte_errno is set. */ -void +static void mlx5_dev_ctx_release(struct mlx5_dev_ctx *dev_ctx) { if (dev_ctx->pd != NULL) { @@ -345,7 +345,7 @@ mlx5_dev_ctx_release(struct mlx5_dev_ctx *dev_ctx) * @return * 0 on success, a negative errno value otherwise and rte_errno is set. */ -int +static int mlx5_dev_ctx_prepare(struct mlx5_dev_ctx *dev_ctx, struct rte_device *dev, uint32_t classes_loaded) { @@ -386,12 +386,36 @@ mlx5_dev_ctx_prepare(struct mlx5_dev_ctx *dev_ctx, struct rte_device *dev, } static void -dev_release(struct mlx5_common_device *dev) +mlx5_common_dev_release(struct mlx5_common_device *dev) { TAILQ_REMOVE(&devices_list, dev, next); + mlx5_dev_ctx_release(&dev->ctx); rte_free(dev); } +static struct mlx5_common_device * +mlx5_common_dev_create(struct rte_device *eal_dev, uint32_t classes) +{ + struct mlx5_common_device *dev; + int ret; + + dev = rte_zmalloc("mlx5_common_device", sizeof(*dev), 0); + if (!dev) { + DRV_LOG(ERR, "Device allocation failure."); + rte_errno = ENOMEM; + return NULL; + } + ret = mlx5_dev_ctx_prepare(&dev->ctx, eal_dev, classes); + if (ret) { + DRV_LOG(ERR, "Failed to create device context."); + rte_free(dev); + return NULL; + } + dev->dev = eal_dev; + TAILQ_INSERT_HEAD(&devices_list, dev, next); + return dev; +} + static int drivers_remove(struct mlx5_common_device *dev, uint32_t enabled_classes) { @@ -477,11 +501,9 @@ mlx5_common_dev_probe(struct rte_device *eal_dev) classes = MLX5_CLASS_ETH; dev = to_mlx5_device(eal_dev); if (!dev) { - dev = rte_zmalloc("mlx5_common_device", sizeof(*dev), 0); + dev = mlx5_common_dev_create(eal_dev, classes); if (!dev) - return -ENOMEM; - dev->dev = eal_dev; - TAILQ_INSERT_HEAD(&devices_list, dev, next); + return -rte_errno; new_device = true; } else { /* Validate combination here. */ @@ -498,7 +520,7 @@ mlx5_common_dev_probe(struct rte_device *eal_dev) return 0; class_err: if (new_device) - dev_release(dev); + mlx5_common_dev_release(dev); return ret; } @@ -514,7 +536,7 @@ mlx5_common_dev_remove(struct rte_device *eal_dev) /* Matching device found, cleanup and unload drivers. */ ret = drivers_remove(dev, dev->classes_loaded); if (ret != 0) - dev_release(dev); + mlx5_common_dev_release(dev); return ret; } diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h index c5f2a6285f..644dc58bc9 100644 --- a/drivers/common/mlx5/mlx5_common.h +++ b/drivers/common/mlx5/mlx5_common.h @@ -339,37 +339,9 @@ struct mlx5_common_device { struct rte_device *dev; TAILQ_ENTRY(mlx5_common_device) next; uint32_t classes_loaded; + struct mlx5_dev_ctx ctx; }; -/** - * Uninitialize context device and release all its resources. - * - * @param dev_ctx - * Pointer to the context device data structure. - * - * @return - * 0 on success, a negative errno value otherwise and rte_errno is set. - */ -__rte_internal -void mlx5_dev_ctx_release(struct mlx5_dev_ctx *dev_ctx); - -/** - * Initialize context device and allocate all its resources. - * - * @param dev_ctx - * Pointer to the context device data structure. - * @param dev - * Pointer to mlx5 device structure. - * @param classes_loaded - * Chosen classes come from device arguments. - * - * @return - * 0 on success, a negative errno value otherwise and rte_errno is set. - */ -__rte_internal -int mlx5_dev_ctx_prepare(struct mlx5_dev_ctx *dev_ctx, struct rte_device *dev, - uint32_t classes_loaded); - /** * Initialization function for the driver called during device probing. */ diff --git a/drivers/common/mlx5/version.map b/drivers/common/mlx5/version.map index a1a8bae5bd..4b24833ecb 100644 --- a/drivers/common/mlx5/version.map +++ b/drivers/common/mlx5/version.map @@ -10,8 +10,6 @@ INTERNAL { mlx5_common_init; mlx5_parse_db_map_arg; # WINDOWS_NO_EXPORT - mlx5_dev_ctx_release; - mlx5_dev_ctx_prepare; mlx5_common_verbs_reg_mr; # WINDOWS_NO_EXPORT mlx5_common_verbs_dereg_mr; # WINDOWS_NO_EXPORT diff --git a/drivers/compress/mlx5/mlx5_compress.c b/drivers/compress/mlx5/mlx5_compress.c index 8348ea8ea3..93b0cc8ea6 100644 --- a/drivers/compress/mlx5/mlx5_compress.c +++ b/drivers/compress/mlx5/mlx5_compress.c @@ -751,43 +751,25 @@ static int mlx5_compress_dev_probe(struct mlx5_common_device *dev) { struct rte_compressdev *cdev; - struct mlx5_dev_ctx *dev_ctx; + struct mlx5_dev_ctx *dev_ctx = &dev->ctx; struct mlx5_compress_priv *priv; struct mlx5_hca_attr att = { 0 }; struct rte_compressdev_pmd_init_params init_params = { .name = "", .socket_id = dev->dev->numa_node, }; - const char *ibdev_name; - int ret; + const char *ibdev_name = mlx5_os_get_ctx_device_name(dev_ctx->ctx); if (rte_eal_process_type() != RTE_PROC_PRIMARY) { DRV_LOG(ERR, "Non-primary process type is not supported."); rte_errno = ENOTSUP; return -rte_errno; } - dev_ctx = mlx5_malloc(MLX5_MEM_ZERO, sizeof(struct mlx5_dev_ctx), - RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); - if (dev_ctx == NULL) { - DRV_LOG(ERR, "Device context allocation failure."); - rte_errno = ENOMEM; - return -rte_errno; - } - ret = mlx5_dev_ctx_prepare(dev_ctx, dev->dev, MLX5_CLASS_COMPRESS); - if (ret < 0) { - DRV_LOG(ERR, "Failed to create device context."); - mlx5_free(dev_ctx); - rte_errno = ENODEV; - return -rte_errno; - } - ibdev_name = mlx5_os_get_ctx_device_name(dev_ctx->ctx); if (mlx5_devx_cmd_query_hca_attr(dev_ctx->ctx, &att) != 0 || att.mmo_compress_en == 0 || att.mmo_decompress_en == 0 || att.mmo_dma_en == 0) { DRV_LOG(ERR, "Not enough capabilities to support compress " "operations, maybe old FW/OFED version?"); - mlx5_dev_ctx_release(dev_ctx); - mlx5_free(dev_ctx); rte_errno = ENOTSUP; return -ENOTSUP; } @@ -795,8 +777,6 @@ mlx5_compress_dev_probe(struct mlx5_common_device *dev) sizeof(*priv), &init_params); if (cdev == NULL) { DRV_LOG(ERR, "Failed to create device \"%s\".", ibdev_name); - mlx5_dev_ctx_release(dev_ctx); - mlx5_free(dev_ctx); return -ENODEV; } DRV_LOG(INFO, @@ -812,8 +792,6 @@ mlx5_compress_dev_probe(struct mlx5_common_device *dev) priv->sq_ts_format = att.sq_ts_format; if (mlx5_compress_hw_global_prepare(priv) != 0) { rte_compressdev_pmd_destroy(priv->cdev); - mlx5_dev_ctx_release(priv->dev_ctx); - mlx5_free(priv->dev_ctx); return -1; } if (mlx5_mr_btree_init(&priv->mr_scache.cache, @@ -821,8 +799,6 @@ mlx5_compress_dev_probe(struct mlx5_common_device *dev) DRV_LOG(ERR, "Failed to allocate shared cache MR memory."); mlx5_compress_hw_global_release(priv); rte_compressdev_pmd_destroy(priv->cdev); - mlx5_dev_ctx_release(priv->dev_ctx); - mlx5_free(priv->dev_ctx); rte_errno = ENOMEM; return -rte_errno; } @@ -858,8 +834,7 @@ mlx5_compress_dev_remove(struct mlx5_common_device *dev) mlx5_mr_release_cache(&priv->mr_scache); mlx5_compress_hw_global_release(priv); rte_compressdev_pmd_destroy(priv->cdev); - mlx5_dev_ctx_release(priv->dev_ctx); - mlx5_free(priv->dev_ctx); + priv->dev_ctx = NULL; } return 0; } diff --git a/drivers/crypto/mlx5/mlx5_crypto.c b/drivers/crypto/mlx5/mlx5_crypto.c index 44656225d2..4f390c8bf4 100644 --- a/drivers/crypto/mlx5/mlx5_crypto.c +++ b/drivers/crypto/mlx5/mlx5_crypto.c @@ -945,7 +945,7 @@ static int mlx5_crypto_dev_probe(struct mlx5_common_device *dev) { struct rte_cryptodev *crypto_dev; - struct mlx5_dev_ctx *dev_ctx; + struct mlx5_dev_ctx *dev_ctx = &dev->ctx; struct mlx5_devx_obj *login; struct mlx5_crypto_priv *priv; struct mlx5_crypto_devarg_params devarg_prms = { 0 }; @@ -957,7 +957,7 @@ mlx5_crypto_dev_probe(struct mlx5_common_device *dev) .max_nb_queue_pairs = RTE_CRYPTODEV_PMD_DEFAULT_MAX_NB_QUEUE_PAIRS, }; - const char *ibdev_name; + const char *ibdev_name = mlx5_os_get_ctx_device_name(dev_ctx->ctx); uint16_t rdmw_wqe_size; int ret; @@ -966,51 +966,28 @@ mlx5_crypto_dev_probe(struct mlx5_common_device *dev) rte_errno = ENOTSUP; return -rte_errno; } - dev_ctx = mlx5_malloc(MLX5_MEM_ZERO, sizeof(struct mlx5_dev_ctx), - RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); - if (dev_ctx == NULL) { - DRV_LOG(ERR, "Device context allocation failure."); - rte_errno = ENOMEM; - return -rte_errno; - } - ret = mlx5_dev_ctx_prepare(dev_ctx, dev->dev, MLX5_CLASS_CRYPTO); - if (ret < 0) { - DRV_LOG(ERR, "Failed to create device context."); - mlx5_free(dev_ctx); - rte_errno = ENODEV; - return -rte_errno; - } - ibdev_name = mlx5_os_get_ctx_device_name(dev_ctx->ctx); if (mlx5_devx_cmd_query_hca_attr(dev_ctx->ctx, &attr) != 0 || attr.crypto == 0 || attr.aes_xts == 0) { DRV_LOG(ERR, "Not enough capabilities to support crypto " "operations, maybe old FW/OFED version?"); - mlx5_dev_ctx_release(dev_ctx); - mlx5_free(dev_ctx); rte_errno = ENOTSUP; return -ENOTSUP; } ret = mlx5_crypto_parse_devargs(dev->dev->devargs, &devarg_prms); if (ret) { DRV_LOG(ERR, "Failed to parse devargs."); - mlx5_dev_ctx_release(dev_ctx); - mlx5_free(dev_ctx); return -rte_errno; } login = mlx5_devx_cmd_create_crypto_login_obj(dev_ctx->ctx, &devarg_prms.login_attr); if (login == NULL) { DRV_LOG(ERR, "Failed to configure login."); - mlx5_dev_ctx_release(dev_ctx); - mlx5_free(dev_ctx); return -rte_errno; } crypto_dev = rte_cryptodev_pmd_create(ibdev_name, dev->dev, &init_params); if (crypto_dev == NULL) { DRV_LOG(ERR, "Failed to create device \"%s\".", ibdev_name); - mlx5_dev_ctx_release(dev_ctx); - mlx5_free(dev_ctx); return -ENODEV; } DRV_LOG(INFO, "Crypto device %s was created successfully.", ibdev_name); @@ -1025,8 +1002,6 @@ mlx5_crypto_dev_probe(struct mlx5_common_device *dev) priv->crypto_dev = crypto_dev; if (mlx5_crypto_hw_global_prepare(priv) != 0) { rte_cryptodev_pmd_destroy(priv->crypto_dev); - mlx5_dev_ctx_release(priv->dev_ctx); - mlx5_free(priv->dev_ctx); return -1; } if (mlx5_mr_btree_init(&priv->mr_scache.cache, @@ -1034,8 +1009,6 @@ mlx5_crypto_dev_probe(struct mlx5_common_device *dev) DRV_LOG(ERR, "Failed to allocate shared cache MR memory."); mlx5_crypto_hw_global_release(priv); rte_cryptodev_pmd_destroy(priv->crypto_dev); - mlx5_dev_ctx_release(priv->dev_ctx); - mlx5_free(priv->dev_ctx); rte_errno = ENOMEM; return -rte_errno; } @@ -1085,8 +1058,7 @@ mlx5_crypto_dev_remove(struct mlx5_common_device *dev) mlx5_crypto_hw_global_release(priv); rte_cryptodev_pmd_destroy(priv->crypto_dev); claim_zero(mlx5_devx_cmd_destroy(priv->login_obj)); - mlx5_dev_ctx_release(priv->dev_ctx); - mlx5_free(priv->dev_ctx); + priv->dev_ctx = NULL; } return 0; } diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c index 812aadaaa4..c8134f064f 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -2882,31 +2882,24 @@ mlx5_verbs_dev_ctx_prepare(struct mlx5_dev_ctx *dev_ctx, struct rte_device *dev) int mlx5_os_net_probe(struct mlx5_common_device *dev) { - struct mlx5_dev_ctx *dev_ctx; + struct mlx5_dev_ctx *dev_ctx = &dev->ctx; uint8_t devx = 0; int ret; - dev_ctx = mlx5_malloc(MLX5_MEM_ZERO, sizeof(struct mlx5_dev_ctx), - RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); - if (dev_ctx == NULL) { - DRV_LOG(ERR, "Device context allocation failure."); - rte_errno = ENOMEM; - return -rte_errno; - } /* - * Initialize context device and allocate all its resources. - * Try to do it with DV first, then usual Verbs. + * Context device and all its resources are created and initialized + * while common probing, using DevX API. When DevX isn't supported, + * we are trying to create them by Verbs only for net driver. + * Here, we check if the ctx creates successfully, and if not try to + * create it by Verbs. */ - ret = mlx5_dev_ctx_prepare(dev_ctx, dev->dev, MLX5_CLASS_ETH); - if (ret < 0) { - goto error; - } else if (dev_ctx->ctx) { + if (dev_ctx->ctx) { devx = 1; DRV_LOG(DEBUG, "DevX is supported."); } else { ret = mlx5_verbs_dev_ctx_prepare(dev_ctx, dev->dev); if (ret < 0) - goto error; + return -rte_errno; DRV_LOG(DEBUG, "DevX is NOT supported."); } if (rte_eal_process_type() == RTE_PROC_PRIMARY) @@ -2915,19 +2908,12 @@ mlx5_os_net_probe(struct mlx5_common_device *dev) if (ret) { DRV_LOG(ERR, "unable to init PMD global data: %s", strerror(rte_errno)); - goto error; + return -rte_errno; } if (mlx5_dev_is_pci(dev->dev)) - ret = mlx5_os_pci_probe(dev, dev_ctx, devx); + return mlx5_os_pci_probe(dev, dev_ctx, devx); else - ret = mlx5_os_auxiliary_probe(dev->dev, dev_ctx, devx); - if (ret) - goto error; - return ret; -error: - mlx5_dev_ctx_release(dev_ctx); - mlx5_free(dev_ctx); - return ret; + return mlx5_os_auxiliary_probe(dev->dev, dev_ctx, devx); } /** diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index e0b180e83c..085bf87abc 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -2355,33 +2355,6 @@ mlx5_eth_find_next(uint16_t port_id, struct rte_device *odev) return port_id; } -/** - * Finds the device context that match the device. - * The existence of multiple ethdev per pci device is only with representors. - * On such case, it is enough to get only one of the ports as they all share - * the same device context. - * - * @param dev - * Pointer to the device. - * - * @return - * Pointer to the device context if found, NULL otherwise. - */ -static struct mlx5_dev_ctx * -mlx5_get_dev_ctx(struct rte_device *dev) -{ - struct mlx5_priv *priv; - uint16_t port_id; - - port_id = rte_eth_find_next_of(0, dev); - if (port_id == RTE_MAX_ETHPORTS) - return NULL; - priv = rte_eth_devices[port_id].data->dev_private; - if (priv == NULL) - return NULL; - return priv->sh->dev_ctx; -} - /** * Callback to remove a device. * @@ -2396,7 +2369,6 @@ mlx5_get_dev_ctx(struct rte_device *dev) int mlx5_net_remove(struct mlx5_common_device *dev) { - struct mlx5_dev_ctx *dev_ctx = mlx5_get_dev_ctx(dev->dev); uint16_t port_id; int ret = 0; @@ -2411,10 +2383,6 @@ mlx5_net_remove(struct mlx5_common_device *dev) ret |= rte_eth_dev_close(port_id); } - if (dev_ctx) { - mlx5_dev_ctx_release(dev_ctx); - mlx5_free(dev_ctx); - } return ret == 0 ? 0 : -EIO; } diff --git a/drivers/net/mlx5/windows/mlx5_os.c b/drivers/net/mlx5/windows/mlx5_os.c index f21fb60272..d269cf2f74 100644 --- a/drivers/net/mlx5/windows/mlx5_os.c +++ b/drivers/net/mlx5/windows/mlx5_os.c @@ -878,7 +878,7 @@ int mlx5_os_net_probe(struct mlx5_common_device *dev) { struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->dev); - struct mlx5_dev_ctx *dev_ctx; + struct mlx5_dev_ctx *dev_ctx = &dev->ctx; struct mlx5_dev_spawn_data spawn = { .pf_bond = -1 }; struct mlx5_dev_config dev_config; unsigned int dev_config_vf; @@ -895,16 +895,6 @@ mlx5_os_net_probe(struct mlx5_common_device *dev) strerror(rte_errno)); return -rte_errno; } - dev_ctx = mlx5_malloc(MLX5_MEM_ZERO, sizeof(struct mlx5_dev_ctx), - RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); - if (dev_ctx == NULL) { - DRV_LOG(ERR, "Device context allocation failure."); - rte_errno = ENOMEM; - return -rte_errno; - } - ret = mlx5_dev_ctx_prepare(dev_ctx, dev->dev, MLX5_CLASS_ETH); - if (ret < 0) - goto error; memset(&spawn.info, 0, sizeof(spawn.info)); spawn.max_port = 1; spawn.phys_port = 1; @@ -955,20 +945,14 @@ mlx5_os_net_probe(struct mlx5_common_device *dev) dev_config.decap_en = 0; dev_config.log_hp_size = MLX5_ARG_UNSET; spawn.eth_dev = mlx5_dev_spawn(dev->dev, dev_ctx, &spawn, &dev_config); - if (!spawn.eth_dev) { - ret = -rte_errno; - goto error; - } + if (!spawn.eth_dev) + return -rte_errno; restore = spawn.eth_dev->data->dev_flags; rte_eth_copy_pci_info(spawn.eth_dev, pci_dev); /* Restore non-PCI flags cleared by the above call. */ spawn.eth_dev->data->dev_flags |= restore; rte_eth_dev_probing_finish(spawn.eth_dev); return 0; -error: - mlx5_dev_ctx_release(dev_ctx); - mlx5_free(dev_ctx); - return ret; } /** diff --git a/drivers/regex/mlx5/mlx5_regex.c b/drivers/regex/mlx5/mlx5_regex.c index 78fa90797c..3772007d24 100644 --- a/drivers/regex/mlx5/mlx5_regex.c +++ b/drivers/regex/mlx5/mlx5_regex.c @@ -125,51 +125,36 @@ static int mlx5_regex_dev_probe(struct mlx5_common_device *mlx5_dev) { struct mlx5_regex_priv *priv = NULL; - struct mlx5_dev_ctx *dev_ctx = NULL; + struct mlx5_dev_ctx *dev_ctx = &mlx5_dev->ctx; struct mlx5_hca_attr attr; char name[RTE_REGEXDEV_NAME_MAX_LEN]; - const char *ibdev_name; + const char *ibdev_name = mlx5_os_get_ctx_device_name(dev_ctx->ctx); int ret; uint32_t val; - dev_ctx = rte_zmalloc("mlx5 context device", sizeof(*dev_ctx), - RTE_CACHE_LINE_SIZE); - if (dev_ctx == NULL) { - DRV_LOG(ERR, "Device context allocation failure."); - rte_errno = ENOMEM; - return -rte_errno; - } - ret = mlx5_dev_ctx_prepare(dev_ctx, mlx5_dev->dev, MLX5_CLASS_REGEX); - if (ret < 0) { - DRV_LOG(ERR, "Failed to create device context."); - rte_free(dev_ctx); - rte_errno = ENODEV; - return -rte_errno; - } - ibdev_name = mlx5_os_get_ctx_device_name(dev_ctx->ctx); DRV_LOG(INFO, "Probe device \"%s\".", ibdev_name); ret = mlx5_devx_cmd_query_hca_attr(dev_ctx->ctx, &attr); if (ret) { DRV_LOG(ERR, "Unable to read HCA capabilities."); rte_errno = ENOTSUP; - goto dev_error; + return -rte_errno; } else if (!attr.regex || attr.regexp_num_of_engines == 0) { DRV_LOG(ERR, "Not enough capabilities to support RegEx, maybe " "old FW/OFED version?"); rte_errno = ENOTSUP; - goto dev_error; + return -rte_errno; } if (mlx5_regex_engines_status(dev_ctx->ctx, 2)) { DRV_LOG(ERR, "RegEx engine error."); rte_errno = ENOMEM; - goto dev_error; + return -rte_errno; } priv = rte_zmalloc("mlx5 regex device private", sizeof(*priv), RTE_CACHE_LINE_SIZE); if (!priv) { DRV_LOG(ERR, "Failed to allocate private memory."); rte_errno = ENOMEM; - goto dev_error; + return -rte_errno; } priv->sq_ts_format = attr.sq_ts_format; priv->dev_ctx = dev_ctx; @@ -244,10 +229,6 @@ mlx5_regex_dev_probe(struct mlx5_common_device *mlx5_dev) if (priv->regexdev) rte_regexdev_unregister(priv->regexdev); dev_error: - if (dev_ctx) { - mlx5_dev_ctx_release(dev_ctx); - rte_free(dev_ctx); - } if (priv) rte_free(priv); return -rte_errno; @@ -279,10 +260,6 @@ mlx5_regex_dev_remove(struct mlx5_common_device *mlx5_dev) mlx5_glue->devx_free_uar(priv->uar); if (priv->regexdev) rte_regexdev_unregister(priv->regexdev); - if (priv->dev_ctx) { - mlx5_dev_ctx_release(priv->dev_ctx); - rte_free(priv->dev_ctx); - } rte_free(priv); } return 0; diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c index 6771445582..2b1b521313 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c @@ -506,34 +506,19 @@ static int mlx5_vdpa_dev_probe(struct mlx5_common_device *dev) { struct mlx5_vdpa_priv *priv = NULL; - struct mlx5_dev_ctx *dev_ctx = NULL; struct mlx5_hca_attr attr; int ret; - dev_ctx = mlx5_malloc(MLX5_MEM_ZERO, sizeof(struct mlx5_dev_ctx), - RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); - if (dev_ctx == NULL) { - DRV_LOG(ERR, "Device context allocation failure."); - rte_errno = ENOMEM; - return -rte_errno; - } - ret = mlx5_dev_ctx_prepare(dev_ctx, dev->dev, MLX5_CLASS_VDPA); - if (ret < 0) { - DRV_LOG(ERR, "Failed to create device context."); - mlx5_free(dev_ctx); - rte_errno = ENODEV; - return -rte_errno; - } - ret = mlx5_devx_cmd_query_hca_attr(dev_ctx->ctx, &attr); + ret = mlx5_devx_cmd_query_hca_attr(dev->ctx.ctx, &attr); if (ret) { DRV_LOG(ERR, "Unable to read HCA capabilities."); rte_errno = ENOTSUP; - goto error; + return -rte_errno; } else if (!attr.vdpa.valid || !attr.vdpa.max_num_virtio_queues) { DRV_LOG(ERR, "Not enough capabilities to support vdpa, maybe " "old FW/OFED version?"); rte_errno = ENOTSUP; - goto error; + return -rte_errno; } if (!attr.vdpa.queue_counters_valid) DRV_LOG(DEBUG, "No capability to support virtq statistics."); @@ -544,7 +529,7 @@ mlx5_vdpa_dev_probe(struct mlx5_common_device *dev) if (!priv) { DRV_LOG(ERR, "Failed to allocate private memory."); rte_errno = ENOMEM; - goto error; + return -rte_errno; } priv->caps = attr.vdpa; priv->log_max_rqt_size = attr.log_max_rqt_size; @@ -552,8 +537,8 @@ mlx5_vdpa_dev_probe(struct mlx5_common_device *dev) priv->qp_ts_format = attr.qp_ts_format; if (attr.num_lag_ports == 0) priv->num_lag_ports = 1; - priv->dev_ctx = dev_ctx; - priv->var = mlx5_glue->dv_alloc_var(dev_ctx->ctx, 0); + priv->dev_ctx = &dev->ctx; + priv->var = mlx5_glue->dv_alloc_var(priv->dev_ctx->ctx, 0); if (!priv->var) { DRV_LOG(ERR, "Failed to allocate VAR %u.", errno); goto error; @@ -578,10 +563,6 @@ mlx5_vdpa_dev_probe(struct mlx5_common_device *dev) mlx5_glue->dv_free_var(priv->var); rte_free(priv); } - if (dev_ctx) { - mlx5_dev_ctx_release(dev_ctx); - mlx5_free(dev_ctx); - } return -rte_errno; } @@ -610,10 +591,6 @@ mlx5_vdpa_dev_remove(struct mlx5_common_device *dev) } if (priv->vdev) rte_vdpa_unregister_device(priv->vdev); - if (priv->dev_ctx) { - mlx5_dev_ctx_release(priv->dev_ctx); - mlx5_free(priv->dev_ctx); - } pthread_mutex_destroy(&priv->vq_config_lock); rte_free(priv); }