blob: 007d8e75666dbc6a836e2c7bc305a8d0379e5c05 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 drivers/net/tulip/21142.c
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 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 Grundler78a65512008-06-05 00:38:55 -060011 for more information on this driver.
Philippe De Muyterf99ec062009-01-29 17:35:04 -080012
13 DC21143 manual "21143 PCI/CardBus 10/100Mb/s Ethernet LAN Controller
14 Hardware Reference Manual" is currently available at :
15 http://developer.intel.com/design/network/manuals/278074.htm
16
Grant Grundler78a65512008-06-05 00:38:55 -060017 Please submit bugs to http://bugzilla.kernel.org/ .
Linus Torvalds1da177e2005-04-16 15:20:36 -070018*/
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/delay.h>
21#include "tulip.h"
22
23
24static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
25u16 t21142_csr14[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
26static u16 t21142_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
27
28
29/* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list
30 of available transceivers. */
David Howellsc4028952006-11-22 14:57:56 +000031void t21142_media_task(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
David Howellsc4028952006-11-22 14:57:56 +000033 struct tulip_private *tp =
34 container_of(work, struct tulip_private, media_work);
35 struct net_device *dev = tp->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 void __iomem *ioaddr = tp->base_addr;
37 int csr12 = ioread32(ioaddr + CSR12);
38 int next_tick = 60*HZ;
39 int new_csr6 = 0;
Philippe De Muyterf99ec062009-01-29 17:35:04 -080040 int csr14 = ioread32(ioaddr + CSR14);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Philippe De Muyterf99ec062009-01-29 17:35:04 -080042 /* CSR12[LS10,LS100] are not reliable during autonegotiation */
43 if ((csr14 & 0x80) && (csr12 & 0x7000) != 0x5000)
44 csr12 |= 6;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 if (tulip_debug > 2)
Joe Perches985a63e2010-01-28 20:59:18 +000046 dev_info(&dev->dev, "21143 negotiation status %08x, %s\n",
47 csr12, medianame[dev->if_port]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 if (tulip_media_cap[dev->if_port] & MediaIsMII) {
49 if (tulip_check_duplex(dev) < 0) {
50 netif_carrier_off(dev);
51 next_tick = 3*HZ;
52 } else {
53 netif_carrier_on(dev);
54 next_tick = 60*HZ;
55 }
56 } else if (tp->nwayset) {
57 /* Don't screw up a negotiated session! */
58 if (tulip_debug > 1)
Joe Perches985a63e2010-01-28 20:59:18 +000059 dev_info(&dev->dev,
60 "Using NWay-set %s media, csr12 %08x\n",
61 medianame[dev->if_port], csr12);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 } else if (tp->medialock) {
63 ;
64 } else if (dev->if_port == 3) {
65 if (csr12 & 2) { /* No 100mbps link beat, revert to 10mbps. */
66 if (tulip_debug > 1)
Joe Perches985a63e2010-01-28 20:59:18 +000067 dev_info(&dev->dev,
68 "No 21143 100baseTx link beat, %08x, trying NWay\n",
69 csr12);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 t21142_start_nway(dev);
71 next_tick = 3*HZ;
72 }
73 } else if ((csr12 & 0x7000) != 0x5000) {
74 /* Negotiation failed. Search media types. */
75 if (tulip_debug > 1)
Joe Perches985a63e2010-01-28 20:59:18 +000076 dev_info(&dev->dev,
77 "21143 negotiation failed, status %08x\n",
78 csr12);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 if (!(csr12 & 4)) { /* 10mbps link beat good. */
80 new_csr6 = 0x82420000;
81 dev->if_port = 0;
82 iowrite32(0, ioaddr + CSR13);
83 iowrite32(0x0003FFFF, ioaddr + CSR14);
84 iowrite16(t21142_csr15[dev->if_port], ioaddr + CSR15);
85 iowrite32(t21142_csr13[dev->if_port], ioaddr + CSR13);
86 } else {
87 /* Select 100mbps port to check for link beat. */
88 new_csr6 = 0x83860000;
89 dev->if_port = 3;
90 iowrite32(0, ioaddr + CSR13);
Philippe De Muyterf99ec062009-01-29 17:35:04 -080091 iowrite32(0x0003FFFF, ioaddr + CSR14);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 iowrite16(8, ioaddr + CSR15);
93 iowrite32(1, ioaddr + CSR13);
94 }
95 if (tulip_debug > 1)
Joe Perches985a63e2010-01-28 20:59:18 +000096 dev_info(&dev->dev, "Testing new 21143 media %s\n",
97 medianame[dev->if_port]);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 if (new_csr6 != (tp->csr6 & ~0x00D5)) {
99 tp->csr6 &= 0x00D5;
100 tp->csr6 |= new_csr6;
101 iowrite32(0x0301, ioaddr + CSR12);
102 tulip_restart_rxtx(tp);
103 }
104 next_tick = 3*HZ;
105 }
106
107 /* mod_timer synchronizes us with potential add_timer calls
108 * from interrupts.
109 */
110 mod_timer(&tp->timer, RUN_AT(next_tick));
111}
112
113
114void t21142_start_nway(struct net_device *dev)
115{
116 struct tulip_private *tp = netdev_priv(dev);
117 void __iomem *ioaddr = tp->base_addr;
118 int csr14 = ((tp->sym_advertise & 0x0780) << 9) |
119 ((tp->sym_advertise & 0x0020) << 1) | 0xffbf;
120
121 dev->if_port = 0;
122 tp->nway = tp->mediasense = 1;
123 tp->nwayset = tp->lpar = 0;
124 if (tulip_debug > 1)
Joe Perches985a63e2010-01-28 20:59:18 +0000125 printk(KERN_DEBUG "%s: Restarting 21143 autonegotiation, csr14=%08x\n",
126 dev->name, csr14);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 iowrite32(0x0001, ioaddr + CSR13);
128 udelay(100);
129 iowrite32(csr14, ioaddr + CSR14);
130 tp->csr6 = 0x82420000 | (tp->sym_advertise & 0x0040 ? FullDuplex : 0);
131 iowrite32(tp->csr6, ioaddr + CSR6);
132 if (tp->mtable && tp->mtable->csr15dir) {
133 iowrite32(tp->mtable->csr15dir, ioaddr + CSR15);
134 iowrite32(tp->mtable->csr15val, ioaddr + CSR15);
135 } else
136 iowrite16(0x0008, ioaddr + CSR15);
137 iowrite32(0x1301, ioaddr + CSR12); /* Trigger NWAY. */
138}
139
140
141
142void t21142_lnk_change(struct net_device *dev, int csr5)
143{
144 struct tulip_private *tp = netdev_priv(dev);
145 void __iomem *ioaddr = tp->base_addr;
146 int csr12 = ioread32(ioaddr + CSR12);
Philippe De Muyterf99ec062009-01-29 17:35:04 -0800147 int csr14 = ioread32(ioaddr + CSR14);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Philippe De Muyterf99ec062009-01-29 17:35:04 -0800149 /* CSR12[LS10,LS100] are not reliable during autonegotiation */
150 if ((csr14 & 0x80) && (csr12 & 0x7000) != 0x5000)
151 csr12 |= 6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 if (tulip_debug > 1)
Joe Perches985a63e2010-01-28 20:59:18 +0000153 dev_info(&dev->dev,
154 "21143 link status interrupt %08x, CSR5 %x, %08x\n",
155 csr12, csr5, csr14);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 /* If NWay finished and we have a negotiated partner capability. */
158 if (tp->nway && !tp->nwayset && (csr12 & 0x7000) == 0x5000) {
159 int setup_done = 0;
160 int negotiated = tp->sym_advertise & (csr12 >> 16);
161 tp->lpar = csr12 >> 16;
162 tp->nwayset = 1;
Philippe De Muyterf99ec062009-01-29 17:35:04 -0800163 /* If partner cannot negotiate, it is 10Mbps Half Duplex */
164 if (!(csr12 & 0x8000)) dev->if_port = 0;
165 else if (negotiated & 0x0100) dev->if_port = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 else if (negotiated & 0x0080) dev->if_port = 3;
167 else if (negotiated & 0x0040) dev->if_port = 4;
168 else if (negotiated & 0x0020) dev->if_port = 0;
169 else {
170 tp->nwayset = 0;
171 if ((csr12 & 2) == 0 && (tp->sym_advertise & 0x0180))
172 dev->if_port = 3;
173 }
174 tp->full_duplex = (tulip_media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0;
175
176 if (tulip_debug > 1) {
177 if (tp->nwayset)
Joe Perches985a63e2010-01-28 20:59:18 +0000178 dev_info(&dev->dev,
179 "Switching to %s based on link negotiation %04x & %04x = %04x\n",
180 medianame[dev->if_port],
181 tp->sym_advertise, tp->lpar,
182 negotiated);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 else
Joe Perches985a63e2010-01-28 20:59:18 +0000184 dev_info(&dev->dev,
185 "Autonegotiation failed, using %s, link beat status %04x\n",
186 medianame[dev->if_port], csr12);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188
189 if (tp->mtable) {
190 int i;
191 for (i = 0; i < tp->mtable->leafcount; i++)
192 if (tp->mtable->mleaf[i].media == dev->if_port) {
Philippe De Muyter32b5bfa2005-09-22 11:09:44 +0200193 int startup = ! ((tp->chip_id == DC21143 && (tp->revision == 48 || tp->revision == 65)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 tp->cur_index = i;
195 tulip_select_media(dev, startup);
196 setup_done = 1;
197 break;
198 }
199 }
200 if ( ! setup_done) {
201 tp->csr6 = (dev->if_port & 1 ? 0x838E0000 : 0x82420000) | (tp->csr6 & 0x20ff);
202 if (tp->full_duplex)
203 tp->csr6 |= 0x0200;
204 iowrite32(1, ioaddr + CSR13);
205 }
206#if 0 /* Restart shouldn't be needed. */
207 iowrite32(tp->csr6 | RxOn, ioaddr + CSR6);
208 if (tulip_debug > 2)
Joe Perches985a63e2010-01-28 20:59:18 +0000209 printk(KERN_DEBUG "%s: Restarting Tx and Rx, CSR5 is %08x\n",
210 dev->name, ioread32(ioaddr + CSR5));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211#endif
212 tulip_start_rxtx(tp);
213 if (tulip_debug > 2)
Joe Perches985a63e2010-01-28 20:59:18 +0000214 printk(KERN_DEBUG "%s: Setting CSR6 %08x/%x CSR12 %08x\n",
215 dev->name, tp->csr6, ioread32(ioaddr + CSR6),
216 ioread32(ioaddr + CSR12));
Joe Perches8e95a202009-12-03 07:58:21 +0000217 } else if ((tp->nwayset && (csr5 & 0x08000000) &&
218 (dev->if_port == 3 || dev->if_port == 5) &&
219 (csr12 & 2) == 2) ||
220 (tp->nway && (csr5 & (TPLnkFail)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 /* Link blew? Maybe restart NWay. */
222 del_timer_sync(&tp->timer);
223 t21142_start_nway(dev);
224 tp->timer.expires = RUN_AT(3*HZ);
225 add_timer(&tp->timer);
226 } else if (dev->if_port == 3 || dev->if_port == 5) {
227 if (tulip_debug > 1)
Joe Perches985a63e2010-01-28 20:59:18 +0000228 dev_info(&dev->dev, "21143 %s link beat %s\n",
229 medianame[dev->if_port],
230 (csr12 & 2) ? "failed" : "good");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 if ((csr12 & 2) && ! tp->medialock) {
232 del_timer_sync(&tp->timer);
233 t21142_start_nway(dev);
234 tp->timer.expires = RUN_AT(3*HZ);
235 add_timer(&tp->timer);
236 } else if (dev->if_port == 5)
Philippe De Muyterf99ec062009-01-29 17:35:04 -0800237 iowrite32(csr14 & ~0x080, ioaddr + CSR14);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 } else if (dev->if_port == 0 || dev->if_port == 4) {
239 if ((csr12 & 4) == 0)
Joe Perches985a63e2010-01-28 20:59:18 +0000240 dev_info(&dev->dev, "21143 10baseT link beat good\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 } else if (!(csr12 & 4)) { /* 10mbps link beat good. */
242 if (tulip_debug)
Joe Perches985a63e2010-01-28 20:59:18 +0000243 dev_info(&dev->dev, "21143 10mbps sensed media\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 dev->if_port = 0;
245 } else if (tp->nwayset) {
246 if (tulip_debug)
Joe Perches985a63e2010-01-28 20:59:18 +0000247 dev_info(&dev->dev, "21143 using NWay-set %s, csr6 %08x\n",
248 medianame[dev->if_port], tp->csr6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 } else { /* 100mbps link beat good. */
250 if (tulip_debug)
Joe Perches985a63e2010-01-28 20:59:18 +0000251 dev_info(&dev->dev, "21143 100baseTx sensed media\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 dev->if_port = 3;
253 tp->csr6 = 0x838E0000 | (tp->csr6 & 0x20ff);
254 iowrite32(0x0003FF7F, ioaddr + CSR14);
255 iowrite32(0x0301, ioaddr + CSR12);
256 tulip_restart_rxtx(tp);
257 }
258}
259
260