Netdev List
 help / color / mirror / Atom feed
From: Ben Hutchings <bhutchings@solarflare.com>
To: "Esa-Pekka Pyökkimies" <esa-pekka.pyokkimies@stonesoft.com>,
	"Yaniv Rosner" <yanivr@broadcom.com>
Cc: netdev <netdev@vger.kernel.org>
Subject: [PATCH ethtool] Combine code to display supported and advertised link capabilities
Date: Wed, 01 Jun 2011 23:49:29 +0100	[thread overview]
Message-ID: <1306968569.2758.54.camel@bwh-desktop> (raw)

Rename dump_advertised() to dump_link_caps(), and change
dump_supported() to call it instead of repeating nearly identical
code.  Add a separate prefix parameter and adjust indentation
so that the output is unchanged except for added lines.

Deleted unused parameter and variables.

As an immediate benefit, this adds the display of supported pause
frame use.

Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
---
I've just committed and pushed out this change to ethtool.

Esa-Pekka, I think this covers what you wanted.

Yaniv, this should allow you to add the 20G flags in just one function.
But I still want you to update the manual page at the same time.

Ben.

 ethtool.c |   80 ++++++++++++++++---------------------------------------------
 1 files changed, 21 insertions(+), 59 deletions(-)

diff --git a/ethtool.c b/ethtool.c
index edfbe3d..b6fa6bd 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -1132,10 +1132,11 @@ static void parse_cmdline(int argc, char **argp)
 		exit_bad_args();
 }
 
+static void dump_link_caps(const char *prefix, const char *an_prefix, u32 mask);
+
 static void dump_supported(struct ethtool_cmd *ep)
 {
-	u_int32_t mask = ep->supported;
-	int did1;
+	u32 mask = ep->supported;
 
 	fprintf(stdout, "	Supported ports: [ ");
 	if (mask & SUPPORTED_TP)
@@ -1150,64 +1151,25 @@ static void dump_supported(struct ethtool_cmd *ep)
 		fprintf(stdout, "FIBRE ");
 	fprintf(stdout, "]\n");
 
-	fprintf(stdout, "	Supported link modes:   ");
-	did1 = 0;
-	if (mask & SUPPORTED_10baseT_Half) {
-		did1++; fprintf(stdout, "10baseT/Half ");
-	}
-	if (mask & SUPPORTED_10baseT_Full) {
-		did1++; fprintf(stdout, "10baseT/Full ");
-	}
-	if (did1 && (mask & (SUPPORTED_100baseT_Half|SUPPORTED_100baseT_Full))) {
-		fprintf(stdout, "\n");
-		fprintf(stdout, "	                        ");
-	}
-	if (mask & SUPPORTED_100baseT_Half) {
-		did1++; fprintf(stdout, "100baseT/Half ");
-	}
-	if (mask & SUPPORTED_100baseT_Full) {
-		did1++; fprintf(stdout, "100baseT/Full ");
-	}
-	if (did1 && (mask & (SUPPORTED_1000baseT_Half|SUPPORTED_1000baseT_Full))) {
-		fprintf(stdout, "\n");
-		fprintf(stdout, "	                        ");
-	}
-	if (mask & SUPPORTED_1000baseT_Half) {
-		did1++; fprintf(stdout, "1000baseT/Half ");
-	}
-	if (mask & SUPPORTED_1000baseT_Full) {
-		did1++; fprintf(stdout, "1000baseT/Full ");
-	}
-	if (did1 && (mask & SUPPORTED_2500baseX_Full)) {
-		fprintf(stdout, "\n");
-		fprintf(stdout, "	                        ");
-	}
-	if (mask & SUPPORTED_2500baseX_Full) {
-		did1++; fprintf(stdout, "2500baseX/Full ");
-	}
-	if (did1 && (mask & SUPPORTED_10000baseT_Full)) {
-		fprintf(stdout, "\n");
-		fprintf(stdout, "	                        ");
-	}
-	if (mask & SUPPORTED_10000baseT_Full) {
-		did1++; fprintf(stdout, "10000baseT/Full ");
-	}
-	fprintf(stdout, "\n");
-
-	fprintf(stdout, "	Supports auto-negotiation: ");
-	if (mask & SUPPORTED_Autoneg)
-		fprintf(stdout, "Yes\n");
-	else
-		fprintf(stdout, "No\n");
+	dump_link_caps("Supported", "Supports", mask);
 }
 
-static void dump_advertised(struct ethtool_cmd *ep,
-			    const char *prefix, u_int32_t mask)
+/* Print link capability flags (supported, advertised or lp_advertised).
+ * Assumes that the corresponding SUPPORTED and ADVERTISED flags are equal.
+ */
+static void
+dump_link_caps(const char *prefix, const char *an_prefix, u32 mask)
 {
-	int indent = strlen(prefix) + 14;
+	int indent;
 	int did1;
 
-	fprintf(stdout, "	%s link modes:  ", prefix);
+	/* Indent just like the separate functions used to */
+	indent = strlen(prefix) + 14;
+	if (indent < 24)
+		indent = 24;
+
+	fprintf(stdout, "	%s link modes:%*s", prefix,
+		indent - strlen(prefix) - 12, "");
 	did1 = 0;
 	if (mask & ADVERTISED_10baseT_Half) {
 		did1++; fprintf(stdout, "10baseT/Half ");
@@ -1266,7 +1228,7 @@ static void dump_advertised(struct ethtool_cmd *ep,
 			fprintf(stdout, "No\n");
 	}
 
-	fprintf(stdout, "	%s auto-negotiation: ", prefix);
+	fprintf(stdout, "	%s auto-negotiation: ", an_prefix);
 	if (mask & ADVERTISED_Autoneg)
 		fprintf(stdout, "Yes\n");
 	else
@@ -1278,10 +1240,10 @@ static int dump_ecmd(struct ethtool_cmd *ep)
 	u32 speed;
 
 	dump_supported(ep);
-	dump_advertised(ep, "Advertised", ep->advertising);
+	dump_link_caps("Advertised", "Advertised", ep->advertising);
 	if (ep->lp_advertising)
-		dump_advertised(ep, "Link partner advertised",
-				ep->lp_advertising);
+		dump_link_caps("Link partner advertised",
+			       "Link partner advertised", ep->lp_advertising);
 
 	fprintf(stdout, "	Speed: ");
 	speed = ethtool_cmd_speed(ep);
-- 
1.7.4.4


-- 
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.


                 reply	other threads:[~2011-06-01 22:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1306968569.2758.54.camel@bwh-desktop \
    --to=bhutchings@solarflare.com \
    --cc=esa-pekka.pyokkimies@stonesoft.com \
    --cc=netdev@vger.kernel.org \
    --cc=yanivr@broadcom.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