From patchwork Tue Feb 13 13:48:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ori Kam X-Patchwork-Id: 136637 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 209C043AD8; Tue, 13 Feb 2024 14:50:46 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0D90340647; Tue, 13 Feb 2024 14:50:46 +0100 (CET) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) by mails.dpdk.org (Postfix) with ESMTP id EECE340294 for ; Tue, 13 Feb 2024 14:50:43 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JueWj32C9+CaEixB1pudGbivQQ0jSIVvo2bMfuOWTnp4Fc3gbL6E/D+lZBzxryuBv3CfavSz1n3ZrG5760D90vcK6ikIj48px/UbrQIL57Z0gBuhvATOkm5MyVb805/BhYOLez2+QnlEV5ItGiMaS1E2drO261F5tSxPwi3CeIS4ClpEwrnVBQMX419zsnqRzHYRjGLYvOwnZ7o4LOx159z5SL3bzKVQ4FJKp+m+uTiD2pydn/YOFstMEZGjYQISqOfCVDlJq4gxljR209qj84wX/gqzr4sxy8KhMME6PLjCXNKighaL45esbTgMgjmiPRSCvMC3vedGCn0tBGzcdA== 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=HCu50r8PMOXbWO6KcSdBRJbde6eBlQ6RLKMDZNrsfSc=; b=FUCjTGzLwWXGAcZjyfE3RhZhHS2yfJcHNC3SMQ051jEzf0KXOnLnmLkp1eimLM23LRk3MxVwHuDcpk7XQmwq+2WaJU5kl1XacWYwmqXkQCLoZ/EzXHze+mEJxjzf3KYrfJW+hEEcHkHkD9J0/RHnh6VkX1Y/MXHN9FbSRQAiFWcCtlYSRgu2Zv5gbfrrzBkFvUNl36fE2q1vbe3Tjdg2ZaAOYVcR0mkj6t5Gbisnzc1BDxXDbT/GKhB78U2ko/VYTp0+4FU1TlHFyybVFleThX9rYZBDbwp99YyvKcNuZYE51Dcswgz/YfErU4Ypyi0h0LxTWbppP1gxidLkeTgySw== 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=HCu50r8PMOXbWO6KcSdBRJbde6eBlQ6RLKMDZNrsfSc=; b=UGJIDWATTRttQdhergVVQlIuyTv/yThdknOqSwxXZibnqN2z7G0l4LExxNaTPJ9v6YhJ5VufUxeIqUZEnROqzRzOFxvH7euek1hrnlLlCpTXqFbwti69FporY+pA+9wB7Wxan6irorPcnO5r3wHFgvXXySO5McLd7cD8TEI+QlskLscap0csJ0ybBFbLqT/4zh9d+AKobTj2V/RWlg8UVZ7JHvldz14cvZpbMbQZJzFZg15WL7WJu81eQ1SmW+SJR9cncItILCHphalTKi151y7Ldveyz/NmLqApAZkm57Cqc8folrKjzTvUoY9vxHCtVgohFfwbbzj+NlehlksgKQ== Received: from PH8PR07CA0016.namprd07.prod.outlook.com (2603:10b6:510:2cd::24) by PH7PR12MB5733.namprd12.prod.outlook.com (2603:10b6:510:1e0::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.11; Tue, 13 Feb 2024 13:50:39 +0000 Received: from SN1PEPF0002BA4B.namprd03.prod.outlook.com (2603:10b6:510:2cd:cafe::73) by PH8PR07CA0016.outlook.office365.com (2603:10b6:510:2cd::24) 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 13:50:39 +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 SN1PEPF0002BA4B.mail.protection.outlook.com (10.167.242.68) 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 13:50:39 +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 05:50:23 -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 05:50:20 -0800 From: Ori Kam To: , , , , , Thomas Monjalon CC: , , Subject: [PATCH v3 1/4] ethdev: introduce encap hash calculation Date: Tue, 13 Feb 2024 15:48:30 +0200 Message-ID: <20240213134834.16762-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 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-TrafficTypeDiagnostic: SN1PEPF0002BA4B:EE_|PH7PR12MB5733:EE_ X-MS-Office365-Filtering-Correlation-Id: c5608110-9649-497a-8be6-08dc2c9ac391 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: Pw5S7xn8GI/lvR8nC7ngOXEC3/gvno67fZJIPIVcRRQ46v8kicA4teOldkp0tFneipeHerAbKGKHRxImmBKBPrhwjJc5ye7iC59zzpOdJgWfhfxJ98+uhW4tRx9RR5R4dGoAmxxYhvGxTO/pTx6AMP3+OF3ncMZntbbfKQojwqh2lexc6ruHYkEMFNSMehE2g5jGUzvnEV0/aZM4jIsilBR+BdH2YBfV2jSrqjaCuSNeUfdT1T+PRSbUjMf/t2V/1u45pUMB7sHxQN6hGReCPFdOtx0Un6bC6FqIWgVejEhQokWreuBxKmA9se1c3mPuSnnY6W3QWFOvZL4N9pB+ypo7HGnKfdQD7N66mhs8GzJXWeQPjsm1Cw8rSIH+TatWRzGAy4JnTrJHPzINs/H8VM33dsHhdG9Rk4rBlV/JY5a7n/3DTIMZh8oQ8pVoD14JC6DtlKHGuFiQaVc0z12lmeVTPqRj5DWwAPwrPM6r/I2j8diLDsHPghKAKyjI61ZKkZkzu00WRnGBx2mnS8TP8W+FVTMoLERME45ZS4Dx0gR8AgWXgjQmT67pruZOmgQAz3P9vBFCYG5vvsU+8QLCOQWIDyPv/Gm5iPObxbuLfGM= 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)(376002)(39860400002)(346002)(396003)(136003)(230273577357003)(230922051799003)(64100799003)(82310400011)(1800799012)(451199024)(186009)(36840700001)(46966006)(40470700004)(41300700001)(82740400003)(36756003)(316002)(7636003)(54906003)(6666004)(86362001)(8676002)(356005)(4326008)(478600001)(26005)(6286002)(70206006)(70586007)(1076003)(110136005)(2616005)(83380400001)(426003)(8936002)(7696005)(336012)(16526019)(107886003)(5660300002)(2906002)(55016003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2024 13:50:39.6042 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c5608110-9649-497a-8be6-08dc2c9ac391 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: SN1PEPF0002BA4B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5733 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 fromm 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 { From patchwork Tue Feb 13 13:48:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ori Kam X-Patchwork-Id: 136638 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 DC2BF43AD8; Tue, 13 Feb 2024 14:50:51 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4591642DBD; Tue, 13 Feb 2024 14:50:47 +0100 (CET) Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2085.outbound.protection.outlook.com [40.107.94.85]) by mails.dpdk.org (Postfix) with ESMTP id 2FE6B40294 for ; Tue, 13 Feb 2024 14:50:45 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kW/rHTEraig2tABWwJ5utuIrG2qRoiKM+ffViJPYHVleshNUolGWvx/jScTwNkaW9IMjF9o+jeYErbtPlSdq/2MSYUTB3SXRyl6+bJiA3XIcFHcJ1NyM8Wj+9xmo8g9OaidW4pM148hjre68IXekA2y6cU6h4aV/lQJVag55ieLDlsPSYq3PBWdgN/Z326GFISrxVh09e2OuL+pgDptpDTUMnR+Ns7hWHLaLiWkwGxpyuvPRrF9CBMLq8OzsRqkGJDsl19JCs6JWUP7owtNQxJA6CCFJAPYSR3jDEBEwM7f4jFnjmhRo0rJ8zcTOx935VzsL1DqOirfs0be0UDXw/Q== 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=gybTW7nJOzeAuOg2EvJs9FzF9DnRwit6iviwDP7REc4=; b=jQb2sBsR0so4mi03GjeBPJvzcytecL2dgCLATklOKscOa+HCSLKK+6XAFVOJHhtxAhyYBu/01H/QwgsBi6SN4Xk9QTb/U66oNz6ZyCGv/2fz2v6pYxh40K+muYeB1+fi+z8N+4kdQlIv7jp1ioqmT+vffOeJ7KZFcr+1oIwIjSlQaOAW6/J2n0mR/4k0s1zvnHV/YIhXW9D+ObG0leSoO7I//NdvwkVeI6SwTSSpvfM5hitwsZURq7/7xIpMINK04CZgdEPJ8sLFbj2xKgNz7PSOS/AwZSKMDMwzdNv5pc0HFVDr3V1DJasBJTCPonzDpFvHxiFLjkxtWPUsDjCCig== 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=gybTW7nJOzeAuOg2EvJs9FzF9DnRwit6iviwDP7REc4=; b=Mp5gaAKk+M7S8yq8qbWVYMPI3pyBqeivujO+PKAU8C1kR14y+RFhSRuDGJttoASroESr0SrBUfBd2zINf7848UHSuVFLaA8D+bHwlZBdoK96s348kKNvjDrAnDSLSoySfKXyboTMHibGgcO5v+boCL/GdOBhOnGyWxMxdjNeMn9M1RZycxU4HZdcxlNm+cS7gDp6HNmL9fN9u4IU4fdDXxPYSZpT4k3YwJHX6HSgfqPX+bOL3fj4+bZLv2yMyai4VrLM3Vw31gio4TEc7+YzJ45jik7zyyPKD5kiUH+A7LI+Uy0ts41cqtcbYEpZpQ58YVrmzzJsflkYDFcb2LwRbA== Received: from PH8PR07CA0011.namprd07.prod.outlook.com (2603:10b6:510:2cd::19) by CH2PR12MB4263.namprd12.prod.outlook.com (2603:10b6:610:a6::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25; Tue, 13 Feb 2024 13:50:42 +0000 Received: from SN1PEPF0002BA4B.namprd03.prod.outlook.com (2603:10b6:510:2cd:cafe::86) by PH8PR07CA0011.outlook.office365.com (2603:10b6:510:2cd::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.39 via Frontend Transport; Tue, 13 Feb 2024 13:50:42 +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 SN1PEPF0002BA4B.mail.protection.outlook.com (10.167.242.68) 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 13:50: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; Tue, 13 Feb 2024 05:50:26 -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 05:50:23 -0800 From: Ori Kam To: , , , , , Viacheslav Ovsiienko , Suanming Mou , Matan Azrad CC: , , , Hamdan Igbaria Subject: [PATCH v3 2/4] net/mlx5/hws: introduce encap entropy hash calculation API Date: Tue, 13 Feb 2024 15:48:31 +0200 Message-ID: <20240213134834.16762-2-orika@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213134834.16762-1-orika@nvidia.com> References: <20240128093943.4461-1-orika@nvidia.com> <20240213134834.16762-1-orika@nvidia.com> MIME-Version: 1.0 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-TrafficTypeDiagnostic: SN1PEPF0002BA4B:EE_|CH2PR12MB4263:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a74dfe4-8606-48ee-6783-08dc2c9ac4f2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3yGj5JyNK/K63y9LCaHiiDKmwGvbgtzs9u8R3mw/X7qm216kenSglcS2louG9hOVXOPoDGZqGW3ybNInmeeyDHtihkqeesrpf6w3RgFaH6Y0a3t7UE4uQgyDnV++L9B0XTVJHNosFZ8dcmJl3tHtMM7XdsN4zgENdwXtpdk3YtbOoinyohtABzwr03u/SPvFtN2DTZ+68Okq2ni9fSuKksh2qkQSnQc75vaaMxS2Tst0lDR7qRZWSA5Nr9AzEZMstaNx0xPAgm1pz/ASiNvxBo22BpfG4xw6OlkgcFoqqmW6cw74op1/3yxkPpibxBpmI2jYym5nQQPL9Pd+wk6rsnqRFPMM5O9nUQTN/jPb8DiAWXFfgI63aixfQDXYQbJA7qrBfb3xvlj5LjIbl2XG6oO91gVGZExvMyo0j2M6hPC2ksvfOA7MIO+CO3vCKIaD9L+qWg0xtnAGQpfUCYDU8htYRwUyL/UdOf1jfJmQ+56H8n64y4WUU5FzKdFiTaC9/NTGPK2itUXgCoA0NHF/Y2BR2y45w8whRA1/LVlpw+9Jb/L73tjHjnirMpE7+b+c0qC65+sF0r3xmGXeaaBZFUuUbr0CmqH4fEwpT0hvnAQ= 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)(136003)(396003)(39860400002)(376002)(346002)(230922051799003)(64100799003)(186009)(82310400011)(1800799012)(451199024)(36840700001)(46966006)(40470700004)(478600001)(41300700001)(55016003)(5660300002)(8936002)(8676002)(4326008)(2906002)(70586007)(6636002)(54906003)(70206006)(7696005)(6666004)(6286002)(316002)(26005)(83380400001)(336012)(426003)(86362001)(82740400003)(7636003)(356005)(2616005)(110136005)(16526019)(36756003)(107886003)(1076003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2024 13:50:41.9011 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2a74dfe4-8606-48ee-6783-08dc2c9ac4f2 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: SN1PEPF0002BA4B.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4263 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 From: Hamdan Igbaria Add new function for encap entropy hash calculation, the function will check the device capability for the entropy hash type used by the device, and will calculate the entropy hash value of the user passed fields according this type. Signed-off-by: Hamdan Igbaria Acked-by: Dariusz Sosnowski --- drivers/common/mlx5/mlx5_prm.h | 8 ++- drivers/net/mlx5/hws/mlx5dr.h | 38 ++++++++++++++ drivers/net/mlx5/hws/mlx5dr_cmd.c | 23 +++++++++ drivers/net/mlx5/hws/mlx5dr_cmd.h | 4 ++ drivers/net/mlx5/hws/mlx5dr_crc32.c | 78 +++++++++++++++++++++++++++++ drivers/net/mlx5/hws/mlx5dr_crc32.h | 5 ++ 6 files changed, 154 insertions(+), 2 deletions(-) diff --git a/drivers/common/mlx5/mlx5_prm.h b/drivers/common/mlx5/mlx5_prm.h index abff8e4dc3..50c681704a 100644 --- a/drivers/common/mlx5/mlx5_prm.h +++ b/drivers/common/mlx5/mlx5_prm.h @@ -2132,7 +2132,10 @@ struct mlx5_ifc_flow_table_prop_layout_bits { struct mlx5_ifc_roce_caps_bits { u8 reserved_0[0x1e]; u8 qp_ts_format[0x2]; - u8 reserved_at_20[0x7e0]; + u8 reserved_at_20[0xa0]; + u8 r_roce_max_src_udp_port[0x10]; + u8 r_roce_min_src_udp_port[0x10]; + u8 reserved_at_e0[0x720]; }; struct mlx5_ifc_ft_fields_support_bits { @@ -2370,7 +2373,8 @@ struct mlx5_ifc_cmd_hca_cap_2_bits { u8 format_select_dw_gtpu_first_ext_dw_0[0x8]; u8 generate_wqe_type[0x20]; u8 reserved_at_2c0[0x160]; - u8 reserved_at_420[0x1c]; + u8 reserved_at_420[0x18]; + u8 encap_entropy_hash_type[0x4]; u8 flow_table_hash_type[0x4]; u8 reserved_at_440[0x3c0]; }; diff --git a/drivers/net/mlx5/hws/mlx5dr.h b/drivers/net/mlx5/hws/mlx5dr.h index d88f73ab57..321b649f8c 100644 --- a/drivers/net/mlx5/hws/mlx5dr.h +++ b/drivers/net/mlx5/hws/mlx5dr.h @@ -279,6 +279,27 @@ struct mlx5dr_action_dest_attr { } reformat; }; +union mlx5dr_crc_encap_entropy_hash_ip_field { + uint8_t ipv6_addr[16]; + struct { + uint8_t reserved[12]; + rte_be32_t ipv4_addr; + }; +}; + +struct mlx5dr_crc_encap_entropy_hash_fields { + union mlx5dr_crc_encap_entropy_hash_ip_field dst; + union mlx5dr_crc_encap_entropy_hash_ip_field src; + uint8_t next_protocol; + rte_be16_t dst_port; + rte_be16_t src_port; +}__rte_packed; + +enum mlx5dr_crc_encap_entropy_hash_size { + MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_8, + MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_16, +}; + /* Open a context used for direct rule insertion using hardware steering. * Each context can contain multiple tables of different types. * @@ -845,4 +866,21 @@ int mlx5dr_send_queue_action(struct mlx5dr_context *ctx, */ int mlx5dr_debug_dump(struct mlx5dr_context *ctx, FILE *f); +/* Calculate encap entropy hash value + * + * @param[in] ctx + * The context to get from it's capabilities the entropy hash type. + * @param[in] data + * The fields for the hash calculation. + * @param[in] entropy_res + * An array to store the hash value to it. + * @param[in] res_size + * The result size. + * @return zero on success non zero otherwise. + */ +int mlx5dr_crc_encap_entropy_hash_calc(struct mlx5dr_context *ctx, + struct mlx5dr_crc_encap_entropy_hash_fields *data, + uint8_t entropy_res[], + enum mlx5dr_crc_encap_entropy_hash_size res_size); + #endif diff --git a/drivers/net/mlx5/hws/mlx5dr_cmd.c b/drivers/net/mlx5/hws/mlx5dr_cmd.c index 876a47147d..f77b194708 100644 --- a/drivers/net/mlx5/hws/mlx5dr_cmd.c +++ b/drivers/net/mlx5/hws/mlx5dr_cmd.c @@ -1103,6 +1103,8 @@ int mlx5dr_cmd_query_caps(struct ibv_context *ctx, caps->ipsec_offload = MLX5_GET(query_hca_cap_out, out, capability.cmd_hca_cap.ipsec_offload); + caps->roce = MLX5_GET(query_hca_cap_out, out, capability.cmd_hca_cap.roce); + MLX5_SET(query_hca_cap_in, in, op_mod, MLX5_GET_HCA_CAP_OP_MOD_GENERAL_DEVICE_2 | MLX5_HCA_CAP_OPMOD_GET_CUR); @@ -1158,6 +1160,9 @@ int mlx5dr_cmd_query_caps(struct ibv_context *ctx, caps->flow_table_hash_type = MLX5_GET(query_hca_cap_out, out, capability.cmd_hca_cap_2.flow_table_hash_type); + caps->encap_entropy_hash_type = MLX5_GET(query_hca_cap_out, out, + capability.cmd_hca_cap_2.encap_entropy_hash_type); + MLX5_SET(query_hca_cap_in, in, op_mod, MLX5_GET_HCA_CAP_OP_MOD_NIC_FLOW_TABLE | MLX5_HCA_CAP_OPMOD_GET_CUR); @@ -1306,6 +1311,24 @@ int mlx5dr_cmd_query_caps(struct ibv_context *ctx, capability.esw_cap.merged_eswitch); } + if (caps->roce) { + MLX5_SET(query_hca_cap_in, in, op_mod, + MLX5_GET_HCA_CAP_OP_MOD_ROCE | + MLX5_HCA_CAP_OPMOD_GET_CUR); + + ret = mlx5_glue->devx_general_cmd(ctx, in, sizeof(in), out, sizeof(out)); + if (ret) { + DR_LOG(ERR, "Failed to query roce caps"); + rte_errno = errno; + return rte_errno; + } + + caps->roce_max_src_udp_port = MLX5_GET(query_hca_cap_out, out, + capability.roce_caps.r_roce_max_src_udp_port); + caps->roce_min_src_udp_port = MLX5_GET(query_hca_cap_out, out, + capability.roce_caps.r_roce_min_src_udp_port); + } + ret = mlx5_glue->query_device_ex(ctx, NULL, &attr_ex); if (ret) { DR_LOG(ERR, "Failed to query device attributes"); diff --git a/drivers/net/mlx5/hws/mlx5dr_cmd.h b/drivers/net/mlx5/hws/mlx5dr_cmd.h index 18c2b07fc8..694231e08f 100644 --- a/drivers/net/mlx5/hws/mlx5dr_cmd.h +++ b/drivers/net/mlx5/hws/mlx5dr_cmd.h @@ -246,6 +246,10 @@ struct mlx5dr_cmd_query_caps { uint32_t shared_vhca_id; char fw_ver[64]; bool ipsec_offload; + uint8_t encap_entropy_hash_type; + bool roce; + uint16_t roce_max_src_udp_port; + uint16_t roce_min_src_udp_port; }; int mlx5dr_cmd_destroy_obj(struct mlx5dr_devx_obj *devx_obj); diff --git a/drivers/net/mlx5/hws/mlx5dr_crc32.c b/drivers/net/mlx5/hws/mlx5dr_crc32.c index 9c454eda0c..7431462e14 100644 --- a/drivers/net/mlx5/hws/mlx5dr_crc32.c +++ b/drivers/net/mlx5/hws/mlx5dr_crc32.c @@ -50,6 +50,42 @@ uint32_t dr_ste_crc_tab32[] = { 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; +/* CRC table for the CRC-16, the polynome is 0x100b */ +uint16_t dr_crc_inner_crc_tab16[] = { + 0x0000, 0x100B, 0x2016, 0x301D, 0x402C, 0x5027, 0x603A, 0x7031, + 0x8058, 0x9053, 0xA04E, 0xB045, 0xC074, 0xD07F, 0xE062, 0xF069, + 0x10BB, 0x00B0, 0x30AD, 0x20A6, 0x5097, 0x409C, 0x7081, 0x608A, + 0x90E3, 0x80E8, 0xB0F5, 0xA0FE, 0xD0CF, 0xC0C4, 0xF0D9, 0xE0D2, + 0x2176, 0x317D, 0x0160, 0x116B, 0x615A, 0x7151, 0x414C, 0x5147, + 0xA12E, 0xB125, 0x8138, 0x9133, 0xE102, 0xF109, 0xC114, 0xD11F, + 0x31CD, 0x21C6, 0x11DB, 0x01D0, 0x71E1, 0x61EA, 0x51F7, 0x41FC, + 0xB195, 0xA19E, 0x9183, 0x8188, 0xF1B9, 0xE1B2, 0xD1AF, 0xC1A4, + 0x42EC, 0x52E7, 0x62FA, 0x72F1, 0x02C0, 0x12CB, 0x22D6, 0x32DD, + 0xC2B4, 0xD2BF, 0xE2A2, 0xF2A9, 0x8298, 0x9293, 0xA28E, 0xB285, + 0x5257, 0x425C, 0x7241, 0x624A, 0x127B, 0x0270, 0x326D, 0x2266, + 0xD20F, 0xC204, 0xF219, 0xE212, 0x9223, 0x8228, 0xB235, 0xA23E, + 0x639A, 0x7391, 0x438C, 0x5387, 0x23B6, 0x33BD, 0x03A0, 0x13AB, + 0xE3C2, 0xF3C9, 0xC3D4, 0xD3DF, 0xA3EE, 0xB3E5, 0x83F8, 0x93F3, + 0x7321, 0x632A, 0x5337, 0x433C, 0x330D, 0x2306, 0x131B, 0x0310, + 0xF379, 0xE372, 0xD36F, 0xC364, 0xB355, 0xA35E, 0x9343, 0x8348, + 0x85D8, 0x95D3, 0xA5CE, 0xB5C5, 0xC5F4, 0xD5FF, 0xE5E2, 0xF5E9, + 0x0580, 0x158B, 0x2596, 0x359D, 0x45AC, 0x55A7, 0x65BA, 0x75B1, + 0x9563, 0x8568, 0xB575, 0xA57E, 0xD54F, 0xC544, 0xF559, 0xE552, + 0x153B, 0x0530, 0x352D, 0x2526, 0x5517, 0x451C, 0x7501, 0x650A, + 0xA4AE, 0xB4A5, 0x84B8, 0x94B3, 0xE482, 0xF489, 0xC494, 0xD49F, + 0x24F6, 0x34FD, 0x04E0, 0x14EB, 0x64DA, 0x74D1, 0x44CC, 0x54C7, + 0xB415, 0xA41E, 0x9403, 0x8408, 0xF439, 0xE432, 0xD42F, 0xC424, + 0x344D, 0x2446, 0x145B, 0x0450, 0x7461, 0x646A, 0x5477, 0x447C, + 0xC734, 0xD73F, 0xE722, 0xF729, 0x8718, 0x9713, 0xA70E, 0xB705, + 0x476C, 0x5767, 0x677A, 0x7771, 0x0740, 0x174B, 0x2756, 0x375D, + 0xD78F, 0xC784, 0xF799, 0xE792, 0x97A3, 0x87A8, 0xB7B5, 0xA7BE, + 0x57D7, 0x47DC, 0x77C1, 0x67CA, 0x17FB, 0x07F0, 0x37ED, 0x27E6, + 0xE642, 0xF649, 0xC654, 0xD65F, 0xA66E, 0xB665, 0x8678, 0x9673, + 0x661A, 0x7611, 0x460C, 0x5607, 0x2636, 0x363D, 0x0620, 0x162B, + 0xF6F9, 0xE6F2, 0xD6EF, 0xC6E4, 0xB6D5, 0xA6DE, 0x96C3, 0x86C8, + 0x76A1, 0x66AA, 0x56B7, 0x46BC, 0x368D, 0x2686, 0x169B, 0x0690 +}; + uint32_t mlx5dr_crc32_calc(uint8_t *p, size_t len) { uint32_t crc = 0; @@ -59,3 +95,45 @@ uint32_t mlx5dr_crc32_calc(uint8_t *p, size_t len) return rte_be_to_cpu_32(crc); } + +uint16_t mlx5dr_crc16_calc(uint8_t *p, size_t len, uint16_t crc_tab16[]) +{ + uint16_t crc = 0; + + while (len--) + crc = (crc << 8) ^ crc_tab16[((crc >> 8) ^ *p++) & 0xff]; + + return crc; +} + +int mlx5dr_crc_encap_entropy_hash_calc(struct mlx5dr_context *ctx, + struct mlx5dr_crc_encap_entropy_hash_fields *data, + uint8_t entropy_res[], + enum mlx5dr_crc_encap_entropy_hash_size res_size) +{ + struct mlx5dr_cmd_query_caps *caps = ctx->caps; + uint16_t max_hash, min_hash, res; + + if (caps->encap_entropy_hash_type) { + DR_LOG(ERR, "calculation of encap_entropy_hash_type 0x%x not supported", + caps->encap_entropy_hash_type); + rte_errno = ENOTSUP; + return rte_errno; + } + + max_hash = caps->roce_max_src_udp_port; + min_hash = caps->roce_min_src_udp_port; + + res = mlx5dr_crc16_calc((uint8_t *)data, sizeof(*data), dr_crc_inner_crc_tab16); + + if (res_size == MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_16) { + *(uint16_t *)entropy_res = rte_cpu_to_be_16((min_hash | res) & max_hash); + } else if (res_size == MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_8) { + *entropy_res = (uint8_t)(res & 0xff); + } else { + rte_errno = ENOTSUP; + return rte_errno; + } + + return 0; +} diff --git a/drivers/net/mlx5/hws/mlx5dr_crc32.h b/drivers/net/mlx5/hws/mlx5dr_crc32.h index 9aab9e06ca..75b6009a15 100644 --- a/drivers/net/mlx5/hws/mlx5dr_crc32.h +++ b/drivers/net/mlx5/hws/mlx5dr_crc32.h @@ -10,4 +10,9 @@ */ uint32_t mlx5dr_crc32_calc(uint8_t *p, size_t len); +/* Standard CRC16 calculation using the crc_tab16 param to indicate + * the pre-calculated polynome hash values. + */ +uint16_t mlx5dr_crc16_calc(uint8_t *p, size_t len, uint16_t crc_tab16[]); + #endif /* MLX5DR_CRC32_C_ */ From patchwork Tue Feb 13 13:48:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ori Kam X-Patchwork-Id: 136639 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 7D3A343AD8; Tue, 13 Feb 2024 14:50:58 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8503B42DC9; Tue, 13 Feb 2024 14:50:48 +0100 (CET) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2089.outbound.protection.outlook.com [40.107.244.89]) by mails.dpdk.org (Postfix) with ESMTP id 8925742DC3 for ; Tue, 13 Feb 2024 14:50:47 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Zi8/Xkh6EF+cmmWX0nPdEvlSfDU9p+vSrOp1vFCQAswECNLMonq9t0DlFQE7LmhnqODbRM2aYCBvugTlU+Wcaq3PnNwdsmRBwUY5Fo3cl+yDwheRfWVg1tbUUhaaXuqPbJI6VEZ1o3epYYw0MOUTaYuXgwwYCmAnTq6CZzxM+hm/LyXAAbGZBcAd2bYM1ZUJF65t2w+Hg6wEK0PreM1rxO6s+VCE0eFsw5/4DK4iaPT+NlAS8FfOuV7+agzFy0OXPdbDkI3JHNpl4fFUm2bbyVc5F3cdx3YRDn9dsAo2y2eTCVYJdbEywuUriqvsPfClqyj7Rp170JNa+WTdMqLRfg== 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=iz69DoQpRO2kftLWjJURD+N8elw4ESZLDPR2GT+frRU=; b=hhtfn/jId/4dLtIUkAqHeBlDiTsBLAHlbFBCK+aULzWx57Gn1PxleZ+PY61GxbwiVOCdmQb9kqe3xFImFXxKd01dfbNRmegMv43LKSS8y3zKrbkV5+C5VRrOeycRdQ36S9rYL2k55wRh7ZTDR6WLMB1e8OiSfRHvM9Wm3iCVSVpy58WvsFy0xXpkJ4NZpb/PBq4lIASyLYETAi2tsm1rqjsFfwTFzpPPzqeAfGwCyi7Z2EINQES2H/u5K7lCs2NzAjKOTJPAFm9wx2AHxvQ9WmKczz2S1Fw2AbO9NZJUwhv5Ls9t0ZWqFwiBMVRSISGnLnw53X1gzPi35CkkZq1+Ag== 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=iz69DoQpRO2kftLWjJURD+N8elw4ESZLDPR2GT+frRU=; b=WxOnmPFBRROH9jT6mMvypFPqWrrDeMk4NNvwfoR/Jb7PSw/uByPvB3qBzTS+V4uWlfX9U3CwNR2O40mLOBnVF4BLHBfQAOArK89IsVPLex/ZSaDJwfijUZz2CY2CC8oPr7Bys+zwFnMWA38ILepp/NphGzxgP8k6iEagLWF7odjOWQaD/fKkXNLsCcssqDuD1WDoBCnB0PkY16TKtHTYsQ8N80CVFvsJBxWNFaWjI7e43Etop9QSMMRL9SmWAJyp+6NqaZUkKisTChyMD6fEtYJKeGmqW+o7IGJHpIWiJ75jGp1sVjujx0EKHTVincAYjzCQ8jn35M8Y764onJGb9Q== Received: from PH7P220CA0094.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:32d::30) by CH3PR12MB8187.namprd12.prod.outlook.com (2603:10b6:610:125::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.25; Tue, 13 Feb 2024 13:50:44 +0000 Received: from SN1PEPF0002BA51.namprd03.prod.outlook.com (2603:10b6:510:32d:cafe::90) by PH7P220CA0094.outlook.office365.com (2603:10b6:510:32d::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.39 via Frontend Transport; Tue, 13 Feb 2024 13:50:44 +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 SN1PEPF0002BA51.mail.protection.outlook.com (10.167.242.74) 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 13:50:44 +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 05:50:30 -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 05:50:27 -0800 From: Ori Kam To: , , , , , Viacheslav Ovsiienko , Suanming Mou , Matan Azrad CC: , , Subject: [PATCH v3 3/4] net/mlx5: add calc encap hash support Date: Tue, 13 Feb 2024 15:48:32 +0200 Message-ID: <20240213134834.16762-3-orika@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213134834.16762-1-orika@nvidia.com> References: <20240128093943.4461-1-orika@nvidia.com> <20240213134834.16762-1-orika@nvidia.com> MIME-Version: 1.0 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-TrafficTypeDiagnostic: SN1PEPF0002BA51:EE_|CH3PR12MB8187:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d38684f-149a-4ad0-1aef-08dc2c9ac686 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sCreK7AeFWbPk+1ak5arDf5oVBhD2ZfAA6I9GOj1VjLYBZZ+h5f5p7eMFCUyEbBL09hKeJalVgKshaL+bL3cu4jMgVsXe3TJtbWvhURHXT+ygkGSRK8BBJsNY1v2XZewmOGXWJ0XI0oZPTuHoW/Hdwn3s2Cg2p8OtRRWLyKMTr1lpKUv6CkCMEX1SLkreedpoeEuzvH8I6Z3tNoLidtYrshS84zSTf7hAxl73HMfFXeoMO6BB7v619USP610AFWrdULv9rHCoHd7kEmNUowTWPZWksvCGuQX0ByGq+nX5A6ImpohSlqnOul2cg+BJWExGWHCdj0hJ/K0YIfp2J5wt8/1QgvyK51Kv1aviKB0XENHsEnqpba97Re3+LClXxcaP5xVOb2NM7NiRerntsf10mZPSiN+/nIpMTrxcOcYfxV1xxBxqixfdv+lR5/u9fv1T3r2dvJIL3MIUVBlDsUepgMeDPOxjggr/EFyhkTz1GwwfhF/3xEn74ViIa5svmX4ezt1jHeo80UW3JYZkoolf71Xl5YmQVH7awk843gpBcLQTXZpq03Sq2zRZM21K/Pat7P9jlKPX3DFQNfa+S9MUqpqCzjucTe5jFphZXdBHbE= 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)(39860400002)(136003)(376002)(346002)(396003)(230922051799003)(64100799003)(1800799012)(451199024)(82310400011)(186009)(46966006)(36840700001)(40470700004)(55016003)(478600001)(41300700001)(4326008)(8936002)(2906002)(5660300002)(8676002)(110136005)(6666004)(70206006)(54906003)(7696005)(6636002)(316002)(83380400001)(2616005)(70586007)(107886003)(426003)(336012)(86362001)(7636003)(356005)(16526019)(1076003)(82740400003)(26005)(6286002)(36756003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2024 13:50:44.5624 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6d38684f-149a-4ad0-1aef-08dc2c9ac686 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: SN1PEPF0002BA51.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8187 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 This commit adds support for encap hash calculation. Signed-off-by: Ori Kam Acked-by: Dariusz Sosnowski --- drivers/net/mlx5/mlx5_flow.c | 29 +++++++++++++++ drivers/net/mlx5/mlx5_flow.h | 8 ++++ drivers/net/mlx5/mlx5_flow_hw.c | 66 +++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c index 40376c99ba..7c5a5da8ec 100644 --- a/drivers/net/mlx5/mlx5_flow.c +++ b/drivers/net/mlx5/mlx5_flow.c @@ -1197,6 +1197,12 @@ mlx5_flow_calc_table_hash(struct rte_eth_dev *dev, const struct rte_flow_item pattern[], uint8_t pattern_template_index, uint32_t *hash, struct rte_flow_error *error); +static int +mlx5_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); static const struct rte_flow_ops mlx5_flow_ops = { .validate = mlx5_flow_validate, @@ -1253,6 +1259,7 @@ static const struct rte_flow_ops mlx5_flow_ops = { .async_action_list_handle_query_update = mlx5_flow_async_action_list_handle_query_update, .flow_calc_table_hash = mlx5_flow_calc_table_hash, + .flow_calc_encap_hash = mlx5_flow_calc_encap_hash, }; /* Tunnel information. */ @@ -11121,6 +11128,28 @@ mlx5_flow_calc_table_hash(struct rte_eth_dev *dev, hash, error); } +static int +mlx5_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) +{ + enum mlx5_flow_drv_type drv_type = flow_get_drv_type(dev, NULL); + const struct mlx5_flow_driver_ops *fops; + + if (drv_type == MLX5_FLOW_TYPE_MIN || drv_type == MLX5_FLOW_TYPE_MAX) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, + NULL, "invalid driver type"); + fops = flow_get_drv_ops(drv_type); + if (!fops || !fops->flow_calc_encap_hash) + return rte_flow_error_set(error, ENOTSUP, + RTE_FLOW_ERROR_TYPE_ACTION, + NULL, "no calc encap hash handler"); + return fops->flow_calc_encap_hash(dev, pattern, dest_field, hash, error); +} + /** * Destroy all indirect actions (shared RSS). * diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index b086dfaf28..a4d0ff7b13 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -2198,6 +2198,13 @@ typedef int const struct rte_flow_item pattern[], uint8_t pattern_template_index, uint32_t *hash, struct rte_flow_error *error); +typedef int +(*mlx5_flow_calc_encap_hash_t) + (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); struct mlx5_flow_driver_ops { mlx5_flow_validate_t validate; @@ -2271,6 +2278,7 @@ struct mlx5_flow_driver_ops { mlx5_flow_async_action_list_handle_query_update_t async_action_list_handle_query_update; mlx5_flow_calc_table_hash_t flow_calc_table_hash; + mlx5_flow_calc_encap_hash_t flow_calc_encap_hash; }; /* mlx5_flow.c */ diff --git a/drivers/net/mlx5/mlx5_flow_hw.c b/drivers/net/mlx5/mlx5_flow_hw.c index 3af5e1f160..ce2fb7c5f9 100644 --- a/drivers/net/mlx5/mlx5_flow_hw.c +++ b/drivers/net/mlx5/mlx5_flow_hw.c @@ -11701,6 +11701,71 @@ flow_hw_calc_table_hash(struct rte_eth_dev *dev, return 0; } +static int +flow_hw_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) +{ + struct mlx5_priv *priv = dev->data->dev_private; + struct mlx5dr_crc_encap_entropy_hash_fields data; + enum mlx5dr_crc_encap_entropy_hash_size res_size = + dest_field == RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT ? + MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_16 : + MLX5DR_CRC_ENCAP_ENTROPY_HASH_SIZE_8; + int res; + + memset(&data, 0, sizeof(struct mlx5dr_crc_encap_entropy_hash_fields)); + + for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) { + switch (pattern->type) { + case RTE_FLOW_ITEM_TYPE_IPV4: + data.dst.ipv4_addr = + ((const struct rte_flow_item_ipv4 *)(pattern->spec))->hdr.dst_addr; + data.src.ipv4_addr = + ((const struct rte_flow_item_ipv4 *)(pattern->spec))->hdr.src_addr; + break; + case RTE_FLOW_ITEM_TYPE_IPV6: + memcpy(data.dst.ipv6_addr, + ((const struct rte_flow_item_ipv6 *)(pattern->spec))->hdr.dst_addr, + sizeof(data.dst.ipv6_addr)); + memcpy(data.src.ipv6_addr, + ((const struct rte_flow_item_ipv6 *)(pattern->spec))->hdr.src_addr, + sizeof(data.src.ipv6_addr)); + break; + case RTE_FLOW_ITEM_TYPE_UDP: + data.next_protocol = IPPROTO_UDP; + data.dst_port = + ((const struct rte_flow_item_udp *)(pattern->spec))->hdr.dst_port; + data.src_port = + ((const struct rte_flow_item_udp *)(pattern->spec))->hdr.src_port; + break; + case RTE_FLOW_ITEM_TYPE_TCP: + data.next_protocol = IPPROTO_TCP; + data.dst_port = + ((const struct rte_flow_item_tcp *)(pattern->spec))->hdr.dst_port; + data.src_port = + ((const struct rte_flow_item_tcp *)(pattern->spec))->hdr.src_port; + break; + case RTE_FLOW_ITEM_TYPE_ICMP: + data.next_protocol = IPPROTO_ICMP; + break; + case RTE_FLOW_ITEM_TYPE_ICMP6: + data.next_protocol = IPPROTO_ICMPV6; + break; + default: + break; + } + } + res = mlx5dr_crc_encap_entropy_hash_calc(priv->dr_ctx, &data, hash, res_size); + if (res) + return rte_flow_error_set(error, res, + RTE_FLOW_ERROR_TYPE_UNSPECIFIED, + NULL, "error while calculating encap hash"); + return 0; +} + const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops = { .info_get = flow_hw_info_get, .configure = flow_hw_configure, @@ -11746,6 +11811,7 @@ const struct mlx5_flow_driver_ops mlx5_flow_hw_drv_ops = { .item_create = flow_dv_item_create, .item_release = flow_dv_item_release, .flow_calc_table_hash = flow_hw_calc_table_hash, + .flow_calc_encap_hash = flow_hw_calc_encap_hash, }; /** From patchwork Tue Feb 13 13:48:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ori Kam X-Patchwork-Id: 136640 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 871C043AD8; Tue, 13 Feb 2024 14:51:06 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 53F0842DCE; Tue, 13 Feb 2024 14:50:52 +0100 (CET) Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2040.outbound.protection.outlook.com [40.107.212.40]) by mails.dpdk.org (Postfix) with ESMTP id A3AEF42DCD for ; Tue, 13 Feb 2024 14:50:51 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CjHb/l32uX9f9qQK6Tp0upHkx9mUv3IeSWg1Byy60FjAV6PdLDN28avRFw3TWRFY8Y7PBIFXejMvkEmo6y9Kc88pDXvrTxUmBKucNu7P8FBqiN36bPaMCK1EzMZzaPi99HFU9pwG4nPeN+7F5GKjwNX6x18BasMtvEqZmh3Xl7AG2+PnvUZI+zC7u5QaZnHok3Du67pEPOVJ0Fs+Xop4+Jxy+C9o5Dk5DP+EFB/3aqtoIgltb0e6sQKPP/E4vSOQDJ6DbGAwGHGTXToMLkR5lU/4SeroIstaxJ422kbXFc9VDsDBWVo/0Y/DUV0GP7689pg1bPc/49jloMlH1iRyzA== 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=Y6L1qqFUtBqdUdU5NmDDNTTLz953m6DeT7INfQB7kQw=; b=n+uETDWGtaR8lmhKYWLhHmF/2TjcxnpO6ZIbMK8qIWzYUkI3OC3VINwFJvwBnu+tVzMcRPNxDYTw2MFvYL2yzSmsO/417sHQ0r1cJZ9LvxXzcSxy9Mv46eyRpp2hl2VsGS9bxxhqKPitatV5nv227GOEauvQ78IbO7k1tjjwqo4pJ0+c30a1Q2oGchffwt705u0UeHgs9/seGv92UPMWF0VGBxKt1M/xOISqqjY3zfQZoxp12FV5B94CcgcUq2353e5gIdyrC6aosT9zdX6f2AH2KV1b0hZyRZj64/PB1Te0Mk+Ns1uEibWbpshgdY4EyG0/qN4nrYd5IMo6NjuLbQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) 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=Y6L1qqFUtBqdUdU5NmDDNTTLz953m6DeT7INfQB7kQw=; b=FpLLpvl6ROWA3onNKYtbTSaMEDFMVwTHqMfjBWXBxgfYV7kNFq8yIebBzzk/d/z76tEospDsh01x9qHRpfALLXIvBnNgneoagGhAUrmcMy1WFUWi7jUTuJza84aEKkvn2ZGkuQFmEU27rXSoKgBYOmlwwrPh0zSVSiNkowi7a3BsOuXqkSpHYJIa7bsSZJMjni/eJxRFjBn6C9RqeWu7kyNxkYIiXvni6w5sJUn43IRwi4H72BozcCOcknCM8+pLCbkGWaiddTyV7Tzur0YaIKaBKJ/6k21wrq8tmxDHPWEZUodMXp0b01VSG2mTqlmV95fCWUm+QCj5zCnvNEjtEg== Received: from MW4PR03CA0024.namprd03.prod.outlook.com (2603:10b6:303:8f::29) by DM4PR12MB6232.namprd12.prod.outlook.com (2603:10b6:8:a5::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.11; Tue, 13 Feb 2024 13:50:49 +0000 Received: from CO1PEPF000042AC.namprd03.prod.outlook.com (2603:10b6:303:8f:cafe::5d) by MW4PR03CA0024.outlook.office365.com (2603:10b6:303:8f::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 13:50:48 +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 CO1PEPF000042AC.mail.protection.outlook.com (10.167.243.41) 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 13:50:48 +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, 13 Feb 2024 05:50:33 -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 05:50:30 -0800 From: Ori Kam To: , , , , , Aman Singh , "Yuying Zhang" CC: , , Subject: [PATCH v3 4/4] app/testpmd: add encap hash calculation Date: Tue, 13 Feb 2024 15:48:33 +0200 Message-ID: <20240213134834.16762-4-orika@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213134834.16762-1-orika@nvidia.com> References: <20240128093943.4461-1-orika@nvidia.com> <20240213134834.16762-1-orika@nvidia.com> MIME-Version: 1.0 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-TrafficTypeDiagnostic: CO1PEPF000042AC:EE_|DM4PR12MB6232:EE_ X-MS-Office365-Filtering-Correlation-Id: 226eede9-283f-4adc-f5ae-08dc2c9ac8fc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: F8PZ0gDSjk02ho5oAP2Fj9Y1xmPtbBKU5Ue12XxDIDSiyYdp23KNgndVkwaBb7UYKA/ur+NA4vSa6PWviZ8Fp228onKmt9mL/gZRYgNkQNw+rkoSSjgHfI0wXPzFHfL/a3fcD6YXjAuJbVTmGYngtufdtMtwypZN7G+aU/ijuCISPO0HyFbpbbYSqbkAANYta3bXbrgpEnJVCjSdPYOvJY/mnzB3TgokfA1zQ49rnA6UH1At0EQHy1J8XqpeD60rl8KMVMNjjCn/7pY9D7jqjCgs/X3Olcle08xf7zuRNPHKorGUTd36fHNAEI/IFzYQILGLC9p6qTJjNfHN5RRWh1ic3TJo8eyPdEkRd3LmQfrJ+/Y0kh77kcYEcWf5ELRb8qeRcj1x5EERW/mo8KsB3NhG2zyyuiK7Q9Te/X7RfXBNrMF9Yg+byNLZwdAqYLoFZ70spy2GcXgVp6v64NT1pLCCh7sqx6dtikpv7xzlgUzyGwdYML534+UyirmK4hKhif8GyBqew1NmVvfqFT4vXPy74vqtjLWdtCf8P9n+QFqbNObn6VPB8q9vanlszFROLuSxZ2/cb9wc7ZKUGSQ9JzWxfLquPvua9LrtsguTyr4= 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)(136003)(376002)(346002)(230922051799003)(64100799003)(186009)(82310400011)(451199024)(1800799012)(40470700004)(46966006)(36840700001)(478600001)(41300700001)(55016003)(7696005)(70586007)(5660300002)(2906002)(316002)(26005)(8676002)(110136005)(70206006)(36756003)(83380400001)(356005)(2616005)(8936002)(4326008)(6286002)(16526019)(336012)(86362001)(54906003)(82740400003)(1076003)(107886003)(7636003)(426003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2024 13:50:48.7593 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 226eede9-283f-4adc-f5ae-08dc2c9ac8fc 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: CO1PEPF000042AC.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6232 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 This commits add support for calculating the encap hash. Command structure: flow hash {port} encap {target field} pattern {item} [/ {item} [...] ] / end Example: calculate hash to be used by VXLAN encapsulation. flow hash 0 encap hash_field_sport pattern ipv4 dst is 7.7.7.7 src is 8.8.8.8 / udp dst is 5678 src is 1234 / end Signed-off-by: Ori Kam Acked-by: Dariusz Sosnowski --- app/test-pmd/cmdline_flow.c | 57 +++++++++++++++++++-- app/test-pmd/config.c | 30 +++++++++++ app/test-pmd/testpmd.h | 3 ++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 21 +++++++- 4 files changed, 106 insertions(+), 5 deletions(-) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index a4131e1b39..844840fe2d 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -219,6 +219,10 @@ enum index { HASH_CALC_TABLE, HASH_CALC_PATTERN_INDEX, HASH_CALC_PATTERN, + HASH_CALC_ENCAP, + HASH_CALC_DEST, + ENCAP_HASH_FIELD_SRC_PORT, + ENCAP_HASH_FIELD_GRE_FLOW_ID, /* Tunnel arguments. */ TUNNEL_CREATE, @@ -1220,6 +1224,8 @@ struct buffer { uint32_t pattern_n; uint32_t actions_n; uint8_t *data; + enum rte_flow_encap_hash_field field; + uint8_t encap_hash; } vc; /**< Validate/create arguments. */ struct { uint64_t *rule; @@ -2618,6 +2624,18 @@ static const enum index action_nat64[] = { ZERO, }; +static const enum index next_hash_subcmd[] = { + HASH_CALC_TABLE, + HASH_CALC_ENCAP, + ZERO, +}; + +static const enum index next_hash_encap_dest_subcmd[] = { + ENCAP_HASH_FIELD_SRC_PORT, + ENCAP_HASH_FIELD_GRE_FLOW_ID, + ZERO, +}; + static int parse_set_raw_encap_decap(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); @@ -3875,7 +3893,7 @@ static const struct token token_list[] = { [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)), + .next = NEXT(next_hash_subcmd, NEXT_ENTRY(COMMON_PORT_ID)), .args = ARGS(ARGS_ENTRY(struct buffer, port)), .call = parse_hash, }, @@ -3889,6 +3907,12 @@ static const struct token token_list[] = { args.vc.table_id)), .call = parse_hash, }, + [HASH_CALC_ENCAP] = { + .name = "encap", + .help = "calculates encap hash", + .next = NEXT(next_hash_encap_dest_subcmd), + .call = parse_hash, + }, [HASH_CALC_PATTERN_INDEX] = { .name = "pattern_template", .help = "specify pattern template id", @@ -3898,6 +3922,18 @@ static const struct token token_list[] = { args.vc.pat_templ_id)), .call = parse_hash, }, + [ENCAP_HASH_FIELD_SRC_PORT] = { + .name = "hash_field_sport", + .help = "the encap hash field is src port", + .next = NEXT(NEXT_ENTRY(ITEM_PATTERN)), + .call = parse_hash, + }, + [ENCAP_HASH_FIELD_GRE_FLOW_ID] = { + .name = "hash_field_flow_id", + .help = "the encap hash field is NVGRE flow id", + .next = NEXT(NEXT_ENTRY(ITEM_PATTERN)), + .call = parse_hash, + }, /* Top-level command. */ [INDIRECT_ACTION] = { .name = "indirect_action", @@ -11075,6 +11111,15 @@ parse_hash(struct context *ctx, const struct token *token, ctx->object = out->args.vc.pattern; ctx->objmask = NULL; return len; + case HASH_CALC_ENCAP: + out->args.vc.encap_hash = 1; + return len; + case ENCAP_HASH_FIELD_SRC_PORT: + out->args.vc.field = RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT; + return len; + case ENCAP_HASH_FIELD_GRE_FLOW_ID: + out->args.vc.field = RTE_FLOW_ENCAP_HASH_FIELD_NVGRE_FLOW_ID; + return len; default: return -1; } @@ -13068,9 +13113,13 @@ cmd_flow_parsed(const struct buffer *in) 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); + if (!in->args.vc.encap_hash) + port_flow_hash_calc(in->port, in->args.vc.table_id, + in->args.vc.pat_templ_id, + in->args.vc.pattern); + else + port_flow_hash_calc_encap(in->port, in->args.vc.field, + in->args.vc.pattern); break; case QUEUE_AGED: port_queue_flow_aged(in->port, in->queue, diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index cad7537bc6..e26b5bd18d 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -3339,6 +3339,36 @@ port_flow_hash_calc(portid_t port_id, uint32_t table_id, return 0; } +/** Calculate the encap hash result for a given pattern. */ +int +port_flow_hash_calc_encap(portid_t port_id, + enum rte_flow_encap_hash_field encap_hash_field, + const struct rte_flow_item pattern[]) +{ + struct rte_flow_error error; + int ret = 0; + uint16_t hash = 0; + uint8_t len = encap_hash_field == RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT ? 2 : 1; + + if (port_id_is_invalid(port_id, ENABLED_WARN) || + port_id == (portid_t)RTE_PORT_ALL) { + printf("Failed to calculate encap hash - not a valid port"); + return -EINVAL; + } + + ret = rte_flow_calc_encap_hash(port_id, pattern, encap_hash_field, len, + (uint8_t *)&hash, &error); + if (ret < 0) { + printf("Failed to calculate encap hash"); + return ret; + } + if (encap_hash_field == RTE_FLOW_ENCAP_HASH_FIELD_SRC_PORT) + printf("encap hash result %#x\n", hash); + else + printf("encap hash result %#x\n", *(uint8_t *)&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 9b10a9ea1c..e18546c46e 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -1016,6 +1016,9 @@ 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[]); +int port_flow_hash_calc_encap(portid_t port_id, + enum rte_flow_encap_hash_field encap_hash_field, + 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/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 08a0b59535..bf48f01b0a 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -3297,7 +3297,7 @@ The usual error message is shown when operations results cannot be pulled:: Calculating hash ~~~~~~~~~~~~~~~~ -``flow hash`` calculates the hash for a given pattern. +``flow hash {port_id} template_table`` calculates the hash for a given pattern. It is bound to ``rte_flow_calc_table_hash()``:: flow hash {port_id} template_table {table_id} @@ -3316,6 +3316,25 @@ Otherwise, it will show an error message of the form:: This command uses the same pattern items as ``flow create``, their format is described in `Creating flow rules`_. + +Simulate encap hash calculation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +``flow hash {port_id} encap`` adds hash query, that returns the hash value +that the HW will calculate when encapsulating a packet. + + flow hash {port_id} encap {target field} pattern {item} [/ {item} [...]] / end + +If successful, it will show:: + + encap hash result #[...] + +The value will be shown as uint16_t without endian conversion. + +Otherwise it will show an error message of the form:: + + Failed to calculate encap hash - [...] + Creating a tunnel stub for offload ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~