Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Paul Gortmaker | 3396c78 | 2012-01-27 13:36:01 +0000 | [diff] [blame^] | 2 | drivers/net/ethernet/dec/tulip/21142.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | Copyright 2000,2001 The Linux Kernel Team |
| 5 | Written/copyright 1994-2001 by Donald Becker. |
| 6 | |
| 7 | This software may be used and distributed according to the terms |
| 8 | of the GNU General Public License, incorporated herein by reference. |
| 9 | |
Philippe De Muyter | f99ec06 | 2009-01-29 17:35:04 -0800 | [diff] [blame] | 10 | DC21143 manual "21143 PCI/CardBus 10/100Mb/s Ethernet LAN Controller |
| 11 | Hardware Reference Manual" is currently available at : |
| 12 | http://developer.intel.com/design/network/manuals/278074.htm |
| 13 | |
Grant Grundler | 78a6551 | 2008-06-05 00:38:55 -0600 | [diff] [blame] | 14 | Please submit bugs to http://bugzilla.kernel.org/ . |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/delay.h> |
| 18 | #include "tulip.h" |
| 19 | |
| 20 | |
| 21 | static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, }; |
| 22 | u16 t21142_csr14[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, }; |
| 23 | static u16 t21142_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, }; |
| 24 | |
| 25 | |
| 26 | /* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list |
| 27 | of available transceivers. */ |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 28 | void t21142_media_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 30 | struct tulip_private *tp = |
| 31 | container_of(work, struct tulip_private, media_work); |
| 32 | struct net_device *dev = tp->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | void __iomem *ioaddr = tp->base_addr; |
| 34 | int csr12 = ioread32(ioaddr + CSR12); |
| 35 | int next_tick = 60*HZ; |
| 36 | int new_csr6 = 0; |
Philippe De Muyter | f99ec06 | 2009-01-29 17:35:04 -0800 | [diff] [blame] | 37 | int csr14 = ioread32(ioaddr + CSR14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Philippe De Muyter | f99ec06 | 2009-01-29 17:35:04 -0800 | [diff] [blame] | 39 | /* CSR12[LS10,LS100] are not reliable during autonegotiation */ |
| 40 | if ((csr14 & 0x80) && (csr12 & 0x7000) != 0x5000) |
| 41 | csr12 |= 6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | if (tulip_debug > 2) |
Joe Perches | 985a63e | 2010-01-28 20:59:18 +0000 | [diff] [blame] | 43 | dev_info(&dev->dev, "21143 negotiation status %08x, %s\n", |
| 44 | csr12, medianame[dev->if_port]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | if (tulip_media_cap[dev->if_port] & MediaIsMII) { |
| 46 | if (tulip_check_duplex(dev) < 0) { |
| 47 | netif_carrier_off(dev); |
| 48 | next_tick = 3*HZ; |
| 49 | } else { |
| 50 | netif_carrier_on(dev); |
| 51 | next_tick = 60*HZ; |
| 52 | } |
| 53 | } else if (tp->nwayset) { |
| 54 | /* Don't screw up a negotiated session! */ |
| 55 | if (tulip_debug > 1) |
Joe Perches | 985a63e | 2010-01-28 20:59:18 +0000 | [diff] [blame] | 56 | dev_info(&dev->dev, |
| 57 | "Using NWay-set %s media, csr12 %08x\n", |
| 58 | medianame[dev->if_port], csr12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } else if (tp->medialock) { |
| 60 | ; |
| 61 | } else if (dev->if_port == 3) { |
| 62 | if (csr12 & 2) { /* No 100mbps link beat, revert to 10mbps. */ |
| 63 | if (tulip_debug > 1) |
Joe Perches | 985a63e | 2010-01-28 20:59:18 +0000 | [diff] [blame] | 64 | dev_info(&dev->dev, |
| 65 | "No 21143 100baseTx link beat, %08x, trying NWay\n", |
| 66 | csr12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | t21142_start_nway(dev); |
| 68 | next_tick = 3*HZ; |
| 69 | } |
| 70 | } else if ((csr12 & 0x7000) != 0x5000) { |
| 71 | /* Negotiation failed. Search media types. */ |
| 72 | if (tulip_debug > 1) |
Joe Perches | 985a63e | 2010-01-28 20:59:18 +0000 | [diff] [blame] | 73 | dev_info(&dev->dev, |
| 74 | "21143 negotiation failed, status %08x\n", |
| 75 | csr12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | if (!(csr12 & 4)) { /* 10mbps link beat good. */ |
| 77 | new_csr6 = 0x82420000; |
| 78 | dev->if_port = 0; |
| 79 | iowrite32(0, ioaddr + CSR13); |
| 80 | iowrite32(0x0003FFFF, ioaddr + CSR14); |
| 81 | iowrite16(t21142_csr15[dev->if_port], ioaddr + CSR15); |
| 82 | iowrite32(t21142_csr13[dev->if_port], ioaddr + CSR13); |
| 83 | } else { |
| 84 | /* Select 100mbps port to check for link beat. */ |
| 85 | new_csr6 = 0x83860000; |
| 86 | dev->if_port = 3; |
| 87 | iowrite32(0, ioaddr + CSR13); |
Philippe De Muyter | f99ec06 | 2009-01-29 17:35:04 -0800 | [diff] [blame] | 88 | iowrite32(0x0003FFFF, ioaddr + CSR14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | iowrite16(8, ioaddr + CSR15); |
| 90 | iowrite32(1, ioaddr + CSR13); |
| 91 | } |
| 92 | if (tulip_debug > 1) |
Joe Perches | 985a63e | 2010-01-28 20:59:18 +0000 | [diff] [blame] | 93 | dev_info(&dev->dev, "Testing new 21143 media %s\n", |
| 94 | medianame[dev->if_port]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | if (new_csr6 != (tp->csr6 & ~0x00D5)) { |
| 96 | tp->csr6 &= 0x00D5; |
| 97 | tp->csr6 |= new_csr6; |
| 98 | iowrite32(0x0301, ioaddr + CSR12); |
| 99 | tulip_restart_rxtx(tp); |
| 100 | } |
| 101 | next_tick = 3*HZ; |
| 102 | } |
| 103 | |
| 104 | /* mod_timer synchronizes us with potential add_timer calls |
| 105 | * from interrupts. |
| 106 | */ |
| 107 | mod_timer(&tp->timer, RUN_AT(next_tick)); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | void t21142_start_nway(struct net_device *dev) |
| 112 | { |
| 113 | struct tulip_private *tp = netdev_priv(dev); |
| 114 | void __iomem *ioaddr = tp->base_addr; |
| 115 | int csr14 = ((tp->sym_advertise & 0x0780) << 9) | |
| 116 | ((tp->sym_advertise & 0x0020) << 1) | 0xffbf; |
| 117 | |
| 118 | dev->if_port = 0; |
| 119 | tp->nway = tp->mediasense = 1; |
| 120 | tp->nwayset = tp->lpar = 0; |
| 121 | if (tulip_debug > 1) |
Joe Perches | 726b65a | 2011-05-09 09:45:22 +0000 | [diff] [blame] | 122 | netdev_dbg(dev, "Restarting 21143 autonegotiation, csr14=%08x\n", |
| 123 | csr14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | iowrite32(0x0001, ioaddr + CSR13); |
| 125 | udelay(100); |
| 126 | iowrite32(csr14, ioaddr + CSR14); |
| 127 | tp->csr6 = 0x82420000 | (tp->sym_advertise & 0x0040 ? FullDuplex : 0); |
| 128 | iowrite32(tp->csr6, ioaddr + CSR6); |
| 129 | if (tp->mtable && tp->mtable->csr15dir) { |
| 130 | iowrite32(tp->mtable->csr15dir, ioaddr + CSR15); |
| 131 | iowrite32(tp->mtable->csr15val, ioaddr + CSR15); |
| 132 | } else |
| 133 | iowrite16(0x0008, ioaddr + CSR15); |
| 134 | iowrite32(0x1301, ioaddr + CSR12); /* Trigger NWAY. */ |
| 135 | } |
| 136 | |
| 137 | |
| 138 | |
| 139 | void t21142_lnk_change(struct net_device *dev, int csr5) |
| 140 | { |
| 141 | struct tulip_private *tp = netdev_priv(dev); |
| 142 | void __iomem *ioaddr = tp->base_addr; |
| 143 | int csr12 = ioread32(ioaddr + CSR12); |
Philippe De Muyter | f99ec06 | 2009-01-29 17:35:04 -0800 | [diff] [blame] | 144 | int csr14 = ioread32(ioaddr + CSR14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Philippe De Muyter | f99ec06 | 2009-01-29 17:35:04 -0800 | [diff] [blame] | 146 | /* CSR12[LS10,LS100] are not reliable during autonegotiation */ |
| 147 | if ((csr14 & 0x80) && (csr12 & 0x7000) != 0x5000) |
| 148 | csr12 |= 6; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | if (tulip_debug > 1) |
Joe Perches | 985a63e | 2010-01-28 20:59:18 +0000 | [diff] [blame] | 150 | dev_info(&dev->dev, |
| 151 | "21143 link status interrupt %08x, CSR5 %x, %08x\n", |
| 152 | csr12, csr5, csr14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | /* If NWay finished and we have a negotiated partner capability. */ |
| 155 | if (tp->nway && !tp->nwayset && (csr12 & 0x7000) == 0x5000) { |
| 156 | int setup_done = 0; |
| 157 | int negotiated = tp->sym_advertise & (csr12 >> 16); |
| 158 | tp->lpar = csr12 >> 16; |
| 159 | tp->nwayset = 1; |
Philippe De Muyter | f99ec06 | 2009-01-29 17:35:04 -0800 | [diff] [blame] | 160 | /* If partner cannot negotiate, it is 10Mbps Half Duplex */ |
| 161 | if (!(csr12 & 0x8000)) dev->if_port = 0; |
| 162 | else if (negotiated & 0x0100) dev->if_port = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | else if (negotiated & 0x0080) dev->if_port = 3; |
| 164 | else if (negotiated & 0x0040) dev->if_port = 4; |
| 165 | else if (negotiated & 0x0020) dev->if_port = 0; |
| 166 | else { |
| 167 | tp->nwayset = 0; |
| 168 | if ((csr12 & 2) == 0 && (tp->sym_advertise & 0x0180)) |
| 169 | dev->if_port = 3; |
| 170 | } |
| 171 | tp->full_duplex = (tulip_media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0; |
| 172 | |
| 173 | if (tulip_debug > 1) { |
| 174 | if (tp->nwayset) |
Joe Perches | 985a63e | 2010-01-28 20:59:18 +0000 | [diff] [blame] | 175 | dev_info(&dev->dev, |
| 176 | "Switching to %s based on link negotiation %04x & %04x = %04x\n", |
| 177 | medianame[dev->if_port], |
| 178 | tp->sym_advertise, tp->lpar, |
| 179 | negotiated); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | else |
Joe Perches | 985a63e | 2010-01-28 20:59:18 +0000 | [diff] [blame] | 181 | dev_info(&dev->dev, |
| 182 | "Autonegotiation failed, using %s, link beat status %04x\n", |
| 183 | medianame[dev->if_port], csr12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | if (tp->mtable) { |
| 187 | int i; |
| 188 | for (i = 0; i < tp->mtable->leafcount; i++) |
| 189 | if (tp->mtable->mleaf[i].media == dev->if_port) { |
Philippe De Muyter | 32b5bfa | 2005-09-22 11:09:44 +0200 | [diff] [blame] | 190 | int startup = ! ((tp->chip_id == DC21143 && (tp->revision == 48 || tp->revision == 65))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | tp->cur_index = i; |
| 192 | tulip_select_media(dev, startup); |
| 193 | setup_done = 1; |
| 194 | break; |
| 195 | } |
| 196 | } |
| 197 | if ( ! setup_done) { |
| 198 | tp->csr6 = (dev->if_port & 1 ? 0x838E0000 : 0x82420000) | (tp->csr6 & 0x20ff); |
| 199 | if (tp->full_duplex) |
| 200 | tp->csr6 |= 0x0200; |
| 201 | iowrite32(1, ioaddr + CSR13); |
| 202 | } |
| 203 | #if 0 /* Restart shouldn't be needed. */ |
| 204 | iowrite32(tp->csr6 | RxOn, ioaddr + CSR6); |
| 205 | if (tulip_debug > 2) |
Joe Perches | 726b65a | 2011-05-09 09:45:22 +0000 | [diff] [blame] | 206 | netdev_dbg(dev, " Restarting Tx and Rx, CSR5 is %08x\n", |
| 207 | ioread32(ioaddr + CSR5)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | #endif |
| 209 | tulip_start_rxtx(tp); |
| 210 | if (tulip_debug > 2) |
Joe Perches | 726b65a | 2011-05-09 09:45:22 +0000 | [diff] [blame] | 211 | netdev_dbg(dev, " Setting CSR6 %08x/%x CSR12 %08x\n", |
| 212 | tp->csr6, ioread32(ioaddr + CSR6), |
| 213 | ioread32(ioaddr + CSR12)); |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 214 | } else if ((tp->nwayset && (csr5 & 0x08000000) && |
| 215 | (dev->if_port == 3 || dev->if_port == 5) && |
| 216 | (csr12 & 2) == 2) || |
| 217 | (tp->nway && (csr5 & (TPLnkFail)))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | /* Link blew? Maybe restart NWay. */ |
| 219 | del_timer_sync(&tp->timer); |
| 220 | t21142_start_nway(dev); |
| 221 | tp->timer.expires = RUN_AT(3*HZ); |
| 222 | add_timer(&tp->timer); |
| 223 | } else if (dev->if_port == 3 || dev->if_port == 5) { |
| 224 | if (tulip_debug > 1) |
Joe Perches | 985a63e | 2010-01-28 20:59:18 +0000 | [diff] [blame] | 225 | dev_info(&dev->dev, "21143 %s link beat %s\n", |
| 226 | medianame[dev->if_port], |
| 227 | (csr12 & 2) ? "failed" : "good"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | if ((csr12 & 2) && ! tp->medialock) { |
| 229 | del_timer_sync(&tp->timer); |
| 230 | t21142_start_nway(dev); |
| 231 | tp->timer.expires = RUN_AT(3*HZ); |
| 232 | add_timer(&tp->timer); |
| 233 | } else if (dev->if_port == 5) |
Philippe De Muyter | f99ec06 | 2009-01-29 17:35:04 -0800 | [diff] [blame] | 234 | iowrite32(csr14 & ~0x080, ioaddr + CSR14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } else if (dev->if_port == 0 || dev->if_port == 4) { |
| 236 | if ((csr12 & 4) == 0) |
Joe Perches | 985a63e | 2010-01-28 20:59:18 +0000 | [diff] [blame] | 237 | dev_info(&dev->dev, "21143 10baseT link beat good\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } else if (!(csr12 & 4)) { /* 10mbps link beat good. */ |
| 239 | if (tulip_debug) |
Joe Perches | 985a63e | 2010-01-28 20:59:18 +0000 | [diff] [blame] | 240 | dev_info(&dev->dev, "21143 10mbps sensed media\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | dev->if_port = 0; |
| 242 | } else if (tp->nwayset) { |
| 243 | if (tulip_debug) |
Joe Perches | 985a63e | 2010-01-28 20:59:18 +0000 | [diff] [blame] | 244 | dev_info(&dev->dev, "21143 using NWay-set %s, csr6 %08x\n", |
| 245 | medianame[dev->if_port], tp->csr6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | } else { /* 100mbps link beat good. */ |
| 247 | if (tulip_debug) |
Joe Perches | 985a63e | 2010-01-28 20:59:18 +0000 | [diff] [blame] | 248 | dev_info(&dev->dev, "21143 100baseTx sensed media\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | dev->if_port = 3; |
| 250 | tp->csr6 = 0x838E0000 | (tp->csr6 & 0x20ff); |
| 251 | iowrite32(0x0003FF7F, ioaddr + CSR14); |
| 252 | iowrite32(0x0301, ioaddr + CSR12); |
| 253 | tulip_restart_rxtx(tp); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | |