if_le_isa.c revision 1.45 1 1.45 ad /* $NetBSD: if_le_isa.c,v 1.45 2007/10/19 12:00:18 ad Exp $ */
2 1.11 thorpej
3 1.11 thorpej /*-
4 1.23 mycroft * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 1.11 thorpej * All rights reserved.
6 1.11 thorpej *
7 1.11 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.23 mycroft * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
9 1.23 mycroft * Simulation Facility, NASA Ames Research Center.
10 1.11 thorpej *
11 1.11 thorpej * Redistribution and use in source and binary forms, with or without
12 1.11 thorpej * modification, are permitted provided that the following conditions
13 1.11 thorpej * are met:
14 1.11 thorpej * 1. Redistributions of source code must retain the above copyright
15 1.11 thorpej * notice, this list of conditions and the following disclaimer.
16 1.11 thorpej * 2. Redistributions in binary form must reproduce the above copyright
17 1.11 thorpej * notice, this list of conditions and the following disclaimer in the
18 1.11 thorpej * documentation and/or other materials provided with the distribution.
19 1.11 thorpej * 3. All advertising materials mentioning features or use of this software
20 1.11 thorpej * must display the following acknowledgement:
21 1.11 thorpej * This product includes software developed by the NetBSD
22 1.11 thorpej * Foundation, Inc. and its contributors.
23 1.11 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.11 thorpej * contributors may be used to endorse or promote products derived
25 1.11 thorpej * from this software without specific prior written permission.
26 1.11 thorpej *
27 1.11 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.11 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.11 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.11 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.11 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.11 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.11 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.11 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.11 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.11 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.11 thorpej * POSSIBILITY OF SUCH DAMAGE.
38 1.11 thorpej */
39 1.1 thorpej
40 1.1 thorpej /*-
41 1.1 thorpej * Copyright (c) 1992, 1993
42 1.1 thorpej * The Regents of the University of California. All rights reserved.
43 1.1 thorpej *
44 1.1 thorpej * This code is derived from software contributed to Berkeley by
45 1.1 thorpej * Ralph Campbell and Rick Macklem.
46 1.1 thorpej *
47 1.1 thorpej * Redistribution and use in source and binary forms, with or without
48 1.1 thorpej * modification, are permitted provided that the following conditions
49 1.1 thorpej * are met:
50 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
51 1.1 thorpej * notice, this list of conditions and the following disclaimer.
52 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
53 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
54 1.1 thorpej * documentation and/or other materials provided with the distribution.
55 1.35 agc * 3. Neither the name of the University nor the names of its contributors
56 1.1 thorpej * may be used to endorse or promote products derived from this software
57 1.1 thorpej * without specific prior written permission.
58 1.1 thorpej *
59 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.1 thorpej * SUCH DAMAGE.
70 1.1 thorpej *
71 1.1 thorpej * @(#)if_le.c 8.2 (Berkeley) 11/16/93
72 1.1 thorpej */
73 1.28 lukem
74 1.28 lukem #include <sys/cdefs.h>
75 1.45 ad __KERNEL_RCSID(0, "$NetBSD: if_le_isa.c,v 1.45 2007/10/19 12:00:18 ad Exp $");
76 1.1 thorpej
77 1.1 thorpej #include <sys/param.h>
78 1.1 thorpej #include <sys/systm.h>
79 1.1 thorpej #include <sys/mbuf.h>
80 1.1 thorpej #include <sys/syslog.h>
81 1.1 thorpej #include <sys/socket.h>
82 1.1 thorpej #include <sys/device.h>
83 1.1 thorpej
84 1.25 thorpej #include <uvm/uvm_extern.h>
85 1.25 thorpej
86 1.1 thorpej #include <net/if.h>
87 1.9 is #include <net/if_ether.h>
88 1.10 thorpej #include <net/if_media.h>
89 1.1 thorpej
90 1.45 ad #include <sys/cpu.h>
91 1.45 ad #include <sys/intr.h>
92 1.45 ad #include <sys/bus.h>
93 1.1 thorpej
94 1.1 thorpej #include <dev/isa/isareg.h>
95 1.1 thorpej #include <dev/isa/isavar.h>
96 1.1 thorpej #include <dev/isa/isadmavar.h>
97 1.1 thorpej
98 1.22 drochner #include <dev/ic/lancereg.h>
99 1.22 drochner #include <dev/ic/lancevar.h>
100 1.1 thorpej #include <dev/ic/am7990reg.h>
101 1.1 thorpej #include <dev/ic/am7990var.h>
102 1.1 thorpej
103 1.1 thorpej #include <dev/isa/if_levar.h>
104 1.1 thorpej
105 1.37 perry int ne2100_isa_probe(struct device *, struct cfdata *, void *);
106 1.37 perry int bicc_isa_probe(struct device *, struct cfdata *, void *);
107 1.37 perry void le_dummyattach(struct device *, struct device *, void *);
108 1.37 perry int le_dummyprobe(struct device *, struct cfdata *, void *);
109 1.37 perry void le_ne2100_attach(struct device *, struct device *, void *);
110 1.37 perry void le_bicc_attach(struct device *, struct device *, void *);
111 1.17 drochner
112 1.34 thorpej CFATTACH_DECL(nele, sizeof(struct device),
113 1.33 thorpej ne2100_isa_probe, le_dummyattach, NULL, NULL);
114 1.33 thorpej
115 1.33 thorpej CFATTACH_DECL(le_nele, sizeof(struct le_softc),
116 1.33 thorpej le_dummyprobe, le_ne2100_attach, NULL, NULL);
117 1.33 thorpej
118 1.33 thorpej CFATTACH_DECL(bicc, sizeof(struct device),
119 1.33 thorpej bicc_isa_probe, le_dummyattach, NULL, NULL);
120 1.33 thorpej
121 1.33 thorpej CFATTACH_DECL(le_bicc, sizeof(struct le_softc),
122 1.33 thorpej le_dummyprobe, le_bicc_attach, NULL, NULL);
123 1.1 thorpej
124 1.17 drochner struct le_isa_params {
125 1.39 christos const char *name;
126 1.17 drochner int iosize, rap, rdp;
127 1.17 drochner int macstart, macstride;
128 1.17 drochner } ne2100_params = {
129 1.17 drochner "NE2100",
130 1.17 drochner 24, NE2100_RAP, NE2100_RDP,
131 1.17 drochner 0, 1
132 1.17 drochner }, bicc_params = {
133 1.17 drochner "BICC Isolan",
134 1.17 drochner 16, BICC_RAP, BICC_RDP,
135 1.17 drochner 0, 2
136 1.1 thorpej };
137 1.1 thorpej
138 1.37 perry int lance_isa_probe(struct isa_attach_args *, struct le_isa_params *, int);
139 1.37 perry void le_isa_attach(struct device *, struct le_softc *,
140 1.37 perry struct isa_attach_args *, struct le_isa_params *);
141 1.1 thorpej
142 1.37 perry int le_isa_intredge(void *);
143 1.1 thorpej
144 1.26 mrg #if defined(_KERNEL_OPT)
145 1.22 drochner #include "opt_ddb.h"
146 1.22 drochner #endif
147 1.22 drochner
148 1.22 drochner #ifdef DDB
149 1.22 drochner #define integrate
150 1.22 drochner #define hide
151 1.22 drochner #else
152 1.41 perry #define integrate static inline
153 1.22 drochner #define hide static
154 1.22 drochner #endif
155 1.22 drochner
156 1.37 perry hide void le_isa_wrcsr(struct lance_softc *, u_int16_t, u_int16_t);
157 1.38 perry hide u_int16_t le_isa_rdcsr(struct lance_softc *, u_int16_t);
158 1.1 thorpej
159 1.11 thorpej #define LE_ISA_MEMSIZE 16384
160 1.11 thorpej
161 1.1 thorpej hide void
162 1.1 thorpej le_isa_wrcsr(sc, port, val)
163 1.22 drochner struct lance_softc *sc;
164 1.1 thorpej u_int16_t port, val;
165 1.1 thorpej {
166 1.6 thorpej struct le_softc *lesc = (struct le_softc *)sc;
167 1.6 thorpej bus_space_tag_t iot = lesc->sc_iot;
168 1.6 thorpej bus_space_handle_t ioh = lesc->sc_ioh;
169 1.1 thorpej
170 1.6 thorpej bus_space_write_2(iot, ioh, lesc->sc_rap, port);
171 1.6 thorpej bus_space_write_2(iot, ioh, lesc->sc_rdp, val);
172 1.1 thorpej }
173 1.1 thorpej
174 1.1 thorpej hide u_int16_t
175 1.1 thorpej le_isa_rdcsr(sc, port)
176 1.22 drochner struct lance_softc *sc;
177 1.1 thorpej u_int16_t port;
178 1.1 thorpej {
179 1.6 thorpej struct le_softc *lesc = (struct le_softc *)sc;
180 1.6 thorpej bus_space_tag_t iot = lesc->sc_iot;
181 1.38 perry bus_space_handle_t ioh = lesc->sc_ioh;
182 1.1 thorpej u_int16_t val;
183 1.1 thorpej
184 1.6 thorpej bus_space_write_2(iot, ioh, lesc->sc_rap, port);
185 1.38 perry val = bus_space_read_2(iot, ioh, lesc->sc_rdp);
186 1.1 thorpej return (val);
187 1.1 thorpej }
188 1.1 thorpej
189 1.1 thorpej int
190 1.43 christos ne2100_isa_probe(struct device *parent, struct cfdata *match,
191 1.42 christos void *aux)
192 1.1 thorpej {
193 1.31 rafal return (lance_isa_probe(aux, &ne2100_params, match->cf_flags));
194 1.17 drochner }
195 1.14 thorpej
196 1.17 drochner int
197 1.43 christos bicc_isa_probe(struct device *parent, struct cfdata *match, void *aux)
198 1.17 drochner {
199 1.31 rafal return (lance_isa_probe(aux, &bicc_params, match->cf_flags));
200 1.1 thorpej }
201 1.1 thorpej
202 1.17 drochner /*
203 1.17 drochner * Determine which chip is present on the card.
204 1.17 drochner */
205 1.1 thorpej int
206 1.31 rafal lance_isa_probe(ia, p, flags)
207 1.1 thorpej struct isa_attach_args *ia;
208 1.17 drochner struct le_isa_params *p;
209 1.31 rafal int flags;
210 1.1 thorpej {
211 1.6 thorpej bus_space_tag_t iot = ia->ia_iot;
212 1.6 thorpej bus_space_handle_t ioh;
213 1.17 drochner int rap, rdp;
214 1.17 drochner int rv = 0;
215 1.17 drochner
216 1.29 thorpej if (ia->ia_nio < 1)
217 1.29 thorpej return (0);
218 1.29 thorpej if (ia->ia_nirq < 1)
219 1.29 thorpej return (0);
220 1.29 thorpej if (ia->ia_ndrq < 1)
221 1.29 thorpej return (0);
222 1.29 thorpej
223 1.29 thorpej if (ISA_DIRECT_CONFIG(ia))
224 1.29 thorpej return (0);
225 1.29 thorpej
226 1.17 drochner /* Disallow wildcarded i/o address. */
227 1.36 drochner if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT)
228 1.29 thorpej return (0);
229 1.36 drochner if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ)
230 1.29 thorpej return (0);
231 1.38 perry if ((flags & LANCEISA_FLAG_LOCALBUS) == 0 &&
232 1.36 drochner ia->ia_drq[0].ir_drq == ISA_UNKNOWN_DRQ)
233 1.17 drochner return (0);
234 1.1 thorpej
235 1.6 thorpej /* Map i/o space. */
236 1.29 thorpej if (bus_space_map(iot, ia->ia_io[0].ir_addr, p->iosize, 0, &ioh))
237 1.17 drochner return (0);
238 1.6 thorpej
239 1.17 drochner rap = p->rap;
240 1.17 drochner rdp = p->rdp;
241 1.6 thorpej
242 1.17 drochner /* Stop the LANCE chip and put it in a known state. */
243 1.17 drochner bus_space_write_2(iot, ioh, rap, LE_CSR0);
244 1.17 drochner bus_space_write_2(iot, ioh, rdp, LE_C0_STOP);
245 1.17 drochner delay(100);
246 1.12 mycroft
247 1.17 drochner bus_space_write_2(iot, ioh, rap, LE_CSR0);
248 1.17 drochner if (bus_space_read_2(iot, ioh, rdp) != LE_C0_STOP)
249 1.6 thorpej goto bad;
250 1.6 thorpej
251 1.17 drochner bus_space_write_2(iot, ioh, rap, LE_CSR3);
252 1.17 drochner bus_space_write_2(iot, ioh, rdp, 0);
253 1.6 thorpej
254 1.29 thorpej ia->ia_nio = 1;
255 1.29 thorpej ia->ia_io[0].ir_size = p->iosize;
256 1.29 thorpej
257 1.29 thorpej ia->ia_nirq = 1;
258 1.31 rafal
259 1.31 rafal if ((flags & LANCEISA_FLAG_LOCALBUS) != 0 &&
260 1.36 drochner ia->ia_drq[0].ir_drq == ISA_UNKNOWN_DRQ)
261 1.31 rafal ia->ia_ndrq = 0;
262 1.31 rafal else
263 1.31 rafal ia->ia_ndrq = 1;
264 1.29 thorpej
265 1.29 thorpej ia->ia_niomem = 0;
266 1.29 thorpej
267 1.17 drochner rv = 1;
268 1.1 thorpej
269 1.17 drochner bad:
270 1.17 drochner bus_space_unmap(iot, ioh, p->iosize);
271 1.17 drochner return (rv);
272 1.17 drochner }
273 1.1 thorpej
274 1.17 drochner void
275 1.43 christos le_dummyattach(struct device *parent, struct device *self,
276 1.42 christos void *aux)
277 1.17 drochner {
278 1.17 drochner printf("\n");
279 1.1 thorpej
280 1.17 drochner config_found(self, aux, 0);
281 1.17 drochner }
282 1.1 thorpej
283 1.17 drochner int
284 1.43 christos le_dummyprobe(struct device *parent, struct cfdata *match,
285 1.43 christos void *aux)
286 1.17 drochner {
287 1.17 drochner return (1);
288 1.17 drochner }
289 1.1 thorpej
290 1.17 drochner void
291 1.17 drochner le_ne2100_attach(parent, self, aux)
292 1.17 drochner struct device *parent, *self;
293 1.17 drochner void *aux;
294 1.17 drochner {
295 1.17 drochner le_isa_attach(parent, (void *)self, aux, &ne2100_params);
296 1.17 drochner }
297 1.1 thorpej
298 1.17 drochner void
299 1.17 drochner le_bicc_attach(parent, self, aux)
300 1.17 drochner struct device *parent, *self;
301 1.17 drochner void *aux;
302 1.17 drochner {
303 1.17 drochner le_isa_attach(parent, (void *)self, aux, &bicc_params);
304 1.1 thorpej }
305 1.1 thorpej
306 1.17 drochner void
307 1.43 christos le_isa_attach(struct device *parent, struct le_softc *lesc,
308 1.42 christos struct isa_attach_args *ia, struct le_isa_params *p)
309 1.1 thorpej {
310 1.22 drochner struct lance_softc *sc = &lesc->sc_am7990.lsc;
311 1.6 thorpej bus_space_tag_t iot = ia->ia_iot;
312 1.6 thorpej bus_space_handle_t ioh;
313 1.18 drochner bus_dma_tag_t dmat = ia->ia_dmat;
314 1.17 drochner bus_dma_segment_t seg;
315 1.20 thorpej int i, rseg, error;
316 1.1 thorpej
317 1.17 drochner printf(": %s Ethernet\n", p->name);
318 1.6 thorpej
319 1.30 rafal if (bus_space_map(iot, ia->ia_io[0].ir_addr, p->iosize, 0, &ioh))
320 1.17 drochner panic("%s: can't map io", sc->sc_dev.dv_xname);
321 1.1 thorpej
322 1.1 thorpej /*
323 1.1 thorpej * Extract the physical MAC address from the ROM.
324 1.1 thorpej */
325 1.9 is for (i = 0; i < sizeof(sc->sc_enaddr); i++)
326 1.17 drochner sc->sc_enaddr[i] =
327 1.17 drochner bus_space_read_1(iot, ioh, p->macstart + i * p->macstride);
328 1.6 thorpej
329 1.7 thorpej lesc->sc_iot = iot;
330 1.7 thorpej lesc->sc_ioh = ioh;
331 1.18 drochner lesc->sc_dmat = dmat;
332 1.17 drochner lesc->sc_rap = p->rap;
333 1.17 drochner lesc->sc_rdp = p->rdp;
334 1.1 thorpej
335 1.1 thorpej /*
336 1.17 drochner * Allocate a DMA area for the card.
337 1.1 thorpej */
338 1.25 thorpej if (bus_dmamem_alloc(dmat, LE_ISA_MEMSIZE, PAGE_SIZE, 0, &seg, 1,
339 1.17 drochner &rseg, BUS_DMA_NOWAIT)) {
340 1.17 drochner printf("%s: couldn't allocate memory for card\n",
341 1.17 drochner sc->sc_dev.dv_xname);
342 1.17 drochner return;
343 1.17 drochner }
344 1.17 drochner if (bus_dmamem_map(dmat, &seg, rseg, LE_ISA_MEMSIZE,
345 1.44 christos (void **)&sc->sc_mem,
346 1.17 drochner BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
347 1.17 drochner printf("%s: couldn't map memory for card\n",
348 1.17 drochner sc->sc_dev.dv_xname);
349 1.17 drochner return;
350 1.17 drochner }
351 1.6 thorpej
352 1.6 thorpej /*
353 1.17 drochner * Create and load the DMA map for the DMA area.
354 1.6 thorpej */
355 1.17 drochner if (bus_dmamap_create(dmat, LE_ISA_MEMSIZE, 1,
356 1.17 drochner LE_ISA_MEMSIZE, 0, BUS_DMA_NOWAIT, &lesc->sc_dmam)) {
357 1.17 drochner printf("%s: couldn't create DMA map\n",
358 1.17 drochner sc->sc_dev.dv_xname);
359 1.17 drochner bus_dmamem_free(dmat, &seg, rseg);
360 1.17 drochner return;
361 1.17 drochner }
362 1.17 drochner if (bus_dmamap_load(dmat, lesc->sc_dmam,
363 1.17 drochner sc->sc_mem, LE_ISA_MEMSIZE, NULL, BUS_DMA_NOWAIT)) {
364 1.17 drochner printf("%s: coundn't load DMA map\n",
365 1.17 drochner sc->sc_dev.dv_xname);
366 1.17 drochner bus_dmamem_free(dmat, &seg, rseg);
367 1.17 drochner return;
368 1.1 thorpej }
369 1.1 thorpej
370 1.17 drochner sc->sc_conf3 = 0;
371 1.17 drochner sc->sc_addr = lesc->sc_dmam->dm_segs[0].ds_addr;
372 1.17 drochner sc->sc_memsize = LE_ISA_MEMSIZE;
373 1.17 drochner
374 1.22 drochner sc->sc_copytodesc = lance_copytobuf_contig;
375 1.22 drochner sc->sc_copyfromdesc = lance_copyfrombuf_contig;
376 1.22 drochner sc->sc_copytobuf = lance_copytobuf_contig;
377 1.22 drochner sc->sc_copyfrombuf = lance_copyfrombuf_contig;
378 1.22 drochner sc->sc_zerobuf = lance_zerobuf_contig;
379 1.1 thorpej
380 1.1 thorpej sc->sc_rdcsr = le_isa_rdcsr;
381 1.1 thorpej sc->sc_wrcsr = le_isa_wrcsr;
382 1.1 thorpej sc->sc_hwinit = NULL;
383 1.1 thorpej
384 1.31 rafal if (ia->ia_ndrq > 0) {
385 1.38 perry if ((error = isa_dmacascade(ia->ia_ic,
386 1.31 rafal ia->ia_drq[0].ir_drq)) != 0) {
387 1.31 rafal printf("%s: unable to cascade DRQ, error = %d\n",
388 1.31 rafal sc->sc_dev.dv_xname, error);
389 1.31 rafal return;
390 1.31 rafal }
391 1.20 thorpej }
392 1.1 thorpej
393 1.29 thorpej lesc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq[0].ir_irq,
394 1.29 thorpej IST_EDGE, IPL_NET, le_isa_intredge, sc);
395 1.20 thorpej
396 1.20 thorpej printf("%s", sc->sc_dev.dv_xname);
397 1.22 drochner am7990_config(&lesc->sc_am7990);
398 1.1 thorpej }
399 1.1 thorpej
400 1.1 thorpej /*
401 1.1 thorpej * Controller interrupt.
402 1.1 thorpej */
403 1.3 thorpej int
404 1.1 thorpej le_isa_intredge(arg)
405 1.1 thorpej void *arg;
406 1.1 thorpej {
407 1.1 thorpej
408 1.1 thorpej if (am7990_intr(arg) == 0)
409 1.1 thorpej return (0);
410 1.1 thorpej for (;;)
411 1.1 thorpej if (am7990_intr(arg) == 0)
412 1.1 thorpej return (1);
413 1.1 thorpej }
414