Staging: hv: mousevsc: Cleanup and properly implement reportdesc_callback()
[zen-stable.git] / drivers / net / tulip / 21142.c
blob092c3faa882a090bec438d83cd607cb54b6aca9a
1 /*
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>
21 #include "tulip.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;
39 int new_csr6 = 0;
40 int csr14 = ioread32(ioaddr + CSR14);
42 /* CSR12[LS10,LS100] are not reliable during autonegotiation */
43 if ((csr14 & 0x80) && (csr12 & 0x7000) != 0x5000)
44 csr12 |= 6;
45 if (tulip_debug > 2)
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);
51 next_tick = 3*HZ;
52 } else {
53 netif_carrier_on(dev);
54 next_tick = 60*HZ;
56 } else if (tp->nwayset) {
57 /* Don't screw up a negotiated session! */
58 if (tulip_debug > 1)
59 dev_info(&dev->dev,
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. */
66 if (tulip_debug > 1)
67 dev_info(&dev->dev,
68 "No 21143 100baseTx link beat, %08x, trying NWay\n",
69 csr12);
70 t21142_start_nway(dev);
71 next_tick = 3*HZ;
73 } else if ((csr12 & 0x7000) != 0x5000) {
74 /* Negotiation failed. Search media types. */
75 if (tulip_debug > 1)
76 dev_info(&dev->dev,
77 "21143 negotiation failed, status %08x\n",
78 csr12);
79 if (!(csr12 & 4)) { /* 10mbps link beat good. */
80 new_csr6 = 0x82420000;
81 dev->if_port = 0;
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);
86 } else {
87 /* Select 100mbps port to check for link beat. */
88 new_csr6 = 0x83860000;
89 dev->if_port = 3;
90 iowrite32(0, ioaddr + CSR13);
91 iowrite32(0x0003FFFF, ioaddr + CSR14);
92 iowrite16(8, ioaddr + CSR15);
93 iowrite32(1, ioaddr + CSR13);
95 if (tulip_debug > 1)
96 dev_info(&dev->dev, "Testing new 21143 media %s\n",
97 medianame[dev->if_port]);
98 if (new_csr6 != (tp->csr6 & ~0x00D5)) {
99 tp->csr6 &= 0x00D5;
100 tp->csr6 |= new_csr6;
101 iowrite32(0x0301, ioaddr + CSR12);
102 tulip_restart_rxtx(tp);
104 next_tick = 3*HZ;
107 /* mod_timer synchronizes us with potential add_timer calls
108 * from interrupts.
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;
121 dev->if_port = 0;
122 tp->nway = tp->mediasense = 1;
123 tp->nwayset = tp->lpar = 0;
124 if (tulip_debug > 1)
125 netdev_dbg(dev, "Restarting 21143 autonegotiation, csr14=%08x\n",
126 csr14);
127 iowrite32(0x0001, ioaddr + CSR13);
128 udelay(100);
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);
135 } else
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)
151 csr12 |= 6;
152 if (tulip_debug > 1)
153 dev_info(&dev->dev,
154 "21143 link status interrupt %08x, CSR5 %x, %08x\n",
155 csr12, csr5, csr14);
157 /* If NWay finished and we have a negotiated partner capability. */
158 if (tp->nway && !tp->nwayset && (csr12 & 0x7000) == 0x5000) {
159 int setup_done = 0;
160 int negotiated = tp->sym_advertise & (csr12 >> 16);
161 tp->lpar = csr12 >> 16;
162 tp->nwayset = 1;
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;
169 else {
170 tp->nwayset = 0;
171 if ((csr12 & 2) == 0 && (tp->sym_advertise & 0x0180))
172 dev->if_port = 3;
174 tp->full_duplex = (tulip_media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0;
176 if (tulip_debug > 1) {
177 if (tp->nwayset)
178 dev_info(&dev->dev,
179 "Switching to %s based on link negotiation %04x & %04x = %04x\n",
180 medianame[dev->if_port],
181 tp->sym_advertise, tp->lpar,
182 negotiated);
183 else
184 dev_info(&dev->dev,
185 "Autonegotiation failed, using %s, link beat status %04x\n",
186 medianame[dev->if_port], csr12);
189 if (tp->mtable) {
190 int i;
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)));
194 tp->cur_index = i;
195 tulip_select_media(dev, startup);
196 setup_done = 1;
197 break;
200 if ( ! setup_done) {
201 tp->csr6 = (dev->if_port & 1 ? 0x838E0000 : 0x82420000) | (tp->csr6 & 0x20ff);
202 if (tp->full_duplex)
203 tp->csr6 |= 0x0200;
204 iowrite32(1, ioaddr + CSR13);
206 #if 0 /* Restart shouldn't be needed. */
207 iowrite32(tp->csr6 | RxOn, ioaddr + CSR6);
208 if (tulip_debug > 2)
209 netdev_dbg(dev, " Restarting Tx and Rx, CSR5 is %08x\n",
210 ioread32(ioaddr + CSR5));
211 #endif
212 tulip_start_rxtx(tp);
213 if (tulip_debug > 2)
214 netdev_dbg(dev, " Setting CSR6 %08x/%x CSR12 %08x\n",
215 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) &&
219 (csr12 & 2) == 2) ||
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) {
227 if (tulip_debug > 1)
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. */
242 if (tulip_debug)
243 dev_info(&dev->dev, "21143 10mbps sensed media\n");
244 dev->if_port = 0;
245 } else if (tp->nwayset) {
246 if (tulip_debug)
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. */
250 if (tulip_debug)
251 dev_info(&dev->dev, "21143 100baseTx sensed media\n");
252 dev->if_port = 3;
253 tp->csr6 = 0x838E0000 | (tp->csr6 & 0x20ff);
254 iowrite32(0x0003FF7F, ioaddr + CSR14);
255 iowrite32(0x0301, ioaddr + CSR12);
256 tulip_restart_rxtx(tp);