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