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 printk(KERN_INFO
"%s: 21143 negotiation status %8.8x, %s.\n",
47 dev
->name
, 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! */
59 printk(KERN_INFO
"%s: Using NWay-set %s media, csr12 %8.8x.\n",
60 dev
->name
, medianame
[dev
->if_port
], csr12
);
61 } else if (tp
->medialock
) {
63 } else if (dev
->if_port
== 3) {
64 if (csr12
& 2) { /* No 100mbps link beat, revert to 10mbps. */
66 printk(KERN_INFO
"%s: No 21143 100baseTx link beat, %8.8x, "
67 "trying NWay.\n", dev
->name
, csr12
);
68 t21142_start_nway(dev
);
71 } else if ((csr12
& 0x7000) != 0x5000) {
72 /* Negotiation failed. Search media types. */
74 printk(KERN_INFO
"%s: 21143 negotiation failed, status %8.8x.\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 printk(KERN_INFO
"%s: Testing new 21143 media %s.\n",
94 dev
->name
, 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 printk(KERN_DEBUG
"%s: Restarting 21143 autonegotiation, csr14=%8.8x.\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)
150 printk(KERN_INFO
"%s: 21143 link status interrupt %8.8x, CSR5 %x, "
151 "%8.8x.\n", dev
->name
, csr12
, csr5
, csr14
);
153 /* If NWay finished and we have a negotiated partner capability. */
154 if (tp
->nway
&& !tp
->nwayset
&& (csr12
& 0x7000) == 0x5000) {
156 int negotiated
= tp
->sym_advertise
& (csr12
>> 16);
157 tp
->lpar
= csr12
>> 16;
159 /* If partner cannot negotiate, it is 10Mbps Half Duplex */
160 if (!(csr12
& 0x8000)) dev
->if_port
= 0;
161 else if (negotiated
& 0x0100) dev
->if_port
= 5;
162 else if (negotiated
& 0x0080) dev
->if_port
= 3;
163 else if (negotiated
& 0x0040) dev
->if_port
= 4;
164 else if (negotiated
& 0x0020) dev
->if_port
= 0;
167 if ((csr12
& 2) == 0 && (tp
->sym_advertise
& 0x0180))
170 tp
->full_duplex
= (tulip_media_cap
[dev
->if_port
] & MediaAlwaysFD
) ? 1:0;
172 if (tulip_debug
> 1) {
174 printk(KERN_INFO
"%s: Switching to %s based on link "
175 "negotiation %4.4x & %4.4x = %4.4x.\n",
176 dev
->name
, medianame
[dev
->if_port
], tp
->sym_advertise
,
177 tp
->lpar
, negotiated
);
179 printk(KERN_INFO
"%s: Autonegotiation failed, using %s,"
180 " link beat status %4.4x.\n",
181 dev
->name
, medianame
[dev
->if_port
], csr12
);
186 for (i
= 0; i
< tp
->mtable
->leafcount
; i
++)
187 if (tp
->mtable
->mleaf
[i
].media
== dev
->if_port
) {
188 int startup
= ! ((tp
->chip_id
== DC21143
&& (tp
->revision
== 48 || tp
->revision
== 65)));
190 tulip_select_media(dev
, startup
);
196 tp
->csr6
= (dev
->if_port
& 1 ? 0x838E0000 : 0x82420000) | (tp
->csr6
& 0x20ff);
199 iowrite32(1, ioaddr
+ CSR13
);
201 #if 0 /* Restart shouldn't be needed. */
202 iowrite32(tp
->csr6
| RxOn
, ioaddr
+ CSR6
);
204 printk(KERN_DEBUG
"%s: Restarting Tx and Rx, CSR5 is %8.8x.\n",
205 dev
->name
, ioread32(ioaddr
+ CSR5
));
207 tulip_start_rxtx(tp
);
209 printk(KERN_DEBUG
"%s: Setting CSR6 %8.8x/%x CSR12 %8.8x.\n",
210 dev
->name
, tp
->csr6
, ioread32(ioaddr
+ CSR6
),
211 ioread32(ioaddr
+ CSR12
));
212 } else if ((tp
->nwayset
&& (csr5
& 0x08000000)
213 && (dev
->if_port
== 3 || dev
->if_port
== 5)
214 && (csr12
& 2) == 2) ||
215 (tp
->nway
&& (csr5
& (TPLnkFail
)))) {
216 /* Link blew? Maybe restart NWay. */
217 del_timer_sync(&tp
->timer
);
218 t21142_start_nway(dev
);
219 tp
->timer
.expires
= RUN_AT(3*HZ
);
220 add_timer(&tp
->timer
);
221 } else if (dev
->if_port
== 3 || dev
->if_port
== 5) {
223 printk(KERN_INFO
"%s: 21143 %s link beat %s.\n",
224 dev
->name
, medianame
[dev
->if_port
],
225 (csr12
& 2) ? "failed" : "good");
226 if ((csr12
& 2) && ! tp
->medialock
) {
227 del_timer_sync(&tp
->timer
);
228 t21142_start_nway(dev
);
229 tp
->timer
.expires
= RUN_AT(3*HZ
);
230 add_timer(&tp
->timer
);
231 } else if (dev
->if_port
== 5)
232 iowrite32(csr14
& ~0x080, ioaddr
+ CSR14
);
233 } else if (dev
->if_port
== 0 || dev
->if_port
== 4) {
234 if ((csr12
& 4) == 0)
235 printk(KERN_INFO
"%s: 21143 10baseT link beat good.\n",
237 } else if (!(csr12
& 4)) { /* 10mbps link beat good. */
239 printk(KERN_INFO
"%s: 21143 10mbps sensed media.\n",
242 } else if (tp
->nwayset
) {
244 printk(KERN_INFO
"%s: 21143 using NWay-set %s, csr6 %8.8x.\n",
245 dev
->name
, medianame
[dev
->if_port
], tp
->csr6
);
246 } else { /* 100mbps link beat good. */
248 printk(KERN_INFO
"%s: 21143 100baseTx sensed media.\n",
251 tp
->csr6
= 0x838E0000 | (tp
->csr6
& 0x20ff);
252 iowrite32(0x0003FF7F, ioaddr
+ CSR14
);
253 iowrite32(0x0301, ioaddr
+ CSR12
);
254 tulip_restart_rxtx(tp
);