From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DECE606A320 for ; Tue, 1 Dec 2026 15:17:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Ul1YvbML Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4AECA4068A; Tue, 1 Dec 2026 16:16:54 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by mails.dpdk.org (Postfix) with ESMTPS id C8FF740430 for ; Tue, 1 Dec 2026 16:16:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796138209; x=1827674209; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZiIyb0TTzACjXpdGjrb30hOarXGCZ63e3+zNQAnwWqc=; b=Ul1YvbMLs9cUwFrlfMr+heoWAcPg+78g3Zt1m+l2Y6phANDp9RHStKnN qcizZwa8Uzv7s/U3Pn3egiyVcyyrjq1wqg6Osge5Si6ZFVjCe147DBkc/ ayE0pBypwHVOgRz75LbFqUubmq0apUFbOB90JHMoqFI4D7Ocpen5y52uG 8O0ZbvfVs8uJEZFXSKzJ6NFFZPRoDVxoS61vKtl36TyZ7ZfgsyBCbEYw9 qrlw/tV5NFLwTBU7yhQazbNLQGX1Bj8Hr8paEFtHrEpA8iUMX1+AVx2Eg BF3QTDf6nPJCTGBczNOKn8wqKwKgYGORWjmLi8KqWrJg42lkI99kvauNT g==; X-CSE-ConnectionGUID: tKj9ATNRSTipJCRBdrTBpg== X-CSE-MsgGUID: rIKrgsoWStWBynjI6tkBcg== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5023494" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="5023494" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 07:16:49 -0800 X-CSE-ConnectionGUID: bQ/zcvHQSViBOahZJGuubw== X-CSE-MsgGUID: ksgJx/5eQXmVw2h+W5cDog== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13749408" Received: from silpixa00401385.ir.intel.com ([10.20.224.226]) by fmviesa001.fm.intel.com with ESMTP; 01 Dec 2026 07:16:48 -0800 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson Subject: [PATCH 07/11] hash: implement IPv4 and IPv6 RSS hashing in SW Date: Tue, 1 Dec 2026 15:16:19 +0000 Message-ID: <20261201151623.2240031-8-bruce.richardson@intel.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261201151623.2240031-1-bruce.richardson@intel.com> References: <20261201151623.2240031-1-bruce.richardson@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Implement functions for generating an RSS hash in SW for IPv4 and IPv6, with optional TCP/UDP src/dst included. Where the system supports AVX-512 + GFNI instruction set, those optimized paths are taken, otherwise a default scalar path is used. Signed-off-by: Bruce Richardson --- doc/guides/rel_notes/release_27_03.rst | 6 ++ lib/hash/rte_thash_rss.h | 87 ++++++++++++++++++++++++++ lib/hash/thash_rss.c | 78 +++++++++++++++++++++++ 3 files changed, 171 insertions(+) diff --git a/doc/guides/rel_notes/release_27_03.rst b/doc/guides/rel_notes/release_27_03.rst index a91813faca..0714b8bd46 100644 --- a/doc/guides/rel_notes/release_27_03.rst +++ b/doc/guides/rel_notes/release_27_03.rst @@ -55,6 +55,12 @@ New Features Also, make sure to start the actual text at the margin. ======================================================= +* **Added software RSS hashing for IP packets.** + + Added ``rte_thash_rss_*`` APIs to calculate RSS hashes for IPv4 and IPv6 addresses, + with optional TCP/UDP ports. + Runtime dispatch selects GFNI implementations when supported and uses scalar hashing otherwise. + Removed Items ------------- diff --git a/lib/hash/rte_thash_rss.h b/lib/hash/rte_thash_rss.h index f76dd667fb..274eab2503 100644 --- a/lib/hash/rte_thash_rss.h +++ b/lib/hash/rte_thash_rss.h @@ -14,6 +14,7 @@ #include #include +#include #ifdef __cplusplus extern "C" { @@ -62,6 +63,92 @@ __rte_experimental void rte_thash_rss_ctx_free(struct rte_thash_rss_ctx *ctx); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Calculate an RSS hash over the source and destination IPv4 addresses. + * + * @param ctx + * RSS hash context. + * @param ip + * Pointer to a complete fixed IPv4 header structure. + * @param hash + * Location to store the calculated hash. + * @return + * 0 on success, or -EINVAL for invalid parameters. + */ +__rte_experimental +int +rte_thash_rss_ipv4_l3(const struct rte_thash_rss_ctx *ctx, + const struct rte_ipv4_hdr *ip, uint32_t *hash); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Calculate an RSS hash over the IPv4 addresses and TCP or UDP ports. + * + * @param ctx + * RSS hash context. + * @param ip + * Pointer to a complete fixed IPv4 header structure. + * @param l4_hdr + * Pointer to at least the first 4 bytes of the TCP or UDP header. + * The caller must ensure that L4 hashing is appropriate for the packet. + * @param hash + * Location to store the calculated hash. + * @return + * 0 on success, or -EINVAL for invalid parameters. + */ +__rte_experimental +int +rte_thash_rss_ipv4_l4(const struct rte_thash_rss_ctx *ctx, + const struct rte_ipv4_hdr *ip, const void *l4_hdr, uint32_t *hash); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Calculate an RSS hash over the source and destination IPv6 addresses. + * + * @param ctx + * RSS hash context. + * @param ip + * Pointer to a complete IPv6 header structure. + * @param hash + * Location to store the calculated hash. + * @return + * 0 on success, or -EINVAL for invalid parameters. + */ +__rte_experimental +int +rte_thash_rss_ipv6_l3(const struct rte_thash_rss_ctx *ctx, + const struct rte_ipv6_hdr *ip, uint32_t *hash); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Calculate an RSS hash over the IPv6 addresses and TCP or UDP ports. + * + * @param ctx + * RSS hash context. + * @param ip + * Pointer to a complete IPv6 header structure. + * @param l4_hdr + * Pointer to at least the first 4 bytes of the TCP or UDP header. + * The caller must ensure that L4 hashing is appropriate for the packet. + * @param hash + * Location to store the calculated hash. + * @return + * 0 on success, or -EINVAL for invalid parameters. + */ +__rte_experimental +int +rte_thash_rss_ipv6_l4(const struct rte_thash_rss_ctx *ctx, + const struct rte_ipv6_hdr *ip, const void *l4_hdr, uint32_t *hash); + #ifdef __cplusplus } #endif diff --git a/lib/hash/thash_rss.c b/lib/hash/thash_rss.c index c53e9dbefa..ddc07720a3 100644 --- a/lib/hash/thash_rss.c +++ b/lib/hash/thash_rss.c @@ -105,3 +105,81 @@ rte_thash_rss_ctx_free(struct rte_thash_rss_ctx *ctx) { free(ctx); } + +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_thash_rss_ipv4_l3, 27.03) +int +rte_thash_rss_ipv4_l3(const struct rte_thash_rss_ctx *ctx, + const struct rte_ipv4_hdr *ip, uint32_t *hash) +{ + if (ctx == NULL || ip == NULL || hash == NULL) + return -EINVAL; + + *hash = ctx->ops->hash_8(ctx, (const uint8_t *)&ip->src_addr); + return 0; +} + +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_thash_rss_ipv6_l3, 27.03) +int +rte_thash_rss_ipv6_l3(const struct rte_thash_rss_ctx *ctx, + const struct rte_ipv6_hdr *ip, uint32_t *hash) +{ + if (ctx == NULL || ip == NULL || hash == NULL) + return -EINVAL; + + *hash = ctx->ops->hash_32(ctx, (const uint8_t *)&ip->src_addr); + return 0; +} + +static __rte_noinline uint32_t +thash_ipv4_l4_gather(const struct rte_thash_rss_ctx *ctx, + const struct rte_ipv4_hdr *ip, const void *l4_hdr) +{ + uint8_t tuple[12]; + + memcpy(tuple, &ip->src_addr, 2 * sizeof(ip->src_addr)); + memcpy(&tuple[8], l4_hdr, 4); + return ctx->ops->hash_12(ctx, tuple); +} + +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_thash_rss_ipv4_l4, 27.03) +int +rte_thash_rss_ipv4_l4(const struct rte_thash_rss_ctx *ctx, + const struct rte_ipv4_hdr *ip, const void *l4_hdr, uint32_t *hash) +{ + if (ctx == NULL || ip == NULL || l4_hdr == NULL || hash == NULL) + return -EINVAL; + + if (l4_hdr == ip + 1) + *hash = ctx->ops->hash_12(ctx, (const uint8_t *)&ip->src_addr); + else + *hash = thash_ipv4_l4_gather(ctx, ip, l4_hdr); + + return 0; +} + +static __rte_noinline uint32_t +thash_ipv6_l4_gather(const struct rte_thash_rss_ctx *ctx, + const struct rte_ipv6_hdr *ip, const void *l4_hdr) +{ + uint8_t tuple[36]; + + memcpy(tuple, &ip->src_addr, 2 * sizeof(ip->src_addr)); + memcpy(&tuple[32], l4_hdr, 4); + return ctx->ops->hash_36(ctx, tuple); +} + +RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_thash_rss_ipv6_l4, 27.03) +int +rte_thash_rss_ipv6_l4(const struct rte_thash_rss_ctx *ctx, + const struct rte_ipv6_hdr *ip, const void *l4_hdr, uint32_t *hash) +{ + if (ctx == NULL || ip == NULL || l4_hdr == NULL || hash == NULL) + return -EINVAL; + + if (l4_hdr == ip + 1) + *hash = ctx->ops->hash_36(ctx, (const uint8_t *)&ip->src_addr); + else + *hash = thash_ipv6_l4_gather(ctx, ip, l4_hdr); + + return 0; +} -- 2.55.0