Skip to content

Commit 125592f

Browse files
RajeshRavi-brcmdavem330
authored andcommitted
bnxt_en: show only relevant ethtool stats for a TX or RX ring
Currently, ethtool -S shows all TX/RX ring counters whether the channel is combined, RX, or TX. The unused counters will always be zero. Improve it by showing only the relevant counters if the channel is RX or TX. If the channel is combined, the counters will be shown exactly the same as before. [ MChan: Lots of cleanups and simplifications on Rajesh's original code] Signed-off-by: Rajesh Ravi <[email protected]> Signed-off-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3316d50 commit 125592f

File tree

1 file changed

+71
-22
lines changed

1 file changed

+71
-22
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c

Lines changed: 71 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,20 @@ static int bnxt_get_num_tpa_ring_stats(struct bnxt *bp)
494494
static int bnxt_get_num_ring_stats(struct bnxt *bp)
495495
{
496496
int rx, tx, cmn;
497+
bool sh = false;
498+
499+
if (bp->flags & BNXT_FLAG_SHARED_RINGS)
500+
sh = true;
497501

498502
rx = NUM_RING_RX_HW_STATS + NUM_RING_RX_SW_STATS +
499503
bnxt_get_num_tpa_ring_stats(bp);
500504
tx = NUM_RING_TX_HW_STATS;
501505
cmn = NUM_RING_CMN_SW_STATS;
502-
return (rx + tx + cmn) * bp->cp_nr_rings;
506+
if (sh)
507+
return (rx + tx + cmn) * bp->cp_nr_rings;
508+
else
509+
return rx * bp->rx_nr_rings + tx * bp->tx_nr_rings +
510+
cmn * bp->cp_nr_rings;
503511
}
504512

505513
static int bnxt_get_num_stats(struct bnxt *bp)
@@ -540,13 +548,29 @@ static int bnxt_get_sset_count(struct net_device *dev, int sset)
540548
}
541549
}
542550

