tg3: extract GRXRINGS from .get_rxnfc
Subsystems (3)
PATCH 1/1 tg3: extract GRXRINGS from .get_rxnfc
Commit 84eaf4359c36 ("net: ethtool: add get_rx_ring_count callback to optimize RX ring queries") added specific support for GRXRINGS callback, simplifying .get_rxnfc.
Remove the handling of GRXRINGS in .get_rxnfc() by moving it to the new .get_rx_ring_count().
Given that tg3_get_rxnfc() only handles ETHTOOL_GRXRINGS, then this function becomes useless now, and it is removed.
This also fixes the behavior for devices without MSIX support. Previously, the function would return -EOPNOTSUPP, but now it correctly returns 1.
The functionality remains the same: return the current queue count if the device is running, otherwise return the minimum of online CPUs and TG3_RSS_MAX_NUM_QS.
---
PS: This was compiled-tested only and NOT tested on a real hardware.
--- drivers/net/ethernet/broadcom/tg3.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-)
drivers/net/ethernet/broadcom/tg3.c +6 -18
@@ -12719,29 +12719,17 @@ static int tg3_get_sset_count(struct net_device *dev, int sset) } } -static int tg3_get_rxnfc (struct net_device *dev,struct ethtool_rxnfc *info, -u32 *rules__always_unused ) +static u32 tg3_get_rx_ring_count (struct net_device *dev) {struct tg3 *tp =netdev_priv (dev);if (!tg3_flag (tp,SUPPORT_MSIX )) -return -EOPNOTSUPP ; +return 1 ; -switch (info->cmd) { -case ETHTOOL_GRXRINGS : -if (netif_running (tp->dev)) - info->data = tp->rxq_cnt; -else { - info->data =num_online_cpus (); -if (info->data >TG3_RSS_MAX_NUM_QS ) - info->data =TG3_RSS_MAX_NUM_QS ; - } +if (netif_running (tp->dev)) +return tp->rxq_cnt; -return 0 ; - -default : -return -EOPNOTSUPP ; - } +return min (num_online_cpus (),TG3_RSS_MAX_NUM_QS ); }static u32 tg3_get_rxfh_indir_size (struct net_device *dev)
@@ -14268,7 +14256,7 @@ static const struct ethtool_ops tg3_ethtool_ops = { .get_coalesce = tg3_get_coalesce, .set_coalesce = tg3_set_coalesce, .get_sset_count = tg3_get_sset_count, - .get_rxnfc = tg3_get_rxnfc, + .get_rx_ring_count = tg3_get_rx_ring_count, .get_rxfh_indir_size = tg3_get_rxfh_indir_size, .get_rxfh = tg3_get_rxfh, .set_rxfh = tg3_set_rxfh,
---
base-commit: 5d505fdf758ebf197e5e99277e7203b4aabaf367
change-id: 20251105-grxrings_v1-5ed8bc9c1ecd
Best regards,
Signature · 1 line
Breno Leitao <[email protected]>
Michael Chan
maintainerQuoted 52 lines · Breno Leitao
Commit
84eaf4359c36("net: ethtool: addget_rx_ring_countcallback to optimize RX ring queries") added specific support for GRXRINGS callback, simplifying .get_rxnfc.Remove the handling of GRXRINGS in .get_rxnfc() by moving it to the new .get_rx_ring_count().
Given that
tg3_get_rxnfc()only handlesETHTOOL_GRXRINGS, then this function becomes useless now, and it is removed.This also fixes the behavior for devices without MSIX support. Previously, the function would return
-EOPNOTSUPP, but now it correctly returns 1.The functionality remains the same: return the current queue count if the device is running, otherwise return the minimum of online CPUs and
TG3_RSS_MAX_NUM_QS.Signed-off-by Breno Leitao <[email protected]>---
PS: This was compiled-tested only and NOT tested on a real hardware.--- drivers/net/ethernet/broadcom/tg3.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-)drivers/net/ethernet/broadcom/tg3.c +2
-11@@ -12719,29 +12719,17 @@ static int tg3_get_sset_count(struct net_device *dev, int sset) } } -static int tg3_get_rxnfc (struct net_device *dev,struct ethtool_rxnfc *info, -u32 *rules__always_unused ) +static u32 tg3_get_rx_ring_count (struct net_device *dev) {struct tg3 *tp =netdev_priv (dev);if (!tg3_flag (tp,SUPPORT_MSIX )) -return -EOPNOTSUPP ; +return 1 ; -switch (info->cmd) { -case ETHTOOL_GRXRINGS : -if (netif_running (tp->dev)) - info->data = tp->rxq_cnt; -else { - info->data =num_online_cpus (); -if (info->data >TG3_RSS_MAX_NUM_QS ) - info->data =TG3_RSS_MAX_NUM_QS ;
drivers/net/ethernet/broadcom/tg3.c static int tg3_get_sset_count(struct net_device *dev, int sset) · line 12732
Quoted 10 lines
drivers/net/ethernet/broadcom/tg3.c +3
-6- } +if (netif_running (tp->dev)) +return tp->rxq_cnt; -return 0 ; - -default : -return -EOPNOTSUPP ; - } +return min (num_online_cpus (),TG3_RSS_MAX_NUM_QS );
The existing code to use num_online_cpus() is actually not correct. This is more correct:
return min(netif_get_num_default_rss_queues(), tp->rxq_max);
I think when netif_get_num_default_rss_queues() was used to replace num_online_cpus(), tg3_get_rxnfc() was not properly converted.
Thanks.
Jakub Kicinski
maintainerQuoted 7 lines · On Wed, 5 Nov 2025 11:05:34 -0800 Michael Chan wrote:
The existing code to use
num_online_cpus()is actually not correct. This is more correct:return
min(netif_get_num_default_rss_queues(), tp->rxq_max);I think when
netif_get_num_default_rss_queues()was used to replacenum_online_cpus(),tg3_get_rxnfc()was not properly converted.
All true, but perhaps we want to do that change as a follow up? Someone may show up later insisting that fewer queues cases a regression for their workload..
The sensitivity to default queue count was why we didn't change most of the drivers when netif_get_num_default_rss_queues() got reworked to a more sane default than 8.
Quoted 5 lines · Jakub Kicinski
Quoted 3 lines · On Wed, 5 Nov 2025 11:05:34 -0800 Michael Chan wrote:
The existing code to use
num_online_cpus()is actually not correct. This is more correct:
Quoted 8 lines
Quoted 4 lines
return
min(netif_get_num_default_rss_queues(), tp->rxq_max);I think when
netif_get_num_default_rss_queues()was used to replacenum_online_cpus(),tg3_get_rxnfc()was not properly converted.All true, but perhaps we want to do that change as a follow up? Someone may show up later insisting that fewer queues cases a regression for their workload..
Sure, we can fix this separately. This returned value here when !netif_running() really won't change the ring count when it becomes netif_running(). tg3_open() will call tg3_enable_msix() which will set it to netif_get_num_default_rss_queues() regardless of what value we return here. IOW, fixing it should not cause any change in the number of default rings.
Anyway,
Quoted 4 lines
The sensitivity to default queue count was why we didn't change most of the drivers when
netif_get_num_default_rss_queues()got reworked to a more sane default than 8.
Quoted 7 lines · Michael Chan
The existing code to use
num_online_cpus()is actually not correct. This is more correct:return
min(netif_get_num_default_rss_queues(), tp->rxq_max);I think when
netif_get_num_default_rss_queues()was used to replacenum_online_cpus(),tg3_get_rxnfc()was not properly converted.
I can resend the current patch with this additional patch:
Author: Breno Leitao <[email protected]> Date: Thu Nov 6 08:05:49 2025 -0800
tg3: Fix num of RX queues being reported by ethtool
Using num_online_cpus() to report number of queues is actually not correct, as reported by Michael[1].
netif_get_num_default_rss_queues() was used to replace num_online_cpus() in the past, but tg3 ethtool callbacks didn't get converted. Doing it now.
drivers/net/ethernet/broadcom/tg3.c +1 -1
@@ -12729,7 +12729,7 @@ static u32 tg3_get_rx_ring_count(struct net_device *dev)if (netif_running (tp->dev))return tp->rxq_cnt; -return min (num_online_cpus (),TG3_RSS_MAX_NUM_QS ); +return min ((u32 )netif_get_num_default_rss_queues (), tp->rxq_max); }static u32 tg3_get_rxfh_indir_size (struct net_device *dev)
Michael Chan
maintainerQuoted 19 lines · Breno Leitao
tg3: Fix num of RX queues being reported by ethtool
Using
num_online_cpus()to report number of queues is actually not correct, as reported by Michael[1].
netif_get_num_default_rss_queues()was used to replacenum_online_cpus()in the past, but tg3 ethtool callbacks didn't get converted. Doing it now.Signed-off-by Breno Leitao <[email protected]>Suggested-by Michael Chan <[email protected]>drivers/net/ethernet/broadcom/tg3.c +0
-0
drivers/net/ethernet/broadcom/tg3.c static u32 tg3_get_rx_ring_count(struct net_device *dev) · line 12732
Quoted 5 lines
drivers/net/ethernet/broadcom/tg3.c +1
-1@@ -12729,7 +12729,7 @@ static u32 tg3_get_rx_ring_count(struct net_device *dev)if (netif_running (tp->dev))return tp->rxq_cnt; -return min (num_online_cpus (),TG3_RSS_MAX_NUM_QS ); +return min ((u32 )netif_get_num_default_rss_queues (), tp->rxq_max);
Isn't it better to use min_t()?
Simon Horman
reviewerQuoted 23 lines · Michael Chan
Quoted 22 lines · Breno Leitao
tg3: Fix num of RX queues being reported by ethtool
Using
num_online_cpus()to report number of queues is actually not correct, as reported by Michael[1].
netif_get_num_default_rss_queues()was used to replacenum_online_cpus()in the past, but tg3 ethtool callbacks didn't get converted. Doing it now.Signed-off-by Breno Leitao <[email protected]>Suggested-by Michael Chan <[email protected]>drivers/net/ethernet/broadcom/tg3.c +0
-0@@ -12729,7 +12729,7 @@ static u32 tg3_get_rx_ring_count(struct net_device *dev)if (netif_running (tp->dev))return tp->rxq_cnt;
Quoted 4 lines
drivers/net/ethernet/broadcom/tg3.c static u32 tg3_get_rx_ring_count(struct net_device *dev) · line 12732
Quoted 2 lines
drivers/net/ethernet/broadcom/tg3.c +1
-1-return min (num_online_cpus (),TG3_RSS_MAX_NUM_QS ); +return min ((u32 )netif_get_num_default_rss_queues (), tp->rxq_max);Isn't it better to use
min_t()?
FWIIW, umin() seems appropriate to me.
Commit 80fcac55385c ("minmax: add umin(a, b) and umax(a, b)") includes quite a long explanation of why it exists. And that does seem to match this case.
Quoted 29 lines · Simon Horman
Quoted 23 lines · Michael Chan
Quoted 22 lines · Breno Leitao
tg3: Fix num of RX queues being reported by ethtool
Using
num_online_cpus()to report number of queues is actually not correct, as reported by Michael[1].
netif_get_num_default_rss_queues()was used to replacenum_online_cpus()in the past, but tg3 ethtool callbacks didn't get converted. Doing it now.Signed-off-by Breno Leitao <[email protected]>Suggested-by Michael Chan <[email protected]>drivers/net/ethernet/broadcom/tg3.c +0
-0@@ -12729,7 +12729,7 @@ static u32 tg3_get_rx_ring_count(struct net_device *dev)if (netif_running (tp->dev))return tp->rxq_cnt;Quoted 4 lines
drivers/net/ethernet/broadcom/tg3.c static u32 tg3_get_rx_ring_count(struct net_device *dev) · line 12732
Quoted 2 lines
drivers/net/ethernet/broadcom/tg3.c +1
-1-return min (num_online_cpus (),TG3_RSS_MAX_NUM_QS ); +return min ((u32 )netif_get_num_default_rss_queues (), tp->rxq_max);Isn't it better to use
min_t()?
Quoted 5 lines
FWIIW,
umin()seems appropriate to me.Commit
80fcac55385c("minmax: addumin(a, b)andumax(a, b)") includes quite a long explanation of why it exists. And that does seem to match this case.
I've send the patch using min_t in [1] before this reply, and if I don't hear any concern about replacing min_t by umin(), I will update that patch with umin().
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 8 lines · On Wed, 05 Nov 2025 10:01:12 -0800 you wrote:
Commit
84eaf4359c36("net: ethtool: addget_rx_ring_countcallback to optimize RX ring queries") added specific support for GRXRINGS callback, simplifying .get_rxnfc.Remove the handling of GRXRINGS in .get_rxnfc() by moving it to the new .get_rx_ring_count().
[...]
Here is the summary with links:
- [net-next] tg3: extract GRXRINGS from .get_rxnfc
https://git.kernel.org/netdev/net-next/c/c04956cccb78
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html