2 drivers/net/tulip/21142.c
4 Copyright 2000,2001 The Linux Kernel Team
5 Written/copyright 1994-2001 by Donald Becker.
7 This software may be used and distributed according to the terms
8 of the GNU General Public License, incorporated herein by reference.
10 DC21143 manual "21143 PCI/CardBus 10/100Mb/s Ethernet LAN Controller
11 Hardware Reference Manual" is currently available at :
12 http://developer.intel.com/design/network/manuals/278074.htm
14 Please submit bugs to http://bugzilla.kernel.org/ .
17 #include <linux/delay.h>
21 static u16 t21142_csr13
[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
22 u16 t21142_csr14
[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
23 static u16 t21142_csr15
[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
26 /* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list
27 of available transceivers. */
28 void t21142_media_task(struct work_struct
*work
)
30 struct tulip_private
*tp
=
31 container_of(work
, struct tulip_private
, media_work
);
32 struct net_device
*dev
= tp
->dev
;
33 void __iomem
*ioaddr
= tp
->base_addr
;
34 int csr12
= ioread32(ioaddr
+ CSR12
);
35 int next_tick
= 60*HZ
;
37 int csr14
= ioread32(ioaddr
+ CSR14
);
39 /* CSR12[LS10,LS100] are not reliable during autonegotiation */
40 if ((csr14
& 0x80) && (csr12
& 0x7000) != 0x5000)
43 dev_info(&dev
->dev
, "21143 negotiation status %08x, %s\n",
44 csr12
, medianame
[dev
->if_port
]);
45 if (tulip_media_cap
[dev
->if_port
] & MediaIsMII
) {
46 if (tulip_check_duplex(dev
) < 0) {
47 netif_carrier_off(dev
);
50 netif_carrier_on(dev
);
53 } else if (tp
->nwayset
) {
54 /* Don't screw up a negotiated session! */
57 "Using NWay-set %s media, csr12 %08x\n",
58 medianame
[dev
->if_port
], csr12
);
59 } else if (tp
->medialock
) {
61 } else if (dev
->if_port
== 3) {
62 if (csr12
& 2) { /* No 100mbps link beat, revert to 10mbps. */
65 "No 21143 100baseTx link beat, %08x, trying NWay\n",
67 t21142_start_nway(dev
);
70 } else if ((csr12
& 0x7000) != 0x5000) {
71 /* Negotiation failed. Search media types. */
74 "21143 negotiation failed, status %08x\n",
76 if (!(csr12
& 4)) { /* 10mbps link beat good. */
77 new_csr6
= 0x82420000;
79 iowrite32(0, ioaddr
+ CSR13
);
80 iowrite32(0x0003FFFF, ioaddr
+ CSR14
);
81 iowrite16(t21142_csr15
[dev
->if_port
], ioaddr
+ CSR15
);
82 iowrite32(t21142_csr13
[dev
->if_port
], ioaddr
+ CSR13
);
84 /* Select 100mbps port to check for link beat. */
85 new_csr6
= 0x83860000;
87 iowrite32(0, ioaddr
+ CSR13
);
88 iowrite32(0x0003FFFF, ioaddr
+ CSR14
);
89 iowrite16(8, ioaddr
+ CSR15
);
90 iowrite32(1, ioaddr
+ CSR13
);
93 dev_info(&dev
->dev
, "Testing new 21143 media %s\n",
94 medianame
[dev
->if_port
]);
95 if (new_csr6
!= (tp
->csr6
& ~0x00D5)) {
98 iowrite32(0x0301, ioaddr
+ CSR12
);
99 tulip_restart_rxtx(tp
);
104 /* mod_timer synchronizes us with potential add_timer calls
107 mod_timer(&tp
->timer
, RUN_AT(next_tick
));
111 void t21142_start_nway(struct net_device
*dev
)
113 struct tulip_private
*tp
= netdev_priv(dev
);
114 void __iomem
*ioaddr
= tp
->base_addr
;
115 int csr14
= ((tp
->sym_advertise
& 0x0780) << 9) |
116 ((tp
->sym_advertise
& 0x0020) << 1) | 0xffbf;
119 tp
->nway
= tp
->mediasense
= 1;
120 tp
->nwayset
= tp
->lpar
= 0;
122 netdev_dbg(dev
, "Restarting 21143 autonegotiation, csr14=%08x\n",
124 iowrite32(0x0001, ioaddr
+ CSR13
);
126 iowrite32(csr14
, ioaddr
+ CSR14
);
127 tp
->csr6
= 0x82420000 | (tp
->sym_advertise
& 0x0040 ? FullDuplex
: 0);
128 iowrite32(tp
->csr6
, ioaddr
+ CSR6
);
129 if (tp
->mtable
&& tp
->mtable
->csr15dir
) {
130 iowrite32(tp
->mtable
->csr15dir
, ioaddr
+ CSR15
);
131 iowrite32(tp
->mtable
->csr15val
, ioaddr
+ CSR15
);
133 iowrite16(0x0008, ioaddr
+ CSR15
);
134 iowrite32(0x1301, ioaddr
+ CSR12
); /* Trigger NWAY. */
139 void t21142_lnk_change(struct net_device
*dev
, int csr5
)
141 struct tulip_private
*tp
= netdev_priv(dev
);
142 void __iomem
*ioaddr
= tp
->base_addr
;
143 int csr12
= ioread32(ioaddr
+ CSR12
);
144 int csr14
= ioread32(ioaddr
+ CSR14
);
146 /* CSR12[LS10,LS100] are not reliable during autonegotiation */
147 if ((csr14
& 0x80) && (csr12
& 0x7000) != 0x5000)
151 "21143 link status interrupt %08x, CSR5 %x, %08x\n",
154 /* If NWay finished and we have a negotiated partner capability. */
155 if (tp
->nway
&& !tp
->nwayset
&& (csr12
& 0x7000) == 0x5000) {
157 int negotiated
= tp
->sym_advertise
& (csr12
>> 16);
158 tp
->lpar
= csr12
>> 16;
160 /* If partner cannot negotiate, it is 10Mbps Half Duplex */
161 if (!(csr12
& 0x8000)) dev
->if_port
= 0;
162 else if (negotiated
& 0x0100) dev
->if_port
= 5;
163 else if (negotiated
& 0x0080) dev
->if_port
= 3;
164 else if (negotiated
& 0x0040) dev
->if_port
= 4;
165 else if (negotiated
& 0x0020) dev
->if_port
= 0;
168 if ((csr12
& 2) == 0 && (tp
->sym_advertise
& 0x0180))
171 tp
->full_duplex
= (tulip_media_cap
[dev
->if_port
] & MediaAlwaysFD
) ? 1:0;
173 if (tulip_debug
> 1) {
176 "Switching to %s based on link negotiation %04x & %04x = %04x\n",
177 medianame
[dev
->if_port
],
178 tp
->sym_advertise
, tp
->lpar
,
182 "Autonegotiation failed, using %s, link beat status %04x\n",
183 medianame
[dev
->if_port
], csr12
);
188 for (i
= 0; i
< tp
->mtable
->leafcount
; i
++)
189 if (tp
->mtable
->mleaf
[i
].media
== dev
->if_port
) {
190 int startup
= ! ((tp
->chip_id
== DC21143
&& (tp
->revision
== 48 || tp
->revision
== 65)));
192 tulip_select_media(dev
, startup
);
198 tp
->csr6
= (dev
->if_port
& 1 ? 0x838E0000 : 0x82420000) | (tp
->csr6
& 0x20ff);
201 iowrite32(1, ioaddr
+ CSR13
);
203 #if 0 /* Restart shouldn't be needed. */
204 iowrite32(tp
->csr6
| RxOn
, ioaddr
+ CSR6
);
206 netdev_dbg(dev
, " Restarting Tx and Rx, CSR5 is %08x\n",
207 ioread32(ioaddr
+ CSR5
));
209 tulip_start_rxtx(tp
);
211 netdev_dbg(dev
, " Setting CSR6 %08x/%x CSR12 %08x\n",
212 tp
->csr6
, ioread32(ioaddr
+ CSR6
),
213 ioread32(ioaddr
+ CSR12
));
214 } else if ((tp
->nwayset
&& (csr5
& 0x08000000) &&
215 (dev
->if_port
== 3 || dev
->if_port
== 5) &&
217 (tp
->nway
&& (csr5
& (TPLnkFail
)))) {
218 /* Link blew? Maybe restart NWay. */
219 del_timer_sync(&tp
->timer
);
220 t21142_start_nway(dev
);
221 tp
->timer
.expires
= RUN_AT(3*HZ
);
222 add_timer(&tp
->timer
);
223 } else if (dev
->if_port
== 3 || dev
->if_port
== 5) {
225 dev_info(&dev
->dev
, "21143 %s link beat %s\n",
226 medianame
[dev
->if_port
],
227 (csr12
& 2) ? "failed" : "good");
228 if ((csr12
& 2) && ! tp
->medialock
) {
229 del_timer_sync(&tp
->timer
);
230 t21142_start_nway(dev
);
231 tp
->timer
.expires
= RUN_AT(3*HZ
);
232 add_timer(&tp
->timer
);
233 } else if (dev
->if_port
== 5)
234 iowrite32(csr14
& ~0x080, ioaddr
+ CSR14
);
235 } else if (dev
->if_port
== 0 || dev
->if_port
== 4) {
236 if ((csr12
& 4) == 0)
237 dev_info(&dev
->dev
, "21143 10baseT link beat good\n");
238 } else if (!(csr12
& 4)) { /* 10mbps link beat good. */
240 dev_info(&dev
->dev
, "21143 10mbps sensed media\n");
242 } else if (tp
->nwayset
) {
244 dev_info(&dev
->dev
, "21143 using NWay-set %s, csr6 %08x\n",
245 medianame
[dev
->if_port
], tp
->csr6
);
246 } else { /* 100mbps link beat good. */
248 dev_info(&dev
->dev
, "21143 100baseTx sensed media\n");
250 tp
->csr6
= 0x838E0000 | (tp
->csr6
& 0x20ff);
251 iowrite32(0x0003FF7F, ioaddr
+ CSR14
);
252 iowrite32(0x0301, ioaddr
+ CSR12
);
253 tulip_restart_rxtx(tp
);