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