if_le_isa.c revision 1.22 1 /* $NetBSD: if_le_isa.c,v 1.22 1998/07/21 17:36:06 drochner 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/lancereg.h>
109 #include <dev/ic/lancevar.h>
110 #include <dev/ic/am7990reg.h>
111 #include <dev/ic/am7990var.h>
112
113 #include <dev/isa/if_levar.h>
114
115 int ne2100_isa_probe __P((struct device *, struct cfdata *, void *));
116 int bicc_isa_probe __P((struct device *, struct cfdata *, void *));
117 void le_dummyattach __P((struct device *, struct device *, void *));
118 int le_dummyprobe __P((struct device *, struct cfdata *, void *));
119 void le_ne2100_attach __P((struct device *, struct device *, void *));
120 void le_bicc_attach __P((struct device *, struct device *, void *));
121
122 struct cfattach nele_ca = {
123 sizeof(struct device), ne2100_isa_probe, le_dummyattach
124 }, le_nele_ca = {
125 sizeof(struct le_softc), le_dummyprobe, le_ne2100_attach
126 }, bicc_ca = {
127 sizeof(struct device), bicc_isa_probe, le_dummyattach
128 }, le_bicc_ca = {
129 sizeof(struct le_softc), le_dummyprobe, le_bicc_attach
130 };
131
132 struct le_isa_params {
133 char *name;
134 int iosize, rap, rdp;
135 int macstart, macstride;
136 } ne2100_params = {
137 "NE2100",
138 24, NE2100_RAP, NE2100_RDP,
139 0, 1
140 }, bicc_params = {
141 "BICC Isolan",
142 16, BICC_RAP, BICC_RDP,
143 0, 2
144 };
145
146 int lance_isa_probe __P((struct isa_attach_args *, struct le_isa_params *));
147 void le_isa_attach __P((struct device *, struct le_softc *,
148 struct isa_attach_args *, struct le_isa_params *));
149
150 int le_isa_intredge __P((void *));
151
152 #if defined(_KERNEL) && !defined(_LKM)
153 #include "opt_ddb.h"
154 #endif
155
156 #ifdef DDB
157 #define integrate
158 #define hide
159 #else
160 #define integrate static __inline
161 #define hide static
162 #endif
163
164 hide void le_isa_wrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
165 hide u_int16_t le_isa_rdcsr __P((struct lance_softc *, u_int16_t));
166
167 #define LE_ISA_MEMSIZE 16384
168
169 hide void
170 le_isa_wrcsr(sc, port, val)
171 struct lance_softc *sc;
172 u_int16_t port, val;
173 {
174 struct le_softc *lesc = (struct le_softc *)sc;
175 bus_space_tag_t iot = lesc->sc_iot;
176 bus_space_handle_t ioh = lesc->sc_ioh;
177
178 bus_space_write_2(iot, ioh, lesc->sc_rap, port);
179 bus_space_write_2(iot, ioh, lesc->sc_rdp, val);
180 }
181
182 hide u_int16_t
183 le_isa_rdcsr(sc, port)
184 struct lance_softc *sc;
185 u_int16_t port;
186 {
187 struct le_softc *lesc = (struct le_softc *)sc;
188 bus_space_tag_t iot = lesc->sc_iot;
189 bus_space_handle_t ioh = lesc->sc_ioh;
190 u_int16_t val;
191
192 bus_space_write_2(iot, ioh, lesc->sc_rap, port);
193 val = bus_space_read_2(iot, ioh, lesc->sc_rdp);
194 return (val);
195 }
196
197 int
198 ne2100_isa_probe(parent, match, aux)
199 struct device *parent;
200 struct cfdata *match;
201 void *aux;
202 {
203 return (lance_isa_probe(aux, &ne2100_params));
204 }
205
206 int
207 bicc_isa_probe(parent, match, aux)
208 struct device *parent;
209 struct cfdata *match;
210 void *aux;
211 {
212 return (lance_isa_probe(aux, &bicc_params));
213 }
214
215 /*
216 * Determine which chip is present on the card.
217 */
218 int
219 lance_isa_probe(ia, p)
220 struct isa_attach_args *ia;
221 struct le_isa_params *p;
222 {
223 bus_space_tag_t iot = ia->ia_iot;
224 bus_space_handle_t ioh;
225 int rap, rdp;
226 int rv = 0;
227
228 /* Disallow wildcarded i/o address. */
229 if (ia->ia_iobase == ISACF_PORT_DEFAULT)
230 return (0);
231
232 /* Map i/o space. */
233 if (bus_space_map(iot, ia->ia_iobase, p->iosize, 0, &ioh))
234 return (0);
235
236 rap = p->rap;
237 rdp = p->rdp;
238
239 /* Stop the LANCE chip and put it in a known state. */
240 bus_space_write_2(iot, ioh, rap, LE_CSR0);
241 bus_space_write_2(iot, ioh, rdp, LE_C0_STOP);
242 delay(100);
243
244 bus_space_write_2(iot, ioh, rap, LE_CSR0);
245 if (bus_space_read_2(iot, ioh, rdp) != LE_C0_STOP)
246 goto bad;
247
248 bus_space_write_2(iot, ioh, rap, LE_CSR3);
249 bus_space_write_2(iot, ioh, rdp, 0);
250
251 ia->ia_iosize = p->iosize;
252 rv = 1;
253
254 bad:
255 bus_space_unmap(iot, ioh, p->iosize);
256 return (rv);
257 }
258
259 void
260 le_dummyattach(parent, self, aux)
261 struct device *parent, *self;
262 void *aux;
263 {
264 printf("\n");
265
266 config_found(self, aux, 0);
267 }
268
269 int
270 le_dummyprobe(parent, match, aux)
271 struct device *parent;
272 struct cfdata *match;
273 void *aux;
274 {
275 return (1);
276 }
277
278 void
279 le_ne2100_attach(parent, self, aux)
280 struct device *parent, *self;
281 void *aux;
282 {
283 le_isa_attach(parent, (void *)self, aux, &ne2100_params);
284 }
285
286 void
287 le_bicc_attach(parent, self, aux)
288 struct device *parent, *self;
289 void *aux;
290 {
291 le_isa_attach(parent, (void *)self, aux, &bicc_params);
292 }
293
294 void
295 le_isa_attach(parent, lesc, ia, p)
296 struct device *parent;
297 struct le_softc *lesc;
298 struct isa_attach_args *ia;
299 struct le_isa_params *p;
300 {
301 struct lance_softc *sc = &lesc->sc_am7990.lsc;
302 bus_space_tag_t iot = ia->ia_iot;
303 bus_space_handle_t ioh;
304 bus_dma_tag_t dmat = ia->ia_dmat;
305 bus_dma_segment_t seg;
306 int i, rseg, error;
307
308 printf(": %s Ethernet\n", p->name);
309
310 if (bus_space_map(iot, ia->ia_iobase, p->iosize, 0, &ioh))
311 panic("%s: can't map io", sc->sc_dev.dv_xname);
312
313 /*
314 * Extract the physical MAC address from the ROM.
315 */
316 for (i = 0; i < sizeof(sc->sc_enaddr); i++)
317 sc->sc_enaddr[i] =
318 bus_space_read_1(iot, ioh, p->macstart + i * p->macstride);
319
320 lesc->sc_iot = iot;
321 lesc->sc_ioh = ioh;
322 lesc->sc_dmat = dmat;
323 lesc->sc_rap = p->rap;
324 lesc->sc_rdp = p->rdp;
325
326 /*
327 * Allocate a DMA area for the card.
328 */
329 if (bus_dmamem_alloc(dmat, LE_ISA_MEMSIZE, NBPG, 0, &seg, 1,
330 &rseg, BUS_DMA_NOWAIT)) {
331 printf("%s: couldn't allocate memory for card\n",
332 sc->sc_dev.dv_xname);
333 return;
334 }
335 if (bus_dmamem_map(dmat, &seg, rseg, LE_ISA_MEMSIZE,
336 (caddr_t *)&sc->sc_mem,
337 BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
338 printf("%s: couldn't map memory for card\n",
339 sc->sc_dev.dv_xname);
340 return;
341 }
342
343 /*
344 * Create and load the DMA map for the DMA area.
345 */
346 if (bus_dmamap_create(dmat, LE_ISA_MEMSIZE, 1,
347 LE_ISA_MEMSIZE, 0, BUS_DMA_NOWAIT, &lesc->sc_dmam)) {
348 printf("%s: couldn't create DMA map\n",
349 sc->sc_dev.dv_xname);
350 bus_dmamem_free(dmat, &seg, rseg);
351 return;
352 }
353 if (bus_dmamap_load(dmat, lesc->sc_dmam,
354 sc->sc_mem, LE_ISA_MEMSIZE, NULL, BUS_DMA_NOWAIT)) {
355 printf("%s: coundn't load DMA map\n",
356 sc->sc_dev.dv_xname);
357 bus_dmamem_free(dmat, &seg, rseg);
358 return;
359 }
360
361 sc->sc_conf3 = 0;
362 sc->sc_addr = lesc->sc_dmam->dm_segs[0].ds_addr;
363 sc->sc_memsize = LE_ISA_MEMSIZE;
364
365 sc->sc_copytodesc = lance_copytobuf_contig;
366 sc->sc_copyfromdesc = lance_copyfrombuf_contig;
367 sc->sc_copytobuf = lance_copytobuf_contig;
368 sc->sc_copyfrombuf = lance_copyfrombuf_contig;
369 sc->sc_zerobuf = lance_zerobuf_contig;
370
371 sc->sc_rdcsr = le_isa_rdcsr;
372 sc->sc_wrcsr = le_isa_wrcsr;
373 sc->sc_hwinit = NULL;
374
375 if (ia->ia_drq != DRQUNK) {
376 if ((error = isa_dmacascade(ia->ia_ic, ia->ia_drq)) != 0) {
377 printf("%s: unable to cascade DRQ, error = %d\n",
378 sc->sc_dev.dv_xname, error);
379 return;
380 }
381 }
382
383 lesc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
384 IPL_NET, le_isa_intredge, sc);
385
386 printf("%s", sc->sc_dev.dv_xname);
387 am7990_config(&lesc->sc_am7990);
388 }
389
390 /*
391 * Controller interrupt.
392 */
393 int
394 le_isa_intredge(arg)
395 void *arg;
396 {
397
398 if (am7990_intr(arg) == 0)
399 return (0);
400 for (;;)
401 if (am7990_intr(arg) == 0)
402 return (1);
403 }
404