* ethtool: add support for block writing of EEPROMs
@ 2008-06-18 17:38 Mandeep Singh Baines
2008-10-04 18:48 ` Mandeep Baines
0 siblings, 1 reply; 2+ messages in thread
From: Mandeep Singh Baines @ 2008-06-18 17:38 UTC (permalink / raw)
To: jeff, netdev; +Cc: nil, thockin
EEPROM write only supports byte writing. Add support for writing
an arbitrary number of bytes at an arbitrary offset.
Signed-off-by: Mandeep Singh Baines <msb@google.com>
---
ethtool.8 | 12 ++++++++----
ethtool.c | 58 ++++++++++++++++++++++++++++++++++++++++++++--------------
2 files changed, 52 insertions(+), 18 deletions(-)
diff --git a/ethtool.8 b/ethtool.8
index cc6a46e..90d160a 100644
--- a/ethtool.8
+++ b/ethtool.8
@@ -144,6 +144,8 @@ ethtool \- Display or change ethernet card settings
.IR N ]
.RB [ offset
.IR N ]
+.RB [ length
+.IR N ]
.RB [ value
.IR N ]
@@ -265,10 +267,12 @@ length and offset parameters allow dumping certain portions of the EEPROM.
Default is to dump the entire EEPROM.
.TP
.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.
+If value is specified, changes EEPROM byte for the specified ethernet device.
+offset and value specify which byte and it's new value. If value is not
+specified, stdin is read and written to the EEPROM. The length and offset
+parameters allow writing to certain portions of the EEPROM.
+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 \-\-show\-offload
Queries the specified ethernet device for offload information.
diff --git a/ethtool.c b/ethtool.c
index a668b49..3fce21c 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -163,6 +163,7 @@ static struct option {
{ "-E", "--change-eeprom", MODE_SEEPROM, "Change bytes in device EEPROM",
" [ magic N ]\n"
" [ offset N ]\n"
+ " [ length 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)",
@@ -264,8 +265,9 @@ static int geeprom_offset = 0;
static int geeprom_length = -1;
static int seeprom_changed = 0;
static int seeprom_magic = 0;
-static int seeprom_offset = -1;
-static int seeprom_value = 0;
+static int seeprom_length = -1;
+static int seeprom_offset = 0;
+static int seeprom_value = EOF;
static enum {
ONLINE=0,
OFFLINE,
@@ -300,6 +302,7 @@ static struct cmdline_info cmdline_geeprom[] = {
static struct cmdline_info cmdline_seeprom[] = {
{ "magic", CMDL_INT, &seeprom_magic, NULL },
{ "offset", CMDL_INT, &seeprom_offset, NULL },
+ { "length", CMDL_INT, &seeprom_length, NULL },
{ "value", CMDL_INT, &seeprom_value, NULL },
};
@@ -1920,22 +1923,49 @@ static int do_geeprom(int fd, struct ifreq *ifr)
static int do_seeprom(int fd, struct ifreq *ifr)
{
int err;
- struct {
- struct ethtool_eeprom eeprom;
- u8 data;
- } edata;
-
- edata.eeprom.cmd = ETHTOOL_SEEPROM;
- edata.eeprom.len = 1;
- edata.eeprom.offset = seeprom_offset;
- edata.eeprom.magic = seeprom_magic;
- edata.data = seeprom_value;
- ifr->ifr_data = (caddr_t)&edata.eeprom;
+ struct ethtool_drvinfo drvinfo;
+ struct ethtool_eeprom *eeprom;
+
+ drvinfo.cmd = ETHTOOL_GDRVINFO;
+ ifr->ifr_data = (caddr_t)&drvinfo;
+ err = ioctl(fd, SIOCETHTOOL, ifr);
+ if (err < 0) {
+ perror("Cannot get driver information");
+ return 74;
+ }
+
+ if (seeprom_value != EOF)
+ seeprom_length = 1;
+
+ if (seeprom_length <= 0)
+ seeprom_length = drvinfo.eedump_len;
+
+ if (drvinfo.eedump_len < seeprom_offset + seeprom_length)
+ seeprom_length = drvinfo.eedump_len - seeprom_offset;
+
+ eeprom = calloc(1, sizeof(*eeprom)+seeprom_length);
+ if (!eeprom) {
+ perror("Cannot allocate memory for EEPROM data");
+ return 75;
+ }
+
+ eeprom->cmd = ETHTOOL_SEEPROM;
+ eeprom->len = seeprom_length;
+ eeprom->offset = seeprom_offset;
+ eeprom->magic = seeprom_magic;
+ eeprom->data[0] = seeprom_value;
+
+ /* Multi-byte write: read input from stdin */
+ if (seeprom_value == EOF)
+ eeprom->len = fread(eeprom->data, 1, eeprom->len, stdin);
+
+ ifr->ifr_data = (caddr_t)eeprom;
err = ioctl(fd, SIOCETHTOOL, ifr);
if (err < 0) {
perror("Cannot set EEPROM data");
- return 87;
+ err = 87;
}
+ free(eeprom);
return err;
}
--
1.5.2.5
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: ethtool: add support for block writing of EEPROMs
2008-06-18 17:38 ethtool: add support for block writing of EEPROMs Mandeep Singh Baines
@ 2008-10-04 18:48 ` Mandeep Baines
0 siblings, 0 replies; 2+ messages in thread
From: Mandeep Baines @ 2008-10-04 18:48 UTC (permalink / raw)
To: jeff, netdev, davem; +Cc: nil, thockin
Hi Jeff,
Just wanted to know if this was in your queue.
http://marc.info/?l=linux-netdev&m=121381113108841
Could be used for restoring e1000es.
You could back up the EEPROM of a good NIC:
ethtool -e eth0 > eth0.eeprom
And then restore it on a bad NIC:
ethtool -E eth0 < eth0.eeprom
Then fix up the MAC address.
Regards,
Mandeep
On Wed, Jun 18, 2008 at 10:38 AM, Mandeep Singh Baines <msb@google.com> wrote:
> EEPROM write only supports byte writing. Add support for writing
> an arbitrary number of bytes at an arbitrary offset.
>
> Signed-off-by: Mandeep Singh Baines <msb@google.com>
> ---
> ethtool.8 | 12 ++++++++----
> ethtool.c | 58 ++++++++++++++++++++++++++++++++++++++++++++--------------
> 2 files changed, 52 insertions(+), 18 deletions(-)
>
> diff --git a/ethtool.8 b/ethtool.8
> index cc6a46e..90d160a 100644
> --- a/ethtool.8
> +++ b/ethtool.8
> @@ -144,6 +144,8 @@ ethtool \- Display or change ethernet card settings
> .IR N ]
> .RB [ offset
> .IR N ]
> +.RB [ length
> +.IR N ]
> .RB [ value
> .IR N ]
>
> @@ -265,10 +267,12 @@ length and offset parameters allow dumping certain portions of the EEPROM.
> Default is to dump the entire EEPROM.
> .TP
> .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.
> +If value is specified, changes EEPROM byte for the specified ethernet device.
> +offset and value specify which byte and it's new value. If value is not
> +specified, stdin is read and written to the EEPROM. The length and offset
> +parameters allow writing to certain portions of the EEPROM.
> +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 \-\-show\-offload
> Queries the specified ethernet device for offload information.
> diff --git a/ethtool.c b/ethtool.c
> index a668b49..3fce21c 100644
> --- a/ethtool.c
> +++ b/ethtool.c
> @@ -163,6 +163,7 @@ static struct option {
> { "-E", "--change-eeprom", MODE_SEEPROM, "Change bytes in device EEPROM",
> " [ magic N ]\n"
> " [ offset N ]\n"
> + " [ length 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)",
> @@ -264,8 +265,9 @@ static int geeprom_offset = 0;
> static int geeprom_length = -1;
> static int seeprom_changed = 0;
> static int seeprom_magic = 0;
> -static int seeprom_offset = -1;
> -static int seeprom_value = 0;
> +static int seeprom_length = -1;
> +static int seeprom_offset = 0;
> +static int seeprom_value = EOF;
> static enum {
> ONLINE=0,
> OFFLINE,
> @@ -300,6 +302,7 @@ static struct cmdline_info cmdline_geeprom[] = {
> static struct cmdline_info cmdline_seeprom[] = {
> { "magic", CMDL_INT, &seeprom_magic, NULL },
> { "offset", CMDL_INT, &seeprom_offset, NULL },
> + { "length", CMDL_INT, &seeprom_length, NULL },
> { "value", CMDL_INT, &seeprom_value, NULL },
> };
>
> @@ -1920,22 +1923,49 @@ static int do_geeprom(int fd, struct ifreq *ifr)
> static int do_seeprom(int fd, struct ifreq *ifr)
> {
> int err;
> - struct {
> - struct ethtool_eeprom eeprom;
> - u8 data;
> - } edata;
> -
> - edata.eeprom.cmd = ETHTOOL_SEEPROM;
> - edata.eeprom.len = 1;
> - edata.eeprom.offset = seeprom_offset;
> - edata.eeprom.magic = seeprom_magic;
> - edata.data = seeprom_value;
> - ifr->ifr_data = (caddr_t)&edata.eeprom;
> + struct ethtool_drvinfo drvinfo;
> + struct ethtool_eeprom *eeprom;
> +
> + drvinfo.cmd = ETHTOOL_GDRVINFO;
> + ifr->ifr_data = (caddr_t)&drvinfo;
> + err = ioctl(fd, SIOCETHTOOL, ifr);
> + if (err < 0) {
> + perror("Cannot get driver information");
> + return 74;
> + }
> +
> + if (seeprom_value != EOF)
> + seeprom_length = 1;
> +
> + if (seeprom_length <= 0)
> + seeprom_length = drvinfo.eedump_len;
> +
> + if (drvinfo.eedump_len < seeprom_offset + seeprom_length)
> + seeprom_length = drvinfo.eedump_len - seeprom_offset;
> +
> + eeprom = calloc(1, sizeof(*eeprom)+seeprom_length);
> + if (!eeprom) {
> + perror("Cannot allocate memory for EEPROM data");
> + return 75;
> + }
> +
> + eeprom->cmd = ETHTOOL_SEEPROM;
> + eeprom->len = seeprom_length;
> + eeprom->offset = seeprom_offset;
> + eeprom->magic = seeprom_magic;
> + eeprom->data[0] = seeprom_value;
> +
> + /* Multi-byte write: read input from stdin */
> + if (seeprom_value == EOF)
> + eeprom->len = fread(eeprom->data, 1, eeprom->len, stdin);
> +
> + ifr->ifr_data = (caddr_t)eeprom;
> err = ioctl(fd, SIOCETHTOOL, ifr);
> if (err < 0) {
> perror("Cannot set EEPROM data");
> - return 87;
> + err = 87;
> }
> + free(eeprom);
>
> return err;
> }
> --
> 1.5.2.5
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-10-04 18:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-18 17:38 ethtool: add support for block writing of EEPROMs Mandeep Singh Baines
2008-10-04 18:48 ` Mandeep Baines
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).