Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+37 -34
+34
net/ethtool/common.c
··· 806 806 return rc; 807 807 } 808 808 809 + struct ethtool_rxfh_context * 810 + ethtool_rxfh_ctx_alloc(const struct ethtool_ops *ops, 811 + u32 indir_size, u32 key_size) 812 + { 813 + size_t indir_bytes, flex_len, key_off, size; 814 + struct ethtool_rxfh_context *ctx; 815 + u32 priv_bytes, indir_max; 816 + u16 key_max; 817 + 818 + key_max = max(key_size, ops->rxfh_key_space); 819 + indir_max = max(indir_size, ops->rxfh_indir_space); 820 + 821 + priv_bytes = ALIGN(ops->rxfh_priv_size, sizeof(u32)); 822 + indir_bytes = array_size(indir_max, sizeof(u32)); 823 + 824 + key_off = size_add(priv_bytes, indir_bytes); 825 + flex_len = size_add(key_off, key_max); 826 + size = struct_size_t(struct ethtool_rxfh_context, data, flex_len); 827 + 828 + ctx = kzalloc(size, GFP_KERNEL_ACCOUNT); 829 + if (!ctx) 830 + return NULL; 831 + 832 + ctx->indir_size = indir_size; 833 + ctx->key_size = key_size; 834 + ctx->key_off = key_off; 835 + ctx->priv_size = ops->rxfh_priv_size; 836 + 837 + ctx->hfunc = ETH_RSS_HASH_NO_CHANGE; 838 + ctx->input_xfrm = RXH_XFRM_NO_CHANGE; 839 + 840 + return ctx; 841 + } 842 + 809 843 /* Check if fields configured for flow hash are symmetric - if src is included 810 844 * so is dst and vice versa. 811 845 */
+3
net/ethtool/common.h
··· 43 43 int ethtool_check_max_channel(struct net_device *dev, 44 44 struct ethtool_channels channels, 45 45 struct genl_info *info); 46 + struct ethtool_rxfh_context * 47 + ethtool_rxfh_ctx_alloc(const struct ethtool_ops *ops, 48 + u32 indir_size, u32 key_size); 46 49 int ethtool_check_rss_ctx_busy(struct net_device *dev, u32 rss_context); 47 50 int ethtool_rxfh_config_is_sym(u64 rxfh); 48 51
-34
net/ethtool/ioctl.c
··· 1473 1473 return ret; 1474 1474 } 1475 1475 1476 - static struct ethtool_rxfh_context * 1477 - ethtool_rxfh_ctx_alloc(const struct ethtool_ops *ops, 1478 - u32 indir_size, u32 key_size) 1479 - { 1480 - size_t indir_bytes, flex_len, key_off, size; 1481 - struct ethtool_rxfh_context *ctx; 1482 - u32 priv_bytes, indir_max; 1483 - u16 key_max; 1484 - 1485 - key_max = max(key_size, ops->rxfh_key_space); 1486 - indir_max = max(indir_size, ops->rxfh_indir_space); 1487 - 1488 - priv_bytes = ALIGN(ops->rxfh_priv_size, sizeof(u32)); 1489 - indir_bytes = array_size(indir_max, sizeof(u32)); 1490 - 1491 - key_off = size_add(priv_bytes, indir_bytes); 1492 - flex_len = size_add(key_off, key_max); 1493 - size = struct_size_t(struct ethtool_rxfh_context, data, flex_len); 1494 - 1495 - ctx = kzalloc(size, GFP_KERNEL_ACCOUNT); 1496 - if (!ctx) 1497 - return NULL; 1498 - 1499 - ctx->indir_size = indir_size; 1500 - ctx->key_size = key_size; 1501 - ctx->key_off = key_off; 1502 - ctx->priv_size = ops->rxfh_priv_size; 1503 - 1504 - ctx->hfunc = ETH_RSS_HASH_NO_CHANGE; 1505 - ctx->input_xfrm = RXH_XFRM_NO_CHANGE; 1506 - 1507 - return ctx; 1508 - } 1509 - 1510 1476 static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, 1511 1477 void __user *useraddr) 1512 1478 {