Home | History | Annotate | Line # | Download | only in pci
if_ep_pci.c revision 1.27
      1 /*	$NetBSD: if_ep_pci.c,v 1.27 1998/07/05 06:49:15 jonathan 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 "opt_inet.h"
     35 #include "opt_ns.h"
     36 #include "bpfilter.h"
     37 
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/mbuf.h>
     41 #include <sys/socket.h>
     42 #include <sys/ioctl.h>
     43 #include <sys/errno.h>
     44 #include <sys/syslog.h>
     45 #include <sys/select.h>
     46 #include <sys/device.h>
     47 
     48 #include <net/if.h>
     49 #include <net/if_dl.h>
     50 #include <net/if_ether.h>
     51 #include <net/if_media.h>
     52 
     53 #ifdef INET
     54 #include <netinet/in.h>
     55 #include <netinet/in_systm.h>
     56 #include <netinet/in_var.h>
     57 #include <netinet/ip.h>
     58 #include <netinet/if_inarp.h>
     59 #endif
     60 
     61 #ifdef NS
     62 #include <netns/ns.h>
     63 #include <netns/ns_if.h>
     64 #endif
     65 
     66 #if NBPFILTER > 0
     67 #include <net/bpf.h>
     68 #include <net/bpfdesc.h>
     69 #endif
     70 
     71 #include <machine/cpu.h>
     72 #include <machine/bus.h>
     73 #include <machine/intr.h>
     74 
     75 #include <dev/ic/elink3var.h>
     76 #include <dev/ic/elink3reg.h>
     77 
     78 #include <dev/pci/pcivar.h>
     79 #include <dev/pci/pcireg.h>
     80 #include <dev/pci/pcidevs.h>
     81 
     82 /*
     83  * PCI constants.
     84  * XXX These should be in a common file!
     85  */
     86 #define PCI_CONN		0x48    /* Connector type */
     87 #define PCI_CBIO		0x10    /* Configuration Base IO Address */
     88 
     89 int ep_pci_match __P((struct device *, struct cfdata *, void *));
     90 void ep_pci_attach __P((struct device *, struct device *, void *));
     91 
     92 struct cfattach ep_pci_ca = {
     93 	sizeof(struct ep_softc), ep_pci_match, ep_pci_attach
     94 };
     95 
     96 int
     97 ep_pci_match(parent, match, aux)
     98 	struct device *parent;
     99 	struct cfdata *match;
    100 	void *aux;
    101 {
    102 	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
    103 
    104 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3COM)
    105 		return 0;
    106 
    107 	switch (PCI_PRODUCT(pa->pa_id)) {
    108 	case PCI_PRODUCT_3COM_3C590:
    109 
    110 	case PCI_PRODUCT_3COM_3C595TX:
    111 	case PCI_PRODUCT_3COM_3C595T4:
    112 	case PCI_PRODUCT_3COM_3C595MII:
    113 
    114 	case PCI_PRODUCT_3COM_3C900TPO:
    115 	case PCI_PRODUCT_3COM_3C900COMBO:
    116 	case PCI_PRODUCT_3COM_3C905TX:
    117 	case PCI_PRODUCT_3COM_3C905T4:
    118 		break;
    119 	default:
    120 		return 0;
    121 	}
    122 
    123 	return 1;
    124 }
    125 
    126 void
    127 ep_pci_attach(parent, self, aux)
    128 	struct device *parent, *self;
    129 	void *aux;
    130 {
    131 	struct ep_softc *sc = (void *)self;
    132 	struct pci_attach_args *pa = aux;
    133 	pci_chipset_tag_t pc = pa->pa_pc;
    134 	pci_intr_handle_t ih;
    135 	char *model;
    136 	const char *intrstr = NULL;
    137 
    138 	if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
    139 	    &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
    140 		printf(": can't map i/o space\n");
    141 		return;
    142 	}
    143 
    144 	sc->bustype = EP_BUS_PCI;
    145 
    146 	switch (PCI_PRODUCT(pa->pa_id)) {
    147 	case PCI_PRODUCT_3COM_3C590:
    148 		model = "3Com 3C590 Ethernet";
    149 		break;
    150 	case PCI_PRODUCT_3COM_3C595TX:
    151 	case PCI_PRODUCT_3COM_3C595T4:
    152 	case PCI_PRODUCT_3COM_3C595MII:
    153 		model = "3Com 3C595 Ethernet";
    154 		break;
    155 	case PCI_PRODUCT_3COM_3C900TPO:
    156 	case PCI_PRODUCT_3COM_3C900COMBO:
    157 		model = "3Com 3C900 Ethernet";
    158 		break;
    159 	case PCI_PRODUCT_3COM_3C905TX:
    160 	case PCI_PRODUCT_3COM_3C905T4:
    161 		model = "3Com 3C905 Ethernet";
    162 		break;
    163 	default:
    164 		model = "unknown model!";
    165 		break;
    166 	}
    167 
    168 	printf(": %s\n", model);
    169 
    170 	sc->enable = NULL;
    171 	sc->disable = NULL;
    172 	sc->enabled = 1;
    173 
    174 	epconfig(sc, EP_CHIPSET_VORTEX, NULL);
    175 
    176 	/* Enable the card. */
    177 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    178 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
    179 	    PCI_COMMAND_MASTER_ENABLE);
    180 
    181 	/* Map and establish the interrupt. */
    182 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    183 	    pa->pa_intrline, &ih)) {
    184 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
    185 		return;
    186 	}
    187 	intrstr = pci_intr_string(pc, ih);
    188 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epintr, sc);
    189 	if (sc->sc_ih == NULL) {
    190 		printf("%s: couldn't establish interrupt",
    191 		    sc->sc_dev.dv_xname);
    192 		if (intrstr != NULL)
    193 			printf(" at %s", intrstr);
    194 		printf("\n");
    195 		return;
    196 	}
    197 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    198 }
    199