Home | History | Annotate | Line # | Download | only in isapnp
if_le_isapnp.c revision 1.12
      1  1.12  jonathan /*	$NetBSD: if_le_isapnp.c,v 1.12 1998/07/05 00:51:22 jonathan Exp $	*/
      2   1.5   thorpej 
      3   1.5   thorpej /*-
      4   1.5   thorpej  * Copyright (c) 1997 The NetBSD Foundation, Inc.
      5   1.5   thorpej  * All rights reserved.
      6   1.5   thorpej  *
      7   1.5   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8   1.5   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9   1.5   thorpej  * NASA Ames Research Center.
     10   1.5   thorpej  *
     11   1.5   thorpej  * Redistribution and use in source and binary forms, with or without
     12   1.5   thorpej  * modification, are permitted provided that the following conditions
     13   1.5   thorpej  * are met:
     14   1.5   thorpej  * 1. Redistributions of source code must retain the above copyright
     15   1.5   thorpej  *    notice, this list of conditions and the following disclaimer.
     16   1.5   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17   1.5   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18   1.5   thorpej  *    documentation and/or other materials provided with the distribution.
     19   1.5   thorpej  * 3. All advertising materials mentioning features or use of this software
     20   1.5   thorpej  *    must display the following acknowledgement:
     21   1.5   thorpej  *	This product includes software developed by the NetBSD
     22   1.5   thorpej  *	Foundation, Inc. and its contributors.
     23   1.5   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24   1.5   thorpej  *    contributors may be used to endorse or promote products derived
     25   1.5   thorpej  *    from this software without specific prior written permission.
     26   1.5   thorpej  *
     27   1.5   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28   1.5   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29   1.5   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30   1.5   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31   1.5   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32   1.5   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33   1.5   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34   1.5   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35   1.5   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36   1.5   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37   1.5   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38   1.5   thorpej  */
     39   1.1  jonathan 
     40   1.1  jonathan /*
     41   1.2  jonathan  * Copyright (c) 1997 Jonathan Stone <jonathan (at) NetBSD.org> and
     42   1.9  drochner  * Matthias Drochner. All rights reserved.
     43   1.1  jonathan  *
     44   1.1  jonathan  * Redistribution and use in source and binary forms, with or without
     45   1.1  jonathan  * modification, are permitted provided that the following conditions
     46   1.1  jonathan  * are met:
     47   1.1  jonathan  * 1. Redistributions of source code must retain the above copyright
     48   1.1  jonathan  *    notice, this list of conditions and the following disclaimer.
     49   1.1  jonathan  * 2. Redistributions in binary form must reproduce the above copyright
     50   1.1  jonathan  *    notice, this list of conditions and the following disclaimer in the
     51   1.1  jonathan  *    documentation and/or other materials provided with the distribution.
     52   1.1  jonathan  * 3. All advertising materials mentioning features or use of this software
     53   1.1  jonathan  *    must display the following acknowledgement:
     54   1.1  jonathan  *      This product includes software developed by Jonathan Stone.
     55   1.1  jonathan  * 4. The name of the author may not be used to endorse or promote products
     56   1.1  jonathan  *    derived from this software without specific prior written permission.
     57   1.1  jonathan  *
     58   1.1  jonathan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     59   1.1  jonathan  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     60   1.1  jonathan  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     61   1.1  jonathan  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     62   1.1  jonathan  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     63   1.1  jonathan  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     64   1.1  jonathan  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     65   1.1  jonathan  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     66   1.1  jonathan  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     67   1.1  jonathan  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     68   1.1  jonathan  */
     69   1.1  jonathan 
     70  1.12  jonathan #include "opt_inet.h"
     71   1.1  jonathan #include "bpfilter.h"
     72   1.1  jonathan 
     73   1.1  jonathan #include <sys/param.h>
     74   1.1  jonathan #include <sys/systm.h>
     75   1.1  jonathan #include <sys/mbuf.h>
     76   1.1  jonathan #include <sys/socket.h>
     77   1.1  jonathan #include <sys/ioctl.h>
     78   1.1  jonathan #include <sys/errno.h>
     79   1.1  jonathan #include <sys/syslog.h>
     80   1.1  jonathan #include <sys/select.h>
     81   1.1  jonathan #include <sys/device.h>
     82   1.1  jonathan 
     83   1.1  jonathan #include <net/if.h>
     84   1.1  jonathan #include <net/if_dl.h>
     85   1.1  jonathan #include <net/if_ether.h>
     86   1.1  jonathan #include <net/if_media.h>
     87   1.1  jonathan 
     88   1.1  jonathan #ifdef INET
     89   1.1  jonathan #include <netinet/in.h>
     90   1.1  jonathan #include <netinet/in_systm.h>
     91   1.1  jonathan #include <netinet/in_var.h>
     92   1.1  jonathan #include <netinet/ip.h>
     93   1.1  jonathan #endif
     94   1.1  jonathan 
     95   1.1  jonathan #ifdef NS
     96   1.1  jonathan #include <netns/ns.h>
     97   1.1  jonathan #include <netns/ns_if.h>
     98   1.1  jonathan #endif
     99   1.1  jonathan 
    100   1.1  jonathan #if NBPFILTER > 0
    101   1.1  jonathan #include <net/bpf.h>
    102   1.1  jonathan #include <net/bpfdesc.h>
    103   1.1  jonathan #endif
    104   1.1  jonathan 
    105   1.1  jonathan #include <machine/cpu.h>
    106   1.1  jonathan #include <machine/bus.h>
    107   1.1  jonathan #include <machine/intr.h>
    108   1.1  jonathan 
    109   1.1  jonathan #include <dev/isa/isavar.h>
    110   1.1  jonathan #include <dev/isa/isadmavar.h>
    111   1.1  jonathan 
    112   1.1  jonathan #include <dev/isapnp/isapnpreg.h>
    113   1.1  jonathan #include <dev/isapnp/isapnpvar.h>
    114   1.1  jonathan 
    115   1.1  jonathan #include <dev/ic/am7990reg.h>
    116   1.1  jonathan #include <dev/ic/am7990var.h>
    117   1.1  jonathan #include <dev/isapnp/if_levar.h>
    118   1.1  jonathan 
    119   1.1  jonathan int le_isapnp_match __P((struct device *, struct cfdata *, void *));
    120   1.1  jonathan void le_isapnp_attach __P((struct device *, struct device *, void *));
    121   1.1  jonathan 
    122   1.4  jonathan struct cfattach le_isapnp_ca = {
    123   1.1  jonathan 	sizeof(struct le_softc), le_isapnp_match, le_isapnp_attach
    124   1.1  jonathan };
    125   1.1  jonathan 
    126   1.2  jonathan int	le_isapnp_intredge __P((void *));
    127   1.2  jonathan static void le_isapnp_wrcsr __P((struct am7990_softc *, u_int16_t, u_int16_t));
    128   1.2  jonathan static u_int16_t le_isapnp_rdcsr __P((struct am7990_softc *, u_int16_t));
    129   1.1  jonathan 
    130   1.1  jonathan 
    131   1.2  jonathan /*
    132   1.2  jonathan  * Names accepted by the match routine.
    133   1.2  jonathan  */
    134   1.2  jonathan static char *if_le_isapnp_devnames[] = {
    135   1.2  jonathan     "TKN0010",
    136   1.2  jonathan     0
    137   1.2  jonathan };
    138   1.1  jonathan 
    139   1.5   thorpej #define	LE_ISAPNP_MEMSIZE	16384
    140   1.1  jonathan 
    141   1.2  jonathan static void
    142   1.1  jonathan le_isapnp_wrcsr(sc, port, val)
    143   1.1  jonathan 	struct am7990_softc *sc;
    144   1.1  jonathan 	u_int16_t port, val;
    145   1.1  jonathan {
    146   1.1  jonathan 	struct le_softc *lesc = (struct le_softc *)sc;
    147   1.1  jonathan 	bus_space_tag_t iot = lesc->sc_iot;
    148   1.1  jonathan 	bus_space_handle_t ioh = lesc->sc_ioh;
    149   1.1  jonathan 
    150   1.1  jonathan 	bus_space_write_2(iot, ioh, lesc->sc_rap, port);
    151   1.1  jonathan 	bus_space_write_2(iot, ioh, lesc->sc_rdp, val);
    152   1.1  jonathan }
    153   1.1  jonathan 
    154   1.2  jonathan static u_int16_t
    155   1.1  jonathan le_isapnp_rdcsr(sc, port)
    156   1.1  jonathan 	struct am7990_softc *sc;
    157   1.1  jonathan 	u_int16_t port;
    158   1.1  jonathan {
    159   1.1  jonathan 	struct le_softc *lesc = (struct le_softc *)sc;
    160   1.1  jonathan 	bus_space_tag_t iot = lesc->sc_iot;
    161   1.1  jonathan 	bus_space_handle_t ioh = lesc->sc_ioh;
    162   1.1  jonathan 	u_int16_t val;
    163   1.1  jonathan 
    164   1.1  jonathan 	bus_space_write_2(iot, ioh, lesc->sc_rap, port);
    165   1.1  jonathan 	val = bus_space_read_2(iot, ioh, lesc->sc_rdp);
    166   1.1  jonathan 	return (val);
    167   1.1  jonathan }
    168   1.1  jonathan 
    169   1.1  jonathan int
    170   1.1  jonathan le_isapnp_match(parent, match, aux)
    171   1.1  jonathan 	struct device *parent;
    172   1.1  jonathan 	struct cfdata *match;
    173   1.1  jonathan 	void *aux;
    174   1.1  jonathan {
    175   1.1  jonathan 	struct isapnp_attach_args *ipa = aux;
    176   1.2  jonathan 	char **card_name = &if_le_isapnp_devnames[0];
    177   1.1  jonathan 
    178   1.2  jonathan 	while (*card_name)
    179   1.2  jonathan 	    if(!strcmp(ipa->ipa_devlogic, *card_name++))
    180   1.2  jonathan 		return(1);
    181   1.1  jonathan 
    182   1.3   thorpej 	return (0);
    183   1.1  jonathan }
    184   1.1  jonathan 
    185   1.1  jonathan void
    186   1.1  jonathan le_isapnp_attach(parent, self, aux)
    187   1.1  jonathan 	struct device *parent, *self;
    188   1.1  jonathan 	void *aux;
    189   1.1  jonathan {
    190   1.1  jonathan 	struct le_softc *lesc = (void *)self;
    191   1.1  jonathan 	struct am7990_softc *sc = &lesc->sc_am7990;
    192   1.1  jonathan 	struct isapnp_attach_args *ipa = aux;
    193   1.1  jonathan 	bus_space_tag_t iot;
    194   1.1  jonathan 	bus_space_handle_t ioh;
    195   1.5   thorpej 	bus_dma_tag_t dmat;
    196   1.5   thorpej 	bus_dma_segment_t seg;
    197  1.11   thorpej 	int i, rseg, error;
    198   1.1  jonathan 
    199   1.7   thorpej 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
    200   1.7   thorpej 		printf("%s: error in region allocation\n",
    201   1.7   thorpej 		    sc->sc_dev.dv_xname);
    202   1.7   thorpej 		return;
    203   1.7   thorpej 	}
    204   1.7   thorpej 
    205   1.1  jonathan 	lesc->sc_iot = iot = ipa->ipa_iot;
    206   1.1  jonathan 	lesc->sc_ioh = ioh = ipa->ipa_io[0].h;
    207   1.5   thorpej 	lesc->sc_dmat = dmat = ipa->ipa_dmat;
    208   1.1  jonathan 
    209   1.1  jonathan 	lesc->sc_rap = PCNET_RAP;
    210   1.1  jonathan 	lesc->sc_rdp = PCNET_RDP;
    211   1.1  jonathan 
    212   1.1  jonathan 	/*
    213   1.1  jonathan 	 * Extract the physical MAC address from the ROM.
    214   1.1  jonathan 	 */
    215   1.1  jonathan 	for (i = 0; i < sizeof(sc->sc_enaddr); i++)
    216   1.1  jonathan 		sc->sc_enaddr[i] = bus_space_read_1(iot, ioh, PCNET_SAPROM+i);
    217   1.1  jonathan 
    218   1.5   thorpej 	/*
    219   1.5   thorpej 	 * Allocate a DMA area for the card.
    220   1.5   thorpej 	 */
    221   1.5   thorpej 	if (bus_dmamem_alloc(dmat, LE_ISAPNP_MEMSIZE, NBPG, 0, &seg, 1,
    222   1.5   thorpej 	    &rseg, BUS_DMA_NOWAIT)) {
    223   1.1  jonathan 		printf("%s: couldn't allocate memory for card\n",
    224   1.1  jonathan 		    sc->sc_dev.dv_xname);
    225   1.1  jonathan 		return;
    226   1.1  jonathan 	}
    227   1.5   thorpej 	if (bus_dmamem_map(dmat, &seg, rseg, LE_ISAPNP_MEMSIZE,
    228   1.8   thorpej 	    (caddr_t *)&sc->sc_mem, BUS_DMA_NOWAIT|BUS_DMA_COHERENT)) {
    229   1.5   thorpej 		printf("%s: couldn't map memory for card\n",
    230   1.5   thorpej 		    sc->sc_dev.dv_xname);
    231   1.5   thorpej 		return;
    232   1.5   thorpej 	}
    233   1.5   thorpej 
    234   1.5   thorpej 	/*
    235   1.5   thorpej 	 * Create and load the DMA map for the DMA area.
    236   1.5   thorpej 	 */
    237   1.5   thorpej 	if (bus_dmamap_create(dmat, LE_ISAPNP_MEMSIZE, 1,
    238   1.5   thorpej 	    LE_ISAPNP_MEMSIZE, 0, BUS_DMA_NOWAIT, &lesc->sc_dmam)) {
    239   1.5   thorpej 		printf("%s: couldn't create DMA map\n",
    240   1.5   thorpej 		    sc->sc_dev.dv_xname);
    241   1.5   thorpej 		bus_dmamem_free(dmat, &seg, rseg);
    242   1.5   thorpej 		return;
    243   1.5   thorpej 	}
    244   1.5   thorpej 	if (bus_dmamap_load(dmat, lesc->sc_dmam,
    245   1.5   thorpej 	    sc->sc_mem, LE_ISAPNP_MEMSIZE, NULL, BUS_DMA_NOWAIT)) {
    246   1.5   thorpej 		printf("%s: coundn't load DMA map\n",
    247   1.5   thorpej 		    sc->sc_dev.dv_xname);
    248   1.5   thorpej 		bus_dmamem_free(dmat, &seg, rseg);
    249   1.5   thorpej 		return;
    250   1.5   thorpej 	}
    251   1.1  jonathan 
    252   1.1  jonathan 	sc->sc_conf3 = 0;
    253   1.5   thorpej 	sc->sc_addr = lesc->sc_dmam->dm_segs[0].ds_addr;
    254   1.5   thorpej 	sc->sc_memsize = LE_ISAPNP_MEMSIZE;
    255   1.1  jonathan 
    256   1.1  jonathan 	sc->sc_copytodesc = am7990_copytobuf_contig;
    257   1.1  jonathan 	sc->sc_copyfromdesc = am7990_copyfrombuf_contig;
    258   1.1  jonathan 	sc->sc_copytobuf = am7990_copytobuf_contig;
    259   1.1  jonathan 	sc->sc_copyfrombuf = am7990_copyfrombuf_contig;
    260   1.1  jonathan 	sc->sc_zerobuf = am7990_zerobuf_contig;
    261   1.1  jonathan 
    262   1.1  jonathan 	sc->sc_rdcsr = le_isapnp_rdcsr;
    263   1.1  jonathan 	sc->sc_wrcsr = le_isapnp_wrcsr;
    264   1.1  jonathan 	sc->sc_hwinit = NULL;
    265   1.1  jonathan 
    266  1.11   thorpej 	if (ipa->ipa_ndrq > 0) {
    267  1.11   thorpej 		if ((error = isa_dmacascade(ipa->ipa_ic,
    268  1.11   thorpej 		    ipa->ipa_drq[0].num)) != 0) {
    269  1.11   thorpej 			printf("%s: unable to cascade DRQ, error = %d\n",
    270  1.11   thorpej 			    sc->sc_dev.dv_xname, error);
    271  1.11   thorpej 			return;
    272  1.11   thorpej 		}
    273  1.11   thorpej 	}
    274  1.11   thorpej 
    275  1.11   thorpej 	lesc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
    276  1.11   thorpej 	    ipa->ipa_irq[0].type, IPL_NET, le_isapnp_intredge, sc);
    277  1.11   thorpej 
    278   1.1  jonathan 	printf("%s: %s %s\n", sc->sc_dev.dv_xname, ipa->ipa_devident,
    279   1.1  jonathan 	    ipa->ipa_devclass);
    280   1.1  jonathan 	am7990_config(sc);
    281   1.1  jonathan }
    282   1.1  jonathan 
    283   1.1  jonathan 
    284   1.1  jonathan /*
    285   1.1  jonathan  * Controller interrupt.
    286   1.1  jonathan  */
    287   1.1  jonathan int
    288   1.1  jonathan le_isapnp_intredge(arg)
    289   1.1  jonathan 	void *arg;
    290   1.1  jonathan {
    291   1.1  jonathan 
    292   1.1  jonathan 	if (am7990_intr(arg) == 0)
    293   1.1  jonathan 		return (0);
    294   1.1  jonathan 	for (;;)
    295   1.1  jonathan 		if (am7990_intr(arg) == 0)
    296   1.1  jonathan 			return (1);
    297   1.1  jonathan }
    298