public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@osdl.org>
To: Jeff Garzik <jgarzik@pobox.com>
Cc: netdev@vger.kernel.org
Subject: [PATCH 3/3] ethtool: dump_registers post mortem
Date: Wed, 18 Oct 2006 10:50:22 -0700	[thread overview]
Message-ID: <20061018105022.57b57b6a@freekitty> (raw)
In-Reply-To: <20061018104632.27a37d75@freekitty>

This patch allows:
	ethtool -d eth0 raw on >saved_regs
and later
	ethtool -d eth0 file saved_regs

Selfish motive is to be able to take register dumps from users and
and decode later, possibly adding more output as needed.

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
---
 ethtool.c |   39 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/ethtool.c b/ethtool.c
index b783248..7861990 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -29,7 +29,9 @@ #endif
 #include <sys/types.h>
 #include <string.h>
 #include <stdlib.h>
+#include <sys/types.h>
 #include <sys/ioctl.h>
+#include <sys/stat.h>
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
@@ -251,6 +253,7 @@ static int msglvl_wanted = -1;
 static int phys_id_time = 0;
 static int gregs_changed = 0;
 static int gregs_dump_raw = 0;
+static char *gregs_dump_file = NULL;
 static int geeprom_changed = 0;
 static int geeprom_dump_raw = 0;
 static int geeprom_offset = 0;
@@ -268,6 +271,7 @@ typedef enum {
 	CMDL_NONE,
 	CMDL_BOOL,
 	CMDL_INT,
+	CMDL_STR,
 } cmdline_type_t;
 
 struct cmdline_info {
@@ -279,6 +283,7 @@ struct cmdline_info {
 
 static struct cmdline_info cmdline_gregs[] = {
 	{ "raw", CMDL_BOOL, &gregs_dump_raw, NULL },
+	{ "file", CMDL_STR, &gregs_dump_file, NULL },
 };
 
 static struct cmdline_info cmdline_geeprom[] = {
@@ -355,20 +360,28 @@ static void parse_generic_cmdline(int ar
 				if (i >= argc)
 					show_usage(1);
 				p = info[idx].wanted_val;
-				if (info[idx].type == CMDL_BOOL) {
+				switch (info[idx].type) {
+				case CMDL_BOOL:
 					if (!strcmp(argp[i], "on"))
 						*p = 1;
 					else if (!strcmp(argp[i], "off"))
 						*p = 0;
 					else
 						show_usage(1);
-				} else if (info[idx].type == CMDL_INT) {
-					long v;
-					v = strtol(argp[i], NULL, 0);
+					break;
+				case CMDL_INT: {
+					long v = strtol(argp[i], NULL, 0);
 					if (v < 0)
 						show_usage(1);
 					*p = (int) v;
-				} else {
+					break;
+				}
+				case CMDL_STR: {
+					char **s = info[idx].wanted_val;
+					*s = strdup(argp[i]);
+					break;
+				}
+				default:
 					show_usage(1);
 				}
 			}
@@ -969,6 +982,22 @@ static int dump_regs(struct ethtool_drvi
 		return 0;
 	}
 
+	if (gregs_dump_file) {
+		FILE *f = fopen(gregs_dump_file, "r");
+		struct stat st;
+
+		if (!f || fstat(fileno(f), &st) < 0) {
+			fprintf(stderr, "Can't open '%s': %s\n",
+				gregs_dump_file, strerror(errno));
+			return -1;
+		}
+		
+		regs = realloc(regs, sizeof(*regs) + st.st_size);
+		regs->len = st.st_size;
+		fread(regs->data, regs->len, 1, f);
+		fclose(f);
+	}
+
 	for (i = 0; i < ARRAY_SIZE(driver_list); i++)
 		if (!strncmp(driver_list[i].name, info->driver,
 			     ETHTOOL_BUSINFO_LEN))
-- 
1.4.1


  parent reply	other threads:[~2006-10-18 17:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-18 17:46 [PATCH 1/3] ethtool: sky2 GMAC decode Stephen Hemminger
2006-10-18 17:47 ` [PATCH 2/3] ethtool: sky2 more decode Stephen Hemminger
2006-10-18 17:50 ` Stephen Hemminger [this message]
2006-10-19 21:53   ` [PATCH] ethtool: more sky2 decode Stephen Hemminger
2006-10-21 18:15   ` [PATCH 3/3] ethtool: dump_registers post mortem Jeff Garzik
2006-10-23 17:51     ` [PATCH 1/3] ethtool: marvell register dump Stephen Hemminger
2006-10-23 17:57       ` [PATCH 2/3] ethtool: flie option to " Stephen Hemminger
2006-10-24  9:50         ` Ingo Oeser
2006-10-23 20:06           ` Stephen Hemminger
2007-02-09 21:29         ` Jeff Garzik
2006-10-23 17:58       ` [PATCH 3/3] ethtool: allow force hex in " Stephen Hemminger
2006-11-07  9:34       ` [PATCH 1/3] ethtool: marvell " Jeff Garzik

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=20061018105022.57b57b6a@freekitty \
    --to=shemminger@osdl.org \
    --cc=jgarzik@pobox.com \
    --cc=netdev@vger.kernel.org \
    /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