summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hutchings <bhutchings@solarflare.com>2011-06-01 23:27:17 +0100
committerBen Hutchings <bhutchings@solarflare.com>2011-06-01 23:38:53 +0100
commitd6c816b659f946f7cf6fccb0d79439bb479b2014 (patch)
treeb31d28dbd475686f19d3e21ba2376e5a0adcdc35
parent0bf5bd216afeb8e26289293b28159f76a9e7673c (diff)
downloadethtool-d6c816b659f946f7cf6fccb0d79439bb479b2014.tar.gz
Combine code to display supported and advertised link capabilities
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>
-rw-r--r--ethtool.c80
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);