Home | History | Annotate | Line # | Download | only in pci
if_ep_pci.c revision 1.17.4.1
      1 /*	$NetBSD: if_ep_pci.c,v 1.17.4.1 1997/02/07 18:05:27 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_types.h>
     48 
     49 #include <net/if_ether.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_ether.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 #ifdef __BROKEN_INDIRECT_CONFIG
     88 int ep_pci_match __P((struct device *, void *, void *));
     89 #else
     90 int ep_pci_match __P((struct device *, struct cfdata *, void *));
     91 #endif
     92 void ep_pci_attach __P((struct device *, struct device *, void *));
     93 
     94 struct cfattach ep_pci_ca = {
     95 	sizeof(struct ep_softc), ep_pci_match, ep_pci_attach
     96 };
     97 
     98 int
     99 ep_pci_match(parent, match, aux)
    100 	struct device *parent;
    101 #ifdef __BROKEN_INDIRECT_CONFIG
    102 	void *match;
    103 #else
    104 	struct cfdata *match;
    105 #endif
    106 	void *aux;
    107 {
    108 	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
    109 
    110 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3COM)
    111 		return 0;
    112 
    113 	switch (PCI_PRODUCT(pa->pa_id)) {
    114 	case PCI_PRODUCT_3COM_3C590:
    115 	case PCI_PRODUCT_3COM_3C595TX:
    116 	case PCI_PRODUCT_3COM_3C900COMBO:
    117 	case PCI_PRODUCT_3COM_3C905TX:
    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 	bus_space_tag_t iot = pa->pa_iot;
    135 	bus_addr_t iobase;
    136 	bus_size_t iosize;
    137 	pci_intr_handle_t ih;
    138 	u_int conn = 0;
    139 	pcireg_t i;
    140 	char *model;
    141 	const char *intrstr = NULL;
    142 
    143 	if (pci_io_find(pc, pa->pa_tag, PCI_CBIO, &iobase, &iosize)) {
    144 		printf(": can't find i/o space\n");
    145 		return;
    146 	}
    147 
    148 	if (bus_space_map(iot, iobase, iosize, 0, &sc->sc_ioh)) {
    149 		printf(": can't map i/o space\n");
    150 		return;
    151 	}
    152 
    153 	sc->sc_iot = iot;
    154 	sc->bustype = EP_BUS_PCI;
    155 
    156 	/*
    157 	 * The EP_W3_RESET_OPTIONS register is mapped into PCI
    158 	 * configuration space.  Read RESET_OPTIONS to get
    159 	 * the media types present on this card.
    160 	 */
    161 	i = pci_conf_read(pc, pa->pa_tag, PCI_CONN);
    162 
    163 	/*
    164 	 * Bits 13,12,9 of the isa adapter are the same as bits
    165 	 * 5,4,3 of the pci adapter
    166 	 */
    167 	if (i & IS_PCI_AUI)
    168 		conn |= IS_AUI;
    169 	if (i & IS_PCI_BNC)
    170 		conn |= IS_BNC;
    171 	if (i & IS_PCI_UTP)
    172 		conn |= IS_UTP;
    173 	if (i & IS_PCI_100BASE_TX)
    174 		conn |= IS_100BASE_TX;
    175 	if (i & IS_PCI_100BASE_T4)
    176 		conn |= IS_100BASE_T4;
    177 	if (i & IS_PCI_100BASE_FX)
    178 		conn |= IS_100BASE_FX;
    179 	if (i & IS_PCI_100BASE_MII)
    180 		conn |= IS_100BASE_MII;
    181 
    182 	GO_WINDOW(0);
    183 
    184 	switch (PCI_PRODUCT(pa->pa_id)) {
    185 	case PCI_PRODUCT_3COM_3C590:
    186 		model = "3Com 3C590 Ethernet";
    187 		break;
    188 	case PCI_PRODUCT_3COM_3C595TX:
    189 	case PCI_PRODUCT_3COM_3C595T4:
    190 	case PCI_PRODUCT_3COM_3C595MII:
    191 		model = "3Com 3C595 Ethernet";
    192 		break;
    193 	case PCI_PRODUCT_3COM_3C900TPO:
    194 		model = "3Com 3C900 Ethernet";
    195 		break;
    196 	case PCI_PRODUCT_3COM_3C900COMBO:
    197 		model = "3Com 3C900 Ethernet";
    198 		break;
    199 	case PCI_PRODUCT_3COM_3C905TX:
    200 		model = "3Com 3C905 Ethernet";
    201 		break;
    202 	default:
    203 		model = "unknown model!";
    204 		break;
    205 	}
    206 
    207 	printf(": %s\n", model);
    208 
    209 	epconfig(sc, conn);
    210 
    211 	/* Enable the card. */
    212 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    213 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
    214 	    PCI_COMMAND_MASTER_ENABLE);
    215 
    216 	/* Map and establish the interrupt. */
    217 	if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    218 	    pa->pa_intrline, &ih)) {
    219 		printf("%s: couldn't map interrupt\n", sc->sc_dev.dv_xname);
    220 		return;
    221 	}
    222 	intrstr = pci_intr_string(pc, ih);
    223 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epintr, sc);
    224 	if (sc->sc_ih == NULL) {
    225 		printf("%s: couldn't establish interrupt",
    226 		    sc->sc_dev.dv_xname);
    227 		if (intrstr != NULL)
    228 			printf(" at %s", intrstr);
    229 		printf("\n");
    230 		return;
    231 	}
    232 	printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
    233 }
    234