diff mbox series

ethtool: Support ETHTOOL_GSTATS2 API.

Message ID 1524016207-4005-1-git-send-email-greearb@candelatech.com
State Rejected, archived
Delegated to: John Linville
Headers show
Series ethtool: Support ETHTOOL_GSTATS2 API. | expand

Commit Message

Ben Greear April 18, 2018, 1:50 a.m. UTC
From: Ben Greear <greearb@candelatech.com>

This allows users to specify flags to the get-stats
API, potentially saving expensive stats queries when
they are not desired.

Signed-off-by: Ben Greear <greearb@candelatech.com>
---
 ethtool-copy.h |  9 +++++++++
 ethtool.c      | 25 ++++++++++++++++++++-----
 2 files changed, 29 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/ethtool-copy.h b/ethtool-copy.h
index 8cc61e9..11ce456 100644
--- a/ethtool-copy.h
+++ b/ethtool-copy.h
@@ -1390,11 +1390,20 @@  enum ethtool_fec_config_bits {
 #define ETHTOOL_PHY_STUNABLE	0x0000004f /* Set PHY tunable configuration */
 #define ETHTOOL_GFECPARAM	0x00000050 /* Get FEC settings */
 #define ETHTOOL_SFECPARAM	0x00000051 /* Set FEC settings */
+#define ETHTOOL_GSTATS2		0x00000052 /* get NIC-specific statistics
+					    * with ability to specify flags.
+					    * See ETHTOOL_GS2* below.
+					    */
 
 /* compatibility with older code */
 #define SPARC_ETH_GSET		ETHTOOL_GSET
 #define SPARC_ETH_SSET		ETHTOOL_SSET
 
+/* GSTATS2 flags */
+#define ETHTOOL_GS2_SKIP_NONE (0)    /* default is to update all stats */
+#define ETHTOOL_GS2_SKIP_FW   (1<<0) /* Skip reading stats that probe firmware,
+				      * and thus are slow/expensive.
+				      */
 /* Link mode bit indices */
 enum ethtool_link_mode_bit_indices {
 	ETHTOOL_LINK_MODE_10baseT_Half_BIT	= 0,
diff --git a/ethtool.c b/ethtool.c
index 3289e0f..6a11077 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -3440,14 +3440,14 @@  static int do_phys_id(struct cmd_context *ctx)
 }
 
 static int do_gstats(struct cmd_context *ctx, int cmd, int stringset,
-		    const char *name)
+		     const char *name, u32 flags)
 {
 	struct ethtool_gstrings *strings;
 	struct ethtool_stats *stats;
 	unsigned int n_stats, sz_stats, i;
 	int err;
 
-	if (ctx->argc != 0)
+	if ((ctx->argc != 0) && (flags == ETHTOOL_GS2_SKIP_NONE))
 		exit_bad_args();
 
 	strings = get_stringset(ctx, stringset,
@@ -3475,7 +3475,10 @@  static int do_gstats(struct cmd_context *ctx, int cmd, int stringset,
 	}
 
 	stats->cmd = cmd;
-	stats->n_stats = n_stats;
+	if (cmd == ETHTOOL_GSTATS2)
+		stats->n_stats = flags;
+	else
+		stats->n_stats = n_stats;
 	err = send_ioctl(ctx, stats);
 	if (err < 0) {
 		perror("Cannot get stats information");
@@ -3500,12 +3503,22 @@  static int do_gstats(struct cmd_context *ctx, int cmd, int stringset,
 
 static int do_gnicstats(struct cmd_context *ctx)
 {
-	return do_gstats(ctx, ETHTOOL_GSTATS, ETH_SS_STATS, "NIC");
+	return do_gstats(ctx, ETHTOOL_GSTATS, ETH_SS_STATS, "NIC", ETHTOOL_GS2_SKIP_NONE);
+}
+
+static int do_gnicstats2(struct cmd_context *ctx)
+{
+	u32 flags = ETHTOOL_GS2_SKIP_NONE;
+	if (ctx->argc >= 1)
+		if (strcmp(ctx->argp[0], "nofw") == 0)
+			flags |= ETHTOOL_GS2_SKIP_FW;
+	return do_gstats(ctx, ETHTOOL_GSTATS2, ETH_SS_STATS, "NIC", flags);
 }
 
 static int do_gphystats(struct cmd_context *ctx)
 {
-	return do_gstats(ctx, ETHTOOL_GPHYSTATS, ETH_SS_PHY_STATS, "PHY");
+	return do_gstats(ctx, ETHTOOL_GPHYSTATS, ETH_SS_PHY_STATS, "PHY",
+			 ETHTOOL_GS2_SKIP_NONE);
 }
 
 static int do_srxntuple(struct cmd_context *ctx,
@@ -5118,6 +5131,8 @@  static const struct option {
 	{ "-t|--test", 1, do_test, "Execute adapter self test",
 	  "               [ online | offline | external_lb ]\n" },
 	{ "-S|--statistics", 1, do_gnicstats, "Show adapter statistics" },
+	{ "-2|--S2", 1, do_gnicstats2, "Show adapter statistics with flags",
+	  "               [ nofw ]\n" },
 	{ "--phy-statistics", 1, do_gphystats,
 	  "Show phy statistics" },
 	{ "-n|-u|--show-nfc|--show-ntuple", 1, do_grxclass,