18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci drivers/net/ethernet/dec/tulip/timer.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 bugs to http://bugzilla.kernel.org/ . 118c2ecf20Sopenharmony_ci*/ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci#include "tulip.h" 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_civoid tulip_media_task(struct work_struct *work) 188c2ecf20Sopenharmony_ci{ 198c2ecf20Sopenharmony_ci struct tulip_private *tp = 208c2ecf20Sopenharmony_ci container_of(work, struct tulip_private, media_work); 218c2ecf20Sopenharmony_ci struct net_device *dev = tp->dev; 228c2ecf20Sopenharmony_ci void __iomem *ioaddr = tp->base_addr; 238c2ecf20Sopenharmony_ci u32 csr12 = ioread32(ioaddr + CSR12); 248c2ecf20Sopenharmony_ci int next_tick = 2*HZ; 258c2ecf20Sopenharmony_ci unsigned long flags; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci if (tulip_debug > 2) { 288c2ecf20Sopenharmony_ci netdev_dbg(dev, "Media selection tick, %s, status %08x mode %08x SIA %08x %08x %08x %08x\n", 298c2ecf20Sopenharmony_ci medianame[dev->if_port], 308c2ecf20Sopenharmony_ci ioread32(ioaddr + CSR5), ioread32(ioaddr + CSR6), 318c2ecf20Sopenharmony_ci csr12, ioread32(ioaddr + CSR13), 328c2ecf20Sopenharmony_ci ioread32(ioaddr + CSR14), ioread32(ioaddr + CSR15)); 338c2ecf20Sopenharmony_ci } 348c2ecf20Sopenharmony_ci switch (tp->chip_id) { 358c2ecf20Sopenharmony_ci case DC21140: 368c2ecf20Sopenharmony_ci case DC21142: 378c2ecf20Sopenharmony_ci case MX98713: 388c2ecf20Sopenharmony_ci case COMPEX9881: 398c2ecf20Sopenharmony_ci case DM910X: 408c2ecf20Sopenharmony_ci default: { 418c2ecf20Sopenharmony_ci struct medialeaf *mleaf; 428c2ecf20Sopenharmony_ci unsigned char *p; 438c2ecf20Sopenharmony_ci if (tp->mtable == NULL) { /* No EEPROM info, use generic code. */ 448c2ecf20Sopenharmony_ci /* Not much that can be done. 458c2ecf20Sopenharmony_ci Assume this a generic MII or SYM transceiver. */ 468c2ecf20Sopenharmony_ci next_tick = 60*HZ; 478c2ecf20Sopenharmony_ci if (tulip_debug > 2) 488c2ecf20Sopenharmony_ci netdev_dbg(dev, "network media monitor CSR6 %08x CSR12 0x%02x\n", 498c2ecf20Sopenharmony_ci ioread32(ioaddr + CSR6), 508c2ecf20Sopenharmony_ci csr12 & 0xff); 518c2ecf20Sopenharmony_ci break; 528c2ecf20Sopenharmony_ci } 538c2ecf20Sopenharmony_ci mleaf = &tp->mtable->mleaf[tp->cur_index]; 548c2ecf20Sopenharmony_ci p = mleaf->leafdata; 558c2ecf20Sopenharmony_ci switch (mleaf->type) { 568c2ecf20Sopenharmony_ci case 0: case 4: { 578c2ecf20Sopenharmony_ci /* Type 0 serial or 4 SYM transceiver. Check the link beat bit. */ 588c2ecf20Sopenharmony_ci int offset = mleaf->type == 4 ? 5 : 2; 598c2ecf20Sopenharmony_ci s8 bitnum = p[offset]; 608c2ecf20Sopenharmony_ci if (p[offset+1] & 0x80) { 618c2ecf20Sopenharmony_ci if (tulip_debug > 1) 628c2ecf20Sopenharmony_ci netdev_dbg(dev, "Transceiver monitor tick CSR12=%#02x, no media sense\n", 638c2ecf20Sopenharmony_ci csr12); 648c2ecf20Sopenharmony_ci if (mleaf->type == 4) { 658c2ecf20Sopenharmony_ci if (mleaf->media == 3 && (csr12 & 0x02)) 668c2ecf20Sopenharmony_ci goto select_next_media; 678c2ecf20Sopenharmony_ci } 688c2ecf20Sopenharmony_ci break; 698c2ecf20Sopenharmony_ci } 708c2ecf20Sopenharmony_ci if (tulip_debug > 2) 718c2ecf20Sopenharmony_ci netdev_dbg(dev, "Transceiver monitor tick: CSR12=%#02x bit %d is %d, expecting %d\n", 728c2ecf20Sopenharmony_ci csr12, (bitnum >> 1) & 7, 738c2ecf20Sopenharmony_ci (csr12 & (1 << ((bitnum >> 1) & 7))) != 0, 748c2ecf20Sopenharmony_ci (bitnum >= 0)); 758c2ecf20Sopenharmony_ci /* Check that the specified bit has the proper value. */ 768c2ecf20Sopenharmony_ci if ((bitnum < 0) != 778c2ecf20Sopenharmony_ci ((csr12 & (1 << ((bitnum >> 1) & 7))) != 0)) { 788c2ecf20Sopenharmony_ci if (tulip_debug > 2) 798c2ecf20Sopenharmony_ci netdev_dbg(dev, "Link beat detected for %s\n", 808c2ecf20Sopenharmony_ci medianame[mleaf->media & MEDIA_MASK]); 818c2ecf20Sopenharmony_ci if ((p[2] & 0x61) == 0x01) /* Bogus Znyx board. */ 828c2ecf20Sopenharmony_ci goto actually_mii; 838c2ecf20Sopenharmony_ci netif_carrier_on(dev); 848c2ecf20Sopenharmony_ci break; 858c2ecf20Sopenharmony_ci } 868c2ecf20Sopenharmony_ci netif_carrier_off(dev); 878c2ecf20Sopenharmony_ci if (tp->medialock) 888c2ecf20Sopenharmony_ci break; 898c2ecf20Sopenharmony_ci select_next_media: 908c2ecf20Sopenharmony_ci if (--tp->cur_index < 0) { 918c2ecf20Sopenharmony_ci /* We start again, but should instead look for default. */ 928c2ecf20Sopenharmony_ci tp->cur_index = tp->mtable->leafcount - 1; 938c2ecf20Sopenharmony_ci } 948c2ecf20Sopenharmony_ci dev->if_port = tp->mtable->mleaf[tp->cur_index].media; 958c2ecf20Sopenharmony_ci if (tulip_media_cap[dev->if_port] & MediaIsFD) 968c2ecf20Sopenharmony_ci goto select_next_media; /* Skip FD entries. */ 978c2ecf20Sopenharmony_ci if (tulip_debug > 1) 988c2ecf20Sopenharmony_ci netdev_dbg(dev, "No link beat on media %s, trying transceiver type %s\n", 998c2ecf20Sopenharmony_ci medianame[mleaf->media & MEDIA_MASK], 1008c2ecf20Sopenharmony_ci medianame[tp->mtable->mleaf[tp->cur_index].media]); 1018c2ecf20Sopenharmony_ci tulip_select_media(dev, 0); 1028c2ecf20Sopenharmony_ci /* Restart the transmit process. */ 1038c2ecf20Sopenharmony_ci tulip_restart_rxtx(tp); 1048c2ecf20Sopenharmony_ci next_tick = (24*HZ)/10; 1058c2ecf20Sopenharmony_ci break; 1068c2ecf20Sopenharmony_ci } 1078c2ecf20Sopenharmony_ci case 1: case 3: /* 21140, 21142 MII */ 1088c2ecf20Sopenharmony_ci actually_mii: 1098c2ecf20Sopenharmony_ci if (tulip_check_duplex(dev) < 0) { 1108c2ecf20Sopenharmony_ci netif_carrier_off(dev); 1118c2ecf20Sopenharmony_ci next_tick = 3*HZ; 1128c2ecf20Sopenharmony_ci } else { 1138c2ecf20Sopenharmony_ci netif_carrier_on(dev); 1148c2ecf20Sopenharmony_ci next_tick = 60*HZ; 1158c2ecf20Sopenharmony_ci } 1168c2ecf20Sopenharmony_ci break; 1178c2ecf20Sopenharmony_ci case 2: /* 21142 serial block has no link beat. */ 1188c2ecf20Sopenharmony_ci default: 1198c2ecf20Sopenharmony_ci break; 1208c2ecf20Sopenharmony_ci } 1218c2ecf20Sopenharmony_ci } 1228c2ecf20Sopenharmony_ci break; 1238c2ecf20Sopenharmony_ci } 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci spin_lock_irqsave(&tp->lock, flags); 1278c2ecf20Sopenharmony_ci if (tp->timeout_recovery) { 1288c2ecf20Sopenharmony_ci tulip_tx_timeout_complete(tp, ioaddr); 1298c2ecf20Sopenharmony_ci tp->timeout_recovery = 0; 1308c2ecf20Sopenharmony_ci } 1318c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&tp->lock, flags); 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci /* mod_timer synchronizes us with potential add_timer calls 1348c2ecf20Sopenharmony_ci * from interrupts. 1358c2ecf20Sopenharmony_ci */ 1368c2ecf20Sopenharmony_ci mod_timer(&tp->timer, RUN_AT(next_tick)); 1378c2ecf20Sopenharmony_ci} 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_civoid mxic_timer(struct timer_list *t) 1418c2ecf20Sopenharmony_ci{ 1428c2ecf20Sopenharmony_ci struct tulip_private *tp = from_timer(tp, t, timer); 1438c2ecf20Sopenharmony_ci struct net_device *dev = tp->dev; 1448c2ecf20Sopenharmony_ci void __iomem *ioaddr = tp->base_addr; 1458c2ecf20Sopenharmony_ci int next_tick = 60*HZ; 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci if (tulip_debug > 3) { 1488c2ecf20Sopenharmony_ci dev_info(&dev->dev, "MXIC negotiation status %08x\n", 1498c2ecf20Sopenharmony_ci ioread32(ioaddr + CSR12)); 1508c2ecf20Sopenharmony_ci } 1518c2ecf20Sopenharmony_ci if (next_tick) { 1528c2ecf20Sopenharmony_ci mod_timer(&tp->timer, RUN_AT(next_tick)); 1538c2ecf20Sopenharmony_ci } 1548c2ecf20Sopenharmony_ci} 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_civoid comet_timer(struct timer_list *t) 1588c2ecf20Sopenharmony_ci{ 1598c2ecf20Sopenharmony_ci struct tulip_private *tp = from_timer(tp, t, timer); 1608c2ecf20Sopenharmony_ci struct net_device *dev = tp->dev; 1618c2ecf20Sopenharmony_ci int next_tick = 2*HZ; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci if (tulip_debug > 1) 1648c2ecf20Sopenharmony_ci netdev_dbg(dev, "Comet link status %04x partner capability %04x\n", 1658c2ecf20Sopenharmony_ci tulip_mdio_read(dev, tp->phys[0], 1), 1668c2ecf20Sopenharmony_ci tulip_mdio_read(dev, tp->phys[0], 5)); 1678c2ecf20Sopenharmony_ci /* mod_timer synchronizes us with potential add_timer calls 1688c2ecf20Sopenharmony_ci * from interrupts. 1698c2ecf20Sopenharmony_ci */ 1708c2ecf20Sopenharmony_ci if (tulip_check_duplex(dev) < 0) 1718c2ecf20Sopenharmony_ci { netif_carrier_off(dev); } 1728c2ecf20Sopenharmony_ci else 1738c2ecf20Sopenharmony_ci { netif_carrier_on(dev); } 1748c2ecf20Sopenharmony_ci mod_timer(&tp->timer, RUN_AT(next_tick)); 1758c2ecf20Sopenharmony_ci} 1768c2ecf20Sopenharmony_ci 177