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