Home | History | Annotate | Line # | Download | only in isa
if_le_isa.c revision 1.20
      1 /*	$NetBSD: if_le_isa.c,v 1.20 1998/06/25 19:18:05 thorpej 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 "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 <vm/vm.h>
     98 
     99 #include <machine/cpu.h>
    100 #include <machine/intr.h>
    101 #include <machine/bus.h>
    102 
    103 #include <dev/isa/isareg.h>
    104 #include <dev/isa/isavar.h>
    105 #include <dev/isa/isadmavar.h>
    106 
    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 hide void le_isa_wrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
    150 hide u_int16_t le_isa_rdcsr __P((struct am7990_softc *, u_int16_t));
    151 
    152 #define	LE_ISA_MEMSIZE	16384
    153 
    154 hide void
    155 le_isa_wrcsr(sc, port, val)
    156 	struct am7990_softc *sc;
    157 	u_int16_t port, val;
    158 {
    159 	struct le_softc *lesc = (struct le_softc *)sc;
    160 	bus_space_tag_t iot = lesc->sc_iot;
    161 	bus_space_handle_t ioh = lesc->sc_ioh;
    162 
    163 	bus_space_write_2(iot, ioh, lesc->sc_rap, port);
    164 	bus_space_write_2(iot, ioh, lesc->sc_rdp, val);
    165 }
    166 
    167 hide u_int16_t
    168 le_isa_rdcsr(sc, port)
    169 	struct am7990_softc *sc;
    170 	u_int16_t port;
    171 {
    172 	struct le_softc *lesc = (struct le_softc *)sc;
    173 	bus_space_tag_t iot = lesc->sc_iot;
    174 	bus_space_handle_t ioh = lesc->sc_ioh;
    175 	u_int16_t val;
    176 
    177 	bus_space_write_2(iot, ioh, lesc->sc_rap, port);
    178 	val = bus_space_read_2(iot, ioh, lesc->sc_rdp);
    179 	return (val);
    180 }
    181 
    182 int
    183 ne2100_isa_probe(parent, match, aux)
    184 	struct device *parent;
    185 	struct cfdata *match;
    186 	void *aux;
    187 {
    188 	return (lance_isa_probe(aux, &ne2100_params));
    189 }
    190 
    191 int
    192 bicc_isa_probe(parent, match, aux)
    193 	struct device *parent;
    194 	struct cfdata *match;
    195 	void *aux;
    196 {
    197 	return (lance_isa_probe(aux, &bicc_params));
    198 }
    199 
    200 /*
    201  * Determine which chip is present on the card.
    202  */
    203 int
    204 lance_isa_probe(ia, p)
    205 	struct isa_attach_args *ia;
    206 	struct le_isa_params *p;
    207 {
    208 	bus_space_tag_t iot = ia->ia_iot;
    209 	bus_space_handle_t ioh;
    210 	int rap, rdp;
    211 	int rv = 0;
    212 
    213 	/* Disallow wildcarded i/o address. */
    214 	if (ia->ia_iobase == ISACF_PORT_DEFAULT)
    215 		return (0);
    216 
    217 	/* Map i/o space. */
    218 	if (bus_space_map(iot, ia->ia_iobase, p->iosize, 0, &ioh))
    219 		return (0);
    220 
    221 	rap = p->rap;
    222 	rdp = p->rdp;
    223 
    224 	/* Stop the LANCE chip and put it in a known state. */
    225 	bus_space_write_2(iot, ioh, rap, LE_CSR0);
    226 	bus_space_write_2(iot, ioh, rdp, LE_C0_STOP);
    227 	delay(100);
    228 
    229 	bus_space_write_2(iot, ioh, rap, LE_CSR0);
    230 	if (bus_space_read_2(iot, ioh, rdp) != LE_C0_STOP)
    231 		goto bad;
    232 
    233 	bus_space_write_2(iot, ioh, rap, LE_CSR3);
    234 	bus_space_write_2(iot, ioh, rdp, 0);
    235 
    236 	ia->ia_iosize = p->iosize;
    237 	rv = 1;
    238 
    239 bad:
    240 	bus_space_unmap(iot, ioh, p->iosize);
    241 	return (rv);
    242 }
    243 
    244 void
    245 le_dummyattach(parent, self, aux)
    246 	struct device *parent, *self;
    247 	void *aux;
    248 {
    249 	printf("\n");
    250 
    251 	config_found(self, aux, 0);
    252 }
    253 
    254 int
    255 le_dummyprobe(parent, match, aux)
    256 	struct device *parent;
    257 	struct cfdata *match;
    258 	void *aux;
    259 {
    260 	return (1);
    261 }
    262 
    263 void
    264 le_ne2100_attach(parent, self, aux)
    265 	struct device *parent, *self;
    266 	void *aux;
    267 {
    268 	le_isa_attach(parent, (void *)self, aux, &ne2100_params);
    269 }
    270 
    271 void
    272 le_bicc_attach(parent, self, aux)
    273 	struct device *parent, *self;
    274 	void *aux;
    275 {
    276 	le_isa_attach(parent, (void *)self, aux, &bicc_params);
    277 }
    278 
    279 void
    280 le_isa_attach(parent, lesc, ia, p)
    281 	struct device *parent;
    282 	struct le_softc *lesc;
    283 	struct isa_attach_args *ia;
    284 	struct le_isa_params *p;
    285 {
    286 	struct am7990_softc *sc = &lesc->sc_am7990;
    287 	bus_space_tag_t iot = ia->ia_iot;
    288 	bus_space_handle_t ioh;
    289 	bus_dma_tag_t dmat = ia->ia_dmat;
    290 	bus_dma_segment_t seg;
    291 	int i, rseg, error;
    292 
    293 	printf(": %s Ethernet\n", p->name);
    294 
    295 	if (bus_space_map(iot, ia->ia_iobase, p->iosize, 0, &ioh))
    296 		panic("%s: can't map io", sc->sc_dev.dv_xname);
    297 
    298 	/*
    299 	 * Extract the physical MAC address from the ROM.
    300 	 */
    301 	for (i = 0; i < sizeof(sc->sc_enaddr); i++)
    302 		sc->sc_enaddr[i] =
    303 		    bus_space_read_1(iot, ioh, p->macstart + i * p->macstride);
    304 
    305 	lesc->sc_iot = iot;
    306 	lesc->sc_ioh = ioh;
    307 	lesc->sc_dmat = dmat;
    308 	lesc->sc_rap = p->rap;
    309 	lesc->sc_rdp = p->rdp;
    310 
    311 	/*
    312 	 * Allocate a DMA area for the card.
    313 	 */
    314 	if (bus_dmamem_alloc(dmat, LE_ISA_MEMSIZE, NBPG, 0, &seg, 1,
    315 			     &rseg, BUS_DMA_NOWAIT)) {
    316 		printf("%s: couldn't allocate memory for card\n",
    317 		       sc->sc_dev.dv_xname);
    318 		return;
    319 	}
    320 	if (bus_dmamem_map(dmat, &seg, rseg, LE_ISA_MEMSIZE,
    321 			   (caddr_t *)&sc->sc_mem,
    322 			   BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
    323 		printf("%s: couldn't map memory for card\n",
    324 		       sc->sc_dev.dv_xname);
    325 		return;
    326 	}
    327 
    328 	/*
    329 	 * Create and load the DMA map for the DMA area.
    330 	 */
    331 	if (bus_dmamap_create(dmat, LE_ISA_MEMSIZE, 1,
    332 			LE_ISA_MEMSIZE, 0, BUS_DMA_NOWAIT, &lesc->sc_dmam)) {
    333 		printf("%s: couldn't create DMA map\n",
    334 		       sc->sc_dev.dv_xname);
    335 		bus_dmamem_free(dmat, &seg, rseg);
    336 		return;
    337 	}
    338 	if (bus_dmamap_load(dmat, lesc->sc_dmam,
    339 			sc->sc_mem, LE_ISA_MEMSIZE, NULL, BUS_DMA_NOWAIT)) {
    340 		printf("%s: coundn't load DMA map\n",
    341 		       sc->sc_dev.dv_xname);
    342 		bus_dmamem_free(dmat, &seg, rseg);
    343 		return;
    344 	}
    345 
    346 	sc->sc_conf3 = 0;
    347 	sc->sc_addr = lesc->sc_dmam->dm_segs[0].ds_addr;
    348 	sc->sc_memsize = LE_ISA_MEMSIZE;
    349 
    350 	sc->sc_copytodesc = am7990_copytobuf_contig;
    351 	sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
    352 	sc->sc_copytobuf = am7990_copytobuf_contig;
    353 	sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
    354 	sc->sc_zerobuf = am7990_zerobuf_contig;
    355 
    356 	sc->sc_rdcsr = le_isa_rdcsr;
    357 	sc->sc_wrcsr = le_isa_wrcsr;
    358 	sc->sc_hwinit = NULL;
    359 
    360 	if (ia->ia_drq != DRQUNK) {
    361 		if ((error = isa_dmacascade(ia->ia_ic, ia->ia_drq)) != 0) {
    362 			printf("%s: unable to cascade DRQ, error = %d\n",
    363 			    sc->sc_dev.dv_xname, error);
    364 			return;
    365 		}
    366 	}
    367 
    368 	lesc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
    369 	    IPL_NET, le_isa_intredge, sc);
    370 
    371 	printf("%s", sc->sc_dev.dv_xname);
    372 	am7990_config(sc);
    373 }
    374 
    375 /*
    376  * Controller interrupt.
    377  */
    378 int
    379 le_isa_intredge(arg)
    380 	void *arg;
    381 {
    382 
    383 	if (am7990_intr(arg) == 0)
    384 		return (0);
    385 	for (;;)
    386 		if (am7990_intr(arg) == 0)
    387 			return (1);
    388 }
    389