diff options
author | Jakub Kicinski <kuba@kernel.org> | 2025-07-17 16:43:40 -0700 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2025-07-21 18:20:19 -0700 |
commit | 55ef461ce18fbe678f0b4834fc1eaa38c24f83fe (patch) | |
tree | 0f5d9c3a64e452db9ac1211f982948b816971550 /net/ethtool/common.c | |
parent | 5c090d9eae8807420bcb01a6280b02774e5320c6 (diff) |
ethtool: move ethtool_rxfh_ctx_alloc() to common code
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>
Diffstat (limited to 'net/ethtool/common.c')
-rw-r--r-- | net/ethtool/common.c | 34 |
1 files changed, 34 insertions, 0 deletions
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 @@ 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. */ |