Blame SOURCES/0050-netdrv-bnxt_en-Refactor-ethtool-ring-statistics-logi.patch

f95c89
From f6434f257c096205df4d2333e219e66229433072 Mon Sep 17 00:00:00 2001
f95c89
From: Jonathan Toppins <jtoppins@redhat.com>
f95c89
Date: Wed, 2 Oct 2019 18:23:05 -0400
f95c89
Subject: [PATCH 50/96] [netdrv] bnxt_en: Refactor ethtool ring statistics
f95c89
 logic
f95c89
f95c89
Message-id: <5774e6c89e7d2c4808b6fd71337d9e03acce8bcd.1570027456.git.jtoppins@redhat.com>
f95c89
Patchwork-id: 276474
f95c89
O-Subject: [RHEL-8.2 PATCH 43/78] bnxt_en: Refactor ethtool ring statistics logic.
f95c89
Bugzilla: 1724766
f95c89
RH-Acked-by: John Linville <linville@redhat.com>
f95c89
RH-Acked-by: Jarod Wilson <jarod@redhat.com>
f95c89
f95c89
The current code assumes that the per ring statistics counters are
f95c89
fixed.  In newer chips that support a newer version of TPA, the
f95c89
TPA counters are also changed.  Refactor the code by defining these
f95c89
counter names in arrays so that it is easy to add a new array for
f95c89
a new set of counters supported by the newer chips.
f95c89
f95c89
Signed-off-by: Michael Chan <michael.chan@broadcom.com>
f95c89
Signed-off-by: David S. Miller <davem@davemloft.net>
f95c89
(cherry picked from commit ee79566e65945dcf557bcfb9335e46fac67fb002)
f95c89
Bugzilla: 1724766
f95c89
Build Info: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=23809532
f95c89
Tested: build, boot, basic ping
f95c89
Signed-off-by: Jonathan Toppins <jtoppins@redhat.com>
f95c89
Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
f95c89
---
f95c89
 drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c | 120 +++++++++++++---------
f95c89
 1 file changed, 70 insertions(+), 50 deletions(-)
f95c89
f95c89
Index: src/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c
f95c89
===================================================================
f95c89
--- src.orig/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c	2020-02-06 16:23:15.727512996 +0100
f95c89
+++ src/drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c	2020-02-06 16:23:17.017501155 +0100
f95c89
@@ -137,7 +137,36 @@
f95c89
 	return rc;
f95c89
 }
f95c89
 
f95c89
-#define BNXT_NUM_STATS	22
f95c89
+static const char * const bnxt_ring_stats_str[] = {
f95c89
+	"rx_ucast_packets",
f95c89
+	"rx_mcast_packets",
f95c89
+	"rx_bcast_packets",
f95c89
+	"rx_discards",
f95c89
+	"rx_drops",
f95c89
+	"rx_ucast_bytes",
f95c89
+	"rx_mcast_bytes",
f95c89
+	"rx_bcast_bytes",
f95c89
+	"tx_ucast_packets",
f95c89
+	"tx_mcast_packets",
f95c89
+	"tx_bcast_packets",
f95c89
+	"tx_discards",
f95c89
+	"tx_drops",
f95c89
+	"tx_ucast_bytes",
f95c89
+	"tx_mcast_bytes",
f95c89
+	"tx_bcast_bytes",
f95c89
+};
f95c89
+
f95c89
+static const char * const bnxt_ring_tpa_stats_str[] = {
f95c89
+	"tpa_packets",
f95c89
+	"tpa_bytes",
f95c89
+	"tpa_events",
f95c89
+	"tpa_aborts",
f95c89
+};
f95c89
+
f95c89
+static const char * const bnxt_ring_sw_stats_str[] = {
f95c89
+	"rx_l4_csum_errors",
f95c89
+	"missed_irqs",
f95c89
+};
f95c89
 
f95c89
 #define BNXT_RX_STATS_ENTRY(counter)	\
f95c89
 	{ BNXT_RX_STATS_OFFSET(counter), __stringify(counter) }
f95c89
@@ -432,9 +461,20 @@
f95c89
 	 ARRAY_SIZE(bnxt_tx_pkts_pri_arr))
f95c89
 #define BNXT_NUM_PCIE_STATS ARRAY_SIZE(bnxt_pcie_stats_arr)
f95c89
 
