6634843
diff -up net-tools-1.60/mii-tool.c.mii-gigabit net-tools-1.60/mii-tool.c
6634843
--- net-tools-1.60/mii-tool.c.mii-gigabit	2010-06-14 15:51:23.000000000 +0200
6634843
+++ net-tools-1.60/mii-tool.c	2010-06-14 16:10:34.000000000 +0200
6634843
@@ -57,7 +57,7 @@ static char version[] =
6634843
 #define LPA_ABILITY_MASK	0x07e0
6634843
 
6634843
 /* Table of known MII's */
6634843
-static struct {
6634843
+static const struct {
6634843
     u_short	id1, id2;
6634843
     char	*name;
6634843
 } mii_id[] = {
6634843
@@ -76,6 +76,9 @@ static struct {
6634843
     { 0x0181, 0x4410, "Quality QS6612" },
6634843
     { 0x0282, 0x1c50, "SMSC 83C180" },
6634843
     { 0x0300, 0xe540, "TDK 78Q2120" },
6634843
+    { 0x0141, 0x0c20, "Yukon 88E1011" },
6634843
+    { 0x0141, 0x0cc0, "Yukon-EC 88E1111" },
6634843
+    { 0x0141, 0x0c90, "Yukon-2 88E1112" },
6634843
 };
6634843
 #define NMII (sizeof(mii_id)/sizeof(mii_id[0]))
6634843
 
6634843
@@ -139,40 +142,47 @@ static void mdio_write(int skfd, int loc
6634843
 
6634843
 const struct {
6634843
     char	*name;
6634843
-    u_short	value;
6634843
+    u_short	value[2];
6634843
 } media[] = {
6634843
     /* The order through 100baseT4 matches bits in the BMSR */
6634843
-    { "10baseT-HD",	LPA_10HALF },
6634843
-    { "10baseT-FD",	LPA_10FULL },
6634843
-    { "100baseTx-HD",	LPA_100HALF },
6634843
-    { "100baseTx-FD",	LPA_100FULL },
6634843
-    { "100baseT4",	LPA_100BASE4 },
6634843
-    { "100baseTx",	LPA_100FULL | LPA_100HALF },
6634843
-    { "10baseT",	LPA_10FULL | LPA_10HALF },
6634843
+    { "10baseT-HD",     {LPA_10HALF} },
6634843
+    { "10baseT-FD",     {LPA_10FULL} },
6634843
+    { "100baseTx-HD",   {LPA_100HALF} },
6634843
+    { "100baseTx-FD",   {LPA_100FULL} },
6634843
+    { "100baseT4",      {LPA_100BASE4} },
6634843
+    { "100baseTx",      {LPA_100FULL | LPA_100HALF} },
6634843
+    { "10baseT",        {LPA_10FULL | LPA_10HALF} },
6634843
+    { "1000baseT-HD",   {0, ADVERTISE_1000HALF} },
6634843
+    { "1000baseT-FD",   {0, ADVERTISE_1000FULL} },
6634843
+    { "1000baseT",      {0, ADVERTISE_1000HALF|ADVERTISE_1000FULL} },
6634843
 };
6634843
 #define NMEDIA (sizeof(media)/sizeof(media[0]))
6634843
 	
6634843
 /* Parse an argument list of media types */
6634843
-static int parse_media(char *arg)
6634843
+static int parse_media(char *arg, unsigned *bmcr2)
6634843
 {
6634843
     int mask, i;
6634843
     char *s;
6634843
     mask = strtoul(arg, &s, 16);
6634843
     if ((*arg != '\0') && (*s == '\0')) {
6634843
-	if ((mask & LPA_ABILITY_MASK) &&
6634843
-	    !(mask & ~LPA_ABILITY_MASK))
6634843
-	    return mask;
6634843
-	goto failed;
6634843
-    } else {
6634843
-	mask = 0;
6634843
-	s = strtok(arg, ", ");
6634843
-	do {
6634843
-	    for (i = 0; i < NMEDIA; i++)
6634843
-		if (strcasecmp(media[i].name, s) == 0) break;
6634843
-	    if (i == NMEDIA) goto failed;
6634843
-	    mask |= media[i].value;
6634843
-	} while ((s = strtok(NULL, ", ")) != NULL);
6634843
-    }
6634843
+        if ((mask & LPA_ABILITY_MASK) &&
6634843
+            !(mask & ~LPA_ABILITY_MASK)) {
6634843
+            *bmcr2 = 0;
6634843
+            return mask;
6634843
+        }
6634843
+        goto failed;
6634843
+    }
6634843
+    mask = 0;
6634843
+    *bmcr2 = 0;
6634843
+    s = strtok(arg, ", ");
6634843
+    do {
6634843
+        for (i = 0; i < NMEDIA; i++)
6634843
+        if (s && strcasecmp(media[i].name, s) == 0) break;
6634843
+        if (i == NMEDIA) goto failed;
6634843
+        mask |= media[i].value[0];
6634843
+        *bmcr2 |= media[i].value[1];
6634843
+    } while ((s = strtok(NULL, ", ")) != NULL);
6634843
+
6634843
     return mask;
6634843
 failed:
6634843
     fprintf(stderr, "Invalid media specification '%s'.\n", arg);
6634843
@@ -181,11 +191,25 @@ failed:
6634843
 
6634843
 /*--------------------------------------------------------------------*/
6634843
 
6634843
-static char *media_list(int mask, int best)
6634843
+static const char *media_list(unsigned mask, unsigned mask2, int best)
6634843
 {
6634843
     static char buf[100];
6634843
     int i;
6634843
     *buf = '\0';
6634843
+
6634843
+    if (mask & BMCR_SPEED1000) {
6634843
+        if (mask2 & ADVERTISE_1000HALF) {
6634843
+            strcat(buf, " ");
6634843
+            strcat(buf, "1000baseT-HD");
6634843
+            if (best) goto out;
6634843
+        }
6634843
+        if (mask2 & ADVERTISE_1000FULL) {
6634843
+            strcat(buf, " ");
6634843
+            strcat(buf, "1000baseT-FD");
6634843
+            if (best) goto out;
6634843
+        }
6634843
+    }
6634843
+
6634843
     mask >>= 5;
6634843
     for (i = 4; i >= 0; i--) {
6634843
 	if (mask & (1<
6634843
@@ -194,6 +218,7 @@ static char *media_list(int mask, int be
6634843
 	    if (best) break;
6634843
 	}
6634843
     }
6634843
+out:
6634843
     if (mask & (1<<5))
6634843
 	strcat(buf, " flow-control");
6634843
     return buf;
6634843
@@ -203,11 +228,11 @@ int show_basic_mii(int sock, int phy_id)
6634843
 {
6634843
     char buf[100];
6634843
     int i, mii_val[32];
6634843
-    int bmcr, bmsr, advert, lkpar;
6634843
+    unsigned bmcr, bmsr, advert, lkpar, bmcr2, lpa2;
6634843
     /* Some bits in the BMSR are latched, but we can't rely on being
6634843
        the only reader, so only the current values are meaningful */
6634843
     mdio_read(sock, MII_BMSR);
6634843
-    for (i = 0; i < ((verbose > 1) ? 32 : 8); i++) {
6634843
+    for (i = 0; i < ((verbose > 1) ? 32 : (MII_STAT1000+1)); i++) {
6634843
         if ((i == MII_BMCR) || (i == MII_BMSR) || (i == MII_PHYSID1) ||
6634843
             (i == MII_PHYSID2) || (i == MII_ADVERTISE) || (i == MII_LPA) ||
6634843
             (i == MII_EXPANSION) || (i == MII_CTRL1000) || (i == MII_STAT1000) ||
6634843
@@ -220,7 +245,7 @@ int show_basic_mii(int sock, int phy_id)
6634843
         else
6634843
             mii_val[i] = 0;
6634843
     }
6634843
-    if (mii_val[MII_BMCR] == 0xffff) {
6634843
+    if (mii_val[MII_BMCR] == 0xffff  || mii_val[MII_BMSR] == 0x0000) {
6634843
 	fprintf(stderr, "  No MII transceiver present!.\n");
6634843
 	return -1;
6634843
     }
6634843
@@ -228,6 +253,7 @@ int show_basic_mii(int sock, int phy_id)
6634843
     /* Descriptive rename. */
6634843
     bmcr = mii_val[MII_BMCR]; bmsr = mii_val[MII_BMSR];
6634843
     advert = mii_val[MII_ADVERTISE]; lkpar = mii_val[MII_LPA];
6634843
+    bmcr2 = mii_val[MII_CTRL1000]; lpa2 = mii_val[MII_STAT1000];
6634843
 
6634843
     sprintf(buf, "%s: ", ifr.ifr_name);
6634843
     if (bmcr & BMCR_ANENABLE) {
6634843
@@ -235,7 +261,7 @@ int show_basic_mii(int sock, int phy_id)
6634843
 	    if (advert & lkpar) {
6634843
 		strcat(buf, (lkpar & LPA_LPACK) ?
6634843
 		       "negotiated" : "no autonegotiation,");
6634843
-		strcat(buf, media_list(advert & lkpar, 1));
6634843
+		strcat(buf, media_list(advert & lkpar, bmcr2 & lpa2>>2, 1));
6634843
 		strcat(buf, ", ");
6634843
 	    } else {
6634843
 		strcat(buf, "autonegotiation failed, ");
6634843
@@ -245,8 +271,10 @@ int show_basic_mii(int sock, int phy_id)
6634843
 	}
6634843
     } else {
6634843
 	sprintf(buf+strlen(buf), "%s Mbit, %s duplex, ",
6634843
-	       (bmcr & BMCR_SPEED100) ? "100" : "10",
6634843
-	       (bmcr & BMCR_FULLDPLX) ? "full" : "half");
6634843
+		((bmcr2 & (ADVERTISE_1000HALF | ADVERTISE_1000FULL)) & lpa2 >> 2)
6634843
+		? "1000"
6634843
+		: (bmcr & BMCR_SPEED100) ? "100" : "10",
6634843
+		(bmcr & BMCR_FULLDPLX) ? "full" : "half");
6634843
     }
6634843
     strcat(buf, (bmsr & BMSR_LSTATUS) ? "link ok" : "no link");
6634843
 
6634843
@@ -307,10 +335,10 @@ int show_basic_mii(int sock, int phy_id)
6634843
 	if (bmsr & BMSR_RFAULT)
6634843
 	    printf("remote fault, ");
6634843
 	printf((bmsr & BMSR_LSTATUS) ? "link ok" : "no link");
6634843
-	printf("\n  capabilities:%s", media_list(bmsr >> 6, 0));
6634843
-	printf("\n  advertising: %s", media_list(advert, 0));
6634843
+	printf("\n  capabilities:%s", media_list(bmsr >> 6, bmcr2, 0));
6634843
+	printf("\n  advertising: %s", media_list(advert, lpa2 >> 2, 0));
6634843
 	if (lkpar & LPA_ABILITY_MASK)
6634843
-	    printf("\n  link partner:%s", media_list(lkpar, 0));
6634843
+	    printf("\n  link partner:%s", media_list(lkpar, bmcr2, 0));
6634843
 	printf("\n");
6634843
     }
6634843
     fflush(stdout);
6634843
@@ -341,7 +369,7 @@ static int do_one_xcvr(int skfd, char *i
6634843
 	printf("resetting the transceiver...\n");
6634843
 	mdio_write(skfd, MII_BMCR, BMCR_RESET);
6634843
     }
6634843
-    if (nway_advertise) {
6634843
+    if (nway_advertise > 0) {
6634843
 	mdio_write(skfd, MII_ADVERTISE, nway_advertise | 1);
6634843
 	opt_restart = 1;
6634843
     }
6634843
@@ -400,18 +428,20 @@ usage: %s [-VvRrwl] [-A media,... | -F m
6634843
        -l, --log                   with -w, write events to syslog\n\
6634843
        -A, --advertise=media,...   advertise only specified media\n\
6634843
        -F, --force=media           force specified media technology\n\
6634843
-media: 100baseT4, 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD,\n\
6634843
+media: 1000baseTx-HD, 1000baseTx-FD,\n\
6634843
+       100baseT4, 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD,\n\
6634843
        (to advertise both HD and FD) 100baseTx, 10baseT\n";
6634843
 
6634843
 int main(int argc, char **argv)
6634843
 {
6634843
     int i, c, ret, errflag = 0;
6634843
     char s[6];
6634843
-    
6634843
+    unsigned ctrl1000 = 0;
6634843
+
6634843
     while ((c = getopt_long(argc, argv, "A:F:p:lrRvVw?", longopts, 0)) != EOF)
6634843
 	switch (c) {
6634843
-	case 'A': nway_advertise = parse_media(optarg); break;
6634843
-	case 'F': fixed_speed = parse_media(optarg); break;
6634843
+	case 'A': nway_advertise = parse_media(optarg, &ctrl1000); break;
6634843
+	case 'F': fixed_speed = parse_media(optarg, &ctrl1000); break;
6634843
 	case 'p': override_phy = atoi(optarg); break;
6634843
 	case 'r': opt_restart++;	break;
6634843
 	case 'R': opt_reset++;		break;
6634843
@@ -423,6 +453,10 @@ int main(int argc, char **argv)
6634843
 	}
6634843
     /* Check for a few inappropriate option combinations */
6634843
     if (opt_watch) verbose = 0;
6634843
+
6634843
+    if ((nway_advertise < 0) || (fixed_speed < 0))
6634843
+        return 2;
6634843
+
6634843
     if (errflag || (fixed_speed & (fixed_speed-1)) ||
6634843
 	(fixed_speed && (opt_restart || nway_advertise))) {
6634843
 	fprintf(stderr, usage, argv[0]);