2 drivers/net/tulip/pnic2.c
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
8 This software may be used and distributed according to the terms
9 of the GNU General Public License, incorporated herein by reference.
11 Please refer to Documentation/DocBook/tulip-user.{pdf,ps,html}
12 for more information on this driver.
14 Please submit bugs to http://bugzilla.kernel.org/ .
18 /* Understanding the PNIC_II - everything is this file is based
19 * on the PNIC_II_PDF datasheet which is sorely lacking in detail
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.
26 * CSR 6 (mask = 0xfe3bd1fd of bits not to change)
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
38 * CSR 14 (mask = 0xfff0ee39 of bits not to change)
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
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
62 * Bit 1 - LS100B - link state of 100baseT 0 - good, 1- faild
65 * Data Port Selection Info
66 *-------------------------
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
79 #include <linux/delay.h>
82 void pnic2_timer(unsigned long data
)
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
;
90 printk(KERN_INFO
"%s: PNIC2 negotiation status %8.8x.\n",
91 dev
->name
,ioread32(ioaddr
+ CSR12
));
94 mod_timer(&tp
->timer
, RUN_AT(next_tick
));
99 void pnic2_start_nway(struct net_device
*dev
)
101 struct tulip_private
*tp
= netdev_priv(dev
);
102 void __iomem
*ioaddr
= tp
->base_addr
;
106 /* set up what to advertise during the negotiation */
108 /* load in csr14 and mask off bits not to touch
109 * comment at top of file explains mask value
111 csr14
= (ioread32(ioaddr
+ CSR14
) & 0xfff0ee39);
113 /* bit 17 - advetise 100baseTx-FD */
114 if (tp
->sym_advertise
& 0x0100) csr14
|= 0x00020000;
116 /* bit 16 - advertise 100baseTx-HD */
117 if (tp
->sym_advertise
& 0x0080) csr14
|= 0x00010000;
119 /* bit 6 - advertise 10baseT-HD */
120 if (tp
->sym_advertise
& 0x0020) csr14
|= 0x00000040;
122 /* Now set bit 12 Link Test Enable, Bit 7 Autonegotiation Enable
123 * and bit 0 Don't PowerDown 10baseT
128 printk(KERN_DEBUG
"%s: Restarting PNIC2 autonegotiation, "
129 "csr14=%8.8x.\n", dev
->name
, csr14
);
131 /* tell pnic2_lnk_change we are doing an nway negotiation */
133 tp
->nway
= tp
->mediasense
= 1;
134 tp
->nwayset
= tp
->lpar
= 0;
136 /* now we have to set up csr6 for NWAY state */
138 tp
->csr6
= ioread32(ioaddr
+ CSR6
);
140 printk(KERN_DEBUG
"%s: On Entry to Nway, "
141 "csr6=%8.8x.\n", dev
->name
, tp
->csr6
);
143 /* mask off any bits not to touch
144 * comment at top of file explains mask value
146 tp
->csr6
= tp
->csr6
& 0xfe3bd1fd;
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;
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)
156 tp
->csr6
|= 0x01000000;
157 iowrite32(csr14
, ioaddr
+ CSR14
);
158 iowrite32(tp
->csr6
, ioaddr
+ CSR6
);
161 /* all set up so now force the negotiation to begin */
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
167 csr12
= (ioread32(ioaddr
+ CSR12
) & 0xffff8fff);
169 iowrite32(csr12
, ioaddr
+ CSR12
);
174 void pnic2_lnk_change(struct net_device
*dev
, int csr5
)
176 struct tulip_private
*tp
= netdev_priv(dev
);
177 void __iomem
*ioaddr
= tp
->base_addr
;
180 /* read the staus register to find out what is up */
181 int csr12
= ioread32(ioaddr
+ CSR12
);
184 printk(KERN_INFO
"%s: PNIC2 link status interrupt %8.8x, "
185 " CSR5 %x, %8.8x.\n", dev
->name
, csr12
,
186 csr5
, ioread32(ioaddr
+ CSR14
));
188 /* If NWay finished and we have a negotiated partner capability.
189 * check bits 14:12 for bit pattern 101 - all is good
191 if (tp
->nway
&& !tp
->nwayset
) {
193 /* we did an auto negotiation */
195 if ((csr12
& 0x7000) == 0x5000) {
197 /* negotiation ended successfully */
199 /* get the link partners reply and mask out all but
200 * bits 24-21 which show the partners capabilities
201 * and match those to what we advertised
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
208 int negotiated
= ((csr12
>> 16) & 0x01E0) & tp
->sym_advertise
;
209 tp
->lpar
= (csr12
>> 16);
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;
218 printk(KERN_INFO
"%s: funny autonegotiate result "
219 "csr12 %8.8x advertising %4.4x\n",
220 dev
->name
, csr12
, tp
->sym_advertise
);
222 /* so check if 100baseTx link state is okay */
223 if ((csr12
& 2) == 0 && (tp
->sym_advertise
& 0x0180))
227 /* now record the duplex that was negotiated */
229 if ((dev
->if_port
== 4) || (dev
->if_port
== 5))
232 if (tulip_debug
> 1) {
234 printk(KERN_INFO
"%s: Switching to %s based on link "
235 "negotiation %4.4x & %4.4x = %4.4x.\n",
236 dev
->name
, medianame
[dev
->if_port
],
237 tp
->sym_advertise
, tp
->lpar
, negotiated
);
240 /* remember to turn off bit 7 - autonegotiate
241 * enable so we can properly end nway mode and
242 * set duplex (ie. use csr6<9> again)
244 csr14
= (ioread32(ioaddr
+ CSR14
) & 0xffffff7f);
245 iowrite32(csr14
,ioaddr
+ CSR14
);
248 /* now set the data port and operating mode
249 * (see the Data Port Selection comments at
250 * the top of the file
253 /* get current csr6 and mask off bits not to touch */
254 /* see comment at top of file */
256 tp
->csr6
= (ioread32(ioaddr
+ CSR6
) & 0xfe3bd1fd);
258 /* so if using if_port 3 or 5 then select the 100baseT
259 * port else select the 10baseT port.
260 * See the Data Port Selection table at the top
261 * of the file which was taken from the PNIC_II.PDF
264 if (dev
->if_port
& 1) tp
->csr6
|= 0x01840000;
265 else tp
->csr6
|= 0x00400000;
267 /* now set the full duplex bit appropriately */
268 if (tp
->full_duplex
) tp
->csr6
|= 0x00000200;
270 iowrite32(1, ioaddr
+ CSR13
);
273 printk(KERN_DEBUG
"%s: Setting CSR6 %8.8x/%x CSR12 "
274 "%8.8x.\n", dev
->name
, tp
->csr6
,
275 ioread32(ioaddr
+ CSR6
), ioread32(ioaddr
+ CSR12
));
277 /* now the following actually writes out the
280 tulip_start_rxtx(tp
);
285 printk(KERN_INFO
"%s: Autonegotiation failed, "
286 "using %s, link beat status %4.4x.\n",
287 dev
->name
, medianame
[dev
->if_port
], csr12
);
289 /* remember to turn off bit 7 - autonegotiate
290 * enable so we don't forget
292 csr14
= (ioread32(ioaddr
+ CSR14
) & 0xffffff7f);
293 iowrite32(csr14
,ioaddr
+ CSR14
);
295 /* what should we do when autonegotiate fails?
296 * should we try again or default to baseline
297 * case. I just don't know.
299 * for now default to some baseline case
306 /* set to 10baseTx-HD - see Data Port Selection
307 * comment given at the top of the file
309 tp
->csr6
= (ioread32(ioaddr
+ CSR6
) & 0xfe3bd1fd);
310 tp
->csr6
|= 0x00400000;
312 tulip_restart_rxtx(tp
);
319 if ((tp
->nwayset
&& (csr5
& 0x08000000)
320 && (dev
->if_port
== 3 || dev
->if_port
== 5)
321 && (csr12
& 2) == 2) || (tp
->nway
&& (csr5
& (TPLnkFail
)))) {
323 /* Link blew? Maybe restart NWay. */
326 printk(KERN_DEBUG
"%s: Ugh! Link blew?\n", dev
->name
);
328 del_timer_sync(&tp
->timer
);
329 pnic2_start_nway(dev
);
330 tp
->timer
.expires
= RUN_AT(3*HZ
);
331 add_timer(&tp
->timer
);
337 if (dev
->if_port
== 3 || dev
->if_port
== 5) {
339 /* we are at 100mb and a potential link change occurred */
342 printk(KERN_INFO
"%s: PNIC2 %s link beat %s.\n",
343 dev
->name
, medianame
[dev
->if_port
],
344 (csr12
& 2) ? "failed" : "good");
346 /* check 100 link beat */
351 /* if failed then try doing an nway to get in sync */
352 if ((csr12
& 2) && ! tp
->medialock
) {
353 del_timer_sync(&tp
->timer
);
354 pnic2_start_nway(dev
);
355 tp
->timer
.expires
= RUN_AT(3*HZ
);
356 add_timer(&tp
->timer
);
362 if (dev
->if_port
== 0 || dev
->if_port
== 4) {
364 /* we are at 10mb and a potential link change occurred */
367 printk(KERN_INFO
"%s: PNIC2 %s link beat %s.\n",
368 dev
->name
, medianame
[dev
->if_port
],
369 (csr12
& 4) ? "failed" : "good");
375 /* if failed, try doing an nway to get in sync */
376 if ((csr12
& 4) && ! tp
->medialock
) {
377 del_timer_sync(&tp
->timer
);
378 pnic2_start_nway(dev
);
379 tp
->timer
.expires
= RUN_AT(3*HZ
);
380 add_timer(&tp
->timer
);
388 printk(KERN_INFO
"%s: PNIC2 Link Change Default?\n",dev
->name
);
390 /* if all else fails default to trying 10baseT-HD */
393 /* make sure autonegotiate enable is off */
394 csr14
= (ioread32(ioaddr
+ CSR14
) & 0xffffff7f);
395 iowrite32(csr14
,ioaddr
+ CSR14
);
397 /* set to 10baseTx-HD - see Data Port Selection
398 * comment given at the top of the file
400 tp
->csr6
= (ioread32(ioaddr
+ CSR6
) & 0xfe3bd1fd);
401 tp
->csr6
|= 0x00400000;
403 tulip_restart_rxtx(tp
);