| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | drivers/net/tulip/pnic.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 |  | 
|  | 7 | This software may be used and distributed according to the terms | 
|  | 8 | of the GNU General Public License, incorporated herein by reference. | 
|  | 9 |  | 
|  | 10 | Please refer to Documentation/DocBook/tulip-user.{pdf,ps,html} | 
| Grant Grundler | 78a6551 | 2008-06-05 00:38:55 -0600 | [diff] [blame] | 11 | for more information on this driver. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 |  | 
| Grant Grundler | 78a6551 | 2008-06-05 00:38:55 -0600 | [diff] [blame] | 13 | Please submit bugs to http://bugzilla.kernel.org/ . | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | */ | 
|  | 15 |  | 
|  | 16 | #include <linux/kernel.h> | 
| Marcelo Feitoza Parisi | ff5688a | 2006-01-09 18:37:15 -0800 | [diff] [blame] | 17 | #include <linux/jiffies.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "tulip.h" | 
|  | 19 |  | 
|  | 20 |  | 
|  | 21 | void pnic_do_nway(struct net_device *dev) | 
|  | 22 | { | 
|  | 23 | struct tulip_private *tp = netdev_priv(dev); | 
|  | 24 | void __iomem *ioaddr = tp->base_addr; | 
|  | 25 | u32 phy_reg = ioread32(ioaddr + 0xB8); | 
|  | 26 | u32 new_csr6 = tp->csr6 & ~0x40C40200; | 
|  | 27 |  | 
|  | 28 | if (phy_reg & 0x78000000) { /* Ignore baseT4 */ | 
|  | 29 | if (phy_reg & 0x20000000)		dev->if_port = 5; | 
|  | 30 | else if (phy_reg & 0x40000000)	dev->if_port = 3; | 
|  | 31 | else if (phy_reg & 0x10000000)	dev->if_port = 4; | 
|  | 32 | else if (phy_reg & 0x08000000)	dev->if_port = 0; | 
|  | 33 | tp->nwayset = 1; | 
|  | 34 | new_csr6 = (dev->if_port & 1) ? 0x01860000 : 0x00420000; | 
|  | 35 | iowrite32(0x32 | (dev->if_port & 1), ioaddr + CSR12); | 
|  | 36 | if (dev->if_port & 1) | 
|  | 37 | iowrite32(0x1F868, ioaddr + 0xB8); | 
|  | 38 | if (phy_reg & 0x30000000) { | 
|  | 39 | tp->full_duplex = 1; | 
|  | 40 | new_csr6 |= 0x00000200; | 
|  | 41 | } | 
|  | 42 | if (tulip_debug > 1) | 
| Joe Perches | 1df8bbd | 2010-01-28 20:59:24 +0000 | [diff] [blame] | 43 | printk(KERN_DEBUG "%s: PNIC autonegotiated status %08x, %s\n", | 
|  | 44 | dev->name, phy_reg, medianame[dev->if_port]); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | if (tp->csr6 != new_csr6) { | 
|  | 46 | tp->csr6 = new_csr6; | 
|  | 47 | /* Restart Tx */ | 
|  | 48 | tulip_restart_rxtx(tp); | 
|  | 49 | dev->trans_start = jiffies; | 
|  | 50 | } | 
|  | 51 | } | 
|  | 52 | } | 
|  | 53 |  | 
|  | 54 | void pnic_lnk_change(struct net_device *dev, int csr5) | 
|  | 55 | { | 
|  | 56 | struct tulip_private *tp = netdev_priv(dev); | 
|  | 57 | void __iomem *ioaddr = tp->base_addr; | 
|  | 58 | int phy_reg = ioread32(ioaddr + 0xB8); | 
|  | 59 |  | 
|  | 60 | if (tulip_debug > 1) | 
| Joe Perches | 1df8bbd | 2010-01-28 20:59:24 +0000 | [diff] [blame] | 61 | printk(KERN_DEBUG "%s: PNIC link changed state %08x, CSR5 %08x\n", | 
|  | 62 | dev->name, phy_reg, csr5); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | if (ioread32(ioaddr + CSR5) & TPLnkFail) { | 
|  | 64 | iowrite32((ioread32(ioaddr + CSR7) & ~TPLnkFail) | TPLnkPass, ioaddr + CSR7); | 
|  | 65 | /* If we use an external MII, then we mustn't use the | 
|  | 66 | * internal negotiation. | 
|  | 67 | */ | 
|  | 68 | if (tulip_media_cap[dev->if_port] & MediaIsMII) | 
|  | 69 | return; | 
| Eric Dumazet | 1ae5dc3 | 2010-05-10 05:01:31 -0700 | [diff] [blame] | 70 | if (! tp->nwayset || time_after(jiffies, dev_trans_start(dev) + 1*HZ)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | tp->csr6 = 0x00420000 | (tp->csr6 & 0x0000fdff); | 
|  | 72 | iowrite32(tp->csr6, ioaddr + CSR6); | 
|  | 73 | iowrite32(0x30, ioaddr + CSR12); | 
|  | 74 | iowrite32(0x0201F078, ioaddr + 0xB8); /* Turn on autonegotiation. */ | 
|  | 75 | dev->trans_start = jiffies; | 
|  | 76 | } | 
|  | 77 | } else if (ioread32(ioaddr + CSR5) & TPLnkPass) { | 
|  | 78 | if (tulip_media_cap[dev->if_port] & MediaIsMII) { | 
|  | 79 | spin_lock(&tp->lock); | 
|  | 80 | tulip_check_duplex(dev); | 
|  | 81 | spin_unlock(&tp->lock); | 
|  | 82 | } else { | 
|  | 83 | pnic_do_nway(dev); | 
|  | 84 | } | 
|  | 85 | iowrite32((ioread32(ioaddr + CSR7) & ~TPLnkPass) | TPLnkFail, ioaddr + CSR7); | 
|  | 86 | } | 
|  | 87 | } | 
|  | 88 |  | 
|  | 89 | void pnic_timer(unsigned long data) | 
|  | 90 | { | 
|  | 91 | struct net_device *dev = (struct net_device *)data; | 
|  | 92 | struct tulip_private *tp = netdev_priv(dev); | 
|  | 93 | void __iomem *ioaddr = tp->base_addr; | 
|  | 94 | int next_tick = 60*HZ; | 
|  | 95 |  | 
|  | 96 | if(!ioread32(ioaddr + CSR7)) { | 
|  | 97 | /* the timer was called due to a work overflow | 
|  | 98 | * in the interrupt handler. Skip the connection | 
|  | 99 | * checks, the nic is definitively speaking with | 
|  | 100 | * his link partner. | 
|  | 101 | */ | 
|  | 102 | goto too_good_connection; | 
|  | 103 | } | 
|  | 104 |  | 
|  | 105 | if (tulip_media_cap[dev->if_port] & MediaIsMII) { | 
|  | 106 | spin_lock_irq(&tp->lock); | 
|  | 107 | if (tulip_check_duplex(dev) > 0) | 
|  | 108 | next_tick = 3*HZ; | 
|  | 109 | spin_unlock_irq(&tp->lock); | 
|  | 110 | } else { | 
|  | 111 | int csr12 = ioread32(ioaddr + CSR12); | 
|  | 112 | int new_csr6 = tp->csr6 & ~0x40C40200; | 
|  | 113 | int phy_reg = ioread32(ioaddr + 0xB8); | 
|  | 114 | int csr5 = ioread32(ioaddr + CSR5); | 
|  | 115 |  | 
|  | 116 | if (tulip_debug > 1) | 
| Joe Perches | 1df8bbd | 2010-01-28 20:59:24 +0000 | [diff] [blame] | 117 | printk(KERN_DEBUG "%s: PNIC timer PHY status %08x, %s CSR5 %08x\n", | 
|  | 118 | dev->name, phy_reg, medianame[dev->if_port], csr5); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | if (phy_reg & 0x04000000) {	/* Remote link fault */ | 
|  | 120 | iowrite32(0x0201F078, ioaddr + 0xB8); | 
|  | 121 | next_tick = 1*HZ; | 
|  | 122 | tp->nwayset = 0; | 
|  | 123 | } else if (phy_reg & 0x78000000) { /* Ignore baseT4 */ | 
|  | 124 | pnic_do_nway(dev); | 
|  | 125 | next_tick = 60*HZ; | 
|  | 126 | } else if (csr5 & TPLnkFail) { /* 100baseTx link beat */ | 
|  | 127 | if (tulip_debug > 1) | 
| Joe Perches | 1df8bbd | 2010-01-28 20:59:24 +0000 | [diff] [blame] | 128 | printk(KERN_DEBUG "%s: %s link beat failed, CSR12 %04x, CSR5 %08x, PHY %03x\n", | 
|  | 129 | dev->name, medianame[dev->if_port], | 
|  | 130 | csr12, | 
|  | 131 | ioread32(ioaddr + CSR5), | 
|  | 132 | ioread32(ioaddr + 0xB8)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | next_tick = 3*HZ; | 
|  | 134 | if (tp->medialock) { | 
|  | 135 | } else if (tp->nwayset  &&  (dev->if_port & 1)) { | 
|  | 136 | next_tick = 1*HZ; | 
|  | 137 | } else if (dev->if_port == 0) { | 
|  | 138 | dev->if_port = 3; | 
|  | 139 | iowrite32(0x33, ioaddr + CSR12); | 
|  | 140 | new_csr6 = 0x01860000; | 
|  | 141 | iowrite32(0x1F868, ioaddr + 0xB8); | 
|  | 142 | } else { | 
|  | 143 | dev->if_port = 0; | 
|  | 144 | iowrite32(0x32, ioaddr + CSR12); | 
|  | 145 | new_csr6 = 0x00420000; | 
|  | 146 | iowrite32(0x1F078, ioaddr + 0xB8); | 
|  | 147 | } | 
|  | 148 | if (tp->csr6 != new_csr6) { | 
|  | 149 | tp->csr6 = new_csr6; | 
|  | 150 | /* Restart Tx */ | 
|  | 151 | tulip_restart_rxtx(tp); | 
|  | 152 | dev->trans_start = jiffies; | 
|  | 153 | if (tulip_debug > 1) | 
| Joe Perches | 1df8bbd | 2010-01-28 20:59:24 +0000 | [diff] [blame] | 154 | dev_info(&dev->dev, | 
|  | 155 | "Changing PNIC configuration to %s %s-duplex, CSR6 %08x\n", | 
|  | 156 | medianame[dev->if_port], | 
|  | 157 | tp->full_duplex ? "full" : "half", | 
|  | 158 | new_csr6); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } | 
|  | 160 | } | 
|  | 161 | } | 
|  | 162 | too_good_connection: | 
|  | 163 | mod_timer(&tp->timer, RUN_AT(next_tick)); | 
|  | 164 | if(!ioread32(ioaddr + CSR7)) { | 
|  | 165 | if (tulip_debug > 1) | 
| Joe Perches | 1df8bbd | 2010-01-28 20:59:24 +0000 | [diff] [blame] | 166 | dev_info(&dev->dev, "sw timer wakeup\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | disable_irq(dev->irq); | 
|  | 168 | tulip_refill_rx(dev); | 
|  | 169 | enable_irq(dev->irq); | 
|  | 170 | iowrite32(tulip_tbl[tp->chip_id].valid_intrs, ioaddr + CSR7); | 
|  | 171 | } | 
|  | 172 | } |