netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Duyck <alexander.duyck@gmail.com>
To: kuba@kernel.org
Cc: netdev@vger.kernel.org, oss-drivers@netronome.com,
	simon.horman@netronome.com, yisen.zhuang@huawei.com,
	salil.mehta@huawei.com, intel-wired-lan@lists.osuosl.org,
	jesse.brandeburg@intel.com, anthony.l.nguyen@intel.com,
	drivers@pensando.io, snelson@pensando.io, netanel@amazon.com,
	akiyano@amazon.com, gtzalik@amazon.com, saeedb@amazon.com,
	GR-Linux-NIC-Dev@marvell.com, skalluru@marvell.com,
	rmody@marvell.com, kys@microsoft.com, haiyangz@microsoft.com,
	sthemmin@microsoft.com, wei.liu@kernel.org, mst@redhat.com,
	jasowang@redhat.com, pv-drivers@vmware.com, doshir@vmware.com,
	alexanderduyck@fb.com
Subject: [RFC PATCH 10/10] ionic: Update driver to use ethtool_gsprintf
Date: Wed, 10 Mar 2021 17:36:17 -0800	[thread overview]
Message-ID: <161542657729.13546.14928347259921159903.stgit@localhost.localdomain> (raw)
In-Reply-To: <161542634192.13546.4185974647834631704.stgit@localhost.localdomain>

From: Alexander Duyck <alexanderduyck@fb.com>

Update the ionic driver to make use of ethtool_gsprintf. In addition add
separate functions for Tx/Rx stats strings in order to reduce the total
amount of indenting needed in the driver code.

Signed-off-by: Alexander Duyck <alexanderduyck@fb.com>
---
 drivers/net/ethernet/pensando/ionic/ionic_stats.c |  145 +++++++++------------
 1 file changed, 60 insertions(+), 85 deletions(-)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_stats.c b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
index 6ae75b771a15..1dac960386df 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_stats.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
@@ -246,98 +246,73 @@ static u64 ionic_sw_stats_get_count(struct ionic_lif *lif)
 	return total;
 }
 
