]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests: hw-net: toeplitz: read the RSS key directly from C
authorJakub Kicinski <kuba@kernel.org>
Fri, 21 Nov 2025 04:02:57 +0000 (20:02 -0800)
committerJakub Kicinski <kuba@kernel.org>
Tue, 25 Nov 2025 02:51:40 +0000 (18:51 -0800)
Now that we have YNL support for RSS accessing the RSS info from
C is very easy. Instead of passing the RSS key from Python do it
directly in the C code.

Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20251121040259.3647749-4-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/drivers/net/hw/Makefile
tools/testing/selftests/drivers/net/hw/toeplitz.c
tools/testing/selftests/drivers/net/hw/toeplitz.py

index 949aeeeb357d6a61f946f5e50bd2e45b0cb6f93a..7c819fdfa10720eb2500aa52b3517fd4508235bf 100644 (file)
@@ -15,7 +15,6 @@ endif
 
 TEST_GEN_FILES := \
        $(COND_GEN_FILES) \
-       toeplitz \
 # end of TEST_GEN_FILES
 
 TEST_PROGS = \
@@ -55,7 +54,10 @@ TEST_INCLUDES := \
        #
 
 # YNL files, must be before "include ..lib.mk"
-YNL_GEN_FILES := ncdevmem
+YNL_GEN_FILES := \
+       ncdevmem \
+       toeplitz \
+# end of YNL_GEN_FILES
 TEST_GEN_FILES += $(YNL_GEN_FILES)
 TEST_GEN_FILES += $(patsubst %.c,%.o,$(wildcard *.bpf.c))
 
index afc5f910b0068d8b604f50dec220a6141cc42dbd..7420a4e201cc72964601912828345689bce30343 100644 (file)
@@ -52,6 +52,9 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+#include <ynl.h>
+#include "ethtool-user.h"
+
 #include "../../../kselftest.h"
 #include "../../../net/lib/ksft.h"
 
@@ -483,6 +486,42 @@ static void parse_rps_bitmap(const char *arg)
                        rps_silo_to_cpu[cfg_num_rps_cpus++] = i;
 }
 
+static void read_rss_dev_info_ynl(void)
+{
+       struct ethtool_rss_get_req *req;
+       struct ethtool_rss_get_rsp *rsp;
+       struct ynl_sock *ys;
+
+       ys = ynl_sock_create(&ynl_ethtool_family, NULL);
+       if (!ys)
+               error(1, errno, "ynl_sock_create failed");
+
+       req = ethtool_rss_get_req_alloc();
+       if (!req)
+               error(1, errno, "ethtool_rss_get_req_alloc failed");
+
+       ethtool_rss_get_req_set_header_dev_name(req, cfg_ifname);
+
+       rsp = ethtool_rss_get(ys, req);
+       if (!rsp)
+               error(1, ys->err.code, "YNL: %s", ys->err.msg);
+
+       if (!rsp->_len.hkey)
+               error(1, 0, "RSS key not available for %s", cfg_ifname);
+
+       if (rsp->_len.hkey < TOEPLITZ_KEY_MIN_LEN ||
+           rsp->_len.hkey > TOEPLITZ_KEY_MAX_LEN)
+               error(1, 0, "RSS key length %u out of bounds [%u, %u]",
+                     rsp->_len.hkey, TOEPLITZ_KEY_MIN_LEN,
+                     TOEPLITZ_KEY_MAX_LEN);
+
+       memcpy(toeplitz_key, rsp->hkey, rsp->_len.hkey);
+
+       ethtool_rss_get_rsp_free(rsp);
+       ethtool_rss_get_req_free(req);
+       ynl_sock_destroy(ys);
+}
+
 static void parse_opts(int argc, char **argv)
 {
        static struct option long_options[] = {
@@ -551,7 +590,7 @@ static void parse_opts(int argc, char **argv)
        }
 
        if (!have_toeplitz)
-               error(1, 0, "Must supply rss key ('-k')");
+               read_rss_dev_info_ynl();
 
        num_cpus = get_nprocs();
        if (num_cpus > RSS_MAX_CPUS)
index 642a5cc385b6eb6fbd52943bf5f9b6d1af795a70..945c58d23310cbf55c20e947321e29a512521f04 100755 (executable)
@@ -156,10 +156,6 @@ def test(cfg, proto_flag, ipver, grp):
                                   "hfunc": rss.get('hfunc'),
                                   "input-xfrm": rss.get('input-xfrm', {})
                                   })
-        # Refresh in case changing hfunc changes things.
-        rss = cfg.ethnl.rss_get({"header": {"dev-index": cfg.ifindex}})
-
-    key = ':'.join(f'{b:02x}' for b in rss["hkey"])
 
     port = rand_port(socket.SOCK_DGRAM)
 
@@ -170,7 +166,6 @@ def test(cfg, proto_flag, ipver, grp):
         proto_flag,
         "-d", str(port),
         "-i", cfg.ifname,
-        "-k", key,
         "-T", "1000",
         "-s",
         "-v"