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