Home | History | Annotate | Line # | Download | only in eisa
if_ep_eisa.c revision 1.10.2.4
      1  1.10.2.4  is /*	$NetBSD: if_ep_eisa.c,v 1.10.2.4 1997/03/09 21:08:59 is Exp $	*/
      2  1.10.2.2  is 
      3  1.10.2.2  is /*
      4  1.10.2.2  is  * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) beer.org>
      5  1.10.2.2  is  * All rights reserved.
      6  1.10.2.2  is  *
      7  1.10.2.2  is  * Redistribution and use in source and binary forms, with or without
      8  1.10.2.2  is  * modification, are permitted provided that the following conditions
      9  1.10.2.2  is  * are met:
     10  1.10.2.2  is  * 1. Redistributions of source code must retain the above copyright
     11  1.10.2.2  is  *    notice, this list of conditions and the following disclaimer.
     12  1.10.2.2  is  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.10.2.2  is  *    notice, this list of conditions and the following disclaimer in the
     14  1.10.2.2  is  *    documentation and/or other materials provided with the distribution.
     15  1.10.2.2  is  * 3. All advertising materials mentioning features or use of this software
     16  1.10.2.2  is  *    must display the following acknowledgement:
     17  1.10.2.2  is  *      This product includes software developed by Herb Peyerl.
     18  1.10.2.2  is  * 4. The name of Herb Peyerl may not be used to endorse or promote products
     19  1.10.2.2  is  *    derived from this software without specific prior written permission.
     20  1.10.2.2  is  *
     21  1.10.2.2  is  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.10.2.2  is  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.10.2.2  is  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.10.2.2  is  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.10.2.2  is  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.10.2.2  is  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.10.2.2  is  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.10.2.2  is  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.10.2.2  is  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.10.2.2  is  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.10.2.2  is  */
     32  1.10.2.2  is 
     33  1.10.2.2  is #include "bpfilter.h"
     34  1.10.2.2  is 
     35  1.10.2.2  is #include <sys/param.h>
     36  1.10.2.2  is #include <sys/systm.h>
     37  1.10.2.2  is #include <sys/mbuf.h>
     38  1.10.2.2  is #include <sys/socket.h>
     39  1.10.2.2  is #include <sys/ioctl.h>
     40  1.10.2.2  is #include <sys/errno.h>
     41  1.10.2.2  is #include <sys/syslog.h>
     42  1.10.2.2  is #include <sys/select.h>
     43  1.10.2.2  is #include <sys/device.h>
     44  1.10.2.2  is 
     45  1.10.2.2  is #include <net/if.h>
     46  1.10.2.2  is #include <net/if_dl.h>
     47  1.10.2.4  is #include <net/if_inarp.h>
     48  1.10.2.3  is #include <net/if_types.h>
     49  1.10.2.2  is 
     50  1.10.2.2  is #ifdef INET
     51  1.10.2.2  is #include <netinet/in.h>
     52  1.10.2.2  is #include <netinet/in_systm.h>
     53  1.10.2.2  is #include <netinet/in_var.h>
     54  1.10.2.2  is #include <netinet/ip.h>
     55  1.10.2.2  is #include <netinet/if_ether.h>
     56  1.10.2.2  is #endif
     57  1.10.2.2  is 
     58  1.10.2.2  is #ifdef NS
     59  1.10.2.2  is #include <netns/ns.h>
     60  1.10.2.2  is #include <netns/ns_if.h>
     61  1.10.2.2  is #endif
     62  1.10.2.2  is 
     63  1.10.2.2  is #if NBPFILTER > 0
     64  1.10.2.2  is #include <net/bpf.h>
     65  1.10.2.2  is #include <net/bpfdesc.h>
     66  1.10.2.2  is #endif
     67  1.10.2.2  is 
     68  1.10.2.2  is #include <machine/cpu.h>
     69  1.10.2.2  is #include <machine/bus.h>
     70  1.10.2.2  is #include <machine/intr.h>
     71  1.10.2.2  is 
     72  1.10.2.2  is #include <dev/ic/elink3var.h>
     73  1.10.2.2  is #include <dev/ic/elink3reg.h>
     74  1.10.2.2  is 
     75  1.10.2.2  is #include <dev/eisa/eisareg.h>
     76  1.10.2.2  is #include <dev/eisa/eisavar.h>
     77  1.10.2.2  is #include <dev/eisa/eisadevs.h>
     78  1.10.2.2  is 
     79  1.10.2.2  is int ep_eisa_match __P((struct device *, void *, void *));
     80  1.10.2.2  is void ep_eisa_attach __P((struct device *, struct device *, void *));
     81  1.10.2.2  is 
     82  1.10.2.2  is struct cfattach ep_eisa_ca = {
     83  1.10.2.2  is 	sizeof(struct ep_softc), ep_eisa_match, ep_eisa_attach
     84  1.10.2.2  is };
     85  1.10.2.2  is 
     86  1.10.2.2  is /* XXX move these somewhere else */
     87  1.10.2.2  is #define EISA_CONTROL	0x0c84
     88  1.10.2.2  is #define EISA_RESET	0x04
     89  1.10.2.2  is #define EISA_ERROR	0x02
     90  1.10.2.2  is #define EISA_ENABLE	0x01
     91  1.10.2.2  is 
     92  1.10.2.2  is int
     93  1.10.2.2  is ep_eisa_match(parent, match, aux)
     94  1.10.2.2  is 	struct device *parent;
     95  1.10.2.2  is 	void *match, *aux;
     96  1.10.2.2  is {
     97  1.10.2.2  is 	struct eisa_attach_args *ea = aux;
     98  1.10.2.2  is 
     99  1.10.2.2  is 	/* must match one of our known ID strings */
    100  1.10.2.2  is 	if (strcmp(ea->ea_idstring, "TCM5091") &&
    101  1.10.2.2  is 	    strcmp(ea->ea_idstring, "TCM5092") &&
    102  1.10.2.2  is 	    strcmp(ea->ea_idstring, "TCM5093") &&
    103  1.10.2.2  is 	    strcmp(ea->ea_idstring, "TCM5920") &&
    104  1.10.2.2  is 	    strcmp(ea->ea_idstring, "TCM5970") &&
    105  1.10.2.2  is 	    strcmp(ea->ea_idstring, "TCM5971") &&
    106  1.10.2.2  is 	    strcmp(ea->ea_idstring, "TCM5972"))
    107  1.10.2.2  is 		return (0);
    108  1.10.2.2  is 
    109  1.10.2.2  is 	return (1);
    110  1.10.2.2  is }
    111  1.10.2.2  is 
    112  1.10.2.2  is void
    113  1.10.2.2  is ep_eisa_attach(parent, self, aux)
    114  1.10.2.2  is 	struct device *parent, *self;
    115  1.10.2.2  is 	void *aux;
    116  1.10.2.2  is {
    117  1.10.2.2  is 	struct ep_softc *sc = (void *)self;
    118  1.10.2.2  is 	struct eisa_attach_args *ea = aux;
    119  1.10.2.2  is 	bus_space_tag_t iot = ea->ea_iot;
    120  1.10.2.2  is 	bus_space_handle_t ioh;
    121  1.10.2.2  is 	u_int16_t k;
    122  1.10.2.2  is 	eisa_chipset_tag_t ec = ea->ea_ec;
    123  1.10.2.2  is 	eisa_intr_handle_t ih;
    124  1.10.2.2  is 	const char *model, *intrstr;
    125  1.10.2.2  is 	int chipset;
    126  1.10.2.2  is 	u_int irq;
    127  1.10.2.2  is 
    128  1.10.2.2  is 	/* Map i/o space. */
    129  1.10.2.2  is 	if (bus_space_map(iot, EISA_SLOT_ADDR(ea->ea_slot),
    130  1.10.2.2  is 	    EISA_SLOT_SIZE, 0, &ioh))
    131  1.10.2.2  is 		panic("ep_eisa_attach: can't map i/o space");
    132  1.10.2.2  is 
    133  1.10.2.2  is 	sc->bustype = EP_BUS_EISA;
    134  1.10.2.2  is 	sc->sc_ioh = ioh;
    135  1.10.2.2  is 	sc->sc_iot = iot;
    136  1.10.2.2  is 
    137  1.10.2.2  is 	/* Reset card. */
    138  1.10.2.2  is 	bus_space_write_1(iot, ioh, EISA_CONTROL, EISA_ENABLE | EISA_RESET);
    139  1.10.2.2  is 	delay(10);
    140  1.10.2.2  is 	bus_space_write_1(iot, ioh, EISA_CONTROL, EISA_ENABLE);
    141  1.10.2.2  is 	/* Wait for reset? */
    142  1.10.2.2  is 	delay(1000);
    143  1.10.2.2  is 
    144  1.10.2.2  is 	/* XXX What is this doing?!  Reading the i/o address? */
    145  1.10.2.2  is 	k = bus_space_read_2(iot, ioh, EP_W0_ADDRESS_CFG);
    146  1.10.2.2  is 	k = (k & 0x1f) * 0x10 + 0x200;
    147  1.10.2.2  is 
    148  1.10.2.2  is 	/* Read the IRQ from the card. */
    149  1.10.2.2  is 	irq = bus_space_read_2(iot, ioh, EP_W0_RESOURCE_CFG) >> 12;
    150  1.10.2.2  is 
    151  1.10.2.2  is 	chipset = EP_CHIPSET_3C509;	/* assume dumb chipset */
    152  1.10.2.2  is 	if (strcmp(ea->ea_idstring, "TCM5091") == 0)
    153  1.10.2.2  is 		model = EISA_PRODUCT_TCM5091;
    154  1.10.2.2  is 	else if (strcmp(ea->ea_idstring, "TCM5092") == 0)
    155  1.10.2.2  is 		model = EISA_PRODUCT_TCM5092;
    156  1.10.2.2  is 	else if (strcmp(ea->ea_idstring, "TCM5093") == 0)
    157  1.10.2.2  is 		model = EISA_PRODUCT_TCM5093;
    158  1.10.2.2  is 	else if (strcmp(ea->ea_idstring, "TCM5920") == 0) {
    159  1.10.2.2  is 		model = EISA_PRODUCT_TCM5920;
    160  1.10.2.2  is 		chipset = EP_CHIPSET_VORTEX;
    161  1.10.2.2  is 	}
    162  1.10.2.2  is 	else if (strcmp(ea->ea_idstring, "TCM5970") == 0) {
    163  1.10.2.2  is 		model = EISA_PRODUCT_TCM5970;
    164  1.10.2.2  is 		chipset = EP_CHIPSET_VORTEX;
    165  1.10.2.2  is 	}
    166  1.10.2.2  is 	else if (strcmp(ea->ea_idstring, "TCM5971") == 0) {
    167  1.10.2.2  is 		model = EISA_PRODUCT_TCM5971;
    168  1.10.2.2  is 		chipset = EP_CHIPSET_VORTEX;
    169  1.10.2.2  is 	}
    170  1.10.2.2  is 	else if (strcmp(ea->ea_idstring, "TCM5972") == 0) {
    171  1.10.2.2  is 		model = EISA_PRODUCT_TCM5972;
    172  1.10.2.2  is 		chipset = EP_CHIPSET_VORTEX;
    173  1.10.2.2  is 	}
    174  1.10.2.2  is 	else
    175  1.10.2.2  is 		model = "unknown model!";
    176  1.10.2.2  is 	printf(": %s\n", model);
    177  1.10.2.2  is 
    178  1.10.2.2  is 	if (eisa_intr_map(ec, irq, &ih)) {
    179  1.10.2.2  is 		printf("%s: couldn't map interrupt (%u)\n",
    180  1.10.2.2  is 		    sc->sc_dev.dv_xname, irq);
    181  1.10.2.2  is 		return;
    182  1.10.2.2  is 	}
    183  1.10.2.2  is 	intrstr = eisa_intr_string(ec, ih);
    184  1.10.2.2  is 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_EDGE, IPL_NET,
    185  1.10.2.2  is 	    epintr, sc);
    186  1.10.2.2  is 	if (sc->sc_ih == NULL) {
    187  1.10.2.2  is 		printf("%s: couldn't establish interrupt",
    188  1.10.2.2  is 		    sc->sc_dev.dv_xname);
    189  1.10.2.2  is 		if (intrstr != NULL)
    190  1.10.2.2  is 			printf(" at %s", intrstr);
    191  1.10.2.2  is 		printf("\n");
    192  1.10.2.2  is 		return;
    193  1.10.2.2  is 	}
    194  1.10.2.2  is 	if (intrstr != NULL)
    195  1.10.2.2  is 		printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
    196  1.10.2.2  is 		    intrstr);
    197  1.10.2.2  is 
    198  1.10.2.2  is 	epconfig(sc, chipset);
    199  1.10.2.2  is }
    200