Blame view
cmd/mii.c
12.2 KB
dd7d41f00 Initial revision |
1 2 3 4 |
/* * (C) Copyright 2001 * Gerald Van Baren, Custom IDEAS, vanbaren@cideas.com * |
1a4596601 Add GPL-2.0+ SPDX... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
dd7d41f00 Initial revision |
6 7 8 9 10 11 12 13 |
*/ /* * MII Utilities */ #include <common.h> #include <command.h> |
e35745bb6 * Temporarily dis... |
14 |
#include <miiphy.h> |
2471111d3 * Patch by John K... |
15 16 17 18 |
typedef struct _MII_reg_desc_t { ushort regno; char * name; } MII_reg_desc_t; |
3a5ee0b1d cmd_mii: localize... |
19 |
static const MII_reg_desc_t reg_0_5_desc_tbl[] = { |
8ef583a03 miiphy: convert t... |
20 21 22 23 24 25 |
{ MII_BMCR, "PHY control register" }, { MII_BMSR, "PHY status register" }, { MII_PHYSID1, "PHY ID 1 register" }, { MII_PHYSID2, "PHY ID 2 register" }, { MII_ADVERTISE, "Autonegotiation advertisement register" }, { MII_LPA, "Autonegotiation partner abilities register" }, |
2471111d3 * Patch by John K... |
26 27 28 29 30 31 32 33 |
}; typedef struct _MII_field_desc_t { ushort hi; ushort lo; ushort mask; char * name; } MII_field_desc_t; |
3a5ee0b1d cmd_mii: localize... |
34 |
static const MII_field_desc_t reg_0_desc_tbl[] = { |
2471111d3 * Patch by John K... |
35 36 37 38 39 40 41 42 43 44 45 |
{ 15, 15, 0x01, "reset" }, { 14, 14, 0x01, "loopback" }, { 13, 6, 0x81, "speed selection" }, /* special */ { 12, 12, 0x01, "A/N enable" }, { 11, 11, 0x01, "power-down" }, { 10, 10, 0x01, "isolate" }, { 9, 9, 0x01, "restart A/N" }, { 8, 8, 0x01, "duplex" }, /* special */ { 7, 7, 0x01, "collision test enable" }, { 5, 0, 0x3f, "(reserved)" } }; |
3a5ee0b1d cmd_mii: localize... |
46 |
static const MII_field_desc_t reg_1_desc_tbl[] = { |
2471111d3 * Patch by John K... |
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
{ 15, 15, 0x01, "100BASE-T4 able" }, { 14, 14, 0x01, "100BASE-X full duplex able" }, { 13, 13, 0x01, "100BASE-X half duplex able" }, { 12, 12, 0x01, "10 Mbps full duplex able" }, { 11, 11, 0x01, "10 Mbps half duplex able" }, { 10, 10, 0x01, "100BASE-T2 full duplex able" }, { 9, 9, 0x01, "100BASE-T2 half duplex able" }, { 8, 8, 0x01, "extended status" }, { 7, 7, 0x01, "(reserved)" }, { 6, 6, 0x01, "MF preamble suppression" }, { 5, 5, 0x01, "A/N complete" }, { 4, 4, 0x01, "remote fault" }, { 3, 3, 0x01, "A/N able" }, { 2, 2, 0x01, "link status" }, { 1, 1, 0x01, "jabber detect" }, { 0, 0, 0x01, "extended capabilities" }, }; |
3a5ee0b1d cmd_mii: localize... |
64 |
static const MII_field_desc_t reg_2_desc_tbl[] = { |
2471111d3 * Patch by John K... |
65 66 |
{ 15, 0, 0xffff, "OUI portion" }, }; |
3a5ee0b1d cmd_mii: localize... |
67 |
static const MII_field_desc_t reg_3_desc_tbl[] = { |
2471111d3 * Patch by John K... |
68 69 70 71 |
{ 15, 10, 0x3f, "OUI portion" }, { 9, 4, 0x3f, "manufacturer part number" }, { 3, 0, 0x0f, "manufacturer rev. number" }, }; |
3a5ee0b1d cmd_mii: localize... |
72 |
static const MII_field_desc_t reg_4_desc_tbl[] = { |
2471111d3 * Patch by John K... |
73 |
{ 15, 15, 0x01, "next page able" }, |
57d33d4b4 net: trivial: Fix... |
74 |
{ 14, 14, 0x01, "(reserved)" }, |
2471111d3 * Patch by John K... |
75 |
{ 13, 13, 0x01, "remote fault" }, |
57d33d4b4 net: trivial: Fix... |
76 |
{ 12, 12, 0x01, "(reserved)" }, |
2471111d3 * Patch by John K... |
77 78 79 80 81 82 83 84 85 |
{ 11, 11, 0x01, "asymmetric pause" }, { 10, 10, 0x01, "pause enable" }, { 9, 9, 0x01, "100BASE-T4 able" }, { 8, 8, 0x01, "100BASE-TX full duplex able" }, { 7, 7, 0x01, "100BASE-TX able" }, { 6, 6, 0x01, "10BASE-T full duplex able" }, { 5, 5, 0x01, "10BASE-T able" }, { 4, 0, 0x1f, "xxx to do" }, }; |
3a5ee0b1d cmd_mii: localize... |
86 |
static const MII_field_desc_t reg_5_desc_tbl[] = { |
2471111d3 * Patch by John K... |
87 88 89 90 91 92 93 94 95 96 97 98 99 |
{ 15, 15, 0x01, "next page able" }, { 14, 14, 0x01, "acknowledge" }, { 13, 13, 0x01, "remote fault" }, { 12, 12, 0x01, "(reserved)" }, { 11, 11, 0x01, "asymmetric pause able" }, { 10, 10, 0x01, "pause able" }, { 9, 9, 0x01, "100BASE-T4 able" }, { 8, 8, 0x01, "100BASE-X full duplex able" }, { 7, 7, 0x01, "100BASE-TX able" }, { 6, 6, 0x01, "10BASE-T full duplex able" }, { 5, 5, 0x01, "10BASE-T able" }, { 4, 0, 0x1f, "xxx to do" }, }; |
2471111d3 * Patch by John K... |
100 |
typedef struct _MII_field_desc_and_len_t { |
3a5ee0b1d cmd_mii: localize... |
101 |
const MII_field_desc_t *pdesc; |
2471111d3 * Patch by John K... |
102 103 |
ushort len; } MII_field_desc_and_len_t; |
3a5ee0b1d cmd_mii: localize... |
104 105 106 107 108 109 110 |
static const MII_field_desc_and_len_t desc_and_len_tbl[] = { { reg_0_desc_tbl, ARRAY_SIZE(reg_0_desc_tbl) }, { reg_1_desc_tbl, ARRAY_SIZE(reg_1_desc_tbl) }, { reg_2_desc_tbl, ARRAY_SIZE(reg_2_desc_tbl) }, { reg_3_desc_tbl, ARRAY_SIZE(reg_3_desc_tbl) }, { reg_4_desc_tbl, ARRAY_SIZE(reg_4_desc_tbl) }, { reg_5_desc_tbl, ARRAY_SIZE(reg_5_desc_tbl) }, |
2471111d3 * Patch by John K... |
111 112 113 114 |
}; static void dump_reg( ushort regval, |
3a5ee0b1d cmd_mii: localize... |
115 116 |
const MII_reg_desc_t *prd, const MII_field_desc_and_len_t *pdl); |
2471111d3 * Patch by John K... |
117 118 119 |
static int special_field( ushort regno, |
3a5ee0b1d cmd_mii: localize... |
120 |
const MII_field_desc_t *pdesc, |
2471111d3 * Patch by John K... |
121 |
ushort regval); |
3a5ee0b1d cmd_mii: localize... |
122 |
static void MII_dump_0_to_5( |
2471111d3 * Patch by John K... |
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
ushort regvals[6], uchar reglo, uchar reghi) { ulong i; for (i = 0; i < 6; i++) { if ((reglo <= i) && (i <= reghi)) dump_reg(regvals[i], ®_0_5_desc_tbl[i], &desc_and_len_tbl[i]); } } static void dump_reg( ushort regval, |
3a5ee0b1d cmd_mii: localize... |
138 139 |
const MII_reg_desc_t *prd, const MII_field_desc_and_len_t *pdl) |
2471111d3 * Patch by John K... |
140 141 142 |
{ ulong i; ushort mask_in_place; |
3a5ee0b1d cmd_mii: localize... |
143 |
const MII_field_desc_t *pdesc; |
2471111d3 * Patch by John K... |
144 145 146 147 148 149 150 151 152 |
printf("%u. (%04hx) -- %s -- ", prd->regno, regval, prd->name); for (i = 0; i < pdl->len; i++) { pdesc = &pdl->pdesc[i]; mask_in_place = pdesc->mask << pdesc->lo; |
c68112f3f common: cmd_mii: ... |
153 154 155 156 |
printf(" (%04hx:%04x) %u.", mask_in_place, regval & mask_in_place, prd->regno); |
2471111d3 * Patch by John K... |
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
if (special_field(prd->regno, pdesc, regval)) { } else { if (pdesc->hi == pdesc->lo) printf("%2u ", pdesc->lo); else printf("%2u-%2u", pdesc->hi, pdesc->lo); printf(" = %5u %s", (regval & mask_in_place) >> pdesc->lo, pdesc->name); } printf(" "); } printf(" "); } /* Special fields: ** 0.6,13 ** 0.8 ** 2.15-0 ** 3.15-0 ** 4.4-0 ** 5.4-0 */ static int special_field( ushort regno, |
3a5ee0b1d cmd_mii: localize... |
188 |
const MII_field_desc_t *pdesc, |
2471111d3 * Patch by John K... |
189 190 |
ushort regval) { |
8ef583a03 miiphy: convert t... |
191 192 |
if ((regno == MII_BMCR) && (pdesc->lo == 6)) { ushort speed_bits = regval & (BMCR_SPEED1000 | BMCR_SPEED100); |
2471111d3 * Patch by John K... |
193 194 195 196 |
printf("%2u,%2u = b%u%u speed selection = %s Mbps", 6, 13, (regval >> 6) & 1, (regval >> 13) & 1, |
8ef583a03 miiphy: convert t... |
197 198 199 |
speed_bits == BMCR_SPEED1000 ? "1000" : speed_bits == BMCR_SPEED100 ? "100" : "10"); |
2471111d3 * Patch by John K... |
200 201 |
return 1; } |
8ef583a03 miiphy: convert t... |
202 |
else if ((regno == MII_BMCR) && (pdesc->lo == 8)) { |
2471111d3 * Patch by John K... |
203 204 205 206 207 208 |
printf("%2u = %5u duplex = %s", pdesc->lo, (regval >> pdesc->lo) & 1, ((regval >> pdesc->lo) & 1) ? "full" : "half"); return 1; } |
8ef583a03 miiphy: convert t... |
209 |
else if ((regno == MII_ADVERTISE) && (pdesc->lo == 0)) { |
2471111d3 * Patch by John K... |
210 211 212 |
ushort sel_bits = (regval >> pdesc->lo) & pdesc->mask; printf("%2u-%2u = %5u selector = %s", pdesc->hi, pdesc->lo, sel_bits, |
b9711de10 * Patch by John K... |
213 |
sel_bits == PHY_ANLPAR_PSB_802_3 ? |
2471111d3 * Patch by John K... |
214 |
"IEEE 802.3" : |
b9711de10 * Patch by John K... |
215 |
sel_bits == PHY_ANLPAR_PSB_802_9 ? |
2471111d3 * Patch by John K... |
216 217 218 219 |
"IEEE 802.9 ISLAN-16T" : "???"); return 1; } |
8ef583a03 miiphy: convert t... |
220 |
else if ((regno == MII_LPA) && (pdesc->lo == 0)) { |
2471111d3 * Patch by John K... |
221 222 223 |
ushort sel_bits = (regval >> pdesc->lo) & pdesc->mask; printf("%2u-%2u = %u selector = %s", pdesc->hi, pdesc->lo, sel_bits, |
b9711de10 * Patch by John K... |
224 |
sel_bits == PHY_ANLPAR_PSB_802_3 ? |
2471111d3 * Patch by John K... |
225 |
"IEEE 802.3" : |
b9711de10 * Patch by John K... |
226 |
sel_bits == PHY_ANLPAR_PSB_802_9 ? |
2471111d3 * Patch by John K... |
227 228 229 230 231 232 233 |
"IEEE 802.9 ISLAN-16T" : "???"); return 1; } return 0; } |
3a5ee0b1d cmd_mii: localize... |
234 235 236 237 238 239 |
static char last_op[2]; static uint last_data; static uint last_addr_lo; static uint last_addr_hi; static uint last_reg_lo; static uint last_reg_hi; |
a095f047e mii: add read-mod... |
240 |
static uint last_mask; |
2471111d3 * Patch by John K... |
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
static void extract_range( char * input, unsigned char * plo, unsigned char * phi) { char * end; *plo = simple_strtoul(input, &end, 16); if (*end == '-') { end++; *phi = simple_strtoul(end, NULL, 16); } else { *phi = *plo; } } |
5cf91d6bd * Modify KUP4X bo... |
257 |
/* ---------------------------------------------------------------- */ |
3a5ee0b1d cmd_mii: localize... |
258 |
static int do_mii(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
2471111d3 * Patch by John K... |
259 |
{ |
63ff004c4 Add support for m... |
260 |
char op[2]; |
2471111d3 * Patch by John K... |
261 |
unsigned char addrlo, addrhi, reglo, reghi; |
2b792afcc * Fix PHY address... |
262 |
unsigned char addr, reg; |
a095f047e mii: add read-mod... |
263 |
unsigned short data, mask; |
2471111d3 * Patch by John K... |
264 |
int rcode = 0; |
5700bb635 miiphy: constify ... |
265 |
const char *devname; |
2471111d3 * Patch by John K... |
266 |
|
47e26b1bf cmd_usage(): simp... |
267 |
if (argc < 2) |
4c12eeb8b Convert cmd_usage... |
268 |
return CMD_RET_USAGE; |
b9173af73 common/cmd_mii.c:... |
269 |
|
0f3ba7e97 Add CONFIG_MII_IN... |
270 |
#if defined(CONFIG_MII_INIT) |
2471111d3 * Patch by John K... |
271 272 273 274 275 276 277 |
mii_init (); #endif /* * We use the last specified parameters, unless new ones are * entered. */ |
63ff004c4 Add support for m... |
278 279 |
op[0] = last_op[0]; op[1] = last_op[1]; |
2471111d3 * Patch by John K... |
280 281 282 283 284 |
addrlo = last_addr_lo; addrhi = last_addr_hi; reglo = last_reg_lo; reghi = last_reg_hi; data = last_data; |
a095f047e mii: add read-mod... |
285 |
mask = last_mask; |
2471111d3 * Patch by John K... |
286 287 |
if ((flag & CMD_FLAG_REPEAT) == 0) { |
63ff004c4 Add support for m... |
288 289 290 291 292 |
op[0] = argv[1][0]; if (strlen(argv[1]) > 1) op[1] = argv[1][1]; else op[1] = '\0'; |
2471111d3 * Patch by John K... |
293 294 295 296 297 |
if (argc >= 3) extract_range(argv[2], &addrlo, &addrhi); if (argc >= 4) extract_range(argv[3], ®lo, ®hi); if (argc >= 5) |
a095f047e mii: add read-mod... |
298 299 300 |
data = simple_strtoul(argv[4], NULL, 16); if (argc >= 6) mask = simple_strtoul(argv[5], NULL, 16); |
2471111d3 * Patch by John K... |
301 |
} |
bdaeb8f23 common: mii: Do n... |
302 303 304 305 306 |
if (addrhi > 31) { printf("Incorrect PHY address. Range should be 0-31 "); return CMD_RET_USAGE; } |
63ff004c4 Add support for m... |
307 308 |
/* use current device */ devname = miiphy_get_current_dev(); |
2471111d3 * Patch by John K... |
309 310 311 |
/* * check info/read/write. */ |
63ff004c4 Add support for m... |
312 |
if (op[0] == 'i') { |
2471111d3 * Patch by John K... |
313 314 315 316 317 318 319 320 321 |
unsigned char j, start, end; unsigned int oui; unsigned char model; unsigned char rev; /* * Look for any and all PHYs. Valid addresses are 0..31. */ if (argc >= 3) { |
2b792afcc * Fix PHY address... |
322 |
start = addrlo; end = addrhi; |
2471111d3 * Patch by John K... |
323 |
} else { |
2b792afcc * Fix PHY address... |
324 |
start = 0; end = 31; |
2471111d3 * Patch by John K... |
325 |
} |
2b792afcc * Fix PHY address... |
326 |
for (j = start; j <= end; j++) { |
63ff004c4 Add support for m... |
327 |
if (miiphy_info (devname, j, &oui, &model, &rev) == 0) { |
2471111d3 * Patch by John K... |
328 329 330 331 |
printf("PHY 0x%02X: " "OUI = 0x%04X, " "Model = 0x%02X, " "Rev = 0x%02X, " |
71bc6e647 NET: Add Ethernet... |
332 333 |
"%3dbase%s, %s ", |
2471111d3 * Patch by John K... |
334 |
j, oui, model, rev, |
63ff004c4 Add support for m... |
335 |
miiphy_speed (devname, j), |
71bc6e647 NET: Add Ethernet... |
336 337 |
miiphy_is_1000base_x (devname, j) ? "X" : "T", |
63ff004c4 Add support for m... |
338 339 |
(miiphy_duplex (devname, j) == FULL) ? "FDX" : "HDX"); |
2471111d3 * Patch by John K... |
340 341 |
} } |
63ff004c4 Add support for m... |
342 |
} else if (op[0] == 'r') { |
2471111d3 * Patch by John K... |
343 344 345 |
for (addr = addrlo; addr <= addrhi; addr++) { for (reg = reglo; reg <= reghi; reg++) { data = 0xffff; |
63ff004c4 Add support for m... |
346 |
if (miiphy_read (devname, addr, reg, &data) != 0) { |
2471111d3 * Patch by John K... |
347 348 349 350 351 |
printf( "Error reading from the PHY addr=%02x reg=%02x ", addr, reg); rcode = 1; |
2b792afcc * Fix PHY address... |
352 |
} else { |
2471111d3 * Patch by John K... |
353 354 355 356 357 358 359 360 361 362 363 |
if ((addrlo != addrhi) || (reglo != reghi)) printf("addr=%02x reg=%02x data=", (uint)addr, (uint)reg); printf("%04X ", data & 0x0000FFFF); } } if ((addrlo != addrhi) && (reglo != reghi)) printf(" "); } |
63ff004c4 Add support for m... |
364 |
} else if (op[0] == 'w') { |
2471111d3 * Patch by John K... |
365 366 |
for (addr = addrlo; addr <= addrhi; addr++) { for (reg = reglo; reg <= reghi; reg++) { |
63ff004c4 Add support for m... |
367 |
if (miiphy_write (devname, addr, reg, data) != 0) { |
2471111d3 * Patch by John K... |
368 369 370 371 372 373 374 |
printf("Error writing to the PHY addr=%02x reg=%02x ", addr, reg); rcode = 1; } } } |
a095f047e mii: add read-mod... |
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
} else if (op[0] == 'm') { for (addr = addrlo; addr <= addrhi; addr++) { for (reg = reglo; reg <= reghi; reg++) { unsigned short val = 0; if (miiphy_read(devname, addr, reg, &val)) { printf("Error reading from the PHY"); printf(" addr=%02x", addr); printf(" reg=%02x ", reg); rcode = 1; } else { val = (val & ~mask) | (data & mask); if (miiphy_write(devname, addr, reg, val)) { printf("Error writing to the PHY"); printf(" addr=%02x", addr); printf(" reg=%02x ", reg); rcode = 1; } } } } |
63ff004c4 Add support for m... |
399 |
} else if (strncmp(op, "du", 2) == 0) { |
2471111d3 * Patch by John K... |
400 401 402 403 404 405 406 407 408 409 |
ushort regs[6]; int ok = 1; if ((reglo > 5) || (reghi > 5)) { printf( "The MII dump command only formats the " "standard MII registers, 0-5. "); return 1; } for (addr = addrlo; addr <= addrhi; addr++) { |
63ff004c4 Add support for m... |
410 411 |
for (reg = reglo; reg < reghi + 1; reg++) { if (miiphy_read(devname, addr, reg, ®s[reg]) != 0) { |
2471111d3 * Patch by John K... |
412 413 414 415 416 417 418 419 420 421 422 423 424 |
ok = 0; printf( "Error reading from the PHY addr=%02x reg=%02x ", addr, reg); rcode = 1; } } if (ok) MII_dump_0_to_5(regs, reglo, reghi); printf(" "); } |
63ff004c4 Add support for m... |
425 426 427 428 429 |
} else if (strncmp(op, "de", 2) == 0) { if (argc == 2) miiphy_listdev (); else miiphy_set_current_dev (argv[2]); |
2471111d3 * Patch by John K... |
430 |
} else { |
4c12eeb8b Convert cmd_usage... |
431 |
return CMD_RET_USAGE; |
2471111d3 * Patch by John K... |
432 433 434 435 436 |
} /* * Save the parameters for repeats. */ |
63ff004c4 Add support for m... |
437 438 |
last_op[0] = op[0]; last_op[1] = op[1]; |
2471111d3 * Patch by John K... |
439 440 441 442 443 |
last_addr_lo = addrlo; last_addr_hi = addrhi; last_reg_lo = reglo; last_reg_hi = reghi; last_data = data; |
a095f047e mii: add read-mod... |
444 |
last_mask = mask; |
2471111d3 * Patch by John K... |
445 446 447 448 449 450 451 |
return rcode; } /***************************************************/ U_BOOT_CMD( |
a095f047e mii: add read-mod... |
452 |
mii, 6, 1, do_mii, |
2fb2604d5 Command usage cle... |
453 |
"MII utility commands", |
a095f047e mii: add read-mod... |
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
"device - list available devices " "mii device <devname> - set current device " "mii info <addr> - display MII PHY info " "mii read <addr> <reg> - read MII PHY <addr> register <reg> " "mii write <addr> <reg> <data> - write MII PHY <addr> register <reg> " "mii modify <addr> <reg> <data> <mask> - modify MII PHY <addr> register <reg> " " updating bits identified in <mask> " "mii dump <addr> <reg> - pretty-print <addr> <reg> (0-5 only) " |
a89c33db9 General help mess... |
470 |
"Addr and/or reg may be ranges, e.g. 2-7." |
2471111d3 * Patch by John K... |
471 |
); |