2 drivers/net/tulip/21142.c
4 Maintained by Jeff Garzik <jgarzik@mandrakesoft.com>
5 Copyright 2000 The Linux Kernel Team
6 Written/copyright 1994-1999 by Donald Becker.
8 This software may be used and distributed according to the terms
9 of the GNU Public License, incorporated herein by reference.
11 Please refer to Documentation/networking/tulip.txt for more
12 information on this driver.
20 static u16 t21142_csr13
[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
21 u16 t21142_csr14
[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
22 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_timer(unsigned long data
)
30 struct net_device
*dev
= (struct net_device
*)data
;
31 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
32 long ioaddr
= dev
->base_addr
;
33 int csr12
= inl(ioaddr
+ CSR12
);
34 int next_tick
= 60*HZ
;
38 printk(KERN_INFO
"%s: 21143 negotiation status %8.8x, %s.\n",
39 dev
->name
, csr12
, medianame
[dev
->if_port
]);
40 if (tulip_media_cap
[dev
->if_port
] & MediaIsMII
) {
41 tulip_check_duplex(dev
);
43 } else if (tp
->nwayset
) {
44 /* Don't screw up a negotiated session! */
46 printk(KERN_INFO
"%s: Using NWay-set %s media, csr12 %8.8x.\n",
47 dev
->name
, medianame
[dev
->if_port
], csr12
);
48 } else if (tp
->medialock
) {
50 } else if (dev
->if_port
== 3) {
51 if (csr12
& 2) { /* No 100mbps link beat, revert to 10mbps. */
53 printk(KERN_INFO
"%s: No 21143 100baseTx link beat, %8.8x, "
54 "trying NWay.\n", dev
->name
, csr12
);
55 t21142_start_nway(dev
);
58 } else if ((csr12
& 0x7000) != 0x5000) {
59 /* Negotiation failed. Search media types. */
61 printk(KERN_INFO
"%s: 21143 negotiation failed, status %8.8x.\n",
63 if (!(csr12
& 4)) { /* 10mbps link beat good. */
64 new_csr6
= 0x82420000;
66 outl(0, ioaddr
+ CSR13
);
67 outl(0x0003FFFF, ioaddr
+ CSR14
);
68 outw(t21142_csr15
[dev
->if_port
], ioaddr
+ CSR15
);
69 outl(t21142_csr13
[dev
->if_port
], ioaddr
+ CSR13
);
71 /* Select 100mbps port to check for link beat. */
72 new_csr6
= 0x83860000;
74 outl(0, ioaddr
+ CSR13
);
75 outl(0x0003FF7F, ioaddr
+ CSR14
);
76 outw(8, ioaddr
+ CSR15
);
77 outl(1, ioaddr
+ CSR13
);
80 printk(KERN_INFO
"%s: Testing new 21143 media %s.\n",
81 dev
->name
, medianame
[dev
->if_port
]);
82 if (new_csr6
!= (tp
->csr6
& ~0x00D5)) {
85 outl(0x0301, ioaddr
+ CSR12
);
86 tulip_outl_CSR6(tp
, tp
->csr6
| 0x0002);
87 tulip_outl_CSR6(tp
, tp
->csr6
| 0x2002);
92 tp
->timer
.expires
= RUN_AT(next_tick
);
93 add_timer(&tp
->timer
);
97 void t21142_start_nway(struct net_device
*dev
)
99 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
100 long ioaddr
= dev
->base_addr
;
101 int csr14
= ((tp
->to_advertise
& 0x0780) << 9) |
102 ((tp
->to_advertise
&0x0020)<<1) | 0xffbf;
105 tp
->nway
= tp
->mediasense
= 1;
106 tp
->nwayset
= tp
->lpar
= 0;
108 printk(KERN_DEBUG
"%s: Restarting 21143 autonegotiation, %8.8x.\n",
110 outl(0x0001, ioaddr
+ CSR13
);
111 outl(csr14
, ioaddr
+ CSR14
);
112 tp
->csr6
= 0x82420000 | (tp
->to_advertise
& 0x0040 ? 0x0200 : 0);
113 tulip_outl_CSR6(tp
, tp
->csr6
);
114 if (tp
->mtable
&& tp
->mtable
->csr15dir
) {
115 outl(tp
->mtable
->csr15dir
, ioaddr
+ CSR15
);
116 outl(tp
->mtable
->csr15val
, ioaddr
+ CSR15
);
118 outw(0x0008, ioaddr
+ CSR15
);
119 outl(0x1301, ioaddr
+ CSR12
); /* Trigger NWAY. */
123 void t21142_lnk_change(struct net_device
*dev
, int csr5
)
125 struct tulip_private
*tp
= (struct tulip_private
*)dev
->priv
;
126 long ioaddr
= dev
->base_addr
;
127 int csr12
= inl(ioaddr
+ CSR12
);
130 printk(KERN_INFO
"%s: 21143 link status interrupt %8.8x, CSR5 %x, "
131 "%8.8x.\n", dev
->name
, csr12
, csr5
, inl(ioaddr
+ CSR14
));
133 /* If NWay finished and we have a negotiated partner capability. */
134 if (tp
->nway
&& !tp
->nwayset
&& (csr12
& 0x7000) == 0x5000) {
136 int negotiated
= tp
->to_advertise
& (csr12
>> 16);
137 tp
->lpar
= csr12
>> 16;
139 if (negotiated
& 0x0100) dev
->if_port
= 5;
140 else if (negotiated
& 0x0080) dev
->if_port
= 3;
141 else if (negotiated
& 0x0040) dev
->if_port
= 4;
142 else if (negotiated
& 0x0020) dev
->if_port
= 0;
145 if ((csr12
& 2) == 0 && (tp
->to_advertise
& 0x0180))
148 tp
->full_duplex
= (tulip_media_cap
[dev
->if_port
] & MediaAlwaysFD
) ? 1:0;
150 if (tulip_debug
> 1) {
152 printk(KERN_INFO
"%s: Switching to %s based on link "
153 "negotiation %4.4x & %4.4x = %4.4x.\n",
154 dev
->name
, medianame
[dev
->if_port
], tp
->to_advertise
,
155 tp
->lpar
, negotiated
);
157 printk(KERN_INFO
"%s: Autonegotiation failed, using %s,"
158 " link beat status %4.4x.\n",
159 dev
->name
, medianame
[dev
->if_port
], csr12
);
164 for (i
= 0; i
< tp
->mtable
->leafcount
; i
++)
165 if (tp
->mtable
->mleaf
[i
].media
== dev
->if_port
) {
167 tulip_select_media(dev
, 0);
173 tp
->csr6
= dev
->if_port
& 1 ? 0x83860000 : 0x82420000;
176 outl(1, ioaddr
+ CSR13
);
178 #if 0 /* Restart shouldn't be needed. */
179 tulip_outl_CSR6(tp
, tp
->csr6
| 0x0000);
181 printk(KERN_DEBUG
"%s: Restarting Tx and Rx, CSR5 is %8.8x.\n",
182 dev
->name
, inl(ioaddr
+ CSR5
));
184 tulip_outl_CSR6(tp
, tp
->csr6
| 0x2002);
186 printk(KERN_DEBUG
"%s: Setting CSR6 %8.8x/%x CSR12 %8.8x.\n",
187 dev
->name
, tp
->csr6
, inl(ioaddr
+ CSR6
),
188 inl(ioaddr
+ CSR12
));
189 } else if ((tp
->nwayset
&& (csr5
& 0x08000000)
190 && (dev
->if_port
== 3 || dev
->if_port
== 5)
191 && (csr12
& 2) == 2) ||
192 (tp
->nway
&& (csr5
& (TPLnkFail
)))) {
193 /* Link blew? Maybe restart NWay. */
194 del_timer(&tp
->timer
);
195 t21142_start_nway(dev
);
196 tp
->timer
.expires
= RUN_AT(3*HZ
);
197 add_timer(&tp
->timer
);
198 } else if (dev
->if_port
== 3 || dev
->if_port
== 5) {
200 printk(KERN_INFO
"%s: 21143 %s link beat %s.\n",
201 dev
->name
, medianame
[dev
->if_port
],
202 (csr12
& 2) ? "failed" : "good");
203 if ((csr12
& 2) && ! tp
->medialock
) {
204 del_timer(&tp
->timer
);
205 t21142_start_nway(dev
);
206 tp
->timer
.expires
= RUN_AT(3*HZ
);
207 add_timer(&tp
->timer
);
209 } else if (dev
->if_port
== 0 || dev
->if_port
== 4) {
210 if ((csr12
& 4) == 0)
211 printk(KERN_INFO
"%s: 21143 10baseT link beat good.\n",
213 } else if (!(csr12
& 4)) { /* 10mbps link beat good. */
215 printk(KERN_INFO
"%s: 21143 10mbps sensed media.\n",
218 } else if (tp
->nwayset
) {
220 printk(KERN_INFO
"%s: 21143 using NWay-set %s, csr6 %8.8x.\n",
221 dev
->name
, medianame
[dev
->if_port
], tp
->csr6
);
222 } else { /* 100mbps link beat good. */
224 printk(KERN_INFO
"%s: 21143 100baseTx sensed media.\n",
227 tp
->csr6
= 0x83860000;
228 outl(0x0003FF7F, ioaddr
+ CSR14
);
229 outl(0x0301, ioaddr
+ CSR12
);
230 tulip_outl_CSR6(tp
, tp
->csr6
| 0x0002);
231 tulip_outl_CSR6(tp
, tp
->csr6
| 0x2002);