A point can be made that devices that report a 0-size indirection table and 0-length key size don't really support RSS. Let's return -EOPNOTSUPP in that case, and skip these devices during DUMP requests. This however also reports -ENOTSUPP for devices that only supports flow hash fields ops now. Signed-off-by: Maxime Chevallier --- net/ethtool/ioctl.c | 6 ++++++ net/ethtool/rss.c | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c index 27b0e2e275dc..d32b403c8d3a 100644 --- a/net/ethtool/ioctl.c +++ b/net/ethtool/ioctl.c @@ -1444,6 +1444,9 @@ static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev, if (ops->get_rxfh_key_size) rxfh_dev.key_size = ops->get_rxfh_key_size(dev); + if (!rxfh_dev.indir_size && !rxfh_dev.key_size) + return -EOPNOTSUPP; + if (copy_from_user(&rxfh, useraddr, sizeof(rxfh))) return -EFAULT; user_indir_size = rxfh.indir_size; @@ -1554,6 +1557,9 @@ static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev, if (ops->get_rxfh_key_size) dev_key_size = ops->get_rxfh_key_size(dev); + if (!dev_indir_size && !dev_key_size) + return -EOPNOTSUPP; + if (copy_from_user(&rxfh, useraddr, sizeof(rxfh))) return -EFAULT; diff --git a/net/ethtool/rss.c b/net/ethtool/rss.c index d4a1a4724b67..cb9bead0cedd 100644 --- a/net/ethtool/rss.c +++ b/net/ethtool/rss.c @@ -129,6 +129,9 @@ rss_get_data_alloc(struct net_device *dev, struct rss_reply_data *data) if (ops->get_rxfh_key_size) data->hkey_size = ops->get_rxfh_key_size(dev); + if (!data->indir_size && !data->hkey_size) + return -EOPNOTSUPP; + indir_bytes = data->indir_size * sizeof(u32); total_size = indir_bytes + data->hkey_size; rss_config = kzalloc(total_size, GFP_KERNEL); @@ -449,7 +452,7 @@ rss_dump_one_dev(struct sk_buff *skb, struct netlink_callback *cb, if (!ctx->ctx_idx) { ret = rss_dump_one_ctx(skb, cb, dev, 0); - if (ret) + if (ret && ret != -EOPNOTSUPP) return ret; ctx->ctx_idx++; } @@ -457,7 +460,7 @@ rss_dump_one_dev(struct sk_buff *skb, struct netlink_callback *cb, for (; xa_find(&dev->ethtool->rss_ctx, &ctx->ctx_idx, ULONG_MAX, XA_PRESENT); ctx->ctx_idx++) { ret = rss_dump_one_ctx(skb, cb, dev, ctx->ctx_idx); - if (ret) + if (ret && ret != -EOPNOTSUPP) return ret; } ctx->ctx_idx = ctx->start_ctx; -- 2.55.0 The RSS feature is only available in stmmac if the hardware reports it through the DMA caps and if the platform glue sets rss_en. Introduce a helper that checks both. For now, no platform sets rss_en, but there's interest in the topic so leave the door open instead of dropping the feature altogether. No functional changes intended. Suggested-by: Nicolai Buchwitz Acked-by: Lorenzo Bianconi Reviewed-by: Joe Damato Signed-off-by: Maxime Chevallier --- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 5 +++++ drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index 4fc96b317d79..17991572fd2d 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -440,6 +440,11 @@ struct timespec64 stmmac_calc_tas_basetime(ktime_t old_base_time, ktime_t current_time, u64 cycle_time); +static inline bool stmmac_rss_is_supported(const struct stmmac_priv *priv) +{ + return priv->dma_cap.rssen && priv->plat->rss_en; +} + #if IS_ENABLED(CONFIG_STMMAC_SELFTESTS) void stmmac_selftest_run(struct net_device *dev, struct ethtool_test *etest, u64 *buf); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index 0c381ae0d0ff..76f9f5d35253 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -3571,7 +3571,7 @@ static void stmmac_mac_config_rx_queues_routing(struct stmmac_priv *priv) static void stmmac_mac_config_rss(struct stmmac_priv *priv) { - if (!priv->dma_cap.rssen || !priv->plat->rss_en) { + if (!stmmac_rss_is_supported(priv)) { priv->rss.enable = false; return; } @@ -8100,7 +8100,7 @@ static int __stmmac_dvr_probe(struct device *device, for (i = 0; i < ARRAY_SIZE(priv->rss.table); i++) priv->rss.table[i] = ethtool_rxfh_indir_default(i, rxq); - if (priv->dma_cap.rssen && priv->plat->rss_en) + if (stmmac_rss_is_supported(priv)) ndev->features |= NETIF_F_RXHASH; ndev->vlan_features |= ndev->features; -- 2.55.0 The RSS kselftests fail on stmmac, and this is partly due to the driver reporting bogus data for the RSS ops : - ethtool -x reports an indirection table and a key while the hardware doesn't have any of that - ethtool -X fails with -EINVAL. Return a 0 indir size and key size when rss isn't supported, effectively meaning we don't support RSS here. Signed-off-by: Maxime Chevallier --- drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c index 1cf0f8820b33..7f2a70575b83 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c @@ -927,6 +927,9 @@ static u32 stmmac_get_rxfh_key_size(struct net_device *dev) { struct stmmac_priv *priv = netdev_priv(dev); + if (!stmmac_rss_is_supported(priv)) + return 0; + return sizeof(priv->rss.key); } @@ -934,6 +937,9 @@ static u32 stmmac_get_rxfh_indir_size(struct net_device *dev) { struct stmmac_priv *priv = netdev_priv(dev); + if (!stmmac_rss_is_supported(priv)) + return 0; + return ARRAY_SIZE(priv->rss.table); } -- 2.55.0