summaryrefslogtreecommitdiffstats
path: root/patches/mii-diag-2.09.orig/generic/01-mii-diag-2.09.orig.patch
blob: 707d1cc37bfc1b3a61bb36db799cfa32ce61d14d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
diff -urN mii-diag-2.09.orig/Makefile mii-diag-2.09.ptx/Makefile
--- mii-diag-2.09.orig/Makefile	1970-01-01 01:00:00.000000000 +0100
+++ mii-diag-2.09.ptx/Makefile	2005-03-03 13:12:50.000000000 +0100
@@ -0,0 +1,20 @@
+CFLAGS?= -O -Wall
+CC?=gcc
+INSTALL?=install
+
+LIBS=libmii.o
+
+all: mii-diag
+
+mii-diag:
+	$(CC) $(CFLAGS) -Wstrict-prototypes -O mii-diag.c -DLIBMII \
+	libmii.c -o mii-diag
+
+clean:
+	rm -f *.o mii-diag mii-diag-udeb *~
+
+install-mii-diag:
+	mkdir -p $(DESTDIR)/usr/sbin
+	$(INSTALL) mii-diag $(DESTDIR)/usr/sbin
+
+install: all install-mii-diag
diff -urN mii-diag-2.09.orig/README mii-diag-2.09.ptx/README
--- mii-diag-2.09.orig/README	1970-01-01 01:00:00.000000000 +0100
+++ mii-diag-2.09.ptx/README	2005-03-03 13:14:06.000000000 +0100
@@ -0,0 +1,7 @@
+This package comes from ftp://ftp.scyld.com/pub/diag/. Compared to the original
+it has two additional options:
+
+-d         lets you power down the phy
+-i REG,VAL lets you write a phy register directly
+
+20050303 Sascha Hauer
diff -urN mii-diag-2.09.orig/mii-diag.c mii-diag-2.09.ptx/mii-diag.c
--- mii-diag-2.09.orig/mii-diag.c	2004-05-03 21:42:12.000000000 +0200
+++ mii-diag-2.09.ptx/mii-diag.c	2005-03-03 13:15:01.000000000 +0100
@@ -37,7 +37,7 @@
 static const char usage_msg[] =
 "Usage: %s [--help] [-aDfrRvVw] [-AF <speed+duplex>] [--watch] <interface>.\n";
 static const char long_usage_msg[] =
-"Usage: %s [-aDfrRvVw] [-AF <speed+duplex>] [--watch] <interface>.\n"
+"Usage: %s [-aDfrRvVw] [-AF <speed+duplex>] [--watch] <interface>."
 "\n"
 "  This program configures and monitors the transceiver management registers\n"
 "  for network interfaces.  It uses the Media Independent Interface (MII)\n"
@@ -56,26 +56,29 @@
 "   -F  --fixed-speed <speed>\n"
 "	Speed is one of: 100baseT4, 100baseTx, 100baseTx-FD, 100baseTx-HD,\n"
 "	                 10baseT, 10baseT-FD, 10baseT-HD\n"
-"   -s  --status     Return exit status 2 if there is no link beat.\n"
+"   -s  --status                Return exit status 2 if there is no link beat.\n"
 "\n"
 " Less frequently used options are\n"
-"   -a  --all-interfaces  Show the status all interfaces\n"
+"   -a  --all-interfaces        Show the status all interfaces\n"
 "              (Not recommended with options that change settings.)\n"
 "   -D  --debug\n"
-"   -g  --read-parameters 	Get driver-specific parameters.\n"
-"   -G  --set-parameters PARMS	Set driver-specific parameters.\n"
+"   -g  --read-parameters       Get driver-specific parameters.\n"
+"   -G  --set-parameters PARMS  Set driver-specific parameters.\n"
 "       Parameters are comma separated, missing elements retain existing value.\n"
-"   -M  --msg-level LEVEL 	Set the driver message bit map.\n"
-"   -p  --phy ADDR		Set the PHY (MII address) to report.\n"
-"   -r  --restart	Restart the link autonegotiation.\n"
-"   -R  --reset		Reset the transceiver.\n"
-"   -v  --verbose	Report each action taken.\n"
-"   -V  --version	Emit version information.\n"
-"   -w  --watch		Continuously monitor the transceiver and report changes.\n"
+"   -M  --msg-level LEVEL       Set the driver message bit map.\n"
+"   -p  --phy ADDR              Set the PHY (MII address) to report.\n"
+"   -r  --restart               Restart the link autonegotiation.\n"
+"   -R  --reset                 Reset the transceiver.\n"
+"   -v  --verbose               Report each action taken.\n"
+"   -V  --version               Emit version information.\n"
+"   -w  --watch                 Continuously monitor the transceiver and report changes.\n"
+"   -d  --pwdown                Power down the phy\n"
+"   -i  --writereg REG,VAL      write VAL to phy register REG\n"
 "\n"
 "   This command returns success (zero) if the interface information can be\n"
 "   read.  If the --status option is passed, a zero return means that the\n"
