Home | History | Annotate | Line # | Download | only in pci
if_ep_pci.c revision 1.25
      1 /*	$NetBSD: if_ep_pci.c,v 1.25 1998/06/08 06:55:55 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Jonathan Stone <jonathan (at) NetBSD.org>
      5  * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) beer.org>
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *      This product includes software developed by Herb Peyerl.
     19  * 4. The name of Herb Peyerl may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include "bpfilter.h"
     35 
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/mbuf.h>
     39 #include <sys/socket.h>
     40 #include <sys/ioctl.h>
     41 #include <sys/errno.h>
     42 #include <sys/syslog.h>
     43 #include <sys/select.h>
     44 #include <sys/device.h>
     45 
     46 #include <net/if.h>
     47 #include <net/if_dl.h>
     48 #include <net/if_ether.h>
     49 #include <net/if_media.h>
     50 
     51 #ifdef INET
     52 #include <netinet/in.h>
     53 #include <netinet/in_systm.h>
     54 #include <netinet/in_var.h>
     55 #include <netinet/ip.h>
     56 #include <netinet/if_inarp.h>
     57 #endif
     58 
     59 #ifdef NS
     60 #include <netns/ns.h>
     61 #include <netns/ns_if.h>
     62 #endif
     63 
     64 #if NBPFILTER > 0
     65 #include <net/bpf.h>
     66 #include <net/bpfdesc.h>
     67 #endif
     68 
     69 #include <machine/cpu.h>
     70 #include <machine/bus.h>
     71 #include <machine/intr.h>
     72 
     73 #include <dev/ic/elink3var.h>
     74 #include <dev/ic/elink3reg.h>
     75 
     76 #include <dev/pci/pcivar.h>
     77 #include <dev/pci/pcireg.h>
     78 #include <dev/pci/pcidevs.h>
     79 
     80 /*
     81  * PCI constants.
     82  * XXX These should be in a common file!
     83  */
     84 #define PCI_CONN		0x48    /* Connector type */
     85 #define PCI_CBIO		0x10    /* Configuration Base IO Address */
     86 
     87 int ep_pci_match __P((struct device *, struct cfdata *, void *));
     88 void ep_pci_attach __P((struct device *, struct device *, void *));
     89 
     90 struct cfattach ep_pci_ca = {
     91 	sizeof(struct ep_softc), ep_pci_match, ep_pci_attach
     92 };
     93 
     94 int
     95 ep_pci_match(parent, match, aux)
     96 	struct device *parent;
     97 	struct cfdata *match;
     98 	void *aux;
     99 {
    100 	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
    101 
    102 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3COM)
    103 		return 0;
    104 
    105 	switch (PCI_PRODUCT(pa->pa_id)) {
    106 	case PCI_PRODUCT_3COM_3C590:
    107 
    108 	case PCI_PRODUCT_3COM_3C595TX:
    109 	case PCI_PRODUCT_3COM_3C595T4:
    110 	case PCI_PRODUCT_3COM_3C595MII:
    111 
    112 	case PCI_PRODUCT_3COM_3C900TPO:
    113 	case PCI_PRODUCT_3COM_3C900COMBO:
    114 	case PCI_PRODUCT_3COM_3C905TX:
    115 	case PCI_PRODUCT_3COM_3C905T4:
    116 		break;
    117 	default:
    118 		return 0;
    119 	}
    120 
    121 	return 1;
    122 }
    123 
    124 void
    125 ep_pci_attach(parent, self, aux)
    126 	struct device *parent, *self;
    127 	void *aux;
    128 {
    129 	struct ep_softc *sc = (void *)self;
    130 	struct pci_attach_args *pa = aux;
    131 	pci_chipset_tag_t pc = pa->pa_pc;
    132 	pci_intr_handle_t ih;
    133 	char *model;
    134 	const char *intrstr = NULL;
    135 
    136 	if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
    137 	    &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
    138 		printf(": can't map i/o space\n");
    139 		return;
    140 	}
    141 
    142 	sc->bustype = EP_BUS_PCI;
    143 
    144 	switch (PCI_PRODUCT(pa->pa_id)) {
    145 	case PCI_PRODUCT_3COM_3C590:
    146 		model = "3Com 3C590 Ethernet";
    147 		break;
    148 	case PCI_PRODUCT_3COM_3C595TX:
    149 	case PCI_PRODUCT_3COM_3C595T4:
    150 	case PCI_PRODUCT_3COM_3C595MII:
    151 		model = "3Com 3C595 Ethernet";
    152 		break;
    153 	case PCI_PRODUCT_3COM_3C900TPO:
    154 	case PCI_PRODUCT_3COM_3C900COMBO:
    155 		model = "3Com 3C900 Ethernet";
    156 		break;
    157 	case PCI_PRODUCT_3COM_3C905TX:
    158 	case PCI_PRODUCT_3COM_3C905T4:
    159 		model = "3Com 3C905 Ethernet";
    160 		break;
    161 	default:
    162 		model = "unknown model!";
    163 		break;
    164 	}
    165 
    166 	printf(": %s\n", model);
    167 
    168 	sc->enable = NULL;
    169 	sc->disable = NULL;
    170 	sc->enabled = 1;
    171 
    172 	epconfig(sc, EP_CHIPSET_VORTEX, NULL);
    173 
    174 	/* Enable the card. */
    175 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    176 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
    177 	    PCI_COMMAND_MASTER_ENABLE);
    178 
    179 	/* Map and establish the interrupt. */
    180 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    181 	    pa->pa_intrline, &ih)) {
    182 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
    183 		return;
    184 	}
    185 	intrstr = pci_intr_string(pc, ih);
    186 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epintr, sc);
    187 	if (sc->sc_ih == NULL) {
    188 		printf("%s: couldn't establish interrupt",
    189 		    sc->sc_dev.dv_xname);
    190 		if (intrstr != NULL)
    191 			printf(" at %s", intrstr);
    192 		printf("\n");
    193 		return;
    194 	}
    195 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    196 }
    197