1 ===================================================================
2 RCS file: /cvsroot/net-tools/net-tools/include/mii.h,v
3 retrieving revision 1.2
4 retrieving revision 1.3
6 --- net-tools/net-tools/include/mii.h 2003/06/28 03:19:04 1.2
7 +++ net-tools/net-tools/include/mii.h 2006/09/27 20:59:19 1.3
9 #define MII_BMCR_RESTART 0x0200
10 #define MII_BMCR_DUPLEX 0x0100
11 #define MII_BMCR_COLTEST 0x0080
12 +#define MII_BMCR_SPEED1000 0x0040
14 /* Basic Mode Status Register */
17 #define MII_ANER_PAGE_RX 0x0002
18 #define MII_ANER_LP_AN_ABLE 0x0001
20 +#define MII_CTRL1000 0x09
21 +#define MII_BMCR2_1000FULL 0x0200
22 +#define MII_BMCR2_1000HALF 0x0100
24 +#define MII_STAT1000 0x0a
25 +#define MII_LPA2_1000LOCALOK 0x2000
26 +#define MII_LPA2_1000REMRXOK 0x1000
27 +#define MII_LPA2_1000FULL 0x0800
28 +#define MII_LPA2_1000HALF 0x0400
30 +/* Last register we need for show_basic_mii() */
31 +#define MII_BASIC_MAX (MII_STAT1000+1)
33 #endif /* _LINUX_MII_H */
34 ===================================================================
35 ===================================================================
36 RCS file: /cvsroot/net-tools/net-tools/mii-tool.c,v
37 retrieving revision 1.1
38 retrieving revision 1.9
40 --- net-tools/net-tools/mii-tool.c 2000/05/21 13:44:36 1.1
41 +++ net-tools/net-tools/mii-tool.c 2006/09/27 20:59:18 1.9
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$\n(Author: David Hinds based on Donald Becker's mii-diag)";
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 {
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]))
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 @@
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--) {
183 strcat(buf, " flow-control");
185 @@ -201,15 +228,15 @@
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");
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) {
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, ");
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 @@
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));
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 @@
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;
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]);
330 /* Open a basic socket. */
331 if ((skfd = socket(AF_INET, SOCK_DGRAM,0)) < 0) {
337 + printf("Using SIOCGMIIPHY=0x%x\n", SIOCGMIIPHY);
339 /* No remaining args means show all interfaces. */
340 if (optind == argc) {