]> git.pld-linux.org Git - packages/net-tools.git/blob - net-tools-mii-tool-GigE.patch
- x32 rebuild
[packages/net-tools.git] / net-tools-mii-tool-GigE.patch
1 ===================================================================
2 RCS file: /cvsroot/net-tools/net-tools/include/mii.h,v
3 retrieving revision 1.2
4 retrieving revision 1.3
5 diff -u -r1.2 -r1.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
8 @@ -41,6 +41,7 @@
9  #define  MII_BMCR_RESTART      0x0200
10  #define  MII_BMCR_DUPLEX       0x0100
11  #define  MII_BMCR_COLTEST      0x0080
12 +#define  MII_BMCR_SPEED1000    0x0040
13  
14  /* Basic Mode Status Register */
15  #define MII_BMSR               0x01
16 @@ -86,4 +87,17 @@
17  #define  MII_ANER_PAGE_RX      0x0002
18  #define  MII_ANER_LP_AN_ABLE   0x0001
19  
20 +#define MII_CTRL1000           0x09
21 +#define   MII_BMCR2_1000FULL   0x0200
22 +#define   MII_BMCR2_1000HALF   0x0100
23 +
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
29 +
30 +/* Last register we need for show_basic_mii() */
31 +#define MII_BASIC_MAX          (MII_STAT1000+1)
32 +
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
39 diff -u -r1.1 -r1.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
42 @@ -29,8 +29,7 @@
43         http://www.national.com/pf/DP/DP83840.html
44  */
45  
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)";
49  
50  #include <unistd.h>
51  #include <stdlib.h>
52 @@ -46,16 +45,19 @@
53  #include <sys/socket.h>
54  #include <sys/ioctl.h>
55  #include <net/if.h>
56 +#include <linux/sockios.h>
57 +
58  #ifndef __GLIBC__
59  #include <linux/if_arp.h>
60  #include <linux/if_ether.h>
61  #endif
62  #include "mii.h"
63 +#include "version.h"
64  
65  #define MAX_ETH                8               /* Maximum # of interfaces */
66  
67  /* Table of known MII's */
68 -static struct {
69 +static const struct {
70      u_short    id1, id2;
71      char       *name;
72  } mii_id[] = {
73 @@ -74,6 +76,9 @@
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" },
80  };
81  #define NMII (sizeof(mii_id)/sizeof(mii_id[0]))
82  
83 @@ -137,40 +142,48 @@
84  
85  const struct {
86      char       *name;
87 -    u_short    value;
88 +    u_short    value[2];
89  } media[] = {
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} },
105 +
106 +    { "1000baseT-HD",  {0, MII_BMCR2_1000HALF} },
107 +    { "1000baseT-FD",  {0, MII_BMCR2_1000FULL} },
108 +    { "1000baseT",     {0, MII_BMCR2_1000HALF|MII_BMCR2_1000FULL} },
109  };
110  #define NMEDIA (sizeof(media)/sizeof(media[0]))
111         
112  /* Parse an argument list of media types */
113 -static int parse_media(char *arg)
114 +static int parse_media(char *arg, unsigned *bmcr2)
115  {
116      int mask, i;
117      char *s;
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))
122 -           return mask;
123 +           !(mask & ~MII_AN_ABILITY_MASK)) {
124 +               *bmcr2 = 0;
125 +               return mask;
126 +       }
127         goto failed;
128 -    } else {
129 -       mask = 0;
130 -       s = strtok(arg, ", ");
131 -       do {
132 +    }
133 +    mask = 0;
134 +    *bmcr2 = 0;
135 +    s = strtok(arg, ", ");
136 +    do {
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);
143 -    }
144 +           mask |= media[i].value[0];
145 +           *bmcr2 |= media[i].value[1];
146 +    } while ((s = strtok(NULL, ", ")) != NULL);
147 +
148      return mask;
149  failed:
150      fprintf(stderr, "Invalid media specification '%s'.\n", arg);
151 @@ -179,11 +192,24 @@
152  
153  /*--------------------------------------------------------------------*/
154  
155 -static char *media_list(int mask, int best)
156 +static const char *media_list(unsigned mask, unsigned mask2, int best)
157  {
158      static char buf[100];
159      int i;
160      *buf = '\0';
161 +
162 +    if (mask & MII_BMCR_SPEED1000) {
163 +       if (mask2 & MII_BMCR2_1000HALF) {
164 +           strcat(buf, " ");
165 +           strcat(buf, "1000baseT-HD");
166 +           if (best) goto out;
167 +       }
168 +       if (mask2 & MII_BMCR2_1000FULL) {
169 +           strcat(buf, " ");
170 +           strcat(buf, "1000baseT-FD");
171 +           if (best) goto out;
172 +       }
173 +    }
174      mask >>= 5;
175      for (i = 4; i >= 0; i--) {
176         if (mask & (1<<i)) {
177 @@ -192,6 +218,7 @@
178             if (best) break;
179         }
180      }
181 + out:
182      if (mask & (1<<5))
183         strcat(buf, " flow-control");
184      return buf;
185 @@ -201,15 +228,15 @@
186  {
187      char buf[100];
188      int i, mii_val[32];
189 -    int bmcr, bmsr, advert, lkpar;
190 +    unsigned bmcr, bmsr, advert, lkpar, bmcr2, lpa2;
191  
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);
198  
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");
202         return -1;
203      }
204 @@ -217,6 +244,7 @@
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];
209  
210      sprintf(buf, "%s: ", ifr.ifr_name);
211      if (bmcr & MII_BMCR_AN_ENA) {
212 @@ -224,7 +252,7 @@
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));
218                 strcat(buf, ", ");
219             } else {
220                 strcat(buf, "autonegotiation failed, ");
221 @@ -234,8 +262,10 @@
222         }
223      } else {
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)
228 +               ? "1000"
229 +               : (bmcr & MII_BMCR_100MBIT) ? "100" : "10",
230 +               (bmcr & MII_BMCR_DUPLEX) ? "full" : "half");
231      }
232      strcat(buf, (bmsr & MII_BMSR_LINK_VALID) ? "link ok" : "no link");
233  
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));
245         printf("\n");
246      }
247 +    fflush(stdout);
248      return 0;
249  }
250  
251 @@ -329,7 +360,7 @@
252         printf("resetting the transceiver...\n");
253         mdio_write(skfd, MII_BMCR, MII_BMCR_RESET);
254      }
255 -    if (nway_advertise) {
256 +    if (nway_advertise > 0) {
257         mdio_write(skfd, MII_ANAR, nway_advertise | 1);
258         opt_restart = 1;
259      }
260 @@ -379,27 +410,38 @@
261  /*--------------------------------------------------------------------*/
262  
263  const char *usage =
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";
288 +
289 +
290 +static void version(void)
291 +{
292 +    fprintf(stderr, "%s\n%s\n", Version, RELEASE);
293 +    exit(5); /* E_VERSION */
294 +}
295 +
296  
297  int main(int argc, char **argv)
298  {
299      int i, c, ret, errflag = 0;
300      char s[6];
301 +    unsigned ctrl1000 = 0;
302      
303      while ((c = getopt_long(argc, argv, "A:F:p:lrRvVw?", longopts, 0)) != EOF)
304         switch (c) {
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 @@
313         }
314      /* Check for a few inappropriate option combinations */
315      if (opt_watch) verbose = 0;
316 +
317 +    if ((nway_advertise < 0) || (fixed_speed < 0))
318 +       return 2;
319 +
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 @@
324      }
325  
326      if (opt_version)
327 -       printf(version);
328 +       version();
329  
330      /* Open a basic socket. */
331      if ((skfd = socket(AF_INET, SOCK_DGRAM,0)) < 0) {
332 @@ -426,6 +472,9 @@
333         exit(-1);
334      }
335  
336 +    if (verbose > 1)
337 +       printf("Using SIOCGMIIPHY=0x%x\n", SIOCGMIIPHY);        
338 +
339      /* No remaining args means show all interfaces. */
340      if (optind == argc) {
341         ret = 1;
This page took 0.075074 seconds and 3 git commands to generate.