Home | History | Annotate | Line # | Download | only in pci
if_tlp_pci.c revision 1.9
      1  1.9  thorpej /*	$NetBSD: if_tlp_pci.c,v 1.9 1999/09/14 23:33:04 thorpej Exp $	*/
      2  1.1  thorpej 
      3  1.1  thorpej /*-
      4  1.1  thorpej  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
      5  1.1  thorpej  * All rights reserved.
      6  1.1  thorpej  *
      7  1.1  thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  thorpej  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  1.1  thorpej  * NASA Ames Research Center.
     10  1.1  thorpej  *
     11  1.1  thorpej  * Redistribution and use in source and binary forms, with or without
     12  1.1  thorpej  * modification, are permitted provided that the following conditions
     13  1.1  thorpej  * are met:
     14  1.1  thorpej  * 1. Redistributions of source code must retain the above copyright
     15  1.1  thorpej  *    notice, this list of conditions and the following disclaimer.
     16  1.1  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  thorpej  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  thorpej  *    documentation and/or other materials provided with the distribution.
     19  1.1  thorpej  * 3. All advertising materials mentioning features or use of this software
     20  1.1  thorpej  *    must display the following acknowledgement:
     21  1.1  thorpej  *	This product includes software developed by the NetBSD
     22  1.1  thorpej  *	Foundation, Inc. and its contributors.
     23  1.1  thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  1.1  thorpej  *    contributors may be used to endorse or promote products derived
     25  1.1  thorpej  *    from this software without specific prior written permission.
     26  1.1  thorpej  *
     27  1.1  thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  1.1  thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  1.1  thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  1.1  thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  1.1  thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  1.1  thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  1.1  thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  1.1  thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  1.1  thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  1.1  thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  1.1  thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38  1.1  thorpej  */
     39  1.1  thorpej 
     40  1.1  thorpej /*
     41  1.1  thorpej  * PCI bus front-end for the Digital Semiconductor ``Tulip'' (21x4x)
     42  1.1  thorpej  * Ethernet controller family driver.
     43  1.1  thorpej  */
     44  1.1  thorpej 
     45  1.1  thorpej #include "opt_inet.h"
     46  1.1  thorpej #include "opt_ns.h"
     47  1.1  thorpej #include "bpfilter.h"
     48  1.1  thorpej 
     49  1.1  thorpej #include <sys/param.h>
     50  1.1  thorpej #include <sys/systm.h>
     51  1.1  thorpej #include <sys/mbuf.h>
     52  1.1  thorpej #include <sys/malloc.h>
     53  1.1  thorpej #include <sys/kernel.h>
     54  1.1  thorpej #include <sys/socket.h>
     55  1.1  thorpej #include <sys/ioctl.h>
     56  1.1  thorpej #include <sys/errno.h>
     57  1.1  thorpej #include <sys/device.h>
     58  1.1  thorpej 
     59  1.1  thorpej #include <net/if.h>
     60  1.1  thorpej #include <net/if_dl.h>
     61  1.1  thorpej #include <net/if_media.h>
     62  1.1  thorpej #include <net/if_ether.h>
     63  1.1  thorpej 
     64  1.1  thorpej #if NBPFILTER > 0
     65  1.1  thorpej #include <net/bpf.h>
     66  1.1  thorpej #endif
     67  1.1  thorpej 
     68  1.1  thorpej #ifdef INET
     69  1.1  thorpej #include <netinet/in.h>
     70  1.1  thorpej #include <netinet/if_inarp.h>
     71  1.1  thorpej #endif
     72  1.1  thorpej 
     73  1.1  thorpej #ifdef NS
     74  1.1  thorpej #include <netns/ns.h>
     75  1.1  thorpej #include <netns/ns_if.h>
     76  1.1  thorpej #endif
     77  1.1  thorpej 
     78  1.1  thorpej #include <machine/bus.h>
     79  1.1  thorpej #include <machine/intr.h>
     80  1.1  thorpej 
     81  1.1  thorpej #include <dev/mii/miivar.h>
     82  1.1  thorpej 
     83  1.1  thorpej #include <dev/ic/tulipreg.h>
     84  1.1  thorpej #include <dev/ic/tulipvar.h>
     85  1.1  thorpej 
     86  1.1  thorpej #include <dev/pci/pcivar.h>
     87  1.1  thorpej #include <dev/pci/pcireg.h>
     88  1.1  thorpej #include <dev/pci/pcidevs.h>
     89  1.1  thorpej 
     90  1.1  thorpej /*
     91  1.1  thorpej  * PCI configuration space registers used by the Tulip.
     92  1.1  thorpej  */
     93  1.1  thorpej #define	TULIP_PCI_IOBA		0x10	/* i/o mapped base */
     94  1.1  thorpej #define	TULIP_PCI_MMBA		0x14	/* memory mapped base */
     95  1.1  thorpej 
     96  1.1  thorpej struct tulip_pci_softc {
     97  1.1  thorpej 	struct tulip_softc sc_tulip;	/* real Tulip softc */
     98  1.1  thorpej 
     99  1.1  thorpej 	/* PCI-specific goo. */
    100  1.1  thorpej 	void	*sc_ih;			/* interrupt handle */
    101  1.8  thorpej 
    102  1.8  thorpej 	pci_chipset_tag_t sc_pc;	/* our PCI chipset */
    103  1.8  thorpej 	pcitag_t sc_pcitag;		/* our PCI tag */
    104  1.8  thorpej 
    105  1.8  thorpej 	int	sc_flags;		/* flags; see below */
    106  1.8  thorpej 
    107  1.8  thorpej 	LIST_HEAD(, tulip_pci_softc) sc_intrslaves;
    108  1.8  thorpej 	LIST_ENTRY(tulip_pci_softc) sc_intrq;
    109  1.8  thorpej 
    110  1.8  thorpej 	/* Our {ROM,interrupt} master. */
    111  1.8  thorpej 	struct tulip_pci_softc *sc_master;
    112  1.1  thorpej };
    113  1.1  thorpej 
    114  1.8  thorpej /* sc_flags */
    115  1.8  thorpej #define	TULIP_PCI_SHAREDINTR	0x01	/* interrupt is shared */
    116  1.8  thorpej #define	TULIP_PCI_SLAVEINTR	0x02	/* interrupt is slave */
    117  1.8  thorpej #define	TULIP_PCI_SHAREDROM	0x04	/* ROM is shared */
    118  1.8  thorpej #define	TULIP_PCI_SLAVEROM	0x08	/* slave of shared ROM */
    119  1.8  thorpej 
    120  1.1  thorpej int	tlp_pci_match __P((struct device *, struct cfdata *, void *));
    121  1.1  thorpej void	tlp_pci_attach __P((struct device *, struct device *, void *));
    122  1.1  thorpej 
    123  1.1  thorpej struct cfattach tlp_pci_ca = {
    124  1.1  thorpej 	sizeof(struct tulip_pci_softc), tlp_pci_match, tlp_pci_attach,
    125  1.1  thorpej };
    126  1.1  thorpej 
    127  1.1  thorpej const struct tulip_pci_product {
    128  1.1  thorpej 	u_int32_t	tpp_vendor;	/* PCI vendor ID */
    129  1.1  thorpej 	u_int32_t	tpp_product;	/* PCI product ID */
    130  1.1  thorpej 	tulip_chip_t	tpp_chip;	/* base Tulip chip type */
    131  1.1  thorpej } tlp_pci_products[] = {
    132  1.5  thorpej #ifdef TLP_MATCH_21040
    133  1.1  thorpej 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21040,
    134  1.1  thorpej 	  TULIP_CHIP_21040 },
    135  1.5  thorpej #endif
    136  1.5  thorpej #ifdef TLP_MATCH_21041
    137  1.1  thorpej 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21041,
    138  1.1  thorpej 	  TULIP_CHIP_21041 },
    139  1.5  thorpej #endif
    140  1.5  thorpej #ifdef TLP_MATCH_21140
    141  1.1  thorpej 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21140,
    142  1.1  thorpej 	  TULIP_CHIP_21140 },
    143  1.5  thorpej #endif
    144  1.5  thorpej #ifdef TLP_MATCH_21142
    145  1.1  thorpej 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21142,
    146  1.1  thorpej 	  TULIP_CHIP_21142 },
    147  1.1  thorpej #endif
    148  1.1  thorpej 
    149  1.3  thorpej 	{ PCI_VENDOR_LITEON,		PCI_PRODUCT_LITEON_82C168,
    150  1.1  thorpej 	  TULIP_CHIP_82C168 },
    151  1.1  thorpej 
    152  1.1  thorpej #if 0
    153  1.4  thorpej 	/*
    154  1.4  thorpej 	 * Note: This is like a MX98715A with Wake-On-LAN and a
    155  1.4  thorpej 	 * 128-bit multicast hash table.
    156  1.4  thorpej 	 */
    157  1.4  thorpej 	{ PCI_VENDOR_LITEON,		PCI_PRODUCT_LITEON_82C115,
    158  1.4  thorpej 	  TULIP_CHIP_82C115 },
    159  1.4  thorpej #endif
    160  1.4  thorpej 
    161  1.4  thorpej #if 0
    162  1.1  thorpej 	{ PCI_VENDOR_MACRONIX,		PCI_PRODUCT_MACRONIX_MX98713,
    163  1.1  thorpej 	  TULIP_CHIP_MX98713 },
    164  1.1  thorpej 	{ PCI_VENDOR_MACRONIX,		PCI_PRODUCT_MACRONIX_MX987x5,
    165  1.1  thorpej 	  TULIP_CHIP_MX98715 },
    166  1.4  thorpej 
    167  1.4  thorpej 	{ PCI_VENDOR_COMPEX,		PCI_PRODUCT_COMPEX_RL100TX,
    168  1.4  thorpej 	  TULIP_CHIP_MX98713 },
    169  1.1  thorpej #endif
    170  1.1  thorpej 
    171  1.1  thorpej 	{ PCI_VENDOR_WINBOND,		PCI_PRODUCT_WINBOND_W89C840F,
    172  1.1  thorpej 	  TULIP_CHIP_WB89C840F },
    173  1.4  thorpej 	{ PCI_VENDOR_COMPEX,		PCI_PRODUCT_COMPEX_RL100ATX,
    174  1.4  thorpej 	  TULIP_CHIP_WB89C840F },
    175  1.4  thorpej 
    176  1.4  thorpej #if 0
    177  1.4  thorpej 	{ PCI_VENDOR_DAVICOM,		PCI_PRODUCT_DAVICOM_DM9102,
    178  1.4  thorpej 	  TULIP_CHIP_DM9102 },
    179  1.4  thorpej 
    180  1.4  thorpej 	{ PCI_VENDOR_ADMTEK,		PCI_PRODUCT_ADMTEK_AL981,
    181  1.4  thorpej 	  TULIP_CHIP_AL981 },
    182  1.4  thorpej 
    183  1.4  thorpej 	{ PCI_VENDOR_ASIX,		PCI_PRODUCT_ASIX_AX88140A,
    184  1.4  thorpej 	  TULIP_CHIP_AX88140 },
    185  1.4  thorpej #endif
    186  1.1  thorpej 
    187  1.1  thorpej 	{ 0,				0,
    188  1.1  thorpej 	  TULIP_CHIP_INVALID },
    189  1.1  thorpej };
    190  1.1  thorpej 
    191  1.8  thorpej struct tlp_pci_quirks {
    192  1.8  thorpej 	void		(*tpq_func) __P((struct tulip_pci_softc *,
    193  1.8  thorpej 			    const u_int8_t *));
    194  1.8  thorpej 	u_int8_t	tpq_oui[3];
    195  1.8  thorpej };
    196  1.8  thorpej 
    197  1.8  thorpej void	tlp_pci_znyx_21040_quirks __P((struct tulip_pci_softc *,
    198  1.8  thorpej 	    const u_int8_t *));
    199  1.8  thorpej void	tlp_pci_smc_21040_quirks __P((struct tulip_pci_softc *,
    200  1.8  thorpej 	    const u_int8_t *));
    201  1.8  thorpej void	tlp_pci_cogent_21040_quirks __P((struct tulip_pci_softc *,
    202  1.8  thorpej 	    const u_int8_t *));
    203  1.8  thorpej void	tlp_pci_accton_21040_quirks __P((struct tulip_pci_softc *,
    204  1.8  thorpej 	    const u_int8_t *));
    205  1.8  thorpej 
    206  1.8  thorpej const struct tlp_pci_quirks tlp_pci_21040_quirks[] = {
    207  1.8  thorpej 	{ tlp_pci_znyx_21040_quirks,	{ 0x00, 0xc0, 0x95 } },
    208  1.8  thorpej 	{ tlp_pci_smc_21040_quirks,	{ 0x00, 0x00, 0xc0 } },
    209  1.8  thorpej 	{ tlp_pci_cogent_21040_quirks,	{ 0x00, 0x00, 0x92 } },
    210  1.8  thorpej 	{ tlp_pci_accton_21040_quirks,	{ 0x00, 0x00, 0xe8 } },
    211  1.8  thorpej 	{ NULL,				{ 0, 0, 0 } }
    212  1.8  thorpej };
    213  1.8  thorpej 
    214  1.1  thorpej const char *tlp_pci_chip_names[] = TULIP_CHIP_NAMES;
    215  1.1  thorpej 
    216  1.8  thorpej int	tlp_pci_shared_intr __P((void *));
    217  1.8  thorpej 
    218  1.1  thorpej const struct tulip_pci_product *tlp_pci_lookup
    219  1.1  thorpej     __P((const struct pci_attach_args *));
    220  1.8  thorpej void tlp_pci_get_quirks __P((struct tulip_pci_softc *, const u_int8_t *,
    221  1.8  thorpej     const struct tlp_pci_quirks *));
    222  1.8  thorpej void tlp_pci_check_slaved __P((struct tulip_pci_softc *, int, int));
    223  1.1  thorpej 
    224  1.1  thorpej const struct tulip_pci_product *
    225  1.1  thorpej tlp_pci_lookup(pa)
    226  1.1  thorpej 	const struct pci_attach_args *pa;
    227  1.1  thorpej {
    228  1.1  thorpej 	const struct tulip_pci_product *tpp;
    229  1.1  thorpej 
    230  1.1  thorpej 	for (tpp = tlp_pci_products;
    231  1.1  thorpej 	     tlp_pci_chip_names[tpp->tpp_chip] != NULL;
    232  1.1  thorpej 	     tpp++) {
    233  1.1  thorpej 		if (PCI_VENDOR(pa->pa_id) == tpp->tpp_vendor &&
    234  1.1  thorpej 		    PCI_PRODUCT(pa->pa_id) == tpp->tpp_product)
    235  1.1  thorpej 			return (tpp);
    236  1.1  thorpej 	}
    237  1.1  thorpej 	return (NULL);
    238  1.1  thorpej }
    239  1.1  thorpej 
    240  1.8  thorpej void
    241  1.8  thorpej tlp_pci_get_quirks(psc, enaddr, tpq)
    242  1.8  thorpej 	struct tulip_pci_softc *psc;
    243  1.8  thorpej 	const u_int8_t *enaddr;
    244  1.8  thorpej 	const struct tlp_pci_quirks *tpq;
    245  1.8  thorpej {
    246  1.8  thorpej 
    247  1.8  thorpej 	for (; tpq->tpq_func != NULL; tpq++) {
    248  1.8  thorpej 		if (tpq->tpq_oui[0] == enaddr[0] &&
    249  1.8  thorpej 		    tpq->tpq_oui[1] == enaddr[1] &&
    250  1.8  thorpej 		    tpq->tpq_oui[2] == enaddr[2]) {
    251  1.8  thorpej 			(*tpq->tpq_func)(psc, enaddr);
    252  1.8  thorpej 			return;
    253  1.8  thorpej 		}
    254  1.8  thorpej 	}
    255  1.8  thorpej }
    256  1.8  thorpej 
    257  1.8  thorpej void
    258  1.8  thorpej tlp_pci_check_slaved(psc, shared, slaved)
    259  1.8  thorpej 	struct tulip_pci_softc *psc;
    260  1.8  thorpej 	int shared, slaved;
    261  1.8  thorpej {
    262  1.8  thorpej 	extern struct cfdriver tlp_cd;
    263  1.8  thorpej 	struct tulip_pci_softc *cur, *best = NULL;
    264  1.8  thorpej 	struct tulip_softc *sc = &psc->sc_tulip;
    265  1.8  thorpej 	int i;
    266  1.8  thorpej 
    267  1.8  thorpej 	/*
    268  1.8  thorpej 	 * First of all, find the lowest pcidev numbered device on our
    269  1.8  thorpej 	 * bus marked as a shared ROM.  That should be our master.
    270  1.8  thorpej 	 */
    271  1.8  thorpej 	for (i = 0; i < tlp_cd.cd_ndevs; i++) {
    272  1.8  thorpej 		if ((cur = tlp_cd.cd_devs[i]) == NULL)
    273  1.8  thorpej 			continue;
    274  1.8  thorpej 		if (cur->sc_tulip.sc_dev.dv_parent != sc->sc_dev.dv_parent)
    275  1.8  thorpej 			continue;
    276  1.8  thorpej 		if ((cur->sc_flags & shared) == 0)
    277  1.8  thorpej 			continue;
    278  1.9  thorpej 		if (best == NULL ||
    279  1.9  thorpej 		    best->sc_tulip.sc_devno > cur->sc_tulip.sc_devno)
    280  1.8  thorpej 			best = cur;
    281  1.8  thorpej 	}
    282  1.8  thorpej 
    283  1.8  thorpej 	if (best != NULL) {
    284  1.8  thorpej 		psc->sc_master = best;
    285  1.8  thorpej 		psc->sc_flags |= (shared | slaved);
    286  1.8  thorpej 	}
    287  1.8  thorpej }
    288  1.8  thorpej 
    289  1.1  thorpej int
    290  1.1  thorpej tlp_pci_match(parent, match, aux)
    291  1.1  thorpej 	struct device *parent;
    292  1.1  thorpej 	struct cfdata *match;
    293  1.1  thorpej 	void *aux;
    294  1.1  thorpej {
    295  1.1  thorpej 	struct pci_attach_args *pa = aux;
    296  1.1  thorpej 
    297  1.1  thorpej 	if (tlp_pci_lookup(pa) != NULL)
    298  1.1  thorpej 		return (10);	/* beat if_de.c */
    299  1.1  thorpej 
    300  1.1  thorpej 	return (0);
    301  1.1  thorpej }
    302  1.1  thorpej 
    303  1.1  thorpej void
    304  1.1  thorpej tlp_pci_attach(parent, self, aux)
    305  1.1  thorpej 	struct device *parent, *self;
    306  1.1  thorpej 	void *aux;
    307  1.1  thorpej {
    308  1.1  thorpej 	struct tulip_pci_softc *psc = (void *) self;
    309  1.1  thorpej 	struct tulip_softc *sc = &psc->sc_tulip;
    310  1.1  thorpej 	struct pci_attach_args *pa = aux;
    311  1.1  thorpej 	pci_chipset_tag_t pc = pa->pa_pc;
    312  1.1  thorpej 	pci_intr_handle_t ih;
    313  1.1  thorpej 	const char *intrstr = NULL;
    314  1.1  thorpej 	bus_space_tag_t iot, memt;
    315  1.1  thorpej 	bus_space_handle_t ioh, memh;
    316  1.1  thorpej 	int ioh_valid, memh_valid, i, j;
    317  1.1  thorpej 	const struct tulip_pci_product *tpp;
    318  1.5  thorpej 	u_int8_t enaddr[ETHER_ADDR_LEN];
    319  1.1  thorpej 	u_int32_t val;
    320  1.8  thorpej 
    321  1.9  thorpej 	sc->sc_devno = pa->pa_device;
    322  1.8  thorpej 	psc->sc_pc = pa->pa_pc;
    323  1.8  thorpej 	psc->sc_pcitag = pa->pa_tag;
    324  1.8  thorpej 
    325  1.8  thorpej 	LIST_INIT(&psc->sc_intrslaves);
    326  1.1  thorpej 
    327  1.1  thorpej 	/*
    328  1.1  thorpej 	 * Map the device.
    329  1.1  thorpej 	 */
    330  1.1  thorpej 	ioh_valid = (pci_mapreg_map(pa, TULIP_PCI_IOBA,
    331  1.1  thorpej 	    PCI_MAPREG_TYPE_IO, 0,
    332  1.1  thorpej 	    &iot, &ioh, NULL, NULL) == 0);
    333  1.1  thorpej 	memh_valid = (pci_mapreg_map(pa, TULIP_PCI_MMBA,
    334  1.1  thorpej 	    PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
    335  1.1  thorpej 	    &memt, &memh, NULL, NULL) == 0);
    336  1.1  thorpej 
    337  1.1  thorpej 	if (memh_valid) {
    338  1.1  thorpej 		sc->sc_st = memt;
    339  1.1  thorpej 		sc->sc_sh = memh;
    340  1.1  thorpej 	} else if (ioh_valid) {
    341  1.1  thorpej 		sc->sc_st = iot;
    342  1.1  thorpej 		sc->sc_sh = ioh;
    343  1.1  thorpej 	} else {
    344  1.1  thorpej 		printf(": unable to map device registers\n");
    345  1.1  thorpej 		return;
    346  1.1  thorpej 	}
    347  1.1  thorpej 
    348  1.1  thorpej 	tpp = tlp_pci_lookup(pa);
    349  1.1  thorpej 	if (tpp == NULL) {
    350  1.1  thorpej 		printf("\n");
    351  1.1  thorpej 		panic("tlp_pci_attach: impossible");
    352  1.1  thorpej 	}
    353  1.1  thorpej 	sc->sc_chip = tpp->tpp_chip;
    354  1.1  thorpej 
    355  1.1  thorpej 	/*
    356  1.6  thorpej 	 * By default, Tulip registers are 8 bytes long (4 bytes
    357  1.6  thorpej 	 * followed by a 4 byte pad).
    358  1.6  thorpej 	 */
    359  1.6  thorpej 	sc->sc_regshift = 3;
    360  1.6  thorpej 
    361  1.6  thorpej 	/*
    362  1.1  thorpej 	 * Get revision info, and set some chip-specific variables.
    363  1.1  thorpej 	 */
    364  1.1  thorpej 	sc->sc_rev = PCI_REVISION(pa->pa_class);
    365  1.1  thorpej 	switch (sc->sc_chip) {
    366  1.1  thorpej 	case TULIP_CHIP_21140:
    367  1.1  thorpej 		if (sc->sc_rev >= 0x20)
    368  1.1  thorpej 			sc->sc_chip = TULIP_CHIP_21140A;
    369  1.1  thorpej 		break;
    370  1.1  thorpej 
    371  1.1  thorpej 	case TULIP_CHIP_21142:
    372  1.1  thorpej 		if (sc->sc_rev >= 0x20)
    373  1.1  thorpej 			sc->sc_chip = TULIP_CHIP_21143;
    374  1.1  thorpej 		break;
    375  1.1  thorpej 
    376  1.1  thorpej 	case TULIP_CHIP_82C168:
    377  1.1  thorpej 		if (sc->sc_rev >= 0x20)
    378  1.1  thorpej 			sc->sc_chip = TULIP_CHIP_82C169;
    379  1.1  thorpej 		break;
    380  1.1  thorpej 
    381  1.1  thorpej 	case TULIP_CHIP_MX98713:
    382  1.1  thorpej 		if (sc->sc_rev >= 0x10)
    383  1.1  thorpej 			sc->sc_chip = TULIP_CHIP_MX98713A;
    384  1.1  thorpej 		break;
    385  1.1  thorpej 
    386  1.1  thorpej 	case TULIP_CHIP_MX98715:
    387  1.1  thorpej 		if (sc->sc_rev >= 0x30)
    388  1.1  thorpej 			sc->sc_chip = TULIP_CHIP_MX98725;
    389  1.1  thorpej 		break;
    390  1.1  thorpej 
    391  1.1  thorpej 	case TULIP_CHIP_WB89C840F:
    392  1.7  thorpej 		sc->sc_regshift = 2;
    393  1.4  thorpej 		break;
    394  1.4  thorpej 
    395  1.4  thorpej 	case TULIP_CHIP_AX88140:
    396  1.4  thorpej 		if (sc->sc_rev >= 0x10)
    397  1.4  thorpej 			sc->sc_chip = TULIP_CHIP_AX88141;
    398  1.1  thorpej 		break;
    399  1.1  thorpej 
    400  1.1  thorpej 	default:
    401  1.1  thorpej 		/* Nothing. */
    402  1.1  thorpej 	}
    403  1.1  thorpej 
    404  1.1  thorpej 	printf(": %s Ethernet, pass %d.%d\n",
    405  1.1  thorpej 	    tlp_pci_chip_names[sc->sc_chip],
    406  1.1  thorpej 	    (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
    407  1.1  thorpej 
    408  1.1  thorpej 	sc->sc_dmat = pa->pa_dmat;
    409  1.1  thorpej 
    410  1.1  thorpej 	/*
    411  1.1  thorpej 	 * Make sure bus mastering is enabled.
    412  1.1  thorpej 	 */
    413  1.1  thorpej 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    414  1.1  thorpej 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
    415  1.1  thorpej 	    PCI_COMMAND_MASTER_ENABLE);
    416  1.1  thorpej 
    417  1.1  thorpej 	/*
    418  1.1  thorpej 	 * Get the cacheline size.
    419  1.1  thorpej 	 */
    420  1.1  thorpej 	sc->sc_cacheline = PCI_CACHELINE(pci_conf_read(pc, pa->pa_tag,
    421  1.1  thorpej 	    PCI_BHLC_REG));
    422  1.1  thorpej 
    423  1.1  thorpej 	/*
    424  1.1  thorpej 	 * Read the contents of the Ethernet Address ROM/SROM.
    425  1.1  thorpej 	 */
    426  1.5  thorpej 	memset(sc->sc_srom, 0, sizeof(sc->sc_srom));
    427  1.1  thorpej 	switch (sc->sc_chip) {
    428  1.1  thorpej 	case TULIP_CHIP_21040:
    429  1.1  thorpej 		TULIP_WRITE(sc, CSR_MIIROM, MIIROM_SROMCS);
    430  1.5  thorpej 		for (i = 0; i < sizeof(sc->sc_srom); i++) {
    431  1.1  thorpej 			for (j = 0; j < 10000; j++) {
    432  1.1  thorpej 				val = TULIP_READ(sc, CSR_MIIROM);
    433  1.1  thorpej 				if ((val & MIIROM_DN) == 0)
    434  1.1  thorpej 					break;
    435  1.1  thorpej 			}
    436  1.5  thorpej 			sc->sc_srom[i] = val & MIIROM_DATA;
    437  1.1  thorpej 		}
    438  1.1  thorpej 		break;
    439  1.1  thorpej 
    440  1.1  thorpej 	case TULIP_CHIP_82C168:
    441  1.1  thorpej 	case TULIP_CHIP_82C169:
    442  1.5  thorpej 	    {
    443  1.5  thorpej 		u_int16_t *rombuf = (u_int16_t *)sc->sc_srom;
    444  1.5  thorpej 
    445  1.1  thorpej 		/*
    446  1.1  thorpej 		 * The Lite-On PNIC stores the Ethernet address in
    447  1.1  thorpej 		 * the first 3 words of the EEPROM.  EEPROM access
    448  1.1  thorpej 		 * is not like the other Tulip chips.
    449  1.1  thorpej 		 */
    450  1.1  thorpej 		for (i = 0; i < 3; i++) {
    451  1.1  thorpej 			TULIP_WRITE(sc, CSR_PNIC_SROMCTL,
    452  1.1  thorpej 			    PNIC_SROMCTL_READ | i);
    453  1.1  thorpej 			for (j = 0; j < 500; j++) {
    454  1.1  thorpej 				delay(2);
    455  1.1  thorpej 				val = TULIP_READ(sc, CSR_MIIROM);
    456  1.1  thorpej 				if ((val & PNIC_MIIROM_BUSY) == 0)
    457  1.1  thorpej 					break;
    458  1.1  thorpej 			}
    459  1.1  thorpej 			if (val & PNIC_MIIROM_BUSY) {
    460  1.1  thorpej 				printf("%s: EEPROM timed out\n",
    461  1.1  thorpej 				    sc->sc_dev.dv_xname);
    462  1.1  thorpej 				return;
    463  1.1  thorpej 			}
    464  1.2  thorpej 			rombuf[i] = bswap16(val & PNIC_MIIROM_DATA);
    465  1.1  thorpej 		}
    466  1.1  thorpej 		break;
    467  1.5  thorpej 	    }
    468  1.1  thorpej 
    469  1.1  thorpej 	default:
    470  1.5  thorpej 		tlp_read_srom(sc, 0, sizeof(sc->sc_srom) >> 2,
    471  1.5  thorpej 		    (u_int16_t *)sc->sc_srom);
    472  1.1  thorpej 	}
    473  1.1  thorpej 
    474  1.1  thorpej 	/*
    475  1.1  thorpej 	 * Deal with chip/board quirks.  This includes setting up
    476  1.1  thorpej 	 * the mediasw, and extracting the Ethernet address from
    477  1.1  thorpej 	 * the rombuf.
    478  1.1  thorpej 	 *
    479  1.1  thorpej 	 * XXX Eventually, handle master/slave interrupts on the
    480  1.1  thorpej 	 * XXX multi-port boards which require that.
    481  1.1  thorpej 	 */
    482  1.1  thorpej 	switch (sc->sc_chip) {
    483  1.5  thorpej 	case TULIP_CHIP_21040:
    484  1.8  thorpej 		/* Check for a slaved ROM on a multi-port board. */
    485  1.8  thorpej 		tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDROM,
    486  1.8  thorpej 		    TULIP_PCI_SLAVEROM);
    487  1.8  thorpej 		if (psc->sc_flags & TULIP_PCI_SLAVEROM)
    488  1.8  thorpej 			memcpy(sc->sc_srom, psc->sc_master->sc_tulip.sc_srom,
    489  1.8  thorpej 			    sizeof(sc->sc_srom));
    490  1.8  thorpej 
    491  1.5  thorpej 		/*
    492  1.8  thorpej 		 * Parse the Ethernet Address ROM.
    493  1.5  thorpej 		 */
    494  1.5  thorpej 		if (tlp_parse_old_srom(sc, enaddr) == 0) {
    495  1.8  thorpej 			printf("%s: unable to decode Ethernet Address ROM\n",
    496  1.5  thorpej 			    sc->sc_dev.dv_xname);
    497  1.5  thorpej 			return;
    498  1.5  thorpej 		}
    499  1.5  thorpej 
    500  1.5  thorpej 		/*
    501  1.8  thorpej 		 * If we have a slaved ROM, adjust the Ethernet address.
    502  1.8  thorpej 		 */
    503  1.8  thorpej 		if (psc->sc_flags & TULIP_PCI_SLAVEROM)
    504  1.8  thorpej 			enaddr[5] +=
    505  1.9  thorpej 			    sc->sc_devno - psc->sc_master->sc_tulip.sc_devno;
    506  1.8  thorpej 
    507  1.8  thorpej 		/*
    508  1.5  thorpej 		 * All 21040 boards start out with the same
    509  1.5  thorpej 		 * media switch.
    510  1.5  thorpej 		 */
    511  1.5  thorpej 		sc->sc_mediasw = &tlp_21040_mediasw;
    512  1.5  thorpej 
    513  1.5  thorpej 		/*
    514  1.8  thorpej 		 * Deal with any quirks this board might have.
    515  1.5  thorpej 		 */
    516  1.8  thorpej 		tlp_pci_get_quirks(psc, enaddr, tlp_pci_21040_quirks);
    517  1.5  thorpej 		break;
    518  1.5  thorpej 
    519  1.1  thorpej 	case TULIP_CHIP_82C168:
    520  1.1  thorpej 	case TULIP_CHIP_82C169:
    521  1.1  thorpej 		/*
    522  1.1  thorpej 		 * Lite-On PNIC's Ethernet address is the first 6
    523  1.1  thorpej 		 * bytes of its EEPROM.
    524  1.1  thorpej 		 */
    525  1.5  thorpej 		memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
    526  1.1  thorpej 
    527  1.1  thorpej 		/*
    528  1.1  thorpej 		 * Lite-On PNICs always use the same mediasw; we
    529  1.1  thorpej 		 * select MII vs. internal NWAY automatically.
    530  1.1  thorpej 		 */
    531  1.1  thorpej 		sc->sc_mediasw = &tlp_pnic_mediasw;
    532  1.1  thorpej 		break;
    533  1.1  thorpej 
    534  1.1  thorpej 	case TULIP_CHIP_WB89C840F:
    535  1.1  thorpej 		/*
    536  1.1  thorpej 		 * Winbond 89C840F's Ethernet address is the first
    537  1.1  thorpej 		 * 6 bytes of its EEPROM.
    538  1.1  thorpej 		 */
    539  1.5  thorpej 		memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
    540  1.1  thorpej 
    541  1.1  thorpej 		/*
    542  1.1  thorpej 		 * Winbond 89C840F has an MII attached to the SIO.
    543  1.1  thorpej 		 */
    544  1.1  thorpej 		sc->sc_mediasw = &tlp_sio_mii_mediasw;
    545  1.1  thorpej 		break;
    546  1.1  thorpej 
    547  1.1  thorpej 	default:
    548  1.1  thorpej 		printf("%s: sorry, unable to handle your board\n",
    549  1.1  thorpej 		    sc->sc_dev.dv_xname);
    550  1.1  thorpej 		return;
    551  1.1  thorpej 	}
    552  1.1  thorpej 
    553  1.1  thorpej 	/*
    554  1.8  thorpej 	 * Handle shared interrupts.
    555  1.1  thorpej 	 */
    556  1.8  thorpej 	if (psc->sc_flags & TULIP_PCI_SHAREDINTR) {
    557  1.8  thorpej 		if (psc->sc_master)
    558  1.8  thorpej 			psc->sc_flags |= TULIP_PCI_SLAVEINTR;
    559  1.8  thorpej 		else {
    560  1.8  thorpej 			tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDINTR,
    561  1.8  thorpej 			    TULIP_PCI_SLAVEINTR);
    562  1.8  thorpej 			if (psc->sc_master == NULL)
    563  1.8  thorpej 				psc->sc_master = psc;
    564  1.8  thorpej 		}
    565  1.8  thorpej 		LIST_INSERT_HEAD(&psc->sc_master->sc_intrslaves,
    566  1.8  thorpej 		    psc, sc_intrq);
    567  1.1  thorpej 	}
    568  1.8  thorpej 
    569  1.8  thorpej 	if (psc->sc_flags & TULIP_PCI_SLAVEINTR) {
    570  1.8  thorpej 		printf("%s: sharing interrupt with %s\n",
    571  1.8  thorpej 		    sc->sc_dev.dv_xname,
    572  1.8  thorpej 		    psc->sc_master->sc_tulip.sc_dev.dv_xname);
    573  1.8  thorpej 	} else {
    574  1.8  thorpej 		/*
    575  1.8  thorpej 		 * Map and establish our interrupt.
    576  1.8  thorpej 		 */
    577  1.8  thorpej 		if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    578  1.8  thorpej 		    pa->pa_intrline, &ih)) {
    579  1.8  thorpej 			printf("%s: unable to map interrupt\n",
    580  1.8  thorpej 			    sc->sc_dev.dv_xname);
    581  1.8  thorpej 			return;
    582  1.8  thorpej 		}
    583  1.8  thorpej 		intrstr = pci_intr_string(pc, ih);
    584  1.8  thorpej 		psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET,
    585  1.8  thorpej 		    (psc->sc_flags & TULIP_PCI_SHAREDINTR) ?
    586  1.8  thorpej 		    tlp_pci_shared_intr : tlp_intr, sc);
    587  1.8  thorpej 		if (psc->sc_ih == NULL) {
    588  1.8  thorpej 			printf("%s: unable to establish interrupt",
    589  1.8  thorpej 			    sc->sc_dev.dv_xname);
    590  1.8  thorpej 			if (intrstr != NULL)
    591  1.8  thorpej 				printf(" at %s", intrstr);
    592  1.8  thorpej 			printf("\n");
    593  1.8  thorpej 			return;
    594  1.8  thorpej 		}
    595  1.8  thorpej 		printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
    596  1.8  thorpej 		    intrstr);
    597  1.1  thorpej 	}
    598  1.1  thorpej 
    599  1.1  thorpej 	/*
    600  1.1  thorpej 	 * Finish off the attach.
    601  1.1  thorpej 	 */
    602  1.8  thorpej 	tlp_attach(sc, enaddr);
    603  1.8  thorpej }
    604  1.8  thorpej 
    605  1.8  thorpej int
    606  1.8  thorpej tlp_pci_shared_intr(arg)
    607  1.8  thorpej 	void *arg;
    608  1.8  thorpej {
    609  1.8  thorpej 	struct tulip_pci_softc *master = arg, *slave;
    610  1.8  thorpej 	int rv = 0;
    611  1.8  thorpej 
    612  1.8  thorpej 	for (slave = LIST_FIRST(&master->sc_intrslaves);
    613  1.8  thorpej 	     slave != NULL;
    614  1.8  thorpej 	     slave = LIST_NEXT(slave, sc_intrq))
    615  1.8  thorpej 		rv |= tlp_intr(&slave->sc_tulip);
    616  1.8  thorpej 
    617  1.8  thorpej 	return (rv);
    618  1.8  thorpej }
    619  1.8  thorpej 
    620  1.8  thorpej void
    621  1.8  thorpej tlp_pci_znyx_21040_quirks(psc, enaddr)
    622  1.8  thorpej 	struct tulip_pci_softc *psc;
    623  1.8  thorpej 	const u_int8_t *enaddr;
    624  1.8  thorpej {
    625  1.8  thorpej 	struct tulip_softc *sc = &psc->sc_tulip;
    626  1.8  thorpej 	u_int16_t id = 0;
    627  1.8  thorpej 
    628  1.8  thorpej 	if (sc->sc_srom[32] == 0x4a && sc->sc_srom[33] == 0x52) {
    629  1.8  thorpej 		id = sc->sc_srom[37] | (sc->sc_srom[36] << 8);
    630  1.8  thorpej 		switch (id) {
    631  1.8  thorpej  zx312:
    632  1.8  thorpej 		case 0x0602:	/* ZX312 */
    633  1.8  thorpej 			strcpy(sc->sc_name, "ZNYX ZX312");
    634  1.8  thorpej 			return;
    635  1.8  thorpej 
    636  1.8  thorpej 		case 0x0622:	/* ZX312T */
    637  1.8  thorpej 			strcpy(sc->sc_name, "ZNYX ZX312T");
    638  1.8  thorpej 			sc->sc_mediasw = &tlp_21040_tp_mediasw;
    639  1.8  thorpej 			return;
    640  1.8  thorpej 
    641  1.8  thorpej  zx314_inta:
    642  1.8  thorpej 		case 0x0701:	/* ZX314 INTA */
    643  1.8  thorpej 			psc->sc_flags |= TULIP_PCI_SHAREDINTR;
    644  1.8  thorpej 			/* FALLTHROUGH */
    645  1.8  thorpej 		case 0x0711:	/* ZX314 */
    646  1.8  thorpej 			strcpy(sc->sc_name, "ZNYX ZX314");
    647  1.8  thorpej 			psc->sc_flags |= TULIP_PCI_SHAREDROM;
    648  1.8  thorpej 			sc->sc_mediasw = &tlp_21040_tp_mediasw;
    649  1.8  thorpej 			return;
    650  1.8  thorpej 
    651  1.8  thorpej  zx315_inta:
    652  1.8  thorpej 		case 0x0801:	/* ZX315 INTA */
    653  1.8  thorpej 			psc->sc_flags |= TULIP_PCI_SHAREDINTR;
    654  1.8  thorpej 			/* FALLTHROUGH */
    655  1.8  thorpej 		case 0x0811:	/* ZX315 */
    656  1.8  thorpej 			strcpy(sc->sc_name, "ZNYX ZX315");
    657  1.8  thorpej 			psc->sc_flags |= TULIP_PCI_SHAREDROM;
    658  1.8  thorpej 			return;
    659  1.8  thorpej 
    660  1.8  thorpej 		default:
    661  1.8  thorpej 			id = 0;
    662  1.8  thorpej 		}
    663  1.8  thorpej 	}
    664  1.8  thorpej 
    665  1.8  thorpej 	/*
    666  1.8  thorpej 	 * Deal with boards that have broken ROMs.
    667  1.8  thorpej 	 */
    668  1.8  thorpej 	if (id == 0) {
    669  1.8  thorpej 		if ((enaddr[3] & ~3) == 0xf0 && (enaddr[5] & 3) == 0x00)
    670  1.8  thorpej 			goto zx314_inta;
    671  1.8  thorpej 		if ((enaddr[3] & ~3) == 0xf4 && (enaddr[5] & 1) == 0x00)
    672  1.8  thorpej 			goto zx315_inta;
    673  1.8  thorpej 		if ((enaddr[3] & ~3) == 0xec)
    674  1.8  thorpej 			goto zx312;
    675  1.8  thorpej 	}
    676  1.8  thorpej 
    677  1.8  thorpej 	strcpy(sc->sc_name, "ZNYX ZX31x");
    678  1.8  thorpej }
    679  1.8  thorpej 
    680  1.8  thorpej void
    681  1.8  thorpej tlp_pci_smc_21040_quirks(psc, enaddr)
    682  1.8  thorpej 	struct tulip_pci_softc *psc;
    683  1.8  thorpej 	const u_int8_t *enaddr;
    684  1.8  thorpej {
    685  1.8  thorpej 	struct tulip_softc *sc = &psc->sc_tulip;
    686  1.8  thorpej 	u_int16_t id1, id2, ei;
    687  1.8  thorpej 	int auibnc = 0, utp = 0;
    688  1.8  thorpej 	char *cp;
    689  1.8  thorpej 
    690  1.8  thorpej 	id1 = sc->sc_srom[0x60] | (sc->sc_srom[0x61] << 8);
    691  1.8  thorpej 	id2 = sc->sc_srom[0x62] | (sc->sc_srom[0x63] << 8);
    692  1.8  thorpej 	ei  = sc->sc_srom[0x66] | (sc->sc_srom[0x67] << 8);
    693  1.8  thorpej 
    694  1.8  thorpej 	strcpy(sc->sc_name, "SMC 8432");
    695  1.8  thorpej 	cp = &sc->sc_name[8];
    696  1.8  thorpej 
    697  1.8  thorpej 	if ((id1 & 1) == 0) {
    698  1.8  thorpej 		*cp++ = 'B';
    699  1.8  thorpej 		auibnc = 1;
    700  1.8  thorpej 	}
    701  1.8  thorpej 	if ((id1 & 0xff) > 0x32) {
    702  1.8  thorpej 		*cp++ = 'T';
    703  1.8  thorpej 		utp = 1;
    704  1.8  thorpej 	}
    705  1.8  thorpej 	if ((id1 & 0x4000) == 0) {
    706  1.8  thorpej 		*cp++ = 'A';
    707  1.8  thorpej 		auibnc = 1;
    708  1.8  thorpej 	}
    709  1.8  thorpej 	if (id2 == 0x15) {
    710  1.8  thorpej 		sc->sc_name[7] = '4';
    711  1.8  thorpej 		*cp++ = '-';
    712  1.8  thorpej 		*cp++ = 'C';
    713  1.8  thorpej 		*cp++ = 'H';
    714  1.8  thorpej 		*cp++ = ei ? '2' : '1';
    715  1.8  thorpej 	}
    716  1.8  thorpej 	*cp = '\0';
    717  1.8  thorpej 
    718  1.8  thorpej 	if (utp != 0 && auibnc == 0)
    719  1.8  thorpej 		sc->sc_mediasw = &tlp_21040_tp_mediasw;
    720  1.8  thorpej 	else if (utp == 0 && auibnc != 0)
    721  1.8  thorpej 		sc->sc_mediasw = &tlp_21040_auibnc_mediasw;
    722  1.8  thorpej }
    723  1.8  thorpej 
    724  1.8  thorpej void
    725  1.8  thorpej tlp_pci_cogent_21040_quirks(psc, enaddr)
    726  1.8  thorpej 	struct tulip_pci_softc *psc;
    727  1.8  thorpej 	const u_int8_t *enaddr;
    728  1.8  thorpej {
    729  1.8  thorpej 
    730  1.8  thorpej 	strcpy(psc->sc_tulip.sc_name, "Cogent multi-port");
    731  1.8  thorpej 	psc->sc_flags |= TULIP_PCI_SHAREDINTR|TULIP_PCI_SHAREDROM;
    732  1.8  thorpej }
    733  1.8  thorpej 
    734  1.8  thorpej void
    735  1.8  thorpej tlp_pci_accton_21040_quirks(psc, enaddr)
    736  1.8  thorpej 	struct tulip_pci_softc *psc;
    737  1.8  thorpej 	const u_int8_t *enaddr;
    738  1.8  thorpej {
    739  1.8  thorpej 
    740  1.8  thorpej 	strcpy(psc->sc_tulip.sc_name, "ACCTON EN1203");
    741  1.1  thorpej }
    742