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