Home | History | Annotate | Line # | Download | only in pci
if_tlp_pci.c revision 1.18
      1 /*	$NetBSD: if_tlp_pci.c,v 1.18 1999/09/28 23:12:23 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * PCI bus front-end for the Digital Semiconductor ``Tulip'' (21x4x)
     42  * Ethernet controller family driver.
     43  */
     44 
     45 #include "opt_inet.h"
     46 #include "opt_ns.h"
     47 #include "bpfilter.h"
     48 
     49 #include <sys/param.h>
     50 #include <sys/systm.h>
     51 #include <sys/mbuf.h>
     52 #include <sys/malloc.h>
     53 #include <sys/kernel.h>
     54 #include <sys/socket.h>
     55 #include <sys/ioctl.h>
     56 #include <sys/errno.h>
     57 #include <sys/device.h>
     58 
     59 #include <net/if.h>
     60 #include <net/if_dl.h>
     61 #include <net/if_media.h>
     62 #include <net/if_ether.h>
     63 
     64 #if NBPFILTER > 0
     65 #include <net/bpf.h>
     66 #endif
     67 
     68 #ifdef INET
     69 #include <netinet/in.h>
     70 #include <netinet/if_inarp.h>
     71 #endif
     72 
     73 #ifdef NS
     74 #include <netns/ns.h>
     75 #include <netns/ns_if.h>
     76 #endif
     77 
     78 #include <machine/bus.h>
     79 #include <machine/intr.h>
     80 
     81 #include <dev/mii/miivar.h>
     82 
     83 #include <dev/ic/tulipreg.h>
     84 #include <dev/ic/tulipvar.h>
     85 
     86 #include <dev/pci/pcivar.h>
     87 #include <dev/pci/pcireg.h>
     88 #include <dev/pci/pcidevs.h>
     89 
     90 /*
     91  * PCI configuration space registers used by the Tulip.
     92  */
     93 #define	TULIP_PCI_IOBA		0x10	/* i/o mapped base */
     94 #define	TULIP_PCI_MMBA		0x14	/* memory mapped base */
     95 #define	TULIP_PCI_CFDA		0x40	/* configuration driver area */
     96 
     97 #define	CFDA_SLEEP		0x80000000	/* sleep mode */
     98 
     99 struct tulip_pci_softc {
    100 	struct tulip_softc sc_tulip;	/* real Tulip softc */
    101 
    102 	/* PCI-specific goo. */
    103 	void	*sc_ih;			/* interrupt handle */
    104 
    105 	pci_chipset_tag_t sc_pc;	/* our PCI chipset */
    106 	pcitag_t sc_pcitag;		/* our PCI tag */
    107 
    108 	int	sc_flags;		/* flags; see below */
    109 
    110 	LIST_HEAD(, tulip_pci_softc) sc_intrslaves;
    111 	LIST_ENTRY(tulip_pci_softc) sc_intrq;
    112 
    113 	/* Our {ROM,interrupt} master. */
    114 	struct tulip_pci_softc *sc_master;
    115 };
    116 
    117 /* sc_flags */
    118 #define	TULIP_PCI_SHAREDINTR	0x01	/* interrupt is shared */
    119 #define	TULIP_PCI_SLAVEINTR	0x02	/* interrupt is slave */
    120 #define	TULIP_PCI_SHAREDROM	0x04	/* ROM is shared */
    121 #define	TULIP_PCI_SLAVEROM	0x08	/* slave of shared ROM */
    122 
    123 int	tlp_pci_match __P((struct device *, struct cfdata *, void *));
    124 void	tlp_pci_attach __P((struct device *, struct device *, void *));
    125 
    126 struct cfattach tlp_pci_ca = {
    127 	sizeof(struct tulip_pci_softc), tlp_pci_match, tlp_pci_attach,
    128 };
    129 
    130 const struct tulip_pci_product {
    131 	u_int32_t	tpp_vendor;	/* PCI vendor ID */
    132 	u_int32_t	tpp_product;	/* PCI product ID */
    133 	tulip_chip_t	tpp_chip;	/* base Tulip chip type */
    134 	int		tpp_pmreg;	/* power management register offset */
    135 } tlp_pci_products[] = {
    136 #ifdef TLP_MATCH_21040
    137 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21040,
    138 	  TULIP_CHIP_21040,		0 },
    139 #endif
    140 #ifdef TLP_MATCH_21041
    141 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21041,
    142 	  TULIP_CHIP_21041,		0 },
    143 #endif
    144 #ifdef TLP_MATCH_21140
    145 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21140,
    146 	  TULIP_CHIP_21140,		0 },
    147 #endif
    148 #ifdef TLP_MATCH_21142
    149 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21142,
    150 	  TULIP_CHIP_21142,		0 },
    151 #endif
    152 
    153 	{ PCI_VENDOR_LITEON,		PCI_PRODUCT_LITEON_82C168,
    154 	  TULIP_CHIP_82C168,		0 },
    155 
    156 #if 0
    157 	/*
    158 	 * Note: This is like a MX98715A with Wake-On-LAN and a
    159 	 * 128-bit multicast hash table.
    160 	 */
    161 	{ PCI_VENDOR_LITEON,		PCI_PRODUCT_LITEON_82C115,
    162 	  TULIP_CHIP_82C115,		0 },
    163 #endif
    164 
    165 	{ PCI_VENDOR_MACRONIX,		PCI_PRODUCT_MACRONIX_MX98713,
    166 	  TULIP_CHIP_MX98713,		0 },
    167 	{ PCI_VENDOR_MACRONIX,		PCI_PRODUCT_MACRONIX_MX987x5,
    168 	  TULIP_CHIP_MX98715,		0x48 },
    169 
    170 	{ PCI_VENDOR_COMPEX,		PCI_PRODUCT_COMPEX_RL100TX,
    171 	  TULIP_CHIP_MX98713,		0 },
    172 
    173 	{ PCI_VENDOR_WINBOND,		PCI_PRODUCT_WINBOND_W89C840F,
    174 	  TULIP_CHIP_WB89C840F,		0 },
    175 	{ PCI_VENDOR_COMPEX,		PCI_PRODUCT_COMPEX_RL100ATX,
    176 	  TULIP_CHIP_WB89C840F,		0 },
    177 
    178 #if 0
    179 	{ PCI_VENDOR_DAVICOM,		PCI_PRODUCT_DAVICOM_DM9102,
    180 	  TULIP_CHIP_DM9102,		0 },
    181 
    182 	{ PCI_VENDOR_ADMTEK,		PCI_PRODUCT_ADMTEK_AL981,
    183 	  TULIP_CHIP_AL981,		0 },
    184 
    185 	{ PCI_VENDOR_ASIX,		PCI_PRODUCT_ASIX_AX88140A,
    186 	  TULIP_CHIP_AX88140,		0 },
    187 #endif
    188 
    189 	{ 0,				0,
    190 	  TULIP_CHIP_INVALID,		0 },
    191 };
    192 
    193 struct tlp_pci_quirks {
    194 	void		(*tpq_func) __P((struct tulip_pci_softc *,
    195 			    const u_int8_t *));
    196 	u_int8_t	tpq_oui[3];
    197 };
    198 
    199 void	tlp_pci_dec_quirks __P((struct tulip_pci_softc *,
    200 	    const u_int8_t *));
    201 
    202 void	tlp_pci_znyx_21040_quirks __P((struct tulip_pci_softc *,
    203 	    const u_int8_t *));
    204 void	tlp_pci_smc_21040_quirks __P((struct tulip_pci_softc *,
    205 	    const u_int8_t *));
    206 void	tlp_pci_cogent_21040_quirks __P((struct tulip_pci_softc *,
    207 	    const u_int8_t *));
    208 void	tlp_pci_accton_21040_quirks __P((struct tulip_pci_softc *,
    209 	    const u_int8_t *));
    210 
    211 const struct tlp_pci_quirks tlp_pci_21040_quirks[] = {
    212 	{ tlp_pci_znyx_21040_quirks,	{ 0x00, 0xc0, 0x95 } },
    213 	{ tlp_pci_smc_21040_quirks,	{ 0x00, 0x00, 0xc0 } },
    214 	{ tlp_pci_cogent_21040_quirks,	{ 0x00, 0x00, 0x92 } },
    215 	{ tlp_pci_accton_21040_quirks,	{ 0x00, 0x00, 0xe8 } },
    216 	{ NULL,				{ 0, 0, 0 } }
    217 };
    218 
    219 const struct tlp_pci_quirks tlp_pci_21041_quirks[] = {
    220 	{ tlp_pci_dec_quirks,		{ 0x08, 0x00, 0x2b } },
    221 	{ tlp_pci_dec_quirks,		{ 0x00, 0x00, 0xf8 } },
    222 	{ NULL,				{ 0, 0, 0 } }
    223 };
    224 
    225 void	tlp_pci_asante_21140_quirks __P((struct tulip_pci_softc *,
    226 	    const u_int8_t *));
    227 
    228 const struct tlp_pci_quirks tlp_pci_21140_quirks[] = {
    229 	{ tlp_pci_dec_quirks,		{ 0x08, 0x00, 0x2b } },
    230 	{ tlp_pci_dec_quirks,		{ 0x00, 0x00, 0xf8 } },
    231 	{ tlp_pci_asante_21140_quirks,	{ 0x00, 0x00, 0x94 } },
    232 	{ NULL,				{ 0, 0, 0 } }
    233 };
    234 
    235 const char *tlp_pci_chip_names[] = TULIP_CHIP_NAMES;
    236 
    237 int	tlp_pci_shared_intr __P((void *));
    238 
    239 const struct tulip_pci_product *tlp_pci_lookup
    240     __P((const struct pci_attach_args *));
    241 void tlp_pci_get_quirks __P((struct tulip_pci_softc *, const u_int8_t *,
    242     const struct tlp_pci_quirks *));
    243 void tlp_pci_check_slaved __P((struct tulip_pci_softc *, int, int));
    244 
    245 const struct tulip_pci_product *
    246 tlp_pci_lookup(pa)
    247 	const struct pci_attach_args *pa;
    248 {
    249 	const struct tulip_pci_product *tpp;
    250 
    251 	for (tpp = tlp_pci_products;
    252 	     tlp_pci_chip_names[tpp->tpp_chip] != NULL;
    253 	     tpp++) {
    254 		if (PCI_VENDOR(pa->pa_id) == tpp->tpp_vendor &&
    255 		    PCI_PRODUCT(pa->pa_id) == tpp->tpp_product)
    256 			return (tpp);
    257 	}
    258 	return (NULL);
    259 }
    260 
    261 void
    262 tlp_pci_get_quirks(psc, enaddr, tpq)
    263 	struct tulip_pci_softc *psc;
    264 	const u_int8_t *enaddr;
    265 	const struct tlp_pci_quirks *tpq;
    266 {
    267 
    268 	for (; tpq->tpq_func != NULL; tpq++) {
    269 		if (tpq->tpq_oui[0] == enaddr[0] &&
    270 		    tpq->tpq_oui[1] == enaddr[1] &&
    271 		    tpq->tpq_oui[2] == enaddr[2]) {
    272 			(*tpq->tpq_func)(psc, enaddr);
    273 			return;
    274 		}
    275 	}
    276 }
    277 
    278 void
    279 tlp_pci_check_slaved(psc, shared, slaved)
    280 	struct tulip_pci_softc *psc;
    281 	int shared, slaved;
    282 {
    283 	extern struct cfdriver tlp_cd;
    284 	struct tulip_pci_softc *cur, *best = NULL;
    285 	struct tulip_softc *sc = &psc->sc_tulip;
    286 	int i;
    287 
    288 	/*
    289 	 * First of all, find the lowest pcidev numbered device on our
    290 	 * bus marked as shared.  That should be our master.
    291 	 */
    292 	for (i = 0; i < tlp_cd.cd_ndevs; i++) {
    293 		if ((cur = tlp_cd.cd_devs[i]) == NULL)
    294 			continue;
    295 		if (cur->sc_tulip.sc_dev.dv_parent != sc->sc_dev.dv_parent)
    296 			continue;
    297 		if ((cur->sc_flags & shared) == 0)
    298 			continue;
    299 		if (cur == psc)
    300 			continue;
    301 		if (best == NULL ||
    302 		    best->sc_tulip.sc_devno > cur->sc_tulip.sc_devno)
    303 			best = cur;
    304 	}
    305 
    306 	if (best != NULL) {
    307 		psc->sc_master = best;
    308 		psc->sc_flags |= (shared | slaved);
    309 	}
    310 }
    311 
    312 int
    313 tlp_pci_match(parent, match, aux)
    314 	struct device *parent;
    315 	struct cfdata *match;
    316 	void *aux;
    317 {
    318 	struct pci_attach_args *pa = aux;
    319 
    320 	if (tlp_pci_lookup(pa) != NULL)
    321 		return (10);	/* beat if_de.c */
    322 
    323 	return (0);
    324 }
    325 
    326 void
    327 tlp_pci_attach(parent, self, aux)
    328 	struct device *parent, *self;
    329 	void *aux;
    330 {
    331 	struct tulip_pci_softc *psc = (void *) self;
    332 	struct tulip_softc *sc = &psc->sc_tulip;
    333 	struct pci_attach_args *pa = aux;
    334 	pci_chipset_tag_t pc = pa->pa_pc;
    335 	pci_intr_handle_t ih;
    336 	const char *intrstr = NULL;
    337 	bus_space_tag_t iot, memt;
    338 	bus_space_handle_t ioh, memh;
    339 	int ioh_valid, memh_valid, i, j;
    340 	const struct tulip_pci_product *tpp;
    341 	u_int8_t enaddr[ETHER_ADDR_LEN];
    342 	u_int32_t val;
    343 	pcireg_t reg;
    344 
    345 	sc->sc_devno = pa->pa_device;
    346 	psc->sc_pc = pa->pa_pc;
    347 	psc->sc_pcitag = pa->pa_tag;
    348 
    349 	LIST_INIT(&psc->sc_intrslaves);
    350 
    351 	tpp = tlp_pci_lookup(pa);
    352 	if (tpp == NULL) {
    353 		printf("\n");
    354 		panic("tlp_pci_attach: impossible");
    355 	}
    356 	sc->sc_chip = tpp->tpp_chip;
    357 
    358 	/*
    359 	 * By default, Tulip registers are 8 bytes long (4 bytes
    360 	 * followed by a 4 byte pad).
    361 	 */
    362 	sc->sc_regshift = 3;
    363 
    364 	/*
    365 	 * Get revision info, and set some chip-specific variables.
    366 	 */
    367 	sc->sc_rev = PCI_REVISION(pa->pa_class);
    368 	switch (sc->sc_chip) {
    369 	case TULIP_CHIP_21140:
    370 		if (sc->sc_rev >= 0x20)
    371 			sc->sc_chip = TULIP_CHIP_21140A;
    372 		break;
    373 
    374 	case TULIP_CHIP_21142:
    375 		if (sc->sc_rev >= 0x20)
    376 			sc->sc_chip = TULIP_CHIP_21143;
    377 		break;
    378 
    379 	case TULIP_CHIP_82C168:
    380 		if (sc->sc_rev >= 0x20)
    381 			sc->sc_chip = TULIP_CHIP_82C169;
    382 		break;
    383 
    384 	case TULIP_CHIP_MX98713:
    385 		if (sc->sc_rev >= 0x10)
    386 			sc->sc_chip = TULIP_CHIP_MX98713A;
    387 		break;
    388 
    389 	case TULIP_CHIP_MX98715:
    390 		if (sc->sc_rev >= 0x30)
    391 			sc->sc_chip = TULIP_CHIP_MX98725;
    392 		break;
    393 
    394 	case TULIP_CHIP_WB89C840F:
    395 		sc->sc_regshift = 2;
    396 		break;
    397 
    398 	case TULIP_CHIP_AX88140:
    399 		if (sc->sc_rev >= 0x10)
    400 			sc->sc_chip = TULIP_CHIP_AX88141;
    401 		break;
    402 
    403 	default:
    404 		/* Nothing. */
    405 	}
    406 
    407 	printf(": %s Ethernet, pass %d.%d\n",
    408 	    tlp_pci_chip_names[sc->sc_chip],
    409 	    (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
    410 
    411 	switch (sc->sc_chip) {
    412 	case TULIP_CHIP_21040:
    413 		if (sc->sc_rev < 0x20) {
    414 			printf("%s: 21040 must be at least pass 2.0\n",
    415 			    sc->sc_dev.dv_xname);
    416 			return;
    417 		}
    418 		break;
    419 
    420 	case TULIP_CHIP_21140:
    421 		if (sc->sc_rev < 0x11) {
    422 			printf("%s: 21140 must be at least pass 1.1\n",
    423 			    sc->sc_dev.dv_xname);
    424 			return;
    425 		}
    426 		break;
    427 
    428 	default:
    429 		/* Nothing. */
    430 	}
    431 
    432 	/*
    433 	 * Check to see if the device is in power-save mode, and
    434 	 * being it out if necessary.
    435 	 */
    436 	switch (sc->sc_chip) {
    437 	case TULIP_CHIP_21140:
    438 	case TULIP_CHIP_21140A:
    439 	case TULIP_CHIP_MX98713A:
    440 	case TULIP_CHIP_MX98715:
    441 	case TULIP_CHIP_MX98725:
    442 		/*
    443 		 * Clear the "sleep mode" bit in the CFDA register.
    444 		 */
    445 		reg = pci_conf_read(pc, pa->pa_tag, TULIP_PCI_CFDA);
    446 		if (reg & CFDA_SLEEP)
    447 			pci_conf_write(pc, pa->pa_tag, TULIP_PCI_CFDA,
    448 			    reg & ~CFDA_SLEEP);
    449 		break;
    450 
    451 	default:
    452 		/* Nothing. */
    453 	}
    454 
    455 	if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PWRMGMT, 0, 0)) {
    456 		if (tpp->tpp_pmreg == 0) {
    457 			printf("%s: don't know location of PMCSR for this "
    458 			    "chip\n", sc->sc_dev.dv_xname);
    459 			return;
    460 		}
    461 		reg = pci_conf_read(pc, pa->pa_tag, tpp->tpp_pmreg) & 0x3;
    462 		if (reg == 3) {
    463 			/*
    464 			 * The card has lost all configuration data in
    465 			 * this state, so punt.
    466 			 */
    467 			printf("%s: unable to wake up from power state D3\n",
    468 			    sc->sc_dev.dv_xname);
    469 			return;
    470 		}
    471 		if (reg != 0) {
    472 			printf("%s: waking up from power state D%d\n",
    473 			    sc->sc_dev.dv_xname, reg);
    474 			pci_conf_write(pc, pa->pa_tag, tpp->tpp_pmreg, 0);
    475 		}
    476 	}
    477 
    478 	/*
    479 	 * Map the device.
    480 	 */
    481 	ioh_valid = (pci_mapreg_map(pa, TULIP_PCI_IOBA,
    482 	    PCI_MAPREG_TYPE_IO, 0,
    483 	    &iot, &ioh, NULL, NULL) == 0);
    484 	memh_valid = (pci_mapreg_map(pa, TULIP_PCI_MMBA,
    485 	    PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
    486 	    &memt, &memh, NULL, NULL) == 0);
    487 
    488 	if (memh_valid) {
    489 		sc->sc_st = memt;
    490 		sc->sc_sh = memh;
    491 	} else if (ioh_valid) {
    492 		sc->sc_st = iot;
    493 		sc->sc_sh = ioh;
    494 	} else {
    495 		printf(": unable to map device registers\n");
    496 		return;
    497 	}
    498 
    499 	sc->sc_dmat = pa->pa_dmat;
    500 
    501 	/*
    502 	 * Make sure bus mastering is enabled.
    503 	 */
    504 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    505 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
    506 	    PCI_COMMAND_MASTER_ENABLE);
    507 
    508 	/*
    509 	 * Get the cacheline size.
    510 	 */
    511 	sc->sc_cacheline = PCI_CACHELINE(pci_conf_read(pc, pa->pa_tag,
    512 	    PCI_BHLC_REG));
    513 
    514 	/*
    515 	 * Read the contents of the Ethernet Address ROM/SROM.
    516 	 */
    517 	memset(sc->sc_srom, 0, sizeof(sc->sc_srom));
    518 	switch (sc->sc_chip) {
    519 	case TULIP_CHIP_21040:
    520 		TULIP_WRITE(sc, CSR_MIIROM, MIIROM_SROMCS);
    521 		for (i = 0; i < sizeof(sc->sc_srom); i++) {
    522 			for (j = 0; j < 10000; j++) {
    523 				val = TULIP_READ(sc, CSR_MIIROM);
    524 				if ((val & MIIROM_DN) == 0)
    525 					break;
    526 			}
    527 			sc->sc_srom[i] = val & MIIROM_DATA;
    528 		}
    529 		break;
    530 
    531 	case TULIP_CHIP_82C168:
    532 	case TULIP_CHIP_82C169:
    533 	    {
    534 		u_int16_t *rombuf = (u_int16_t *)sc->sc_srom;
    535 
    536 		/*
    537 		 * The Lite-On PNIC stores the Ethernet address in
    538 		 * the first 3 words of the EEPROM.  EEPROM access
    539 		 * is not like the other Tulip chips.
    540 		 */
    541 		for (i = 0; i < 3; i++) {
    542 			TULIP_WRITE(sc, CSR_PNIC_SROMCTL,
    543 			    PNIC_SROMCTL_READ | i);
    544 			for (j = 0; j < 500; j++) {
    545 				delay(2);
    546 				val = TULIP_READ(sc, CSR_MIIROM);
    547 				if ((val & PNIC_MIIROM_BUSY) == 0)
    548 					break;
    549 			}
    550 			if (val & PNIC_MIIROM_BUSY) {
    551 				printf("%s: EEPROM timed out\n",
    552 				    sc->sc_dev.dv_xname);
    553 				return;
    554 			}
    555 			rombuf[i] = bswap16(val & PNIC_MIIROM_DATA);
    556 		}
    557 		break;
    558 	    }
    559 
    560 	default:
    561 		tlp_read_srom(sc, 0, sizeof(sc->sc_srom) >> 1, sc->sc_srom);
    562 #if 0
    563 		printf("SROM CONTENTS:");
    564 		for (i = 0; i < sizeof(sc->sc_srom); i++) {
    565 			if ((i % 8) == 0)
    566 				printf("\n\t");
    567 			printf("0x%02x ", sc->sc_srom[i]);
    568 		}
    569 		printf("\n");
    570 #endif
    571 	}
    572 
    573 	/*
    574 	 * Deal with chip/board quirks.  This includes setting up
    575 	 * the mediasw, and extracting the Ethernet address from
    576 	 * the rombuf.
    577 	 */
    578 	switch (sc->sc_chip) {
    579 	case TULIP_CHIP_21040:
    580 		/* Check for a slaved ROM on a multi-port board. */
    581 		tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDROM,
    582 		    TULIP_PCI_SLAVEROM);
    583 		if (psc->sc_flags & TULIP_PCI_SLAVEROM)
    584 			memcpy(sc->sc_srom, psc->sc_master->sc_tulip.sc_srom,
    585 			    sizeof(sc->sc_srom));
    586 
    587 		/*
    588 		 * Parse the Ethernet Address ROM.
    589 		 */
    590 		if (tlp_parse_old_srom(sc, enaddr) == 0) {
    591 			printf("%s: unable to decode Ethernet Address ROM\n",
    592 			    sc->sc_dev.dv_xname);
    593 			return;
    594 		}
    595 
    596 		/*
    597 		 * If we have a slaved ROM, adjust the Ethernet address.
    598 		 */
    599 		if (psc->sc_flags & TULIP_PCI_SLAVEROM)
    600 			enaddr[5] +=
    601 			    sc->sc_devno - psc->sc_master->sc_tulip.sc_devno;
    602 
    603 		/*
    604 		 * All 21040 boards start out with the same
    605 		 * media switch.
    606 		 */
    607 		sc->sc_mediasw = &tlp_21040_mediasw;
    608 
    609 		/*
    610 		 * Deal with any quirks this board might have.
    611 		 */
    612 		tlp_pci_get_quirks(psc, enaddr, tlp_pci_21040_quirks);
    613 		break;
    614 
    615 	case TULIP_CHIP_21041:
    616 		/* Check for a slaved ROM on a multi-port board. */
    617 		tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDROM,
    618 		    TULIP_PCI_SLAVEROM);
    619 		if (psc->sc_flags & TULIP_PCI_SLAVEROM)
    620 			memcpy(sc->sc_srom, psc->sc_master->sc_tulip.sc_srom,
    621 			    sizeof(sc->sc_srom));
    622 
    623 		/* Check for new format SROM. */
    624 		if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
    625 			/*
    626 			 * Not an ISV SROM; try the old DEC Ethernet Address
    627 			 * ROM format.
    628 			 */
    629 			if (tlp_parse_old_srom(sc, enaddr) == 0) {
    630 				printf("%s: unable to decode Ethernet "
    631 				    "Address ROM\n", sc->sc_dev.dv_xname);
    632 				return;
    633 			}
    634 		}
    635 
    636 		/*
    637 		 * All 21041 boards use the same media switch; they all
    638 		 * work basically the same!  Yippee!
    639 		 */
    640 		sc->sc_mediasw = &tlp_21041_mediasw;
    641 
    642 		/*
    643 		 * Deal with any quirks this board might have.
    644 		 */
    645 		tlp_pci_get_quirks(psc, enaddr, tlp_pci_21041_quirks);
    646 		break;
    647 
    648 	case TULIP_CHIP_21140:
    649 	case TULIP_CHIP_21140A:
    650 		/* Check for new format SROM. */
    651 		if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
    652 			/*
    653 			 * Not an ISV SROM; try the old DEC Ethernet Address
    654 			 * ROM format.
    655 			 */
    656 			if (tlp_parse_old_srom(sc, enaddr) == 0) {
    657 				printf("%s: unable to decode Ethernet "
    658 				    "Address ROM\n", sc->sc_dev.dv_xname);
    659 				return;
    660 			}
    661 		} else {
    662 			/*
    663 			 * We start out with the 2114x ISV media switch.
    664 			 * When we search for quirks, we may change to
    665 			 * a different switch.
    666 			 */
    667 			sc->sc_mediasw = &tlp_2114x_isv_mediasw;
    668 		}
    669 
    670 		/*
    671 		 * Deal with any quirks this board might have.
    672 		 */
    673 		tlp_pci_get_quirks(psc, enaddr, tlp_pci_21140_quirks);
    674 
    675 		/*
    676 		 * Bail out now if we can't deal with this board.
    677 		 */
    678 		if (sc->sc_mediasw == NULL)
    679 			goto cant_cope;
    680 		break;
    681 
    682 	case TULIP_CHIP_82C168:
    683 	case TULIP_CHIP_82C169:
    684 		/*
    685 		 * Lite-On PNIC's Ethernet address is the first 6
    686 		 * bytes of its EEPROM.
    687 		 */
    688 		memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
    689 
    690 		/*
    691 		 * Lite-On PNICs always use the same mediasw; we
    692 		 * select MII vs. internal NWAY automatically.
    693 		 */
    694 		sc->sc_mediasw = &tlp_pnic_mediasw;
    695 		break;
    696 
    697 	case TULIP_CHIP_MX98713:
    698 	case TULIP_CHIP_MX98713A:
    699 	case TULIP_CHIP_MX98715:
    700 	case TULIP_CHIP_MX98725:
    701 		/*
    702 		 * Happily, Macronix chips use the ISV SROM format!
    703 		 * Wow, a clone that's actually Tulip-like!
    704 		 */
    705 		if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
    706 			/*
    707 			 * Not ISV SROM; can't cope right now.
    708 			 */
    709 			goto cant_cope;
    710 		} else {
    711 			/*
    712 			 * We start out with the 2114x ISV media switch.
    713 			 * When we search for quirks, we may change to
    714 			 * a different switch.
    715 			 */
    716 			sc->sc_mediasw = &tlp_2114x_isv_mediasw;
    717 		}
    718 		break;
    719 
    720 	case TULIP_CHIP_WB89C840F:
    721 		/*
    722 		 * Winbond 89C840F's Ethernet address is the first
    723 		 * 6 bytes of its EEPROM.
    724 		 */
    725 		memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
    726 
    727 		/*
    728 		 * Winbond 89C840F has an MII attached to the SIO.
    729 		 */
    730 		sc->sc_mediasw = &tlp_sio_mii_mediasw;
    731 		break;
    732 
    733 	default:
    734  cant_cope:
    735 		printf("%s: sorry, unable to handle your board\n",
    736 		    sc->sc_dev.dv_xname);
    737 		return;
    738 	}
    739 
    740 	/*
    741 	 * Handle shared interrupts.
    742 	 */
    743 	if (psc->sc_flags & TULIP_PCI_SHAREDINTR) {
    744 		if (psc->sc_master)
    745 			psc->sc_flags |= TULIP_PCI_SLAVEINTR;
    746 		else {
    747 			tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDINTR,
    748 			    TULIP_PCI_SLAVEINTR);
    749 			if (psc->sc_master == NULL)
    750 				psc->sc_master = psc;
    751 		}
    752 		LIST_INSERT_HEAD(&psc->sc_master->sc_intrslaves,
    753 		    psc, sc_intrq);
    754 	}
    755 
    756 	if (psc->sc_flags & TULIP_PCI_SLAVEINTR) {
    757 		printf("%s: sharing interrupt with %s\n",
    758 		    sc->sc_dev.dv_xname,
    759 		    psc->sc_master->sc_tulip.sc_dev.dv_xname);
    760 	} else {
    761 		/*
    762 		 * Map and establish our interrupt.
    763 		 */
    764 		if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    765 		    pa->pa_intrline, &ih)) {
    766 			printf("%s: unable to map interrupt\n",
    767 			    sc->sc_dev.dv_xname);
    768 			return;
    769 		}
    770 		intrstr = pci_intr_string(pc, ih);
    771 		psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET,
    772 		    (psc->sc_flags & TULIP_PCI_SHAREDINTR) ?
    773 		    tlp_pci_shared_intr : tlp_intr, sc);
    774 		if (psc->sc_ih == NULL) {
    775 			printf("%s: unable to establish interrupt",
    776 			    sc->sc_dev.dv_xname);
    777 			if (intrstr != NULL)
    778 				printf(" at %s", intrstr);
    779 			printf("\n");
    780 			return;
    781 		}
    782 		printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
    783 		    intrstr);
    784 	}
    785 
    786 	/*
    787 	 * Finish off the attach.
    788 	 */
    789 	tlp_attach(sc, enaddr);
    790 }
    791 
    792 int
    793 tlp_pci_shared_intr(arg)
    794 	void *arg;
    795 {
    796 	struct tulip_pci_softc *master = arg, *slave;
    797 	int rv = 0;
    798 
    799 	for (slave = LIST_FIRST(&master->sc_intrslaves);
    800 	     slave != NULL;
    801 	     slave = LIST_NEXT(slave, sc_intrq))
    802 		rv |= tlp_intr(&slave->sc_tulip);
    803 
    804 	return (rv);
    805 }
    806 
    807 void
    808 tlp_pci_dec_quirks(psc, enaddr)
    809 	struct tulip_pci_softc *psc;
    810 	const u_int8_t *enaddr;
    811 {
    812 	struct tulip_softc *sc = &psc->sc_tulip;
    813 
    814 	/*
    815 	 * This isn't really a quirk-gathering device, really.  We
    816 	 * just want to get the spiffy DEC board name from the SROM.
    817 	 */
    818 	strcpy(sc->sc_name, "DEC ");
    819 
    820 	if (memcmp(&sc->sc_srom[29], "DE500", 5) == 0 ||
    821 	    memcmp(&sc->sc_srom[29], "DE450", 5) == 0)
    822 		memcpy(&sc->sc_name[4], &sc->sc_srom[29], 8);
    823 }
    824 
    825 void
    826 tlp_pci_znyx_21040_quirks(psc, enaddr)
    827 	struct tulip_pci_softc *psc;
    828 	const u_int8_t *enaddr;
    829 {
    830 	struct tulip_softc *sc = &psc->sc_tulip;
    831 	u_int16_t id = 0;
    832 
    833 	/*
    834 	 * If we have a slaved ROM, just copy the bits from the master.
    835 	 * This is in case we fail the ROM ID check (older boards) and
    836 	 * need to fall back on Ethernet address model checking; that
    837 	 * will fail for slave chips.
    838 	 */
    839 	if (psc->sc_flags & TULIP_PCI_SLAVEROM) {
    840 		strcpy(sc->sc_name, psc->sc_master->sc_tulip.sc_name);
    841 		sc->sc_mediasw = psc->sc_master->sc_tulip.sc_mediasw;
    842 		psc->sc_flags |=
    843 		    psc->sc_master->sc_flags & TULIP_PCI_SHAREDINTR;
    844 		return;
    845 	}
    846 
    847 	if (sc->sc_srom[32] == 0x4a && sc->sc_srom[33] == 0x52) {
    848 		id = sc->sc_srom[37] | (sc->sc_srom[36] << 8);
    849 		switch (id) {
    850  zx312:
    851 		case 0x0602:	/* ZX312 */
    852 			strcpy(sc->sc_name, "ZNYX ZX312");
    853 			return;
    854 
    855 		case 0x0622:	/* ZX312T */
    856 			strcpy(sc->sc_name, "ZNYX ZX312T");
    857 			sc->sc_mediasw = &tlp_21040_tp_mediasw;
    858 			return;
    859 
    860  zx314_inta:
    861 		case 0x0701:	/* ZX314 INTA */
    862 			psc->sc_flags |= TULIP_PCI_SHAREDINTR;
    863 			/* FALLTHROUGH */
    864 		case 0x0711:	/* ZX314 */
    865 			strcpy(sc->sc_name, "ZNYX ZX314");
    866 			psc->sc_flags |= TULIP_PCI_SHAREDROM;
    867 			sc->sc_mediasw = &tlp_21040_tp_mediasw;
    868 			return;
    869 
    870  zx315_inta:
    871 		case 0x0801:	/* ZX315 INTA */
    872 			psc->sc_flags |= TULIP_PCI_SHAREDINTR;
    873 			/* FALLTHROUGH */
    874 		case 0x0811:	/* ZX315 */
    875 			strcpy(sc->sc_name, "ZNYX ZX315");
    876 			psc->sc_flags |= TULIP_PCI_SHAREDROM;
    877 			return;
    878 
    879 		default:
    880 			id = 0;
    881 		}
    882 	}
    883 
    884 	/*
    885 	 * Deal with boards that have broken ROMs.
    886 	 */
    887 	if (id == 0) {
    888 		if ((enaddr[3] & ~3) == 0xf0 && (enaddr[5] & 3) == 0x00)
    889 			goto zx314_inta;
    890 		if ((enaddr[3] & ~3) == 0xf4 && (enaddr[5] & 1) == 0x00)
    891 			goto zx315_inta;
    892 		if ((enaddr[3] & ~3) == 0xec)
    893 			goto zx312;
    894 	}
    895 
    896 	strcpy(sc->sc_name, "ZNYX ZX31x");
    897 }
    898 
    899 void
    900 tlp_pci_smc_21040_quirks(psc, enaddr)
    901 	struct tulip_pci_softc *psc;
    902 	const u_int8_t *enaddr;
    903 {
    904 	struct tulip_softc *sc = &psc->sc_tulip;
    905 	u_int16_t id1, id2, ei;
    906 	int auibnc = 0, utp = 0;
    907 	char *cp;
    908 
    909 	id1 = sc->sc_srom[0x60] | (sc->sc_srom[0x61] << 8);
    910 	id2 = sc->sc_srom[0x62] | (sc->sc_srom[0x63] << 8);
    911 	ei  = sc->sc_srom[0x66] | (sc->sc_srom[0x67] << 8);
    912 
    913 	strcpy(sc->sc_name, "SMC 8432");
    914 	cp = &sc->sc_name[8];
    915 
    916 	if ((id1 & 1) == 0) {
    917 		*cp++ = 'B';
    918 		auibnc = 1;
    919 	}
    920 	if ((id1 & 0xff) > 0x32) {
    921 		*cp++ = 'T';
    922 		utp = 1;
    923 	}
    924 	if ((id1 & 0x4000) == 0) {
    925 		*cp++ = 'A';
    926 		auibnc = 1;
    927 	}
    928 	if (id2 == 0x15) {
    929 		sc->sc_name[7] = '4';
    930 		*cp++ = '-';
    931 		*cp++ = 'C';
    932 		*cp++ = 'H';
    933 		*cp++ = ei ? '2' : '1';
    934 	}
    935 	*cp = '\0';
    936 
    937 	if (utp != 0 && auibnc == 0)
    938 		sc->sc_mediasw = &tlp_21040_tp_mediasw;
    939 	else if (utp == 0 && auibnc != 0)
    940 		sc->sc_mediasw = &tlp_21040_auibnc_mediasw;
    941 }
    942 
    943 void
    944 tlp_pci_cogent_21040_quirks(psc, enaddr)
    945 	struct tulip_pci_softc *psc;
    946 	const u_int8_t *enaddr;
    947 {
    948 
    949 	strcpy(psc->sc_tulip.sc_name, "Cogent multi-port");
    950 	psc->sc_flags |= TULIP_PCI_SHAREDINTR|TULIP_PCI_SHAREDROM;
    951 }
    952 
    953 void
    954 tlp_pci_accton_21040_quirks(psc, enaddr)
    955 	struct tulip_pci_softc *psc;
    956 	const u_int8_t *enaddr;
    957 {
    958 
    959 	strcpy(psc->sc_tulip.sc_name, "ACCTON EN1203");
    960 }
    961 
    962 void	tlp_pci_asante_21140_reset __P((struct tulip_softc *));
    963 
    964 void
    965 tlp_pci_asante_21140_quirks(psc, enaddr)
    966 	struct tulip_pci_softc *psc;
    967 	const u_int8_t *enaddr;
    968 {
    969 	struct tulip_softc *sc = &psc->sc_tulip;
    970 
    971 	/*
    972 	 * Some Asante boards don't use the ISV SROM format.  For
    973 	 * those that don't, we initialize the GPIO direction bits,
    974 	 * and provide our own reset hook, which resets the MII.
    975 	 *
    976 	 * All of these boards use SIO-attached-MII media.
    977 	 */
    978 	if (sc->sc_mediasw == &tlp_2114x_isv_mediasw)
    979 		return;
    980 
    981 	strcpy(sc->sc_name, "Asante");
    982 
    983 	sc->sc_gp_dir = 0xbf;
    984 	sc->sc_reset = tlp_pci_asante_21140_reset;
    985 	sc->sc_mediasw = &tlp_sio_mii_mediasw;
    986 }
    987 
    988 void
    989 tlp_pci_asante_21140_reset(sc)
    990 	struct tulip_softc *sc;
    991 {
    992 
    993 	TULIP_WRITE(sc, CSR_GPP, GPP_GPC | sc->sc_gp_dir);
    994 	TULIP_WRITE(sc, CSR_GPP, 0x8);
    995 	delay(100);
    996 	TULIP_WRITE(sc, CSR_GPP, 0);
    997 }
    998