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 CFD99A0353; Thu, 24 Feb 2022 04:11:10 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0B8A741169; Thu, 24 Feb 2022 04:11:00 +0100 (CET) Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2076.outbound.protection.outlook.com [40.107.243.76]) by mails.dpdk.org (Postfix) with ESMTP id C7A8441163 for ; Thu, 24 Feb 2022 04:10:57 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ih0FQ1adPgOhphwAWk0dLcmQ+gl2I/yEPTsyoPElB/KbfByOesSjbDn7vRKimxxsFDss/cFjq/2JitsuKgEXGyPjzjiYMbDq//N5Sa7eQY+6JepKB57W0i+DGz5QpA4Wm/OvcbjTKbZm9mDGdudWjumnTrTp3w6BAteh+pSdNxn3qPuVhrsqOQgJirB1CoeFtuX+suVmY971R0dMuYoz9bKs6g1flARqGMDO/3hqo0O6dyjbuVSo2natnRlz9TWkiHXpeNTYj5NQtTVQJNVxgcVlkb2f+Tkt8f25J7hwmJNNUiM0+Po6VA1PfDfmj6W7yx885cTzE0fZebLlfdhCUg== 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=CeXIHH59JcXhSwZMeQK2SkIWTAW55VrDquiNdSNCJ44=; b=LbfoajwHo8reEw8u5RAov+iMSzXWPIAOzjDVQ/8J7YESvTGGzeEH8MM7h3zjB6iV0R9PEYD5kOhffcou+GF9MAR9cf/941fT8O3BEnS2hHWCPPQrZ5rb6z9fVmYrqatZ96i1lvlo1RM3/kabq2ZIXT51Ya4hKjqhFlnBJUZ+P/PirH0qA6Nv2U9vkU3Pna3UD0i+5K5k9sKP+rlcegGqhFuEfS4N+9ONtwWKa6ymT66HbGwK6LSRpi967NiUoL5j4nOUDy0jU0UnbDVzaYvlH1cxDeKK8stew0BFM/vGm9k4nakr4RDKUs0nuKyEbwgOwf4eWD4sENsvN7tEJjt66w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.238) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject 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=CeXIHH59JcXhSwZMeQK2SkIWTAW55VrDquiNdSNCJ44=; b=W59ar1AeVe7i4Axb1SmDBVZlKDuaXn5YaJxhUKTzqz8a9Vky/CuuJBeL+ACO/o47oWe6h3AxAfylJS5AFizuPP+aAg/8MPZWm4fUTEtWbQaUwKbqeXGDuw99KPEdA9m+PqpCD/nxtPfQXLjNWk5e3W8fKKmTI1LcFYbrS7Vr02Jq6iKxCvMJgBVsJDULF8yH9qrZrtF8V4DIPqvW5id4yXQlaGFY45UQPdM0lFciQNsFtoPCwmXx/AGTEvH5aWAHKHVpbuVB23EK0quPdC6Ytu5R1K+nVBL7oMLVUKxclmCBXP7YsyfKbzVI7eXRJlo2cPya6foGtSwH+axglQ8+Ug== Received: from DM5PR04CA0030.namprd04.prod.outlook.com (2603:10b6:3:12b::16) by MN2PR12MB3424.namprd12.prod.outlook.com (2603:10b6:208:cc::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Thu, 24 Feb 2022 03:10:55 +0000 Received: from DM6NAM11FT004.eop-nam11.prod.protection.outlook.com (2603:10b6:3:12b:cafe::52) by DM5PR04CA0030.outlook.office365.com (2603:10b6:3:12b::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.23 via Frontend Transport; Thu, 24 Feb 2022 03:10:55 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.238) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 12.22.5.238 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.238; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.238) by DM6NAM11FT004.mail.protection.outlook.com (10.13.172.217) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 03:10:55 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL105.nvidia.com (10.27.9.14) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 24 Feb 2022 03:10:55 +0000 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.9; Wed, 23 Feb 2022 19:10:52 -0800 From: Suanming Mou To: , CC: , , Subject: [PATCH v3 05/14] net/mlx5: add pattern template management Date: Thu, 24 Feb 2022 05:10:20 +0200 Message-ID: <20220224031029.14049-6-suanmingm@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20220224031029.14049-1-suanmingm@nvidia.com> References: <20220210162926.20436-1-suanmingm@nvidia.com> <20220224031029.14049-1-suanmingm@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail201.nvidia.com (10.129.68.8) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 00af76f6-3d63-427d-71af-08d9f74345c3 X-MS-TrafficTypeDiagnostic: MN2PR12MB3424:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6g8lCrTSWDluJXGAbEXr2uzXlAVAca/rpQfvu9m6jIbco5SbuGre2J8PD8f3e1RvGVAMd1XWYFOeXjk32APCxeeGSAaJdRbSTgH/oym+GIwRJEKXuMOhi6FFt9q5fQtSnuGS6bBpQa0M+YveY9iIKWJExuLehHgmeJy68zaWAcZ2/GZWm6VmJZaDiPtaxuBnn4odG6M325xy0hcO8h0cv45FaXAhuvBuw9HkO2wrfZDHFg0buK2ARgiY+cWHwgVGubUjqQhXJI2b9b/dvZvD2sAZS11ooHEgDg0c9EU0z3EcabRPRYXD7eH70VvS39840LoCoKtlF2WX0wcyfGKpdf8rd8XAc/896VeCQWBXLyRTvNRnu1WOk0pVS+TAxhYjyvpLkMSanLDvVQrANupNUAwHbXErAiOMMAWiCuPAlPvuyqrnf+rWvudwDZRrqUB+7SjxyrEacskVemjfp4LmLzCKGVvZWB7hcqAPP326pget148MDHRdwJ1lwLcQR76mU2MNhZHry5H3GZ5HQ8Ytm4OkyfGXhcZunwNPNIUAZf7rsVWSe9KWbhgKAIjQOu/nNVkrxGY/4nNAoMTsYXWetQCANWI2IyYqY4slGNIIb+NJ/4UvhTJBcka2LCm9Qsyphjn9IHdKenIPA8tojQqSqbDcF5/GK8CdnA8LKAKYeeSmIo1xcJTyIh4oaoxOkEZ4oA6S8sJ3SIkDsK6J6Y3XJQ== X-Forefront-Antispam-Report: CIP:12.22.5.238; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(8936002)(2906002)(316002)(54906003)(6636002)(508600001)(110136005)(6666004)(16526019)(86362001)(7696005)(2616005)(6286002)(1076003)(70206006)(4326008)(70586007)(426003)(336012)(186003)(26005)(8676002)(55016003)(356005)(81166007)(47076005)(83380400001)(36860700001)(5660300002)(82310400004)(40460700003)(36756003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 03:10:55.3691 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 00af76f6-3d63-427d-71af-08d9f74345c3 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[12.22.5.238]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT004.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3424 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 The pattern template defines flows that have the same matching fields but with different matching values. For example, matching on 5 tuple TCP flow, the template will be (eth(null) + IPv4(source + dest) + TCP(s_port + d_port) while the values for each rule will be different. Due to the pattern template can be used in different domains, the items will only be cached in pattern template create stage, while the template is binded to a dedicated table, the HW criteria will be created and saved to the table. The pattern templates can be used by multiple tables. But different tables create the same criteria and will not share the matcher between each other in order to have better performance. This commit adds pattern template management. Signed-off-by: Suanming Mou Acked-by: Viacheslav Ovsiienko --- drivers/net/mlx5/mlx5.h | 2 + drivers/net/mlx5/mlx5_flow.c | 76 +++++++++++++++++++++++++++++ drivers/net/mlx5/mlx5_flow.h | 24 +++++++++ drivers/net/mlx5/mlx5_flow_hw.c | 86 +++++++++++++++++++++++++++++++++ 4 files changed, 188 insertions(+) diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index f0edf7f559..e36adde708 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -1502,6 +1502,8 @@ struct mlx5_priv { /* Flex items have been created on the port. */ uint32_t flex_item_map; /* Map of allocated flex item elements. */ #if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) + /* Item template list. */ + LIST_HEAD(flow_hw_itt, rte_flow_pattern_template) flow_hw_itt; struct mlx5dr_context *dr_ctx; /**< HW steering DR context. */ uint32_t nb_queue; /* HW steering queue number. */ /* HW steering queue polling mechanism job descriptor LIFO. */ diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 554ebc804d..673e0ec55f 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -817,6 +817,17 @@ mlx5_flow_port_configure(struct rte_eth_dev *dev, const struct rte_flow_queue_attr *queue_attr[], struct rte_flow_error *err); +static struct rte_flow_pattern_template * +mlx5_flow_pattern_template_create(struct rte_eth_dev *dev, + const struct rte_flow_pattern_template_attr *attr, + const struct rte_flow_item items[], + struct rte_flow_error *error); + +static int +mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev, + struct rte_flow_pattern_template *template, + struct rte_flow_error *error); + static const struct rte_flow_ops mlx5_flow_ops = { .validate = mlx5_flow_validate, .create = mlx5_flow_create, @@ -839,6 +850,8 @@ static const struct rte_flow_ops mlx5_flow_ops = { .flex_item_release = mlx5_flow_flex_item_release, .info_get = mlx5_flow_info_get, .configure = mlx5_flow_port_configure, + .pattern_template_create = mlx5_flow_pattern_template_create, + .pattern_template_destroy = mlx5_flow_pattern_template_destroy, }; /* Tunnel information. */ @@ -7924,6 +7937,69 @@ mlx5_flow_port_configure(struct rte_eth_dev *dev, return fops->configure(dev, port_attr, nb_queue, queue_attr, error); } +/** + * Create flow item template. + * + * @param[in] dev + * Pointer to the rte_eth_dev structure. + * @param[in] attr + * Pointer to the item template attributes. + * @param[in] items + * The template item pattern. + * @param[out] error + * Pointer to error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static struct rte_flow_pattern_template * +mlx5_flow_pattern_template_create(struct rte_eth_dev *dev, + const struct rte_flow_pattern_template_attr *attr, + const struct rte_flow_item items[], + struct rte_flow_error *error) +{ + const struct mlx5_flow_driver_ops *fops; + + if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW) { + rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "pattern create with incorrect steering mode"); + return NULL; + } + fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW); + return fops->pattern_template_create(dev, attr, items, error); +} + +/** + * Destroy flow item template. + * + * @param[in] dev + * Pointer to the rte_eth_dev structure. + * @param[in] template + * Pointer to the item template to be destroyed. + * @param[out] error + * Pointer to error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +mlx5_flow_pattern_template_destroy(struct rte_eth_dev *dev, + struct rte_flow_pattern_template *template, + struct rte_flow_error *error) +{ + const struct mlx5_flow_driver_ops *fops; + + if (flow_get_drv_type(dev, NULL) != MLX5_FLOW_TYPE_HW) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "pattern destroy with incorrect steering mode"); + fops = flow_get_drv_ops(MLX5_FLOW_TYPE_HW); + return fops->pattern_template_destroy(dev, template, error); +} + /** * Allocate a new memory for the counter values wrapped by all the needed * management. diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 9f0dc4bde7..49027d6a3a 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -1015,6 +1015,19 @@ struct rte_flow { uint32_t geneve_tlv_option; /**< Holds Geneve TLV option id. > */ } __rte_packed; +#if defined(HAVE_IBV_FLOW_DV_SUPPORT) || !defined(HAVE_INFINIBAND_VERBS_H) + +/* Flow item template struct. */ +struct rte_flow_pattern_template { + LIST_ENTRY(rte_flow_pattern_template) next; + /* Template attributes. */ + struct rte_flow_pattern_template_attr attr; + struct mlx5dr_match_template *mt; /* mlx5 match template. */ + uint32_t refcnt; /* Reference counter. */ +}; + +#endif + /* * Define list of valid combinations of RX Hash fields * (see enum ibv_rx_hash_fields). @@ -1268,6 +1281,15 @@ typedef int (*mlx5_flow_port_configure_t) uint16_t nb_queue, const struct rte_flow_queue_attr *queue_attr[], struct rte_flow_error *err); +typedef struct rte_flow_pattern_template *(*mlx5_flow_pattern_template_create_t) + (struct rte_eth_dev *dev, + const struct rte_flow_pattern_template_attr *attr, + const struct rte_flow_item items[], + struct rte_flow_error *error); +typedef int (*mlx5_flow_pattern_template_destroy_t) + (struct rte_eth_dev *dev, + struct rte_flow_pattern_template *template, + struct rte_flow_error *error); struct mlx5_flow_driver_ops { mlx5_flow_validate_t validate; @@ -1308,6 +1330,8 @@ struct mlx5_flow_driver_ops { mlx5_flow_item_update_t item_update; mlx5_flow_info_get_t info_get; mlx5_flow_port_configure_t configure; + mlx5_flow_pattern_template_create_t pattern_template_create; + mlx5_flow_pattern_template_destroy_t pattern_template_destroy; }; /* mlx5_flow.c */ diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c index e5b2ae91d8..66c5825084 100644 --- a/drivers/net/mlx5/mlx5_flow_hw.c +++ b/drivers/net/mlx5/mlx5_flow_hw.c @@ -13,6 +13,85 @@ const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops; /** + * Create flow item template. + * + * @param[in] dev + * Pointer to the rte_eth_dev structure. + * @param[in] attr + * Pointer to the item template attributes. + * @param[in] items + * The template item pattern. + * @param[out] error + * Pointer to error structure. + * + * @return + * Item template pointer on success, NULL otherwise and rte_errno is set. + */ +static struct rte_flow_pattern_template * +flow_hw_pattern_template_create(struct rte_eth_dev *dev, + const struct rte_flow_pattern_template_attr *attr, + const struct rte_flow_item items[], + struct rte_flow_error *error) +{ + struct mlx5_priv *priv = dev->data->dev_private; + struct rte_flow_pattern_template *it; + + it = mlx5_malloc(MLX5_MEM_ZERO, sizeof(*it), 0, rte_socket_id()); + if (!it) { + rte_flow_error_set(error, ENOMEM, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "cannot allocate item template"); + return NULL; + } + it->attr = *attr; + it->mt = mlx5dr_match_template_create(items, attr->relaxed_matching); + if (!it->mt) { + mlx5_free(it); + rte_flow_error_set(error, rte_errno, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "cannot create match template"); + return NULL; + } + __atomic_fetch_add(&it->refcnt, 1, __ATOMIC_RELAXED); + LIST_INSERT_HEAD(&priv->flow_hw_itt, it, next); + return it; +} + +/** + * Destroy flow item template. + * + * @param[in] dev + * Pointer to the rte_eth_dev structure. + * @param[in] template + * Pointer to the item template to be destroyed. + * @param[out] error + * Pointer to error structure. + * + * @return + * 0 on success, a negative errno value otherwise and rte_errno is set. + */ +static int +flow_hw_pattern_template_destroy(struct rte_eth_dev *dev __rte_unused, + struct rte_flow_pattern_template *template, + struct rte_flow_error *error __rte_unused) +{ + if (__atomic_load_n(&template->refcnt, __ATOMIC_RELAXED) > 1) { + DRV_LOG(WARNING, "Item template %p is still in use.", + (void *)template); + return rte_flow_error_set(error, EBUSY, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, + "item template in using"); + } + LIST_REMOVE(template, next); + claim_zero(mlx5dr_match_template_destroy(template->mt)); + mlx5_free(template); + return 0; +} + +/* * Get information about HWS pre-configurable resources. * * @param[in] dev @@ -154,9 +233,14 @@ void flow_hw_resource_release(struct rte_eth_dev *dev) { struct mlx5_priv *priv = dev->data->dev_private; + struct rte_flow_pattern_template *it; if (!priv->dr_ctx) return; + while (!LIST_EMPTY(&priv->flow_hw_itt)) { + it = LIST_FIRST(&priv->flow_hw_itt); + flow_hw_pattern_template_destroy(dev, it, NULL); + } mlx5_free(priv->hw_q); priv->hw_q = NULL; claim_zero(mlx5dr_context_close(priv->dr_ctx)); @@ -167,6 +251,8 @@ flow_hw_resource_release(struct rte_eth_dev *dev) const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops = { .info_get = flow_hw_info_get, .configure = flow_hw_configure, + .pattern_template_create = flow_hw_pattern_template_create, + .pattern_template_destroy = flow_hw_pattern_template_destroy, }; #endif -- 2.25.1