-"   interface has link beat.\n";
+"   interface has link beat.\n"
+"\n";
 
 #include <unistd.h>
 #include <stdlib.h>
@@ -104,12 +107,12 @@
 #define SIOCSPARAMS (SIOCDEVPRIVATE+4) 		/* Set operational parameters. */
 #endif
 
-const char shortopts[] = "aA:C:DfF:gG:hmM:p:rRsvVw?";
+const char shortopts[] = "aA:C:DfF:gG:hmM:p:rRsvVw?di:";
 struct option longopts[] = {
  /* { name  has_arg  *flag  val } */
     {"all-interfaces", 0, 0, 'a'},	/* Show all interfaces. */
-	{"advertise",	1, 0, 'A'},		/* Change the capabilities advertised. */
-	{"BMCR",		1, 0, 'C'},		/* Set the control register. */
+    {"advertise",	1, 0, 'A'},		/* Change the capabilities advertised. */
+    {"BMCR",		1, 0, 'C'},		/* Set the control register. */
     {"debug",       0, 0, 'D'},		/* Increase the debug level. */
     {"force",       0, 0, 'f'},		/* Force the operation. */
     {"fixed-speed", 1, 0, 'F'},		/* Fixed speed name. */
@@ -126,13 +129,11 @@
     {"version", 	0, 0, 'V'},		/* Emit version information.  */
     {"watch", 		0, 0, 'w'},		/* Constantly monitor the port.  */
     {"error", 		0, 0, '?'},		/* Return the error message. */
+    {"pwdown",		0, 0, 'd'},		/* Power down the phy */
+    {"writereg",	1, 0, 'i'},		/* write value to reg */
     { 0, 0, 0, 0 }
 };
 
-/* Usually in libmii.c, but trivial substitions are below. */
-extern int  show_mii_details(long ioaddr, int phy_id);
-extern void monitor_mii(long ioaddr, int phy_id);
-
 /* Command-line flags. */
 unsigned int opt_a = 0,					/* Show-all-interfaces flag. */
 	opt_f = 0,					/* Force the operation. */
@@ -144,13 +145,18 @@
 	opt_restart = 0,
 	opt_reset = 0,
 	opt_status = 0,
-	opt_watch = 0;
+	opt_watch = 0,
+	opt_pwdown = 0,
+	opt_writereg = 0;
+
 static int msg_level = -1;
 static int set_BMCR = -1;
 static int nway_advertise = 0;
 static int fixed_speed = -1;
 static int override_phy = -1;
 char *opt_G_string = NULL;
+unsigned long wr_reg = -1;
+unsigned long wr_val = -1;
 
 /* Internal values. */
 int new_ioctl_nums;
@@ -170,6 +176,7 @@
 {
 	int c, errflag = 0;
 	char **spp, *ifname;
+	char *endp;
     char *progname = rindex(argv[0], '/') ? rindex(argv[0], '/')+1 : argv[0];
 
 	while ((c = getopt_long(argc, argv, shortopts, longopts, 0)) != EOF)
@@ -197,6 +204,11 @@
 		case 'V': opt_version++;	break;
 		case 'w': opt_watch++;		break;
 		case '?': errflag++;		break;
+		case 'd': opt_pwdown++;		break;
+		case 'i': opt_writereg++;
+			wr_reg = strtoul(optarg,&endp,0);
+			wr_val = strtoul(endp+1,NULL,0);
+			break;
 		}
 	if (errflag) {
 		fprintf(stderr, usage_msg, progname);
@@ -340,6 +352,17 @@
 		printf("Resetting the transceiver...\n");
 		mdio_write(skfd, phy_id, 0, 0x8000);
 	}
+	
+	if (opt_pwdown) {
+		printf("shutting the phy down...\n");
+		mdio_write(skfd, phy_id, 0, 1<<11);
+	}
+	
+	if (opt_writereg) {
+		printf("writing value 0x%04x to reg 0x%02x\n",wr_val,wr_reg);
+		mdio_write(skfd, phy_id, wr_reg, wr_val);
+	}
+
 	/* Note: PHY addresses > 32 are pseudo-MII devices, usually built-in. */
 	if (phy_id < 64  &&  nway_advertise > 0) {
 		printf(" Setting the media capability advertisement register of "