if_we_pnpbus.c revision 1.3 1 1.3 garbled /* $NetBSD: if_we_pnpbus.c,v 1.3 2008/04/28 19:01:45 garbled Exp $ */
2 1.1 garbled
3 1.1 garbled /*-
4 1.1 garbled * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 1.1 garbled * All rights reserved.
6 1.1 garbled *
7 1.1 garbled * This code is derived from software contributed to The NetBSD Foundation
8 1.1 garbled * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 garbled * NASA Ames Research Center.
10 1.1 garbled *
11 1.1 garbled * Redistribution and use in source and binary forms, with or without
12 1.1 garbled * modification, are permitted provided that the following conditions
13 1.1 garbled * are met:
14 1.1 garbled * 1. Redistributions of source code must retain the above copyright
15 1.1 garbled * notice, this list of conditions and the following disclaimer.
16 1.1 garbled * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 garbled * notice, this list of conditions and the following disclaimer in the
18 1.1 garbled * documentation and/or other materials provided with the distribution.
19 1.1 garbled * 3. All advertising materials mentioning features or use of this software
20 1.1 garbled * must display the following acknowledgement:
21 1.1 garbled * This product includes software developed by the NetBSD
22 1.1 garbled * Foundation, Inc. and its contributors.
23 1.1 garbled * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1 garbled * contributors may be used to endorse or promote products derived
25 1.1 garbled * from this software without specific prior written permission.
26 1.1 garbled *
27 1.1 garbled * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1 garbled * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1 garbled * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1 garbled * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1 garbled * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 garbled * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 garbled * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 garbled * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 garbled * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 garbled * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 garbled * POSSIBILITY OF SUCH DAMAGE.
38 1.1 garbled */
39 1.1 garbled
40 1.1 garbled /*
41 1.1 garbled * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
42 1.1 garbled * adapters.
43 1.1 garbled *
44 1.1 garbled * Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
45 1.1 garbled *
46 1.1 garbled * Copyright (C) 1993, David Greenman. This software may be used, modified,
47 1.1 garbled * copied, distributed, and sold, in both source and binary form provided that
48 1.1 garbled * the above copyright and these terms are retained. Under no circumstances is
49 1.1 garbled * the author responsible for the proper functioning of this software, nor does
50 1.1 garbled * the author assume any responsibility for damages incurred with its use.
51 1.1 garbled */
52 1.1 garbled
53 1.1 garbled /*
54 1.1 garbled * Device driver for the Western Digital/SMC 8003 and 8013 series,
55 1.1 garbled * and the SMC Elite Ultra (8216).
56 1.1 garbled */
57 1.1 garbled
58 1.1 garbled #include <sys/cdefs.h>
59 1.3 garbled __KERNEL_RCSID(0, "$NetBSD: if_we_pnpbus.c,v 1.3 2008/04/28 19:01:45 garbled Exp $");
60 1.1 garbled
61 1.1 garbled #include <sys/types.h>
62 1.1 garbled #include <sys/param.h>
63 1.1 garbled #include <sys/systm.h>
64 1.1 garbled #include <sys/device.h>
65 1.1 garbled #include <sys/socket.h>
66 1.1 garbled #include <sys/mbuf.h>
67 1.1 garbled #include <sys/syslog.h>
68 1.1 garbled #include <sys/bswap.h>
69 1.1 garbled
70 1.1 garbled #include <net/if.h>
71 1.1 garbled #include <net/if_dl.h>
72 1.1 garbled #include <net/if_types.h>
73 1.1 garbled #include <net/if_media.h>
74 1.1 garbled
75 1.1 garbled #include <net/if_ether.h>
76 1.1 garbled
77 1.1 garbled #include <machine/bus.h>
78 1.1 garbled #include <machine/intr.h>
79 1.1 garbled #include <machine/isa_machdep.h>
80 1.1 garbled #include <machine/residual.h>
81 1.1 garbled
82 1.1 garbled #include <dev/ic/dp8390reg.h>
83 1.1 garbled #include <dev/ic/dp8390var.h>
84 1.1 garbled #include <dev/ic/wereg.h>
85 1.1 garbled #include <dev/ic/wevar.h>
86 1.1 garbled
87 1.1 garbled #include <prep/pnpbus/pnpbusvar.h>
88 1.1 garbled
89 1.1 garbled int we_pnpbus_probe(struct device *, struct cfdata *, void *);
90 1.1 garbled void we_pnpbus_attach(struct device *, struct device *, void *);
91 1.1 garbled
92 1.1 garbled CFATTACH_DECL(we_pnpbus, sizeof(struct we_softc),
93 1.1 garbled we_pnpbus_probe, we_pnpbus_attach, NULL, NULL);
94 1.1 garbled
95 1.1 garbled extern struct cfdriver we_cd;
96 1.1 garbled
97 1.1 garbled static const char *we_params(bus_space_tag_t, bus_space_handle_t,
98 1.1 garbled u_int8_t *, bus_size_t *, u_int8_t *, int *);
99 1.1 garbled
100 1.1 garbled #define WE_DEFAULT_IOMEM 0xe4000
101 1.1 garbled
102 1.1 garbled /*
103 1.1 garbled * Delay needed when switching 16-bit access to shared memory.
104 1.1 garbled */
105 1.1 garbled #define WE_DELAY(wsc) delay(3)
106 1.1 garbled
107 1.1 garbled /*
108 1.1 garbled * Enable card RAM, and 16-bit access.
109 1.1 garbled */
110 1.1 garbled #define WE_MEM_ENABLE(wsc) \
111 1.1 garbled do { \
112 1.1 garbled if ((wsc)->sc_16bitp) \
113 1.1 garbled bus_space_write_1((wsc)->sc_asict, (wsc)->sc_asich, \
114 1.1 garbled WE_LAAR, (wsc)->sc_laar_proto | WE_LAAR_M16EN); \
115 1.1 garbled bus_space_write_1((wsc)->sc_asict, (wsc)->sc_asich, \
116 1.1 garbled WE_MSR, wsc->sc_msr_proto | WE_MSR_MENB); \
117 1.1 garbled WE_DELAY((wsc)); \
118 1.1 garbled } while (0)
119 1.1 garbled
120 1.1 garbled /*
121 1.1 garbled * Disable card RAM, and 16-bit access.
122 1.1 garbled */
123 1.1 garbled #define WE_MEM_DISABLE(wsc) \
124 1.1 garbled do { \
125 1.1 garbled bus_space_write_1((wsc)->sc_asict, (wsc)->sc_asich, \
126 1.1 garbled WE_MSR, (wsc)->sc_msr_proto); \
127 1.1 garbled if ((wsc)->sc_16bitp) \
128 1.1 garbled bus_space_write_1((wsc)->sc_asict, (wsc)->sc_asich, \
129 1.1 garbled WE_LAAR, (wsc)->sc_laar_proto); \
130 1.1 garbled WE_DELAY((wsc)); \
131 1.1 garbled } while (0)
132 1.1 garbled
133 1.1 garbled int
134 1.1 garbled we_pnpbus_probe(struct device *parent, struct cfdata *cf, void *aux)
135 1.1 garbled {
136 1.1 garbled struct pnpbus_dev_attach_args *pna = aux;
137 1.1 garbled int ret = 0;
138 1.1 garbled
139 1.1 garbled if (strcmp(pna->pna_devid, "IBM2001") == 0)
140 1.1 garbled ret = 1;
141 1.1 garbled
142 1.1 garbled if (strcmp(pna->pna_devid, "IBM0010") == 0)
143 1.1 garbled ret = 1;
144 1.1 garbled
145 1.1 garbled if (ret)
146 1.1 garbled pnpbus_scan(pna, pna->pna_ppc_dev);
147 1.1 garbled
148 1.1 garbled return ret;
149 1.1 garbled }
150 1.1 garbled
151 1.1 garbled void
152 1.1 garbled we_pnpbus_attach(struct device *parent, struct device *self, void *aux)
153 1.1 garbled {
154 1.1 garbled struct we_softc *wsc = (struct we_softc *)self;
155 1.1 garbled struct dp8390_softc *sc = &wsc->sc_dp8390;
156 1.1 garbled struct pnpbus_dev_attach_args *pna = aux;
157 1.1 garbled struct pnpbus_irq *irq;
158 1.1 garbled bus_space_tag_t nict, asict, memt;
159 1.1 garbled bus_space_handle_t nich, asich, memh;
160 1.1 garbled bus_size_t memsize = 0x4000;
161 1.1 garbled const char *typestr;
162 1.1 garbled int memfound = 0, i, irqnum;
163 1.1 garbled
164 1.1 garbled nict = asict = pna->pna_iot;
165 1.1 garbled memt = pna->pna_memt;
166 1.1 garbled
167 1.1 garbled aprint_normal("\n");
168 1.1 garbled
169 1.1 garbled if (pnpbus_io_map(&pna->pna_res, 0, &asict, &asich)) {
170 1.1 garbled aprint_error("%s: can't map nic i/o space\n",
171 1.1 garbled device_xname(self));
172 1.1 garbled return;
173 1.1 garbled }
174 1.1 garbled
175 1.1 garbled if (bus_space_subregion(asict, asich, WE_NIC_OFFSET, WE_NIC_NPORTS,
176 1.1 garbled &nich)) {
177 1.1 garbled aprint_error("%s: can't subregion i/o space\n",
178 1.1 garbled device_xname(self));
179 1.1 garbled return;
180 1.1 garbled }
181 1.1 garbled
182 1.1 garbled typestr = we_params(asict, asich, &wsc->sc_type, &memsize,
183 1.1 garbled &wsc->sc_flags, &sc->is790);
184 1.1 garbled if (typestr == NULL) {
185 1.1 garbled aprint_error("%s: where did the card go?\n",
186 1.1 garbled device_xname(self));
187 1.1 garbled return;
188 1.1 garbled }
189 1.1 garbled
190 1.1 garbled /*
191 1.1 garbled * Map memory space. See if any was allocated via PNP, if not, use
192 1.1 garbled * the default.
193 1.1 garbled */
194 1.1 garbled if (pnpbus_iomem_map(&pna->pna_res, 0, &memt, &memh) == 0)
195 1.1 garbled memfound = 1;
196 1.1 garbled else if (bus_space_map(memt, WE_DEFAULT_IOMEM, memsize, 0, &memh)) {
197 1.1 garbled aprint_error("%s: can't map shared memory\n",
198 1.1 garbled device_xname(self));
199 1.1 garbled return;
200 1.1 garbled }
201 1.1 garbled
202 1.1 garbled wsc->sc_asict = asict;
203 1.1 garbled wsc->sc_asich = asich;
204 1.1 garbled
205 1.1 garbled sc->sc_regt = nict;
206 1.1 garbled sc->sc_regh = nich;
207 1.1 garbled
208 1.1 garbled sc->sc_buft = memt;
209 1.1 garbled sc->sc_bufh = memh;
210 1.1 garbled
211 1.1 garbled if (memfound)
212 1.1 garbled pnpbus_getiomem(&pna->pna_res, 0, &wsc->sc_maddr,
213 1.1 garbled &sc->mem_size);
214 1.1 garbled else {
215 1.1 garbled wsc->sc_maddr = WE_DEFAULT_IOMEM;
216 1.1 garbled sc->mem_size = memsize;
217 1.1 garbled }
218 1.1 garbled
219 1.1 garbled /* Interface is always enabled. */
220 1.1 garbled sc->sc_enabled = 1;
221 1.1 garbled
222 1.1 garbled if (we_config(self, wsc, typestr))
223 1.1 garbled return;
224 1.1 garbled
225 1.1 garbled /*
226 1.1 garbled * Enable the configured interrupt.
227 1.1 garbled */
228 1.1 garbled #if 0
229 1.1 garbled if (sc->is790)
230 1.1 garbled bus_space_write_1(asict, asich, WE790_ICR,
231 1.1 garbled bus_space_read_1(asict, asich, WE790_ICR) |
232 1.1 garbled WE790_ICR_EIL);
233 1.1 garbled else if (wsc->sc_type & WE_SOFTCONFIG)
234 1.1 garbled bus_space_write_1(asict, asich, WE_IRR,
235 1.1 garbled bus_space_read_1(asict, asich, WE_IRR) | WE_IRR_IEN);
236 1.1 garbled #endif
237 1.1 garbled
238 1.1 garbled /*
239 1.1 garbled * Establish interrupt handler.
240 1.1 garbled * Loop through all probed IRQs until one looks sane.
241 1.1 garbled */
242 1.1 garbled for (i = 0, irq = SIMPLEQ_FIRST(&pna->pna_res.irq);
243 1.1 garbled i < pna->pna_res.numirq; i++, irq = SIMPLEQ_NEXT(irq, next)) {
244 1.1 garbled irqnum = ffs(irq->mask) - 1;
245 1.1 garbled /* some cards think they are level. force them to edge */
246 1.1 garbled if (irq->flags & 0x0c)
247 1.1 garbled irq->flags = 0x01;
248 1.1 garbled if (!LEGAL_IRQ(irqnum))
249 1.1 garbled continue;
250 1.1 garbled if (irqnum < 2)
251 1.1 garbled continue;
252 1.1 garbled break;
253 1.1 garbled }
254 1.3 garbled wsc->sc_ih = pnpbus_intr_establish(i, IPL_NET, IST_PNP, dp8390_intr, sc,
255 1.1 garbled &pna->pna_res);
256 1.1 garbled if (wsc->sc_ih == NULL)
257 1.1 garbled aprint_error("%s: can't establish interrupt\n",
258 1.1 garbled device_xname(self));
259 1.1 garbled }
260 1.1 garbled
261 1.1 garbled static const char *
262 1.1 garbled we_params(asict, asich, typep, memsizep, flagp, is790p)
263 1.1 garbled bus_space_tag_t asict;
264 1.1 garbled bus_space_handle_t asich;
265 1.1 garbled u_int8_t *typep, *flagp;
266 1.1 garbled bus_size_t *memsizep;
267 1.1 garbled int *is790p;
268 1.1 garbled {
269 1.1 garbled const char *typestr;
270 1.1 garbled bus_size_t memsize;
271 1.1 garbled int is16bit, is790;
272 1.1 garbled u_int8_t type;
273 1.1 garbled
274 1.1 garbled memsize = 8192;
275 1.1 garbled is16bit = is790 = 0;
276 1.1 garbled
277 1.1 garbled type = bus_space_read_1(asict, asich, WE_CARD_ID);
278 1.1 garbled switch (type) {
279 1.1 garbled case WE_TYPE_WD8003S:
280 1.1 garbled typestr = "WD8003S";
281 1.1 garbled break;
282 1.1 garbled case WE_TYPE_WD8003E:
283 1.1 garbled typestr = "WD8003E";
284 1.1 garbled break;
285 1.1 garbled case WE_TYPE_WD8003EB:
286 1.1 garbled typestr = "WD8003EB";
287 1.1 garbled break;
288 1.1 garbled case WE_TYPE_WD8003W:
289 1.1 garbled typestr = "WD8003W";
290 1.1 garbled break;
291 1.1 garbled case WE_TYPE_WD8013EBT:
292 1.1 garbled typestr = "WD8013EBT";
293 1.1 garbled memsize = 16384;
294 1.1 garbled is16bit = 1;
295 1.1 garbled break;
296 1.1 garbled case WE_TYPE_WD8013W:
297 1.1 garbled typestr = "WD8013W";
298 1.1 garbled memsize = 16384;
299 1.1 garbled is16bit = 1;
300 1.1 garbled break;
301 1.1 garbled case WE_TYPE_WD8013EP: /* also WD8003EP */
302 1.1 garbled if (bus_space_read_1(asict, asich, WE_ICR) & WE_ICR_16BIT) {
303 1.1 garbled is16bit = 1;
304 1.1 garbled memsize = 16384;
305 1.1 garbled typestr = "WD8013EP";
306 1.1 garbled } else
307 1.1 garbled typestr = "WD8003EP";
308 1.1 garbled break;
309 1.1 garbled case WE_TYPE_WD8013WC:
310 1.1 garbled typestr = "WD8013WC";
311 1.1 garbled memsize = 16384;
312 1.1 garbled is16bit = 1;
313 1.1 garbled break;
314 1.1 garbled case WE_TYPE_WD8013EBP:
315 1.1 garbled typestr = "WD8013EBP";
316 1.1 garbled memsize = 16384;
317 1.1 garbled is16bit = 1;
318 1.1 garbled break;
319 1.1 garbled case WE_TYPE_WD8013EPC:
320 1.1 garbled typestr = "WD8013EPC";
321 1.1 garbled memsize = 16384;
322 1.1 garbled is16bit = 1;
323 1.1 garbled break;
324 1.1 garbled case WE_TYPE_SMC8216C:
325 1.1 garbled case WE_TYPE_SMC8216T:
326 1.1 garbled {
327 1.1 garbled u_int8_t hwr;
328 1.1 garbled
329 1.1 garbled typestr = (type == WE_TYPE_SMC8216C) ?
330 1.1 garbled "SMC8216/SMC8216C" : "SMC8216T";
331 1.1 garbled
332 1.1 garbled hwr = bus_space_read_1(asict, asich, WE790_HWR);
333 1.1 garbled bus_space_write_1(asict, asich, WE790_HWR,
334 1.1 garbled hwr | WE790_HWR_SWH);
335 1.1 garbled switch (bus_space_read_1(asict, asich, WE790_RAR) &
336 1.1 garbled WE790_RAR_SZ64) {
337 1.1 garbled case WE790_RAR_SZ64:
338 1.1 garbled memsize = 65536;
339 1.1 garbled break;
340 1.1 garbled case WE790_RAR_SZ32:
341 1.1 garbled memsize = 32768;
342 1.1 garbled break;
343 1.1 garbled case WE790_RAR_SZ16:
344 1.1 garbled memsize = 16384;
345 1.1 garbled break;
346 1.1 garbled case WE790_RAR_SZ8:
347 1.1 garbled /* 8216 has 16K shared mem -- 8416 has 8K */
348 1.1 garbled typestr = (type == WE_TYPE_SMC8216C) ?
349 1.1 garbled "SMC8416C/SMC8416BT" : "SMC8416T";
350 1.1 garbled memsize = 8192;
351 1.1 garbled break;
352 1.1 garbled }
353 1.1 garbled bus_space_write_1(asict, asich, WE790_HWR, hwr);
354 1.1 garbled
355 1.1 garbled is16bit = 1;
356 1.1 garbled is790 = 1;
357 1.1 garbled break;
358 1.1 garbled }
359 1.1 garbled #ifdef TOSH_ETHER
360 1.1 garbled case WE_TYPE_TOSHIBA1:
361 1.1 garbled typestr = "Toshiba1";
362 1.1 garbled memsize = 32768;
363 1.1 garbled is16bit = 1;
364 1.1 garbled break;
365 1.1 garbled case WE_TYPE_TOSHIBA4:
366 1.1 garbled typestr = "Toshiba4";
367 1.1 garbled memsize = 32768;
368 1.1 garbled is16bit = 1;
369 1.1 garbled break;
370 1.1 garbled #endif
371 1.1 garbled default:
372 1.1 garbled /* Not one we recognize. */
373 1.1 garbled return (NULL);
374 1.1 garbled }
375 1.1 garbled
376 1.1 garbled /*
377 1.1 garbled * Make some adjustments to initial values depending on what is
378 1.1 garbled * found in the ICR.
379 1.1 garbled */
380 1.1 garbled if (is16bit && (type != WE_TYPE_WD8013EBT) &&
381 1.1 garbled #ifdef TOSH_ETHER
382 1.1 garbled (type != WE_TYPE_TOSHIBA1 && type != WE_TYPE_TOSHIBA4) &&
383 1.1 garbled #endif
384 1.1 garbled (bus_space_read_1(asict, asich, WE_ICR) & WE_ICR_16BIT) == 0) {
385 1.1 garbled is16bit = 0;
386 1.1 garbled memsize = 8192;
387 1.1 garbled }
388 1.1 garbled
389 1.1 garbled #ifdef WE_DEBUG
390 1.1 garbled {
391 1.1 garbled int i;
392 1.1 garbled
393 1.2 garbled aprint_debug("we_params: type = 0x%x, typestr = %s,"
394 1.2 garbled " is16bit = %d, memsize = %d\n", type, typestr, is16bit,
395 1.2 garbled memsize);
396 1.1 garbled for (i = 0; i < 8; i++)
397 1.2 garbled aprint_debug(" %d -> 0x%x\n", i,
398 1.1 garbled bus_space_read_1(asict, asich, i));
399 1.1 garbled }
400 1.1 garbled #endif
401 1.1 garbled
402 1.1 garbled if (typep != NULL)
403 1.1 garbled *typep = type;
404 1.1 garbled if (memsizep != NULL)
405 1.1 garbled *memsizep = memsize;
406 1.1 garbled if (flagp != NULL && is16bit)
407 1.1 garbled *flagp |= WE_16BIT_ENABLE;
408 1.1 garbled if (is790p != NULL)
409 1.1 garbled *is790p = is790;
410 1.1 garbled return (typestr);
411 1.1 garbled }
412