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 7F9BB43B05; Tue, 13 Feb 2024 15:17:41 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DD9BF42DED; Tue, 13 Feb 2024 15:17:26 +0100 (CET) Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2079.outbound.protection.outlook.com [40.107.93.79]) by mails.dpdk.org (Postfix) with ESMTP id 3969742DE3 for ; Tue, 13 Feb 2024 15:17:25 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YxhXk0Lbw8Dp3JJPsRX1RNJjchnwRzpcRTl8+ucwDTa0XMN0yYUdj30W3VFXNwTQzJ+JRZ56fhbpjf/8PZT1leEzsI35STL2nfMpG356VGf5WJBtzOJDI5uzBklYCpVExCKt4yAp2b25nCnXpw0gDnR/BSgw5AHSl9v+xyUpKAjuqTbEVypQqr5fql5t5FPE3sqg+g9feItEMa7eMO0bK+n2Sf/tA5nxYNKuMiik2UV4PiPHByJHhcP73wqW6EQOLLUR0vtJhsim2JHBfi1VaszLF3z5J0QPr2tSE8eBZT8+ZSo/0p2eqMEdrGEnirj+D1AGaLo/51v1yqGN16j2Gg== 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=Hg7tP+vp9TQkRZ/FHg5L+HbMQTmpfXm524IfOpKHN60=; b=lYKq5m1Ob5udWvJWq7JB3SYc3d2PrVSusvcB4o1u5UWFYYh9EG9+I4tfn+7Xm1y4Ez8kYGnCel2vPcYv9xjinq3+D26Hj3+8lxl6wgJnaFrr8UqGCDjdRjj4AUF3BvOb806FVVQCL2eXL2SblxiozJFO5eHWLndzcPEp1E9SV8b5NKkFTF+rY/BHZi3ANzSfagxoEHgmHWD5vym2acTcy9dKs53XDvm/QvFZpB5jAE4vRu60SQsmirpn3Ir11XPhwpW2hFdSyA1WGhumrpw6qKPkLWy/L21XyOYVHpArVXvkCcnLS9CRp5Sop2ZHpOoFsvvlGMdNjBOy3vt4Jh+/Gw== 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=Hg7tP+vp9TQkRZ/FHg5L+HbMQTmpfXm524IfOpKHN60=; b=VZLrCz4vNWOEao8+udxnfjEmJ82jGFvq6Hxg/ifuhbgbxgUc7t0hlUvy9mpkA0qcosDSSyjIphqGdT8z/eBhxrdL9FC4QMGB1slJlxj1jHBCQGouaSka2sJXQfRysUO0x18y0/nt/P/D/k9HeFVdjNptzegM5+GlLlfizYir7G0KlD+SOEk8vuMdcMpAb0H+h/PUGHkTVbF6cBhhd/hCzX94I2Xi4vloAX/99TZkjBqgFnxuLo4oF8T8emdCxjmE3w8JbLKkfmNwcs56Pd7ej+yrkvK1dzkiBMFu0xgAskMp26irt0sDi7c00bzFnAVru2yUzqV2dpKq34T0xvwMSw== Received: from CYZPR05CA0025.namprd05.prod.outlook.com (2603:10b6:930:a3::26) by DM6PR12MB4369.namprd12.prod.outlook.com (2603:10b6:5:2a1::9) 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:22 +0000 Received: from CY4PEPF0000E9D2.namprd03.prod.outlook.com (2603:10b6:930:a3:cafe::c5) by CYZPR05CA0025.outlook.office365.com (2603:10b6:930:a3::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.17 via Frontend Transport; Tue, 13 Feb 2024 14:17:22 +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 CY4PEPF0000E9D2.mail.protection.outlook.com (10.167.241.145) 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:22 +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:17:09 -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:17:06 -0800 From: Ori Kam To: , , , , , Aman Singh , "Yuying Zhang" CC: , , Subject: [PATCH v4 4/4] app/testpmd: add encap hash calculation Date: Tue, 13 Feb 2024 16:16:40 +0200 Message-ID: <20240213141640.19812-4-orika@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240213141640.19812-1-orika@nvidia.com> References: <20240128093943.4461-1-orika@nvidia.com> <20240213141640.19812-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: CY4PEPF0000E9D2:EE_|DM6PR12MB4369:EE_ X-MS-Office365-Filtering-Correlation-Id: f1914fdc-8276-490d-1bb5-08dc2c9e7eff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BuarmUfO3YtiMAPEriT0zT1i+pink199eOc+blp35yzv8YSsINImWHmunvCuQ1MgwAM3hGCQ7nle2deOzo68xidoMP7ud1hG/kJougCUDOx3a8B8bcQ0ZSwCaJq/Dvv3uAQO+Cwq+C/JDATGPJ6Q7NJ7JVFo/PMGBhTty0bAGuqU7gsNkeoBKEMmIZgqv3KZDO1WR95eJRh3ilVYv7YD06iDS3KSCI9QsEZCSMp1+J0NVprjkjWs0iDjrFzBbw+DXItLUWRzF+V5bIozHCSEJXAkBGWlNBdOg35cl5A1gsm3dkvTBCv5DDC1UNsYsySX7tkUxPZju5rooNSAWXB7Bl+PrgSujsXOaZWq5kMPoE0eRpjiwty4dd2NgNjh/C5LI7X6fKOtAOpgOwnlQdhelOuYQgfUuxqbqMKPgd9HTVslxI+HTGdbKvV3hNYfKcj+DdbTpUynGYvDuwR/VtyjvD6QYd5+gEaLvKYJBPYzW9WJ2n2NxOk2eIKhKZyw2BvcFB5jHxa/MJLX9xPMtgj0WDCmKcWed3WKaAJTsrw+4xnjHPTL2buNopBXLJ3tcNSFdIfOy6zcG6/VtTobJvn9ra+a3wzzBHjlX67Yqq1+74s= 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)(376002)(39860400002)(346002)(396003)(230922051799003)(1800799012)(186009)(82310400011)(451199024)(64100799003)(46966006)(36840700001)(40470700004)(4326008)(8676002)(8936002)(2906002)(5660300002)(426003)(336012)(2616005)(83380400001)(107886003)(26005)(16526019)(1076003)(6286002)(36756003)(82740400003)(86362001)(7636003)(356005)(110136005)(316002)(70586007)(70206006)(7696005)(6666004)(54906003)(55016003)(478600001)(41300700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Feb 2024 14:17:22.5776 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f1914fdc-8276-490d-1bb5-08dc2c9e7eff 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: CY4PEPF0000E9D2.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB4369 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