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 Please refer to Documentation/DocBook/tulip-user.{pdf,ps,html}
11 for more information on this driver.
13 DC21143 manual "21143 PCI/CardBus 10/100Mb/s Ethernet LAN Controller
14 Hardware Reference Manual" is currently available at :
15 http://developer.intel.com/design/network/manuals/278074.htm
17 Please submit bugs to http://bugzilla.kernel.org/ .
20 #include <linux/delay.h>
24 static u16 t21142_csr13
[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
25 u16 t21142_csr14
[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
26 static u16 t21142_csr15
[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
29 /* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list
30 of available transceivers. */
31 void t21142_media_task(struct work_struct
*work
)
33 struct tulip_private
*tp
=
34 container_of(work
, struct tulip_private
, media_work
);
35 struct net_device
*dev
= tp
->dev
;
36 void __iomem
*ioaddr
= tp
->base_addr
;
37 int csr12
= ioread32(ioaddr
+ CSR12
);
38 int next_tick
= 60*HZ
;
40 int csr14
= ioread32(ioaddr
+ CSR14
);
42 /* CSR12[LS10,LS100] are not reliable during autonegotiation */
43 if ((csr14
& 0x80) && (csr12
& 0x7000) != 0x5000)
46 dev_info(&dev
->dev
, "21143 negotiation status %08x, %s\n",
47 csr12
, medianame
[dev
->if_port
]);
48 if (tulip_media_cap
[dev
->if_port
] & MediaIsMII
) {
49 if (tulip_check_duplex(dev
) < 0) {
50 netif_carrier_off(dev
);
53 netif_carrier_on(dev
);
56 } else if (tp
->nwayset
) {
57 /* Don't screw up a negotiated session! */
60 "Using NWay-set %s media, csr12 %08x\n",
61 medianame
[dev
->if_port
], csr12
);
62 } else if (tp
->medialock
) {
64 } else if (dev
->if_port
== 3) {
65 if (csr12
& 2) { /* No 100mbps link beat, revert to 10mbps. */
68 "No 21143 100baseTx link beat, %08x, trying NWay\n",
70 t21142_start_nway(dev
);
73 } else if ((csr12
& 0x7000) != 0x5000) {
74 /* Negotiation failed. Search media types. */
77 "21143 negotiation failed, status %08x\n",
79 if (!(csr12
& 4)) { /* 10mbps link beat good. */
80 new_csr6
= 0x82420000;
82 iowrite32(0, ioaddr
+ CSR13
);
83 iowrite32(0x0003FFFF, ioaddr
+ CSR14
);
84 iowrite16(t21142_csr15
[dev
->if_port
], ioaddr
+ CSR15
);
85 iowrite32(t21142_csr13
[dev
->if_port
], ioaddr
+ CSR13
);
87 /* Select 100mbps port to check for link beat. */
88 new_csr6
= 0x83860000;
90 iowrite32(0, ioaddr
+ CSR13
);
91 iowrite32(0x0003FFFF, ioaddr
+ CSR14
);
92 iowrite16(8, ioaddr
+ CSR15
);
93 iowrite32(1, ioaddr
+ CSR13
);
96 dev_info(&dev
->dev
, "Testing new 21143 media %s\n",
97 medianame
[dev
->if_port
]);
98 if (new_csr6
!= (tp
->csr6
& ~0x00D5)) {
100 tp
->csr6
|= new_csr6
;
101 iowrite32(0x0301, ioaddr
+ CSR12
);
102 tulip_restart_rxtx(tp
);
107 /* mod_timer synchronizes us with potential add_timer calls
110 mod_timer(&tp
->timer
, RUN_AT(next_tick
));
114 void t21142_start_nway(struct net_device
*dev
)
116 struct tulip_private
*tp
= netdev_priv(dev
);
117 void __iomem
*ioaddr
= tp
->base_addr
;
118 int csr14
= ((tp
->sym_advertise
& 0x0780) << 9) |
119 ((tp
->sym_advertise
& 0x0020) << 1) | 0xffbf;
122 tp
->nway
= tp
->mediasense
= 1;
123 tp
->nwayset
= tp
->lpar
= 0;
125 printk(KERN_DEBUG
"%s: Restarting 21143 autonegotiation, csr14=%08x\n",
127 iowrite32(0x0001, ioaddr
+ CSR13
);
129 iowrite32(csr14
, ioaddr
+ CSR14
);
130 tp
->csr6
= 0x82420000 | (tp
->sym_advertise
& 0x0040 ? FullDuplex
: 0);
131 iowrite32(tp
->csr6
, ioaddr
+ CSR6
);
132 if (tp
->mtable
&& tp
->mtable
->csr15dir
) {
133 iowrite32(tp
->mtable
->csr15dir
, ioaddr
+ CSR15
);
134 iowrite32(tp
->mtable
->csr15val
, ioaddr
+ CSR15
);
136 iowrite16(0x0008, ioaddr
+ CSR15
);
137 iowrite32(0x1301, ioaddr
+ CSR12
); /* Trigger NWAY. */
142 void t21142_lnk_change(struct net_device
*dev
, int csr5
)
144 struct tulip_private
*tp
= netdev_priv(dev
);
145 void __iomem
*ioaddr
= tp
->base_addr
;
146 int csr12
= ioread32(ioaddr
+ CSR12
);
147 int csr14
= ioread32(ioaddr
+ CSR14
);
149 /* CSR12[LS10,LS100] are not reliable during autonegotiation */
150 if ((csr14
& 0x80) && (csr12
& 0x7000) != 0x5000)
154 "21143 link status interrupt %08x, CSR5 %x, %08x\n",
157 /* If NWay finished and we have a negotiated partner capability. */
158 if (tp
->nway
&& !tp
->nwayset
&& (csr12
& 0x7000) == 0x5000) {
160 int negotiated
= tp
->sym_advertise
& (csr12
>> 16);
161 tp
->lpar
= csr12
>> 16;
163 /* If partner cannot negotiate, it is 10Mbps Half Duplex */
164 if (!(csr12
& 0x8000)) dev
->if_port
= 0;
165 else if (negotiated
& 0x0100) dev
->if_port
= 5;
166 else if (negotiated
& 0x0080) dev
->if_port
= 3;
167 else if (negotiated
& 0x0040) dev
->if_port
= 4;
168 else if (negotiated
& 0x0020) dev
->if_port
= 0;
171 if ((csr12
& 2) == 0 && (tp
->sym_advertise
& 0x0180))
174 tp
->full_duplex
= (tulip_media_cap
[dev
->if_port
] & MediaAlwaysFD
) ? 1:0;
176 if (tulip_debug
> 1) {
179 "Switching to %s based on link negotiation %04x & %04x = %04x\n",
180 medianame
[dev
->if_port
],
181 tp
->sym_advertise
, tp
->lpar
,
185 "Autonegotiation failed, using %s, link beat status %04x\n",
186 medianame
[dev
->if_port
], csr12
);
191 for (i
= 0; i
< tp
->mtable
->leafcount
; i
++)
192 if (tp
->mtable
->mleaf
[i
].media
== dev
->if_port
) {
193 int startup
= ! ((tp
->chip_id
== DC21143
&& (tp
->revision
== 48 || tp
->revision
== 65)));
195 tulip_select_media(dev
, startup
);
201 tp
->csr6
= (dev
->if_port
& 1 ? 0x838E0000 : 0x82420000) | (tp
->csr6
& 0x20ff);
204 iowrite32(1, ioaddr
+ CSR13
);
206 #if 0 /* Restart shouldn't be needed. */
207 iowrite32(tp
->csr6
| RxOn
, ioaddr
+ CSR6
);
209 printk(KERN_DEBUG
"%s: Restarting Tx and Rx, CSR5 is %08x\n",
210 dev
->name
, ioread32(ioaddr
+ CSR5
));
212 tulip_start_rxtx(tp
);
214 printk(KERN_DEBUG
"%s: Setting CSR6 %08x/%x CSR12 %08x\n",
215 dev
->name
, tp
->csr6
, ioread32(ioaddr
+ CSR6
),
216 ioread32(ioaddr
+ CSR12
));
217 } else if ((tp
->nwayset
&& (csr5
& 0x08000000) &&
218 (dev
->if_port
== 3 || dev
->if_port
== 5) &&
220 (tp
->nway
&& (csr5
& (TPLnkFail
)))) {
221 /* Link blew? Maybe restart NWay. */
222 del_timer_sync(&tp
->timer
);
223 t21142_start_nway(dev
);
224 tp
->timer
.expires
= RUN_AT(3*HZ
);
225 add_timer(&tp
->timer
);
226 } else if (dev
->if_port
== 3 || dev
->if_port
== 5) {
228 dev_info(&dev
->dev
, "21143 %s link beat %s\n",
229 medianame
[dev
->if_port
],
230 (csr12
& 2) ? "failed" : "good");
231 if ((csr12
& 2) && ! tp
->medialock
) {
232 del_timer_sync(&tp
->timer
);
233 t21142_start_nway(dev
);
234 tp
->timer
.expires
= RUN_AT(3*HZ
);
235 add_timer(&tp
->timer
);
236 } else if (dev
->if_port
== 5)
237 iowrite32(csr14
& ~0x080, ioaddr
+ CSR14
);
238 } else if (dev
->if_port
== 0 || dev
->if_port
== 4) {
239 if ((csr12
& 4) == 0)
240 dev_info(&dev
->dev
, "21143 10baseT link beat good\n");
241 } else if (!(csr12
& 4)) { /* 10mbps link beat good. */
243 dev_info(&dev
->dev
, "21143 10mbps sensed media\n");
245 } else if (tp
->nwayset
) {
247 dev_info(&dev
->dev
, "21143 using NWay-set %s, csr6 %08x\n",
248 medianame
[dev
->if_port
], tp
->csr6
);
249 } else { /* 100mbps link beat good. */
251 dev_info(&dev
->dev
, "21143 100baseTx sensed media\n");
253 tp
->csr6
= 0x838E0000 | (tp
->csr6
& 0x20ff);
254 iowrite32(0x0003FF7F, ioaddr
+ CSR14
);
255 iowrite32(0x0301, ioaddr
+ CSR12
);
256 tulip_restart_rxtx(tp
);