Merge with 2.3.48.
[linux-2.6/linux-mips.git] / drivers / net / tulip / 21142.c
blob57b3aa2524d5719add8064c149c100afbc625225
1 /*
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.
16 #include "tulip.h"
17 #include <asm/io.h>
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;
35 int new_csr6 = 0;
37 if (tulip_debug > 2)
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);
42 next_tick = 60*HZ;
43 } else if (tp->nwayset) {
44 /* Don't screw up a negotiated session! */
45 if (tulip_debug > 1)
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. */
52 if (tulip_debug > 1)
53 printk(KERN_INFO"%s: No 21143 100baseTx link beat, %8.8x, "
54 "trying NWay.\n", dev->name, csr12);
55 t21142_start_nway(dev);
56 next_tick = 3*HZ;
58 } else if ((csr12 & 0x7000) != 0x5000) {
59 /* Negotiation failed. Search media types. */
60 if (tulip_debug > 1)
61 printk(KERN_INFO"%s: 21143 negotiation failed, status %8.8x.\n",
62 dev->name, csr12);
63 if (!(csr12 & 4)) { /* 10mbps link beat good. */
64 new_csr6 = 0x82420000;
65 dev->if_port = 0;
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);
70 } else {
71 /* Select 100mbps port to check for link beat. */
72 new_csr6 = 0x83860000;
73 dev->if_port = 3;
74 outl(0, ioaddr + CSR13);
75 outl(0x0003FF7F, ioaddr + CSR14);
76 outw(8, ioaddr + CSR15);
77 outl(1, ioaddr + CSR13);
79 if (tulip_debug > 1)
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)) {
83 tp->csr6 &= 0x00D5;
84 tp->csr6 |= new_csr6;
85 outl(0x0301, ioaddr + CSR12);
86 tulip_outl_CSR6(tp, tp->csr6 | 0x0002);
87 tulip_outl_CSR6(tp, tp->csr6 | 0x2002);
89 next_tick = 3*HZ;
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;
104 dev->if_port = 0;
105 tp->nway = tp->mediasense = 1;
106 tp->nwayset = tp->lpar = 0;
107 if (tulip_debug > 1)
108 printk(KERN_DEBUG "%s: Restarting 21143 autonegotiation, %8.8x.\n",
109 dev->name, csr14);
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);
117 } else
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);
129 if (tulip_debug > 1)
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) {
135 int setup_done = 0;
136 int negotiated = tp->to_advertise & (csr12 >> 16);
137 tp->lpar = csr12 >> 16;
138 tp->nwayset = 1;
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;
143 else {
144 tp->nwayset = 0;
145 if ((csr12 & 2) == 0 && (tp->to_advertise & 0x0180))
146 dev->if_port = 3;
148 tp->full_duplex = (tulip_media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0;
150 if (tulip_debug > 1) {
151 if (tp->nwayset)
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);
156 else
157 printk(KERN_INFO "%s: Autonegotiation failed, using %s,"
158 " link beat status %4.4x.\n",
159 dev->name, medianame[dev->if_port], csr12);
162 if (tp->mtable) {
163 int i;
164 for (i = 0; i < tp->mtable->leafcount; i++)
165 if (tp->mtable->mleaf[i].media == dev->if_port) {
166 tp->cur_index = i;
167 tulip_select_media(dev, 0);
168 setup_done = 1;
169 break;
172 if ( ! setup_done) {
173 tp->csr6 = dev->if_port & 1 ? 0x83860000 : 0x82420000;
174 if (tp->full_duplex)
175 tp->csr6 |= 0x0200;
176 outl(1, ioaddr + CSR13);
178 #if 0 /* Restart shouldn't be needed. */
179 tulip_outl_CSR6(tp, tp->csr6 | 0x0000);
180 if (tulip_debug > 2)
181 printk(KERN_DEBUG "%s: Restarting Tx and Rx, CSR5 is %8.8x.\n",
182 dev->name, inl(ioaddr + CSR5));
183 #endif
184 tulip_outl_CSR6(tp, tp->csr6 | 0x2002);
185 if (tulip_debug > 2)
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) {
199 if (tulip_debug > 1)
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",
212 dev->name);
213 } else if (!(csr12 & 4)) { /* 10mbps link beat good. */
214 if (tulip_debug)
215 printk(KERN_INFO"%s: 21143 10mbps sensed media.\n",
216 dev->name);
217 dev->if_port = 0;
218 } else if (tp->nwayset) {
219 if (tulip_debug)
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. */
223 if (tulip_debug)
224 printk(KERN_INFO"%s: 21143 100baseTx sensed media.\n",
225 dev->name);
226 dev->if_port = 3;
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);