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