All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, edumazet@google.com, pabeni@redhat.com,
	andrew+netdev@lunn.ch, horms@kernel.org, andrew@lunn.ch,
	donald.hunter@gmail.com, shuah@kernel.org,
	kory.maincent@bootlin.com, gal@nvidia.com,
	ecree.xilinx@gmail.com, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH net-next 5/8] ethtool: move ethtool_rxfh_ctx_alloc() to common code
Date: Thu, 17 Jul 2025 16:43:40 -0700	[thread overview]
Message-ID: <20250717234343.2328602-6-kuba@kernel.org> (raw)
In-Reply-To: <20250717234343.2328602-1-kuba@kernel.org>

Move ethtool_rxfh_ctx_alloc() to common code, Netlink will need it.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 net/ethtool/common.h |  3 +++
 net/ethtool/common.c | 34 ++++++++++++++++++++++++++++++++++
 net/ethtool/ioctl.c  | 34 ----------------------------------
 3 files changed, 37 insertions(+), 34 deletions(-)

diff --git a/net/ethtool/common.h b/net/ethtool/common.h
index c8385a268ced..c4d084dde5bf 100644
--- a/net/ethtool/common.h
+++ b/net/ethtool/common.h
@@ -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);
 
diff --git a/net/ethtool/common.c b/net/ethtool/common.c
index 82afe0f2a7cd..2a1d40efb1fc 100644
--- a/net/ethtool/common.c
+++ b/net/ethtool/common.c
@@ -806,6 +806,40 @@ int ethtool_check_rss_ctx_busy(struct net_device *dev, u32 rss_context)
 	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.
  */
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index beb17f3671a2..c53868889969 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -1473,40 +1473,6 @@ static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev,
 	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)
 {
-- 
2.50.1


  parent reply	other threads:[~2025-07-17 23:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-17 23:43 [PATCH net-next 0/8] ethtool: rss: support creating and removing contexts via Netlink Jakub Kicinski
2025-07-17 23:43 ` [PATCH net-next 1/8] ethtool: assert that drivers with sym hash are consistent for RSS contexts Jakub Kicinski
2025-07-17 23:43 ` [PATCH net-next 2/8] ethtool: rejig the RSS notification machinery for more types Jakub Kicinski
2025-07-20 11:09   ` Gal Pressman
2025-07-17 23:43 ` [PATCH net-next 3/8] ethtool: rss: factor out allocating memory for response Jakub Kicinski
2025-07-17 23:43 ` [PATCH net-next 4/8] ethtool: rss: factor out populating response from context Jakub Kicinski
2025-07-20 11:12   ` Gal Pressman
2025-07-17 23:43 ` Jakub Kicinski [this message]
2025-07-20 11:15   ` [PATCH net-next 5/8] ethtool: move ethtool_rxfh_ctx_alloc() to common code Gal Pressman
2025-07-17 23:43 ` [PATCH net-next 6/8] ethtool: rss: support creating contexts via Netlink Jakub Kicinski
2025-07-20 11:42   ` Gal Pressman
2025-07-21 15:21     ` Jakub Kicinski
2025-07-21 18:35       ` Gal Pressman
2025-07-17 23:43 ` [PATCH net-next 7/8] ethtool: rss: support removing " Jakub Kicinski
2025-07-17 23:43 ` [PATCH net-next 8/8] selftests: drv-net: rss_api: context create and delete tests Jakub Kicinski
2025-07-22  1:40 ` [PATCH net-next 0/8] ethtool: rss: support creating and removing contexts via Netlink patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250717234343.2328602-6-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=ecree.xilinx@gmail.com \
    --cc=edumazet@google.com \
    --cc=gal@nvidia.com \
    --cc=horms@kernel.org \
    --cc=kory.maincent@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.