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