f95c89
+static int bnxt_get_num_ring_stats(struct bnxt *bp)
f95c89
+{
f95c89
+	int num_stats;
f95c89
+
f95c89
+	num_stats = ARRAY_SIZE(bnxt_ring_stats_str) +
f95c89
+		    ARRAY_SIZE(bnxt_ring_sw_stats_str);
f95c89
+	if (BNXT_SUPPORTS_TPA(bp))
f95c89
+		num_stats += ARRAY_SIZE(bnxt_ring_tpa_stats_str);
f95c89
+	return num_stats * bp->cp_nr_rings;
f95c89
+}
f95c89
+
f95c89
 static int bnxt_get_num_stats(struct bnxt *bp)
f95c89
 {
f95c89
-	int num_stats = BNXT_NUM_STATS * bp->cp_nr_rings;
f95c89
+	int num_stats = bnxt_get_num_ring_stats(bp);
f95c89
 
f95c89
 	num_stats += BNXT_NUM_SW_FUNC_STATS;
f95c89
 
f95c89
@@ -475,10 +515,13 @@
f95c89
 {
f95c89
 	u32 i, j = 0;
f95c89
 	struct bnxt *bp = netdev_priv(dev);
f95c89
-	u32 stat_fields = sizeof(struct ctx_hw_stats) / 8;
f95c89
+	u32 stat_fields = ARRAY_SIZE(bnxt_ring_stats_str);
f95c89
+
f95c89
+	if (BNXT_SUPPORTS_TPA(bp))
f95c89
+		stat_fields += ARRAY_SIZE(bnxt_ring_tpa_stats_str);
f95c89
 
f95c89
 	if (!bp->bnapi) {
f95c89
-		j += BNXT_NUM_STATS * bp->cp_nr_rings + BNXT_NUM_SW_FUNC_STATS;
f95c89
+		j += bnxt_get_num_ring_stats(bp) + BNXT_NUM_SW_FUNC_STATS;
f95c89
 		goto skip_ring_stats;
f95c89
 	}
f95c89
 
f95c89
@@ -566,56 +609,33 @@
f95c89
 static void bnxt_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
f95c89
 {
f95c89
 	struct bnxt *bp = netdev_priv(dev);
f95c89
-	u32 i;
f95c89
+	u32 i, j, num_str;
f95c89
 
f95c89
 	switch (stringset) {
f95c89
-	/* The number of strings must match BNXT_NUM_STATS defined above. */
f95c89
 	case ETH_SS_STATS:
f95c89
 		for (i = 0; i < bp->cp_nr_rings; i++) {
f95c89
-			sprintf(buf, "[%d]: rx_ucast_packets", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: rx_mcast_packets", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: rx_bcast_packets", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: rx_discards", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: rx_drops", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: rx_ucast_bytes", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: rx_mcast_bytes", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: rx_bcast_bytes", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: tx_ucast_packets", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: tx_mcast_packets", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: tx_bcast_packets", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: tx_discards", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: tx_drops", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: tx_ucast_bytes", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: tx_mcast_bytes", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: tx_bcast_bytes", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: tpa_packets", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: tpa_bytes", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: tpa_events", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: tpa_aborts", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: rx_l4_csum_errors", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
-			sprintf(buf, "[%d]: missed_irqs", i);
f95c89
-			buf += ETH_GSTRING_LEN;
f95c89
+			num_str = ARRAY_SIZE(bnxt_ring_stats_str);
f95c89
+			for (j = 0; j < num_str; j++) {
f95c89
+				sprintf(buf, "[%d]: %s", i,
f95c89
+					bnxt_ring_stats_str[j]);
f95c89
+				buf += ETH_GSTRING_LEN;
f95c89
+			}
f95c89
+			if (!BNXT_SUPPORTS_TPA(bp))
f95c89
+				goto skip_tpa_stats;
f95c89
+
f95c89
+			num_str = ARRAY_SIZE(bnxt_ring_tpa_stats_str);
f95c89
+			for (j = 0; j < num_str; j++) {
f95c89
+				sprintf(buf, "[%d]: %s", i,
f95c89
+					bnxt_ring_tpa_stats_str[j]);
f95c89
+				buf += ETH_GSTRING_LEN;
f95c89
+			}
f95c89
+skip_tpa_stats:
f95c89
+			num_str = ARRAY_SIZE(bnxt_ring_sw_stats_str);
f95c89
+			for (j = 0; j < num_str; j++) {
f95c89
+				sprintf(buf, "[%d]: %s", i,
f95c89
+					bnxt_ring_sw_stats_str[j]);
f95c89
+				buf += ETH_GSTRING_LEN;
f95c89
+			}
f95c89
 		}
f95c89
 		for (i = 0; i < BNXT_NUM_SW_FUNC_STATS; i++) {
f95c89
 			strcpy(buf, bnxt_sw_func_stats[i].string);