cornucopia: bump SRCREV
[openembedded.git] / recipes / mii-diag / mii-diag-2.11 / libmii.c
blob96f00605096e10637db5976a6fff9203e31ebe69
1 /* libmii.c: MII diagnostic and setup library.
3 Copyright 1997-2003 by Donald Becker.
4 This version released under the Gnu General Public License,
5 incorporated herein by reference.
6 This source code may be distributed without modification using the
7 existing notice. Any modification to this source code must include a
8 full notice as described in the GPL
9 Contact the author for use under other terms.
11 The author may be reached as becker@scyld.com, or C/O
12 Scyld Computing Corporation
13 914 Bay Ridge Road, Suite 220
14 Annapolis MD 21403
16 References
17 http://www.scyld.com/expert/NWay.html
18 http://www.national.com/pf/DP/DP83840A.html
21 static const char version_msg[] =
22 "libmii.c:v2.11 2/28/2005 Donald Becker (becker@scyld.com)\n"
23 " http://www.scyld.com/diag/index.html\n";
25 /* This library exports the following functions:
26 IOADDR: A token passed to the mdio_read() function.
27 PHY_ID: The MII transceiver address, passed uninterpreted to mdio_read().
29 void show_mii_details(long ioaddr, int phy_id);
30 int monitor_mii(long ioaddr, int phy_id);
32 /* This library expects to be able to call the following functions: */
33 extern int mdio_read(long ioaddr, int phy_id, int mii_reg_num);
35 #include <unistd.h>
36 #include <stdio.h>
37 #include <time.h>
38 #include <sys/time.h>
40 #include <sys/types.h>
41 typedef u_int32_t u32;
42 typedef u_int16_t u16;
43 typedef u_int8_t u8;
45 static const char *media_names[] = {
46 "10baseT", "10baseT-FD", "100baseTx", "100baseTx-FD", "100baseT4",
47 "Flow-control", 0,
50 static void ns83843(long ioaddr, int phy_id);
51 static void qs6612(long ioaddr, int phy_id);
52 static void smsc83c180(long ioaddr, int phy_id);
53 static void tdk78q2120(long ioaddr, int phy_id);
54 static void davicom_dm9101(long ioaddr, int phy_id);
55 static void intel_i553(long ioaddr, int phy_id);
56 static void enablesemi(long ioaddr, int phy_id);
57 static void amd_pna(long ioaddr, int phy_id);
58 static void amd_tx(long ioaddr, int phy_id);
59 static void admtek(long ioaddr, int phy_id);
60 static void lu3x31(long ioaddr, int phy_id);
61 static void myson981(long ioaddr, int phy_id);
62 static void via_tahoe(long ioaddr, int phy_id);
63 static void via_vt6103(long ioaddr, int phy_id);
64 static void via_vt6105(long ioaddr, int phy_id);
65 static void intel(long ioaddr, int phy_id);
67 struct mii_partnum {
68 const char *vendor; /* Vendor name. */
69 u16 phy_id0; /* Vendor ID (alternate ver. of ieee_oui[]) */
70 u16 phy_id1; /* Vendor ID (alternate ver. of ieee_oui[]) */
71 unsigned char ieee_oui[3]; /* IEEE-assigned organizationally unique ID */
72 char flags;
73 void (*(func))(long xcvr_if, int phy_id);/* Function to emit more info. */
74 } static oui_map[] = {
75 {"Unknown transceiver type", 0x0000, 0x0000, {0,}, 0, NULL,},
76 {"National Semiconductor 83840A", 0x2000, 0x5c01, {0,}, 0, NULL,},
77 {"National Semiconductor 83843", 0x2000, 0x5c10, {0,}, 0, ns83843, },
78 {"Level One LXT970", 0x7810, 0x0000, {0,}, 0, NULL, },
79 {"Level One LXT971", 0x7810, 0x0001, {0,}, 0, NULL, },
80 {"Level One LXT971A",0x7810, 0x0003, {0,}, 0, NULL, },
81 {"Level One (unknown type)", 0, 0, {0x1e,0x04,0x00}, 0, NULL, },
82 {"Davicom DM9101", 0x0181, 0xB800, {0,}, 0, davicom_dm9101, },
83 {"Davicom (unknown type)", 0, 0, {0x00, 0x60, 0x6e}, 0, davicom_dm9101, },
84 {"Quality Semiconductor QS6612", 0x0181, 0x4410, {0,}, 0, qs6612},
85 {"Quality Semiconductor (unknown type)", 0,0, {0x00, 0x60, 0x51}, 0, NULL},
86 {"SMSC 83c180", 0x0282, 0x1C51, {0}, 0, smsc83c180, },
87 {"TDK Semi 78Q2120 rev. 2", 0x0300, 0xE542, {0,}, 0, tdk78q2120, },
88 {"TDK Semi 78Q2120 rev. 3", 0x0300, 0xE543, {0,}, 0, tdk78q2120, },
89 {"TDK Semi 78Q2120 rev. 11", 0x0300, 0xE54B, {0,}, 0, tdk78q2120, },
90 {"TDK transceiver (unknown type)", 0,0, {0x00, 0xc0, 0x39}, 0, tdk78q2120},
91 {"Intel (unknown type)", 0,0, {0x00, 0xf8, 0x00}, 0, intel_i553},
92 {"Enable Semiconductor EL40-331", 0x0043, 0x7411, {0,}, 0, enablesemi},
93 {"AMD 79c901A.1 HomePNA", 0x0000, 0x6B91, {0,}, 0, amd_pna},
94 {"AMD 79c901A.2 HomePNA", 0x0000, 0x6B92, {0,}, 0, amd_pna},
95 {"AMD 79c901A.3 HomePNA", 0x0000, 0x6B93, {0,}, 0, amd_pna},
96 {"AMD 79c901A.3 10baseT", 0x0000, 0x6B71, {0,}, 0, amd_tx},
97 {"AdHoc Technology AH101LF", 0x0022, 0x561B, {0,}, 0, tdk78q2120},
98 {"Altimata Communications AC101LF", 0x0022, 0x5523, {0,}, 0, tdk78q2120},
99 {"Altimata Comm (unknown type)", 0, 0, {0x00,0x10,0xA9}, 0, tdk78q2120},
100 {"ASIX (unknown type)", 0, 0, {0x00,0xC0,0xB4}, 0, tdk78q2120},
101 {"ADMtek AN983 Comet", 0x0022, 0x5410, {0,}, 0, admtek},
102 {"ADMtek AN985 Comet", 0x0022, 0x5513, {0,}, 0, admtek},
103 {"ADMtek (unknown type)", 0, 0, {0x00,0xe0,0x92}, 0, admtek},
104 {"Lucent LU6612", 0x0180, 0x7641, {0,}, 0, qs6612},
105 {"Lucent LU3X31", 0x0043, 0x7411, {0,}, 0, lu3x31},
106 {"LSI Logic (Seeq) 80225", 0, 0, {0x00,0xA0,0x7D}, 0, NULL},
107 {"Myson MTD981", 0x0302, 0xD000, {0,}, 0, myson981},
108 {"Myson (unknown type)", 0, 0, {0x00,0xC0,0xB4,}, 0, myson981},
109 {"Alta/Kendin Sundance", 0x0022, 0x1720, {0,}, 0, NULL},
110 {"Alta/Kendin Sundance", 0, 0, {0x00,0x08,0x85}, 0, NULL},
111 {"VIA Tahoe VT6103", 0x0101, 0x8f20, {0,}, 0, via_vt6103},
112 {"VIA Tahoe VT6104", 0x0101, 0x8f30, {0,}, 0, via_tahoe},
113 {"VIA Rhine VT6105", 0x0101, 0x8f22, {0,}, 0, via_vt6105},
114 {"Intel 82557 series", 0x02a8, 0x0150, {0,}, 0, intel},
115 {"Intel 82555 rev 1", 0x02a8, 0x0151, {0,}, 0, intel},
116 {"Intel 82559 transceiver", 0x02a8, 0x0154, {0,}, 0, intel},
117 {"Intel 82555 series transceiver", 0,0, {0x00,0xaa,0x00}, 0, intel},
118 {0, },
121 static u16 mii_val[32];
123 void show_mii_details(long ioaddr, int phy_id)
125 int mii_reg, i, vendor = 0;
126 u16 bmcr, bmsr, new_bmsr;
128 /* This may not be omitted from the output. */
129 printf("%s", version_msg);
130 printf(" MII PHY #%d transceiver registers:", phy_id);
131 for (mii_reg = 0; mii_reg < 32; mii_reg++) {
132 mii_val[mii_reg] = mdio_read(ioaddr, phy_id, mii_reg);
133 printf("%s %4.4x", (mii_reg % 8) == 0 ? "\n " : "",
134 mii_val[mii_reg]);
136 printf(".\n");
137 if (mii_val[0] == 0xffff) {
138 printf(" No MII transceiver present!.\n");
139 return;
141 bmcr = mii_val[0];
142 bmsr = mii_val[1];
143 printf(" Basic mode control register 0x%4.4x:", bmcr);
144 if (bmcr & 0x1000)
145 printf(" Auto-negotiation enabled.\n");
146 else
147 printf(" Auto-negotiation disabled!\n"
148 " Speed fixed at 10%s mbps, %s-duplex.\n",
149 bmcr & 0x2000 ? "0" : "",
150 bmcr & 0x0100 ? "full":"half");
151 if (bmcr & 0x8000)
152 printf(" Transceiver currently being reset!\n");
153 if (bmcr & 0x4000)
154 printf(" Transceiver in loopback mode!\n");
155 if (bmcr & 0x0800)
156 printf(" Transceiver powered down!\n");
157 if (bmcr & 0x0400)
158 printf(" Transceiver isolated from the MII!\n");
159 if (bmcr & 0x0200)
160 printf(" Restarted auto-negotiation in progress!\n");
161 if (bmcr & 0x0080)
162 printf(" Internal Collision-Test enabled!\n");
164 new_bmsr = mdio_read(ioaddr, phy_id, 1);
165 printf(" Basic mode status register 0x%4.4x ... %4.4x.\n"
166 " Link status: %sestablished.\n"
167 " Capable of ",
168 bmsr, new_bmsr,
169 bmsr & 0x0004 ? "" :
170 (new_bmsr & 0x0004) ? "previously broken, but now re" : "not ");
171 if (bmsr & 0xF800) {
172 for (i = 15; i >= 11; i--)
173 if (bmsr & (1<<i))
174 printf(" %s", media_names[i-11]);
175 } else
176 printf("<Warning! No media capabilities>");
178 printf(".\n"
179 " %s to perform Auto-negotiation, negotiation %scomplete.\n",
180 bmsr & 0x0008 ? "Able" : "Unable",
181 bmsr & 0x0020 ? "" : "not ");
183 if (bmsr & 0x0010)
184 printf(" Remote fault detected!\n");
185 if (bmsr & 0x0002)
186 printf(" *** Link Jabber! ***\n");
188 if (mii_val[2] ^ mii_val[3]) { /* Eliminate 0x0000 and 0xffff IDs. */
189 unsigned char oui_0 = mii_val[2] >> 10;
190 unsigned char oui_1 = mii_val[2] >> 2;
191 unsigned char oui_2 = (mii_val[2] << 6) | (mii_val[3] >> 10);
193 printf(" Vendor ID is %2.2x:%2.2x:%2.2x:--:--:--, model %d rev. %d.\n",
194 oui_0, oui_1, oui_2,
195 ((mii_val[3] >> 4) & 0x3f), mii_val[3] & 0x0f);
196 for ( i = 0; oui_map[i].vendor; i++)
197 /* We match either the Phy ID or the IEEE OUI. */
198 if ((oui_map[i].phy_id0 == mii_val[2] &&
199 oui_map[i].phy_id1 == mii_val[3]) ||
200 (oui_map[i].ieee_oui[0] == oui_0 &&
201 oui_map[i].ieee_oui[1] == oui_1 &&
202 oui_map[i].ieee_oui[2] == oui_2)) {
203 printf(" Vendor/Part: %s.\n", oui_map[i].vendor);
204 vendor = i;
205 break;
207 if (oui_map[i].vendor == NULL)
208 printf(" No specific information is known about this transceiver"
209 " type.\n");
210 } else
211 printf(" This transceiver has no vendor identification.\n");
214 int nway_advert = mii_val[4];
215 int lkpar = mii_val[5];
216 printf(" I'm advertising %4.4x:", nway_advert);
217 for (i = 10; i >= 5; i--)
218 if (nway_advert & (1<<i))
219 printf(" %s", media_names[i-5]);
220 printf("\n Advertising %sadditional info pages.\n",
221 nway_advert & 0x8000 ? "" : "no ");
222 if ((nway_advert & 31) == 1)
223 printf(" IEEE 802.3 CSMA/CD protocol.\n");
224 else
225 printf(" Using an unknown (non 802.3) encapsulation.\n");
226 printf(" Link partner capability is %4.4x:",
227 lkpar);
228 for (i = 10; i >= 5; i--)
229 if (lkpar & (1<<i))
230 printf(" %s", media_names[i-5]);
231 printf(".\n Negotiation %s.\n",
232 lkpar & 0x4000 ? " completed" : "did not complete");
234 if (oui_map[vendor].func)
235 oui_map[vendor].func(ioaddr, phy_id);
239 int monitor_mii(long ioaddr, int phy_id)
241 int i, last_event = 0;
242 unsigned short new_1, baseline_1 = mdio_read(ioaddr, phy_id, 1);
243 struct timeval tv, sleepval;
244 time_t cur_time;
245 char timebuf[12];
247 if (baseline_1 == 0xffff) {
248 fprintf(stderr, "No MII transceiver present to monitor.\n");
249 return -1;
252 gettimeofday(&tv, NULL);
253 cur_time = tv.tv_sec;
254 strftime(timebuf, sizeof(timebuf), "%H:%M:%S", localtime(&cur_time));
256 printf("Monitoring the MII transceiver status.\n"
257 "%s.%03d Baseline value of MII BMSR (basic mode status register)"
258 " is %4.4x.\n", timebuf, (int)tv.tv_usec/1000, baseline_1);
259 while (1) {
260 new_1 = mdio_read(ioaddr, phy_id, 1);
261 if (new_1 == 0xffff) {
262 fprintf(stderr, "The MII transceiver is no longer accessable!\n");
263 return -1;
265 if (new_1 != baseline_1) {
266 gettimeofday(&tv, NULL);
267 cur_time = tv.tv_sec;
268 strftime(timebuf, sizeof(timebuf), "%H:%M:%S",
269 localtime(&cur_time));
270 printf("%s.%03d MII BMSR now %4.4x: %4s link, NWay %s, "
271 "%3sJabber%s (%4.4x).\n",
272 timebuf, (int)tv.tv_usec/1000, new_1,
273 new_1 & 0x04 ? "Good" : "no",
274 new_1 & 0x20 ? "done" : "busy",
275 new_1 & 0x02 ? "" : "No ",
276 new_1 & 0x10 ? ", remote fault" : "",
277 mdio_read(ioaddr, phy_id, 5)
279 if (!(baseline_1 & 0x20) && (new_1 & 0x20)) {
280 int lkpar = mdio_read(ioaddr, phy_id, 5);
281 printf(" New link partner capability is %4.4x %4.4x:",
282 lkpar, mdio_read(ioaddr, phy_id, 6));
283 switch (lkpar) {
284 case 0x45e1: printf(" 10/100 switch w/ flow control"); break;
285 case 0x41e1: printf(" 10/100 HD+FD switch"); break;
286 case 0x40a1: printf(" 10/100 bridged repeater"); break;
287 case 0x4081: printf(" 100baseTx repeater w/autonegotation");
288 break;
289 case 0x0081: printf(" 100baseTx (no autonegotation)"); break;
290 case 0x4021: printf(" 10baseT repeater w/autonegotation");
291 break;
292 case 0x0021: printf(" 10baseT (no autonegotation)"); break;
293 default:
294 for (i = 9; i >= 5; i--)
295 if (lkpar & (1<<i))
296 printf(" %s", media_names[i-5]);
298 printf(".\n");
300 fflush(stdout);
301 baseline_1 = new_1;
302 last_event = 0;
304 sleepval.tv_sec = 0;
305 sleepval.tv_usec = last_event++ > 30 ? 200000 : 1000;
306 select(0, 0, 0, 0, &sleepval); /* Or just sleep(1); */
308 printf(" Value of MII BMSR (basic mode status register) is %4.4x.\n",
309 mdio_read(ioaddr, phy_id, 1));
310 return 0;
313 /* Emit transceiver-specific info. */
315 struct msg_tbl { int bitmask; char *msg; };
317 static void msg_if_set(const int val, const struct msg_tbl msg_tbl[])
319 int i;
320 for (i = 0; msg_tbl[i].bitmask; i++)
321 if (msg_tbl[i].bitmask & val)
322 printf(" %s\n", msg_tbl[i].msg);
325 static void msg_if_set_fmt(const int val, const struct msg_tbl msg_tbl[],
326 const char *fmt)
328 int i;
329 for (i = 0; msg_tbl[i].bitmask; i++)
330 if (msg_tbl[i].bitmask & val)
331 printf(fmt, msg_tbl[i].msg);
334 static void qs6612(long ioaddr, int phy_id)
336 printf(" QS6612 extra registers: Mode %4.4x.\n"
337 " Interrupt source %4.4x, mask %4.4x.\n"
338 " PHY control %4.4x.\n",
339 mii_val[17], mii_val[29], mii_val[30], mii_val[31]);
340 return;
343 static void ns83843(long ioaddr, int phy_id)
345 printf(" NatSemi 83843 extra registers:\n"
346 " PHY status %4.4x\n"
347 " %s link, %d Mb/sec %s duplex\n"
348 " MII interrupts %sabled, %s pending.\n"
349 " Events since last read\n"
350 " Link disconnects %d\n"
351 " False carriers %d\n"
352 " Receive errors %d\n"
353 " Link beat is currently %sstable\n",
354 mii_val[0x10],
355 mii_val[10] & 0x0001 ? "Valid" : "Invalid",
356 mii_val[10] & 0x0002 ? 10 : 100,
357 mii_val[10] & 0x0004 ? "full" : "half",
358 mii_val[0x11] & 0x0002 ? "en":"dis",
359 mii_val[0x10] & 0x0100 ? "interrupt": "none",
360 mii_val[0x13], mii_val[0x14], mii_val[0x15],
361 mii_val[0x16] & 0x0010 ? "UN" : "");
362 return;
364 static void smsc83c180(long ioaddr, int phy_id)
366 int mii_reg25 = mii_val[25];
367 printf(" SMSC 83c180 extra registers:\n"
368 " Auto-negotiation status 0x%4.4x.\n"
369 " 10baseT polarity is %s.\n"
370 " PHY address is %d.\n"
371 " Auto-negotiation %scomplete, 1%s0Mbps %s duplex.\n"
372 " Rx symbol errors since last read %d.\n",
373 mii_reg25,
374 mii_reg25 & 0x2000 ? "normal" : "reversed",
375 (mii_reg25>>8) & 0x1F,
376 mii_reg25 & 0x0080 ? "did not " : "",
377 mii_reg25 & 0x0020 ? "0" : "",
378 mii_reg25 & 0x0040 ? "full" : "half",
379 mdio_read(ioaddr, phy_id, 26));
380 return;
383 static const char *tdk_events[8] = {
384 "Jabber", "Rx error", "Negotiation page received", "Link detection fault",
385 "Link partner acknowledge", "Link status change", "Remote partner fault",
386 "Auto-Negotiation complete"};
388 static const struct msg_tbl tdk_reg16[] = {
389 {0x8000, " Transceiver is in repeater mode!"},
390 {0x4000, " Interrupt pin set to active high."},
391 {0x2000, " Reserved bit 12 is unexpectedly set."},
392 {0x1000, " Transmit pins are internally disconnected."},
393 {0x0800, " 10baseT signal quality test is disabled."},
394 {0x0400, " 10baseT loopback mode."},
395 {0, 0},
398 static void tdk78q2120(long ioaddr, int phy_id)
400 int mii_reg16 = mii_val[16];
401 int mii_reg17 = mii_val[17];
402 int mii_reg18 = mii_val[18];
403 int i;
404 printf(" TDK format vendor-specific registers 16..18 are "
405 "0x%4.4x 0x%4.4x 0x%4.4x\n", mii_reg16, mii_reg17, mii_reg18);
406 printf(" Link polarity is %s %s.\n"
407 "%s%s"
408 " Auto-negotiation %s, 1%s0Mbps %s duplex.\n"
409 " Rx link in %s state, PLL %s.\n",
410 mii_reg16 & 0x0020 ? "OVERRIDDEN to" : "detected as",
411 mii_reg16 & 0x0010 ? "reversed" : "normal",
412 mii_reg16 & 0x0002 ?
413 " 100baseTx Coding and scrambling is disabled!\n":"",
414 mii_reg16 & 0x0001 ? " Rx_CLK power-save mode is enabled!\n":"",
415 mii_reg18 & 0x1000 ? "had no common media" : "complete",
416 mii_reg18 & 0x0400 ? "0" : "",
417 mii_reg18 & 0x0800 ? "full" : "half",
418 mii_reg18 & 0x0200 ? "pass" : "fail",
419 mii_reg18 & 0x0100 ? "slipped since last read" : "locked");
421 msg_if_set(mii_reg16, tdk_reg16);
422 if (mii_reg17 & 0x00ff) {
423 printf(" Events since last read:");
424 for (i = 0; i < 8; i++)
425 if (mii_reg17 & (1 << i))
426 printf(" %s", tdk_events[i]);
427 } else
428 printf(" No new link status events.");
430 if (mii_reg17 & 0xff00) {
431 printf("\n Events that will raise an interrupt:");
432 for (i = 0; i < 8; i++)
433 if (mii_reg17 & (0x100 << i))
434 printf(" %s", tdk_events[i]);
436 printf("\n");
437 return;
440 static void davicom_dm9101(long ioaddr, int phy_id)
442 printf(" Davicom vendor specific registers: 0x%4.4x 0x%4.4x 0x%4.4x.\n",
443 mii_val[16], mii_val[17], mii_val[18]);
445 static void intel_i553(long ioaddr, int phy_id)
447 printf(" This transceiver is 100baseT4 only! Register 16 is %4.4x.\n",
448 mii_val[16]);
450 /* http://www.enablesemi.com/cgi-bin/byteserve/Products/Docs/3VCardBus.pdf */
451 static void enablesemi(long ioaddr, int phy_id)
453 printf(" Isolated %d times, %d false carrier events, %d Rx errors.\n",
454 mii_val[18], mii_val[19], mii_val[21]);
455 printf(" Cable polarity is %s, 100Mb PLL is %slocked.\n",
456 mii_val[28]&0x8000 ? "reversed" : "normal",
457 mii_val[27]&0x2000 ? "" : "un");
459 /* The amd79c901 contains both PNA and 10/100 management registers.
460 http://www.amd.com/products/npd/techdocs/22304.pdf
462 static void amd_pna(long ioaddr, int phy_id)
464 printf(" HomePNA transceiver in %s speed, %s power mode.\n",
465 mii_val[16] & 4 ? "high" : "low",
466 mii_val[16] & 2 ? "high" : "low");
467 printf(" HomePNA noise level %d, peak power %d..\n",
468 mii_val[25] >> 8, mii_val[25] & 0xff);
470 static void amd_tx(long ioaddr, int phy_id)
472 int mii_reg25 = mii_val[25];
473 printf(" AMD vendor specific registers: 0x%4.4x 0x%4.4x 0x%4.4x.\n",
474 mii_val[16], mii_val[17], mii_val[18]);
475 printf(" The link is %s in 10%s %s duplex mode, autonegotiation state "
476 "has%s changed.\n",
477 mii_reg25 & 8 ? "up" : "down",
478 mii_reg25 & 1 ? "0baseTx" : "baseT",
479 mii_reg25 & 4 ? "full" : "half",
480 mii_reg25 & 2 ? "" : " not");
483 static const struct msg_tbl admtek_reg21[] = {
484 {0x4000, " Link test diabled: Ignoring lack of 10baseT link beat."},
485 {0x2000, " Link forced up."},
486 {0x1000, " Tx jabber check disabled."},
487 {0x0080, " Transmitting 'Far End Fault'!"},
488 {0x0040, " Rx error count full."},
489 {0x0008, " Remote loop back enabled."},
490 {0, 0},
493 static void admtek(long ioaddr, int phy_id)
496 printf(" ADMtek vendor specific registers information:\n"
497 " Cable length is approximately %d meters.\n"
498 " The receiver has lost lock %d times since last check and "
499 "had %d error events.\n",
500 ((mii_val[20] & 0x00f0) >> 4)*10,
501 mii_val[23], mii_val[23]);
502 msg_if_set(mii_val[21], admtek_reg21);
503 tdk78q2120(ioaddr, phy_id);
506 static void lu3x31(long ioaddr, int phy_id)
508 printf(" Lucent vendor specific registers 17: 0x%4.4x"
509 " 29: 0x%4.4x 30: 0x%4.4x 31: 0x%4.4x.\n",
510 mii_val[17], mii_val[29], mii_val[30], mii_val[31]);
513 static const struct msg_tbl myson_reg16[] = {
514 {0x0080, " Far end fault enabled."},
515 {0x0040, " Transformer ratio 1.25:1."},
516 {0x0020, " Polarity correction diabled."},
517 {0x0010, " Link is forced up regardless of link beat."},
518 {0x0004, " Bypass Jabber check."},
519 {0x0001, " 100baseFx mode selected."},
520 {0, 0},
523 static void myson981(long ioaddr, int phy_id)
525 int i, mii_reg17 = mii_val[17];
527 printf(" Myson mtd981 extra registers: %4.4x %4.4x %4.4x %4.4x.\n",
528 mii_val[16], mii_val[17], mii_val[18], mii_val[19]);
529 msg_if_set(mii_val[16] & 0xC800, tdk_reg16);
530 msg_if_set(mii_val[16], myson_reg16);
532 if (mii_reg17 & 0x00ff) {
533 printf(" Events since last read:");
534 for (i = 0; i < 8; i++)
535 if (mii_reg17 & (1 << i))
536 printf(" %s", tdk_events[i]);
537 } else
538 printf(" No new link status events.");
539 if (mii_reg17 & 0xff00) {
540 printf("\n Events that will raise an interrupt:");
541 for (i = 0; i < 8; i++)
542 if (mii_reg17 & (0x100 << i))
543 printf(" %s", tdk_events[i]);
545 printf("\n");
547 return;
550 /* These are much like the TDK events in reversed order. */
551 static const struct msg_tbl via_reg17[] = {
552 {0x0001, "Auto-Negotiation complete"},
553 {0x0002, "Remote fault detected"},
554 {0x0004, "Link failure detected"},
555 {0x0008, "Bad Start Stream detected"},
556 {0x0010, "Parallel detection fault"},
557 {0x0020, "Extended negotiation page received"},
558 {0x0040, "5B/4B code error detected"},
559 {0x0080, "Jabber detected"},
560 {0, 0},
563 static void via_tahoe(long ioaddr, int phy_id)
565 int mii_reg16 = mii_val[16];
566 int mii_reg17 = mii_val[17];
567 int mii_reg18 = mii_val[18];
569 printf(" VIA Tahoe extended registers: 16 %4.4x #17 %4.4x #18 %4.4x.\n",
570 mii_reg16, mii_reg17, mii_reg18);
571 msg_if_set_fmt(mii_reg17, via_reg17, " %s\n");
572 printf(" Link %s 10%s Mbps %s duplex\n",
573 mii_reg18 & 0x2000 ? "up" : "down",
574 mii_reg18 & 0x0400 ? "0" : "",
575 mii_reg18 & 0x0800 ? "full" : "half");
578 /* Information from
579 http://www.via.com.tw/en/datasheet/DS6103110.pdf
582 static void via_vt6103(long ioaddr, int phy_id)
584 printf(" VIA vt6103 error counts since the last check:\n"
585 " The link has failed %d times.\n"
586 " The receiver has lost lock %d times.\n"
587 " There have been %d false carrier/SQE error.\n",
588 mii_val[21], mii_val[22], mii_val[23]);
591 /* Information from
592 http://www.via.com.tw/en/Networking/DS6105LOM100.pdf
595 static void via_vt6105(long ioaddr, int phy_id)
597 printf(" VIA vt6105 PHY status:\n"
598 " Duplex %s speed %s\n",
599 mii_val[20] & 0x0001 ? "full" : "half",
600 mii_val[20] & 0x0002 ? "100" : "10");
603 /* Information from
604 http://www.via.com.tw/en/Networking/DS6105LOM100.pdf
606 static void intel(long ioaddr, int phy_id)
608 printf(" Intel 8255* PHY #%d extended management registers:\n"
609 " Error counts, cleared when read:\n"
610 " False carriers %d\n"
611 " Link disconnects %d\n"
612 " Receive errors %d\n"
613 " Rx symbol errors %d.\n"
614 " Rx 10Mbps Early End-Of-Frame errors %d.\n"
615 " Rx 100Mbps Early End-Of-Frame errors %d.\n"
616 " Tx jabber errors %d.\n",
617 mii_val[18],
618 mii_val[19], mii_val[20], mii_val[21], mii_val[22], mii_val[23],
619 mii_val[24], mii_val[25]);
624 * Local variables:
625 * compile-command: "cc -O -Wall -c libmii.c"
626 * c-indent-level: 4
627 * c-basic-offset: 4
628 * tab-width: 4
629 * End: