From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4C021A06CC; Wed, 19 Oct 2022 16:45:04 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5B63042C23; Wed, 19 Oct 2022 16:44:04 +0200 (CEST) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2081.outbound.protection.outlook.com [40.107.93.81]) by mails.dpdk.org (Postfix) with ESMTP id 5643142C15 for ; Wed, 19 Oct 2022 16:44:02 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XoYG0gkeYG74/nxM3YMNTu4hm16t2yPJWbMfAVBkNq2F6KCpza1ooao6MCARhVFdnNr4ZWtQF1mWp/0SZKXmT4RTDVWlEAdZIoGALG8GwRm9OPY9B4ARlhrj9bl+nSdlWCbJpfNBQK/0adz6wGqKnIX9Z0Ui7p9rU40bVubcibBAoYkyh1ygzcw6PmEWt9ltegK6YwCvfMjjblcVLf0f20k8S7RV9DlxYHXTHdj4z99o9vMG7/Oes6Kkqr68Ndk6/58W84+eGnOA1Km9PhOANRnRIYrAR/fl1KxYFVWDu9GHrmMUa+yNP0UsWnX+QdNrCEoyThiKZ5gW7uixlmGx6A== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ltNuH4M7sLfKDUVr583xDwRN0p1P5NfyWY8svqrUJuI=; b=m29TsVSDIeANCeeOGCnecMENPiMUEEdh6O870mBsaYU8xAnU4WDLf38Z1gLHxlu8jfVvgWmKHAZEhlB+Tp9LtgUhDpwyhQGl2wuG78cXfjilJ1xfzthnKjuSqSigv0xnPVAHf1SRznn1bnO3e/MPKBJiSXqRWFzGFzRLG/FJun7rvHE/eSnabQVn5nG4I/kNlh/UaUqO4feUAhtQrPhSWc4riSkZAilBt+eWqcWctlRiy4KkJQYE4nEi9DuMupoZ1msgJ24wcJ+bHYIiHNFSnzCVwDMGgV7seKw6i99Zkm+/BCtV/Mk6Qd12hLye4jDBjQiW7iNT37HOa4Wwa9WOXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none (sender ip is 216.228.117.160) smtp.rcpttodomain=monjalon.net smtp.mailfrom=nvidia.com; dmarc=fail (p=reject sp=reject pct=100) action=oreject 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=ltNuH4M7sLfKDUVr583xDwRN0p1P5NfyWY8svqrUJuI=; b=kgoJnsmKoE/BGylLCjwPbQlHfFdnaXZwDIO10jsO21JlP5ti6mn9e3fJeR5n1a3zTE2oidMp+sF6YIxAawq2ID34l1FVw8pCMbVjpYyEnJ7wUy0BVHwQ/VfcCxYEf2kijyC59uxSevvmDGoUk2xqGl+h/21vAVb782KnTpnyrxk0x6QwZUJHRzl1uPf/rl9lfxrya90PStHwYFav6fvrS+WnQoTKSSs0XgteykcJh5Yp3sL3OWzMh8aJVdP9E5Tz4hWRji8WQ/kD0jfMTxigRSAU/CXaWiR1bgriZug+8QA2o53eEF6GMgifiTsQVXt/016yW3Yzgi0DADkZVU2smw== Received: from DM6PR18CA0034.namprd18.prod.outlook.com (2603:10b6:5:15b::47) by MW4PR12MB6900.namprd12.prod.outlook.com (2603:10b6:303:207::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.33; Wed, 19 Oct 2022 14:43:59 +0000 Received: from DM6NAM11FT040.eop-nam11.prod.protection.outlook.com (2603:10b6:5:15b:cafe::d8) by DM6PR18CA0034.outlook.office365.com (2603:10b6:5:15b::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.30 via Frontend Transport; Wed, 19 Oct 2022 14:43:59 +0000 X-MS-Exchange-Authentication-Results: spf=none (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=fail action=oreject header.from=nvidia.com; Received-SPF: None (protection.outlook.com: nvidia.com does not designate permitted sender hosts) Received: from mail.nvidia.com (216.228.117.160) by DM6NAM11FT040.mail.protection.outlook.com (10.13.173.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5746.16 via Frontend Transport; Wed, 19 Oct 2022 14:43:59 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.26; Wed, 19 Oct 2022 07:43:50 -0700 Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.29; Wed, 19 Oct 2022 07:43:48 -0700 From: Alex Vesker To: , , , , Matan Azrad CC: , Subject: [v4 12/18] net/mlx5/hws: Add HWS context object Date: Wed, 19 Oct 2022 17:42:52 +0300 Message-ID: <20221019144258.16282-13-valex@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20221019144258.16282-1-valex@nvidia.com> References: <20220922190345.394-1-valex@nvidia.com> <20221019144258.16282-1-valex@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6NAM11FT040:EE_|MW4PR12MB6900:EE_ X-MS-Office365-Filtering-Correlation-Id: fbeda8c5-3b5d-404f-9b97-08dab1e05b97 X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0kdZMuz9xUQ2lOCUSH2CUN+YyPajOvmOl6M6hCOBAAPu4RMQ/nDiF+j2ocA+rNnEk0phob6zZrvAHDD60q1k6kAyoYWsPK58a5h5KmmQzz9yuXyNFkgfJRgwgpwjBUqlbSMvXO/tx8sj8FTV6Rljy0xcoMIalRYeFBT6DBLsELVzsRCr08pfA1d1gaBq49utVZKt4WqscSTRm/NxukQiiZKjZdUMfU/o1aZWuzCzvW8qn48eVPczzKLQjKuVBc3UfrDEQ54QUIu9+9bDki7iI7GnVmnKrkpazux0rrZwdFvqY/hUfszdEGo7cMtA5p3LGNK+0xjls/1VU4F9HCleUAmZjF/mpjwf/BEAHjzbKEoxGBi6cr78bPa2/vFeANe2sbVFCUjJZFyz0aZ0v9sWaxpi5FUzAoUpzy11mU8fwkPghoy7gqmYXtlYxCH2qMDDjU7o64dbVjcmF+ufFAmwxtQs7Krghef/5D5iNNGAR4RGZQiHnUbhSxa2/RdAYjBDwKU8813eNNB5dxcuuMUdOv7rHaEEKce4vYPKkpp+fY5mzQdwZRWuNu5LCYAsEYucoiHc+Zs+2cvLRKx5dl8Yh9QOjXMwLzEaPKNQxgWTmt0Uy4LnuY5ZwHQDUmEzfXLGFCbpfjkqwuBjbi3Vwbw6HyutIEg1i+F7zRcFVSoGM0zutcqygrmxdFJ2nBe4hffaV/Ov+3y1VouB0Wc+l9GVaKCJBm3zbZI3Q+P8Xkor3RXilSn0+yo/HSrP6ElFc9P3V0OW06nav7d9ux/ZUV5e3w== X-Forefront-Antispam-Report: CIP:216.228.117.160; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge1.nvidia.com; CAT:NONE; SFS:(13230022)(4636009)(376002)(136003)(346002)(39860400002)(396003)(451199015)(40470700004)(36840700001)(46966006)(66899015)(8936002)(40480700001)(55016003)(36860700001)(7696005)(186003)(7636003)(47076005)(356005)(16526019)(2906002)(426003)(86362001)(26005)(2616005)(8676002)(40460700003)(5660300002)(4326008)(1076003)(83380400001)(82310400005)(70586007)(70206006)(478600001)(6666004)(316002)(41300700001)(36756003)(54906003)(82740400003)(6286002)(6636002)(336012)(107886003)(110136005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Oct 2022 14:43:59.2393 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fbeda8c5-3b5d-404f-9b97-08dab1e05b97 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.117.160]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT040.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6900 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 Context is the first mlx5dr object created, all sub object: table, matcher, rule, action are created using the context. The context holds the capabilities and send queues used for configuring the offloads to the HW. Signed-off-by: Alex Vesker --- drivers/net/mlx5/hws/mlx5dr_context.c | 223 ++++++++++++++++++++++++++ drivers/net/mlx5/hws/mlx5dr_context.h | 40 +++++ 2 files changed, 263 insertions(+) create mode 100644 drivers/net/mlx5/hws/mlx5dr_context.c create mode 100644 drivers/net/mlx5/hws/mlx5dr_context.h diff --git a/drivers/net/mlx5/hws/mlx5dr_context.c b/drivers/net/mlx5/hws/mlx5dr_context.c new file mode 100644 index 0000000000..ae86694a51 --- /dev/null +++ b/drivers/net/mlx5/hws/mlx5dr_context.c @@ -0,0 +1,223 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 NVIDIA Corporation & Affiliates + */ + +#include "mlx5dr_internal.h" + +static int mlx5dr_context_pools_init(struct mlx5dr_context *ctx) +{ + struct mlx5dr_pool_attr pool_attr = {0}; + uint8_t max_log_sz; + int i; + + if (mlx5dr_pat_init_pattern_cache(&ctx->pattern_cache)) + return rte_errno; + + /* Create an STC pool per FT type */ + pool_attr.pool_type = MLX5DR_POOL_TYPE_STC; + pool_attr.flags = MLX5DR_POOL_FLAGS_FOR_STC_POOL; + max_log_sz = RTE_MIN(MLX5DR_POOL_STC_LOG_SZ, ctx->caps->stc_alloc_log_max); + pool_attr.alloc_log_sz = RTE_MAX(max_log_sz, ctx->caps->stc_alloc_log_gran); + + for (i = 0; i < MLX5DR_TABLE_TYPE_MAX; i++) { + pool_attr.table_type = i; + ctx->stc_pool[i] = mlx5dr_pool_create(ctx, &pool_attr); + if (!ctx->stc_pool[i]) { + DR_LOG(ERR, "Failed to allocate STC pool [%d]", i); + goto free_stc_pools; + } + } + + return 0; + +free_stc_pools: + for (i = 0; i < MLX5DR_TABLE_TYPE_MAX; i++) + if (ctx->stc_pool[i]) + mlx5dr_pool_destroy(ctx->stc_pool[i]); + + mlx5dr_pat_uninit_pattern_cache(ctx->pattern_cache); + + return rte_errno; +} + +static void mlx5dr_context_pools_uninit(struct mlx5dr_context *ctx) +{ + int i; + + mlx5dr_pat_uninit_pattern_cache(ctx->pattern_cache); + + for (i = 0; i < MLX5DR_TABLE_TYPE_MAX; i++) { + if (ctx->stc_pool[i]) + mlx5dr_pool_destroy(ctx->stc_pool[i]); + } +} + +static int mlx5dr_context_init_pd(struct mlx5dr_context *ctx, + struct ibv_pd *pd) +{ + struct mlx5dv_pd mlx5_pd = {0}; + struct mlx5dv_obj obj; + int ret; + + if (pd) { + ctx->pd = pd; + } else { + ctx->pd = mlx5_glue->alloc_pd(ctx->ibv_ctx); + if (!ctx->pd) { + DR_LOG(ERR, "Failed to allocate PD"); + rte_errno = errno; + return rte_errno; + } + ctx->flags |= MLX5DR_CONTEXT_FLAG_PRIVATE_PD; + } + + obj.pd.in = ctx->pd; + obj.pd.out = &mlx5_pd; + + ret = mlx5_glue->dv_init_obj(&obj, MLX5DV_OBJ_PD); + if (ret) + goto free_private_pd; + + ctx->pd_num = mlx5_pd.pdn; + + return 0; + +free_private_pd: + if (ctx->flags & MLX5DR_CONTEXT_FLAG_PRIVATE_PD) + mlx5_glue->dealloc_pd(ctx->pd); + + return ret; +} + +static int mlx5dr_context_uninit_pd(struct mlx5dr_context *ctx) +{ + if (ctx->flags & MLX5DR_CONTEXT_FLAG_PRIVATE_PD) + return mlx5_glue->dealloc_pd(ctx->pd); + + return 0; +} + +static void mlx5dr_context_check_hws_supp(struct mlx5dr_context *ctx) +{ + struct mlx5dr_cmd_query_caps *caps = ctx->caps; + + /* HWS not supported on device / FW */ + if (!caps->wqe_based_update) { + DR_LOG(INFO, "Required HWS WQE based insertion cap not supported"); + return; + } + + /* Current solution requires all rules to set reparse bit */ + if ((!caps->nic_ft.reparse || !caps->fdb_ft.reparse) || + !IS_BIT_SET(caps->rtc_reparse_mode, MLX5_IFC_RTC_REPARSE_ALWAYS)) { + DR_LOG(INFO, "Required HWS reparse cap not supported"); + return; + } + + /* FW/HW must support 8DW STE */ + if (!IS_BIT_SET(caps->ste_format, MLX5_IFC_RTC_STE_FORMAT_8DW)) { + DR_LOG(INFO, "Required HWS STE format not supported"); + return; + } + + /* Adding rules by hash and by offset are requirements */ + if (!IS_BIT_SET(caps->rtc_index_mode, MLX5_IFC_RTC_STE_UPDATE_MODE_BY_HASH) || + !IS_BIT_SET(caps->rtc_index_mode, MLX5_IFC_RTC_STE_UPDATE_MODE_BY_OFFSET)) { + DR_LOG(INFO, "Required HWS RTC update mode not supported"); + return; + } + + /* Support for SELECT definer ID is required */ + if (!IS_BIT_SET(caps->definer_format_sup, MLX5_IFC_DEFINER_FORMAT_ID_SELECT)) { + DR_LOG(INFO, "Required HWS Dynamic definer not supported"); + return; + } + + ctx->flags |= MLX5DR_CONTEXT_FLAG_HWS_SUPPORT; +} + +static int mlx5dr_context_init_hws(struct mlx5dr_context *ctx, + struct mlx5dr_context_attr *attr) +{ + int ret; + + mlx5dr_context_check_hws_supp(ctx); + + if (!(ctx->flags & MLX5DR_CONTEXT_FLAG_HWS_SUPPORT)) + return 0; + + ret = mlx5dr_context_init_pd(ctx, attr->pd); + if (ret) + return ret; + + ret = mlx5dr_context_pools_init(ctx); + if (ret) + goto uninit_pd; + + ret = mlx5dr_send_queues_open(ctx, attr->queues, attr->queue_size); + if (ret) + goto pools_uninit; + + return 0; + +pools_uninit: + mlx5dr_context_pools_uninit(ctx); +uninit_pd: + mlx5dr_context_uninit_pd(ctx); + return ret; +} + +static void mlx5dr_context_uninit_hws(struct mlx5dr_context *ctx) +{ + if (!(ctx->flags & MLX5DR_CONTEXT_FLAG_HWS_SUPPORT)) + return; + + mlx5dr_send_queues_close(ctx); + mlx5dr_context_pools_uninit(ctx); + mlx5dr_context_uninit_pd(ctx); +} + +struct mlx5dr_context *mlx5dr_context_open(struct ibv_context *ibv_ctx, + struct mlx5dr_context_attr *attr) +{ + struct mlx5dr_context *ctx; + int ret; + + ctx = simple_calloc(1, sizeof(*ctx)); + if (!ctx) { + rte_errno = ENOMEM; + return NULL; + } + + ctx->ibv_ctx = ibv_ctx; + pthread_spin_init(&ctx->ctrl_lock, PTHREAD_PROCESS_PRIVATE); + + ctx->caps = simple_calloc(1, sizeof(*ctx->caps)); + if (!ctx->caps) + goto free_ctx; + + ret = mlx5dr_cmd_query_caps(ibv_ctx, ctx->caps); + if (ret) + goto free_caps; + + ret = mlx5dr_context_init_hws(ctx, attr); + if (ret) + goto free_caps; + + return ctx; + +free_caps: + simple_free(ctx->caps); +free_ctx: + simple_free(ctx); + return NULL; +} + +int mlx5dr_context_close(struct mlx5dr_context *ctx) +{ + mlx5dr_context_uninit_hws(ctx); + simple_free(ctx->caps); + pthread_spin_destroy(&ctx->ctrl_lock); + simple_free(ctx); + return 0; +} diff --git a/drivers/net/mlx5/hws/mlx5dr_context.h b/drivers/net/mlx5/hws/mlx5dr_context.h new file mode 100644 index 0000000000..b0c7802daf --- /dev/null +++ b/drivers/net/mlx5/hws/mlx5dr_context.h @@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2022 NVIDIA Corporation & Affiliates + */ + +#ifndef MLX5DR_CONTEXT_H_ +#define MLX5DR_CONTEXT_H_ + +enum mlx5dr_context_flags { + MLX5DR_CONTEXT_FLAG_HWS_SUPPORT = 1 << 0, + MLX5DR_CONTEXT_FLAG_PRIVATE_PD = 1 << 1, +}; + +enum mlx5dr_context_shared_stc_type { + MLX5DR_CONTEXT_SHARED_STC_DECAP = 0, + MLX5DR_CONTEXT_SHARED_STC_POP = 1, + MLX5DR_CONTEXT_SHARED_STC_MAX = 2, +}; + +struct mlx5dr_context_common_res { + struct mlx5dr_action_default_stc *default_stc; + struct mlx5dr_action_shared_stc *shared_stc[MLX5DR_CONTEXT_SHARED_STC_MAX]; + struct mlx5dr_cmd_forward_tbl *default_miss; +}; + +struct mlx5dr_context { + struct ibv_context *ibv_ctx; + struct mlx5dr_cmd_query_caps *caps; + struct ibv_pd *pd; + uint32_t pd_num; + struct mlx5dr_pool *stc_pool[MLX5DR_TABLE_TYPE_MAX]; + struct mlx5dr_context_common_res common_res[MLX5DR_TABLE_TYPE_MAX]; + struct mlx5dr_pattern_cache *pattern_cache; + pthread_spinlock_t ctrl_lock; + enum mlx5dr_context_flags flags; + struct mlx5dr_send_engine *send_queue; + size_t queues; + LIST_HEAD(table_head, mlx5dr_table) head; +}; + +#endif /* MLX5DR_CONTEXT_H_ */ -- 2.18.1