git: 1ad999a1c7e0 - main - mlx4en: Use the common RSS key for programming and queries

From: Kevin Bowling <kbowling_at_FreeBSD.org>
Date: Fri, 18 Sep 2026 23:00:36 UTC
The branch main has been updated by kbowling:

URL: https://cgit.FreeBSD.org/src/commit/?id=1ad999a1c7e0efd4fd65df634a4c108d593d4027

commit 1ad999a1c7e0efd4fd65df634a4c108d593d4027
Author:     Kevin Bowling <kbowling@FreeBSD.org>
AuthorDate: 2026-09-18 08:29:19 +0000
Commit:     Kevin Bowling <kbowling@FreeBSD.org>
CommitDate: 2026-09-18 22:59:12 +0000

    mlx4en: Use the common RSS key for programming and queries
    
    Replace the private fixed key with rss_getkey().  Copy the common byte
    stream directly into the RSS queue-pair context and use the same helper
    for SIOCGIFRSSKEY, so hardware programming and hn's query agree.
    
    Change the helper to fill caller-owned storage instead of returning a
    pointer to a static key.  Check the fixed hardware and ioctl buffer sizes
    at compile time.  Leave RSS masks and queue steering unchanged.
    
    MFC after:      2 weeks
    Sponsored by:   BBOX.io
    Differential Revision:  https://reviews.freebsd.org/D59798
---
 sys/dev/mlx4/mlx4_en/en.h             |  2 +-
 sys/dev/mlx4/mlx4_en/mlx4_en_netdev.c | 10 ++++------
 sys/dev/mlx4/mlx4_en/mlx4_en_rx.c     | 30 +++++++-----------------------
 3 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/sys/dev/mlx4/mlx4_en/en.h b/sys/dev/mlx4/mlx4_en/en.h
index dbe29f1d24ec..88a38d68e77d 100644
--- a/sys/dev/mlx4/mlx4_en/en.h
+++ b/sys/dev/mlx4/mlx4_en/en.h
@@ -845,7 +845,7 @@ int mlx4_en_map_buffer(struct mlx4_buf *buf);
 void mlx4_en_unmap_buffer(struct mlx4_buf *buf);
 void mlx4_en_calc_rx_buf(if_t dev);
 
-const u32 *mlx4_en_get_rss_key(struct mlx4_en_priv *priv, u16 *keylen);
+void mlx4_en_get_rss_key(void *key);
 u8 mlx4_en_get_rss_mask(struct mlx4_en_priv *priv);
 int mlx4_en_config_rss_steer(struct mlx4_en_priv *priv);
 void mlx4_en_release_rss_steer(struct mlx4_en_priv *priv);
diff --git a/sys/dev/mlx4/mlx4_en/mlx4_en_netdev.c b/sys/dev/mlx4/mlx4_en/mlx4_en_netdev.c
index ac4bfd1b1a14..6bab5d25cbc6 100644
--- a/sys/dev/mlx4/mlx4_en/mlx4_en_netdev.c
+++ b/sys/dev/mlx4/mlx4_en/mlx4_en_netdev.c
@@ -1953,7 +1953,6 @@ static int mlx4_en_ioctl(if_t dev, u_long command, caddr_t data)
 	int error;
 	int mask;
 	struct ifrsskey *ifrk;
-	const u32 *key;
 	struct ifrsshash *ifrh;
 	u8 rss_mask;
 
@@ -2092,12 +2091,11 @@ out:
 	case SIOCGIFRSSKEY:
 		ifrk = (struct ifrsskey *)data;
 		ifrk->ifrk_func = RSS_FUNC_TOEPLITZ;
+		ifrk->ifrk_keylen = MLX4_EN_RSS_KEY_SIZE;
+		_Static_assert(sizeof(ifrk->ifrk_key) >= MLX4_EN_RSS_KEY_SIZE,
+		    "RSS query buffer too small");
 		mutex_lock(&mdev->state_lock);
-		key = mlx4_en_get_rss_key(priv, &ifrk->ifrk_keylen);
-		if (ifrk->ifrk_keylen > RSS_KEYLEN)
-			error = EINVAL;
-		else
-			memcpy(ifrk->ifrk_key, key, ifrk->ifrk_keylen);
+		mlx4_en_get_rss_key(ifrk->ifrk_key);
 		mutex_unlock(&mdev->state_lock);
 		break;
 
diff --git a/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c b/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c
index 5baae707413d..60a530947ca0 100644
--- a/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c
+++ b/sys/dev/mlx4/mlx4_en/mlx4_en_rx.c
@@ -43,6 +43,7 @@
 #endif
 
 #include "en.h"
+#include <net/rss_config.h>
 
 #if (MLX4_EN_MAX_RX_SEGS == 1)
 static void mlx4_en_init_rx_desc(struct mlx4_en_priv *priv,
@@ -993,26 +994,12 @@ void mlx4_en_destroy_drop_qp(struct mlx4_en_priv *priv)
 	mlx4_qp_release_range(priv->mdev->dev, qpn, 1);
 }
 
-const u32 *
-mlx4_en_get_rss_key(struct mlx4_en_priv *priv __unused,
-    u16 *keylen)
+void
+mlx4_en_get_rss_key(void *key)
 {
-	static const u32 rsskey[10] = {
-		cpu_to_be32(0xD181C62C),
-		cpu_to_be32(0xF7F4DB5B),
-		cpu_to_be32(0x1983A2FC),
-		cpu_to_be32(0x943E1ADB),
-		cpu_to_be32(0xD9389E6B),
-		cpu_to_be32(0xD1039C2C),
-		cpu_to_be32(0xA74499AD),
-		cpu_to_be32(0x593D56D9),
-		cpu_to_be32(0xF3253C06),
-		cpu_to_be32(0x2ADC1FFC)
-	};
-
-	if (keylen != NULL)
-		*keylen = sizeof(rsskey);
-	return (rsskey);
+	_Static_assert(MLX4_EN_RSS_KEY_SIZE == RSS_KEYSIZE,
+	    "RSS key size mismatch");
+	rss_getkey(key);
 }
 
 u8 mlx4_en_get_rss_mask(struct mlx4_en_priv *priv)
@@ -1032,7 +1019,6 @@ int mlx4_en_config_rss_steer(struct mlx4_en_priv *priv)
 	struct mlx4_en_rss_map *rss_map = &priv->rss_map;
 	struct mlx4_qp_context context;
 	struct mlx4_rss_context *rss_context;
-	const u32 *key;
 	int rss_rings;
 	void *ptr;
 	int i;
@@ -1085,9 +1071,7 @@ int mlx4_en_config_rss_steer(struct mlx4_en_priv *priv)
 		rss_context->base_qpn_udp = rss_context->default_qpn;
 	rss_context->flags = mlx4_en_get_rss_mask(priv);
 	rss_context->hash_fn = MLX4_RSS_HASH_TOP;
-	key = mlx4_en_get_rss_key(priv, NULL);
-	for (i = 0; i < 10; i++)
-		rss_context->rss_key[i] = key[i];
+	mlx4_en_get_rss_key(rss_context->rss_key);
 
 	err = mlx4_qp_to_ready(mdev->dev, &priv->res.mtt, &context,
 			       &rss_map->indir_qp, &rss_map->indir_state);