~ubuntu-branches/debian/sid/net-tools/sid

« back to all changes in this revision

Viewing changes to debian/patches/CVS-20060927-mii-tool.c_sync.patch

  • Committer: Package Import Robot
  • Author(s): Martín Ferrari
  • Date: 2015-09-07 01:54:07 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20150907015407-v2tfsgxayjd3iq4i
Tags: 1.60+git20150829.73cef8a-1
* After 14 years without an upstream release, I am producing a new package
  based on today's upstream repository.
  Closes: #391495, #486448, #323261, #260587, #545328, #511395.
* Remove many patches now merged upstream, delete unmaintainable and
  undocumented local changes, and update the rest.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Sync with upstream CVS, complete log:
2
 
 
3
 
Revision 1.9 - Wed Sep 27 20:59:18 2006 UTC by ecki
4
 
 
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
8
 
 
9
 
Revision 1.8 - Thu Jun 3 22:18:26 2004 UTC by ecki
10
 
 
11
 
added linebreak to  version signature
12
 
 
13
 
Revision 1.7 - Mon Oct 20 22:22:22 2003 UTC by ecki
14
 
make sure version string is helpful
15
 
 
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).
19
 
 
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.
26
 
 
27
 
Revision 1.4 - Wed May 28 19:41:16 2003 UTC by ecki
28
 
make it compile on stricter gcc3.3
29
 
 
30
 
Revision 1.3 - Sun Sep 15 00:25:14 2002 UTC by ecki
31
 
Implemented the Sean Reifenschneider suggested fflush() to the --watch
32
 
function of mii-tool.
33
 
 
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
36
 
bug #139027
37
 
 
38
 
Index: net-tools/mii-tool.c
39
 
===================================================================
40
 
--- net-tools.orig/mii-tool.c
41
 
+++ net-tools/mii-tool.c
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: 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)";
49
 
 
50
 
 #include <unistd.h>
51
 
 #include <stdlib.h>
52
 
@@ -46,16 +45,19 @@ static char version[] =
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 @@ 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" },
80
 
 };
81
 
 #define NMII (sizeof(mii_id)/sizeof(mii_id[0]))
82
 
 
83
 
@@ -137,40 +142,48 @@ static void mdio_write(int skfd, int loc
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 @@ failed:
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 @@ static char *media_list(int mask, int be
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 @@ int show_basic_mii(int sock, int phy_id)
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 @@ 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];
209
 
 
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));
218
 
                strcat(buf, ", ");
219
 
            } else {
220
 
                strcat(buf, "autonegotiation failed, ");
221
 
@@ -234,8 +262,10 @@ int show_basic_mii(int sock, int phy_id)
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 @@ 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));
245
 
        printf("\n");
246
 
     }
247
 
+    fflush(stdout);
248
 
     return 0;
249
 
 }
250
 
 
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);
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 @@ static void watch_one_xcvr(int skfd, cha
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 @@ int main(int argc, char **argv)
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 @@ int main(int argc, char **argv)
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 @@ int main(int argc, char **argv)
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;