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 5E698A0524; Wed, 5 May 2021 08:51:45 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4060341110; Wed, 5 May 2021 08:51:22 +0200 (CEST) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2049.outbound.protection.outlook.com [40.107.244.49]) by mails.dpdk.org (Postfix) with ESMTP id BA171410F3 for ; Wed, 5 May 2021 08:51:16 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cuk7HgGEmZuW1MXHyPRXOvOfOguGYVE5FTlnzERNQmkdjwGvfzqVxayEN1s6H7u4abkXJq4kpaPeqAq+H4GZhqvICG1tU3/rSoxJUdjl5MP2nfH+wA+LpdKtmKL86nECtS3A3YrJg4hyVr0JeZ7GH1rySM2F7a/yA9CWLe+Fcdcw66GFrTAhbGKpFORsQlzCXk763aJX+bp4g01Ju4vtwLp8kL8WiwBV1pLZRdXCcVXf/gN53IhH5WdXKG21iwp+gFiMRd74/qLdl7LQzMlsfDLhQBDwB5+vR3OsxUD2Ne2J0w2svTV1U4zT6RulzLkvTLCMYi+bwHaE5NbRnsL4cA== 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=lFtVPxmiGdnzMFnQcOUr84MkOp6rQV+JzmP2o471acI=; b=Rp6Z7XLiVzRftVHpYcVxlUFXBLU6xqIdPrgOfd3IqsVp0lnkjarmGBfapJ3wTi676tUjIBpS33LAVOh+U70xCalwvuoC6EOEMvCx1UO0YYIXrVRfLvDqIuZzwFX+9Y14qRPsX3TwhCcK2Z8lWlXEJh9FC265nB1D6aAqFYlM9EDyyDCzSFpZDnX38M+r5BRKpqNo+P0TVkoceMwUIjph1rEWBbx0GKIU7wwZzabrpLMa6kKT/vNvka3DoWFZXRs9SDmXk69iWjVjJbUuQnzrqZpRof3gSVkZp9dCD+vOOF7C0n0wd3B9SJIZ/bIdsCugqkvc/jVyfGAnTFCcsALhEA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none 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=lFtVPxmiGdnzMFnQcOUr84MkOp6rQV+JzmP2o471acI=; b=uKJR6mRL7NPvAYMGHH2lyCRnaV0Xm6KR6DVi5QYNY1WxYXfFyCqepIdnk7bIBPkHI2+H7hT1iL8mn3J5vWFOK3qDZUQNPnGaoMDXdogRP7SXTisDbq3xjxbp7CuVdleh81ONefbNpFoUS73O1RsCjQyd2/G50iujISd9P7chz10F24/qYOwRE8BE/Q5v7eycvttJ8mIo76fln/w67rXApLL85bSa4xxm0Neel/UKvtew+yHRHaSYwjy53OYs6VCbsPxOTJseT2/GWfkLL5TpPZtcl6J3DHat4gJzW4v9JBllxURjVYkrvJLIQpX07lEkqiue1RmmtxHMg+0esc8P1A== Received: from BN6PR16CA0048.namprd16.prod.outlook.com (2603:10b6:405:14::34) by BYAPR12MB4711.namprd12.prod.outlook.com (2603:10b6:a03:95::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.40; Wed, 5 May 2021 06:51:15 +0000 Received: from BN8NAM11FT046.eop-nam11.prod.protection.outlook.com (2603:10b6:405:14:cafe::79) by BN6PR16CA0048.outlook.office365.com (2603:10b6:405:14::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4108.25 via Frontend Transport; Wed, 5 May 2021 06:51:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) 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.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT046.mail.protection.outlook.com (10.13.177.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4108.25 via Frontend Transport; Wed, 5 May 2021 06:51:14 +0000 Received: from nvidia.com (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 5 May 2021 06:50:44 +0000 From: Bing Zhao To: , , CC: , , Date: Wed, 5 May 2021 09:49:55 +0300 Message-ID: <20210505065008.30680-5-bingz@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210505065008.30680-1-bingz@nvidia.com> References: <20210427153811.11554-1-bingz@nvidia.com> <20210505065008.30680-1-bingz@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL101.nvidia.com (172.20.187.10) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b20f0fb6-29e6-4b85-1348-08d90f922d49 X-MS-TrafficTypeDiagnostic: BYAPR12MB4711: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MI/McWlf1yaplkvFu2d18FmF0XTd1wtRi0TlmzTJNyiuxkyC86QhhhF3F3zN+ZDfF3OBkUZPr8CrCMhQVVLg1wC4bP4OPzl/P4ipjbvalX0ktWB4/Z2bLz0GyQVufgiptpO/MAPz9If4vtnQNgkx6eW7J9gHMvuNbtXGL4+YtOAiPs1EmKoL2n3h1LEx+Hq1B97PpVRThI0s4FIBj+lEPcUTknN376zWRdeIAbmloP1l0x0+5YHDLZyTvRnyIFnIx5UdQCrPhPjkbWc+VxEaAdSyYCO3MNEgG79ohLsrkkTqtIkIvJqpW/i+Kb3r4LqC6btq+GgDbGRUU5dAcI2vaizMafLd4cOqm/yMxy/qzTmLhPCcBAonF/T7Sf22b88aE1SBq9JDY7GRLoZ6L6xr/Vi8oslBb9s3OZZIZ5WxslN3W/LiPFA+Z4AQf70+yOUm737aGcpOKz65zZnYIyDUCzN6xNWX4zfm1XStOCWhRTBC+VScTCgmx/8T5FkH/uvOjBt/AE/G1BulXEd1w0nUOZLByLLbF9hlS4HSvobbxiK6Br6/CrivUVulm0QcDp2zJ3ff99MdUqN5os8O2wy3gBcYB0t/IXHe1fD0KAEpNT7rWLiC0qTsHXIEytheYmIypBXIrJTeTeBi0ZlokOfiGPIL41PsDaLjUUuBNlIDbWs= X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(136003)(346002)(396003)(376002)(39860400002)(36840700001)(46966006)(70206006)(26005)(110136005)(107886003)(86362001)(70586007)(6666004)(186003)(426003)(82740400003)(336012)(7636003)(8676002)(47076005)(82310400003)(316002)(7696005)(478600001)(5660300002)(16526019)(6286002)(2906002)(36756003)(36860700001)(54906003)(2616005)(55016002)(1076003)(83380400001)(356005)(36906005)(8936002)(4326008); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2021 06:51:14.7372 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b20f0fb6-29e6-4b85-1348-08d90f922d49 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.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT046.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB4711 Subject: [dpdk-dev] [PATCH v3 04/17] net/mlx5: initialization of CT management 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" The definitions of ASO connection tracking objects management structures are added. Considering performance, the bulk allocation of ASO CT objects should be used. The maximal value per bulk and the granularity could be fetched from HCA capabilities 2. Right now, a fixed number of 64 is used for each bulk for a better management purpose. The ASO QP for CT is initialized, the SQ will be used for both modify and query command. Signed-off-by: Bing Zhao --- drivers/net/mlx5/linux/mlx5_os.c | 13 +++++++++ drivers/net/mlx5/mlx5.c | 36 +++++++++++++++++++++++ drivers/net/mlx5/mlx5.h | 50 ++++++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow_aso.c | 50 ++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+) diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c index 479ee7d8d1..5ac787106d 100644 --- a/drivers/net/mlx5/linux/mlx5_os.c +++ b/drivers/net/mlx5/linux/mlx5_os.c @@ -1323,6 +1323,19 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, DRV_LOG(DEBUG, "Flow Hit ASO is supported."); } #endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO */ +#if defined(HAVE_MLX5_DR_CREATE_ACTION_ASO) && \ + defined(HAVE_MLX5_DR_ACTION_ASO_CT) + if (config->hca_attr.ct_offload && + priv->mtr_color_reg == REG_C_3) { + err = mlx5_flow_aso_ct_mng_init(sh); + if (err) { + err = -err; + goto error; + } + DRV_LOG(DEBUG, "CT ASO is supported."); + sh->ct_aso_en = 1; + } +#endif /* HAVE_MLX5_DR_CREATE_ACTION_ASO && HAVE_MLX5_DR_ACTION_ASO_CT */ #if defined(HAVE_MLX5DV_DR) && defined(HAVE_MLX5_DR_CREATE_ACTION_FLOW_SAMPLE) if (config->hca_attr.log_max_ft_sampler_num > 0 && config->dv_flow_en) { diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 8cd6f1eaee..86dbe6d573 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -670,6 +670,42 @@ mlx5_age_event_prepare(struct mlx5_dev_ctx_shared *sh) } } +/* + * Initialize the ASO connection tracking structure. + * + * @param[in] sh + * Pointer to mlx5_dev_ctx_shared object. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +int +mlx5_flow_aso_ct_mng_init(struct mlx5_dev_ctx_shared *sh) +{ + int err; + + if (sh->ct_mng) + return 0; + sh->ct_mng = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*sh->ct_mng), + RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY); + if (!sh->ct_mng) { + DRV_LOG(ERR, "ASO CT management allocation failed."); + rte_errno = ENOMEM; + return -rte_errno; + } + err = mlx5_aso_queue_init(sh, ASO_OPC_MOD_CONNECTION_TRACKING); + if (err) { + mlx5_free(sh->ct_mng); + /* rte_errno should be extracted from the failure. */ + rte_errno = EINVAL; + return -rte_errno; + } + rte_spinlock_init(&sh->ct_mng->ct_sl); + rte_rwlock_init(&sh->ct_mng->resize_rwl); + LIST_INIT(&sh->ct_mng->free_cts); + return 0; +} + /** * Initialize the flow resources' indexed mempool. * diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index c62977613a..1a5c78fa3a 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -983,6 +983,52 @@ struct mlx5_bond_info { } ports[MLX5_BOND_MAX_PORTS]; }; +/* Number of connection tracking objects per pool: must be a power of 2. */ +#define MLX5_ASO_CT_ACTIONS_PER_POOL 64 + +/* ASO Conntrack state. */ +enum mlx5_aso_ct_state { + ASO_CONNTRACK_FREE, /* Inactive, in the free list. */ + ASO_CONNTRACK_WAIT, /* WQE sent in the SQ. */ + ASO_CONNTRACK_READY, /* CQE received w/o error. */ + ASO_CONNTRACK_QUERY, /* WQE for query sent. */ + ASO_CONNTRACK_MAX, /* Guard. */ +}; + +/* Generic ASO connection tracking structure. */ +struct mlx5_aso_ct_action { + LIST_ENTRY(mlx5_aso_ct_action) next; /* Pointer to the next ASO CT. */ + void *dr_action_orig; /* General action object for original dir. */ + void *dr_action_rply; /* General action object for reply dir. */ + uint32_t refcnt; /* Action used count in device flows. */ + uint16_t offset; /* Offset of ASO CT in DevX objects bulk. */ + uint16_t peer; /* The only peer port index could also use this CT. */ + enum mlx5_aso_ct_state state; /* ASO CT state. */ + bool is_original; /* The direction of the DR action to be used. */ +}; + +/* ASO connection tracking software pool definition. */ +struct mlx5_aso_ct_pool { + uint16_t index; /* Pool index in pools array. */ + struct mlx5_devx_obj *devx_obj; + /* The first devx object in the bulk, used for freeing (not yet). */ + struct mlx5_aso_ct_action actions[MLX5_ASO_CT_ACTIONS_PER_POOL]; + /* CT action structures bulk. */ +}; + +LIST_HEAD(aso_ct_list, mlx5_aso_ct_action); + +/* Pools management structure for ASO connection tracking pools. */ +struct mlx5_aso_ct_pools_mng { + struct mlx5_aso_ct_pool **pools; + uint16_t n; /* Total number of pools. */ + uint16_t next; /* Number of pools in use, index of next free pool. */ + rte_spinlock_t ct_sl; /* The ASO CT free list lock. */ + rte_rwlock_t resize_rwl; /* The ASO CT pool resize lock. */ + struct aso_ct_list free_cts; /* Free ASO CT objects list. */ + struct mlx5_aso_sq aso_sq; /* ASO queue objects. */ +}; + /* * Shared Infiniband device context for Master/Representors * which belong to same IB device with multiple IB ports. @@ -996,6 +1042,7 @@ struct mlx5_dev_ctx_shared { uint32_t sq_ts_format:2; /* SQ timestamp formats supported. */ uint32_t qp_ts_format:2; /* QP timestamp formats supported. */ uint32_t meter_aso_en:1; /* Flow Meter ASO is supported. */ + uint32_t ct_aso_en:1; /* Connection Tracking ASO is supported. */ uint32_t max_port; /* Maximal IB device port index. */ struct mlx5_bond_info bond; /* Bonding information. */ void *ctx; /* Verbs/DV/DevX context. */ @@ -1058,6 +1105,8 @@ struct mlx5_dev_ctx_shared { rte_spinlock_t geneve_tlv_opt_sl; /* Lock for geneve tlv resource */ struct mlx5_flow_mtr_mng *mtrmng; /* Meter management structure. */ + struct mlx5_aso_ct_pools_mng *ct_mng; + /* Management data for ASO connection tracking. */ struct mlx5_dev_shared_port port[]; /* per device port data array. */ }; @@ -1355,6 +1404,7 @@ bool mlx5_flex_parser_ecpri_exist(struct rte_eth_dev *dev); int mlx5_flex_parser_ecpri_alloc(struct rte_eth_dev *dev); int mlx5_flow_aso_age_mng_init(struct mlx5_dev_ctx_shared *sh); int mlx5_aso_flow_mtrs_mng_init(struct mlx5_dev_ctx_shared *sh); +int mlx5_flow_aso_ct_mng_init(struct mlx5_dev_ctx_shared *sh); /* mlx5_ethdev.c */ diff --git a/drivers/net/mlx5/mlx5_flow_aso.c b/drivers/net/mlx5/mlx5_flow_aso.c index 300987d0e9..c24d865284 100644 --- a/drivers/net/mlx5/mlx5_flow_aso.c +++ b/drivers/net/mlx5/mlx5_flow_aso.c @@ -186,6 +186,43 @@ mlx5_aso_mtr_init_sq(struct mlx5_aso_sq *sq) } } +/* + * Initialize Send Queue used for ASO connection tracking. + * + * @param[in] sq + * ASO SQ to initialize. + */ +static void +mlx5_aso_ct_init_sq(struct mlx5_aso_sq *sq) +{ + volatile struct mlx5_aso_wqe *restrict wqe; + int i; + int size = 1 << sq->log_desc_n; + uint64_t addr; + + /* All the next fields state should stay constant. */ + for (i = 0, wqe = &sq->sq_obj.aso_wqes[0]; i < size; ++i, ++wqe) { + wqe->general_cseg.sq_ds = rte_cpu_to_be_32((sq->sqn << 8) | + (sizeof(*wqe) >> 4)); + /* One unique MR for the query data. */ + wqe->aso_cseg.lkey = rte_cpu_to_be_32(sq->mr.mkey->id); + /* Magic number 64 represents the length of a ASO CT obj. */ + addr = (uint64_t)((uintptr_t)sq->mr.addr + i * 64); + wqe->aso_cseg.va_h = rte_cpu_to_be_32((uint32_t)(addr >> 32)); + wqe->aso_cseg.va_l_r = rte_cpu_to_be_32((uint32_t)addr | 1u); + /* + * The values of operand_masks are different for modify + * and query. + * And data_mask may be different for each modification. In + * query, it could be zero and ignored. + * CQE generation is always needed, in order to decide when + * it is available to create the flow or read the data. + */ + wqe->general_cseg.flags = RTE_BE32(MLX5_COMP_ALWAYS << + MLX5_COMP_MODE_OFFSET); + } +} + /** * Create Send Queue used for ASO access. * @@ -293,6 +330,19 @@ mlx5_aso_queue_init(struct mlx5_dev_ctx_shared *sh, return -1; mlx5_aso_mtr_init_sq(&sh->mtrmng->pools_mng.sq); break; + case ASO_OPC_MOD_CONNECTION_TRACKING: + /* 64B per object for query. */ + if (mlx5_aso_reg_mr(sh, 64 * sq_desc_n, + &sh->ct_mng->aso_sq.mr, 0)) + return -1; + if (mlx5_aso_sq_create(sh->ctx, &sh->ct_mng->aso_sq, 0, + sh->tx_uar, sh->pdn, MLX5_ASO_QUEUE_LOG_DESC, + sh->sq_ts_format)) { + mlx5_aso_dereg_mr(sh, &sh->ct_mng->aso_sq.mr); + return -1; + } + mlx5_aso_ct_init_sq(&sh->ct_mng->aso_sq); + break; default: DRV_LOG(ERR, "Unknown ASO operation mode"); return -1; -- 2.27.0