1 /* $NetBSD: if_le_isa.c,v 1.47 2008/04/28 20:23:52 martin Exp $ */
4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
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.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1992, 1993
35 * The Regents of the University of California. All rights reserved.
37 * This code is derived from software contributed to Berkeley by
38 * Ralph Campbell and Rick Macklem.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
67 #include <sys/cdefs.h>
68 __KERNEL_RCSID(0, "$NetBSD: if_le_isa.c,v 1.47 2008/04/28 20:23:52 martin Exp $");
70 #include <sys/param.h>
71 #include <sys/systm.h>
73 #include <sys/syslog.h>
74 #include <sys/socket.h>
75 #include <sys/device.h>
77 #include <uvm/uvm_extern.h>
80 #include <net/if_ether.h>
81 #include <net/if_media.h>
87 #include <dev/isa/isareg.h>
88 #include <dev/isa/isavar.h>
89 #include <dev/isa/isadmavar.h>
91 #include <dev/ic/lancereg.h>
92 #include <dev/ic/lancevar.h>
93 #include <dev/ic/am7990reg.h>
94 #include <dev/ic/am7990var.h>
96 #include <dev/isa/if_levar.h>
98 int ne2100_isa_probe(device_t
, cfdata_t
, void *);
99 int bicc_isa_probe(device_t
, cfdata_t
, void *);
100 void le_dummyattach(device_t
, device_t
, void *);
101 int le_dummyprobe(device_t
, cfdata_t
, void *);
102 void le_ne2100_attach(device_t
, device_t
, void *);
103 void le_bicc_attach(device_t
, device_t
, void *);
105 CFATTACH_DECL_NEW(nele
, 0,
106 ne2100_isa_probe
, le_dummyattach
, NULL
, NULL
);
108 CFATTACH_DECL_NEW(le_nele
, sizeof(struct le_softc
),
109 le_dummyprobe
, le_ne2100_attach
, NULL
, NULL
);
111 CFATTACH_DECL_NEW(bicc
, 0,
112 bicc_isa_probe
, le_dummyattach
, NULL
, NULL
);
114 CFATTACH_DECL_NEW(le_bicc
, sizeof(struct le_softc
),
115 le_dummyprobe
, le_bicc_attach
, NULL
, NULL
);
117 struct le_isa_params
{
119 int iosize
, rap
, rdp
;
120 int macstart
, macstride
;
123 24, NE2100_RAP
, NE2100_RDP
,
127 16, BICC_RAP
, BICC_RDP
,
131 int lance_isa_probe(struct isa_attach_args
*, struct le_isa_params
*, int);
132 void le_isa_attach(device_t
, struct le_softc
*,
133 struct isa_attach_args
*, struct le_isa_params
*);
135 int le_isa_intredge(void *);
137 #if defined(_KERNEL_OPT)
145 #define integrate static inline
149 hide
void le_isa_wrcsr(struct lance_softc
*, uint16_t, uint16_t);
150 hide
uint16_t le_isa_rdcsr(struct lance_softc
*, uint16_t);
152 #define LE_ISA_MEMSIZE 16384
155 le_isa_wrcsr(struct lance_softc
*sc
, uint16_t port
, uint16_t val
)
157 struct le_softc
*lesc
= (struct le_softc
*)sc
;
158 bus_space_tag_t iot
= lesc
->sc_iot
;
159 bus_space_handle_t ioh
= lesc
->sc_ioh
;
161 bus_space_write_2(iot
, ioh
, lesc
->sc_rap
, port
);
162 bus_space_write_2(iot
, ioh
, lesc
->sc_rdp
, val
);
166 le_isa_rdcsr(struct lance_softc
*sc
, uint16_t port
)
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
;
173 bus_space_write_2(iot
, ioh
, lesc
->sc_rap
, port
);
174 val
= bus_space_read_2(iot
, ioh
, lesc
->sc_rdp
);
179 ne2100_isa_probe(device_t parent
, cfdata_t cf
, void *aux
)
182 return (lance_isa_probe(aux
, &ne2100_params
, cf
->cf_flags
));
186 bicc_isa_probe(device_t parent
, cfdata_t cf
, void *aux
)
189 return (lance_isa_probe(aux
, &bicc_params
, cf
->cf_flags
));
193 * Determine which chip is present on the card.
196 lance_isa_probe(struct isa_attach_args
*ia
, struct le_isa_params
*p
, int flags
)
198 bus_space_tag_t iot
= ia
->ia_iot
;
199 bus_space_handle_t ioh
;
210 if (ISA_DIRECT_CONFIG(ia
))
213 /* Disallow wildcarded i/o address. */
214 if (ia
->ia_io
[0].ir_addr
== ISA_UNKNOWN_PORT
)
216 if (ia
->ia_irq
[0].ir_irq
== ISA_UNKNOWN_IRQ
)
218 if ((flags
& LANCEISA_FLAG_LOCALBUS
) == 0 &&
219 ia
->ia_drq
[0].ir_drq
== ISA_UNKNOWN_DRQ
)
223 if (bus_space_map(iot
, ia
->ia_io
[0].ir_addr
, p
->iosize
, 0, &ioh
))
229 /* Stop the LANCE chip and put it in a known state. */
230 bus_space_write_2(iot
, ioh
, rap
, LE_CSR0
);
231 bus_space_write_2(iot
, ioh
, rdp
, LE_C0_STOP
);
234 bus_space_write_2(iot
, ioh
, rap
, LE_CSR0
);
235 if (bus_space_read_2(iot
, ioh
, rdp
) != LE_C0_STOP
)
238 bus_space_write_2(iot
, ioh
, rap
, LE_CSR3
);
239 bus_space_write_2(iot
, ioh
, rdp
, 0);
242 ia
->ia_io
[0].ir_size
= p
->iosize
;
246 if ((flags
& LANCEISA_FLAG_LOCALBUS
) != 0 &&
247 ia
->ia_drq
[0].ir_drq
== ISA_UNKNOWN_DRQ
)
257 bus_space_unmap(iot
, ioh
, p
->iosize
);
262 le_dummyattach(device_t parent
, device_t self
, void *aux
)
267 config_found(self
, aux
, 0);
271 le_dummyprobe(device_t parent
, cfdata_t cf
, void *aux
)
278 le_ne2100_attach(device_t parent
, device_t self
, void *aux
)
280 struct le_softc
*lesc
= device_private(self
);
281 struct lance_softc
*sc
= &lesc
->sc_am7990
.lsc
;
284 le_isa_attach(parent
, lesc
, aux
, &ne2100_params
);
288 le_bicc_attach(device_t parent
, device_t self
, void *aux
)
290 struct le_softc
*lesc
= device_private(self
);
291 struct lance_softc
*sc
= &lesc
->sc_am7990
.lsc
;
294 le_isa_attach(parent
, lesc
, aux
, &bicc_params
);
298 le_isa_attach(device_t parent
, struct le_softc
*lesc
,
299 struct isa_attach_args
*ia
, struct le_isa_params
*p
)
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
;
308 aprint_normal(": %s Ethernet\n", p
->name
);
310 if (bus_space_map(iot
, ia
->ia_io
[0].ir_addr
, p
->iosize
, 0, &ioh
))
311 panic("%s: can't map io", device_xname(sc
->sc_dev
));
314 * Extract the physical MAC address from the ROM.
316 for (i
= 0; i
< sizeof(sc
->sc_enaddr
); i
++)
318 bus_space_read_1(iot
, ioh
, p
->macstart
+ i
* p
->macstride
);
322 lesc
->sc_dmat
= dmat
;
323 lesc
->sc_rap
= p
->rap
;
324 lesc
->sc_rdp
= p
->rdp
;
327 * Allocate a DMA area for the card.
329 if (bus_dmamem_alloc(dmat
, LE_ISA_MEMSIZE
, PAGE_SIZE
, 0, &seg
, 1,
330 &rseg
, BUS_DMA_NOWAIT
)) {
331 aprint_error_dev(sc
->sc_dev
,
332 "couldn't allocate memory for card\n");
335 if (bus_dmamem_map(dmat
, &seg
, rseg
, LE_ISA_MEMSIZE
,
336 (void **)&sc
->sc_mem
,
337 BUS_DMA_NOWAIT
|BUS_DMA_COHERENT
)) {
338 aprint_error_dev(sc
->sc_dev
, "couldn't map memory for card\n");
343 * Create and load the DMA map for the DMA area.
345 if (bus_dmamap_create(dmat
, LE_ISA_MEMSIZE
, 1,
346 LE_ISA_MEMSIZE
, 0, BUS_DMA_NOWAIT
, &lesc
->sc_dmam
)) {
347 aprint_error_dev(sc
->sc_dev
, "couldn't create DMA map\n");
348 bus_dmamem_free(dmat
, &seg
, rseg
);
351 if (bus_dmamap_load(dmat
, lesc
->sc_dmam
,
352 sc
->sc_mem
, LE_ISA_MEMSIZE
, NULL
, BUS_DMA_NOWAIT
)) {
353 aprint_error_dev(sc
->sc_dev
, "coundn't load DMA map\n");
354 bus_dmamem_free(dmat
, &seg
, rseg
);
359 sc
->sc_addr
= lesc
->sc_dmam
->dm_segs
[0].ds_addr
;
360 sc
->sc_memsize
= LE_ISA_MEMSIZE
;
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
;
368 sc
->sc_rdcsr
= le_isa_rdcsr
;
369 sc
->sc_wrcsr
= le_isa_wrcsr
;
370 sc
->sc_hwinit
= NULL
;
372 if (ia
->ia_ndrq
> 0) {
373 if ((error
= isa_dmacascade(ia
->ia_ic
,
374 ia
->ia_drq
[0].ir_drq
)) != 0) {
375 aprint_error_dev(sc
->sc_dev
,
376 "unable to cascade DRQ, error = %d\n", error
);
381 lesc
->sc_ih
= isa_intr_establish(ia
->ia_ic
, ia
->ia_irq
[0].ir_irq
,
382 IST_EDGE
, IPL_NET
, le_isa_intredge
, sc
);
384 aprint_normal("%s", device_xname(sc
->sc_dev
));
385 am7990_config(&lesc
->sc_am7990
);
389 * Controller interrupt.
392 le_isa_intredge(void *arg
)
395 if (am7990_intr(arg
) == 0)
398 if (am7990_intr(arg
) == 0)