Home | History | Annotate | Line # | Download | only in eisa
if_ep_eisa.c revision 1.1
      1 /*	$NetBSD: if_ep_eisa.c,v 1.1 1996/04/25 02:16:40 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) novatel.ca>
      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/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_types.h>
     47 #include <net/netisr.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 #include <netinet/if_ether.h>
     55 #endif
     56 
     57 #ifdef NS
     58 #include <netns/ns.h>
     59 #include <netns/ns_if.h>
     60 #endif
     61 
     62 #if NBPFILTER > 0
     63 #include <net/bpf.h>
     64 #include <net/bpfdesc.h>
     65 #endif
     66 
     67 #include <machine/cpu.h>
     68 #include <machine/pio.h>
     69 
     70 #include <dev/ic/elink3var.h>
     71 #include <dev/ic/elink3reg.h>
     72 
     73 #include <dev/eisa/eisareg.h>
     74 #include <dev/eisa/eisavar.h>
     75 #include <dev/eisa/eisadevs.h>
     76 
     77 int ep_eisa_match __P((struct device *, void *, void *));
     78 void ep_eisa_attach __P((struct device *, struct device *, void *));
     79 
     80 struct cfattach ep_eisa_ca = {
     81 	sizeof(struct ep_softc), ep_eisa_match, ep_eisa_attach
     82 };
     83 
     84 /* XXX move these somewhere else */
     85 #define EISA_CONTROL	0x0c84
     86 #define EISA_RESET	0x04
     87 #define EISA_ERROR	0x02
     88 #define EISA_ENABLE	0x01
     89 
     90 int
     91 ep_eisa_match(parent, match, aux)
     92 	struct device *parent;
     93 	void *match, *aux;
     94 {
     95 	struct cfdata *cf = match;
     96 	struct eisa_attach_args *ea = aux;
     97 
     98 	/* must match one of our known ID strings */
     99 	if (strcmp(ea->ea_idstring, "TCM5091") &&
    100 	    strcmp(ea->ea_idstring, "TCM5092") &&
    101 	    strcmp(ea->ea_idstring, "TCM5093"))
    102 		return (0);
    103 
    104 	return (1);
    105 }
    106 
    107 void
    108 ep_eisa_attach(parent, self, aux)
    109 	struct device *parent, *self;
    110 	void *aux;
    111 {
    112 	struct ep_softc *sc = (void *)self;
    113 	struct eisa_attach_args *ea = aux;
    114 	int iobase, irq, k;
    115 	u_short conn = 0;
    116 	eisa_chipset_tag_t ec = ea->ea_ec;
    117 	eisa_intr_handle_t ih;
    118 	const char *model, *intrstr;
    119 
    120 	sc->ep_iobase = iobase = EISA_SLOT_ADDR(ea->ea_slot);
    121 	sc->bustype = EP_BUS_EISA;
    122 
    123 	/* Reset card. */
    124 	outb(iobase + EISA_CONTROL, EISA_ENABLE | EISA_RESET);
    125 	delay(10);
    126 	outb(iobase + EISA_CONTROL, EISA_ENABLE);
    127 	/* Wait for reset? */
    128 	delay(1000);
    129 
    130 	/* XXX What is this doing?! */
    131 	k = inw(iobase + EP_W0_ADDRESS_CFG);
    132 	k = (k & 0x1f) * 0x10 + 0x200;
    133 
    134 	/* Read the IRQ from the card. */
    135 	irq = inw(iobase + EP_W0_RESOURCE_CFG) >> 12;
    136 
    137 	GO_WINDOW(0);
    138 	conn = inw(iobase + EP_W0_CONFIG_CTRL);
    139 
    140 	if (strcmp(ea->ea_idstring, "TCM5091") == 0)
    141 		model = EISA_PRODUCT_TCM5091;
    142 	else if (strcmp(ea->ea_idstring, "TCM5092") == 0)
    143 		model = EISA_PRODUCT_TCM5092;
    144 	else if (strcmp(ea->ea_idstring, "TCM5093") == 0)
    145 		model = EISA_PRODUCT_TCM5093;
    146 	else
    147 		model = "unknown model!";
    148 	printf(": %s\n", model);
    149 
    150 	if (eisa_intr_map(ec, irq, &ih)) {
    151 		printf("%s: couldn't map interrupt (%d)\n",
    152 		    sc->sc_dev.dv_xname, irq);
    153 		return;
    154 	}
    155 	intrstr = eisa_intr_string(ec, ih);
    156 	sc->sc_ih = eisa_intr_establish(ec, ih, IST_EDGE, IPL_NET,
    157 	    epintr, sc);
    158 	if (sc->sc_ih == NULL) {
    159 		printf("%s: couldn't establish interrupt",
    160 		    sc->sc_dev.dv_xname);
    161 		if (intrstr != NULL)
    162 			printf(" at %s", intrstr);
    163 		printf("\n");
    164 		return;
    165 	}
    166 	if (intrstr != NULL)
    167 		printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
    168 		    intrstr);
    169 
    170 	epconfig(sc, conn);
    171 }
    172