1/*
2 drivers/net/ethernet/dec/tulip/21142.c
3
4 Copyright 2000,2001 The Linux Kernel Team
5 Written/copyright 1994-2001 by Donald Becker.
6
7 This software may be used and distributed according to the terms
8 of the GNU General Public License, incorporated herein by reference.
9
10 DC21143 manual "21143 PCI/CardBus 10/100Mb/s Ethernet LAN Controller
11 Hardware Reference Manual" is currently available at :
12 http://developer.intel.com/design/network/manuals/278074.htm
13
14 Please submit bugs to http://bugzilla.kernel.org/ .
15*/
16
17#include <linux/delay.h>
18#include "tulip.h"
19
20
21static u16 t21142_csr13[] = { 0x0001, 0x0009, 0x0009, 0x0000, 0x0001, };
22u16 t21142_csr14[] = { 0xFFFF, 0x0705, 0x0705, 0x0000, 0x7F3D, };
23static u16 t21142_csr15[] = { 0x0008, 0x0006, 0x000E, 0x0008, 0x0008, };
24
25
26/* Handle the 21143 uniquely: do autoselect with NWay, not the EEPROM list
27 of available transceivers. */
28void t21142_media_task(struct work_struct *work)
29{
30 struct tulip_private *tp =
31 container_of(work, struct tulip_private, media_work);
32 struct net_device *dev = tp->dev;
33 void __iomem *ioaddr = tp->base_addr;
34 int csr12 = ioread32(ioaddr + CSR12);
35 int next_tick = 60*HZ;
36 int new_csr6 = 0;
37 int csr14 = ioread32(ioaddr + CSR14);
38
39 /* CSR12[LS10,LS100] are not reliable during autonegotiation */
40 if ((csr14 & 0x80) && (csr12 & 0x7000) != 0x5000)
41 csr12 |= 6;
42 if (tulip_debug > 2)
43 dev_info(&dev->dev, "21143 negotiation status %08x, %s\n",
44 csr12, medianame[dev->if_port]);
45 if (tulip_media_cap[dev->if_port] & MediaIsMII) {
46 if (tulip_check_duplex(dev) < 0) {
47 netif_carrier_off(dev);
48 next_tick = 3*HZ;
49 } else {
50 netif_carrier_on(dev);
51 next_tick = 60*HZ;
52 }
53 } else if (tp->nwayset) {
54 /* Don't screw up a negotiated session! */
55 if (tulip_debug > 1)
56 dev_info(&dev->dev,
57 "Using NWay-set %s media, csr12 %08x\n",
58 medianame[dev->if_port], csr12);
59 } else if (tp->medialock) {
60 ;
61 } else if (dev->if_port == 3) {
62 if (csr12 & 2) { /* No 100mbps link beat, revert to 10mbps. */
63 if (tulip_debug > 1)
64 dev_info(&dev->dev,
65 "No 21143 100baseTx link beat, %08x, trying NWay\n",
66 csr12);
67 t21142_start_nway(dev);
68 next_tick = 3*HZ;
69 }
70 } else if ((csr12 & 0x7000) != 0x5000) {
71 /* Negotiation failed. Search media types. */
72 if (tulip_debug > 1)
73 dev_info(&dev->dev,
74 "21143 negotiation failed, status %08x\n",
75 csr12);
76 if (!(csr12 & 4)) { /* 10mbps link beat good. */
77 new_csr6 = 0x82420000;
78 dev->if_port = 0;
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);
83 } else {
84 /* Select 100mbps port to check for link beat. */
85 new_csr6 = 0x83860000;
86 dev->if_port = 3;
87 iowrite32(0, ioaddr + CSR13);
88 iowrite32(0x0003FFFF, ioaddr + CSR14);
89 iowrite16(8, ioaddr + CSR15);
90 iowrite32(1, ioaddr + CSR13);
91 }
92 if (tulip_debug > 1)
93 dev_info(&dev->dev, "Testing new 21143 media %s\n",
94 medianame[dev->if_port]);
95 if (new_csr6 != (tp->csr6 & ~0x00D5)) {
96 tp->csr6 &= 0x00D5;
97 tp->csr6 |= new_csr6;
98 iowrite32(0x0301, ioaddr + CSR12);
99 tulip_restart_rxtx(tp);
100 }
101 next_tick = 3*HZ;
102 }
103
104 /* mod_timer synchronizes us with potential add_timer calls
105 * from interrupts.
106 */
107 mod_timer(timer: &tp->timer, RUN_AT(next_tick));
108}
109
110
111void t21142_start_nway(struct net_device *dev)
112{
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;
117
118 dev->if_port = 0;
119 tp->nway = tp->mediasense = 1;
120 tp->nwayset = tp->lpar = 0;
121 if (tulip_debug > 1)
122 netdev_dbg(dev, "Restarting 21143 autonegotiation, csr14=%08x\n",
123 csr14);
124 iowrite32(0x0001, ioaddr + CSR13);
125 udelay(100);
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);
132 } else
133 iowrite16(0x0008, ioaddr + CSR15);
134 iowrite32(0x1301, ioaddr + CSR12); /* Trigger NWAY. */
135}
136
137
138
139void t21142_lnk_change(struct net_device *dev, int csr5)
140{
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);
145
146 /* CSR12[LS10,LS100] are not reliable during autonegotiation */
147 if ((csr14 & 0x80) && (csr12 & 0x7000) != 0x5000)
148 csr12 |= 6;
149 if (tulip_debug > 1)
150 dev_info(&dev->dev,
151 "21143 link status interrupt %08x, CSR5 %x, %08x\n",
152 csr12, csr5, csr14);
153
154 /* If NWay finished and we have a negotiated partner capability. */
155 if (tp->nway && !tp->nwayset && (csr12 & 0x7000) == 0x5000) {
156 int setup_done = 0;
157 int negotiated = tp->sym_advertise & (csr12 >> 16);
158 tp->lpar = csr12 >> 16;
159 tp->nwayset = 1;
160 /* If partner cannot negotiate, it is 10Mbps Half Duplex */
161 if (!(csr12 & 0x8000)) dev->if_port = 0;
162 else if (negotiated & 0x0100) dev->if_port = 5;
163 else if (negotiated & 0x0080) dev->if_port = 3;
164 else if (negotiated & 0x0040) dev->if_port = 4;
165 else if (negotiated & 0x0020) dev->if_port = 0;
166 else {
167 tp->nwayset = 0;
168 if ((csr12 & 2) == 0 && (tp->sym_advertise & 0x0180))
169 dev->if_port = 3;
170 }
171 tp->full_duplex = (tulip_media_cap[dev->if_port] & MediaAlwaysFD) ? 1:0;
172
173 if (tulip_debug > 1) {
174 if (tp->nwayset)
175 dev_info(&dev->dev,
176 "Switching to %s based on link negotiation %04x & %04x = %04x\n",
177 medianame[dev->if_port],
178 tp->sym_advertise, tp->lpar,
179 negotiated);
180 else
181 dev_info(&dev->dev,
182 "Autonegotiation failed, using %s, link beat status %04x\n",
183 medianame[dev->if_port], csr12);
184 }
185
186 if (tp->mtable) {
187 int i;
188 for (i = 0; i < tp->mtable->leafcount; i++)
189 if (tp->mtable->mleaf[i].media == dev->if_port) {
190 int startup = ! ((tp->chip_id == DC21143 && (tp->revision == 48 || tp->revision == 65)));
191 tp->cur_index = i;
192 tulip_select_media(dev, startup);
193 setup_done = 1;
194 break;
195 }
196 }
197 if ( ! setup_done) {
198 tp->csr6 = (dev->if_port & 1 ? 0x838E0000 : 0x82420000) | (tp->csr6 & 0x20ff);
199 if (tp->full_duplex)
200 tp->csr6 |= 0x0200;
201 iowrite32(1, ioaddr + CSR13);
202 }
203#if 0 /* Restart shouldn't be needed. */
204 iowrite32(tp->csr6 | RxOn, ioaddr + CSR6);
205 if (tulip_debug > 2)
206 netdev_dbg(dev, " Restarting Tx and Rx, CSR5 is %08x\n",
207 ioread32(ioaddr + CSR5));
208#endif
209 tulip_start_rxtx(tp);
210 if (tulip_debug > 2)
211 netdev_dbg(dev, " Setting CSR6 %08x/%x CSR12 %08x\n",
212 tp->csr6, ioread32(ioaddr + CSR6),
213 ioread32(ioaddr + CSR12));
214 } else if ((tp->nwayset && (csr5 & 0x08000000) &&
215 (dev->if_port == 3 || dev->if_port == 5) &&
216 (csr12 & 2) == 2) ||
217 (tp->nway && (csr5 & (TPLnkFail)))) {
218 /* Link blew? Maybe restart NWay. */
219 del_timer_sync(timer: &tp->timer);
220 t21142_start_nway(dev);
221 tp->timer.expires = RUN_AT(3*HZ);
222 add_timer(timer: &tp->timer);
223 } else if (dev->if_port == 3 || dev->if_port == 5) {
224 if (tulip_debug > 1)
225 dev_info(&dev->dev, "21143 %s link beat %s\n",
226 medianame[dev->if_port],
227 (csr12 & 2) ? "failed" : "good");
228 if ((csr12 & 2) && ! tp->medialock) {
229 del_timer_sync(timer: &tp->timer);
230 t21142_start_nway(dev);
231 tp->timer.expires = RUN_AT(3*HZ);
232 add_timer(timer: &tp->timer);
233 } else if (dev->if_port == 5)
234 iowrite32(csr14 & ~0x080, ioaddr + CSR14);
235 } else if (dev->if_port == 0 || dev->if_port == 4) {
236 if ((csr12 & 4) == 0)
237 dev_info(&dev->dev, "21143 10baseT link beat good\n");
238 } else if (!(csr12 & 4)) { /* 10mbps link beat good. */
239 if (tulip_debug)
240 dev_info(&dev->dev, "21143 10mbps sensed media\n");
241 dev->if_port = 0;
242 } else if (tp->nwayset) {
243 if (tulip_debug)
244 dev_info(&dev->dev, "21143 using NWay-set %s, csr6 %08x\n",
245 medianame[dev->if_port], tp->csr6);
246 } else { /* 100mbps link beat good. */
247 if (tulip_debug)
248 dev_info(&dev->dev, "21143 100baseTx sensed media\n");
249 dev->if_port = 3;
250 tp->csr6 = 0x838E0000 | (tp->csr6 & 0x20ff);
251 iowrite32(0x0003FF7F, ioaddr + CSR14);
252 iowrite32(0x0301, ioaddr + CSR12);
253 tulip_restart_rxtx(tp);
254 }
255}
256
257
258

source code of linux/drivers/net/ethernet/dec/tulip/21142.c