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