1
Sync with upstream CVS, complete log:
3
Revision 1.9 - Wed Sep 27 20:59:18 2006 UTC by ecki
5
GigE Support by Stephen Hemminger from
6
http://developer.osdl.org/shemminger/prototypes/mii-tool.tar.bz2
7
with verbose register patch from Dean Gaudet
9
Revision 1.8 - Thu Jun 3 22:18:26 2004 UTC by ecki
11
added linebreak to version signature
13
Revision 1.7 - Mon Oct 20 22:22:22 2003 UTC by ecki
14
make sure version string is helpful
16
Revision 1.6 - Mon Oct 20 22:01:13 2003 UTC by ecki
17
patch to recognize more hardware without MII support (from Redhat Bug#77882,
18
notified by Tilmann Bubeck).
20
Revision 1.5 - Sat Jun 28 03:19:04 2003 UTC by ecki
21
Use new style MII ioctls only. This will give you a warning, if compiled
22
with old kernel source tree. It will also not work if compiled with
23
new source on old kernels. The new ioctls also require root for reading, the
24
old didnt. This fixes Debian bug #133648. No fallback compatibility
25
is included for reasons of cleaner source.
27
Revision 1.4 - Wed May 28 19:41:16 2003 UTC by ecki
28
make it compile on stricter gcc3.3
30
Revision 1.3 - Sun Sep 15 00:25:14 2002 UTC by ecki
31
Implemented the Sean Reifenschneider suggested fflush() to the --watch
34
Revision 1.2 - Fri Jun 14 01:08:20 2002 UTC by ecki
35
this fixes segfault on -A "" and -F "" in mii-tool reported in debian
38
Index: net-tools/mii-tool.c
39
===================================================================
40
--- net-tools.orig/mii-tool.c
41
+++ net-tools/mii-tool.c
43
http://www.national.com/pf/DP/DP83840.html
46
-static char version[] =
47
-"mii-tool.c 1.9 2000/04/28 00:56:08 (David Hinds)\n";
48
+static char Version[] = "$Id: mii-tool.c,v 1.9 2006/09/27 20:59:18 ecki Exp $\n(Author: David Hinds based on Donald Becker's mii-diag)";
52
@@ -46,16 +45,19 @@ static char version[] =
53
#include <sys/socket.h>
54
#include <sys/ioctl.h>
56
+#include <linux/sockios.h>
59
#include <linux/if_arp.h>
60
#include <linux/if_ether.h>
65
#define MAX_ETH 8 /* Maximum # of interfaces */
67
/* Table of known MII's */
69
+static const struct {
73
@@ -74,6 +76,9 @@ static struct {
74
{ 0x0181, 0x4410, "Quality QS6612" },
75
{ 0x0282, 0x1c50, "SMSC 83C180" },
76
{ 0x0300, 0xe540, "TDK 78Q2120" },
77
+ { 0x0141, 0x0c20, "Yukon 88E1011" },
78
+ { 0x0141, 0x0cc0, "Yukon-EC 88E1111" },
79
+ { 0x0141, 0x0c90, "Yukon-2 88E1112" },
81
#define NMII (sizeof(mii_id)/sizeof(mii_id[0]))
83
@@ -137,40 +142,48 @@ static void mdio_write(int skfd, int loc
90
/* The order through 100baseT4 matches bits in the BMSR */
91
- { "10baseT-HD", MII_AN_10BASET_HD },
92
- { "10baseT-FD", MII_AN_10BASET_FD },
93
- { "100baseTx-HD", MII_AN_100BASETX_HD },
94
- { "100baseTx-FD", MII_AN_100BASETX_FD },
95
- { "100baseT4", MII_AN_100BASET4 },
96
- { "100baseTx", MII_AN_100BASETX_FD | MII_AN_100BASETX_HD },
97
- { "10baseT", MII_AN_10BASET_FD | MII_AN_10BASET_HD },
98
+ { "10baseT-HD", {MII_AN_10BASET_HD} },
99
+ { "10baseT-FD", {MII_AN_10BASET_FD} },
100
+ { "100baseTx-HD", {MII_AN_100BASETX_HD} },
101
+ { "100baseTx-FD", {MII_AN_100BASETX_FD} },
102
+ { "100baseT4", {MII_AN_100BASET4} },
103
+ { "100baseTx", {MII_AN_100BASETX_FD | MII_AN_100BASETX_HD} },
104
+ { "10baseT", {MII_AN_10BASET_FD | MII_AN_10BASET_HD} },
106
+ { "1000baseT-HD", {0, MII_BMCR2_1000HALF} },
107
+ { "1000baseT-FD", {0, MII_BMCR2_1000FULL} },
108
+ { "1000baseT", {0, MII_BMCR2_1000HALF|MII_BMCR2_1000FULL} },
110
#define NMEDIA (sizeof(media)/sizeof(media[0]))
112
/* Parse an argument list of media types */
113
-static int parse_media(char *arg)
114
+static int parse_media(char *arg, unsigned *bmcr2)
118
mask = strtoul(arg, &s, 16);
119
if ((*arg != '\0') && (*s == '\0')) {
120
if ((mask & MII_AN_ABILITY_MASK) &&
121
- !(mask & ~MII_AN_ABILITY_MASK))
123
+ !(mask & ~MII_AN_ABILITY_MASK)) {
130
- s = strtok(arg, ", ");
135
+ s = strtok(arg, ", ");
137
for (i = 0; i < NMEDIA; i++)
138
- if (strcasecmp(media[i].name, s) == 0) break;
139
+ if (s && strcasecmp(media[i].name, s) == 0) break;
140
if (i == NMEDIA) goto failed;
141
- mask |= media[i].value;
142
- } while ((s = strtok(NULL, ", ")) != NULL);
144
+ mask |= media[i].value[0];
145
+ *bmcr2 |= media[i].value[1];
146
+ } while ((s = strtok(NULL, ", ")) != NULL);
150
fprintf(stderr, "Invalid media specification '%s'.\n", arg);
151
@@ -179,11 +192,24 @@ failed:
153
/*--------------------------------------------------------------------*/
155
-static char *media_list(int mask, int best)
156
+static const char *media_list(unsigned mask, unsigned mask2, int best)
158
static char buf[100];
162
+ if (mask & MII_BMCR_SPEED1000) {
163
+ if (mask2 & MII_BMCR2_1000HALF) {
165
+ strcat(buf, "1000baseT-HD");
166
+ if (best) goto out;
168
+ if (mask2 & MII_BMCR2_1000FULL) {
170
+ strcat(buf, "1000baseT-FD");
171
+ if (best) goto out;
175
for (i = 4; i >= 0; i--) {
177
@@ -192,6 +218,7 @@ static char *media_list(int mask, int be
183
strcat(buf, " flow-control");
185
@@ -201,15 +228,15 @@ int show_basic_mii(int sock, int phy_id)
189
- int bmcr, bmsr, advert, lkpar;
190
+ unsigned bmcr, bmsr, advert, lkpar, bmcr2, lpa2;
192
/* Some bits in the BMSR are latched, but we can't rely on being
193
the only reader, so only the current values are meaningful */
194
mdio_read(sock, MII_BMSR);
195
- for (i = 0; i < ((verbose > 1) ? 32 : 8); i++)
196
+ for (i = 0; i < ((verbose > 1) ? 32 : MII_BASIC_MAX); i++)
197
mii_val[i] = mdio_read(sock, i);
199
- if (mii_val[MII_BMCR] == 0xffff) {
200
+ if (mii_val[MII_BMCR] == 0xffff || mii_val[MII_BMSR] == 0x0000) {
201
fprintf(stderr, " No MII transceiver present!.\n");
204
@@ -217,6 +244,7 @@ int show_basic_mii(int sock, int phy_id)
205
/* Descriptive rename. */
206
bmcr = mii_val[MII_BMCR]; bmsr = mii_val[MII_BMSR];
207
advert = mii_val[MII_ANAR]; lkpar = mii_val[MII_ANLPAR];
208
+ bmcr2 = mii_val[MII_CTRL1000]; lpa2 = mii_val[MII_STAT1000];
210
sprintf(buf, "%s: ", ifr.ifr_name);
211
if (bmcr & MII_BMCR_AN_ENA) {
212
@@ -224,7 +252,7 @@ int show_basic_mii(int sock, int phy_id)
213
if (advert & lkpar) {
214
strcat(buf, (lkpar & MII_AN_ACK) ?
215
"negotiated" : "no autonegotiation,");
216
- strcat(buf, media_list(advert & lkpar, 1));
217
+ strcat(buf, media_list(advert & lkpar, bmcr2 & lpa2>>2, 1));
220
strcat(buf, "autonegotiation failed, ");
221
@@ -234,8 +262,10 @@ int show_basic_mii(int sock, int phy_id)
224
sprintf(buf+strlen(buf), "%s Mbit, %s duplex, ",
225
- (bmcr & MII_BMCR_100MBIT) ? "100" : "10",
226
- (bmcr & MII_BMCR_DUPLEX) ? "full" : "half");
227
+ ((bmcr2 & (MII_BMCR2_1000HALF | MII_BMCR2_1000FULL)) & lpa2 >> 2)
229
+ : (bmcr & MII_BMCR_100MBIT) ? "100" : "10",
230
+ (bmcr & MII_BMCR_DUPLEX) ? "full" : "half");
232
strcat(buf, (bmsr & MII_BMSR_LINK_VALID) ? "link ok" : "no link");
234
@@ -296,12 +326,13 @@ int show_basic_mii(int sock, int phy_id)
235
if (bmsr & MII_BMSR_REMOTE_FAULT)
236
printf("remote fault, ");
237
printf((bmsr & MII_BMSR_LINK_VALID) ? "link ok" : "no link");
238
- printf("\n capabilities:%s", media_list(bmsr >> 6, 0));
239
- printf("\n advertising: %s", media_list(advert, 0));
240
+ printf("\n capabilities:%s", media_list(bmsr >> 6, bmcr2, 0));
241
+ printf("\n advertising: %s", media_list(advert, lpa2 >> 2, 0));
242
if (lkpar & MII_AN_ABILITY_MASK)
243
- printf("\n link partner:%s", media_list(lkpar, 0));
244
+ printf("\n link partner:%s", media_list(lkpar, bmcr2, 0));
251
@@ -329,7 +360,7 @@ static int do_one_xcvr(int skfd, char *i
252
printf("resetting the transceiver...\n");
253
mdio_write(skfd, MII_BMCR, MII_BMCR_RESET);
255
- if (nway_advertise) {
256
+ if (nway_advertise > 0) {
257
mdio_write(skfd, MII_ANAR, nway_advertise | 1);
260
@@ -379,27 +410,38 @@ static void watch_one_xcvr(int skfd, cha
261
/*--------------------------------------------------------------------*/
264
-"usage: %s [-VvRrwl] [-A media,... | -F media] [interface ...]
265
- -V, --version display version information
266
- -v, --verbose more verbose output
267
- -R, --reset reset MII to poweron state
268
- -r, --restart restart autonegotiation
269
- -w, --watch monitor for link status changes
270
- -l, --log with -w, write events to syslog
271
- -A, --advertise=media,... advertise only specified media
272
- -F, --force=media force specified media technology
273
-media: 100baseT4, 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD,
274
- (to advertise both HD and FD) 100baseTx, 10baseT\n";
275
+"usage: %s [-VvRrwl] [-A media,... | -F media] [interface ...]\n"
276
+" -V, --version display version information\n"
277
+" -v, --verbose more verbose output\n"
278
+" -R, --reset reset MII to poweron state\n"
279
+" -r, --restart restart autonegotiation\n"
280
+" -w, --watch monitor for link status changes\n"
281
+" -l, --log with -w, write events to syslog\n"
282
+" -A, --advertise=media,... advertise only specified media\n"
283
+" -F, --force=media force specified media technology\n"
284
+"media: 1000baseTx-HD, 1000baseTx-FD,\n"
285
+" 100baseT4, 100baseTx-FD, 100baseTx-HD,\n"
286
+" 10baseT-FD, 10baseT-HD,\n"
287
+" (to advertise both HD and FD) 1000baseTx, 100baseTx, 10baseT\n";
290
+static void version(void)
292
+ fprintf(stderr, "%s\n%s\n", Version, RELEASE);
293
+ exit(5); /* E_VERSION */
297
int main(int argc, char **argv)
299
int i, c, ret, errflag = 0;
301
+ unsigned ctrl1000 = 0;
303
while ((c = getopt_long(argc, argv, "A:F:p:lrRvVw?", longopts, 0)) != EOF)
305
- case 'A': nway_advertise = parse_media(optarg); break;
306
- case 'F': fixed_speed = parse_media(optarg); break;
307
+ case 'A': nway_advertise = parse_media(optarg, &ctrl1000); break;
308
+ case 'F': fixed_speed = parse_media(optarg, &ctrl1000); break;
309
case 'p': override_phy = atoi(optarg); break;
310
case 'r': opt_restart++; break;
311
case 'R': opt_reset++; break;
312
@@ -411,6 +453,10 @@ int main(int argc, char **argv)
314
/* Check for a few inappropriate option combinations */
315
if (opt_watch) verbose = 0;
317
+ if ((nway_advertise < 0) || (fixed_speed < 0))
320
if (errflag || (fixed_speed & (fixed_speed-1)) ||
321
(fixed_speed && (opt_restart || nway_advertise))) {
322
fprintf(stderr, usage, argv[0]);
323
@@ -418,7 +464,7 @@ int main(int argc, char **argv)
330
/* Open a basic socket. */
331
if ((skfd = socket(AF_INET, SOCK_DGRAM,0)) < 0) {
332
@@ -426,6 +472,9 @@ int main(int argc, char **argv)
337
+ printf("Using SIOCGMIIPHY=0x%x\n", SIOCGMIIPHY);
339
/* No remaining args means show all interfaces. */
340
if (optind == argc) {