2 drivers/net/tulip/pnic2.c
4 Maintained by Valerie Henson <val_henson@linux.intel.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
9 This software may be used and distributed according to the terms
10 of the GNU General Public License, incorporated herein by reference.
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/
19 /* Understanding the PNIC_II - everything is this file is based
20 * on the PNIC_II_PDF datasheet which is sorely lacking in detail
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.
27 * CSR 6 (mask = 0xfe3bd1fd of bits not to change)
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
39 * CSR 14 (mask = 0xfff0ee39 of bits not to change)
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
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
66 * Data Port Selection Info
67 *-------------------------
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
80 #include <linux/delay.h>
83 void pnic2_timer(unsigned long data
)
85 struct net_device
*dev
= (struct net_device
*)data
;
86 struct tulip_private
*tp
= netdev_priv(dev
);
87 void __iomem
*ioaddr
= tp
->base_addr
;
88 int next_tick
= 60*HZ
;
91 printk(KERN_INFO
"%s: PNIC2 negotiation status %8.8x.\n",
92 dev
->name
,ioread32(ioaddr
+ CSR12
));
95 mod_timer(&tp
->timer
, RUN_AT(next_tick
));
100 void pnic2_start_nway(struct net_device
*dev
)
102 struct tulip_private
*tp
= netdev_priv(dev
);
103 void __iomem
*ioaddr
= tp
->base_addr
;
107 /* set up what to advertise during the negotiation */
109 /* load in csr14 and mask off bits not to touch
110 * comment at top of file explains mask value
112 csr14
= (ioread32(ioaddr
+ CSR14
) & 0xfff0ee39);
114 /* bit 17 - advetise 100baseTx-FD */
115 if (tp
->sym_advertise
& 0x0100) csr14
|= 0x00020000;
117 /* bit 16 - advertise 100baseTx-HD */
118 if (tp
->sym_advertise
& 0x0080) csr14
|= 0x00010000;
120 /* bit 6 - advertise 10baseT-HD */
121 if (tp
->sym_advertise
& 0x0020) csr14
|= 0x00000040;
123 /* Now set bit 12 Link Test Enable, Bit 7 Autonegotiation Enable
124 * and bit 0 Don't PowerDown 10baseT
129 printk(KERN_DEBUG
"%s: Restarting PNIC2 autonegotiation, "
130 "csr14=%8.8x.\n", dev
->name
, csr14
);
132 /* tell pnic2_lnk_change we are doing an nway negotiation */
134 tp
->nway
= tp
->mediasense
= 1;
135 tp
->nwayset
= tp
->lpar
= 0;
137 /* now we have to set up csr6 for NWAY state */
139 tp
->csr6
= ioread32(ioaddr
+ CSR6
);
141 printk(KERN_DEBUG
"%s: On Entry to Nway, "
142 "csr6=%8.8x.\n", dev
->name
, tp
->csr6
);
144 /* mask off any bits not to touch
145 * comment at top of file explains mask value
147 tp
->csr6
= tp
->csr6
& 0xfe3bd1fd;
149 /* don't forget that bit 9 is also used for advertising */
150 /* advertise 10baseT-FD for the negotiation (bit 9) */
151 if (tp
->sym_advertise
& 0x0040) tp
->csr6
|= 0x00000200;
153 /* set bit 24 for nway negotiation mode ...
154 * see Data Port Selection comment at top of file
155 * and "Stop" - reset both Transmit (bit 13) and Receive (bit 1)
157 tp
->csr6
|= 0x01000000;
158 iowrite32(csr14
, ioaddr
+ CSR14
);
159 iowrite32(tp
->csr6
, ioaddr
+ CSR6
);
162 /* all set up so now force the negotiation to begin */
164 /* read in current values and mask off all but the
165 * Autonegotiation bits 14:12. Writing a 001 to those bits
166 * should start the autonegotiation
168 csr12
= (ioread32(ioaddr
+ CSR12
) & 0xffff8fff);
170 iowrite32(csr12
, ioaddr
+ CSR12
);
175 void pnic2_lnk_change(struct net_device
*dev
, int csr5
)
177 struct tulip_private
*tp
= netdev_priv(dev
);
178 void __iomem
*ioaddr
= tp
->base_addr
;
181 /* read the staus register to find out what is up */
182 int csr12
= ioread32(ioaddr
+ CSR12
);
185 printk(KERN_INFO
"%s: PNIC2 link status interrupt %8.8x, "
186 " CSR5 %x, %8.8x.\n", dev
->name
, csr12
,
187 csr5
, ioread32(ioaddr
+ CSR14
));
189 /* If NWay finished and we have a negotiated partner capability.
190 * check bits 14:12 for bit pattern 101 - all is good
192 if (tp
->nway
&& !tp
->nwayset
) {
194 /* we did an auto negotiation */
196 if ((csr12
& 0x7000) == 0x5000) {
198 /* negotiation ended successfully */
200 /* get the link partners reply and mask out all but
201 * bits 24-21 which show the partners capabilities
202 * and match those to what we advertised
204 * then begin to interpret the results of the negotiation.
205 * Always go in this order : (we are ignoring T4 for now)
206 * 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD
209 int negotiated
= ((csr12
>> 16) & 0x01E0) & tp
->sym_advertise
;
210 tp
->lpar
= (csr12
>> 16);
213 if (negotiated
& 0x0100) dev
->if_port
= 5;
214 else if (negotiated
& 0x0080) dev
->if_port
= 3;
215 else if (negotiated
& 0x0040) dev
->if_port
= 4;
216 else if (negotiated
& 0x0020) dev
->if_port
= 0;
219 printk(KERN_INFO
"%s: funny autonegotiate result "
220 "csr12 %8.8x advertising %4.4x\n",
221 dev
->name
, csr12
, tp
->sym_advertise
);
223 /* so check if 100baseTx link state is okay */
224 if ((csr12
& 2) == 0 && (tp
->sym_advertise
& 0x0180))
228 /* now record the duplex that was negotiated */
230 if ((dev
->if_port
== 4) || (dev
->if_port
== 5))
233 if (tulip_debug
> 1) {
235 printk(KERN_INFO
"%s: Switching to %s based on link "
236 "negotiation %4.4x & %4.4x = %4.4x.\n",
237 dev
->name
, medianame
[dev
->if_port
],
238 tp
->sym_advertise
, tp
->lpar
, negotiated
);
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)
245 csr14
= (ioread32(ioaddr
+ CSR14
) & 0xffffff7f);
246 iowrite32(csr14
,ioaddr
+ CSR14
);
249 /* now set the data port and operating mode
250 * (see the Data Port Selection comments at
251 * the top of the file
254 /* get current csr6 and mask off bits not to touch */
255 /* see comment at top of file */
257 tp
->csr6
= (ioread32(ioaddr
+ CSR6
) & 0xfe3bd1fd);
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
265 if (dev
->if_port
& 1) tp
->csr6
|= 0x01840000;
266 else tp
->csr6
|= 0x00400000;
268 /* now set the full duplex bit appropriately */
269 if (tp
->full_duplex
) tp
->csr6
|= 0x00000200;
271 iowrite32(1, ioaddr
+ CSR13
);
274 printk(KERN_DEBUG
"%s: Setting CSR6 %8.8x/%x CSR12 "
275 "%8.8x.\n", dev
->name
, tp
->csr6
,
276 ioread32(ioaddr
+ CSR6
), ioread32(ioaddr
+ CSR12
));
278 /* now the following actually writes out the
281 tulip_start_rxtx(tp
);
286 printk(KERN_INFO
"%s: Autonegotiation failed, "
287 "using %s, link beat status %4.4x.\n",
288 dev
->name
, medianame
[dev
->if_port
], csr12
);
290 /* remember to turn off bit 7 - autonegotiate
291 * enable so we don't forget
293 csr14
= (ioread32(ioaddr
+ CSR14
) & 0xffffff7f);
294 iowrite32(csr14
,ioaddr
+ CSR14
);
296 /* what should we do when autonegotiate fails?
297 * should we try again or default to baseline
298 * case. I just don't know.
300 * for now default to some baseline case
307 /* set to 10baseTx-HD - see Data Port Selection
308 * comment given at the top of the file
310 tp
->csr6
= (ioread32(ioaddr
+ CSR6
) & 0xfe3bd1fd);
311 tp
->csr6
|= 0x00400000;
313 tulip_restart_rxtx(tp
);
320 if ((tp
->nwayset
&& (csr5
& 0x08000000)
321 && (dev
->if_port
== 3 || dev
->if_port
== 5)
322 && (csr12
& 2) == 2) || (tp
->nway
&& (csr5
& (TPLnkFail
)))) {
324 /* Link blew? Maybe restart NWay. */
327 printk(KERN_DEBUG
"%s: Ugh! Link blew?\n", dev
->name
);
329 del_timer_sync(&tp
->timer
);
330 pnic2_start_nway(dev
);
331 tp
->timer
.expires
= RUN_AT(3*HZ
);
332 add_timer(&tp
->timer
);
338 if (dev
->if_port
== 3 || dev
->if_port
== 5) {
340 /* we are at 100mb and a potential link change occurred */
343 printk(KERN_INFO
"%s: PNIC2 %s link beat %s.\n",
344 dev
->name
, medianame
[dev
->if_port
],
345 (csr12
& 2) ? "failed" : "good");
347 /* check 100 link beat */
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
);
363 if (dev
->if_port
== 0 || dev
->if_port
== 4) {
365 /* we are at 10mb and a potential link change occurred */
368 printk(KERN_INFO
"%s: PNIC2 %s link beat %s.\n",
369 dev
->name
, medianame
[dev
->if_port
],
370 (csr12
& 4) ? "failed" : "good");
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
);
389 printk(KERN_INFO
"%s: PNIC2 Link Change Default?\n",dev
->name
);
391 /* if all else fails default to trying 10baseT-HD */
394 /* make sure autonegotiate enable is off */
395 csr14
= (ioread32(ioaddr
+ CSR14
) & 0xffffff7f);
396 iowrite32(csr14
,ioaddr
+ CSR14
);
398 /* set to 10baseTx-HD - see Data Port Selection
399 * comment given at the top of the file
401 tp
->csr6
= (ioread32(ioaddr
+ CSR6
) & 0xfe3bd1fd);
402 tp
->csr6
|= 0x00400000;
404 tulip_restart_rxtx(tp
);