Home | History | Annotate | Line # | Download | only in pci
if_ep_pci.c revision 1.46.16.2
      1  1.46.16.1       mjf /*	$NetBSD: if_ep_pci.c,v 1.46.16.2 2008/09/28 10:40:26 mjf Exp $	*/
      2       1.28   thorpej 
      3       1.28   thorpej /*-
      4       1.28   thorpej  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5       1.28   thorpej  * All rights reserved.
      6       1.28   thorpej  *
      7       1.28   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8       1.28   thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9       1.28   thorpej  * NASA Ames Research Center.
     10       1.28   thorpej  *
     11       1.28   thorpej  * Redistribution and use in source and binary forms, with or without
     12       1.28   thorpej  * modification, are permitted provided that the following conditions
     13       1.28   thorpej  * are met:
     14       1.28   thorpej  * 1. Redistributions of source code must retain the above copyright
     15       1.28   thorpej  *    notice, this list of conditions and the following disclaimer.
     16       1.28   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.28   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18       1.28   thorpej  *    documentation and/or other materials provided with the distribution.
     19       1.28   thorpej  *
     20       1.28   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21       1.28   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22       1.28   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23       1.28   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24       1.28   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25       1.28   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26       1.28   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27       1.28   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28       1.28   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29       1.28   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30       1.28   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     31       1.28   thorpej  */
     32        1.1   thorpej 
     33        1.1   thorpej /*
     34       1.21  jonathan  * Copyright (c) 1997 Jonathan Stone <jonathan (at) NetBSD.org>
     35        1.4   thorpej  * Copyright (c) 1994 Herb Peyerl <hpeyerl (at) beer.org>
     36        1.1   thorpej  * All rights reserved.
     37        1.1   thorpej  *
     38        1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     39        1.1   thorpej  * modification, are permitted provided that the following conditions
     40        1.1   thorpej  * are met:
     41        1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     42        1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     43        1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     44        1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     45        1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     46        1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     47        1.1   thorpej  *    must display the following acknowledgement:
     48        1.1   thorpej  *      This product includes software developed by Herb Peyerl.
     49        1.1   thorpej  * 4. The name of Herb Peyerl may not be used to endorse or promote products
     50        1.1   thorpej  *    derived from this software without specific prior written permission.
     51        1.1   thorpej  *
     52        1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     53        1.1   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     54        1.1   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     55        1.1   thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     56        1.1   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     57        1.1   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     58        1.1   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     59        1.1   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     60        1.1   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     61        1.1   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     62        1.1   thorpej  */
     63       1.36     lukem 
     64       1.36     lukem #include <sys/cdefs.h>
     65  1.46.16.1       mjf __KERNEL_RCSID(0, "$NetBSD: if_ep_pci.c,v 1.46.16.2 2008/09/28 10:40:26 mjf Exp $");
     66        1.1   thorpej 
     67        1.1   thorpej #include <sys/param.h>
     68        1.3  christos #include <sys/systm.h>
     69       1.42     perry #include <sys/mbuf.h>
     70       1.42     perry #include <sys/socket.h>
     71        1.1   thorpej #include <sys/ioctl.h>
     72        1.1   thorpej #include <sys/errno.h>
     73        1.1   thorpej #include <sys/syslog.h>
     74        1.1   thorpej #include <sys/select.h>
     75        1.1   thorpej #include <sys/device.h>
     76        1.1   thorpej 
     77        1.1   thorpej #include <net/if.h>
     78        1.1   thorpej #include <net/if_dl.h>
     79       1.19        is #include <net/if_ether.h>
     80       1.21  jonathan #include <net/if_media.h>
     81        1.1   thorpej 
     82       1.46        ad #include <sys/cpu.h>
     83       1.46        ad #include <sys/bus.h>
     84       1.46        ad #include <sys/intr.h>
     85        1.1   thorpej 
     86       1.28   thorpej #include <dev/mii/miivar.h>
     87       1.28   thorpej 
     88        1.1   thorpej #include <dev/ic/elink3var.h>
     89        1.1   thorpej #include <dev/ic/elink3reg.h>
     90        1.1   thorpej 
     91        1.1   thorpej #include <dev/pci/pcivar.h>
     92        1.1   thorpej #include <dev/pci/pcireg.h>
     93        1.1   thorpej #include <dev/pci/pcidevs.h>
     94        1.1   thorpej 
     95        1.5   thorpej /*
     96        1.5   thorpej  * PCI constants.
     97        1.5   thorpej  */
     98        1.5   thorpej #define PCI_CBIO		0x10    /* Configuration Base IO Address */
     99        1.1   thorpej 
    100  1.46.16.2       mjf static int	ep_pci_match(device_t , cfdata_t , void *);
    101  1.46.16.2       mjf static void	ep_pci_attach(device_t , device_t , void *);
    102        1.1   thorpej 
    103  1.46.16.2       mjf CFATTACH_DECL_NEW(ep_pci, sizeof(struct ep_softc),
    104       1.39   thorpej     ep_pci_match, ep_pci_attach, NULL, NULL);
    105        1.1   thorpej 
    106       1.41   thorpej static struct ep_pci_product {
    107       1.28   thorpej 	u_int32_t	epp_prodid;	/* PCI product ID */
    108       1.28   thorpej 	u_short		epp_chipset;	/* 3Com chipset used */
    109       1.28   thorpej 	int		epp_flags;	/* initial softc flags */
    110       1.28   thorpej 	const char	*epp_name;	/* device name */
    111       1.28   thorpej } ep_pci_products[] = {
    112       1.29      fvdl 	{ PCI_PRODUCT_3COM_3C590,	ELINK_CHIPSET_VORTEX,
    113       1.32   thorpej 	  0,
    114       1.32   thorpej 	  "3c590 Ethernet" },
    115       1.28   thorpej 
    116       1.28   thorpej 	/*
    117       1.28   thorpej 	 * Note: The 3c595-MII is an MII connector for an
    118       1.28   thorpej 	 * external PHY.  We treat it as `manual' in the
    119       1.28   thorpej 	 * core driver.
    120       1.28   thorpej 	 */
    121       1.29      fvdl 	{ PCI_PRODUCT_3COM_3C595TX,	ELINK_CHIPSET_VORTEX,
    122       1.32   thorpej 	  0,
    123       1.32   thorpej 	  "3c595-TX 10/100 Ethernet" },
    124       1.29      fvdl 	{ PCI_PRODUCT_3COM_3C595T4,	ELINK_CHIPSET_VORTEX,
    125       1.32   thorpej 	  0,
    126       1.32   thorpej 	  "3c595-T4 10/100 Ethernet" },
    127       1.29      fvdl 	{ PCI_PRODUCT_3COM_3C595MII,	ELINK_CHIPSET_VORTEX,
    128       1.32   thorpej 	  0,
    129       1.32   thorpej 	  "3c595-MII 10/100 Ethernet" },
    130       1.31   thorpej 
    131       1.29      fvdl 	{ PCI_PRODUCT_3COM_3C900TPO,	ELINK_CHIPSET_BOOMERANG,
    132       1.32   thorpej 	  0,
    133       1.32   thorpej 	  "3c900-TPO Ethernet" },
    134       1.29      fvdl 	{ PCI_PRODUCT_3COM_3C900COMBO,	ELINK_CHIPSET_BOOMERANG,
    135       1.32   thorpej 	  0,
    136       1.32   thorpej 	  "3c900-COMBO Ethernet" },
    137       1.31   thorpej 
    138       1.29      fvdl 	{ PCI_PRODUCT_3COM_3C905TX,	ELINK_CHIPSET_BOOMERANG,
    139       1.32   thorpej 	  ELINK_FLAGS_MII,
    140       1.32   thorpej 	  "3c905-TX 10/100 Ethernet" },
    141       1.29      fvdl 	{ PCI_PRODUCT_3COM_3C905T4,	ELINK_CHIPSET_BOOMERANG,
    142       1.32   thorpej 	  ELINK_FLAGS_MII,
    143       1.32   thorpej 	  "3c905-T4 10/100 Ethernet" },
    144       1.28   thorpej 
    145       1.28   thorpej 	{ 0,				0,
    146       1.28   thorpej 	  0,				NULL },
    147       1.28   thorpej };
    148       1.28   thorpej 
    149       1.41   thorpej static const struct ep_pci_product *
    150       1.41   thorpej ep_pci_lookup(const struct pci_attach_args *pa)
    151       1.28   thorpej {
    152       1.28   thorpej 	struct ep_pci_product *epp;
    153       1.28   thorpej 
    154       1.31   thorpej 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3COM)
    155       1.31   thorpej 		return (NULL);
    156       1.31   thorpej 
    157       1.28   thorpej 	for (epp = ep_pci_products; epp->epp_name != NULL; epp++)
    158       1.28   thorpej 		if (PCI_PRODUCT(pa->pa_id) == epp->epp_prodid)
    159       1.28   thorpej 			return (epp);
    160       1.28   thorpej 
    161       1.28   thorpej 	return (NULL);
    162       1.28   thorpej }
    163       1.28   thorpej 
    164       1.41   thorpej static int
    165  1.46.16.2       mjf ep_pci_match(device_t parent, cfdata_t match, void *aux)
    166        1.1   thorpej {
    167        1.1   thorpej 	struct pci_attach_args *pa = (struct pci_attach_args *) aux;
    168        1.1   thorpej 
    169       1.28   thorpej 	if (ep_pci_lookup(pa) != NULL)
    170       1.28   thorpej 		return (1);
    171        1.1   thorpej 
    172       1.28   thorpej 	return (0);
    173        1.1   thorpej }
    174        1.1   thorpej 
    175       1.41   thorpej static void
    176  1.46.16.2       mjf ep_pci_attach(device_t parent, device_t self, void *aux)
    177        1.1   thorpej {
    178  1.46.16.2       mjf 	struct ep_softc *sc = device_private(self);
    179        1.1   thorpej 	struct pci_attach_args *pa = aux;
    180        1.1   thorpej 	pci_chipset_tag_t pc = pa->pa_pc;
    181        1.1   thorpej 	pci_intr_handle_t ih;
    182       1.31   thorpej 	const struct ep_pci_product *epp;
    183        1.1   thorpej 	const char *intrstr = NULL;
    184        1.1   thorpej 
    185       1.40   thorpej 	aprint_naive(": Ethernet controller\n");
    186       1.40   thorpej 
    187       1.23       cgd 	if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
    188       1.22       cgd 	    &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
    189       1.40   thorpej 		aprint_error(": can't map i/o space\n");
    190        1.2   thorpej 		return;
    191        1.2   thorpej 	}
    192        1.2   thorpej 
    193       1.28   thorpej 	epp = ep_pci_lookup(pa);
    194       1.28   thorpej 	if (epp == NULL) {
    195       1.28   thorpej 		printf("\n");
    196       1.28   thorpej 		panic("ep_pci_attach: impossible");
    197        1.1   thorpej 	}
    198        1.1   thorpej 
    199       1.40   thorpej 	aprint_normal(": 3Com %s\n", epp->epp_name);
    200        1.1   thorpej 
    201  1.46.16.2       mjf 	sc->sc_dev = self;
    202       1.24   thorpej 	sc->enable = NULL;
    203       1.24   thorpej 	sc->disable = NULL;
    204       1.24   thorpej 	sc->enabled = 1;
    205       1.24   thorpej 
    206       1.29      fvdl 	sc->bustype = ELINK_BUS_PCI;
    207       1.28   thorpej 	sc->ep_flags = epp->epp_flags;
    208        1.1   thorpej 
    209        1.1   thorpej 	/* Enable the card. */
    210        1.1   thorpej 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    211        1.1   thorpej 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
    212        1.1   thorpej 	    PCI_COMMAND_MASTER_ENABLE);
    213        1.1   thorpej 
    214        1.1   thorpej 	/* Map and establish the interrupt. */
    215       1.33  sommerfe 	if (pci_intr_map(pa, &ih)) {
    216  1.46.16.2       mjf 		aprint_error_dev(sc->sc_dev, "couldn't map interrupt\n");
    217        1.1   thorpej 		return;
    218        1.1   thorpej 	}
    219        1.1   thorpej 	intrstr = pci_intr_string(pc, ih);
    220        1.1   thorpej 	sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, epintr, sc);
    221        1.1   thorpej 	if (sc->sc_ih == NULL) {
    222  1.46.16.2       mjf 		aprint_error_dev(sc->sc_dev, "couldn't establish interrupt");
    223        1.1   thorpej 		if (intrstr != NULL)
    224       1.40   thorpej 			aprint_normal(" at %s", intrstr);
    225       1.40   thorpej 		aprint_normal("\n");
    226        1.1   thorpej 		return;
    227        1.1   thorpej 	}
    228  1.46.16.2       mjf 	aprint_normal_dev(sc->sc_dev, "interrupting at %s\n", intrstr);
    229       1.28   thorpej 
    230       1.28   thorpej 	epconfig(sc, epp->epp_chipset, NULL);
    231        1.1   thorpej }
    232