]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ethtool: move ethtool_rxfh_ctx_alloc() to common code
authorJakub Kicinski <kuba@kernel.org>
Thu, 17 Jul 2025 23:43:40 +0000 (16:43 -0700)
committerJakub Kicinski <kuba@kernel.org>
Tue, 22 Jul 2025 01:20:19 +0000 (18:20 -0700)
Move ethtool_rxfh_ctx_alloc() to common code, Netlink will need it.

Reviewed-by: Gal Pressman <gal@nvidia.com>
Link: https://patch.msgid.link/20250717234343.2328602-6-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ethtool/common.c
net/ethtool/common.h
net/ethtool/ioctl.c

index 82afe0f2a7cd654e777d9bb8726c6ef0562f0da7..2a1d40efb1fcc9d3398ddf1e5ed812b063651deb 100644 (file)
@@ -806,6 +806,40 @@ out_free:
        return rc;
 }
 
+struct ethtool_rxfh_context *
+ethtool_rxfh_ctx_alloc(const struct ethtool_ops *ops,
+                      u32 indir_size, u32 key_size)
+{
+       size_t indir_bytes, flex_len, key_off, size;
+       struct ethtool_rxfh_context *ctx;
+       u32 priv_bytes, indir_max;
+       u16 key_max;
+
+       key_max = max(key_size, ops->rxfh_key_space);
+       indir_max = max(indir_size, ops->rxfh_indir_space);
+
+       priv_bytes = ALIGN(ops->rxfh_priv_size, sizeof(u32));
+       indir_bytes = array_size(indir_max, sizeof(u32));
+
+       key_off = size_add(priv_bytes, indir_bytes);
+       flex_len = size_add(key_off, key_max);
+       size = struct_size_t(struct ethtool_rxfh_context, data, flex_len);
+
+       ctx = kzalloc(size, GFP_KERNEL_ACCOUNT);
+       if (!ctx)
+               return NULL;
+
+       ctx->indir_size = indir_size;
+       ctx->key_size = key_size;
+       ctx->key_off = key_off;
+       ctx->priv_size = ops->rxfh_priv_size;
+
+       ctx->hfunc = ETH_RSS_HASH_NO_CHANGE;
+       ctx->input_xfrm = RXH_XFRM_NO_CHANGE;
+
+       return ctx;
+}
+
 /* Check if fields configured for flow hash are symmetric - if src is included
  * so is dst and vice versa.
  */
index c8385a268ceddf11f3221ffdaa3b3178cf45c49c..c4d084dde5bf4f0f9318af8a98815fb9d3c3a246 100644 (file)
@@ -43,6 +43,9 @@ bool convert_legacy_settings_to_link_ksettings(
 int ethtool_check_max_channel(struct net_device *dev,
                              struct ethtool_channels channels,
                              struct genl_info *info);
+struct ethtool_rxfh_context *
+ethtool_rxfh_ctx_alloc(const struct ethtool_ops *ops,
+                      u32 indir_size, u32 key_size);
 int ethtool_check_rss_ctx_busy(struct net_device *dev, u32 rss_context);
 int ethtool_rxfh_config_is_sym(u64 rxfh);
 
index beb17f3671a2853be1424c8743a9a875cedbb30d..c53868889969af201296d349bc398885cd341b39 100644 (file)
@@ -1473,40 +1473,6 @@ out:
        return ret;
 }
 
-static struct ethtool_rxfh_context *
-ethtool_rxfh_ctx_alloc(const struct ethtool_ops *ops,
-                      u32 indir_size, u32 key_size)
-{
-       size_t indir_bytes, flex_len, key_off, size;
-       struct ethtool_rxfh_context *ctx;
-       u32 priv_bytes, indir_max;
-       u16 key_max;
-
-       key_max = max(key_size, ops->rxfh_key_space);
-       indir_max = max(indir_size, ops->rxfh_indir_space);
-
-       priv_bytes = ALIGN(ops->rxfh_priv_size, sizeof(u32));
-       indir_bytes = array_size(indir_max, sizeof(u32));
-
-       key_off = size_add(priv_bytes, indir_bytes);
-       flex_len = size_add(key_off, key_max);
-       size = struct_size_t(struct ethtool_rxfh_context, data, flex_len);
-
-       ctx = kzalloc(size, GFP_KERNEL_ACCOUNT);
-       if (!ctx)
-               return NULL;
-
-       ctx->indir_size = indir_size;
-       ctx->key_size = key_size;
-       ctx->key_off = key_off;
-       ctx->priv_size = ops->rxfh_priv_size;
-
-       ctx->hfunc = ETH_RSS_HASH_NO_CHANGE;
-       ctx->input_xfrm = RXH_XFRM_NO_CHANGE;
-
-       return ctx;
-}
-
 static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
                                               void __user *useraddr)
 {