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 805D2439EC; Sun, 28 Jan 2024 10:41:12 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1D58340DCE; Sun, 28 Jan 2024 10:40:58 +0100 (CET) Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2070.outbound.protection.outlook.com [40.107.96.70]) by mails.dpdk.org (Postfix) with ESMTP id B2BF040A80 for ; Sun, 28 Jan 2024 10:40:55 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=behHqbm7HzGZlaMXAM16XvCun7X7c0S2CZn+/FPJ8Eoiry7YDtqpCuWjwRo/Gm7ufiHqqfXS1VoxK/xFQxr4ggO0m+WQaPzLiIEuhmPYgZV/YWlrlBtbNNyLTIbf014ofaSliJNuCy0IXDuu7/WKQySBDJVwyqViVru6KG0+ejoscmrt+OMHjUMHSVN0kfyHaFImH7N5145B7JCgj8XjZkq02FZQpSLkQILiXScwV2fID+rL0RG8lHrD8U7GDMHWcY4aZO99OSIqWETN2kd/17Io0dpXAAxWIpBAFqsTwSpcpBJ4dkof43vsdsPxqFXRWijqPlMffCqp94iKYW/NZA== 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=D4l4D53euJfVnDSjgYwYsBOgnaQy85MuIQsg8WKHtSI=; b=FvqmoOFgZBZ2S+3OjqX9+1aWT5DJolnsOfdVGalZJjT4ksiDal/aY+N8Yq79mpRHrR+twUTemh3Bm75FANzNqFrQ8vVy4QO0B24I7AA1ZnCbcKv7T5QVNthxIJyw3tcBnFpNtlMwdISq60qJT8Z4KZgSXTPxAA1sLqzfxWs+W19VwzCwh2ciBsW5rsfbKEZeFNsmsKOi6rZvup1kxIrigX4ah7VYT52XxInABUabxupwFsAVg/03CBBP4iUp3L1EYddSEDFHtvYmsanbtO7hdmyBfcVQ2fA28hQV74oT+U3XrwoveWrVpJ7uc7iDLzIzT8Z2JFC/qKZ/ueZ+5A1Q6w== 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=D4l4D53euJfVnDSjgYwYsBOgnaQy85MuIQsg8WKHtSI=; b=LfHQoI3ctg9Jx6jKs+U2Xb/XBlnULVZZNn0HB8WtLGI1UjpCCiN/VEkgcWbTXG/Qctkrn7axeiSqugPMAGkpmTNX6Jd1lfH6mVo16wId8rKhR0tw88Y7AVeN3DEleo4TV1IDBktkBjTCnl583fk5GTVC8PL9dbeHoj81jHa7vr/q3iWvOh3bwTuXE0Z89jaFZjRgEPPSi8CWC9sUwmipSL4Bes4UMkn4inGRy5G6zD0SP8QIZtyNEIPfpu7KZdXth0in7XGRwk66/+BE6D7qIV4PWF7EPufGDNcGWP7Jz8GJMBf9F6lpxSCzPVU/YgXyd5gNQR1tfXlKAjb8ie/0lQ== Received: from SA0PR12CA0013.namprd12.prod.outlook.com (2603:10b6:806:6f::18) by SN7PR12MB7022.namprd12.prod.outlook.com (2603:10b6:806:261::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.31; Sun, 28 Jan 2024 09:40:51 +0000 Received: from SN1PEPF0002636A.namprd02.prod.outlook.com (2603:10b6:806:6f:cafe::71) by SA0PR12CA0013.outlook.office365.com (2603:10b6:806:6f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7228.31 via Frontend Transport; Sun, 28 Jan 2024 09:40:51 +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 SN1PEPF0002636A.mail.protection.outlook.com (10.167.241.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.19 via Frontend Transport; Sun, 28 Jan 2024 09:40:51 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 28 Jan 2024 01:40:42 -0800 Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Sun, 28 Jan 2024 01:40:38 -0800 From: Ori Kam To: , , , , , Aman Singh , "Yuying Zhang" CC: , , Subject: [PATCH 4/4] app/testpmd: add encap hash calculation Date: Sun, 28 Jan 2024 11:39:42 +0200 Message-ID: <20240128093943.4461-5-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.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1PEPF0002636A:EE_|SN7PR12MB7022:EE_ X-MS-Office365-Filtering-Correlation-Id: 792ad8f5-797c-4be5-5453-08dc1fe5372a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q8slGe1jC/RzIxYWqx8MfaTtOfPoEbUWtji17HCsx+D0S75xxzxa+H/9cAQG9w4T2zPyNvcLsq7heSxxKihe4K+D2/ERl+bH1Ngff2uCKHYWcC53UgAUjSwL/Taj3OnDRyXqnvSIEFnQsNM+VcoCcqVVlzS2q6cpm7b9SrJol7D7R1KC46S9yZ3g+77mSDnZ0n7e/iu7GFyFr89pZjq/Z9dfTlQWpiguB3lojtYMiZA4rJaCHVi6E6rpDL6vSa92BdyEGllojsHD3zSjKxKfhp6C/UDMCaLTHfRB+dVb1wRKSXFvd8W8GpxAEd4rmAok8UrAB9/y7kNlZm7HGuhkWL1OqLzDi8fE2yFsBKQtirXeWYwLcjDr5ilbpX45su4sZseCudD0NYwjwa0eiHzY1oc+SuUnCUHgIe9V/dgyTUstpifIBng8x/pGcm/YBU0SXBhXp3d+hwvYJYdvqtn3X57OuBm+Y0gm0YWYI7yLgd6F8a78W1crCiPaAeL5Rkr5cHinhyS4X8Sj5u//UL8QK3xRFZ8yRWEXfaa6xUNn+Edm7c40eo0mkX50TrxCvXpB8AFOv8eDrzLKBCW2nZkvqFcrypyw6YxQ76Dz6SY2A5ytOi6GYCGSVeVvr4TIg+YToI4gHUF1b3DXOviVNsrCxHjhikkR9WoeZ0zQlrBTTKWZT3wKNGKIOoHo/MncV48ZKf6KymK41XAhn+rGafkAF7ajZggLI3iOWPYicHOxxOdSchWdPV7O2slFbwpJypNk 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)(396003)(39860400002)(346002)(230922051799003)(64100799003)(451199024)(1800799012)(82310400011)(186009)(40470700004)(46966006)(36840700001)(41300700001)(2906002)(5660300002)(36756003)(70586007)(54906003)(70206006)(316002)(110136005)(86362001)(83380400001)(2616005)(1076003)(426003)(55016003)(336012)(107886003)(26005)(6286002)(16526019)(478600001)(47076005)(6666004)(40460700003)(40480700001)(82740400003)(7696005)(4326008)(8936002)(8676002)(356005)(7636003)(36860700001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Jan 2024 09:40:51.1854 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 792ad8f5-797c-4be5-5453-08dc1fe5372a 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: SN1PEPF0002636A.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR12MB7022 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 --- 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 4062879552..a42f07276d 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, @@ -1192,6 +1196,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; @@ -2550,6 +2556,18 @@ static const enum index action_represented_port[] = { 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); @@ -3789,7 +3807,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, }, @@ -3803,6 +3821,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", @@ -3812,6 +3836,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", @@ -10691,6 +10727,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; } @@ -12651,9 +12696,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 38ab421547..37a508c967 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