From patchwork Tue Oct 10 14:24:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ori Kam X-Patchwork-Id: 132462 X-Patchwork-Delegate: ferruh.yigit@amd.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 2BB794234D; Tue, 10 Oct 2023 16:25:02 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A89C2402C2; Tue, 10 Oct 2023 16:25:01 +0200 (CEST) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2087.outbound.protection.outlook.com [40.107.212.87]) by mails.dpdk.org (Postfix) with ESMTP id EDCDD40297 for ; Tue, 10 Oct 2023 16:24:59 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XSb21Szu3gxZpsfcU5yNVDB13xesXdvjvg38t4FU8vu84Puhb9eVuZUb9QwRoX2/w6tho659/ukPtvu5zCqOFWAceFGnT0VDmwlv+iAi+Ae5g2JT5muQ8J4oZJakU+zZUJEfZqxrb+Wid70mpWynKeAoEBf5Ms8rciCaHwkP2hJHAE1f0YQkaCiuyD10Ef8GKMPuEkv+pQ3I9KjhL3zGUhzmfJ6OICg9xCOBzo3gYLXI6BPMc3V5EnZHvrKfdW/+eRTtddroIfUA75ZxIuE9b4ulWXi2WjO6UOKCRH7h/gfwzbSkknwGTgVIGXVqLpZ/5/xkbt9W99moJNayHLnmlg== 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=Yh2OfMxHNe0PtMkYRGNmJG02UBOff+psiO3iY0aZyDk=; b=aQMAuUfVr+jg7xcuL4Qz3yQtgYI9VtlPov983u6NUXJNMLurleqO9KpAaVF1J0AfSdotJ62QypHOvhM7BiggY/zhB1iaU6TFbLATHmfrAVxRo2YUWnxYvIXluzK8r1AJmWm5wCwxLSerAgF1l1IPkirktSWcjjHvK6SnOnz4GisTsmGpgR+id4rHiG2jZsG4ZBfyDiXGNEnAQm0ruwHlGqapp+NhgLXVC2gCUtuUbWyb48cEltaUNT+A7ikjcWw6SfZNFHrDG2X2GdYxe/t92xFpxo2w6RKgiIbBQBBowp6TtVdw3FjiNf6G6ZWKZmqLkRRQ9aLgo5g5HBkQHuwpCw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=intel.com 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=Yh2OfMxHNe0PtMkYRGNmJG02UBOff+psiO3iY0aZyDk=; b=PWuXXGrA01nkbyGtcwxdR6G7AlDfeuulK9cjV8zHWEM4nu0DcqSDEHtJ94jKDog8Su1jiYRKf7uIi3DcCotLHBjFOB86/O8zCyt3ODrFtSL2oK1q0nL72NjeyIc+oBI8Dp3NS7pbc3k9RwO5qXpM+FGFehwZu7yXFr1npn1k74lse6IlWDIC2lQcGGUKbqAnAwfiVW/t3UCDpkamdlHjOqBGcQG2vModydNY+jLCDm/4wF6pQQG5H8U8C4ca+L/lYgzF04lPFwQo1qh8FR0BOf/K3puG/wgqzdZfVnySXiH3FVq2bdl2ZuLABN5TqrpV4jlNJRrTMZ7ZtzIiXBlWvw== Received: from BYAPR08CA0039.namprd08.prod.outlook.com (2603:10b6:a03:117::16) by CO6PR12MB5474.namprd12.prod.outlook.com (2603:10b6:303:139::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.38; Tue, 10 Oct 2023 14:24:57 +0000 Received: from SN1PEPF0002BA4E.namprd03.prod.outlook.com (2603:10b6:a03:117:cafe::ef) by BYAPR08CA0039.outlook.office365.com (2603:10b6:a03:117::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.27 via Frontend Transport; Tue, 10 Oct 2023 14:24:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) 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 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by SN1PEPF0002BA4E.mail.protection.outlook.com (10.167.242.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.22 via Frontend Transport; Tue, 10 Oct 2023 14:24:56 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Tue, 10 Oct 2023 07:24:25 -0700 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.41; Tue, 10 Oct 2023 07:24:21 -0700 From: Ori Kam To: , Aman Singh , Yuying Zhang , Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko CC: , , Subject: [PATCH v2] ethdev: add calculate hash function Date: Tue, 10 Oct 2023 17:24:01 +0300 Message-ID: <20231010142401.27289-1-orika@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230926113753.28765-1-orika@nvidia.com> References: <20230926113753.28765-1-orika@nvidia.com> MIME-Version: 1.0 X-Originating-IP: [10.126.230.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: SN1PEPF0002BA4E:EE_|CO6PR12MB5474:EE_ X-MS-Office365-Filtering-Correlation-Id: d1d4a61c-f055-48db-661b-08dbc99cadca 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: B0bdG4hSk3I71JaL916qAwGTtNjxjXdlTP8+b+L1U1/Diw9usiLMP5eJP65FGK8q743UlbQME5qsEokHCtWaqGATc15KC6ivZCv3MpViWgCCOy1cFSh605yuI+fVfgImHU5GyNxUxTUBXE0/nO0zj3Q9WQ5/j4Cf4eYR3T7Ju4UvJxv0pvv+EawFLOk5nnzC1ZkF2LEvM7ufDacKCZzViZPT0gOGfS5Krni8Qark/7v3Q9n+azJY/jD6fpqJ8eHfbA68DrspFHsRz3Bb25DPJdRSQFsIZcLRfvUlHTG6S9ZKThgMLq+C7jco7sJhsNOFRgCIe+rSl6sf9ESi0T2iaVNf7khHTgkp1fQCAW0eO5iZlUrb0QpVWzGPw6pcGWv9y/aJALirogvbj2O3g+Pr2e3GrozDQI2oAmYtvFclT4t1Jv716KYj992lasHlS6LGUUjDFifOPWboBYinp0Bm4Po/OGvIslGIaW+YB4K8pG+TA/wv3M692UfWxXnIEWZhpzvIvFxdP0K3NV8brTIgHWhcqfjRuJbBz3hEDz96PNcWYlmZSbmN17cc3zItf/3rjixl5rKfxaQfFL2ZQ3ph+niViyc9B9TjNHNl0YqpdM5HSGSU7cEcXlyfgR9jSABxfv9l2ffBVpVfsn3d9Xm9TtH/AE/CSKnsgfGj9iaQkqsvFqJkcccOhvDWZ6OSNb7XS3UUdA1KakCRpA6eVERrMoG/vpKou4GRL1T7KQqBQchgm245CLVL+XiEnbhEvDXqBrtAsrNjos9TjGLc3srSxw== X-Forefront-Antispam-Report: CIP:216.228.117.161; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:dc6edge2.nvidia.com; CAT:NONE; SFS:(13230031)(4636009)(39860400002)(396003)(346002)(376002)(136003)(230922051799003)(82310400011)(64100799003)(451199024)(1800799009)(186009)(46966006)(40470700004)(36840700001)(110136005)(316002)(70206006)(54906003)(966005)(41300700001)(5660300002)(8936002)(4326008)(70586007)(8676002)(30864003)(40460700003)(36860700001)(1076003)(107886003)(2616005)(86362001)(83380400001)(7636003)(7696005)(2906002)(40480700001)(82740400003)(356005)(55016003)(36756003)(6666004)(336012)(6286002)(16526019)(426003)(26005)(478600001)(47076005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Oct 2023 14:24:56.9454 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d1d4a61c-f055-48db-661b-08dbc99cadca 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.161]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: SN1PEPF0002BA4E.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR12MB5474 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 rte_flow supports insert by index table[1]. Using the above table, the application can create rules that are based on hash. For example application can create the following logic in order to create load balancing: 1. Create insert by index table with 2 rules, that hashes based on dmac 2. Insert to index 0 a rule that sends the traffic to port A. 3. Insert to index 1 a rule that sends the traffic to port B. Let's also assume that before this table, there is a 5 tuple match table that jumps to the above table. So each packet that matches one of the 5 tuple rules is RSSed to port A or B, based on dmac hash. The issue arises when there is a miss on the 5 tuple table, which resulted due to the packet being the first packet of this flow, or fragmented packet or any other reason. In this case, the application must calculate what would be the hash calculated by the HW so it can send the packet to the correct port. This new API allows applications to calculate the hash value of a given packet for a given table. [1] - http://patches.dpdk.org/project/dpdk/patch/20230208030624.78465-2-akozyrev@nvidia.com/ Signed-off-by: Ori Kam --- v2: add rst documentations --- app/test-pmd/cmdline_flow.c | 86 ++++++++++++++++++++- app/test-pmd/config.c | 54 +++++++++++++ app/test-pmd/testpmd.h | 2 + doc/guides/prog_guide/rte_flow.rst | 17 ++++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 22 ++++++ lib/ethdev/rte_flow.c | 21 +++++ lib/ethdev/rte_flow.h | 32 ++++++++ lib/ethdev/rte_flow_driver.h | 5 ++ lib/ethdev/version.map | 1 + 9 files changed, 239 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 12809f1042..dd66429554 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -102,6 +102,7 @@ enum index { QUEUE, PUSH, PULL, + HASH, /* Flex arguments */ FLEX_ITEM_INIT, @@ -214,6 +215,11 @@ enum index { GROUP_TRANSFER, GROUP_SET_MISS_ACTIONS, + /* Hash calculation arguments. */ + HASH_CALC_TABLE, + HASH_CALC_PATTERN_INDEX, + HASH_CALC_PATTERN, + /* Tunnel arguments. */ TUNNEL_CREATE, TUNNEL_CREATE_TYPE, @@ -2708,6 +2714,9 @@ static int parse_pull(struct context *, const struct token *, static int parse_group(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); +static int parse_hash(struct context *, const struct token *, + const char *, unsigned int, + void *, unsigned int); static int parse_tunnel(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); @@ -3066,7 +3075,8 @@ static const struct token token_list[] = { FLEX, QUEUE, PUSH, - PULL)), + PULL, + HASH)), .call = parse_init, }, /* Top-level command. */ @@ -3751,6 +3761,33 @@ static const struct token token_list[] = { .args = ARGS(ARGS_ENTRY(struct buffer, queue)), }, /* Top-level command. */ + [HASH] = { + .name = "hash", + .help = "calculate hash for a given pattern in a given template table", + .next = NEXT(NEXT_ENTRY(HASH_CALC_TABLE), NEXT_ENTRY(COMMON_PORT_ID)), + .args = ARGS(ARGS_ENTRY(struct buffer, port)), + .call = parse_hash, + }, + /* Sub-level commands. */ + [HASH_CALC_TABLE] = { + .name = "template_table", + .help = "specify table id", + .next = NEXT(NEXT_ENTRY(HASH_CALC_PATTERN_INDEX), + NEXT_ENTRY(COMMON_TABLE_ID)), + .args = ARGS(ARGS_ENTRY(struct buffer, + args.vc.table_id)), + .call = parse_hash, + }, + [HASH_CALC_PATTERN_INDEX] = { + .name = "pattern_template", + .help = "specify pattern template id", + .next = NEXT(NEXT_ENTRY(ITEM_PATTERN), + NEXT_ENTRY(COMMON_UNSIGNED)), + .args = ARGS(ARGS_ENTRY(struct buffer, + args.vc.pat_templ_id)), + .call = parse_hash, + }, + /* Top-level command. */ [INDIRECT_ACTION] = { .name = "indirect_action", .type = "{command} {port_id} [{arg} [...]]", @@ -10544,6 +10581,48 @@ parse_pull(struct context *ctx, const struct token *token, return len; } +/** Parse tokens for hash calculation commands. */ +static int +parse_hash(struct context *ctx, const struct token *token, + const char *str, unsigned int len, + void *buf, unsigned int size) +{ + struct buffer *out = buf; + + /* Token name must match. */ + if (parse_default(ctx, token, str, len, NULL, 0) < 0) + return -1; + /* Nothing else to do if there is no buffer. */ + if (!out) + return len; + if (!out->command) { + if (ctx->curr != HASH) + return -1; + if (sizeof(*out) > size) + return -1; + out->command = ctx->curr; + ctx->objdata = 0; + ctx->object = out; + ctx->objmask = NULL; + out->args.vc.data = (uint8_t *)out + size; + return len; + } + switch (ctx->curr) { + case HASH_CALC_TABLE: + case HASH_CALC_PATTERN_INDEX: + return len; + case ITEM_PATTERN: + out->args.vc.pattern = + (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1), + sizeof(double)); + ctx->object = out->args.vc.pattern; + ctx->objmask = NULL; + return len; + default: + return -1; + } +} + static int parse_group(struct context *ctx, const struct token *token, const char *str, unsigned int len, @@ -12498,6 +12577,11 @@ cmd_flow_parsed(const struct buffer *in) case PULL: port_queue_flow_pull(in->port, in->queue); break; + case HASH: + port_flow_hash_calc(in->port, in->args.vc.table_id, + in->args.vc.pat_templ_id, + in->args.vc.pattern); + break; case QUEUE_AGED: port_queue_flow_aged(in->port, in->queue, in->args.aged.destroy); diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 709864bb44..35586e0ad2 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -3301,6 +3302,59 @@ port_queue_flow_push(portid_t port_id, queueid_t queue_id) return ret; } +/** Calculate the hash result for a given pattern in a given table. */ +int +port_flow_hash_calc(portid_t port_id, uint32_t table_id, + uint8_t pattern_template_index, const struct rte_flow_item pattern[]) +{ + uint32_t hash; + bool found; + struct port_table *pt; + struct rte_port *port; + struct rte_flow_error error; + int ret = 0; + + if (port_id_is_invalid(port_id, ENABLED_WARN) || + port_id == (portid_t)RTE_PORT_ALL) + return -EINVAL; + port = &ports[port_id]; + + found = false; + pt = port->table_list; + while (pt) { + if (table_id == pt->id) { + found = true; + break; + } + pt = pt->next; + } + if (!found) { + printf("Table #%u is invalid\n", table_id); + return -EINVAL; + } + + memset(&error, 0x55, sizeof(error)); + ret = rte_flow_calc_table_hash(port_id, pt->table, pattern, + pattern_template_index, &hash, &error); + if (ret < 0) { + printf("Failed to calculate hash "); + switch (abs(ret)) { + case ENODEV: + printf("no such device\n"); + break; + case ENOTSUP: + printf("device doesn't support this operation\n"); + break; + default: + printf("\n"); + break; + } + return ret; + } + printf("Hash results 0x%x\n", hash); + return 0; +} + /** Pull queue operation results from the queue. */ static int port_queue_aged_flow_destroy(portid_t port_id, queueid_t queue_id, diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index e236845a81..dec333a8fa 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -1014,6 +1014,8 @@ port_queue_action_handle_query_update(portid_t port_id, const struct rte_flow_action *action); int port_queue_flow_push(portid_t port_id, queueid_t queue_id); int port_queue_flow_pull(portid_t port_id, queueid_t queue_id); +int port_flow_hash_calc(portid_t port_id, uint32_t table_id, + uint8_t pattern_template_index, const struct rte_flow_item pattern[]); void port_queue_flow_aged(portid_t port_id, uint32_t queue_id, uint8_t destroy); int port_flow_validate(portid_t port_id, const struct rte_flow_attr *attr, diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst index 860e42025f..a11eb2977a 100644 --- a/doc/guides/prog_guide/rte_flow.rst +++ b/doc/guides/prog_guide/rte_flow.rst @@ -4173,6 +4173,23 @@ User data may be provided during a flow creation/destruction in order to distinguish between multiple operations. User data is returned as part of the result to provide a method to detect which operation is completed. +Calculate hash +~~~~~~~~~~~~~~ + +Calculating hash of a packet in SW as it would be calculated in HW. + +The application can use this function to calculate the hash of a given packet +as it would be calculated in the HW. + +.. code-block:: c + + int + rte_flow_calc_table_hash(uint16_t port_id, + const struct rte_flow_template_table *table, + const struct rte_flow_item pattern[], + uint8_t pattern_template_index, + uint32_t *hash, struct rte_flow_error *error); + .. _flow_isolated_mode: Flow isolated mode diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index e6d218caaa..1006239d86 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -3276,6 +3276,28 @@ The usual error message is shown when operations results cannot be pulled:: Caught error type [...] ([...]): [...] +Calculating hash +~~~~~~~~~~~~~~~~ + +``flow hash`` calculates the hash for a given pattern. +It is bound to ``rte_flow_calc_table_hash()``:: + + flow hash {port_id} template_table {table_id} + pattern_template {pattern_template_index} + actions_template {actions_template_index} + pattern {item} [/ {item} [...]] / end + +If successful, it will show the calculated hash result as seen below:: + + Hash results 0x[...] + +Otherwise, it will show an error message of the form:: + + Caught error type [...] ([...]): [...] + +This command uses the same pattern items as ``flow create``, +their format is described in `Creating flow rules`_. + Creating a tunnel stub for offload ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c index c9d23da702..6917fbd262 100644 --- a/lib/ethdev/rte_flow.c +++ b/lib/ethdev/rte_flow.c @@ -2454,3 +2454,24 @@ rte_flow_async_action_list_handle_query_update(uint16_t port_id, uint32_t queue_ ret); return ret; } + +int +rte_flow_calc_table_hash(uint16_t port_id, const struct rte_flow_template_table *table, + const struct rte_flow_item pattern[], uint8_t pattern_template_index, + uint32_t *hash, struct rte_flow_error *error) +{ + int ret; + struct rte_eth_dev *dev; + const struct rte_flow_ops *ops; + + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + ops = rte_flow_ops_get(port_id, error); + if (!ops || !ops->flow_calc_table_hash) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "action_list async query_update not supported"); + dev = &rte_eth_devices[port_id]; + ret = ops->flow_calc_table_hash(dev, table, pattern, pattern_template_index, + hash, error); + return flow_err(port_id, ret, error); +} diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h index e576b15e3d..00e472b65b 100644 --- a/lib/ethdev/rte_flow.h +++ b/lib/ethdev/rte_flow.h @@ -6717,6 +6717,38 @@ rte_flow_async_action_list_handle_query_update(uint16_t port_id, uint32_t queue_ void *user_data, struct rte_flow_error *error); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Calculate the hash for a given pattern in a given table as + * calculated by the HW. + * + * @param port_id + * Port identifier of Ethernet device. + * @param table + * The table the SW wishes to simulate. + * @param pattern + * The values to be used in the hash calculation. + * @param pattern_template_index + * The pattern index in the table to be used for the calculation. + * @param hash + * Used to return the calculated hash. + * @param error + * Perform verbose error reporting if not NULL. + * PMDs initialize this structure in case of error only. + * + * @return + * - (0) if success. + * - (-ENODEV) if *port_id* invalid. + * - (-ENOTSUP) if underlying device does not support this functionality. + */ +__rte_experimental +int +rte_flow_calc_table_hash(uint16_t port_id, const struct rte_flow_template_table *table, + const struct rte_flow_item pattern[], uint8_t pattern_template_index, + uint32_t *hash, struct rte_flow_error *error); + #ifdef __cplusplus } #endif diff --git a/lib/ethdev/rte_flow_driver.h b/lib/ethdev/rte_flow_driver.h index 3ced086c47..f35f659503 100644 --- a/lib/ethdev/rte_flow_driver.h +++ b/lib/ethdev/rte_flow_driver.h @@ -365,6 +365,11 @@ struct rte_flow_ops { const void **update, void **query, enum rte_flow_query_update_mode mode, void *user_data, struct rte_flow_error *error); + /** @see rte_flow_calc_table_hash() */ + int (*flow_calc_table_hash) + (struct rte_eth_dev *dev, const struct rte_flow_template_table *table, + const struct rte_flow_item pattern[], uint8_t pattern_template_index, + uint32_t *hash, struct rte_flow_error *error); }; /** diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map index 1e51478405..919ba5b8e6 100644 --- a/lib/ethdev/version.map +++ b/lib/ethdev/version.map @@ -316,6 +316,7 @@ EXPERIMENTAL { # added in 23.11 rte_eth_recycle_rx_queue_info_get; rte_flow_group_set_miss_actions; + rte_flow_calc_table_hash; }; INTERNAL {