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 0EA9BA034E; Thu, 24 Feb 2022 14:41:57 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E14F14270D; Thu, 24 Feb 2022 14:41:39 +0100 (CET) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2088.outbound.protection.outlook.com [40.107.236.88]) by mails.dpdk.org (Postfix) with ESMTP id 2B3BE426F6 for ; Thu, 24 Feb 2022 14:41:34 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IoAU0ejMW5w1rqt840xd7YRFIxTitBku7e8c6l7kDYy/bfTV0e4ABlCGRiF/HGRXftf/+MfmEFRO2t8oYG1fb/YpFnN92HpaEDFYnKSPapl8lpERWxi+z+IVD0gq3F92ADoBrDq7BEfEYJNhpefElh+YSkP0mtVzU8bKhL40MiL2U9ymDhSRRdgKcT5zxSuwCWJl7ZawUZoODHqI2YDkGMYMoj4hmtXOtBRGlcfXT7fiGPqzm/2z4ornvYMnkznX5WJXFWy2a8slcZMGYs1CbgJJCC9hC0XA2IJMQ7urdWjuvqiKwFRY3DR4xnH3m1q1e6C7YWamk7PACk7TRfNcAA== 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=j15WcTYeYcBImdBD8Wg4QX0dH+9Qp5QEgt9OErsKHs8=; b=NkIFBKfeHjYp+ClPVil/eJy+Mo4Kmq4uqJ91Sk13gC0hhrZjXxnqbcZq/V2jthlXIKKluuM3n7DLGj5TVRf0qbUvEHyycvIjjaT+LiS5l0xpX8ZaR/A/QRz+/KNAo/CPRtjHC8KHiA0I6S9GR5dat8Ga5rEvIpfKbinME50I6NZog4/a5IOC23QPxKQGGBkILCyH3AeiVv9Ni5i4dbaPajlGjCq5GRR8o5mfVH3Rj1qfpQ+VwGEi0H3hN3hlD2o4lNSH4czjPUxLQEGhH0SRFFGsJWhJHQdwH++ChnXptGMCbD6d74rYSq7UuGmWnNXUzLA5nTIaWRVxKMj8r5DCyg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 12.22.5.235) 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=j15WcTYeYcBImdBD8Wg4QX0dH+9Qp5QEgt9OErsKHs8=; b=GgF9Py04qCA9KterRjwjNZpDzYVVp38msFWXHJD4LHhdDPvTfqJALfIYO+MmBIFsTCMzwsxQ4Bx9naac6JME2VTHNFsFHAeOR9f/kAKh/anP3sWc3TR4rpbLCneqqjuMwFe6yduj+PnpbbCXVKhtsy+aLNigX1ZLrCnfe3E3gQFJZQxZiqJnso3CfhhkuhauGo71UXVTeXa3pxrxYkPY7aDm6QyDfXY7vVvj+N1lrcEqDWpbFgLj/gz3jc994q1DB3Ie/lyIwWIuVjBplz7Lgysp4nZQEcVdLaKQl2tR7XNcD7ebGA//ASJzAuuHd85MqOMLDzG1AIhkcbSi4BgAeQ== Received: from DM3PR08CA0020.namprd08.prod.outlook.com (2603:10b6:0:52::30) by MWHPR12MB1552.namprd12.prod.outlook.com (2603:10b6:301:a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Thu, 24 Feb 2022 13:41:30 +0000 Received: from DM6NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:0:52:cafe::91) by DM3PR08CA0020.outlook.office365.com (2603:10b6:0:52::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.24 via Frontend Transport; Thu, 24 Feb 2022 13:41:30 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 12.22.5.235) 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.235 as permitted sender) receiver=protection.outlook.com; client-ip=12.22.5.235; helo=mail.nvidia.com; Received: from mail.nvidia.com (12.22.5.235) by DM6NAM11FT034.mail.protection.outlook.com (10.13.173.47) 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 13:41:30 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by DRHQMAIL107.nvidia.com (10.27.9.16) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 24 Feb 2022 13:41:25 +0000 Received: from nvidia.com (10.126.230.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; Thu, 24 Feb 2022 05:41:18 -0800 From: Suanming Mou To: , CC: , , Subject: [PATCH v4 05/14] net/mlx5: add pattern template management Date: Thu, 24 Feb 2022 15:40:42 +0200 Message-ID: <20220224134051.18167-6-suanmingm@nvidia.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20220224134051.18167-1-suanmingm@nvidia.com> References: <20220210162926.20436-1-suanmingm@nvidia.com> <20220224134051.18167-1-suanmingm@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 62b7b548-4bd2-428b-2cc9-08d9f79b5d52 X-MS-TrafficTypeDiagnostic: MWHPR12MB1552: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: cDPk2jrpr+Y/hTcjzXQh/vFOQWmCH9NBpm5tYYSuRZGKnezYBMiwQ2eqJi43gRfm+F/AukoH8mL1r11JmwparkQwlVqA5TJb8SnbmPy+29R75Uam/V5SvG+L0lI4jT0/VnYpfvWzWkkwJDTeWvnzvIR8s94Oh4Pv+0socUuZk4TW2KEDKZKHDUcG1l3DHchwMEsKUvHBNWjJk2M9WTx5n9BhkYlXoa2fmdnoYrZl4hJEYmQnUJzYlTw7xTumiDkNzAqRAL/GFbG4wbQExgQn5WpXcHWkzjRhxvaydKVqkq/db79mILQlgX6NRqXjG3Ydhqe00pF5gixq+eF3S3bUP9hJDEPSJcU7fLmYvt0yKUGKSgl06Mw2oTuEdGR8mtU/3vTtVPtoxMFg1uJ7btc5IGBCTZ8mVIwXi5lFwBYBa0tZSJm8nF6heTtaHDnJvyb2D00iVCHudd2h/ZVLCMkYLOE/FUda0Ov0Ak6cVnd/wMPkGzN2KRpcO37rmDa+wiLXX6GybGCKT/l6AuamwvZW3fVJij6vK0ZZvqHphOIbiAvHnjqtYgQdd7J9DUjckTPr9gUCIdqkCGmRkEeO6HaXmpsvw7pPmssnuC6cB+e2cF1J2LUi2fmul3roLik7QZYiCWCgsdH30n4AceFh6UijvihlEe1Zfzemj6inNXDDYAka65FfswSeQuQefi035KZhADs+q6slYe/CfvPyxfvFAw== X-Forefront-Antispam-Report: CIP:12.22.5.235; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:mail.nvidia.com; PTR:InfoNoRecords; CAT:NONE; SFS:(13230001)(4636009)(46966006)(36840700001)(40470700004)(6636002)(16526019)(6286002)(2906002)(26005)(5660300002)(186003)(316002)(83380400001)(110136005)(54906003)(36860700001)(7696005)(2616005)(47076005)(86362001)(55016003)(82310400004)(1076003)(81166007)(4326008)(8936002)(8676002)(336012)(426003)(70586007)(70206006)(40460700003)(508600001)(356005)(36756003)(6666004)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 13:41:30.6043 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 62b7b548-4bd2-428b-2cc9-08d9f79b5d52 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.235]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1552 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 86c84d1510..7b458c410d 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -1503,6 +1503,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 156fb35ce9..a603b69d36 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. */ @@ -7933,6 +7946,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