]>
Commit | Line | Data |
---|---|---|
236898d6 MT |
1 | diff -up net-tools-1.60/mii-tool.c.mii-refactor net-tools-1.60/mii-tool.c |
2 | --- net-tools-1.60/mii-tool.c.mii-refactor 2009-10-30 16:25:23.000000000 +0100 | |
3 | +++ net-tools-1.60/mii-tool.c 2009-10-30 16:45:01.000000000 +0100 | |
4 | @@ -50,9 +50,11 @@ static char version[] = | |
5 | #include <linux/if_arp.h> | |
6 | #include <linux/if_ether.h> | |
7 | #endif | |
8 | -#include "mii.h" | |
9 | +#include <linux/mii.h> | |
10 | +#include <linux/sockios.h> | |
11 | ||
12 | #define MAX_ETH 8 /* Maximum # of interfaces */ | |
13 | +#define LPA_ABILITY_MASK 0x07e0 | |
14 | ||
15 | /* Table of known MII's */ | |
16 | static struct { | |
17 | @@ -112,7 +114,7 @@ static struct ifreq ifr; | |
18 | ||
19 | static int mdio_read(int skfd, int location) | |
20 | { | |
21 | - struct mii_data *mii = (struct mii_data *)&ifr.ifr_data; | |
22 | + struct mii_ioctl_data *mii = (struct mii_ioctl_data *)&ifr.ifr_data; | |
23 | mii->reg_num = location; | |
24 | if (ioctl(skfd, SIOCGMIIREG, &ifr) < 0) { | |
25 | fprintf(stderr, "SIOCGMIIREG on %s failed: %s\n", ifr.ifr_name, | |
26 | @@ -124,7 +126,7 @@ static int mdio_read(int skfd, int locat | |
27 | ||
28 | static void mdio_write(int skfd, int location, int value) | |
29 | { | |
30 | - struct mii_data *mii = (struct mii_data *)&ifr.ifr_data; | |
31 | + struct mii_ioctl_data *mii = (struct mii_ioctl_data *)&ifr.ifr_data; | |
32 | mii->reg_num = location; | |
33 | mii->val_in = value; | |
34 | if (ioctl(skfd, SIOCSMIIREG, &ifr) < 0) { | |
35 | @@ -140,13 +142,13 @@ const struct { | |
36 | u_short value; | |
37 | } media[] = { | |
38 | /* The order through 100baseT4 matches bits in the BMSR */ | |
39 | - { "10baseT-HD", MII_AN_10BASET_HD }, | |
40 | - { "10baseT-FD", MII_AN_10BASET_FD }, | |
41 | - { "100baseTx-HD", MII_AN_100BASETX_HD }, | |
42 | - { "100baseTx-FD", MII_AN_100BASETX_FD }, | |
43 | - { "100baseT4", MII_AN_100BASET4 }, | |
44 | - { "100baseTx", MII_AN_100BASETX_FD | MII_AN_100BASETX_HD }, | |
45 | - { "10baseT", MII_AN_10BASET_FD | MII_AN_10BASET_HD }, | |
46 | + { "10baseT-HD", LPA_10HALF }, | |
47 | + { "10baseT-FD", LPA_10FULL }, | |
48 | + { "100baseTx-HD", LPA_100HALF }, | |
49 | + { "100baseTx-FD", LPA_100FULL }, | |
50 | + { "100baseT4", LPA_100BASE4 }, | |
51 | + { "100baseTx", LPA_100FULL | LPA_100HALF }, | |
52 | + { "10baseT", LPA_10FULL | LPA_10HALF }, | |
53 | }; | |
54 | #define NMEDIA (sizeof(media)/sizeof(media[0])) | |
55 | ||
56 | @@ -157,8 +159,8 @@ static int parse_media(char *arg) | |
57 | char *s; | |
58 | mask = strtoul(arg, &s, 16); | |
59 | if ((*arg != '\0') && (*s == '\0')) { | |
60 | - if ((mask & MII_AN_ABILITY_MASK) && | |
61 | - !(mask & ~MII_AN_ABILITY_MASK)) | |
62 | + if ((mask & LPA_ABILITY_MASK) && | |
63 | + !(mask & ~LPA_ABILITY_MASK)) | |
64 | return mask; | |
65 | goto failed; | |
66 | } else { | |
67 | @@ -202,13 +204,22 @@ int show_basic_mii(int sock, int phy_id) | |
68 | char buf[100]; | |
69 | int i, mii_val[32]; | |
70 | int bmcr, bmsr, advert, lkpar; | |
71 | - | |
72 | /* Some bits in the BMSR are latched, but we can't rely on being | |
73 | the only reader, so only the current values are meaningful */ | |
74 | mdio_read(sock, MII_BMSR); | |
75 | - for (i = 0; i < ((verbose > 1) ? 32 : 8); i++) | |
76 | - mii_val[i] = mdio_read(sock, i); | |
77 | - | |
78 | + for (i = 0; i < ((verbose > 1) ? 32 : 8); i++) { | |
79 | + if ((i == MII_BMCR) || (i == MII_BMSR) || (i == MII_PHYSID1) || | |
80 | + (i == MII_PHYSID2) || (i == MII_ADVERTISE) || (i == MII_LPA) || | |
81 | + (i == MII_EXPANSION) || (i == MII_CTRL1000) || (i == MII_STAT1000) || | |
82 | + (i == MII_ESTATUS) || (i == MII_DCOUNTER) || (i == MII_FCSCOUNTER) || | |
83 | + (i == MII_NWAYTEST) || (i == MII_RERRCOUNTER) || | |
84 | + (i == MII_SREVISION) || (i == MII_RESV1) || (i == MII_LBRERROR) || | |
85 | + (i == MII_PHYADDR) || (i == MII_RESV2) || | |
86 | + (i == MII_TPISTATUS) || (i == MII_NCONFIG)) | |
87 | + mii_val[i] = mdio_read(sock, i); | |
88 | + else | |
89 | + mii_val[i] = 0; | |
90 | + } | |
91 | if (mii_val[MII_BMCR] == 0xffff) { | |
92 | fprintf(stderr, " No MII transceiver present!.\n"); | |
93 | return -1; | |
94 | @@ -216,28 +227,28 @@ int show_basic_mii(int sock, int phy_id) | |
95 | ||
96 | /* Descriptive rename. */ | |
97 | bmcr = mii_val[MII_BMCR]; bmsr = mii_val[MII_BMSR]; | |
98 | - advert = mii_val[MII_ANAR]; lkpar = mii_val[MII_ANLPAR]; | |
99 | + advert = mii_val[MII_ADVERTISE]; lkpar = mii_val[MII_LPA]; | |
100 | ||
101 | sprintf(buf, "%s: ", ifr.ifr_name); | |
102 | - if (bmcr & MII_BMCR_AN_ENA) { | |
103 | - if (bmsr & MII_BMSR_AN_COMPLETE) { | |
104 | + if (bmcr & BMCR_ANENABLE) { | |
105 | + if (bmsr & BMSR_ANEGCOMPLETE) { | |
106 | if (advert & lkpar) { | |
107 | - strcat(buf, (lkpar & MII_AN_ACK) ? | |
108 | + strcat(buf, (lkpar & LPA_LPACK) ? | |
109 | "negotiated" : "no autonegotiation,"); | |
110 | strcat(buf, media_list(advert & lkpar, 1)); | |
111 | strcat(buf, ", "); | |
112 | } else { | |
113 | strcat(buf, "autonegotiation failed, "); | |
114 | } | |
115 | - } else if (bmcr & MII_BMCR_RESTART) { | |
116 | + } else if (bmcr & BMCR_ANRESTART) { | |
117 | strcat(buf, "autonegotiation restarted, "); | |
118 | } | |
119 | } else { | |
120 | sprintf(buf+strlen(buf), "%s Mbit, %s duplex, ", | |
121 | - (bmcr & MII_BMCR_100MBIT) ? "100" : "10", | |
122 | - (bmcr & MII_BMCR_DUPLEX) ? "full" : "half"); | |
123 | + (bmcr & BMCR_SPEED100) ? "100" : "10", | |
124 | + (bmcr & BMCR_FULLDPLX) ? "full" : "half"); | |
125 | } | |
126 | - strcat(buf, (bmsr & MII_BMSR_LINK_VALID) ? "link ok" : "no link"); | |
127 | + strcat(buf, (bmsr & BMSR_LSTATUS) ? "link ok" : "no link"); | |
128 | ||
129 | if (opt_watch) { | |
130 | if (opt_log) { | |
131 | @@ -273,32 +284,32 @@ int show_basic_mii(int sock, int phy_id) | |
132 | ((mii_val[2]<<6)|(mii_val[3]>>10))&0xff, | |
133 | (mii_val[3]>>4)&0x3f, mii_val[3]&0x0f); | |
134 | printf(" basic mode: "); | |
135 | - if (bmcr & MII_BMCR_RESET) | |
136 | + if (bmcr & BMCR_RESET) | |
137 | printf("software reset, "); | |
138 | - if (bmcr & MII_BMCR_LOOPBACK) | |
139 | + if (bmcr & BMCR_LOOPBACK) | |
140 | printf("loopback, "); | |
141 | - if (bmcr & MII_BMCR_ISOLATE) | |
142 | + if (bmcr & BMCR_ISOLATE) | |
143 | printf("isolate, "); | |
144 | - if (bmcr & MII_BMCR_COLTEST) | |
145 | + if (bmcr & BMCR_CTST) | |
146 | printf("collision test, "); | |
147 | - if (bmcr & MII_BMCR_AN_ENA) { | |
148 | + if (bmcr & BMCR_ANENABLE) { | |
149 | printf("autonegotiation enabled\n"); | |
150 | } else { | |
151 | printf("%s Mbit, %s duplex\n", | |
152 | - (bmcr & MII_BMCR_100MBIT) ? "100" : "10", | |
153 | - (bmcr & MII_BMCR_DUPLEX) ? "full" : "half"); | |
154 | + (bmcr & BMCR_SPEED100) ? "100" : "10", | |
155 | + (bmcr & BMCR_FULLDPLX) ? "full" : "half"); | |
156 | } | |
157 | printf(" basic status: "); | |
158 | - if (bmsr & MII_BMSR_AN_COMPLETE) | |
159 | + if (bmsr & BMSR_ANEGCOMPLETE) | |
160 | printf("autonegotiation complete, "); | |
161 | - else if (bmcr & MII_BMCR_RESTART) | |
162 | + else if (bmcr & BMCR_ANRESTART) | |
163 | printf("autonegotiation restarted, "); | |
164 | - if (bmsr & MII_BMSR_REMOTE_FAULT) | |
165 | + if (bmsr & BMSR_RFAULT) | |
166 | printf("remote fault, "); | |
167 | - printf((bmsr & MII_BMSR_LINK_VALID) ? "link ok" : "no link"); | |
168 | + printf((bmsr & BMSR_LSTATUS) ? "link ok" : "no link"); | |
169 | printf("\n capabilities:%s", media_list(bmsr >> 6, 0)); | |
170 | printf("\n advertising: %s", media_list(advert, 0)); | |
171 | - if (lkpar & MII_AN_ABILITY_MASK) | |
172 | + if (lkpar & LPA_ABILITY_MASK) | |
173 | printf("\n link partner:%s", media_list(lkpar, 0)); | |
174 | printf("\n"); | |
175 | } | |
176 | @@ -310,7 +321,7 @@ int show_basic_mii(int sock, int phy_id) | |
177 | ||
178 | static int do_one_xcvr(int skfd, char *ifname, int maybe) | |
179 | { | |
180 | - struct mii_data *mii = (struct mii_data *)&ifr.ifr_data; | |
181 | + struct mii_ioctl_data *mii = (struct mii_ioctl_data *)&ifr.ifr_data; | |
182 | ||
183 | /* Get the vitals from the interface. */ | |
184 | strncpy(ifr.ifr_name, ifname, IFNAMSIZ); | |
185 | @@ -328,23 +339,23 @@ static int do_one_xcvr(int skfd, char *i | |
186 | ||
187 | if (opt_reset) { | |
188 | printf("resetting the transceiver...\n"); | |
189 | - mdio_write(skfd, MII_BMCR, MII_BMCR_RESET); | |
190 | + mdio_write(skfd, MII_BMCR, BMCR_RESET); | |
191 | } | |
192 | if (nway_advertise) { | |
193 | - mdio_write(skfd, MII_ANAR, nway_advertise | 1); | |
194 | + mdio_write(skfd, MII_ADVERTISE, nway_advertise | 1); | |
195 | opt_restart = 1; | |
196 | } | |
197 | if (opt_restart) { | |
198 | printf("restarting autonegotiation...\n"); | |
199 | mdio_write(skfd, MII_BMCR, 0x0000); | |
200 | - mdio_write(skfd, MII_BMCR, MII_BMCR_AN_ENA|MII_BMCR_RESTART); | |
201 | + mdio_write(skfd, MII_BMCR, BMCR_ANENABLE|BMCR_ANRESTART); | |
202 | } | |
203 | if (fixed_speed) { | |
204 | int bmcr = 0; | |
205 | - if (fixed_speed & (MII_AN_100BASETX_FD|MII_AN_100BASETX_HD)) | |
206 | - bmcr |= MII_BMCR_100MBIT; | |
207 | - if (fixed_speed & (MII_AN_100BASETX_FD|MII_AN_10BASET_FD)) | |
208 | - bmcr |= MII_BMCR_DUPLEX; | |
209 | + if (fixed_speed & (LPA_100FULL|LPA_100HALF)) | |
210 | + bmcr |= BMCR_SPEED100; | |
211 | + if (fixed_speed & (LPA_100FULL|LPA_10FULL)) | |
212 | + bmcr |= BMCR_FULLDPLX; | |
213 | mdio_write(skfd, MII_BMCR, bmcr); | |
214 | } | |
215 | ||
216 | @@ -358,7 +369,7 @@ static int do_one_xcvr(int skfd, char *i | |
217 | ||
218 | static void watch_one_xcvr(int skfd, char *ifname, int index) | |
219 | { | |
220 | - struct mii_data *mii = (struct mii_data *)&ifr.ifr_data; | |
221 | + struct mii_ioctl_data *mii = (struct mii_ioctl_data *)&ifr.ifr_data; | |
222 | static int status[MAX_ETH] = { 0, /* ... */ }; | |
223 | int now; | |
224 |