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 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.126.230.35] X-ClientProxiedBy: rnnvmail203.nvidia.com (10.129.68.9) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- 2.34.1