nictools-pci (1.3.8-1.2) myson-diag.c

Summary

 myson-diag.c |  117 +++++++++++++++++++++++++++++++----------------------------
 1 file changed, 62 insertions(+), 55 deletions(-)

    
download this patch

Patch contents

--- nictools-pci-1.3.8.orig/myson-diag.c
+++ nictools-pci-1.3.8/myson-diag.c
@@ -14,7 +14,7 @@
 
 	The author may be reached as becker@scyld.com, or C/O
 	 Scyld Computing Corporation
-	 410 Severn Ave., Suite 210
+	 914 Bay Ridge Road, Suite 220
 	 Annapolis MD 21403
 
 	Support and updates available at
@@ -28,44 +28,45 @@
 */
 
 static char *version_msg =
-"myson-diag.c:v1.07 8/07/2002 Donald Becker (becker@scyld.com)\n"
+"myson-diag.c:v1.08 2/28/2005 Donald Becker (becker@scyld.com)\n"
 " http://www.scyld.com/diag/index.html\n";
 static char *usage_msg =
 "Usage: myson-diag [-aEefFGhmqrRtvVwW] [-p <IOport>] [-[AF] <media>]\n"
 "  For details and other options see http://www.scyld.com/diag/index.html\n";
 
 static const char long_usage_msg[] =
-"Usage: %s [-aDfrRvVw] [-AF <speed+duplex>] [-#<BoardNum>]\n"
-"\n"
-"   Show the internal state of a network adapter.\n"
-"\n"
-"   The common usage is\n"
-"      myson-diag -aem\n"
-"\n"
-" Frequently used options are\n"
-"   -a  --show_all_registers	Print all registers.\n"
-"   -e  --show-eeprom	Dump EEPROM contents, \"-ee\" shows the details.\n"
-"   -m  --show_mii		Print the MII transceiver state\n"
-"					Using -mm monitors the link.\n"
-"   -f  --force		Perform operation, even on a running NIC.\n"
-"\n"
-" To operate on a single NIC, or one that hasn't been automatically found:\n"
-"   -#  --card_num	INDEX	Operate on the specified card index.\n"
-"   -p  --port-base	IOADDR	Assume an adapter at the specified I/O address.\n"
-"   -t  --chip-type	TYPE	Specify adapter type with '-p', use '-1' to list.\n"
-"\n"
-" To change the persistent EEPROM settings\n"
-"   -G  --parameters PARMS	Set adapter-specific parameters.\n"
-"   -H  --new-hwaddr 01:23:45:67:ab:cd\n"
-"			Set a new hardware station address.  Typically diabled, \n"
-"   -w  --write-EEPROM	 Actually write the new settings into the EEPROM.\n"
-"\n"
-"   -D  --debug\n"
-"   -v  --verbose	Report each action taken.\n"
-"   -V  --version	Emit version information.\n"
-"\n"
-"   -A  --advertise <speed|setting>  (See the mii-diag manual page.)\n"
-"\n";
+"Usage: %s [-aDfrRvVw] [-AF <speed+duplex>] [-#<BoardNum>]\n\
+\n\
+   Show the internal state of a network adapter.\n\
+\n\
+   The common usage is\n\
+      myson-diag -aem\n\
+\n\
+ Frequently used options are\n\
+   -a  --show_all_registers	Print all registers.\n\
+   -e  --show-eeprom	Dump EEPROM contents, \"-ee\" shows the details.\n\
+   -m  --show_mii		Print the MII transceiver state\n\
+					Using -mm monitors the link.\n\
+   -f  --force		Perform operation, even on a running NIC.\n\
+\n\
+ To operate on a single NIC, or one that hasn't been automatically found:\n\
+   -#  --card_num	INDEX	Operate on the specified card index.\n\
+   -p  --port-base	IOADDR	Assume an adapter at the specified I/O address.\n\
+   -t  --chip-type	TYPE	Specify adapter type (with '-p').  Use '-1' to\n\
+                            list available types indicies.\n\
+\n\
+ To change the persistent EEPROM settings\n\
+   -G  --parameters PARMS	Set adapter-specific parameters.\n\
+   -H  --new-hwaddr 01:23:45:67:89:ab\n\
+        Set a new hardware station address.  Typically disabled for safety.\n\
+   -w  --write-EEPROM	 Actually write the new settings into the EEPROM.\n\
+\n\
+   -D  --debug\n\
+   -v  --verbose	Report each action taken.\n\
+   -V  --version	Emit version information.\n\
+\n\
+   -A  --advertise <speed|setting>  (See the mii-diag manual page.)\n\
+\n";
 
 #if ! defined(__OPTIMIZE__)
 #warning  You must compile this program with the correct options!
