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