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