From patchwork Sun Jan 28 09:39:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ori Kam X-Patchwork-Id: 136189 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 64157439EC; Sun, 28 Jan 2024 10:40:51 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 175B740A6C; Sun, 28 Jan 2024 10:40:46 +0100 (CET) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2051.outbound.protection.outlook.com [40.107.244.51]) by mails.dpdk.org (Postfix) with ESMTP id 583D540696 for ; Sun, 28 Jan 2024 10:40:44 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hrJhbuVj6lY7abI4WXMrkvgDDoke+svcQ9pe5GIBFX35Fizgi0em6r/WaYDTVh7Cbtes3q7qULC3hM8TJrLXu7a9YoSxF288NdKZMCZIBey/Dg+rCC22JO5DpJsn1U1jpeJrzZGZhnLf4N+m5KG+kTxyAOQwiJ9hN3rrnQrO25B8RD1hOx0xoo6LVQW5ep9qQz7vOFT6J3F8lfkaFb/6gNCQAXXkPOiA7aRl4tCh/2gEHcdwGXTiD9mX5940tDFPt3ZR7OF4XMAc3lvBgAoEYoX3aQjyvdINgePyz4bgv5yVA44Plncd+vEqx4TaA/rQFEtvDg/+9H/rXqT3CXcpAw== 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=hATIhYUBOOmFz9RTjgThrSjs7zzfMzkf/1l1JreDr6A=; b=VW0GzpZdRRdIK07UvL4ato3gU4CAODdFVd++mIXWdvlLVkCp2p6DStHpM3gVq4nq4pStExxPrBhgECZRo47U0LrDNncntFODk7li8/YK4R8aoFY+960iVtBzCcHiKdgc4xSgiF1wSr7vxg+cMzZIoA2fR8o6dHeEqmOLLOls4T+3WUeVEkrHJl0Qr9VsOe8+L4bkrEYqBT21XKnkOKf4t/wLN1jrbTIbAMWPA0MIMOOWbyu321yrkxdRVL7H/588vZSYo/yIEZO28dd2eT60dtxzjE+I6dZCHbOe3U7fKR0QpL6E6tGWUdqAm1dpK5eErYt3p54fwZ2yRuuBaEcsew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=amd.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 (0) 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=hATIhYUBOOmFz9RTjgThrSjs7zzfMzkf/1l1JreDr6A=; b=l+fCM68UpHuQD2SymFYrq8ayLSCo5A78yWnWyZVccAF0c2vmCPHq5GOYKNisIHMnwz5ofbXrAicae29V5rxYdpIVIBgtqjHnSs3hhbZSw/o7oLIQu8BmgvpooqviemUyUpH7IodzHNt4R9gtFauiwCmee2G8LYAs5Jp6hXFiPZRx+eYmiiLKe+j2eQTOPfTMlAUUXjWW9XSRpIuvn3b7fdoFlKGVZNY01h3S1K60Oe84DsM2IrF+CJcP/ZYy92Ko45YQ5xP8QVmZLS41YuWrsrvdjSE8qAv5s+R6bi+aUtrHA3NDIt6nf2ypyWkpArbniAmJewx0BZGvlB2hxBBHDw== Received: from SA0PR11CA0123.namprd11.prod.outlook.com (2603:10b6:806:131::8) by CYXPR12MB9428.namprd12.prod.outlook.com (2603:10b6:930:d5::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.31; Sun, 28 Jan 2024 09:40:42 +0000 Received: from SN1PEPF00026368.namprd02.prod.outlook.com (2603:10b6:806:131:cafe::d2) by SA0PR11CA0123.outlook.office365.com (2603:10b6:806:131::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.31 via Frontend Transport; Sun, 28 Jan 2024 09:40:41 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) 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.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by SN1PEPF00026368.mail.protection.outlook.com (10.167.241.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.19 via Frontend Transport; Sun, 28 Jan 2024 09:40:41 +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.41; Sun, 28 Jan 2024 01:40:30 -0800 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.41; Sun, 28 Jan 2024 01:40:26 -0800 From: Ori Kam To: , , , , , Thomas Monjalon CC: , , Subject: [PATCH 1/4] ethdev: introduce encap hash calculation Date: Sun, 28 Jan 2024 11:39:39 +0200 Message-ID: <20240128093943.4461-2-orika@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240128093943.4461-1-orika@nvidia.com> References: <20240128093943.4461-1-orika@nvidia.com> MIME-Version: 1.0 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: SN1PEPF00026368:EE_|CYXPR12MB9428:EE_ X-MS-Office365-Filtering-Correlation-Id: 2ea9e124-65a3-49a6-1dbc-08dc1fe53171 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: /9NubfJDXE7nFjXcy8vegr4bCcmT2xNyWIDnXCorrT7tFSedktYf8/yylI2yKbz18TwrepfhMQrpX+HfLPDTmhtFOzHHljZ62Gcuh/gEamLY4rN9iUPdQJmq3uLAPIdYgxakHAIaMqowGMDOBz5XHzW/zdlFWfzd2n4uKHamxFR5pGB5/88JSOtDyq53RObHp6/j6yxOeovMa86Y8ZRhHetHIn4BWa+J+7OvpjrGAlAncmuWITPfYHEj/QLpi+RMjVmTclywRajlMQOr/r5DFlEMTX5U/GgZ+tTCtX2QrThlUVsuY2wUKGxFFtfpICcnsOhyQrS8E3+29rL5wRf4GWCAtkOMATBfcz2uNq6i9Zy+Z6Xqz86LSTQYX/24LWhcCsA3dn1EUkE/CVZxRqlppADwDSgFxhuIWXi8TYMzQRA3FXOI4NUWSMRNBzKb02FikZeA58qSSlPbvxKHbjfr7h77Mmom2jFR35b2dqmcRP1irJQ/G1xF6RouQYAaDWL8hUCX+hDrOg/xNIRgHdi9xhnHfv+a0GMu6g1qR7vG4sDbslHXC7G1UcrqkrhqyxkSIvkSHWZCJIdFZf9bhRax818SCkDTWzf/hmVwT2uDHbtqtsoWEPqdYTYqXcIdVLuBMSh3l4abCoXi9apDekr70UA5CRJi9zXnSJbNG6tvWec7eHeDxBYdIzGQKQnRzAOLWNN5lsBzWVkj7ijbzBhF5H1ey30JqH5x21PutY2ulUDxYooR3PUQFUexdHwI3nd6XsUB8eS4Dj8LfkADzAH1xVTi933aeahJakPF5b5r+0w= 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:(13230031)(4636009)(396003)(346002)(376002)(136003)(39860400002)(230173577357003)(230273577357003)(230922051799003)(186009)(64100799003)(451199024)(1800799012)(82310400011)(36840700001)(40470700004)(46966006)(41300700001)(478600001)(6666004)(107886003)(2616005)(7696005)(55016003)(86362001)(2906002)(5660300002)(70586007)(70206006)(110136005)(316002)(54906003)(8676002)(8936002)(4326008)(1076003)(36860700001)(6286002)(16526019)(83380400001)(26005)(336012)(426003)(47076005)(7636003)(356005)(36756003)(82740400003)(40480700001)(40460700003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2024 09:40:41.5830 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2ea9e124-65a3-49a6-1dbc-08dc1fe53171 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: SN1PEPF00026368.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYXPR12MB9428 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 During the encapsulation of a packet, it is expected to calculate the hash value which is based on the original packet (the outer values, which will become the inner values). The tunnel protocol defines which tunnel field should hold this hash, but it doesn't define the hash calculation algorithm. An application that uses flow offloads gets the first few packets and then decides to offload the flow. As a result, there are two different paths that a packet from a given flow may take. SW for the first few packets or HW for the rest. When the packet goes through the SW, the SW encapsulates the packet and must use the same hash calculation as the HW will do for the rest of the packets in this flow. This patch gives the SW a way to query the hash value for a given packet as if the packet was passed through the HW. Signed-off-by: Ori Kam --- doc/guides/prog_guide/rte_flow.rst | 22 ++++++++++++ doc/guides/rel_notes/release_24_03.rst | 4 +++ lib/ethdev/rte_flow.c | 25 +++++++++++++ lib/ethdev/rte_flow.h | 50 ++++++++++++++++++++++++++ lib/ethdev/rte_flow_driver.h | 5 +++ lib/ethdev/version.map | 1 + 6 files changed, 107 insertions(+) diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst index 900fdaefb6..0435dda3c7 100644 --- a/doc/guides/prog_guide/rte_flow.rst +++ b/doc/guides/prog_guide/rte_flow.rst @@ -4211,6 +4211,28 @@ as it would be calculated in the HW. uint8_t pattern_template_index, uint32_t *hash, struct rte_flow_error *error); +Calculate encap hash +~~~~~~~~~~~~~~~~~~~~ + +Calculating hash of a packet in SW as it would be calculated in HW for the encap action + +When the HW execute an encapsulation action, it may calculate an hash value which is based +on the original packet. This hash is stored depending on the encapsulation protocol, in one +of the outer fields. + +This function allows the application to calculate the hash for a given packet as if the +encapsulation was done in HW. + +.. code-block:: c + + int + rte_flow_calc_encap_hash(uint16_t port_id, + const struct rte_flow_item pattern[], + enum rte_flow_encap_hash_field dest_field, + uint8_t hash_len, + uint8_t *hash, + struct rte_flow_error *error); + .. _flow_isolated_mode: Flow isolated mode diff --git a/doc/guides/rel_notes/release_24_03.rst b/doc/guides/rel_notes/release_24_03.rst index 5e545da867..80af380172 100644 --- a/doc/guides/rel_notes/release_24_03.rst +++ b/doc/guides/rel_notes/release_24_03.rst @@ -75,6 +75,10 @@ New Features * Added support for VXLAN-GPE matching in HW Steering flow engine (``dv_flow_en`` = 2). +* **Added ability to calculate the encap hash as done by HW.** + + * Added function that calculates the encap hash, as the HW calculates it: + ``rte_flow_calc_encap_hash()`` Removed Items ------------- diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c index 3f58d792f9..7fce754be1 100644 --- a/lib/ethdev/rte_flow.c +++ b/lib/ethdev/rte_flow.c @@ -2482,3 +2482,28 @@ rte_flow_calc_table_hash(uint16_t port_id, const struct rte_flow_template_table hash, error); return flow_err(port_id, ret, error); } + +int +rte_flow_calc_encap_hash(uint16_t port_id, const struct rte_flow_item pattern[], + enum rte_flow_encap_hash_field dest_field, uint8_t hash_len, + uint8_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_encap_hash) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "calc encap hash is not supported"); + if ((dest_field == RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT && hash_len != 2) || + (dest_field == RTE_FLOW_ENCAP_HASH_FIELD_NVGRE_FLOW_ID && hash_len != 1)) + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "hash len doesn't match the requested field len"); + dev = &rte_eth_devices[port_id]; + ret = ops->flow_calc_encap_hash(dev, pattern, dest_field, hash, error); + return flow_err(port_id, ret, error); +} diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h index 1267c146e5..ffbde58245 100644 --- a/lib/ethdev/rte_flow.h +++ b/lib/ethdev/rte_flow.h @@ -6783,6 +6783,56 @@ rte_flow_calc_table_hash(uint16_t port_id, const struct rte_flow_template_table const struct rte_flow_item pattern[], uint8_t pattern_template_index, uint32_t *hash, struct rte_flow_error *error); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Destination field type for the hash calculation, when encap action is used. + * + * @see function rte_flow_calc_encap_hash + */ +enum rte_flow_encap_hash_field { + /* Calculate hash placed in UDP source port field. */ + RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT, + /* Calculate hash placed in NVGRE flow ID field. */ + RTE_FLOW_ENCAP_HASH_FIELD_NVGRE_FLOW_ID, +}; + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Simulates HW hash calculation that is done when encap action is being used. + * + * @param[in] port_id + * Port identifier of Ethernet device. + * @param[in] pattern + * The values to be used in the hash calculation. + * @param[in] dest_field + * Type of destination field for hash calculation. + * @param[in] hash_len + * The length of the hash pointer in bytes. Should be according to encap_hash_field. + * @param[out] hash + * Used to return the calculated hash. It will be written in network order, + * so hash[0] is the MSB. + * The number of bytes is based on the destination field type. + * @param[out] 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. + * - (-EINVAL) if *pattern* doesn't hold enough information to calculate the hash + * or the dest is not supported. + */ +__rte_experimental +int +rte_flow_calc_encap_hash(uint16_t port_id, const struct rte_flow_item pattern[], + enum rte_flow_encap_hash_field dest_field, uint8_t hash_len, + uint8_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 f35f659503..447163655a 100644 --- a/lib/ethdev/rte_flow_driver.h +++ b/lib/ethdev/rte_flow_driver.h @@ -370,6 +370,11 @@ struct rte_flow_ops { (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); + /** @see rte_flow_calc_encap_hash() */ + int (*flow_calc_encap_hash) + (struct rte_eth_dev *dev, const struct rte_flow_item pattern[], + enum rte_flow_encap_hash_field dest_field, uint8_t *hash, + struct rte_flow_error *error); }; /** diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map index a050baab0f..360898d067 100644 --- a/lib/ethdev/version.map +++ b/lib/ethdev/version.map @@ -319,6 +319,7 @@ EXPERIMENTAL { # added in 24.03 rte_eth_find_rss_algo; + rte_flow_calc_encap_hash; }; INTERNAL {