2 drivers/net/ethernet/dec/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 submit bugs to http://bugzilla.kernel.org/ .
15 /* Understanding the PNIC_II - everything is this file is based
16 * on the PNIC_II_PDF datasheet which is sorely lacking in detail
18 * As I understand things, here are the registers and bits that
19 * explain the masks and constants used in this file that are
20 * either different from the 21142/3 or important for basic operation.
23 * CSR 6 (mask = 0xfe3bd1fd of bits not to change)
27 * Bit 22 - TTM (Trasmit Threshold Mode)
28 * Bit 18 - Port Select
29 * Bit 13 - Start - 1, Stop - 0 Transmissions
30 * Bit 11:10 - Loop Back Operation Mode
31 * Bit 9 - Full Duplex mode (Advertise 10BaseT-FD is CSR14<7> is set)
32 * Bit 1 - Start - 1, Stop - 0 Receive
35 * CSR 14 (mask = 0xfff0ee39 of bits not to change)
37 * Bit 19 - PAUSE-Pause
38 * Bit 18 - Advertise T4
39 * Bit 17 - Advertise 100baseTx-FD
40 * Bit 16 - Advertise 100baseTx-HD
41 * Bit 12 - LTE - Link Test Enable
42 * Bit 7 - ANE - Auto Negotiate Enable
43 * Bit 6 - HDE - Advertise 10baseT-HD
44 * Bit 2 - Reset to Power down - kept as 1 for normal operation
45 * Bit 1 - Loop Back enable for 10baseT MCC
50 * Bit 25 - Partner can do T4
51 * Bit 24 - Partner can do 100baseTx-FD
52 * Bit 23 - Partner can do 100baseTx-HD
53 * Bit 22 - Partner can do 10baseT-FD
54 * Bit 21 - Partner can do 10baseT-HD
55 * Bit 15 - LPN is 1 if all above bits are valid other wise 0
56 * Bit 14:12 - autonegotiation state (write 001 to start autonegotiate)
57 * Bit 3 - Autopolarity state
58 * Bit 2 - LS10B - link state of 10baseT 0 - good, 1 - failed
59 * Bit 1 - LS100B - link state of 100baseT 0 - good, 1 - failed
62 * Data Port Selection Info
63 *-------------------------
65 * CSR14<7> CSR6<18> CSR6<22> CSR6<23> CSR6<24> MODE/PORT
66 * 1 0 0 (X) 0 (X) 1 NWAY
67 * 0 0 1 0 (X) 0 10baseT
68 * 0 1 0 1 1 (X) 100baseT
76 #include <linux/delay.h>
79 void pnic2_timer(unsigned long data
)
81 struct net_device
*dev
= (struct net_device
*)data
;
82 struct tulip_private
*tp
= netdev_priv(dev
);
83 void __iomem
*ioaddr
= tp
->base_addr
;
84 int next_tick
= 60*HZ
;
87 dev_info(&dev
->dev
, "PNIC2 negotiation status %08x\n",
88 ioread32(ioaddr
+ CSR12
));
91 mod_timer(&tp
->timer
, RUN_AT(next_tick
));
96 void pnic2_start_nway(struct net_device
*dev
)
98 struct tulip_private
*tp
= netdev_priv(dev
);
99 void __iomem
*ioaddr
= tp
->base_addr
;
103 /* set up what to advertise during the negotiation */
105 /* load in csr14 and mask off bits not to touch
106 * comment at top of file explains mask value
108 csr14
= (ioread32(ioaddr
+ CSR14
) & 0xfff0ee39);
110 /* bit 17 - advetise 100baseTx-FD */
111 if (tp
->sym_advertise
& 0x0100) csr14
|= 0x00020000;
113 /* bit 16 - advertise 100baseTx-HD */
114 if (tp
->sym_advertise
& 0x0080) csr14
|= 0x00010000;
116 /* bit 6 - advertise 10baseT-HD */
117 if (tp
->sym_advertise
& 0x0020) csr14
|= 0x00000040;
119 /* Now set bit 12 Link Test Enable, Bit 7 Autonegotiation Enable
120 * and bit 0 Don't PowerDown 10baseT
125 netdev_dbg(dev
, "Restarting PNIC2 autonegotiation, csr14=%08x\n",
128 /* tell pnic2_lnk_change we are doing an nway negotiation */
130 tp
->nway
= tp
->mediasense
= 1;
131 tp
->nwayset
= tp
->lpar
= 0;
133 /* now we have to set up csr6 for NWAY state */
135 tp
->csr6
= ioread32(ioaddr
+ CSR6
);
137 netdev_dbg(dev
, "On Entry to Nway, csr6=%08x\n", tp
->csr6
);
139 /* mask off any bits not to touch
140 * comment at top of file explains mask value
142 tp
->csr6
= tp
->csr6
& 0xfe3bd1fd;
144 /* don't forget that bit 9 is also used for advertising */
145 /* advertise 10baseT-FD for the negotiation (bit 9) */
146 if (tp
->sym_advertise
& 0x0040) tp
->csr6
|= 0x00000200;
148 /* set bit 24 for nway negotiation mode ...
149 * see Data Port Selection comment at top of file
150 * and "Stop" - reset both Transmit (bit 13) and Receive (bit 1)
152 tp
->csr6
|= 0x01000000;
153 iowrite32(csr14
, ioaddr
+ CSR14
);
154 iowrite32(tp
->csr6
, ioaddr
+ CSR6
);
157 /* all set up so now force the negotiation to begin */
159 /* read in current values and mask off all but the
160 * Autonegotiation bits 14:12. Writing a 001 to those bits
161 * should start the autonegotiation
163 csr12
= (ioread32(ioaddr
+ CSR12
) & 0xffff8fff);
165 iowrite32(csr12
, ioaddr
+ CSR12
);
170 void pnic2_lnk_change(struct net_device
*dev
, int csr5
)
172 struct tulip_private
*tp
= netdev_priv(dev
);
173 void __iomem
*ioaddr
= tp
->base_addr
;
176 /* read the staus register to find out what is up */
177 int csr12
= ioread32(ioaddr
+ CSR12
);
181 "PNIC2 link status interrupt %08x, CSR5 %x, %08x\n",
182 csr12
, csr5
, ioread32(ioaddr
+ CSR14
));
184 /* If NWay finished and we have a negotiated partner capability.
185 * check bits 14:12 for bit pattern 101 - all is good
187 if (tp
->nway
&& !tp
->nwayset
) {
189 /* we did an auto negotiation */
191 if ((csr12
& 0x7000) == 0x5000) {
193 /* negotiation ended successfully */
195 /* get the link partners reply and mask out all but
196 * bits 24-21 which show the partners capabilities
197 * and match those to what we advertised
199 * then begin to interpret the results of the negotiation.
200 * Always go in this order : (we are ignoring T4 for now)
201 * 100baseTx-FD, 100baseTx-HD, 10baseT-FD, 10baseT-HD
204 int negotiated
= ((csr12
>> 16) & 0x01E0) & tp
->sym_advertise
;
205 tp
->lpar
= (csr12
>> 16);
208 if (negotiated
& 0x0100) dev
->if_port
= 5;
209 else if (negotiated
& 0x0080) dev
->if_port
= 3;
210 else if (negotiated
& 0x0040) dev
->if_port
= 4;
211 else if (negotiated
& 0x0020) dev
->if_port
= 0;
215 "funny autonegotiate result csr12 %08x advertising %04x\n",
216 csr12
, tp
->sym_advertise
);
218 /* so check if 100baseTx link state is okay */
219 if ((csr12
& 2) == 0 && (tp
->sym_advertise
& 0x0180))
223 /* now record the duplex that was negotiated */
225 if ((dev
->if_port
== 4) || (dev
->if_port
== 5))
228 if (tulip_debug
> 1) {
231 "Switching to %s based on link negotiation %04x & %04x = %04x\n",
232 medianame
[dev
->if_port
],
233 tp
->sym_advertise
, tp
->lpar
,
237 /* remember to turn off bit 7 - autonegotiate
238 * enable so we can properly end nway mode and
239 * set duplex (ie. use csr6<9> again)
241 csr14
= (ioread32(ioaddr
+ CSR14
) & 0xffffff7f);
242 iowrite32(csr14
,ioaddr
+ CSR14
);
245 /* now set the data port and operating mode
246 * (see the Data Port Selection comments at
247 * the top of the file
250 /* get current csr6 and mask off bits not to touch */
251 /* see comment at top of file */
253 tp
->csr6
= (ioread32(ioaddr
+ CSR6
) & 0xfe3bd1fd);
255 /* so if using if_port 3 or 5 then select the 100baseT
256 * port else select the 10baseT port.
257 * See the Data Port Selection table at the top
258 * of the file which was taken from the PNIC_II.PDF
261 if (dev
->if_port
& 1) tp
->csr6
|= 0x01840000;
262 else tp
->csr6
|= 0x00400000;
264 /* now set the full duplex bit appropriately */
265 if (tp
->full_duplex
) tp
->csr6
|= 0x00000200;
267 iowrite32(1, ioaddr
+ CSR13
);
270 netdev_dbg(dev
, "Setting CSR6 %08x/%x CSR12 %08x\n",
272 ioread32(ioaddr
+ CSR6
),
273 ioread32(ioaddr
+ CSR12
));
275 /* now the following actually writes out the
278 tulip_start_rxtx(tp
);
284 "Autonegotiation failed, using %s, link beat status %04x\n",
285 medianame
[dev
->if_port
], csr12
);
287 /* remember to turn off bit 7 - autonegotiate
288 * enable so we don't forget
290 csr14
= (ioread32(ioaddr
+ CSR14
) & 0xffffff7f);
291 iowrite32(csr14
,ioaddr
+ CSR14
);
293 /* what should we do when autonegotiate fails?
294 * should we try again or default to baseline
295 * case. I just don't know.
297 * for now default to some baseline case
304 /* set to 10baseTx-HD - see Data Port Selection
305 * comment given at the top of the file
307 tp
->csr6
= (ioread32(ioaddr
+ CSR6
) & 0xfe3bd1fd);
308 tp
->csr6
|= 0x00400000;
310 tulip_restart_rxtx(tp
);
317 if ((tp
->nwayset
&& (csr5
& 0x08000000) &&
318 (dev
->if_port
== 3 || dev
->if_port
== 5) &&
319 (csr12
& 2) == 2) || (tp
->nway
&& (csr5
& (TPLnkFail
)))) {
321 /* Link blew? Maybe restart NWay. */
324 netdev_dbg(dev
, "Ugh! Link blew?\n");
326 del_timer_sync(&tp
->timer
);
327 pnic2_start_nway(dev
);
328 tp
->timer
.expires
= RUN_AT(3*HZ
);
329 add_timer(&tp
->timer
);
335 if (dev
->if_port
== 3 || dev
->if_port
== 5) {
337 /* we are at 100mb and a potential link change occurred */
340 dev_info(&dev
->dev
, "PNIC2 %s link beat %s\n",
341 medianame
[dev
->if_port
],
342 (csr12
& 2) ? "failed" : "good");
344 /* check 100 link beat */
349 /* if failed then try doing an nway to get in sync */
350 if ((csr12
& 2) && ! tp
->medialock
) {
351 del_timer_sync(&tp
->timer
);
352 pnic2_start_nway(dev
);
353 tp
->timer
.expires
= RUN_AT(3*HZ
);
354 add_timer(&tp
->timer
);
360 if (dev
->if_port
== 0 || dev
->if_port
== 4) {
362 /* we are at 10mb and a potential link change occurred */
365 dev_info(&dev
->dev
, "PNIC2 %s link beat %s\n",
366 medianame
[dev
->if_port
],
367 (csr12
& 4) ? "failed" : "good");
373 /* if failed, try doing an nway to get in sync */
374 if ((csr12
& 4) && ! tp
->medialock
) {
375 del_timer_sync(&tp
->timer
);
376 pnic2_start_nway(dev
);
377 tp
->timer
.expires
= RUN_AT(3*HZ
);
378 add_timer(&tp
->timer
);
386 dev_info(&dev
->dev
, "PNIC2 Link Change Default?\n");
388 /* if all else fails default to trying 10baseT-HD */
391 /* make sure autonegotiate enable is off */
392 csr14
= (ioread32(ioaddr
+ CSR14
) & 0xffffff7f);
393 iowrite32(csr14
,ioaddr
+ CSR14
);
395 /* set to 10baseTx-HD - see Data Port Selection
396 * comment given at the top of the file
398 tp
->csr6
= (ioread32(ioaddr
+ CSR6
) & 0xfe3bd1fd);
399 tp
->csr6
|= 0x00400000;
401 tulip_restart_rxtx(tp
);