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