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 E450D43B05; Tue, 13 Feb 2024 15:17:16 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AB43440647; Tue, 13 Feb 2024 15:17:16 +0100 (CET) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2077.outbound.protection.outlook.com [40.107.244.77]) by mails.dpdk.org (Postfix) with ESMTP id A1905402D5 for ; Tue, 13 Feb 2024 15:17:14 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PG+og1z4AMeaZWPwlD9pQ+YRZjuUUhpDoSmGm30Ow3bbQSQYYq3iD3BlQzwaHL4ApDPV9fDIrthKiH9lvC6s8fenZTJ86Et60I3/voFHtpwxw0AgpDEfthAXUTghjxRCIuEDT/XHK9FhaomfcE8jeb3g4lPod2RFiZeO1u4veMfm5V7h+BAyKfgR8hgFYTdHlIshQhyxASeRJvuySoY+jXPQNNipYL7u/2iRDhql9cGGIgIwo6sotQZYNIgZJYxkrk3Q4oCul1RgigXG37KwzLZHiyrH5qNh68VlHZ4vlXZcoeWFoHLVA/VVJyUPN97Lomls2mnxI+wEaYMydJ4Ccg== 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=UinOcz/fv2QFSs4fIb+9YE64XbvymU/XJZpyIQXWBHs=; b=V055ewuSqiMxPmUHIujhxb7eQTEEJkNxEeoDnoHtAuR7haWIRCnF1Op80hZaLXQjax/zVmlP5LlbuHutFg2tJdhp2SckCdh/MpOdnFf+HB4SUWNwKkGLVWoT8T+unWgkmucobL6vRvcSqKq1NXFzCwL6LS5fyUADt4hPujHHqVgTmOI8BLRO6ssyJ9dsmxsecOq78n1giFhiLEbTiD83J9HClG4EjyYw7sLVue5xoqvd+V7dChF1dmvTgBRhJWcPNQ6dUsjtTD5r0776f4AJI60EvvdZwp1owMOdQs5+UPRhczkKKqWHfA/emmLruteLeAXuXop/68Tfvn2Wd9ornA== 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=UinOcz/fv2QFSs4fIb+9YE64XbvymU/XJZpyIQXWBHs=; b=X7RRHwKH88v4y/NSyJjWCx6xcETZdjZEgPd6lUvWEevZ1CWlCmAaGN6FQWz1EyXqJSkrEWj3NEwOCY50GJVrfukYpM9bqjdUw00QcwagpNYj4L1XLGjF2EhLCIy2bKxR5XjTUmBE54P5nt0s2S4BPKqfSQ3uwkV+ZPqlZbjkoysEditDsyO2bZk4DPK/GJmzqzBW+DsHMArcWmhiobkzoIScbLlZHtPOtgyrUowVeLkVlBIN38zcWhJvS0Qk/9mIkf8xfHGzYgyQStFqZHxeWDMmwH0PJzlf9wKRXM7f0q3YhW2OfqGUnVTaUE3wKaMYs9EaoOeB0R1x69hQW/EryQ== Received: from CY5PR22CA0102.namprd22.prod.outlook.com (2603:10b6:930:65::29) by DM3PR12MB9325.namprd12.prod.outlook.com (2603:10b6:0:46::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.26; Tue, 13 Feb 2024 14:17:11 +0000 Received: from CY4PEPF0000E9D3.namprd03.prod.outlook.com (2603:10b6:930:65:cafe::a1) by CY5PR22CA0102.outlook.office365.com (2603:10b6:930:65::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.40 via Frontend Transport; Tue, 13 Feb 2024 14:17:11 +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 CY4PEPF0000E9D3.mail.protection.outlook.com (10.167.241.146) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25 via Frontend Transport; Tue, 13 Feb 2024 14:17:11 +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; Tue, 13 Feb 2024 06:16:59 -0800 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.1258.12; Tue, 13 Feb 2024 06:16:56 -0800 From: Ori Kam To: , , , , , Thomas Monjalon CC: , , Subject: [PATCH v4 1/4] ethdev: introduce encap hash calculation Date: Tue, 13 Feb 2024 16:16:37 +0200 Message-ID: <20240213141640.19812-1-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 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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: CY4PEPF0000E9D3:EE_|DM3PR12MB9325:EE_ X-MS-Office365-Filtering-Correlation-Id: 22c960dc-1bac-4083-8b16-08dc2c9e7864 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: QNX55KAxNuAu3ilH1Rt+pGfXhwf2aHlOop1ityzG4fjFp8+yQPngUslKjgRw66WxjtZGD4uIivua0XSnMJQ7hAtU7k9b4O0wWZkXTTiv9OqftXeidzg5D0UI6safYNt1yfrtScPcNuYfH4SY3JpFzqZyHC2eu8kpRohshOZ+nCDgiDh+OngqoWS+zx3bXKvhJiqfpRzUn8cUOrX+03v6jEIKX9e8hcGWTAzORQYE/coj4WPVaCrb11zvsORbYPzD0oxaytuoRs0aqob5JTPiy/Wo6gp4L02xN9NZ03KFiWB1tAVUIG44AbaLB3tv+7WXXJD9wQeOovcSBsVvu3xMJ6owE8QLcme0ltYP/be6inLzxwrSa5vWVTKtyIakbjR+dAVZ9Jc+qtaO1UDe9ZPRxQaJcfg/v7DyVy/22lA91ZI7uI/6cCqv3RPC2sljFxmZ46e5U/LOpK36gky3a5be8/qBVUc0WWfwfIvd1S6tEy61/DfhKKzpx3JCMEQUo+Se2BYMXf7+Z6y69EhayD6ym1eD5v6Dnc/7eFe9YAVyKbtbsroKlFZiVLXm5ayCHMt6z6iZsf/n/NbQg37F5cRXvrrXueylqd52bjoldkEudKc= 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)(346002)(376002)(136003)(396003)(39850400004)(230273577357003)(230922051799003)(451199024)(186009)(82310400011)(64100799003)(1800799012)(36840700001)(40470700004)(46966006)(2906002)(6666004)(26005)(6286002)(7696005)(478600001)(36756003)(356005)(7636003)(82740400003)(107886003)(426003)(336012)(2616005)(1076003)(16526019)(86362001)(83380400001)(70586007)(70206006)(8676002)(4326008)(8936002)(5660300002)(54906003)(110136005)(316002)(55016003)(41300700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2024 14:17:11.4984 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 22c960dc-1bac-4083-8b16-08dc2c9e7864 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: CY4PEPF0000E9D3.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM3PR12MB9325 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 encapsulation of a packet, it is possible to change some outer headers to improve flow destribution. For example, from VXLAN RFC: "It is recommended that the UDP source port number be calculated using a hash of fields from the inner packet -- one example being a hash of the inner Ethernet frame's headers. This is to enable a level of entropy for the ECMP/load-balancing" The tunnel protocol defines which outer 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 (exception path) 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. the new function rte_flow_calc_encap_hash can query the hash value from the driver for a given packet as if the packet was passed through the HW. Signed-off-by: Ori Kam Acked-by: Dariusz Sosnowski --- doc/guides/prog_guide/rte_flow.rst | 14 +++++++ doc/guides/rel_notes/release_24_03.rst | 6 ++- lib/ethdev/rte_flow.c | 29 ++++++++++++++ lib/ethdev/rte_flow.h | 53 ++++++++++++++++++++++++++ lib/ethdev/rte_flow_driver.h | 5 +++ lib/ethdev/version.map | 1 + 6 files changed, 107 insertions(+), 1 deletion(-) diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst index 34dc06ec66..294862d502 100644 --- a/doc/guides/prog_guide/rte_flow.rst +++ b/doc/guides/prog_guide/rte_flow.rst @@ -4226,6 +4226,20 @@ as it would be calculated in the HW. uint8_t pattern_template_index, uint32_t *hash, struct rte_flow_error *error); +Calculate encapsulation hash +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Calculating hash of a packet as it would be calculated by the HW, when encapsulating +a packet. + +When the HW execute an encapsulation action, for example VXLAN tunnel, +it may calculate an hash of the packet to be encapsulated. +This hash is stored in the outer header of the tunnel. +This allow better spreading of traffic. + +This function can be used for packets of a flow that are not offloaded and +pass through the SW instead of the HW, for example, SYN/FIN packets. + .. _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 358998e988..cf114ead89 100644 --- a/doc/guides/rel_notes/release_24_03.rst +++ b/doc/guides/rel_notes/release_24_03.rst @@ -60,6 +60,11 @@ New Features * Added new function ``rte_eth_find_rss_algo`` to get RSS hash algorithm by its name. +* **Added hash calculation of an encapsulated packet as done by the HW.** + + Added function to calculate hash when doing tunnel encapsulation: + ``rte_flow_calc_encap_hash()`` + * **Added flow matching of random value.** * Added ``RTE_FLOW_ITEM_TYPE_RANDOM`` to match random value. @@ -102,7 +107,6 @@ New Features * Added HW steering support for modify field ``RTE_FLOW_FIELD_GENEVE_OPT_CLASS`` flow action. * Added HW steering support for modify field ``RTE_FLOW_FIELD_GENEVE_OPT_DATA`` flow action. - Removed Items ------------- diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c index b06da0cc00..7a4f7a94f6 100644 --- a/lib/ethdev/rte_flow.c +++ b/lib/ethdev/rte_flow.c @@ -2484,3 +2484,32 @@ 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_NVGRE_FLOW_ID) + return rte_flow_error_set(error, EINVAL, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, + "hash dest field is not defined"); + 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 09c1b13381..48e4f47844 100644 --- a/lib/ethdev/rte_flow.h +++ b/lib/ethdev/rte_flow.h @@ -6846,6 +6846,59 @@ 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. + * The encap field implies the size, meaning XXX_SRC_PORT hash len is 2 bytes, + * while XXX_NVGRE_FLOW_ID hash len is 1 byte. + * + * @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. + * + * Simulate HW hash calculation that is done when an encap action is being used. + * This hash can be stored in tunnel outer header to improve packet distribution. + * + * @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 dest_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 { -- 2.34.1