if_we_mca.c revision 1.9 1 /* $NetBSD: if_we_mca.c,v 1.9 2004/01/20 19:59:59 jdolecek Exp $ */
2
3 /*-
4 * Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center, and Jaromir Dolecek.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
42 * adapters.
43 *
44 * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
45 *
46 * Copyright (C) 1993, David Greenman. This software may be used, modified,
47 * copied, distributed, and sold, in both source and binary form provided that
48 * the above copyright and these terms are retained. Under no circumstances is
49 * the author responsible for the proper functioning of this software, nor does
50 * the author assume any responsibility for damages incurred with its use.
51 */
52
53 /*
54 * Device driver for the Western Digital/SMC 8003 and 8013 series,
55 * and the SMC Elite Ultra (8216).
56 *
57 * Currently only tested with WD8003W/A and EtherCard PLUS Elite 10T/A
58 * (8013WP/A). Other WD8003 and SMC Elite based cards should work
59 * without problems too.
60 */
61
62 #include <sys/cdefs.h>
63 __KERNEL_RCSID(0, "$NetBSD: if_we_mca.c,v 1.9 2004/01/20 19:59:59 jdolecek Exp $");
64
65 #include <sys/param.h>
66 #include <sys/systm.h>
67 #include <sys/device.h>
68 #include <sys/socket.h>
69 #include <sys/mbuf.h>
70
71 #include <net/if.h>
72 #include <net/if_types.h>
73 #include <net/if_media.h>
74 #include <net/if_ether.h>
75
76 #include <machine/bus.h>
77
78 #include <dev/mca/mcareg.h>
79 #include <dev/mca/mcavar.h>
80 #include <dev/mca/mcadevs.h>
81
82 #include <dev/ic/dp8390reg.h>
83 #include <dev/ic/dp8390var.h>
84 #include <dev/ic/wereg.h>
85 #include <dev/ic/wevar.h>
86
87 #define WD_8003 0x01
88 #define WD_ELITE 0x02
89 #define WD_MEMSIZE 16384 /* all supported cards have 16K Bytes memory */
90
91 int we_mca_probe __P((struct device *, struct cfdata *, void *));
92 void we_mca_attach __P((struct device *, struct device *, void *));
93 void we_mca_init_hook __P((struct we_softc *));
94
95 CFATTACH_DECL(we_mca, sizeof(struct we_softc),
96 we_mca_probe, we_mca_attach, NULL, NULL);
97
98 /*
99 * The types for some cards may not be correct; hopefully it's close
100 * enough.
101 */
102 static const struct we_mca_product {
103 u_int32_t we_id;
104 const char *we_name;
105 int we_flag;
106 int we_type;
107 const char *we_typestr;
108 } we_mca_products[] = {
109 { MCA_PRODUCT_WD_8013EP, "EtherCard PLUS Elite/A (8013EP/A)",
110 WD_ELITE, WE_TYPE_WD8013EP, "WD8013EP/A" },
111 { MCA_PRODUCT_WD_8013WP, "EtherCard PLUS Elite 10T/A (8013WP/A)",
112 WD_ELITE, WE_TYPE_WD8013EP, "WD8013WP/A" },
113 { MCA_PRODUCT_IBM_WD_2,"IBM PS/2 Adapter/A for Ethernet Networks (UTP)",
114 WD_ELITE, WE_TYPE_WD8013EP, "WD8013WP/A"}, /* XXX */
115 { MCA_PRODUCT_IBM_WD_T,"IBM PS/2 Adapter/A for Ethernet Networks (BNC)",
116 WD_ELITE, WE_TYPE_WD8013EP, "WD8013WP/A"}, /* XXX */
117 { MCA_PRODUCT_WD_8003E, "WD EtherCard PLUS/A (WD8003E/A or WD8003ET/A)",
118 WD_8003, WE_TYPE_WD8003E, "WD8003E/A or WD8003ET/A" },
119 { MCA_PRODUCT_WD_8003ST,"WD StarCard PLUS/A (WD8003ST/A)",
120 WD_8003, WE_TYPE_WD8003W, "WD8003ST/A" }, /* XXX */
121 { MCA_PRODUCT_WD_8003W, "WD EtherCard PLUS 10T/A (WD8003W/A)",
122 WD_8003, WE_TYPE_WD8003W, "WD8003W/A" },
123 { MCA_PRODUCT_IBM_WD_O, "IBM PS/2 Adapter/A for Ethernet Networks",
124 WD_8003, WE_TYPE_WD8003W, "IBM PS/2 Adapter/A" },/*XXX*/
125 { 0x0000, NULL },
126 };
127
128 /* see POS description in we_mca_attach() */
129 static const int we_mca_irq[] = {
130 3, 4, 10, 15,
131 };
132
133 /* memory position and shared RAM sizes for WD8013-type of cards */
134 static const struct {
135 u_int8_t id;
136 int maddr;
137 int memsize;
138 } we_mca_elite_mem[] = {
139 { 0x10, 0x0C0000, 16384 },
140 { 0x12, 0x0C4000, 16384 },
141 { 0x14, 0x0C8000, 16384 },
142 { 0x16, 0x0CC000, 16384 },
143 { 0x18, 0x0D0000, 16384 },
144 { 0x1A, 0x0D4000, 16384 },
145 { 0x1C, 0x0D8000, 16384 },
146 { 0x1E, 0x0DC000, 16384 },
147 { 0x90, 0xFC0000, 16384 },
148 { 0x94, 0xFC8000, 16384 },
149 { 0x98, 0xFD0000, 16384 },
150 { 0x9A, 0xFD8000, 16384 },
151 { 0x9C, 0x0C0000, 16384 },
152 { 0x00, 0x0C0000, 8192 },
153 { 0x01, 0x0C2000, 8192 },
154 { 0x02, 0x0C4000, 8192 },
155 { 0x03, 0x0C6000, 8192 },
156 { 0, 0, 0 },
157 };
158
159
160 static const struct we_mca_product *we_mca_lookup __P((int));
161
162 static const struct we_mca_product *
163 we_mca_lookup(id)
164 int id;
165 {
166 const struct we_mca_product *wep;
167
168 for(wep = we_mca_products; wep->we_name; wep++)
169 if (wep->we_id == id)
170 return (wep);
171
172 return (NULL);
173 }
174
175 int
176 we_mca_probe(parent, cf, aux)
177 struct device *parent;
178 struct cfdata *cf;
179 void *aux;
180 {
181 struct mca_attach_args *ma = aux;
182
183 return (we_mca_lookup(ma->ma_id) != NULL);
184 }
185
186 void
187 we_mca_attach(parent, self, aux)
188 struct device *parent, *self;
189 void *aux;
190 {
191 struct we_softc *wsc = (struct we_softc *)self;
192 struct dp8390_softc *sc = &wsc->sc_dp8390;
193 struct mca_attach_args *ma = aux;
194 const struct we_mca_product *wep;
195 bus_space_tag_t nict, asict, memt;
196 bus_space_handle_t nich, asich, memh;
197 const char *typestr;
198 int irq, iobase, maddr;
199 int pos2, pos3, pos5;
200
201 pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
202 pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
203 pos5 = mca_conf_read(ma->ma_mc, ma->ma_slot, 5);
204
205 /*
206 * POS registers differ a lot between 8003 and 8013, so they are
207 * divided to two sections.
208 *
209 * 8003: POS register 2: (adf pos0)
210 * 7 6 5 4 3 2 1 0
211 * 0 0 1 \___/ \__ enable: 0=adapter disabled, 1=adapter enabled
212 * \_____ Adapter IO Space: 0x200-0x29F + XX*0x20
213 *
214 * 8003: POS register 3: (adf pos1)
215 * 7 6 5 4 3 2 1 0
216 * 1 1 0 \__/ 1 X
217 * \______ Shared Ram Space (16K Bytes):
218 * 0xC0000-0xC3FFF + XX * 0x4000
219 *
220 * 8003: POS register 5: (adf pos3)
221 * 7 6 5 4 3 2 1 0
222 * \_/
223 * \__ Interrupt Level: 00=3 01=4 10=10 11=15
224 *
225 * -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
226 *
227 * 8013: POS register 2: (adf pos0)
228 * 7 6 5 4 3 2 1 0
229 * \____/ \__ enable: 0=adapter disabled, 1=adapter enabled
230 * \___________ Adapter I/O Space: 0x0800-0x081F + XX * 0x1000
231 *
232 * 8013: POS register 3: (adf pos1)
233 * 7 6 5 4 3 2 1 0
234 * X 0 Shared Ram Base Address - mask 0x9f
235 * see wd_elite_mem[] array for details
236 *
237 * 8013: POS register 5: (adf pos3)
238 * 7 6 5 4 3 2 1 0
239 * \_/ \_/
240 * \ \__ Media Select: 00=TwPr (no link) 10=BNC
241 * \ 01=AUI|AUI or 10BaseT
242 * \____ Interrupt Level: 00=3 01=4 10=10 11=14
243 */
244
245 wep = we_mca_lookup(ma->ma_id);
246 #ifdef DIAGNOSTIC
247 if (wep == NULL) {
248 printf("\n%s: where did the card go?\n", sc->sc_dev.dv_xname);
249 return;
250 }
251 #endif
252
253 if (wep->we_flag & WD_8003) {
254 /* WD8003 based */
255 iobase = 0x200 + (((pos2 & 0x0e) >> 1) * 0x020);
256 maddr = 0xC0000 + (((pos3 & 0x1c) >> 2) * 0x04000);
257 irq = we_mca_irq[(pos5 & 0x03)];
258 sc->mem_size = WD_MEMSIZE;
259 } else {
260 /* SMC Elite */
261 int i, id;
262
263 iobase = 0x800 + (((pos2 & 0xf0) >> 4) * 0x1000);
264 irq = we_mca_irq[(pos5 & 0x0c) >> 2];
265
266 /* find location of shared mem and it's size */
267 id = (pos3 & 0x9f);
268 for(i=0; we_mca_elite_mem[i].maddr; i++)
269 if (we_mca_elite_mem[i].id == id)
270 break;
271 if (we_mca_elite_mem[i].maddr == 0) {
272 printf("\n%s: cannot find Shared Ram Base Address\n",
273 sc->sc_dev.dv_xname);
274 return;
275 }
276
277 maddr = we_mca_elite_mem[i].maddr;
278 sc->mem_size = we_mca_elite_mem[i].memsize;
279 }
280
281 nict = asict = ma->ma_iot;
282 memt = ma->ma_memt;
283
284 printf(" slot %d port %#x-%#x mem %#x-%#x irq %d: %s\n",
285 ma->ma_slot + 1,
286 iobase, iobase + WE_NPORTS - 1,
287 maddr, maddr + sc->mem_size - 1,
288 irq, wep->we_name);
289
290 /* Map the device. */
291 if (bus_space_map(asict, iobase, WE_NPORTS, 0, &asich)) {
292 printf("%s: can't map nic i/o space\n",
293 sc->sc_dev.dv_xname);
294 return;
295 }
296
297 if (bus_space_subregion(asict, asich, WE_NIC_OFFSET, WE_NIC_NPORTS,
298 &nich)) {
299 printf("%s: can't subregion i/o space\n",
300 sc->sc_dev.dv_xname);
301 return;
302 }
303
304 wsc->sc_type = wep->we_type;
305 wsc->sc_16bitp = 1; /* all cards we support are 16bit */
306 sc->is790 = 0;
307 typestr = wep->we_typestr;
308
309 /*
310 * Map memory space.
311 */
312 if (bus_space_map(memt, maddr, sc->mem_size, 0, &memh)) {
313 printf("%s: can't map shared memory %#x-%#x\n",
314 sc->sc_dev.dv_xname,
315 maddr, maddr + sc->mem_size - 1);
316 return;
317 }
318
319 wsc->sc_asict = asict;
320 wsc->sc_asich = asich;
321
322 sc->sc_regt = nict;
323 sc->sc_regh = nich;
324
325 sc->sc_buft = memt;
326 sc->sc_bufh = memh;
327
328 wsc->sc_maddr = maddr;
329
330 /* Interface is always enabled. */
331 sc->sc_enabled = 1;
332
333 wsc->sc_init_hook = we_mca_init_hook;
334
335 if (we_config(self, wsc, typestr))
336 return;
337
338 /* Map and establish the interrupt. */
339 wsc->sc_ih = mca_intr_establish(ma->ma_mc, irq,
340 IPL_NET, dp8390_intr, sc);
341 if (wsc->sc_ih == NULL) {
342 printf("%s: can't establish interrupt\n", sc->sc_dev.dv_xname);
343 return;
344 }
345 }
346
347 void
348 we_mca_init_hook(wsc)
349 struct we_softc *wsc;
350 {
351 /*
352 * This quirk really needs to be here, at least for WD8003W/A. Without
353 * this, the card doesn't send any interrupts in 16bit mode. The quirk
354 * was taken from Linux smc-mca.c driver.
355 * I do not know why it's necessary. I don't want to know. It works
356 * and that is enough for me.
357 */
358 bus_space_write_1(wsc->sc_asict, wsc->sc_asich, WE_LAAR, 0x04);
359 wsc->sc_laar_proto |= 0x04;
360 }
361