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