18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci drivers/net/ethernet/dec/tulip/eeprom.c 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci Copyright 2000,2001 The Linux Kernel Team 58c2ecf20Sopenharmony_ci Written/copyright 1994-2001 by Donald Becker. 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci This software may be used and distributed according to the terms 88c2ecf20Sopenharmony_ci of the GNU General Public License, incorporated herein by reference. 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci Please submit bug reports to http://bugzilla.kernel.org/. 118c2ecf20Sopenharmony_ci*/ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/pci.h> 148c2ecf20Sopenharmony_ci#include <linux/slab.h> 158c2ecf20Sopenharmony_ci#include "tulip.h" 168c2ecf20Sopenharmony_ci#include <asm/unaligned.h> 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci/* Serial EEPROM section. */ 218c2ecf20Sopenharmony_ci/* The main routine to parse the very complicated SROM structure. 228c2ecf20Sopenharmony_ci Search www.digital.com for "21X4 SROM" to get details. 238c2ecf20Sopenharmony_ci This code is very complex, and will require changes to support 248c2ecf20Sopenharmony_ci additional cards, so I'll be verbose about what is going on. 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* Known cards that have old-style EEPROMs. */ 288c2ecf20Sopenharmony_cistatic struct eeprom_fixup eeprom_fixups[] = { 298c2ecf20Sopenharmony_ci {"Asante", 0, 0, 0x94, {0x1e00, 0x0000, 0x0800, 0x0100, 0x018c, 308c2ecf20Sopenharmony_ci 0x0000, 0x0000, 0xe078, 0x0001, 0x0050, 0x0018 }}, 318c2ecf20Sopenharmony_ci {"SMC9332DST", 0, 0, 0xC0, { 0x1e00, 0x0000, 0x0800, 0x041f, 328c2ecf20Sopenharmony_ci 0x0000, 0x009E, /* 10baseT */ 338c2ecf20Sopenharmony_ci 0x0004, 0x009E, /* 10baseT-FD */ 348c2ecf20Sopenharmony_ci 0x0903, 0x006D, /* 100baseTx */ 358c2ecf20Sopenharmony_ci 0x0905, 0x006D, /* 100baseTx-FD */ }}, 368c2ecf20Sopenharmony_ci {"Cogent EM100", 0, 0, 0x92, { 0x1e00, 0x0000, 0x0800, 0x063f, 378c2ecf20Sopenharmony_ci 0x0107, 0x8021, /* 100baseFx */ 388c2ecf20Sopenharmony_ci 0x0108, 0x8021, /* 100baseFx-FD */ 398c2ecf20Sopenharmony_ci 0x0100, 0x009E, /* 10baseT */ 408c2ecf20Sopenharmony_ci 0x0104, 0x009E, /* 10baseT-FD */ 418c2ecf20Sopenharmony_ci 0x0103, 0x006D, /* 100baseTx */ 428c2ecf20Sopenharmony_ci 0x0105, 0x006D, /* 100baseTx-FD */ }}, 438c2ecf20Sopenharmony_ci {"Maxtech NX-110", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x0513, 448c2ecf20Sopenharmony_ci 0x1001, 0x009E, /* 10base2, CSR12 0x10*/ 458c2ecf20Sopenharmony_ci 0x0000, 0x009E, /* 10baseT */ 468c2ecf20Sopenharmony_ci 0x0004, 0x009E, /* 10baseT-FD */ 478c2ecf20Sopenharmony_ci 0x0303, 0x006D, /* 100baseTx, CSR12 0x03 */ 488c2ecf20Sopenharmony_ci 0x0305, 0x006D, /* 100baseTx-FD CSR12 0x03 */}}, 498c2ecf20Sopenharmony_ci {"Accton EN1207", 0, 0, 0xE8, { 0x1e00, 0x0000, 0x0800, 0x051F, 508c2ecf20Sopenharmony_ci 0x1B01, 0x0000, /* 10base2, CSR12 0x1B */ 518c2ecf20Sopenharmony_ci 0x0B00, 0x009E, /* 10baseT, CSR12 0x0B */ 528c2ecf20Sopenharmony_ci 0x0B04, 0x009E, /* 10baseT-FD,CSR12 0x0B */ 538c2ecf20Sopenharmony_ci 0x1B03, 0x006D, /* 100baseTx, CSR12 0x1B */ 548c2ecf20Sopenharmony_ci 0x1B05, 0x006D, /* 100baseTx-FD CSR12 0x1B */ 558c2ecf20Sopenharmony_ci }}, 568c2ecf20Sopenharmony_ci {"NetWinder", 0x00, 0x10, 0x57, 578c2ecf20Sopenharmony_ci /* Default media = MII 588c2ecf20Sopenharmony_ci * MII block, reset sequence (3) = 0x0821 0x0000 0x0001, capabilities 0x01e1 598c2ecf20Sopenharmony_ci */ 608c2ecf20Sopenharmony_ci { 0x1e00, 0x0000, 0x000b, 0x8f01, 0x0103, 0x0300, 0x0821, 0x000, 0x0001, 0x0000, 0x01e1 } 618c2ecf20Sopenharmony_ci }, 628c2ecf20Sopenharmony_ci {"Cobalt Microserver", 0, 0x10, 0xE0, {0x1e00, /* 0 == controller #, 1e == offset */ 638c2ecf20Sopenharmony_ci 0x0000, /* 0 == high offset, 0 == gap */ 648c2ecf20Sopenharmony_ci 0x0800, /* Default Autoselect */ 658c2ecf20Sopenharmony_ci 0x8001, /* 1 leaf, extended type, bogus len */ 668c2ecf20Sopenharmony_ci 0x0003, /* Type 3 (MII), PHY #0 */ 678c2ecf20Sopenharmony_ci 0x0400, /* 0 init instr, 4 reset instr */ 688c2ecf20Sopenharmony_ci 0x0801, /* Set control mode, GP0 output */ 698c2ecf20Sopenharmony_ci 0x0000, /* Drive GP0 Low (RST is active low) */ 708c2ecf20Sopenharmony_ci 0x0800, /* control mode, GP0 input (undriven) */ 718c2ecf20Sopenharmony_ci 0x0000, /* clear control mode */ 728c2ecf20Sopenharmony_ci 0x7800, /* 100TX FDX + HDX, 10bT FDX + HDX */ 738c2ecf20Sopenharmony_ci 0x01e0, /* Advertise all above */ 748c2ecf20Sopenharmony_ci 0x5000, /* FDX all above */ 758c2ecf20Sopenharmony_ci 0x1800, /* Set fast TTM in 100bt modes */ 768c2ecf20Sopenharmony_ci 0x0000, /* PHY cannot be unplugged */ 778c2ecf20Sopenharmony_ci }}, 788c2ecf20Sopenharmony_ci {NULL}}; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_cistatic const char *const block_name[] = { 828c2ecf20Sopenharmony_ci "21140 non-MII", 838c2ecf20Sopenharmony_ci "21140 MII PHY", 848c2ecf20Sopenharmony_ci "21142 Serial PHY", 858c2ecf20Sopenharmony_ci "21142 MII PHY", 868c2ecf20Sopenharmony_ci "21143 SYM PHY", 878c2ecf20Sopenharmony_ci "21143 reset method" 888c2ecf20Sopenharmony_ci}; 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci/** 928c2ecf20Sopenharmony_ci * tulip_build_fake_mediatable - Build a fake mediatable entry. 938c2ecf20Sopenharmony_ci * @tp: Ptr to the tulip private data. 948c2ecf20Sopenharmony_ci * 958c2ecf20Sopenharmony_ci * Some cards like the 3x5 HSC cards (J3514A) do not have a standard 968c2ecf20Sopenharmony_ci * srom and can not be handled under the fixup routine. These cards 978c2ecf20Sopenharmony_ci * still need a valid mediatable entry for correct csr12 setup and 988c2ecf20Sopenharmony_ci * mii handling. 998c2ecf20Sopenharmony_ci * 1008c2ecf20Sopenharmony_ci * Since this is currently a parisc-linux specific function, the 1018c2ecf20Sopenharmony_ci * #ifdef __hppa__ should completely optimize this function away for 1028c2ecf20Sopenharmony_ci * non-parisc hardware. 1038c2ecf20Sopenharmony_ci */ 1048c2ecf20Sopenharmony_cistatic void tulip_build_fake_mediatable(struct tulip_private *tp) 1058c2ecf20Sopenharmony_ci{ 1068c2ecf20Sopenharmony_ci#ifdef CONFIG_GSC 1078c2ecf20Sopenharmony_ci if (tp->flags & NEEDS_FAKE_MEDIA_TABLE) { 1088c2ecf20Sopenharmony_ci static unsigned char leafdata[] = 1098c2ecf20Sopenharmony_ci { 0x01, /* phy number */ 1108c2ecf20Sopenharmony_ci 0x02, /* gpr setup sequence length */ 1118c2ecf20Sopenharmony_ci 0x02, 0x00, /* gpr setup sequence */ 1128c2ecf20Sopenharmony_ci 0x02, /* phy reset sequence length */ 1138c2ecf20Sopenharmony_ci 0x01, 0x00, /* phy reset sequence */ 1148c2ecf20Sopenharmony_ci 0x00, 0x78, /* media capabilities */ 1158c2ecf20Sopenharmony_ci 0x00, 0xe0, /* nway advertisement */ 1168c2ecf20Sopenharmony_ci 0x00, 0x05, /* fdx bit map */ 1178c2ecf20Sopenharmony_ci 0x00, 0x06 /* ttm bit map */ 1188c2ecf20Sopenharmony_ci }; 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci tp->mtable = kmalloc(sizeof(struct mediatable) + 1218c2ecf20Sopenharmony_ci sizeof(struct medialeaf), GFP_KERNEL); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci if (tp->mtable == NULL) 1248c2ecf20Sopenharmony_ci return; /* Horrible, impossible failure. */ 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci tp->mtable->defaultmedia = 0x800; 1278c2ecf20Sopenharmony_ci tp->mtable->leafcount = 1; 1288c2ecf20Sopenharmony_ci tp->mtable->csr12dir = 0x3f; /* inputs on bit7 for hsc-pci, bit6 for pci-fx */ 1298c2ecf20Sopenharmony_ci tp->mtable->has_nonmii = 0; 1308c2ecf20Sopenharmony_ci tp->mtable->has_reset = 0; 1318c2ecf20Sopenharmony_ci tp->mtable->has_mii = 1; 1328c2ecf20Sopenharmony_ci tp->mtable->csr15dir = tp->mtable->csr15val = 0; 1338c2ecf20Sopenharmony_ci tp->mtable->mleaf[0].type = 1; 1348c2ecf20Sopenharmony_ci tp->mtable->mleaf[0].media = 11; 1358c2ecf20Sopenharmony_ci tp->mtable->mleaf[0].leafdata = &leafdata[0]; 1368c2ecf20Sopenharmony_ci tp->flags |= HAS_PHY_IRQ; 1378c2ecf20Sopenharmony_ci tp->csr12_shadow = -1; 1388c2ecf20Sopenharmony_ci } 1398c2ecf20Sopenharmony_ci#endif 1408c2ecf20Sopenharmony_ci} 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_civoid tulip_parse_eeprom(struct net_device *dev) 1438c2ecf20Sopenharmony_ci{ 1448c2ecf20Sopenharmony_ci /* 1458c2ecf20Sopenharmony_ci dev is not registered at this point, so logging messages can't 1468c2ecf20Sopenharmony_ci use dev_<level> or netdev_<level> but dev->name is good via a 1478c2ecf20Sopenharmony_ci hack in the caller 1488c2ecf20Sopenharmony_ci */ 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci /* The last media info list parsed, for multiport boards. */ 1518c2ecf20Sopenharmony_ci static struct mediatable *last_mediatable; 1528c2ecf20Sopenharmony_ci static unsigned char *last_ee_data; 1538c2ecf20Sopenharmony_ci static int controller_index; 1548c2ecf20Sopenharmony_ci struct tulip_private *tp = netdev_priv(dev); 1558c2ecf20Sopenharmony_ci unsigned char *ee_data = tp->eeprom; 1568c2ecf20Sopenharmony_ci int i; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci tp->mtable = NULL; 1598c2ecf20Sopenharmony_ci /* Detect an old-style (SA only) EEPROM layout: 1608c2ecf20Sopenharmony_ci memcmp(eedata, eedata+16, 8). */ 1618c2ecf20Sopenharmony_ci for (i = 0; i < 8; i ++) 1628c2ecf20Sopenharmony_ci if (ee_data[i] != ee_data[16+i]) 1638c2ecf20Sopenharmony_ci break; 1648c2ecf20Sopenharmony_ci if (i >= 8) { 1658c2ecf20Sopenharmony_ci if (ee_data[0] == 0xff) { 1668c2ecf20Sopenharmony_ci if (last_mediatable) { 1678c2ecf20Sopenharmony_ci controller_index++; 1688c2ecf20Sopenharmony_ci pr_info("%s: Controller %d of multiport board\n", 1698c2ecf20Sopenharmony_ci dev->name, controller_index); 1708c2ecf20Sopenharmony_ci tp->mtable = last_mediatable; 1718c2ecf20Sopenharmony_ci ee_data = last_ee_data; 1728c2ecf20Sopenharmony_ci goto subsequent_board; 1738c2ecf20Sopenharmony_ci } else 1748c2ecf20Sopenharmony_ci pr_info("%s: Missing EEPROM, this interface may not work correctly!\n", 1758c2ecf20Sopenharmony_ci dev->name); 1768c2ecf20Sopenharmony_ci return; 1778c2ecf20Sopenharmony_ci } 1788c2ecf20Sopenharmony_ci /* Do a fix-up based on the vendor half of the station address prefix. */ 1798c2ecf20Sopenharmony_ci for (i = 0; eeprom_fixups[i].name; i++) { 1808c2ecf20Sopenharmony_ci if (dev->dev_addr[0] == eeprom_fixups[i].addr0 && 1818c2ecf20Sopenharmony_ci dev->dev_addr[1] == eeprom_fixups[i].addr1 && 1828c2ecf20Sopenharmony_ci dev->dev_addr[2] == eeprom_fixups[i].addr2) { 1838c2ecf20Sopenharmony_ci if (dev->dev_addr[2] == 0xE8 && ee_data[0x1a] == 0x55) 1848c2ecf20Sopenharmony_ci i++; /* An Accton EN1207, not an outlaw Maxtech. */ 1858c2ecf20Sopenharmony_ci memcpy(ee_data + 26, eeprom_fixups[i].newtable, 1868c2ecf20Sopenharmony_ci sizeof(eeprom_fixups[i].newtable)); 1878c2ecf20Sopenharmony_ci pr_info("%s: Old format EEPROM on '%s' board. Using substitute media control info\n", 1888c2ecf20Sopenharmony_ci dev->name, eeprom_fixups[i].name); 1898c2ecf20Sopenharmony_ci break; 1908c2ecf20Sopenharmony_ci } 1918c2ecf20Sopenharmony_ci } 1928c2ecf20Sopenharmony_ci if (eeprom_fixups[i].name == NULL) { /* No fixup found. */ 1938c2ecf20Sopenharmony_ci pr_info("%s: Old style EEPROM with no media selection information\n", 1948c2ecf20Sopenharmony_ci dev->name); 1958c2ecf20Sopenharmony_ci return; 1968c2ecf20Sopenharmony_ci } 1978c2ecf20Sopenharmony_ci } 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci controller_index = 0; 2008c2ecf20Sopenharmony_ci if (ee_data[19] > 1) { /* Multiport board. */ 2018c2ecf20Sopenharmony_ci last_ee_data = ee_data; 2028c2ecf20Sopenharmony_ci } 2038c2ecf20Sopenharmony_cisubsequent_board: 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci if (ee_data[27] == 0) { /* No valid media table. */ 2068c2ecf20Sopenharmony_ci tulip_build_fake_mediatable(tp); 2078c2ecf20Sopenharmony_ci } else { 2088c2ecf20Sopenharmony_ci unsigned char *p = (void *)ee_data + ee_data[27]; 2098c2ecf20Sopenharmony_ci unsigned char csr12dir = 0; 2108c2ecf20Sopenharmony_ci int count, new_advertise = 0; 2118c2ecf20Sopenharmony_ci struct mediatable *mtable; 2128c2ecf20Sopenharmony_ci u16 media = get_u16(p); 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci p += 2; 2158c2ecf20Sopenharmony_ci if (tp->flags & CSR12_IN_SROM) 2168c2ecf20Sopenharmony_ci csr12dir = *p++; 2178c2ecf20Sopenharmony_ci count = *p++; 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci /* there is no phy information, don't even try to build mtable */ 2208c2ecf20Sopenharmony_ci if (count == 0) { 2218c2ecf20Sopenharmony_ci if (tulip_debug > 0) 2228c2ecf20Sopenharmony_ci pr_warn("%s: no phy info, aborting mtable build\n", 2238c2ecf20Sopenharmony_ci dev->name); 2248c2ecf20Sopenharmony_ci return; 2258c2ecf20Sopenharmony_ci } 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci mtable = kmalloc(struct_size(mtable, mleaf, count), GFP_KERNEL); 2288c2ecf20Sopenharmony_ci if (mtable == NULL) 2298c2ecf20Sopenharmony_ci return; /* Horrible, impossible failure. */ 2308c2ecf20Sopenharmony_ci last_mediatable = tp->mtable = mtable; 2318c2ecf20Sopenharmony_ci mtable->defaultmedia = media; 2328c2ecf20Sopenharmony_ci mtable->leafcount = count; 2338c2ecf20Sopenharmony_ci mtable->csr12dir = csr12dir; 2348c2ecf20Sopenharmony_ci mtable->has_nonmii = mtable->has_mii = mtable->has_reset = 0; 2358c2ecf20Sopenharmony_ci mtable->csr15dir = mtable->csr15val = 0; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci pr_info("%s: EEPROM default media type %s\n", 2388c2ecf20Sopenharmony_ci dev->name, 2398c2ecf20Sopenharmony_ci media & 0x0800 ? "Autosense" 2408c2ecf20Sopenharmony_ci : medianame[media & MEDIA_MASK]); 2418c2ecf20Sopenharmony_ci for (i = 0; i < count; i++) { 2428c2ecf20Sopenharmony_ci struct medialeaf *leaf = &mtable->mleaf[i]; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci if ((p[0] & 0x80) == 0) { /* 21140 Compact block. */ 2458c2ecf20Sopenharmony_ci leaf->type = 0; 2468c2ecf20Sopenharmony_ci leaf->media = p[0] & 0x3f; 2478c2ecf20Sopenharmony_ci leaf->leafdata = p; 2488c2ecf20Sopenharmony_ci if ((p[2] & 0x61) == 0x01) /* Bogus, but Znyx boards do it. */ 2498c2ecf20Sopenharmony_ci mtable->has_mii = 1; 2508c2ecf20Sopenharmony_ci p += 4; 2518c2ecf20Sopenharmony_ci } else { 2528c2ecf20Sopenharmony_ci leaf->type = p[1]; 2538c2ecf20Sopenharmony_ci if (p[1] == 0x05) { 2548c2ecf20Sopenharmony_ci mtable->has_reset = i; 2558c2ecf20Sopenharmony_ci leaf->media = p[2] & 0x0f; 2568c2ecf20Sopenharmony_ci } else if (tp->chip_id == DM910X && p[1] == 0x80) { 2578c2ecf20Sopenharmony_ci /* Hack to ignore Davicom delay period block */ 2588c2ecf20Sopenharmony_ci mtable->leafcount--; 2598c2ecf20Sopenharmony_ci count--; 2608c2ecf20Sopenharmony_ci i--; 2618c2ecf20Sopenharmony_ci leaf->leafdata = p + 2; 2628c2ecf20Sopenharmony_ci p += (p[0] & 0x3f) + 1; 2638c2ecf20Sopenharmony_ci continue; 2648c2ecf20Sopenharmony_ci } else if (p[1] & 1) { 2658c2ecf20Sopenharmony_ci int gpr_len, reset_len; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci mtable->has_mii = 1; 2688c2ecf20Sopenharmony_ci leaf->media = 11; 2698c2ecf20Sopenharmony_ci gpr_len=p[3]*2; 2708c2ecf20Sopenharmony_ci reset_len=p[4+gpr_len]*2; 2718c2ecf20Sopenharmony_ci new_advertise |= get_u16(&p[7+gpr_len+reset_len]); 2728c2ecf20Sopenharmony_ci } else { 2738c2ecf20Sopenharmony_ci mtable->has_nonmii = 1; 2748c2ecf20Sopenharmony_ci leaf->media = p[2] & MEDIA_MASK; 2758c2ecf20Sopenharmony_ci /* Davicom's media number for 100BaseTX is strange */ 2768c2ecf20Sopenharmony_ci if (tp->chip_id == DM910X && leaf->media == 1) 2778c2ecf20Sopenharmony_ci leaf->media = 3; 2788c2ecf20Sopenharmony_ci switch (leaf->media) { 2798c2ecf20Sopenharmony_ci case 0: new_advertise |= 0x0020; break; 2808c2ecf20Sopenharmony_ci case 4: new_advertise |= 0x0040; break; 2818c2ecf20Sopenharmony_ci case 3: new_advertise |= 0x0080; break; 2828c2ecf20Sopenharmony_ci case 5: new_advertise |= 0x0100; break; 2838c2ecf20Sopenharmony_ci case 6: new_advertise |= 0x0200; break; 2848c2ecf20Sopenharmony_ci } 2858c2ecf20Sopenharmony_ci if (p[1] == 2 && leaf->media == 0) { 2868c2ecf20Sopenharmony_ci if (p[2] & 0x40) { 2878c2ecf20Sopenharmony_ci u32 base15 = get_unaligned((u16*)&p[7]); 2888c2ecf20Sopenharmony_ci mtable->csr15dir = 2898c2ecf20Sopenharmony_ci (get_unaligned((u16*)&p[9])<<16) + base15; 2908c2ecf20Sopenharmony_ci mtable->csr15val = 2918c2ecf20Sopenharmony_ci (get_unaligned((u16*)&p[11])<<16) + base15; 2928c2ecf20Sopenharmony_ci } else { 2938c2ecf20Sopenharmony_ci mtable->csr15dir = get_unaligned((u16*)&p[3])<<16; 2948c2ecf20Sopenharmony_ci mtable->csr15val = get_unaligned((u16*)&p[5])<<16; 2958c2ecf20Sopenharmony_ci } 2968c2ecf20Sopenharmony_ci } 2978c2ecf20Sopenharmony_ci } 2988c2ecf20Sopenharmony_ci leaf->leafdata = p + 2; 2998c2ecf20Sopenharmony_ci p += (p[0] & 0x3f) + 1; 3008c2ecf20Sopenharmony_ci } 3018c2ecf20Sopenharmony_ci if (tulip_debug > 1 && leaf->media == 11) { 3028c2ecf20Sopenharmony_ci unsigned char *bp = leaf->leafdata; 3038c2ecf20Sopenharmony_ci pr_info("%s: MII interface PHY %d, setup/reset sequences %d/%d long, capabilities %02x %02x\n", 3048c2ecf20Sopenharmony_ci dev->name, 3058c2ecf20Sopenharmony_ci bp[0], bp[1], bp[2 + bp[1]*2], 3068c2ecf20Sopenharmony_ci bp[5 + bp[2 + bp[1]*2]*2], 3078c2ecf20Sopenharmony_ci bp[4 + bp[2 + bp[1]*2]*2]); 3088c2ecf20Sopenharmony_ci } 3098c2ecf20Sopenharmony_ci pr_info("%s: Index #%d - Media %s (#%d) described by a %s (%d) block\n", 3108c2ecf20Sopenharmony_ci dev->name, 3118c2ecf20Sopenharmony_ci i, medianame[leaf->media & 15], leaf->media, 3128c2ecf20Sopenharmony_ci leaf->type < ARRAY_SIZE(block_name) ? block_name[leaf->type] : "<unknown>", 3138c2ecf20Sopenharmony_ci leaf->type); 3148c2ecf20Sopenharmony_ci } 3158c2ecf20Sopenharmony_ci if (new_advertise) 3168c2ecf20Sopenharmony_ci tp->sym_advertise = new_advertise; 3178c2ecf20Sopenharmony_ci } 3188c2ecf20Sopenharmony_ci} 3198c2ecf20Sopenharmony_ci/* Reading a serial EEPROM is a "bit" grungy, but we work our way through:->.*/ 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci/* EEPROM_Ctrl bits. */ 3228c2ecf20Sopenharmony_ci#define EE_SHIFT_CLK 0x02 /* EEPROM shift clock. */ 3238c2ecf20Sopenharmony_ci#define EE_CS 0x01 /* EEPROM chip select. */ 3248c2ecf20Sopenharmony_ci#define EE_DATA_WRITE 0x04 /* Data from the Tulip to EEPROM. */ 3258c2ecf20Sopenharmony_ci#define EE_WRITE_0 0x01 3268c2ecf20Sopenharmony_ci#define EE_WRITE_1 0x05 3278c2ecf20Sopenharmony_ci#define EE_DATA_READ 0x08 /* Data from the EEPROM chip. */ 3288c2ecf20Sopenharmony_ci#define EE_ENB (0x4800 | EE_CS) 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci/* Delay between EEPROM clock transitions. 3318c2ecf20Sopenharmony_ci Even at 33Mhz current PCI implementations don't overrun the EEPROM clock. 3328c2ecf20Sopenharmony_ci We add a bus turn-around to insure that this remains true. */ 3338c2ecf20Sopenharmony_ci#define eeprom_delay() ioread32(ee_addr) 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci/* The EEPROM commands include the alway-set leading bit. */ 3368c2ecf20Sopenharmony_ci#define EE_READ_CMD (6) 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci/* Note: this routine returns extra data bits for size detection. */ 3398c2ecf20Sopenharmony_ciint tulip_read_eeprom(struct net_device *dev, int location, int addr_len) 3408c2ecf20Sopenharmony_ci{ 3418c2ecf20Sopenharmony_ci int i; 3428c2ecf20Sopenharmony_ci unsigned retval = 0; 3438c2ecf20Sopenharmony_ci struct tulip_private *tp = netdev_priv(dev); 3448c2ecf20Sopenharmony_ci void __iomem *ee_addr = tp->base_addr + CSR9; 3458c2ecf20Sopenharmony_ci int read_cmd = location | (EE_READ_CMD << addr_len); 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci /* If location is past the end of what we can address, don't 3488c2ecf20Sopenharmony_ci * read some other location (ie truncate). Just return zero. 3498c2ecf20Sopenharmony_ci */ 3508c2ecf20Sopenharmony_ci if (location > (1 << addr_len) - 1) 3518c2ecf20Sopenharmony_ci return 0; 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci iowrite32(EE_ENB & ~EE_CS, ee_addr); 3548c2ecf20Sopenharmony_ci iowrite32(EE_ENB, ee_addr); 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci /* Shift the read command bits out. */ 3578c2ecf20Sopenharmony_ci for (i = 4 + addr_len; i >= 0; i--) { 3588c2ecf20Sopenharmony_ci short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0; 3598c2ecf20Sopenharmony_ci iowrite32(EE_ENB | dataval, ee_addr); 3608c2ecf20Sopenharmony_ci eeprom_delay(); 3618c2ecf20Sopenharmony_ci iowrite32(EE_ENB | dataval | EE_SHIFT_CLK, ee_addr); 3628c2ecf20Sopenharmony_ci eeprom_delay(); 3638c2ecf20Sopenharmony_ci retval = (retval << 1) | ((ioread32(ee_addr) & EE_DATA_READ) ? 1 : 0); 3648c2ecf20Sopenharmony_ci } 3658c2ecf20Sopenharmony_ci iowrite32(EE_ENB, ee_addr); 3668c2ecf20Sopenharmony_ci eeprom_delay(); 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci for (i = 16; i > 0; i--) { 3698c2ecf20Sopenharmony_ci iowrite32(EE_ENB | EE_SHIFT_CLK, ee_addr); 3708c2ecf20Sopenharmony_ci eeprom_delay(); 3718c2ecf20Sopenharmony_ci retval = (retval << 1) | ((ioread32(ee_addr) & EE_DATA_READ) ? 1 : 0); 3728c2ecf20Sopenharmony_ci iowrite32(EE_ENB, ee_addr); 3738c2ecf20Sopenharmony_ci eeprom_delay(); 3748c2ecf20Sopenharmony_ci } 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci /* Terminate the EEPROM access. */ 3778c2ecf20Sopenharmony_ci iowrite32(EE_ENB & ~EE_CS, ee_addr); 3788c2ecf20Sopenharmony_ci return (tp->flags & HAS_SWAPPED_SEEPROM) ? swab16(retval) : retval; 3798c2ecf20Sopenharmony_ci} 3808c2ecf20Sopenharmony_ci 381