@@ -82,7 +83,7 @@
 
 /* The following are required only with unaligned field accesses. */
 #include <asm/types.h>
-#include <asm/unaligned.h>
+#include "unaligned.h"
 
 #if defined(__linux__)  &&  __GNU_LIBRARY__ == 1
 #include <asm/io.h>			/* Newer libraries use <sys/io.h> instead. */
@@ -101,9 +102,9 @@
 extern void (*flash_out_hook)(long addr, int offset, int val);
 
 /* We should use __u8 .. __u32, but they are not always defined. */
-typedef unsigned int u32;
-typedef unsigned short u16;
-typedef unsigned char u8;
+typedef u_int32_t u32;
+typedef u_int16_t u16;
+typedef u_int8_t u8;
 
 struct option longopts[] = {
  /* { name  has_arg  *flag  val } */
@@ -137,7 +138,7 @@
 
 /* The table of known chips.
    Because of the bogus /proc/pci interface we must have both the exact
-   name and a PCI vendor/device IDs.
+   name from the kernel, a common name and the PCI vendor/device IDs.
    This table is searched in order: place specific entries followed by
    'catch-all' general entries. */
 struct pcidev_entry {
@@ -437,6 +438,7 @@
 		"100baseT4", "100baseTx", "100baseTx-FD", "100baseTx-HD",
 		"10baseT", "10baseT-FD", "10baseT-HD", 0,
 	};
+	char *endptr;
 	int cap_map[] = { 0x0200, 0x0180, 0x0100, 0x0080, 0x0060, 0x0040, 0x0020,};
 	int i;
 	if (debug)
@@ -444,7 +446,8 @@
 	for (i = 0; mtypes[i]; i++)
 		if (strcasecmp(mtypes[i], capabilities) == 0)
 			return cap_map[i];
-	if ((i = strtoul(capabilities, NULL, 16)) <= 0xffff)
+	i = strtoul(capabilities, &endptr, 16);
+	if (*endptr == 0  &&  0 < i  &&  i <= 0xffff)
 		return i;
 	fprintf(stderr, "Invalid media advertisement '%s'.\n", capabilities);
 	return 0;
@@ -475,16 +478,20 @@
 
 static int get_media_index(const char *name)
 {
+	char *endptr;
 	int i;
+
+	if (! name)
+		return -1;
 	for (i = 0; mediamap[i].name; i++)
 		if (strcasecmp(name, mediamap[i].name) == 0)
 			return i;
-	if (name  &&  atoi(name) >= 00)
-		return atoi(name);
-	fprintf(stderr, "Invalid interface specified: it must be one of\n  ");
+	i = strtol(name, &endptr, 0);
+	if (*endptr == 0)
+		return i;
+	fprintf(stderr, "Invalid interface specified.  It must be one of\n");
 	for (i = 0; mediamap[i].name; i++)
-		fprintf(stderr, "  %s", mediamap[i].name);
-	fprintf(stderr, ".\n");
+		fprintf(stderr, "  %d %s\n", mediamap[i].value, mediamap[i].name);
 	return -1;
 }
 
@@ -825,17 +832,17 @@
 }
 
 
-static char davicom_msg[] = "\n"
-"  Your EEPROM has been misprogrammed from the factory!\n"
-"\n"
-"  It contains the EEPROM programming for a Davicom 9102 chip, not the\n"
-"  configuration for the Myson 800 series part.\n"
-"  This results incorrect operation, and no Wake-On-LAN feature.\n"
-"  Contact your vendor for a fix or replacement board.\n"
-"\n"
-"  You may, at your own risk, attempt to use the '-E' Emergency rewrite\n"
-"  option to correct the EEPROM contents.\n"
-"\n";
+static char davicom_msg[] = "\n\
+  Your EEPROM has been misprogrammed from the factory!\n\
+\n\
+  It contains the EEPROM programming for a Davicom 9102 chip, not the\n\
+  configuration for the Myson 800 series part.\n\
+  This results incorrect operation, and no Wake-On-LAN feature.\n\
+  Contact your vendor for a fix or replacement board.\n\
+\n\
+  You may, at your own risk, attempt to use the '-E' Emergency rewrite\n\
+  option to correct the EEPROM contents.\n\
+";
 
 static void myson_eeprom(unsigned short *ee_data)
 {