Message ID | 20240416062952.14196-2-jiawenwu@trustnetic.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | Wangxun fixes | expand |
Jiawen Wu <jiawenwu@trustnetic.com> : > When using ethtool -S to print hardware statistics, the number of > Rx/Tx queues printed is greater than the number of queues actually > used. > > Fixes: 46b92e10d631 ("net: libwx: support hardware statistics") > Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com> > --- > .../net/ethernet/wangxun/libwx/wx_ethtool.c | 19 ++++++++++++++----- > 1 file changed, 14 insertions(+), 5 deletions(-) > > diff --git a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c > index cc3bec42ed8e..3847c909ba1a 100644 > --- a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c > +++ b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c > @@ -59,9 +59,17 @@ static const struct wx_stats wx_gstrings_stats[] = { > > int wx_get_sset_count(struct net_device *netdev, int sset) > { > + struct wx *wx = netdev_priv(netdev); > + > switch (sset) { > case ETH_SS_STATS: > - return WX_STATS_LEN; > + if (wx->num_tx_queues <= WX_NUM_RX_QUEUES) { > + return WX_STATS_LEN - > + (WX_NUM_RX_QUEUES - wx->num_tx_queues) * > + (sizeof(struct wx_queue_stats) / sizeof(u64)) * 2; > + } else { > + return WX_STATS_LEN; > + } The same code appears in wx_get_drvinfo. 1) It may be factored out. 2) The size of stats depends on num_{rx, tx}_queues. Unless there is some reason to keep WX_STATS_LEN, you may remove it, avoid the conditional code and always perform the required arithmetic. By the way, I understand that driver allocates num_tx_queues and num_rx_queues symmetrically as outlined in the comment at the start of wx_ethtool.c. However, it's a bit unexpected to see this dependency elsewhere.
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c index cc3bec42ed8e..3847c909ba1a 100644 --- a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c +++ b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c @@ -59,9 +59,17 @@ static const struct wx_stats wx_gstrings_stats[] = { int wx_get_sset_count(struct net_device *netdev, int sset) { + struct wx *wx = netdev_priv(netdev); + switch (sset) { case ETH_SS_STATS: - return WX_STATS_LEN; + if (wx->num_tx_queues <= WX_NUM_RX_QUEUES) { + return WX_STATS_LEN - + (WX_NUM_RX_QUEUES - wx->num_tx_queues) * + (sizeof(struct wx_queue_stats) / sizeof(u64)) * 2; + } else { + return WX_STATS_LEN; + } default: return -EOPNOTSUPP; } @@ -70,6 +78,7 @@ EXPORT_SYMBOL(wx_get_sset_count); void wx_get_strings(struct net_device *netdev, u32 stringset, u8 *data) { + struct wx *wx = netdev_priv(netdev); u8 *p = data; int i; @@ -77,11 +86,11 @@ void wx_get_strings(struct net_device *netdev, u32 stringset, u8 *data) case ETH_SS_STATS: for (i = 0; i < WX_GLOBAL_STATS_LEN; i++) ethtool_puts(&p, wx_gstrings_stats[i].stat_string); - for (i = 0; i < netdev->num_tx_queues; i++) { + for (i = 0; i < wx->num_tx_queues; i++) { ethtool_sprintf(&p, "tx_queue_%u_packets", i); ethtool_sprintf(&p, "tx_queue_%u_bytes", i); } - for (i = 0; i < WX_NUM_RX_QUEUES; i++) { + for (i = 0; i < wx->num_rx_queues; i++) { ethtool_sprintf(&p, "rx_queue_%u_packets", i); ethtool_sprintf(&p, "rx_queue_%u_bytes", i); } @@ -107,7 +116,7 @@ void wx_get_ethtool_stats(struct net_device *netdev, sizeof(u64)) ? *(u64 *)p : *(u32 *)p; } - for (j = 0; j < netdev->num_tx_queues; j++) { + for (j = 0; j < wx->num_tx_queues; j++) { ring = wx->tx_ring[j]; if (!ring) { data[i++] = 0; @@ -122,7 +131,7 @@ void wx_get_ethtool_stats(struct net_device *netdev, } while (u64_stats_fetch_retry(&ring->syncp, start)); i += 2; } - for (j = 0; j < WX_NUM_RX_QUEUES; j++) { + for (j = 0; j < wx->num_rx_queues; j++) { ring = wx->rx_ring[j]; if (!ring) { data[i++] = 0;
When using ethtool -S to print hardware statistics, the number of Rx/Tx queues printed is greater than the number of queues actually used. Fixes: 46b92e10d631 ("net: libwx: support hardware statistics") Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com> --- .../net/ethernet/wangxun/libwx/wx_ethtool.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)