Home | History | Annotate | Line # | Download | only in isapnp
if_le_isapnp.c revision 1.1
      1 /*	$NetBSD: if_le_isapnp.c,v 1.1 1997/03/31 20:22:20 jonathan Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Jonathan Stone <jonathan (at) NetBSD.org>
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *      This product includes software developed by Jonathan Stone.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include "bpfilter.h"
     33 
     34 #include <sys/param.h>
     35 #include <sys/systm.h>
     36 #include <sys/mbuf.h>
     37 #include <sys/socket.h>
     38 #include <sys/ioctl.h>
     39 #include <sys/errno.h>
     40 #include <sys/syslog.h>
     41 #include <sys/select.h>
     42 #include <sys/device.h>
     43 
     44 #include <net/if.h>
     45 #include <net/if_dl.h>
     46 #include <net/if_ether.h>
     47 #include <net/if_media.h>
     48 
     49 #ifdef INET
     50 #include <netinet/in.h>
     51 #include <netinet/in_systm.h>
     52 #include <netinet/in_var.h>
     53 #include <netinet/ip.h>
     54 #endif
     55 
     56 #ifdef NS
     57 #include <netns/ns.h>
     58 #include <netns/ns_if.h>
     59 #endif
     60 
     61 #if NBPFILTER > 0
     62 #include <net/bpf.h>
     63 #include <net/bpfdesc.h>
     64 #endif
     65 
     66 #include <machine/cpu.h>
     67 #include <machine/bus.h>
     68 #include <machine/intr.h>
     69 
     70 #include <dev/isa/isavar.h>
     71 #include <dev/isa/isadmavar.h>
     72 
     73 #include <dev/isapnp/isapnpreg.h>
     74 #include <dev/isapnp/isapnpvar.h>
     75 
     76 #include <dev/ic/am7990reg.h>
     77 #include <dev/ic/am7990var.h>
     78 #include <dev/isapnp/if_levar.h>
     79 
     80 #ifdef __alpha__			/* XXX */
     81 /* XXX XXX NEED REAL DMA MAPPING SUPPORT XXX XXX */
     82 #undef vtophys
     83 #define	vtophys(va)	alpha_XXX_dmamap((vm_offset_t)(va))
     84 #endif
     85 
     86 
     87 
     88 #ifdef __BROKEN_INDIRECT_CONFIG
     89 int le_isapnp_match __P((struct device *, void *, void *));
     90 #else
     91 int le_isapnp_match __P((struct device *, struct cfdata *, void *));
     92 #endif
     93 void le_isapnp_attach __P((struct device *, struct device *, void *));
     94 
     95 struct cfattach ep_isapnp_ca = {
     96 	sizeof(struct le_softc), le_isapnp_match, le_isapnp_attach
     97 };
     98 
     99 
    100 int le_isapnp_intredge __P((void *));
    101 
    102 hide void le_isapnp_wrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
    103 hide u_int16_t le_isapnp_rdcsr __P((struct am7990_softc *, u_int16_t));
    104 
    105 
    106 hide void
    107 le_isapnp_wrcsr(sc, port, val)
    108 	struct am7990_softc *sc;
    109 	u_int16_t port, val;
    110 {
    111 	struct le_softc *lesc = (struct le_softc *)sc;
    112 	bus_space_tag_t iot = lesc->sc_iot;
    113 	bus_space_handle_t ioh = lesc->sc_ioh;
    114 
    115 	bus_space_write_2(iot, ioh, lesc->sc_rap, port);
    116 	bus_space_write_2(iot, ioh, lesc->sc_rdp, val);
    117 }
    118 
    119 hide u_int16_t
    120 le_isapnp_rdcsr(sc, port)
    121 	struct am7990_softc *sc;
    122 	u_int16_t port;
    123 {
    124 	struct le_softc *lesc = (struct le_softc *)sc;
    125 	bus_space_tag_t iot = lesc->sc_iot;
    126 	bus_space_handle_t ioh = lesc->sc_ioh;
    127 	u_int16_t val;
    128 
    129 	bus_space_write_2(iot, ioh, lesc->sc_rap, port);
    130 	val = bus_space_read_2(iot, ioh, lesc->sc_rdp);
    131 	return (val);
    132 }
    133 
    134 int
    135 le_isapnp_match(parent, match, aux)
    136 	struct device *parent;
    137 #ifdef __BROKEN_INDIRECT_CONFIG
    138 	void *match;
    139 #else
    140 	struct cfdata *match;
    141 #endif
    142 	void *aux;
    143 {
    144 	struct isapnp_attach_args *ipa = aux;
    145 
    146 	if (strcmp(ipa->ipa_devlogic, "TKN0010"))
    147 		return (0);
    148 
    149 	return (1);
    150 }
    151 
    152 void
    153 le_isapnp_attach(parent, self, aux)
    154 	struct device *parent, *self;
    155 	void *aux;
    156 {
    157 	struct le_softc *lesc = (void *)self;
    158 	struct am7990_softc *sc = &lesc->sc_am7990;
    159 	struct isapnp_attach_args *ipa = aux;
    160 	bus_space_tag_t iot;
    161 	bus_space_handle_t ioh;
    162 	int i;
    163 
    164 
    165 	lesc->sc_iot = iot = ipa->ipa_iot;
    166 	lesc->sc_ioh = ioh = ipa->ipa_io[0].h;
    167 
    168 	lesc->sc_rap = PCNET_RAP;
    169 	lesc->sc_rdp = PCNET_RDP;
    170 
    171 	/* XXX SHOULD RE-MAP I/O SPACE HERE? */
    172 
    173 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    174 		printf("%s: error in region allocation\n",
    175 		    sc->sc_dev.dv_xname);
    176 		return;
    177 	}
    178 
    179 	/*
    180 	 * Extract the physical MAC address from the ROM.
    181 	 */
    182 	for (i = 0; i < sizeof(sc->sc_enaddr); i++)
    183 		sc->sc_enaddr[i] = bus_space_read_1(iot, ioh, PCNET_SAPROM+i);
    184 
    185 	if (ipa->ipa_ndrq > 0)
    186 		isa_dmacascade(ipa->ipa_drq[0].num);
    187 
    188 	/* XXX SHOULD GET DMA-CAPABLE BUFFER SPACE */
    189 	sc->sc_mem = malloc(16384, M_DEVBUF, M_NOWAIT);
    190 	if (sc->sc_mem == 0) {
    191 		printf("%s: couldn't allocate memory for card\n",
    192 		    sc->sc_dev.dv_xname);
    193 		return;
    194 	}
    195 
    196 	sc->sc_conf3 = 0;
    197 	sc->sc_addr = kvtop(sc->sc_mem);	/* XXX XXX XXX !! */
    198 	sc->sc_memsize = 16384;
    199 
    200 	sc->sc_copytodesc = am7990_copytobuf_contig;
    201 	sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
    202 	sc->sc_copytobuf = am7990_copytobuf_contig;
    203 	sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
    204 	sc->sc_zerobuf = am7990_zerobuf_contig;
    205 
    206 	sc->sc_rdcsr = le_isapnp_rdcsr;
    207 	sc->sc_wrcsr = le_isapnp_wrcsr;
    208 	sc->sc_hwinit = NULL;
    209 
    210 	printf("%s: %s %s\n", sc->sc_dev.dv_xname, ipa->ipa_devident,
    211 	    ipa->ipa_devclass);
    212 	am7990_config(sc);
    213 
    214 	lesc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    215 	    IST_EDGE, IPL_NET, le_isapnp_intredge, sc);
    216 }
    217 
    218 
    219 /*
    220  * Controller interrupt.
    221  */
    222 int
    223 le_isapnp_intredge(arg)
    224 	void *arg;
    225 {
    226 
    227 	if (am7990_intr(arg) == 0)
    228 		return (0);
    229 	for (;;)
    230 		if (am7990_intr(arg) == 0)
    231 			return (1);
    232 }
    233