+static void ionic_sw_stats_get_tx_strings(struct ionic_lif *lif, u8 **buf,
+					  int q_num)
+{
+	int i;
+
+	for (i = 0; i < IONIC_NUM_TX_STATS; i++)
+		ethtool_gsprintf(buf, "tx_%d_%s", q_num,
+				 ionic_tx_stats_desc[i].name);
+
+	if (!test_bit(IONIC_LIF_F_UP, lif->state) ||
+	    !test_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state))
+		return;
+
+	for (i = 0; i < IONIC_NUM_TX_Q_STATS; i++)
+		ethtool_gsprintf(buf, "txq_%d_%s", q_num,
+				 ionic_txq_stats_desc[i].name);
+	for (i = 0; i < IONIC_NUM_DBG_CQ_STATS; i++)
+		ethtool_gsprintf(buf, "txq_%d_cq_%s", q_num,
+				 ionic_dbg_cq_stats_desc[i].name);
+	for (i = 0; i < IONIC_NUM_DBG_INTR_STATS; i++)
+		ethtool_gsprintf(buf, "txq_%d_intr_%s", q_num,
+				 ionic_dbg_intr_stats_desc[i].name);
+	for (i = 0; i < IONIC_MAX_NUM_SG_CNTR; i++)
+		ethtool_gsprintf(buf, "txq_%d_sg_cntr_%d", q_num, i);
+}
+
+static void ionic_sw_stats_get_rx_strings(struct ionic_lif *lif, u8 **buf,
+					  int q_num)
+{
+	int i;
+
+	for (i = 0; i < IONIC_NUM_RX_STATS; i++)
+		ethtool_gsprintf(buf, "rx_%d_%s", q_num,
+				 ionic_rx_stats_desc[i].name);
+
+	if (!test_bit(IONIC_LIF_F_UP, lif->state) ||
+	    !test_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state))
+		return;
+
+	for (i = 0; i < IONIC_NUM_DBG_CQ_STATS; i++)
+		ethtool_gsprintf(buf, "rxq_%d_cq_%s", q_num,
+				 ionic_dbg_cq_stats_desc[i].name);
+	for (i = 0; i < IONIC_NUM_DBG_INTR_STATS; i++)
+		ethtool_gsprintf(buf, "rxq_%d_intr_%s", q_num,
+				 ionic_dbg_intr_stats_desc[i].name);
+	for (i = 0; i < IONIC_NUM_DBG_NAPI_STATS; i++)
+		ethtool_gsprintf(buf, "rxq_%d_napi_%s", q_num,
+				 ionic_dbg_napi_stats_desc[i].name);
+	for (i = 0; i < IONIC_MAX_NUM_NAPI_CNTR; i++)
+		ethtool_gsprintf(buf, "rxq_%d_napi_work_done_%d", q_num, i);
+}
+
 static void ionic_sw_stats_get_strings(struct ionic_lif *lif, u8 **buf)
 {
 	int i, q_num;
 
-	for (i = 0; i < IONIC_NUM_LIF_STATS; i++) {
-		snprintf(*buf, ETH_GSTRING_LEN, ionic_lif_stats_desc[i].name);
-		*buf += ETH_GSTRING_LEN;
-	}
+	for (i = 0; i < IONIC_NUM_LIF_STATS; i++)
+		ethtool_gsprintf(buf, ionic_lif_stats_desc[i].name);
 
-	for (i = 0; i < IONIC_NUM_PORT_STATS; i++) {
-		snprintf(*buf, ETH_GSTRING_LEN,
-			 ionic_port_stats_desc[i].name);
-		*buf += ETH_GSTRING_LEN;
-	}
+	for (i = 0; i < IONIC_NUM_PORT_STATS; i++)
+		ethtool_gsprintf(buf, ionic_port_stats_desc[i].name);
 
-	for (q_num = 0; q_num < MAX_Q(lif); q_num++) {
-		for (i = 0; i < IONIC_NUM_TX_STATS; i++) {
-			snprintf(*buf, ETH_GSTRING_LEN, "tx_%d_%s",
-				 q_num, ionic_tx_stats_desc[i].name);
-			*buf += ETH_GSTRING_LEN;
-		}
+	for (q_num = 0; q_num < MAX_Q(lif); q_num++)
+		ionic_sw_stats_get_tx_strings(lif, buf, q_num);
 
-		if (test_bit(IONIC_LIF_F_UP, lif->state) &&
-		    test_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state)) {
-			for (i = 0; i < IONIC_NUM_TX_Q_STATS; i++) {
-				snprintf(*buf, ETH_GSTRING_LEN,
-					 "txq_%d_%s",
-					 q_num,
-					 ionic_txq_stats_desc[i].name);
-				*buf += ETH_GSTRING_LEN;
-			}
-			for (i = 0; i < IONIC_NUM_DBG_CQ_STATS; i++) {
-				snprintf(*buf, ETH_GSTRING_LEN,
-					 "txq_%d_cq_%s",
-					 q_num,
-					 ionic_dbg_cq_stats_desc[i].name);
-				*buf += ETH_GSTRING_LEN;
-			}
-			for (i = 0; i < IONIC_NUM_DBG_INTR_STATS; i++) {
-				snprintf(*buf, ETH_GSTRING_LEN,
-					 "txq_%d_intr_%s",
-					 q_num,
-					 ionic_dbg_intr_stats_desc[i].name);
-				*buf += ETH_GSTRING_LEN;
-			}
-			for (i = 0; i < IONIC_MAX_NUM_SG_CNTR; i++) {
-				snprintf(*buf, ETH_GSTRING_LEN,
-					 "txq_%d_sg_cntr_%d",
-					 q_num, i);
-				*buf += ETH_GSTRING_LEN;
-			}
-		}
-	}
-	for (q_num = 0; q_num < MAX_Q(lif); q_num++) {
-		for (i = 0; i < IONIC_NUM_RX_STATS; i++) {
-			snprintf(*buf, ETH_GSTRING_LEN,
-				 "rx_%d_%s",
-				 q_num, ionic_rx_stats_desc[i].name);
-			*buf += ETH_GSTRING_LEN;
-		}
-
-		if (test_bit(IONIC_LIF_F_UP, lif->state) &&
-		    test_bit(IONIC_LIF_F_SW_DEBUG_STATS, lif->state)) {
-			for (i = 0; i < IONIC_NUM_DBG_CQ_STATS; i++) {
-				snprintf(*buf, ETH_GSTRING_LEN,
-					 "rxq_%d_cq_%s",
-					 q_num,
-					 ionic_dbg_cq_stats_desc[i].name);
-				*buf += ETH_GSTRING_LEN;
-			}
-			for (i = 0; i < IONIC_NUM_DBG_INTR_STATS; i++) {
-				snprintf(*buf, ETH_GSTRING_LEN,
-					 "rxq_%d_intr_%s",
-					 q_num,
-					 ionic_dbg_intr_stats_desc[i].name);
-				*buf += ETH_GSTRING_LEN;
-			}
-			for (i = 0; i < IONIC_NUM_DBG_NAPI_STATS; i++) {
-				snprintf(*buf, ETH_GSTRING_LEN,
-					 "rxq_%d_napi_%s",
-					 q_num,
-					 ionic_dbg_napi_stats_desc[i].name);
-				*buf += ETH_GSTRING_LEN;
-			}
-			for (i = 0; i < IONIC_MAX_NUM_NAPI_CNTR; i++) {
-				snprintf(*buf, ETH_GSTRING_LEN,
-					 "rxq_%d_napi_work_done_%d",
-					 q_num, i);
-				*buf += ETH_GSTRING_LEN;
-			}
-		}
-	}
+	for (q_num = 0; q_num < MAX_Q(lif); q_num++)
+		ionic_sw_stats_get_rx_strings(lif, buf, q_num);
 }
 
 static void ionic_sw_stats_get_values(struct ionic_lif *lif, u64 **buf)



  parent reply	other threads:[~2021-03-11  1:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11  1:35 [RFC PATCH 00/10] ethtool: Factor out common code related to writing ethtool strings Alexander Duyck
2021-03-11  1:35 ` [RFC PATCH 01/10] ethtool: Add common function for filling out strings Alexander Duyck
2021-03-11  2:08   ` Jakub Kicinski
2021-03-11 20:37     ` Jesse Brandeburg
2021-03-11  1:35 ` [RFC PATCH 02/10] intel: Update drivers to use ethtool_gsprintf Alexander Duyck
2021-03-11 20:32   ` Jesse Brandeburg
2021-03-11  1:35 ` [RFC PATCH 03/10] nfp: Replace nfp_pr_et with ethtool_gsprintf Alexander Duyck
2021-03-11 11:51   ` Simon Horman
2021-03-11  1:35 ` [RFC PATCH 04/10] hisilicon: Update drivers to use ethtool_gsprintf Alexander Duyck
2021-03-11  1:35 ` [RFC PATCH 05/10] ena: Update driver " Alexander Duyck
2021-03-11 13:42   ` Kiyanovski, Arthur
2021-03-11  1:35 ` [RFC PATCH 06/10] netvsc: " Alexander Duyck
2021-03-11  1:35 ` [RFC PATCH 07/10] virtio_net: " Alexander Duyck
2021-03-11  1:36 ` [RFC PATCH 08/10] vmxnet3: " Alexander Duyck
2021-03-11  1:36 ` [RFC PATCH 09/10] bna: " Alexander Duyck
2021-03-11  1:36 ` Alexander Duyck [this message]
2021-03-11 17:19   ` [RFC PATCH 10/10] ionic: " Shannon Nelson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=161542657729.13546.14928347259921159903.stgit@localhost.localdomain \
    --to=alexander.duyck@gmail.com \
    --cc=GR-Linux-NIC-Dev@marvell.com \
    --cc=akiyano@amazon.com \
    --cc=alexanderduyck@fb.com \
    --cc=anthony.l.nguyen@intel.com \
    --cc=doshir@vmware.com \
    --cc=drivers@pensando.io \
    --cc=gtzalik@amazon.com \
    --cc=haiyangz@microsoft.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jasowang@redhat.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=kuba@kernel.org \
    --cc=kys@microsoft.com \
    --cc=mst@redhat.com \
    --cc=netanel@amazon.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    --cc=pv-drivers@vmware.com \
    --cc=rmody@marvell.com \
    --cc=saeedb@amazon.com \
    --cc=salil.mehta@huawei.com \
    --cc=simon.horman@netronome.com \
    --cc=skalluru@marvell.com \
    --cc=snelson@pensando.io \
    --cc=sthemmin@microsoft.com \
    --cc=wei.liu@kernel.org \
    --cc=yisen.zhuang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).