diff options
author | Ben Hutchings <bhutchings@solarflare.com> | 2012-06-08 19:19:08 +0100 |
---|---|---|
committer | Ben Hutchings <bhutchings@solarflare.com> | 2012-06-08 19:19:08 +0100 |
commit | 74c42809c4cbd404c8f928a672df0e7ef43a90af (patch) | |
tree | 1b1f17e7f3b0f5298eef2a58f259a4aee8886525 | |
parent | 7adf748185e6d2897ad7dd04e481cf7b0921fc4d (diff) | |
download | ethtool-74c42809c4cbd404c8f928a672df0e7ef43a90af.tar.gz |
Make link mode listing in dump_link_caps() a data-driven loop
This removes lots of repeated code and makes it trivial to support
additional modes.
Signed-off-by: Ben Hutchings <bhutchings@solarflare.com>
-rw-r--r-- | ethtool.c | 99 |
1 files changed, 31 insertions, 68 deletions
@@ -444,8 +444,25 @@ static void dump_supported(struct ethtool_cmd *ep) static void dump_link_caps(const char *prefix, const char *an_prefix, u32 mask) { + static const struct { + int same_line; /* print on same line as previous */ + u32 value; + const char *name; + } mode_defs[] = { + { 0, ADVERTISED_10baseT_Half, "10baseT/Half" }, + { 1, ADVERTISED_10baseT_Full, "10baseT/Full" }, + { 0, ADVERTISED_100baseT_Half, "100baseT/Half" }, + { 1, ADVERTISED_100baseT_Full, "100baseT/Full" }, + { 0, ADVERTISED_1000baseT_Half, "1000baseT/Half" }, + { 1, ADVERTISED_1000baseT_Full, "1000baseT/Full" }, + { 0, ADVERTISED_1000baseKX_Full, "1000baseKX/Full" }, + { 0, ADVERTISED_2500baseX_Full, "2500baseX/Full" }, + { 0, ADVERTISED_10000baseT_Full, "10000baseT/Full" }, + { 0, ADVERTISED_10000baseKX4_Full, "10000baseKX4/Full" }, + { 0, ADVERTISED_20000baseMLD2_Full, "20000baseMLD2/Full" }, + }; int indent; - int did1; + int did1, new_line_pend, i; /* Indent just like the separate functions used to */ indent = strlen(prefix) + 14; @@ -455,73 +472,19 @@ dump_link_caps(const char *prefix, const char *an_prefix, u32 mask) fprintf(stdout, " %s link modes:%*s", prefix, indent - (int)strlen(prefix) - 12, ""); did1 = 0; - if (mask & ADVERTISED_10baseT_Half) { - did1++; fprintf(stdout, "10baseT/Half "); - } - if (mask & ADVERTISED_10baseT_Full) { - did1++; fprintf(stdout, "10baseT/Full "); - } - if (did1 && (mask & (ADVERTISED_100baseT_Half|ADVERTISED_100baseT_Full))) { - fprintf(stdout, "\n"); - fprintf(stdout, " %*s", indent, ""); - } - if (mask & ADVERTISED_100baseT_Half) { - did1++; fprintf(stdout, "100baseT/Half "); - } - if (mask & ADVERTISED_100baseT_Full) { - did1++; fprintf(stdout, "100baseT/Full "); - } - if (did1 && (mask & (ADVERTISED_1000baseT_Half|ADVERTISED_1000baseT_Full))) { - fprintf(stdout, "\n"); - fprintf(stdout, " %*s", indent, ""); - } - if (mask & ADVERTISED_1000baseT_Half) { - did1++; fprintf(stdout, "1000baseT/Half "); - } - if (mask & ADVERTISED_1000baseT_Full) { - did1++; fprintf(stdout, "1000baseT/Full "); - } - if (did1 && (mask & ADVERTISED_1000baseKX_Full)) { - fprintf(stdout, "\n"); - fprintf(stdout, " %*s", indent, ""); - } - if (mask & ADVERTISED_1000baseKX_Full) { - did1++; fprintf(stdout, "1000baseKX/Full "); - } - if (did1 && (mask & ADVERTISED_2500baseX_Full)) { - fprintf(stdout, "\n"); - fprintf(stdout, " %*s", indent, ""); - } - if (mask & ADVERTISED_2500baseX_Full) { - did1++; fprintf(stdout, "2500baseX/Full "); - } - if (did1 && (mask & ADVERTISED_10000baseT_Full)) { - fprintf(stdout, "\n"); - fprintf(stdout, " %*s", indent, ""); - } - if (mask & ADVERTISED_10000baseT_Full) { - did1++; fprintf(stdout, "10000baseT/Full "); - } - if (did1 && (mask & ADVERTISED_10000baseKX4_Full)) { - fprintf(stdout, "\n"); - fprintf(stdout, " %*s", indent, ""); - } - if (mask & ADVERTISED_10000baseKX4_Full) { - did1++; fprintf(stdout, "10000baseKX4/Full "); - } - if (did1 && (mask & ADVERTISED_20000baseMLD2_Full)) { - fprintf(stdout, "\n"); - fprintf(stdout, " %*s", indent, ""); - } - if (mask & ADVERTISED_20000baseMLD2_Full) { - did1++; fprintf(stdout, "20000baseMLD2/Full "); - } - if (did1 && (mask & ADVERTISED_20000baseKR2_Full)) { - fprintf(stdout, "\n"); - fprintf(stdout, " %*s", indent, ""); - } - if (mask & ADVERTISED_20000baseKR2_Full) { - did1++; fprintf(stdout, "20000baseKR2/Full "); + new_line_pend = 0; + for (i = 0; i < ARRAY_SIZE(mode_defs); i++) { + if (did1 && !mode_defs[i].same_line) + new_line_pend = 1; + if (mask & mode_defs[i].value) { + if (new_line_pend) { + fprintf(stdout, "\n"); + fprintf(stdout, " %*s", indent, ""); + new_line_pend = 0; + } + did1++; + fprintf(stdout, "%s ", mode_defs[i].name); + } } if (did1 == 0) fprintf(stdout, "Not reported"); |