Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | drivers/net/tulip/pnic2.c |
| 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 | Modified to hep support PNIC_II by Kevin B. Hendricks |
| 7 | |
| 8 | This software may be used and distributed according to the terms |
| 9 | of the GNU General Public License, incorporated herein by reference. |
| 10 | |
| 11 | Please refer to Documentation/DocBook/tulip-user.{pdf,ps,html} |
Grant Grundler | 78a6551 | 2008-06-05 00:38:55 -0600 | [diff] [blame] | 12 | for more information on this driver. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 17 | |
| 18 | /* Understanding the PNIC_II - everything is this file is based |
| 19 | * on the PNIC_II_PDF datasheet which is sorely lacking in detail |
| 20 | * |
| 21 | * As I understand things, here are the registers and bits that |
| 22 | * explain the masks and constants used in this file that are |
| 23 | * either different from the 21142/3 or important for basic operation. |
| 24 | * |
| 25 | * |
| 26 | * CSR 6 (mask = 0xfe3bd1fd of bits not to change) |
| 27 | * ----- |
| 28 | * Bit 24 - SCR |
| 29 | * Bit 23 - PCS |
| 30 | * Bit 22 - TTM (Trasmit Threshold Mode) |
| 31 | * Bit 18 - Port Select |
| 32 | * Bit 13 - Start - 1, Stop - 0 Transmissions |
| 33 | * Bit 11:10 - Loop Back Operation Mode |
| 34 | * Bit 9 - Full Duplex mode (Advertise 10BaseT-FD is CSR14<7> is set) |
| 35 | * Bit 1 - Start - 1, Stop - 0 Receive |
| 36 | * |
| 37 | * |
| 38 | * CSR 14 (mask = 0xfff0ee39 of bits not to change) |
| 39 | * ------ |
| 40 | * Bit 19 - PAUSE-Pause |
| 41 | * Bit 18 - Advertise T4 |
| 42 | * Bit 17 - Advertise 100baseTx-FD |
| 43 | * Bit 16 - Advertise 100baseTx-HD |
| 44 | * Bit 12 - LTE - Link Test Enable |
| 45 | * Bit 7 - ANE - Auto Negotiate Enable |
| 46 | * Bit 6 - HDE - Advertise 10baseT-HD |
| 47 | * Bit 2 - Reset to Power down - kept as 1 for normal operation |
| 48 | * Bit 1 - Loop Back enable for 10baseT MCC |
| 49 | * |
| 50 | * |
| 51 | * CSR 12 |
| 52 | * ------ |
| 53 | * Bit 25 - Partner can do T4 |
| 54 | * Bit 24 - Partner can do 100baseTx-FD |
| 55 | * Bit 23 - Partner can do 100baseTx-HD |
| 56 | * Bit 22 - Partner can do 10baseT-FD |
| 57 | * Bit 21 - Partner can do 10baseT-HD |
| 58 | * Bit 15 - LPN is 1 if all above bits are valid other wise 0 |
| 59 | * Bit 14:12 - autonegotiation state (write 001 to start autonegotiate) |
| 60 | * Bit 3 - Autopolarity state |
| 61 | * Bit 2 - LS10B - link state of 10baseT 0 - good, 1 - failed |
Paul Bolle | 426d310 | 2010-08-07 12:30:03 +0200 | [diff] [blame^] | 62 | * Bit 1 - LS100B - link state of 100baseT 0 - good, 1 - failed |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | * |
| 64 | * |
| 65 | * Data Port Selection Info |
| 66 | *------------------------- |
| 67 | * |
| 68 | * CSR14<7> CSR6<18> CSR6<22> CSR6<23> CSR6<24> MODE/PORT |
| 69 | * 1 0 0 (X) 0 (X) 1 NWAY |
| 70 | * 0 0 1 0 (X) 0 10baseT |
| 71 | * 0 1 0 1 1 (X) 100baseT |
| 72 | * |
| 73 | * |
| 74 | */ |
| 75 | |
| 76 | |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #include "tulip.h" |
| 79 | #include <linux/delay.h> |
| 80 | |
| 81 | |
| 82 | void pnic2_timer(unsigned long data) |
| 83 | { |
| 84 | struct net_device *dev = (struct net_device *)data; |
| 85 | struct tulip_private *tp = netdev_priv(dev); |
| 86 | void __iomem *ioaddr = tp->base_addr; |
| 87 | int next_tick = 60*HZ; |
| 88 | |
| 89 | if (tulip_debug > 3) |
Joe Perches | 22086a1 | 2010-01-28 20:59:25 +0000 | [diff] [blame] | 90 | dev_info(&dev->dev, "PNIC2 negotiation status %08x\n", |
| 91 | ioread32(ioaddr + CSR12)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | if (next_tick) { |
| 94 | mod_timer(&tp->timer, RUN_AT(next_tick)); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | |
| 99 | void pnic2_start_nway(struct net_device *dev) |
| 100 | { |
| 101 | struct tulip_private *tp = netdev_priv(dev); |
| 102 | void __iomem *ioaddr = tp->base_addr; |
| 103 | int csr14; |
| 104 | int csr12; |
| 105 | |
| 106 | /* set up what to advertise during the negotiation */ |
| 107 | |
| 108 | /* load in csr14 and mask off bits not to touch |
| 109 | * comment at top of file explains mask value |
| 110 | */ |
| 111 | csr14 = (ioread32(ioaddr + CSR14) & 0xfff0ee39); |
| 112 | |
| 113 | /* bit 17 - advetise 100baseTx-FD */ |
| 114 | if (tp->sym_advertise & 0x0100) csr14 |= 0x00020000; |
| 115 | |
| 116 | /* bit 16 - advertise 100baseTx-HD */ |
| 117 | if (tp->sym_advertise & 0x0080) csr14 |= 0x00010000; |
| 118 | |
| 119 | /* bit 6 - advertise 10baseT-HD */ |
| 120 | if (tp->sym_advertise & 0x0020) csr14 |= 0x00000040; |
| 121 | |
| 122 | /* Now set bit 12 Link Test Enable, Bit 7 Autonegotiation Enable |
| 123 | * and bit 0 Don't PowerDown 10baseT |
| 124 | */ |
| 125 | csr14 |= 0x00001184; |
| 126 | |
| 127 | if (tulip_debug > 1) |
Joe Perches | 22086a1 | 2010-01-28 20:59:25 +0000 | [diff] [blame] | 128 | printk(KERN_DEBUG "%s: Restarting PNIC2 autonegotiation, csr14=%08x\n", |
| 129 | dev->name, csr14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | /* tell pnic2_lnk_change we are doing an nway negotiation */ |
| 132 | dev->if_port = 0; |
| 133 | tp->nway = tp->mediasense = 1; |
| 134 | tp->nwayset = tp->lpar = 0; |
| 135 | |
| 136 | /* now we have to set up csr6 for NWAY state */ |
| 137 | |
| 138 | tp->csr6 = ioread32(ioaddr + CSR6); |
| 139 | if (tulip_debug > 1) |
Joe Perches | 22086a1 | 2010-01-28 20:59:25 +0000 | [diff] [blame] | 140 | printk(KERN_DEBUG "%s: On Entry to Nway, csr6=%08x\n", |
| 141 | dev->name, tp->csr6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
| 143 | /* mask off any bits not to touch |
| 144 | * comment at top of file explains mask value |
| 145 | */ |
| 146 | tp->csr6 = tp->csr6 & 0xfe3bd1fd; |
| 147 | |
| 148 | /* don't forget that bit 9 is also used for advertising */ |
| 149 | /* advertise 10baseT-FD for the negotiation (bit 9) */ |
| 150 | if (tp->sym_advertise & 0x0040) tp->csr6 |= 0x00000200; |
| 151 | |
| 152 | /* set bit 24 for nway negotiation mode ... |
| 153 | * see Data Port Selection comment at top of file |
| 154 | * and "Stop" - reset both Transmit (bit 13) and Receive (bit 1) |
| 155 | */ |
| 156 | tp->csr6 |= 0x01000000; |
| 157 | iowrite32(csr14, ioaddr + CSR14); |
| 158 | iowrite32(tp->csr6, ioaddr + CSR6); |
| 159 | udelay(100); |
| 160 | |
| 161 | /* all set up so now force the negotiation to begin */ |
| 162 | |
| 163 | /* read in current values and mask off all but the |
| 164 | * Autonegotiation bits 14:12. Writing a 001 to those bits |
| 165 | * should start the autonegotiation |
| 166 | */ |
| 167 | csr12 = (ioread32(ioaddr + CSR12) & 0xffff8fff); |
| 168 | csr12 |= 0x1000; |
| 169 | iowrite32(csr12, ioaddr + CSR12); |
| 170 | } |
| 171 | |
| 172 | |
| 173 | |
| 174 | void pnic2_lnk_change(struct net_device *dev, int csr5) |
| 175 | { |
| 176 | struct tulip_private *tp = netdev_priv(dev); |
| 177 | void __iomem *ioaddr = tp->base_addr; |
| 178 | int csr14; |
| 179 | |
| 180 | /* read the staus register to find out what is up */ |
| 181 | int csr12 = ioread32(ioaddr + CSR12); |
| 182 | |
| 183 | if (tulip_debug > 1) |
Joe Perches | 22086a1 | 2010-01-28 20:59:25 +0000 | [diff] [blame] | 184 | dev_info(&dev->dev, |
| 185 | "PNIC2 link status interrupt %08x, CSR5 %x, %08x\n", |
| 186 | csr12, csr5, ioread32(ioaddr + CSR14)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | /* If NWay finished and we have a negotiated partner capability. |
| 189 | * check bits 14:12 for bit pattern 101 - all is good |
| 190 | */ |
| 191 | if (tp->nway && !tp->nwayset) { |
| 192 | |
| 193 | /* we did an auto negotiation */ |
| 194 | |
| 195 | if ((csr12 & 0x7000) == 0x5000) { |
| 196 | |
| 197 | /* negotiation ended successfully */ |
| 198 | |
| 199 | /* get the link partners reply and mask out all but |
Alexey Dobriyan | 7f927fc | 2006-03-28 01:56:53 -0800 | [diff] [blame] | 200 | * bits 24-21 which show the partners capabilities |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | * and match those to what we advertised |
| 202 | * |
| 203 | * then begin to interpret the results of the negotiation. |
| 204 | * Always go in this order : (we are ignoring T4 for now) |
| 205 | * 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD |
| 206 | */ |
| 207 | |
| 208 | int negotiated = ((csr12 >> 16) & 0x01E0) & tp->sym_advertise; |
| 209 | tp->lpar = (csr12 >> 16); |
| 210 | tp->nwayset = 1; |
| 211 | |
| 212 | if (negotiated & 0x0100) dev->if_port = 5; |
| 213 | else if (negotiated & 0x0080) dev->if_port = 3; |
| 214 | else if (negotiated & 0x0040) dev->if_port = 4; |
| 215 | else if (negotiated & 0x0020) dev->if_port = 0; |
| 216 | else { |
| 217 | if (tulip_debug > 1) |
Joe Perches | 22086a1 | 2010-01-28 20:59:25 +0000 | [diff] [blame] | 218 | dev_info(&dev->dev, |
| 219 | "funny autonegotiate result csr12 %08x advertising %04x\n", |
| 220 | csr12, tp->sym_advertise); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | tp->nwayset = 0; |
| 222 | /* so check if 100baseTx link state is okay */ |
| 223 | if ((csr12 & 2) == 0 && (tp->sym_advertise & 0x0180)) |
| 224 | dev->if_port = 3; |
| 225 | } |
| 226 | |
| 227 | /* now record the duplex that was negotiated */ |
| 228 | tp->full_duplex = 0; |
| 229 | if ((dev->if_port == 4) || (dev->if_port == 5)) |
| 230 | tp->full_duplex = 1; |
| 231 | |
| 232 | if (tulip_debug > 1) { |
| 233 | if (tp->nwayset) |
Joe Perches | 22086a1 | 2010-01-28 20:59:25 +0000 | [diff] [blame] | 234 | dev_info(&dev->dev, |
| 235 | "Switching to %s based on link negotiation %04x & %04x = %04x\n", |
| 236 | medianame[dev->if_port], |
| 237 | tp->sym_advertise, tp->lpar, |
| 238 | negotiated); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | /* remember to turn off bit 7 - autonegotiate |
| 242 | * enable so we can properly end nway mode and |
| 243 | * set duplex (ie. use csr6<9> again) |
| 244 | */ |
| 245 | csr14 = (ioread32(ioaddr + CSR14) & 0xffffff7f); |
| 246 | iowrite32(csr14,ioaddr + CSR14); |
| 247 | |
| 248 | |
| 249 | /* now set the data port and operating mode |
| 250 | * (see the Data Port Selection comments at |
| 251 | * the top of the file |
| 252 | */ |
| 253 | |
| 254 | /* get current csr6 and mask off bits not to touch */ |
| 255 | /* see comment at top of file */ |
| 256 | |
| 257 | tp->csr6 = (ioread32(ioaddr + CSR6) & 0xfe3bd1fd); |
| 258 | |
| 259 | /* so if using if_port 3 or 5 then select the 100baseT |
| 260 | * port else select the 10baseT port. |
| 261 | * See the Data Port Selection table at the top |
| 262 | * of the file which was taken from the PNIC_II.PDF |
| 263 | * datasheet |
| 264 | */ |
| 265 | if (dev->if_port & 1) tp->csr6 |= 0x01840000; |
| 266 | else tp->csr6 |= 0x00400000; |
| 267 | |
| 268 | /* now set the full duplex bit appropriately */ |
| 269 | if (tp->full_duplex) tp->csr6 |= 0x00000200; |
| 270 | |
| 271 | iowrite32(1, ioaddr + CSR13); |
| 272 | |
| 273 | if (tulip_debug > 2) |
Joe Perches | 22086a1 | 2010-01-28 20:59:25 +0000 | [diff] [blame] | 274 | printk(KERN_DEBUG "%s: Setting CSR6 %08x/%x CSR12 %08x\n", |
| 275 | dev->name, tp->csr6, |
| 276 | ioread32(ioaddr + CSR6), ioread32(ioaddr + CSR12)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | /* now the following actually writes out the |
| 279 | * new csr6 values |
| 280 | */ |
| 281 | tulip_start_rxtx(tp); |
| 282 | |
| 283 | return; |
| 284 | |
| 285 | } else { |
Joe Perches | 22086a1 | 2010-01-28 20:59:25 +0000 | [diff] [blame] | 286 | dev_info(&dev->dev, |
| 287 | "Autonegotiation failed, using %s, link beat status %04x\n", |
| 288 | medianame[dev->if_port], csr12); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
| 290 | /* remember to turn off bit 7 - autonegotiate |
| 291 | * enable so we don't forget |
| 292 | */ |
| 293 | csr14 = (ioread32(ioaddr + CSR14) & 0xffffff7f); |
| 294 | iowrite32(csr14,ioaddr + CSR14); |
| 295 | |
| 296 | /* what should we do when autonegotiate fails? |
| 297 | * should we try again or default to baseline |
| 298 | * case. I just don't know. |
| 299 | * |
| 300 | * for now default to some baseline case |
| 301 | */ |
| 302 | |
| 303 | dev->if_port = 0; |
| 304 | tp->nway = 0; |
| 305 | tp->nwayset = 1; |
| 306 | |
| 307 | /* set to 10baseTx-HD - see Data Port Selection |
| 308 | * comment given at the top of the file |
| 309 | */ |
| 310 | tp->csr6 = (ioread32(ioaddr + CSR6) & 0xfe3bd1fd); |
| 311 | tp->csr6 |= 0x00400000; |
| 312 | |
| 313 | tulip_restart_rxtx(tp); |
| 314 | |
| 315 | return; |
| 316 | |
| 317 | } |
| 318 | } |
| 319 | |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 320 | if ((tp->nwayset && (csr5 & 0x08000000) && |
| 321 | (dev->if_port == 3 || dev->if_port == 5) && |
| 322 | (csr12 & 2) == 2) || (tp->nway && (csr5 & (TPLnkFail)))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | /* Link blew? Maybe restart NWay. */ |
| 325 | |
| 326 | if (tulip_debug > 2) |
| 327 | printk(KERN_DEBUG "%s: Ugh! Link blew?\n", dev->name); |
| 328 | |
| 329 | del_timer_sync(&tp->timer); |
| 330 | pnic2_start_nway(dev); |
| 331 | tp->timer.expires = RUN_AT(3*HZ); |
| 332 | add_timer(&tp->timer); |
| 333 | |
| 334 | return; |
| 335 | } |
| 336 | |
| 337 | |
| 338 | if (dev->if_port == 3 || dev->if_port == 5) { |
| 339 | |
| 340 | /* we are at 100mb and a potential link change occurred */ |
| 341 | |
| 342 | if (tulip_debug > 1) |
Joe Perches | 22086a1 | 2010-01-28 20:59:25 +0000 | [diff] [blame] | 343 | dev_info(&dev->dev, "PNIC2 %s link beat %s\n", |
| 344 | medianame[dev->if_port], |
| 345 | (csr12 & 2) ? "failed" : "good"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
| 347 | /* check 100 link beat */ |
| 348 | |
| 349 | tp->nway = 0; |
| 350 | tp->nwayset = 1; |
| 351 | |
| 352 | /* if failed then try doing an nway to get in sync */ |
| 353 | if ((csr12 & 2) && ! tp->medialock) { |
| 354 | del_timer_sync(&tp->timer); |
| 355 | pnic2_start_nway(dev); |
| 356 | tp->timer.expires = RUN_AT(3*HZ); |
| 357 | add_timer(&tp->timer); |
| 358 | } |
| 359 | |
| 360 | return; |
| 361 | } |
| 362 | |
| 363 | if (dev->if_port == 0 || dev->if_port == 4) { |
| 364 | |
| 365 | /* we are at 10mb and a potential link change occurred */ |
| 366 | |
| 367 | if (tulip_debug > 1) |
Joe Perches | 22086a1 | 2010-01-28 20:59:25 +0000 | [diff] [blame] | 368 | dev_info(&dev->dev, "PNIC2 %s link beat %s\n", |
| 369 | medianame[dev->if_port], |
| 370 | (csr12 & 4) ? "failed" : "good"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
| 372 | |
| 373 | tp->nway = 0; |
| 374 | tp->nwayset = 1; |
| 375 | |
| 376 | /* if failed, try doing an nway to get in sync */ |
| 377 | if ((csr12 & 4) && ! tp->medialock) { |
| 378 | del_timer_sync(&tp->timer); |
| 379 | pnic2_start_nway(dev); |
| 380 | tp->timer.expires = RUN_AT(3*HZ); |
| 381 | add_timer(&tp->timer); |
| 382 | } |
| 383 | |
| 384 | return; |
| 385 | } |
| 386 | |
| 387 | |
| 388 | if (tulip_debug > 1) |
Joe Perches | 22086a1 | 2010-01-28 20:59:25 +0000 | [diff] [blame] | 389 | dev_info(&dev->dev, "PNIC2 Link Change Default?\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | /* if all else fails default to trying 10baseT-HD */ |
| 392 | dev->if_port = 0; |
| 393 | |
| 394 | /* make sure autonegotiate enable is off */ |
| 395 | csr14 = (ioread32(ioaddr + CSR14) & 0xffffff7f); |
| 396 | iowrite32(csr14,ioaddr + CSR14); |
| 397 | |
| 398 | /* set to 10baseTx-HD - see Data Port Selection |
| 399 | * comment given at the top of the file |
| 400 | */ |
| 401 | tp->csr6 = (ioread32(ioaddr + CSR6) & 0xfe3bd1fd); |
| 402 | tp->csr6 |= 0x00400000; |
| 403 | |
| 404 | tulip_restart_rxtx(tp); |
| 405 | } |
| 406 | |