551+
static bool is_rx_ring(struct bnxt *bp, int ring_num)
552+
{
553+
return ring_num < bp->rx_nr_rings;
554+
}
555+
556+
static bool is_tx_ring(struct bnxt *bp, int ring_num)
557+
{
558+
int tx_base = 0;
559+
560+
if (!(bp->flags & BNXT_FLAG_SHARED_RINGS))
561+
tx_base = bp->rx_nr_rings;
562+
563+
if (ring_num >= tx_base && ring_num < (tx_base + bp->tx_nr_rings))
564+
return true;
565+
return false;
566+
}
567+
543568
static void bnxt_get_ethtool_stats(struct net_device *dev,
544569
struct ethtool_stats *stats, u64 *buf)
545570
{
546571
u32 i, j = 0;
547572
struct bnxt *bp = netdev_priv(dev);
548-
u32 stat_fields = NUM_RING_RX_HW_STATS + NUM_RING_TX_HW_STATS +
549-
bnxt_get_num_tpa_ring_stats(bp);
573+
u32 tpa_stats;
550574

551575
if (!bp->bnapi) {
552576
j += bnxt_get_num_ring_stats(bp) + BNXT_NUM_SW_FUNC_STATS;
@@ -556,19 +580,38 @@ static void bnxt_get_ethtool_stats(struct net_device *dev,
556580
for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++)
557581
bnxt_sw_func_stats[i].counter = 0;
558582

583+
tpa_stats = bnxt_get_num_tpa_ring_stats(bp);
559584
for (i = 0; i < bp->cp_nr_rings; i++) {
560585
struct bnxt_napi *bnapi = bp->bnapi[i];
561586
struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring;
562587
__le64 *hw_stats = (__le64 *)cpr->hw_stats;
563588
u64 *sw;
564589
int k;
565590

566-
for (k = 0; k < stat_fields; j++, k++)
591+
if (is_rx_ring(bp, i)) {
592+
for (k = 0; k < NUM_RING_RX_HW_STATS; j++, k++)
593+
buf[j] = le64_to_cpu(hw_stats[k]);
594+
}
595+
if (is_tx_ring(bp, i)) {
596+
k = NUM_RING_RX_HW_STATS;
597+
for (; k < NUM_RING_RX_HW_STATS + NUM_RING_TX_HW_STATS;
598+
j++, k++)
599+
buf[j] = le64_to_cpu(hw_stats[k]);
600+
}
601+
if (!tpa_stats || !is_rx_ring(bp, i))
602+
goto skip_tpa_ring_stats;
603+
604+
k = NUM_RING_RX_HW_STATS + NUM_RING_TX_HW_STATS;
605+
for (; k < NUM_RING_RX_HW_STATS + NUM_RING_TX_HW_STATS +
606+
tpa_stats; j++, k++)
567607
buf[j] = le64_to_cpu(hw_stats[k]);
568608

609+
skip_tpa_ring_stats:
569610
sw = (u64 *)&cpr->sw_stats.rx;
570-
for (k = 0; k < NUM_RING_RX_SW_STATS; j++, k++)
571-
buf[j] = sw[k];
611+
if (is_rx_ring(bp, i)) {
612+
for (k = 0; k < NUM_RING_RX_SW_STATS; j++, k++)
613+
buf[j] = sw[k];
614+
}
572615

573616
sw = (u64 *)&cpr->sw_stats.cmn;
574617
for (k = 0; k < NUM_RING_CMN_SW_STATS; j++, k++)
@@ -650,20 +693,24 @@ static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
650693
switch (stringset) {
651694
case ETH_SS_STATS:
652695
for (i = 0; i < bp->cp_nr_rings; i++) {
653-
num_str = NUM_RING_RX_HW_STATS;
654-
for (j = 0; j < num_str; j++) {
655-
sprintf(buf, "[%d]: %s", i,
656-
bnxt_ring_rx_stats_str[j]);
657-
buf += ETH_GSTRING_LEN;
696+
if (is_rx_ring(bp, i)) {
697+
num_str = NUM_RING_RX_HW_STATS;
698+
for (j = 0; j < num_str; j++) {
699+
sprintf(buf, "[%d]: %s", i,
700+
bnxt_ring_rx_stats_str[j]);
701+
buf += ETH_GSTRING_LEN;
702+
}
658703
}
659-
num_str = NUM_RING_TX_HW_STATS;
660-
for (j = 0; j < num_str; j++) {
661-
sprintf(buf, "[%d]: %s", i,
662-
bnxt_ring_tx_stats_str[j]);
663-
buf += ETH_GSTRING_LEN;
704+
if (is_tx_ring(bp, i)) {
705+
num_str = NUM_RING_TX_HW_STATS;
706+
for (j = 0; j < num_str; j++) {
707+
sprintf(buf, "[%d]: %s", i,
708+
bnxt_ring_tx_stats_str[j]);
709+
buf += ETH_GSTRING_LEN;
710+
}
664711
}
665712
num_str = bnxt_get_num_tpa_ring_stats(bp);
666-
if (!num_str)
713+
if (!num_str || !is_rx_ring(bp, i))
667714
goto skip_tpa_stats;
668715

669716
if (bp->max_tpa_v2)
@@ -676,11 +723,13 @@ static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
676723
buf += ETH_GSTRING_LEN;
677724
}
678725
skip_tpa_stats:
679-
num_str = NUM_RING_RX_SW_STATS;
680-
for (j = 0; j < num_str; j++) {
681-
sprintf(buf, "[%d]: %s", i,
682-
bnxt_rx_sw_stats_str[j]);
683-
buf += ETH_GSTRING_LEN;
726+
if (is_rx_ring(bp, i)) {
727+
num_str = NUM_RING_RX_SW_STATS;
728+
for (j = 0; j < num_str; j++) {
729+
sprintf(buf, "[%d]: %s", i,
730+
bnxt_rx_sw_stats_str[j]);
731+
buf += ETH_GSTRING_LEN;
732+
}
684733
}
685734
num_str = NUM_RING_CMN_SW_STATS;
686735
for (j = 0; j < num_str; j++) {

0 commit comments

Comments
 (0)