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