summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rw-r--r--ethtool.873
-rw-r--r--ethtool.c288
3 files changed, 145 insertions, 217 deletions
diff --git a/AUTHORS b/AUTHORS
index b2b9043..2b3c0a6 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -5,3 +5,4 @@ Tim Hockin <thockin@sun.com>
Eli Kupermann <eli.kupermann@intel.com>
Chris Leech <christopher.leech@intel.com>
Scott Feldman <scott.feldman@intel.com>
+Andi Kleen
diff --git a/ethtool.8 b/ethtool.8
index d760907..242fe9d 100644
--- a/ethtool.8
+++ b/ethtool.8
@@ -47,21 +47,21 @@ ethtool \- Display or change ethernet card settings
.B ethtool
.I ethX
-.B ethtool \-h
+.B ethtool \-h|\-\-help
-.B ethtool \-a
+.B ethtool \-a|\-\-show\-pause
.I ethX
-.B ethtool \-A
+.B ethtool \-A|\-\-pause
.I ethX
.B2 autoneg on off
.B2 rx on off
.B2 tx on off
-.B ethtool \-c
+.B ethtool \-c|\-\-show\-coalesce
.I ethX
-.B ethtool \-C
+.B ethtool \-C|\-\-coalesce
.I ethX
.B2 adaptive-rx on off
.B2 adaptive-tx on off
@@ -106,10 +106,10 @@ ethtool \- Display or change ethernet card settings
.RB [ sample-interval
.IR N ]
-.B ethtool \-g
+.B ethtool \-g|\-\-show\-ring
.I ethX
-.B ethtool \-G
+.B ethtool \-G|\-\-set\-ring
.I ethX
.RB [ rx
.IR N ]
@@ -120,14 +120,14 @@ ethtool \- Display or change ethernet card settings
.RB [ tx
.IR N ]
-.B ethtool \-i
+.B ethtool \-i|\-\-driver
.I ethX
-.B ethtool \-d
+.B ethtool \-d|\-\-register\-dump
.I ethX
.B2 raw on off
-.B ethtool \-e
+.B ethtool \-e|\-\-eeprom\-dump
.I ethX
.B2 raw on off
.RB [ offset
@@ -135,7 +135,7 @@ ethtool \- Display or change ethernet card settings
.RB [ length
.IR N ]
-.B ethtool \-E
+.B ethtool \-E|\-\-change\-eeprom
.I ethX
.RB [ magic
.IR N ]
@@ -144,27 +144,27 @@ ethtool \- Display or change ethernet card settings
.RB [ value
.IR N ]
-.B ethtool \-k
+.B ethtool \-k|\-\-show\-offload
.I ethX
-.B ethtool \-K
+.B ethtool \-K\-\-offload
.I ethX
.B2 rx on off
.B2 tx on off
.B2 sg on off
.B2 tso on off
-.B ethtool \-p
+.B ethtool \-p|\-\-blink
.I ethX
.IR [ N ]
-.B ethtool \-r
+.B ethtool \-r|\-\-negotiate
.I ethX
-.B ethtool \-S
+.B ethtool \-S|\-\-statistics
.I ethX
-.B ethtool \-t
+.B ethtool \-t|\-\-test
.I ethX
.B1 offline online
@@ -193,13 +193,13 @@ is the name of the ethernet device to work on.
with a single argument specifying the device name prints current
setting of the specified device.
.TP
-.B \-h
+.B \-h \-\-help
shows a short help message.
.TP
-.B \-a
+.B \-a \-\-show\-pause
queries the specified ethernet device for pause parameter information.
.TP
-.B \-A
+.B \-A \-\-pause
change the pause parameters of the specified ethernet device.
.TP
.A2 autoneg on off
@@ -211,16 +211,16 @@ Specify if RX pause is enabled.
.A2 tx on off
Specify if TX pause is enabled.
.TP
-.B \-c
+.B \-c \-\-show\-coalesce
queries the specified ethernet device for coalescing information.
.TP
-.B \-C
+.B \-C \-\-coalesce
change the coalescing settings of the specified ethernet device.
.TP
-.B \-g
+.B \-g \-\-show\-ring
queries the specified ethernet device for rx/tx ring parameter information.
.TP
-.B \-G
+.B \-G \-\-set\-ring
change the rx/tx ring parameters of the specified ethernet device.
.TP
.BI rx \ N
@@ -235,29 +235,29 @@ Change number of ring entries for the Rx Jumbo ring.
.BI tx \ N
Change number of ring entries for the Tx ring.
.TP
-.B \-i
+.B \-i \-\-driver
queries the specified ethernet device for associated driver information.
.TP
-.B \-d
+.B \-d \-\-register\-dump
retrieves and prints a register dump for the specified ethernet device.
When raw is enabled, then it dumps the raw register data to stdout.
.TP
-.B \-e
+.B \-e \-\-eeprom\-dump
retrieves and prints an EEPROM dump for the specified ethernet device.
When raw is enabled, then it dumps the raw EEPROM data to stdout. The
length and offset parameters allow dumping certain portions of the EEPROM.
Default is to dump the entire EEPROM.
.TP
-.B \-E
+.B \-E \-\-change\-eeprom
Changes EEPROM byte for the specified ethernet device. offset and value
specify which byte and it's new value. Because of the persistent nature
of writing to the EEPROM, a device-specific magic key must be specified
to prevent the accidental writing to the EEPROM.
.TP
-.B \-k
+.B \-k \-\-show\-offload
queries the specified ethernet device for offload information.
.TP
-.B \-K
+.B \-K \-\-offload
change the offload parameters of the specified ethernet device.
.TP
.A2 rx on off
@@ -272,7 +272,7 @@ Specify if scatter-gather is enabled.
.A2 tso on off
Specify if tcp segmentation offload is enabled.
.TP
-.B \-p
+.B \-p \-\-identify
initiates adapter-specific action intended to enable an operator to
easily identify the adapter by sight. typically this involves
blinking one or more LEDs on the specific ethernet port.
@@ -280,15 +280,15 @@ blinking one or more LEDs on the specific ethernet port.
.B N
Length of time to perform phys-id, in seconds.
.TP
-.B \-r
+.B \-r \-\-negotiate
restarts auto-negotiation on the specified ethernet device, if
auto-negotiation is enabled.
.TP
-.B \-S
+.B \-S \-\-statistics
queries the specified ethernet device for NIC- and driver-specific
statistics.
.TP
-.B \-t
+.B \-t \-\-test
executes adapter selftest on the specified ethernet device. Possible test modes are:
.TP
.A1 offline online
@@ -298,7 +298,7 @@ defines test type:
.B online
means to perform limited set of tests do not interrupting normal adapter operation.
.TP
-.B \-s
+.B \-s \-\-change
option allows changing some or all settings of the specified ethernet device.
All following options only apply if
.B \-s
@@ -376,7 +376,8 @@ Tim Hockin,
Jakub Jelinek,
Andre Majorel,
Eli Kupermann,
-Scott Feldman.
+Scott Feldman,
+Andi Kleen.
.SH AVAILABILITY
.B ethtool
is available over the Web on the SourceForge site at
diff --git a/ethtool.c b/ethtool.c
index 77ce379..f7f89a4 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -11,6 +11,7 @@
* e1000 support by Scott Feldman <scott.feldman@intel.com>
* e100 support by Wen Tao <wen-hwa.tao@intel.com>
* amd8111e support by Reeja John <reeja.john@amd.com>
+ * long arguments by Andi Kleen.
*
* TODO:
* * no-args => summary of each device (mii-tool style)
@@ -65,152 +66,8 @@ static int do_goffload(int fd, struct ifreq *ifr);
static int do_soffload(int fd, struct ifreq *ifr);
static int do_gstats(int fd, struct ifreq *ifr);
-/* Syntax:
- *
- * ethtool DEVNAME
- * ethtool -a DEVNAME
- * ethtool -A DEVNAME \
- * [ autoneg on|off ] \
- * [ rx on|off ] \
- * [ tx on|off ]
- * ethtool -c DEVNAME
- * ethtool -C DEVNAME \
- * [adaptive-rx on|off] \
- * [adaptive-tx on|off] \
- * [rx-usecs N] \
- * [rx-frames N] \
- * [rx-usecs-irq N] \
- * [rx-frames-irq N] \
- * [tx-usecs N] \
- * [tx-frames N] \
- * [tx-usecs-irq N] \
- * [tx-frames-irq N] \
- * [stats-block-usecs N] \
- * [pkt-rate-low N] \
- * [rx-usecs-low N] \
- * [rx-frames-low N] \
- * [tx-usecs-low N] \
- * [tx-frames-low N] \
- * [pkt-rate-high N] \
- * [rx-usecs-high N] \
- * [rx-frames-high N] \
- * [tx-usecs-high N] \
- * [tx-frames-high N] \
- * [sample-interval N]
- * ethtool -g DEVNAME
- * ethtool -G DEVNAME \
- * [ rx N ] \
- * [ rx-mini N ] \
- * [ rx-jumbo N ] \
- * [ tx N ]
- * ethtool -i DEVNAME
- * ethtool -d DEVNAME [ raw on|off ]
- * ethtool -e DEVNAME \
- * [ raw on|off ] \
- * [ offset N ] \
- * [ len N ]
- * ethtool -E DEVNAME \
- * [ magic N ] \
- * [ offset N ] \
- * [ value N ] \
- * ethtool -k DEVNAME
- * ethtool -K DEVNAME \
- * [ rx on|off ] \
- * [ tx on|off ] \
- * [ sg on|off ] \
- * [ tso on|off ]
- * ethtool -r DEVNAME
- * ethtool -p DEVNAME [ %d ]
- * ethtool -t DEVNAME [ online|offline ]
- * ethtool -s DEVNAME [ speed 10|100|1000 ] \
- * [ duplex half|full ] \
- * [ port tp|aui|bnc|mii|fibre ] \
- * [ autoneg on|off ] \
- * [ phyad %d ] \
- * [ xcvr internal|external ] \
- * [ wol p|u|m|b|a|g|s|d... ] \
- * [ sopass %x:%x:%x:%x:%x:%x ] \
- * [ msglvl %d ]
- * ethtool -S DEVNAME
- */
-
-static void show_usage(int badarg)
-{
- fprintf(stderr, PACKAGE " version " VERSION "\n");
- fprintf(stderr,
- "Usage:\n"
- " ethtool DEVNAME\n"
- " ethtool -a DEVNAME\n"
- " ethtool -A DEVNAME \\\n"
- " [ autoneg on|off ] \\\n"
- " [ rx on|off ] \\\n"
- " [ tx on|off ]\n"
- " ethtool -c DEVNAME\n"
- " ethtool -C DEVNAME \\\n"
- " [adaptive-rx on|off] \\\n"
- " [adaptive-tx on|off] \\\n"
- " [rx-usecs N] \\\n"
- " [rx-frames N] \\\n"
- " [rx-usecs-irq N] \\\n"
- " [rx-frames-irq N] \\\n"
- " [tx-usecs N] \\\n"
- " [tx-frames N] \\\n"
- " [tx-usecs-irq N] \\\n"
- " [tx-frames-irq N] \\\n"
- " [stats-block-usecs N] \\\n"
- " [pkt-rate-low N] \\\n"
- " [rx-usecs-low N] \\\n"
- " [rx-frames-low N] \\\n"
- " [tx-usecs-low N] \\\n"
- " [tx-frames-low N] \\\n"
- " [pkt-rate-high N] \\\n"
- " [rx-usecs-high N] \\\n"
- " [rx-frames-high N] \\\n"
- " [tx-usecs-high N] \\\n"
- " [tx-frames-high N] \\\n"
- " [sample-interval N]\n"
- " ethtool -g DEVNAME\n"
- " ethtool -G DEVNAME \\\n"
- " [ rx N ] \\\n"
- " [ rx-mini N ] \\\n"
- " [ rx-jumbo N ] \\\n"
- " [ tx N ]\n"
- " ethtool -i DEVNAME\n"
- " ethtool -d DEVNAME [ raw on|off ]\n"
- " ethtool -e DEVNAME \\\n"
- " [ raw on|off ] \\\n"
- " [ offset N ] \\\n"
- " [ length N ]\n"
- " ethtool -E DEVNAME \\\n"
- " [ magic N ] \\\n"
- " [ offset N ] \\\n"
- " [ value N ]\n"
- " ethtool -k DEVNAME\n"
- " ethtool -K DEVNAME \\\n"
- " [ rx on|off ] \\\n"
- " [ tx on|off ] \\\n"
- " [ sg on|off ] \\\n"
- " [ tso on|off ]\n"
- " ethtool -r DEVNAME\n"
- " ethtool -p DEVNAME [ %%d ]\n"
- " ethtool -t DEVNAME [online|(offline)]\n"
- " ethtool -s DEVNAME \\\n"
- " [ speed 10|100|1000 ] \\\n"
- " [ duplex half|full ] \\\n"
- " [ port tp|aui|bnc|mii|fibre ] \\\n"
- " [ autoneg on|off ] \\\n"
- " [ phyad %%d ] \\\n"
- " [ xcvr internal|external ] \\\n"
- " [ wol p|u|m|b|a|g|s|d... ] \\\n"
- " [ sopass %%x:%%x:%%x:%%x:%%x:%%x ] \\\n"
- " [ msglvl %%d ] \n"
- " ethtool -S DEVNAME\n"
- );
- exit(badarg);
-}
-
-static char *devname = NULL;
static enum {
+ MODE_HELP = -1,
MODE_GSET=0,
MODE_SSET,
MODE_GDRV,
@@ -231,6 +88,102 @@ static enum {
MODE_GSTATS,
} mode = MODE_GSET;
+static struct option {
+ char *srt, *lng;
+ int Mode;
+ char *help;
+ char *opthelp;
+} args[] = {
+ { "-s", "--change", MODE_SSET, "Change generic options",
+ " [ speed 10|100|1000 ]\n"
+ " [ duplex half|full ]\n"
+ " [ port tp|aui|bnc|mii|fibre ]\n"
+ " [ autoneg on|off ]\n"
+ " [ phyad %%d ]\n"
+ " [ xcvr internal|external ]\n"
+ " [ wol p|u|m|b|a|g|s|d... ]\n"
+ " [ sopass %%x:%%x:%%x:%%x:%%x:%%x ]\n"
+ " [ msglvl %%d ] \n" },
+ { "-a", "--show-pause", MODE_GPAUSE, "Show pause options" },
+ { "-A", "--pause", MODE_SPAUSE, "Set pause options",
+ " [ autoneg on|off ]\n"
+ " [ rx on|off ]\n"
+ " [ tx on|off ]\n" },
+ { "-c", "--show-coalesce", MODE_GCOALESCE, "Show coalesce options" },
+ { "-C", "--coalesce", MODE_SCOALESCE, "Set coalesce options",
+ " [adaptive-rx on|off]\n"
+ " [adaptive-tx on|off]\n"
+ " [rx-usecs N]\n"
+ " [rx-frames N]\n"
+ " [rx-usecs-irq N]\n"
+ " [rx-frames-irq N]\n"
+ " [tx-usecs N]\n"
+ " [tx-frames N]\n"
+ " [tx-usecs-irq N]\n"
+ " [tx-frames-irq N]\n"
+ " [stats-block-usecs N]\n"
+ " [pkt-rate-low N]\n"
+ " [rx-usecs-low N]\n"
+ " [rx-frames-low N]\n"
+ " [tx-usecs-low N]\n"
+ " [tx-frames-low N]\n"
+ " [pkt-rate-high N]\n"
+ " [rx-usecs-high N]\n"
+ " [rx-frames-high N]\n"
+ " [tx-usecs-high N]\n"
+ " [tx-frames-high N]\n"
+ " [sample-interval N]\n" },
+ { "-g", "--show-ring", MODE_GRING, "Query RX/TX ring parameters" },
+ { "-G", "--set-ring", MODE_SRING, "Set RX/TX ring parameters",
+ " [ rx N ]\n"
+ " [ rx-mini N ]\n"
+ " [ rx-jumbo N ]\n"
+ " [ tx N ]\n" },
+ { "-k", "--show-offload", MODE_GOFFLOAD, "Get protocol offload information" },
+ { "-K", "--offload", MODE_SOFFLOAD, "Set protocol offload",
+ " [ rx on|off ]\n"
+ " [ tx on|off ]\n"
+ " [ sg on|off ]\n"
+ " [ tso on|off ]\n" },
+ { "-i", "--driver", MODE_GDRV, "Show driver information" },
+ { "-d", "--register-dump", MODE_GREGS, "Do a register dump" },
+ { "-e", "--eeprom-dump", MODE_GEEPROM, "Do a EEPROM dump",
+ " [ raw on|off ]\n"
+ " [ offset N ]\n"
+ " [ length N ]\n" },
+ { "-E", "--change-eeprom", MODE_SEEPROM, "Change bytes in device EEPROM",
+ " [ magic N ]\n"
+ " [ offset N ]\n"
+ " [ value N ]\n" },
+ { "-r", "--negotiate", MODE_NWAY_RST, "Restart N-WAY negotation" },
+ { "-p", "--identify", MODE_PHYS_ID, "Show visible port identification (e.g. blinking)",
+ " [ TIME-IN-SECONDS ]\n" },
+ { "-t", "--test", MODE_TEST, "Execute adapter self test",
+ " [ online | offline ]\n" },
+ { "-S", "--statistics", MODE_GSTATS, "Show adapter statistics" },
+ { "-h", "--help", MODE_HELP, "Show this help" },
+ {}
+};
+
+
+static void show_usage(int badarg)
+{
+ int i;
+ fprintf(stderr, PACKAGE " version " VERSION "\n");
+ fprintf(stderr,
+ "Usage:\n"
+ "ethtool DEVNAME\tDisplay standard information about device\n");
+ for (i = 0; args[i].srt; i++) {
+ fprintf(stderr, " ethtool %s|%s DEVNAME\t%s\n%s",
+ args[i].srt, args[i].lng,
+ args[i].help,
+ args[i].opthelp ? args[i].opthelp : "");
+ }
+ exit(badarg);
+}
+
+static char *devname = NULL;
+
static int goffload_changed = 0;
static int off_csum_rx_wanted = -1;
static int off_csum_tx_wanted = -1;
@@ -417,46 +370,19 @@ static void parse_generic_cmdline(int argc, char **argp,
static void parse_cmdline(int argc, char **argp)
{
- int i;
+ int i, k;
for (i = 1; i < argc; i++) {
switch (i) {
case 1:
- if (!strcmp(argp[i], "-s"))
- mode = MODE_SSET;
- else if (!strcmp(argp[i], "-a"))
- mode = MODE_GPAUSE;
- else if (!strcmp(argp[i], "-A"))
- mode = MODE_SPAUSE;
- else if (!strcmp(argp[i], "-c"))
- mode = MODE_GCOALESCE;
- else if (!strcmp(argp[i], "-C"))
- mode = MODE_SCOALESCE;
- else if (!strcmp(argp[i], "-g"))
- mode = MODE_GRING;
- else if (!strcmp(argp[i], "-G"))
- mode = MODE_SRING;
- else if (!strcmp(argp[i], "-k"))
- mode = MODE_GOFFLOAD;
- else if (!strcmp(argp[i], "-K"))
- mode = MODE_SOFFLOAD;
- else if (!strcmp(argp[i], "-i"))
- mode = MODE_GDRV;
- else if (!strcmp(argp[i], "-d"))
- mode = MODE_GREGS;
- else if (!strcmp(argp[i], "-e"))
- mode = MODE_GEEPROM;
- else if (!strcmp(argp[i], "-E"))
- mode = MODE_SEEPROM;
- else if (!strcmp(argp[i], "-r"))
- mode = MODE_NWAY_RST;
- else if (!strcmp(argp[i], "-p"))
- mode = MODE_PHYS_ID;
- else if (!strcmp(argp[i], "-t"))
- mode = MODE_TEST;
- else if (!strcmp(argp[i], "-S"))
- mode = MODE_GSTATS;
- else if (!strcmp(argp[i], "-h"))
+ for (k = 0; args[k].srt; k++)
+ if (!strcmp(argp[i], args[k].srt) ||
+ !strcmp(argp[i], args[k].lng)) {
+ mode = args[k].Mode;
+ break;
+ }
+ if (mode == MODE_HELP ||
+ (!args[k].srt && argp[i][0] == '-'))
show_usage(0);
else
devname = argp[i];