Home | History | Annotate | Line # | Download | only in pci
if_tlp_pci.c revision 1.61
      1 /*	$NetBSD: if_tlp_pci.c,v 1.61 2002/03/16 18:44:17 chs Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998, 1999, 2000 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 <sys/cdefs.h>
     46 __KERNEL_RCSID(0, "$NetBSD: if_tlp_pci.c,v 1.61 2002/03/16 18:44:17 chs Exp $");
     47 
     48 #include "opt_tlp.h"
     49 
     50 #include <sys/param.h>
     51 #include <sys/systm.h>
     52 #include <sys/mbuf.h>
     53 #include <sys/malloc.h>
     54 #include <sys/kernel.h>
     55 #include <sys/socket.h>
     56 #include <sys/ioctl.h>
     57 #include <sys/errno.h>
     58 #include <sys/device.h>
     59 
     60 #include <machine/endian.h>
     61 
     62 #include <net/if.h>
     63 #include <net/if_dl.h>
     64 #include <net/if_media.h>
     65 #include <net/if_ether.h>
     66 
     67 #include <machine/bus.h>
     68 #include <machine/intr.h>
     69 
     70 #include <dev/mii/miivar.h>
     71 #include <dev/mii/mii_bitbang.h>
     72 
     73 #include <dev/ic/tulipreg.h>
     74 #include <dev/ic/tulipvar.h>
     75 
     76 #include <dev/pci/pcivar.h>
     77 #include <dev/pci/pcireg.h>
     78 #include <dev/pci/pcidevs.h>
     79 
     80 /*
     81  * PCI configuration space registers used by the Tulip.
     82  */
     83 #define	TULIP_PCI_IOBA		0x10	/* i/o mapped base */
     84 #define	TULIP_PCI_MMBA		0x14	/* memory mapped base */
     85 #define	TULIP_PCI_CFDA		0x40	/* configuration driver area */
     86 
     87 #define	CFDA_SLEEP		0x80000000	/* sleep mode */
     88 #define	CFDA_SNOOZE		0x40000000	/* snooze mode */
     89 
     90 struct tulip_pci_softc {
     91 	struct tulip_softc sc_tulip;	/* real Tulip softc */
     92 
     93 	/* PCI-specific goo. */
     94 	void	*sc_ih;			/* interrupt handle */
     95 
     96 	pci_chipset_tag_t sc_pc;	/* our PCI chipset */
     97 	pcitag_t sc_pcitag;		/* our PCI tag */
     98 
     99 	int	sc_flags;		/* flags; see below */
    100 
    101 	LIST_HEAD(, tulip_pci_softc) sc_intrslaves;
    102 	LIST_ENTRY(tulip_pci_softc) sc_intrq;
    103 
    104 	/* Our {ROM,interrupt} master. */
    105 	struct tulip_pci_softc *sc_master;
    106 };
    107 
    108 /* sc_flags */
    109 #define	TULIP_PCI_SHAREDINTR	0x01	/* interrupt is shared */
    110 #define	TULIP_PCI_SLAVEINTR	0x02	/* interrupt is slave */
    111 #define	TULIP_PCI_SHAREDROM	0x04	/* ROM is shared */
    112 #define	TULIP_PCI_SLAVEROM	0x08	/* slave of shared ROM */
    113 
    114 int	tlp_pci_match __P((struct device *, struct cfdata *, void *));
    115 void	tlp_pci_attach __P((struct device *, struct device *, void *));
    116 
    117 struct cfattach tlp_pci_ca = {
    118 	sizeof(struct tulip_pci_softc), tlp_pci_match, tlp_pci_attach,
    119 };
    120 
    121 const struct tulip_pci_product {
    122 	u_int32_t	tpp_vendor;	/* PCI vendor ID */
    123 	u_int32_t	tpp_product;	/* PCI product ID */
    124 	tulip_chip_t	tpp_chip;	/* base Tulip chip type */
    125 } tlp_pci_products[] = {
    126 #ifdef TLP_MATCH_21040
    127 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21040,
    128 	  TULIP_CHIP_21040 },
    129 #endif
    130 #ifdef TLP_MATCH_21041
    131 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21041,
    132 	  TULIP_CHIP_21041 },
    133 #endif
    134 #ifdef TLP_MATCH_21140
    135 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21140,
    136 	  TULIP_CHIP_21140 },
    137 #endif
    138 #ifdef TLP_MATCH_21142
    139 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21142,
    140 	  TULIP_CHIP_21142 },
    141 #endif
    142 
    143 	{ PCI_VENDOR_LITEON,		PCI_PRODUCT_LITEON_82C168,
    144 	  TULIP_CHIP_82C168 },
    145 
    146 	/*
    147 	 * Note: This is like a MX98725 with Wake-On-LAN and a
    148 	 * 128-bit multicast hash table.
    149 	 */
    150 	{ PCI_VENDOR_LITEON,		PCI_PRODUCT_LITEON_82C115,
    151 	  TULIP_CHIP_82C115 },
    152 
    153 	{ PCI_VENDOR_MACRONIX,		PCI_PRODUCT_MACRONIX_MX98713,
    154 	  TULIP_CHIP_MX98713 },
    155 	{ PCI_VENDOR_MACRONIX,		PCI_PRODUCT_MACRONIX_MX987x5,
    156 	  TULIP_CHIP_MX98715 },
    157 
    158 	{ PCI_VENDOR_COMPEX,		PCI_PRODUCT_COMPEX_RL100TX,
    159 	  TULIP_CHIP_MX98713 },
    160 
    161 	{ PCI_VENDOR_WINBOND,		PCI_PRODUCT_WINBOND_W89C840F,
    162 	  TULIP_CHIP_WB89C840F },
    163 	{ PCI_VENDOR_COMPEX,		PCI_PRODUCT_COMPEX_RL100ATX,
    164 	  TULIP_CHIP_WB89C840F },
    165 
    166 	{ PCI_VENDOR_DAVICOM,		PCI_PRODUCT_DAVICOM_DM9102,
    167 	  TULIP_CHIP_DM9102 },
    168 
    169 	{ PCI_VENDOR_ADMTEK,		PCI_PRODUCT_ADMTEK_AL981,
    170 	  TULIP_CHIP_AL981 },
    171 
    172 	{ PCI_VENDOR_ADMTEK,		PCI_PRODUCT_ADMTEK_AN985,
    173 	  TULIP_CHIP_AN985 },
    174 	{ PCI_VENDOR_ACCTON,		PCI_PRODUCT_ACCTON_EN2242,
    175 	  TULIP_CHIP_AN985 },
    176 
    177 #if 0
    178 	{ PCI_VENDOR_ASIX,		PCI_PRODUCT_ASIX_AX88140A,
    179 	  TULIP_CHIP_AX88140 },
    180 #endif
    181 
    182 	{ 0,				0,
    183 	  TULIP_CHIP_INVALID },
    184 };
    185 
    186 struct tlp_pci_quirks {
    187 	void		(*tpq_func) __P((struct tulip_pci_softc *,
    188 			    const u_int8_t *));
    189 	u_int8_t	tpq_oui[3];
    190 };
    191 
    192 void	tlp_pci_dec_quirks __P((struct tulip_pci_softc *,
    193 	    const u_int8_t *));
    194 
    195 void	tlp_pci_znyx_21040_quirks __P((struct tulip_pci_softc *,
    196 	    const u_int8_t *));
    197 void	tlp_pci_smc_21040_quirks __P((struct tulip_pci_softc *,
    198 	    const u_int8_t *));
    199 void	tlp_pci_cogent_21040_quirks __P((struct tulip_pci_softc *,
    200 	    const u_int8_t *));
    201 void	tlp_pci_accton_21040_quirks __P((struct tulip_pci_softc *,
    202 	    const u_int8_t *));
    203 
    204 void	tlp_pci_cobalt_21142_quirks __P((struct tulip_pci_softc *,
    205 	    const u_int8_t *));
    206 void	tlp_pci_algor_21142_quirks __P((struct tulip_pci_softc *,
    207 	    const u_int8_t *));
    208 
    209 void	tlp_pci_adaptec_quirks __P((struct tulip_pci_softc *,
    210 	    const u_int8_t *));
    211 
    212 const struct tlp_pci_quirks tlp_pci_21040_quirks[] = {
    213 	{ tlp_pci_znyx_21040_quirks,	{ 0x00, 0xc0, 0x95 } },
    214 	{ tlp_pci_smc_21040_quirks,	{ 0x00, 0x00, 0xc0 } },
    215 	{ tlp_pci_cogent_21040_quirks,	{ 0x00, 0x00, 0x92 } },
    216 	{ tlp_pci_accton_21040_quirks,	{ 0x00, 0x00, 0xe8 } },
    217 	{ NULL,				{ 0, 0, 0 } }
    218 };
    219 
    220 const struct tlp_pci_quirks tlp_pci_21041_quirks[] = {
    221 	{ tlp_pci_dec_quirks,		{ 0x08, 0x00, 0x2b } },
    222 	{ tlp_pci_dec_quirks,		{ 0x00, 0x00, 0xf8 } },
    223 	{ NULL,				{ 0, 0, 0 } }
    224 };
    225 
    226 void	tlp_pci_asante_21140_quirks __P((struct tulip_pci_softc *,
    227 	    const u_int8_t *));
    228 
    229 const struct tlp_pci_quirks tlp_pci_21140_quirks[] = {
    230 	{ tlp_pci_dec_quirks,		{ 0x08, 0x00, 0x2b } },
    231 	{ tlp_pci_dec_quirks,		{ 0x00, 0x00, 0xf8 } },
    232 	{ tlp_pci_asante_21140_quirks,	{ 0x00, 0x00, 0x94 } },
    233 	{ tlp_pci_adaptec_quirks,	{ 0x00, 0x00, 0x92 } },
    234 	{ tlp_pci_adaptec_quirks,	{ 0x00, 0x00, 0xd1 } },
    235 	{ NULL,				{ 0, 0, 0 } }
    236 };
    237 
    238 const struct tlp_pci_quirks tlp_pci_21142_quirks[] = {
    239 	{ tlp_pci_dec_quirks,		{ 0x08, 0x00, 0x2b } },
    240 	{ tlp_pci_dec_quirks,		{ 0x00, 0x00, 0xf8 } },
    241 	{ tlp_pci_cobalt_21142_quirks,	{ 0x00, 0x10, 0xe0 } },
    242 	{ tlp_pci_algor_21142_quirks,	{ 0x00, 0x40, 0xbc } },
    243 	{ tlp_pci_adaptec_quirks,	{ 0x00, 0x00, 0xd1 } },
    244 	{ NULL,				{ 0, 0, 0 } }
    245 };
    246 
    247 int	tlp_pci_shared_intr __P((void *));
    248 
    249 const struct tulip_pci_product *tlp_pci_lookup
    250     __P((const struct pci_attach_args *));
    251 void tlp_pci_get_quirks __P((struct tulip_pci_softc *, const u_int8_t *,
    252     const struct tlp_pci_quirks *));
    253 void tlp_pci_check_slaved __P((struct tulip_pci_softc *, int, int));
    254 
    255 const struct tulip_pci_product *
    256 tlp_pci_lookup(pa)
    257 	const struct pci_attach_args *pa;
    258 {
    259 	const struct tulip_pci_product *tpp;
    260 
    261 	for (tpp = tlp_pci_products;
    262 	     tlp_chip_names[tpp->tpp_chip] != NULL;
    263 	     tpp++) {
    264 		if (PCI_VENDOR(pa->pa_id) == tpp->tpp_vendor &&
    265 		    PCI_PRODUCT(pa->pa_id) == tpp->tpp_product)
    266 			return (tpp);
    267 	}
    268 	return (NULL);
    269 }
    270 
    271 void
    272 tlp_pci_get_quirks(psc, enaddr, tpq)
    273 	struct tulip_pci_softc *psc;
    274 	const u_int8_t *enaddr;
    275 	const struct tlp_pci_quirks *tpq;
    276 {
    277 
    278 	for (; tpq->tpq_func != NULL; tpq++) {
    279 		if (tpq->tpq_oui[0] == enaddr[0] &&
    280 		    tpq->tpq_oui[1] == enaddr[1] &&
    281 		    tpq->tpq_oui[2] == enaddr[2]) {
    282 			(*tpq->tpq_func)(psc, enaddr);
    283 			return;
    284 		}
    285 	}
    286 }
    287 
    288 void
    289 tlp_pci_check_slaved(psc, shared, slaved)
    290 	struct tulip_pci_softc *psc;
    291 	int shared, slaved;
    292 {
    293 	extern struct cfdriver tlp_cd;
    294 	struct tulip_pci_softc *cur, *best = NULL;
    295 	struct tulip_softc *sc = &psc->sc_tulip;
    296 	int i;
    297 
    298 	/*
    299 	 * First of all, find the lowest pcidev numbered device on our
    300 	 * bus marked as shared.  That should be our master.
    301 	 */
    302 	for (i = 0; i < tlp_cd.cd_ndevs; i++) {
    303 		if ((cur = tlp_cd.cd_devs[i]) == NULL)
    304 			continue;
    305 		if (cur->sc_tulip.sc_dev.dv_parent != sc->sc_dev.dv_parent)
    306 			continue;
    307 		if ((cur->sc_flags & shared) == 0)
    308 			continue;
    309 		if (cur == psc)
    310 			continue;
    311 		if (best == NULL ||
    312 		    best->sc_tulip.sc_devno > cur->sc_tulip.sc_devno)
    313 			best = cur;
    314 	}
    315 
    316 	if (best != NULL) {
    317 		psc->sc_master = best;
    318 		psc->sc_flags |= (shared | slaved);
    319 	}
    320 }
    321 
    322 int
    323 tlp_pci_match(parent, match, aux)
    324 	struct device *parent;
    325 	struct cfdata *match;
    326 	void *aux;
    327 {
    328 	struct pci_attach_args *pa = aux;
    329 
    330 	if (tlp_pci_lookup(pa) != NULL)
    331 		return (10);	/* beat if_de.c */
    332 
    333 	return (0);
    334 }
    335 
    336 void
    337 tlp_pci_attach(parent, self, aux)
    338 	struct device *parent, *self;
    339 	void *aux;
    340 {
    341 	struct tulip_pci_softc *psc = (void *) self;
    342 	struct tulip_softc *sc = &psc->sc_tulip;
    343 	struct pci_attach_args *pa = aux;
    344 	pci_chipset_tag_t pc = pa->pa_pc;
    345 	pci_intr_handle_t ih;
    346 	const char *intrstr = NULL;
    347 	bus_space_tag_t iot, memt;
    348 	bus_space_handle_t ioh, memh;
    349 	int ioh_valid, memh_valid, i, j;
    350 	const struct tulip_pci_product *tpp;
    351 	u_int8_t enaddr[ETHER_ADDR_LEN];
    352 	u_int32_t val;
    353 	pcireg_t reg;
    354 	int pmreg;
    355 
    356 	sc->sc_devno = pa->pa_device;
    357 	psc->sc_pc = pa->pa_pc;
    358 	psc->sc_pcitag = pa->pa_tag;
    359 
    360 	LIST_INIT(&psc->sc_intrslaves);
    361 
    362 	tpp = tlp_pci_lookup(pa);
    363 	if (tpp == NULL) {
    364 		printf("\n");
    365 		panic("tlp_pci_attach: impossible");
    366 	}
    367 	sc->sc_chip = tpp->tpp_chip;
    368 
    369 	/*
    370 	 * By default, Tulip registers are 8 bytes long (4 bytes
    371 	 * followed by a 4 byte pad).
    372 	 */
    373 	sc->sc_regshift = 3;
    374 
    375 	/*
    376 	 * No power management hooks.
    377 	 * XXX Maybe we should add some!
    378 	 */
    379 	sc->sc_flags |= TULIPF_ENABLED;
    380 
    381 	/*
    382 	 * Get revision info, and set some chip-specific variables.
    383 	 */
    384 	sc->sc_rev = PCI_REVISION(pa->pa_class);
    385 	switch (sc->sc_chip) {
    386 	case TULIP_CHIP_21140:
    387 		if (sc->sc_rev >= 0x20)
    388 			sc->sc_chip = TULIP_CHIP_21140A;
    389 		break;
    390 
    391 	case TULIP_CHIP_21142:
    392 		if (sc->sc_rev >= 0x20)
    393 			sc->sc_chip = TULIP_CHIP_21143;
    394 		break;
    395 
    396 	case TULIP_CHIP_82C168:
    397 		if (sc->sc_rev >= 0x20)
    398 			sc->sc_chip = TULIP_CHIP_82C169;
    399 		break;
    400 
    401 	case TULIP_CHIP_MX98713:
    402 		if (sc->sc_rev >= 0x10)
    403 			sc->sc_chip = TULIP_CHIP_MX98713A;
    404 		break;
    405 
    406 	case TULIP_CHIP_MX98715:
    407 		if (sc->sc_rev >= 0x20)
    408 			sc->sc_chip = TULIP_CHIP_MX98715A;
    409  		if (sc->sc_rev >= 0x25)
    410  			sc->sc_chip = TULIP_CHIP_MX98715AEC_X;
    411 		if (sc->sc_rev >= 0x30)
    412 			sc->sc_chip = TULIP_CHIP_MX98725;
    413 		break;
    414 
    415 	case TULIP_CHIP_WB89C840F:
    416 		sc->sc_regshift = 2;
    417 		break;
    418 
    419 	case TULIP_CHIP_AN985:
    420 		/*
    421 		 * The AN983 and AN985 are very similar, and are
    422 		 * differentiated by a "signature" register that
    423 		 * is like, but not identical, to a PCI ID register.
    424 		 */
    425 		reg = pci_conf_read(pc, pa->pa_tag, 0x80);
    426 		switch (reg) {
    427 		case 0x09811317:
    428 			sc->sc_chip = TULIP_CHIP_AN985;
    429 			break;
    430 
    431 		case 0x09851317:
    432 			sc->sc_chip = TULIP_CHIP_AN983;
    433 			break;
    434 
    435 		default:
    436 			/* Unknown -- use default. */
    437 			break;
    438 		}
    439 		break;
    440 
    441 	case TULIP_CHIP_AX88140:
    442 		if (sc->sc_rev >= 0x10)
    443 			sc->sc_chip = TULIP_CHIP_AX88141;
    444 		break;
    445 
    446 	case TULIP_CHIP_DM9102:
    447 		if (sc->sc_rev >= 0x30)
    448 			sc->sc_chip = TULIP_CHIP_DM9102A;
    449 		break;
    450 
    451 	default:
    452 		/* Nothing. */
    453 		break;
    454 	}
    455 
    456 	printf(": %s Ethernet, pass %d.%d\n",
    457 	    tlp_chip_names[sc->sc_chip],
    458 	    (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
    459 
    460 	switch (sc->sc_chip) {
    461 	case TULIP_CHIP_21040:
    462 		if (sc->sc_rev < 0x20) {
    463 			printf("%s: 21040 must be at least pass 2.0\n",
    464 			    sc->sc_dev.dv_xname);
    465 			return;
    466 		}
    467 		break;
    468 
    469 	case TULIP_CHIP_21140:
    470 		if (sc->sc_rev < 0x11) {
    471 			printf("%s: 21140 must be at least pass 1.1\n",
    472 			    sc->sc_dev.dv_xname);
    473 			return;
    474 		}
    475 		break;
    476 
    477 	default:
    478 		/* Nothing. */
    479 		break;
    480 	}
    481 
    482 	/*
    483 	 * Check to see if the device is in power-save mode, and
    484 	 * being it out if necessary.
    485 	 */
    486 	switch (sc->sc_chip) {
    487 	case TULIP_CHIP_21140:
    488 	case TULIP_CHIP_21140A:
    489 	case TULIP_CHIP_21142:
    490 	case TULIP_CHIP_21143:
    491 	case TULIP_CHIP_MX98713A:
    492 	case TULIP_CHIP_MX98715:
    493 	case TULIP_CHIP_MX98715A:
    494 	case TULIP_CHIP_MX98715AEC_X:
    495 	case TULIP_CHIP_MX98725:
    496 	case TULIP_CHIP_DM9102:
    497 	case TULIP_CHIP_DM9102A:
    498 		/*
    499 		 * Clear the "sleep mode" bit in the CFDA register.
    500 		 */
    501 		reg = pci_conf_read(pc, pa->pa_tag, TULIP_PCI_CFDA);
    502 		if (reg & (CFDA_SLEEP|CFDA_SNOOZE))
    503 			pci_conf_write(pc, pa->pa_tag, TULIP_PCI_CFDA,
    504 			    reg & ~(CFDA_SLEEP|CFDA_SNOOZE));
    505 		break;
    506 
    507 	default:
    508 		/* Nothing. */
    509 		break;
    510 	}
    511 
    512 	if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PWRMGMT, &pmreg, 0)) {
    513 		reg = pci_conf_read(pc, pa->pa_tag, pmreg + 4);
    514 		switch (reg & PCI_PMCSR_STATE_MASK) {
    515 		case PCI_PMCSR_STATE_D1:
    516 		case PCI_PMCSR_STATE_D2:
    517 			printf(": waking up from power state D%d\n%s",
    518 			    reg & PCI_PMCSR_STATE_MASK, sc->sc_dev.dv_xname);
    519 			pci_conf_write(pc, pa->pa_tag, pmreg + 4,
    520 			    (reg & ~PCI_PMCSR_STATE_MASK) |
    521 			    PCI_PMCSR_STATE_D0);
    522 			break;
    523 		case PCI_PMCSR_STATE_D3:
    524 			/*
    525 			 * The card has lost all configuration data in
    526 			 * this state, so punt.
    527 			 */
    528 			printf(": unable to wake up from power state D3, "
    529 			       "reboot required.\n");
    530 			pci_conf_write(pc, pa->pa_tag, pmreg + 4,
    531 			    (reg & ~PCI_PMCSR_STATE_MASK) |
    532 			    PCI_PMCSR_STATE_D0);
    533 			return;
    534 		}
    535 	}
    536 
    537 	/*
    538 	 * Map the device.
    539 	 */
    540 	ioh_valid = (pci_mapreg_map(pa, TULIP_PCI_IOBA,
    541 	    PCI_MAPREG_TYPE_IO, 0,
    542 	    &iot, &ioh, NULL, NULL) == 0);
    543 	memh_valid = (pci_mapreg_map(pa, TULIP_PCI_MMBA,
    544 	    PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
    545 	    &memt, &memh, NULL, NULL) == 0);
    546 
    547 	if (memh_valid) {
    548 		sc->sc_st = memt;
    549 		sc->sc_sh = memh;
    550 	} else if (ioh_valid) {
    551 		sc->sc_st = iot;
    552 		sc->sc_sh = ioh;
    553 	} else {
    554 		printf(": unable to map device registers\n");
    555 		return;
    556 	}
    557 
    558 	sc->sc_dmat = pa->pa_dmat;
    559 
    560 	/*
    561 	 * Make sure bus mastering is enabled.
    562 	 */
    563 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    564 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
    565 	    PCI_COMMAND_MASTER_ENABLE);
    566 
    567 	/*
    568 	 * Get the cacheline size.
    569 	 */
    570 	sc->sc_cacheline = PCI_CACHELINE(pci_conf_read(pc, pa->pa_tag,
    571 	    PCI_BHLC_REG));
    572 
    573 	/*
    574 	 * Get PCI data moving command info.
    575 	 */
    576 	if (pa->pa_flags & PCI_FLAGS_MRL_OKAY)
    577 		sc->sc_flags |= TULIPF_MRL;
    578 	if (pa->pa_flags & PCI_FLAGS_MRM_OKAY)
    579 		sc->sc_flags |= TULIPF_MRM;
    580 	if (pa->pa_flags & PCI_FLAGS_MWI_OKAY)
    581 		sc->sc_flags |= TULIPF_MWI;
    582 
    583 	/*
    584 	 * Read the contents of the Ethernet Address ROM/SROM.
    585 	 */
    586 	switch (sc->sc_chip) {
    587 	case TULIP_CHIP_21040:
    588 		sc->sc_srom_addrbits = 6;
    589 		sc->sc_srom = malloc(TULIP_ROM_SIZE(6), M_DEVBUF, M_NOWAIT);
    590 		TULIP_WRITE(sc, CSR_MIIROM, MIIROM_SROMCS);
    591 		for (i = 0; i < TULIP_ROM_SIZE(6); i++) {
    592 			for (j = 0; j < 10000; j++) {
    593 				val = TULIP_READ(sc, CSR_MIIROM);
    594 				if ((val & MIIROM_DN) == 0)
    595 					break;
    596 			}
    597 			sc->sc_srom[i] = val & MIIROM_DATA;
    598 		}
    599 		break;
    600 
    601 	case TULIP_CHIP_82C168:
    602 	case TULIP_CHIP_82C169:
    603 	    {
    604 		sc->sc_srom_addrbits = 2;
    605 		sc->sc_srom = malloc(TULIP_ROM_SIZE(2), M_DEVBUF, M_NOWAIT);
    606 
    607 		/*
    608 		 * The Lite-On PNIC stores the Ethernet address in
    609 		 * the first 3 words of the EEPROM.  EEPROM access
    610 		 * is not like the other Tulip chips.
    611 		 */
    612 		for (i = 0; i < 6; i += 2) {
    613 			TULIP_WRITE(sc, CSR_PNIC_SROMCTL,
    614 			    PNIC_SROMCTL_READ | (i >> 1));
    615 			for (j = 0; j < 500; j++) {
    616 				delay(2);
    617 				val = TULIP_READ(sc, CSR_MIIROM);
    618 				if ((val & PNIC_MIIROM_BUSY) == 0)
    619 					break;
    620 			}
    621 			if (val & PNIC_MIIROM_BUSY) {
    622 				printf("%s: EEPROM timed out\n",
    623 				    sc->sc_dev.dv_xname);
    624 				return;
    625 			}
    626 			val &= PNIC_MIIROM_DATA;
    627 			sc->sc_srom[i] = val >> 8;
    628 			sc->sc_srom[i + 1] = val & 0xff;
    629 		}
    630 		break;
    631 	    }
    632 
    633 	default:
    634 #ifdef algor
    635 		/*
    636 		 * XXX This should be done with device properties, but
    637 		 * XXX we don't have those yet.
    638 		 */
    639 		if (algor_get_ethaddr(pa, NULL)) {
    640 			extern int tlp_srom_debug;
    641 			sc->sc_srom_addrbits = 6;
    642 			sc->sc_srom = malloc(TULIP_ROM_SIZE(6), M_DEVBUF,
    643 			    M_NOWAIT|M_ZERO);
    644 			algor_get_ethaddr(pa, sc->sc_srom);
    645 			if (tlp_srom_debug) {
    646 				printf("SROM CONTENTS:");
    647 				for (i = 0; i < TULIP_ROM_SIZE(6); i++) {
    648 					if ((i % 8) == 0)
    649 						printf("\n\t");
    650 					printf("0x%02x ", sc->sc_srom[i]);
    651 				}
    652 				printf("\n");
    653 			}
    654 			break;
    655 		}
    656 #endif /* algor */
    657 
    658 		/* Check for a slaved ROM on a multi-port board. */
    659 		tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDROM,
    660 		    TULIP_PCI_SLAVEROM);
    661 		if (psc->sc_flags & TULIP_PCI_SLAVEROM) {
    662 			sc->sc_srom_addrbits =
    663 			    psc->sc_master->sc_tulip.sc_srom_addrbits;
    664 			sc->sc_srom = psc->sc_master->sc_tulip.sc_srom;
    665 			enaddr[5] +=
    666 			    sc->sc_devno - psc->sc_master->sc_tulip.sc_devno;
    667 		}
    668 		else if (tlp_read_srom(sc) == 0)
    669 			goto cant_cope;
    670 		break;
    671 	}
    672 
    673 	/*
    674 	 * Deal with chip/board quirks.  This includes setting up
    675 	 * the mediasw, and extracting the Ethernet address from
    676 	 * the rombuf.
    677 	 */
    678 	switch (sc->sc_chip) {
    679 	case TULIP_CHIP_21040:
    680 		/*
    681 		 * Parse the Ethernet Address ROM.
    682 		 */
    683 		if (tlp_parse_old_srom(sc, enaddr) == 0)
    684 			goto cant_cope;
    685 
    686 
    687 		/*
    688 		 * All 21040 boards start out with the same
    689 		 * media switch.
    690 		 */
    691 		sc->sc_mediasw = &tlp_21040_mediasw;
    692 
    693 		/*
    694 		 * Deal with any quirks this board might have.
    695 		 */
    696 		tlp_pci_get_quirks(psc, enaddr, tlp_pci_21040_quirks);
    697 		break;
    698 
    699 	case TULIP_CHIP_21041:
    700 		/* Check for new format SROM. */
    701 		if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
    702 			/*
    703 			 * Not an ISV SROM; try the old DEC Ethernet Address
    704 			 * ROM format.
    705 			 */
    706 			if (tlp_parse_old_srom(sc, enaddr) == 0)
    707 				goto cant_cope;
    708 		}
    709 
    710 		/*
    711 		 * All 21041 boards use the same media switch; they all
    712 		 * work basically the same!  Yippee!
    713 		 */
    714 		sc->sc_mediasw = &tlp_21041_mediasw;
    715 
    716 		/*
    717 		 * Deal with any quirks this board might have.
    718 		 */
    719 		tlp_pci_get_quirks(psc, enaddr, tlp_pci_21041_quirks);
    720 		break;
    721 
    722 	case TULIP_CHIP_21140:
    723 	case TULIP_CHIP_21140A:
    724 		/* Check for new format SROM. */
    725 		if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
    726 			/*
    727 			 * Not an ISV SROM; try the old DEC Ethernet Address
    728 			 * ROM format.
    729 			 */
    730 			if (tlp_parse_old_srom(sc, enaddr) == 0)
    731 				goto cant_cope;
    732 		} else {
    733 			/*
    734 			 * We start out with the 2114x ISV media switch.
    735 			 * When we search for quirks, we may change to
    736 			 * a different switch.
    737 			 */
    738 			sc->sc_mediasw = &tlp_2114x_isv_mediasw;
    739 		}
    740 
    741 		/*
    742 		 * Deal with any quirks this board might have.
    743 		 */
    744 		tlp_pci_get_quirks(psc, enaddr, tlp_pci_21140_quirks);
    745 
    746 		/*
    747 		 * Bail out now if we can't deal with this board.
    748 		 */
    749 		if (sc->sc_mediasw == NULL)
    750 			goto cant_cope;
    751 		break;
    752 
    753 	case TULIP_CHIP_21142:
    754 	case TULIP_CHIP_21143:
    755 		/* Check for new format SROM. */
    756 		if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
    757 			/*
    758 			 * Not an ISV SROM; try the old DEC Ethernet Address
    759 			 * ROM format.
    760 			 */
    761 			if (tlp_parse_old_srom(sc, enaddr) == 0)
    762 				goto cant_cope;
    763 		} else {
    764 			/*
    765 			 * We start out with the 2114x ISV media switch.
    766 			 * When we search for quirks, we may change to
    767 			 * a different switch.
    768 			 */
    769 			sc->sc_mediasw = &tlp_2114x_isv_mediasw;
    770 		}
    771 
    772 		/*
    773 		 * Deal with any quirks this board might have.
    774 		 */
    775 		tlp_pci_get_quirks(psc, enaddr, tlp_pci_21142_quirks);
    776 
    777 		/*
    778 		 * Bail out now if we can't deal with this board.
    779 		 */
    780 		if (sc->sc_mediasw == NULL)
    781 			goto cant_cope;
    782 		break;
    783 
    784 	case TULIP_CHIP_82C168:
    785 	case TULIP_CHIP_82C169:
    786 		/*
    787 		 * Lite-On PNIC's Ethernet address is the first 6
    788 		 * bytes of its EEPROM.
    789 		 */
    790 		memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
    791 
    792 		/*
    793 		 * Lite-On PNICs always use the same mediasw; we
    794 		 * select MII vs. internal NWAY automatically.
    795 		 */
    796 		sc->sc_mediasw = &tlp_pnic_mediasw;
    797 		break;
    798 
    799 	case TULIP_CHIP_MX98713:
    800 		/*
    801 		 * The Macronix MX98713 has an MII and GPIO, but no
    802 		 * internal Nway block.  This chip is basically a
    803 		 * perfect 21140A clone, with the exception of the
    804 		 * a magic register frobbing in order to make the
    805 		 * interface function.
    806 		 */
    807 		if (tlp_isv_srom_enaddr(sc, enaddr)) {
    808 			sc->sc_mediasw = &tlp_2114x_isv_mediasw;
    809 			break;
    810 		}
    811 		/* FALLTHROUGH */
    812 
    813 	case TULIP_CHIP_82C115:
    814 		/*
    815 		 * Yippee!  The Lite-On 82C115 is a clone of
    816 		 * the MX98725 (the data sheet even says `MXIC'
    817 		 * on it)!  Imagine that, a clone of a clone.
    818 		 *
    819 		 * The differences are really minimal:
    820 		 *
    821 		 *	- Wake-On-LAN support
    822 		 *	- 128-bit multicast hash table, rather than
    823 		 *	  the standard 512-bit hash table
    824 		 */
    825 		/* FALLTHROUGH */
    826 
    827 	case TULIP_CHIP_MX98713A:
    828 	case TULIP_CHIP_MX98715A:
    829 	case TULIP_CHIP_MX98715AEC_X:
    830 	case TULIP_CHIP_MX98725:
    831 		/*
    832 		 * The MX98713A has an MII as well as an internal Nway block,
    833 		 * but no GPIO.  The MX98715 and MX98725 have an internal
    834 		 * Nway block only.
    835 		 *
    836 		 * The internal Nway block, unlike the Lite-On PNIC's, does
    837 		 * just that - performs Nway.  Once autonegotiation completes,
    838 		 * we must program the GPR media information into the chip.
    839 		 *
    840 		 * The byte offset of the Ethernet address is stored at
    841 		 * offset 0x70.
    842 		 */
    843 		memcpy(enaddr, &sc->sc_srom[sc->sc_srom[0x70]], ETHER_ADDR_LEN);
    844 		sc->sc_mediasw = &tlp_pmac_mediasw;
    845 		break;
    846 
    847 	case TULIP_CHIP_WB89C840F:
    848 		/*
    849 		 * Winbond 89C840F's Ethernet address is the first
    850 		 * 6 bytes of its EEPROM.
    851 		 */
    852 		memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
    853 
    854 		/*
    855 		 * Winbond 89C840F has an MII attached to the SIO.
    856 		 */
    857 		sc->sc_mediasw = &tlp_sio_mii_mediasw;
    858 		break;
    859 
    860 	case TULIP_CHIP_AL981:
    861 		/*
    862 		 * The ADMtek AL981's Ethernet address is located
    863 		 * at offset 8 of its EEPROM.
    864 		 */
    865 		memcpy(enaddr, &sc->sc_srom[8], ETHER_ADDR_LEN);
    866 
    867 		/*
    868 		 * ADMtek AL981 has a built-in PHY accessed through
    869 		 * special registers.
    870 		 */
    871 		sc->sc_mediasw = &tlp_al981_mediasw;
    872 		break;
    873 
    874 	case TULIP_CHIP_AN983:
    875 	case TULIP_CHIP_AN985:
    876 		/*
    877 		 * The ADMtek AN985's Ethernet address is located
    878 		 * at offset 8 of its EEPROM.
    879 		 */
    880 		memcpy(enaddr, &sc->sc_srom[8], ETHER_ADDR_LEN);
    881 
    882 		/*
    883 		 * The ADMtek AN985 can be configured in Single-Chip
    884 		 * mode or MAC-only mode.  Single-Chip uses the built-in
    885 		 * PHY, MAC-only has an external PHY (usually HomePNA).
    886 		 * The selection is based on an EEPROM setting, and both
    887 		 * PHYs are accessed via MII attached to SIO.
    888 		 *
    889 		 * The AN985 "ghosts" the internal PHY onto all
    890 		 * MII addresses, so we have to use a media init
    891 		 * routine that limits the search.
    892 		 * XXX How does this work with MAC-only mode?
    893 		 */
    894 		sc->sc_mediasw = &tlp_an985_mediasw;
    895 		break;
    896 
    897 	case TULIP_CHIP_DM9102:
    898 	case TULIP_CHIP_DM9102A:
    899 		/*
    900 		 * Some boards with the Davicom chip have an ISV
    901 		 * SROM (mostly DM9102A boards -- trying to describe
    902 		 * the HomePNA PHY, probably) although the data in
    903 		 * them is generally wrong.  Check for ISV format
    904 		 * and grab the Ethernet address that way, and if
    905 		 * that fails, fall back on grabbing it from an
    906 		 * observed offset of 20 (which is where it would
    907 		 * be in an ISV SROM anyhow, tho ISV can cope with
    908 		 * multi-port boards).
    909 		 */
    910 		if (!tlp_isv_srom_enaddr(sc, enaddr)) {
    911 #ifdef __sparc__
    912 			if (!sc->sc_srom[20] && !sc->sc_srom[21] &&
    913 			    !sc->sc_srom[22]) {
    914 				extern void myetheraddr __P((u_char *));
    915 				myetheraddr(enaddr);
    916 			} else
    917 #endif
    918 			memcpy(enaddr, &sc->sc_srom[20], ETHER_ADDR_LEN);
    919 		}
    920 
    921 		/*
    922 		 * Davicom chips all have an internal MII interface
    923 		 * and a built-in PHY.  DM9102A also has a an external
    924 		 * MII interface, usually with a HomePNA PHY attached
    925 		 * to it.
    926 		 */
    927 		sc->sc_mediasw = &tlp_dm9102_mediasw;
    928 		break;
    929 
    930 	default:
    931  cant_cope:
    932 		printf("%s: sorry, unable to handle your board\n",
    933 		    sc->sc_dev.dv_xname);
    934 		return;
    935 	}
    936 
    937 	/*
    938 	 * Handle shared interrupts.
    939 	 */
    940 	if (psc->sc_flags & TULIP_PCI_SHAREDINTR) {
    941 		if (psc->sc_master)
    942 			psc->sc_flags |= TULIP_PCI_SLAVEINTR;
    943 		else {
    944 			tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDINTR,
    945 			    TULIP_PCI_SLAVEINTR);
    946 			if (psc->sc_master == NULL)
    947 				psc->sc_master = psc;
    948 		}
    949 		LIST_INSERT_HEAD(&psc->sc_master->sc_intrslaves,
    950 		    psc, sc_intrq);
    951 	}
    952 
    953 	if (psc->sc_flags & TULIP_PCI_SLAVEINTR) {
    954 		printf("%s: sharing interrupt with %s\n",
    955 		    sc->sc_dev.dv_xname,
    956 		    psc->sc_master->sc_tulip.sc_dev.dv_xname);
    957 	} else {
    958 		/*
    959 		 * Map and establish our interrupt.
    960 		 */
    961 		if (pci_intr_map(pa, &ih)) {
    962 			printf("%s: unable to map interrupt\n",
    963 			    sc->sc_dev.dv_xname);
    964 			return;
    965 		}
    966 		intrstr = pci_intr_string(pc, ih);
    967 		psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET,
    968 		    (psc->sc_flags & TULIP_PCI_SHAREDINTR) ?
    969 		    tlp_pci_shared_intr : tlp_intr, sc);
    970 		if (psc->sc_ih == NULL) {
    971 			printf("%s: unable to establish interrupt",
    972 			    sc->sc_dev.dv_xname);
    973 			if (intrstr != NULL)
    974 				printf(" at %s", intrstr);
    975 			printf("\n");
    976 			return;
    977 		}
    978 		printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
    979 		    intrstr);
    980 	}
    981 
    982 	/*
    983 	 * Finish off the attach.
    984 	 */
    985 	tlp_attach(sc, enaddr);
    986 }
    987 
    988 int
    989 tlp_pci_shared_intr(arg)
    990 	void *arg;
    991 {
    992 	struct tulip_pci_softc *master = arg, *slave;
    993 	int rv = 0;
    994 
    995 	for (slave = LIST_FIRST(&master->sc_intrslaves);
    996 	     slave != NULL;
    997 	     slave = LIST_NEXT(slave, sc_intrq))
    998 		rv |= tlp_intr(&slave->sc_tulip);
    999 
   1000 	return (rv);
   1001 }
   1002 
   1003 void
   1004 tlp_pci_dec_quirks(psc, enaddr)
   1005 	struct tulip_pci_softc *psc;
   1006 	const u_int8_t *enaddr;
   1007 {
   1008 	struct tulip_softc *sc = &psc->sc_tulip;
   1009 
   1010 	/*
   1011 	 * This isn't really a quirk-gathering device, really.  We
   1012 	 * just want to get the spiffy DEC board name from the SROM.
   1013 	 */
   1014 	strcpy(sc->sc_name, "DEC ");
   1015 
   1016 	if (memcmp(&sc->sc_srom[29], "DE500", 5) == 0 ||
   1017 	    memcmp(&sc->sc_srom[29], "DE450", 5) == 0)
   1018 		memcpy(&sc->sc_name[4], &sc->sc_srom[29], 8);
   1019 }
   1020 
   1021 void
   1022 tlp_pci_znyx_21040_quirks(psc, enaddr)
   1023 	struct tulip_pci_softc *psc;
   1024 	const u_int8_t *enaddr;
   1025 {
   1026 	struct tulip_softc *sc = &psc->sc_tulip;
   1027 	u_int16_t id = 0;
   1028 
   1029 	/*
   1030 	 * If we have a slaved ROM, just copy the bits from the master.
   1031 	 * This is in case we fail the ROM ID check (older boards) and
   1032 	 * need to fall back on Ethernet address model checking; that
   1033 	 * will fail for slave chips.
   1034 	 */
   1035 	if (psc->sc_flags & TULIP_PCI_SLAVEROM) {
   1036 		strcpy(sc->sc_name, psc->sc_master->sc_tulip.sc_name);
   1037 		sc->sc_mediasw = psc->sc_master->sc_tulip.sc_mediasw;
   1038 		psc->sc_flags |=
   1039 		    psc->sc_master->sc_flags & TULIP_PCI_SHAREDINTR;
   1040 		return;
   1041 	}
   1042 
   1043 	if (sc->sc_srom[32] == 0x4a && sc->sc_srom[33] == 0x52) {
   1044 		id = sc->sc_srom[37] | (sc->sc_srom[36] << 8);
   1045 		switch (id) {
   1046  zx312:
   1047 		case 0x0602:	/* ZX312 */
   1048 			strcpy(sc->sc_name, "ZNYX ZX312");
   1049 			return;
   1050 
   1051 		case 0x0622:	/* ZX312T */
   1052 			strcpy(sc->sc_name, "ZNYX ZX312T");
   1053 			sc->sc_mediasw = &tlp_21040_tp_mediasw;
   1054 			return;
   1055 
   1056  zx314_inta:
   1057 		case 0x0701:	/* ZX314 INTA */
   1058 			psc->sc_flags |= TULIP_PCI_SHAREDINTR;
   1059 			/* FALLTHROUGH */
   1060 		case 0x0711:	/* ZX314 */
   1061 			strcpy(sc->sc_name, "ZNYX ZX314");
   1062 			psc->sc_flags |= TULIP_PCI_SHAREDROM;
   1063 			sc->sc_mediasw = &tlp_21040_tp_mediasw;
   1064 			return;
   1065 
   1066  zx315_inta:
   1067 		case 0x0801:	/* ZX315 INTA */
   1068 			psc->sc_flags |= TULIP_PCI_SHAREDINTR;
   1069 			/* FALLTHROUGH */
   1070 		case 0x0811:	/* ZX315 */
   1071 			strcpy(sc->sc_name, "ZNYX ZX315");
   1072 			psc->sc_flags |= TULIP_PCI_SHAREDROM;
   1073 			return;
   1074 
   1075 		default:
   1076 			id = 0;
   1077 			break;
   1078 		}
   1079 	}
   1080 
   1081 	/*
   1082 	 * Deal with boards that have broken ROMs.
   1083 	 */
   1084 	if (id == 0) {
   1085 		if ((enaddr[3] & ~3) == 0xf0 && (enaddr[5] & 3) == 0x00)
   1086 			goto zx314_inta;
   1087 		if ((enaddr[3] & ~3) == 0xf4 && (enaddr[5] & 1) == 0x00)
   1088 			goto zx315_inta;
   1089 		if ((enaddr[3] & ~3) == 0xec)
   1090 			goto zx312;
   1091 	}
   1092 
   1093 	strcpy(sc->sc_name, "ZNYX ZX31x");
   1094 }
   1095 
   1096 void
   1097 tlp_pci_smc_21040_quirks(psc, enaddr)
   1098 	struct tulip_pci_softc *psc;
   1099 	const u_int8_t *enaddr;
   1100 {
   1101 	struct tulip_softc *sc = &psc->sc_tulip;
   1102 	u_int16_t id1, id2, ei;
   1103 	int auibnc = 0, utp = 0;
   1104 	char *cp;
   1105 
   1106 	id1 = sc->sc_srom[0x60] | (sc->sc_srom[0x61] << 8);
   1107 	id2 = sc->sc_srom[0x62] | (sc->sc_srom[0x63] << 8);
   1108 	ei  = sc->sc_srom[0x66] | (sc->sc_srom[0x67] << 8);
   1109 
   1110 	strcpy(sc->sc_name, "SMC 8432");
   1111 	cp = &sc->sc_name[8];
   1112 
   1113 	if ((id1 & 1) == 0) {
   1114 		*cp++ = 'B';
   1115 		auibnc = 1;
   1116 	}
   1117 	if ((id1 & 0xff) > 0x32) {
   1118 		*cp++ = 'T';
   1119 		utp = 1;
   1120 	}
   1121 	if ((id1 & 0x4000) == 0) {
   1122 		*cp++ = 'A';
   1123 		auibnc = 1;
   1124 	}
   1125 	if (id2 == 0x15) {
   1126 		sc->sc_name[7] = '4';
   1127 		*cp++ = '-';
   1128 		*cp++ = 'C';
   1129 		*cp++ = 'H';
   1130 		*cp++ = ei ? '2' : '1';
   1131 	}
   1132 	*cp = '\0';
   1133 
   1134 	if (utp != 0 && auibnc == 0)
   1135 		sc->sc_mediasw = &tlp_21040_tp_mediasw;
   1136 	else if (utp == 0 && auibnc != 0)
   1137 		sc->sc_mediasw = &tlp_21040_auibnc_mediasw;
   1138 }
   1139 
   1140 void
   1141 tlp_pci_cogent_21040_quirks(psc, enaddr)
   1142 	struct tulip_pci_softc *psc;
   1143 	const u_int8_t *enaddr;
   1144 {
   1145 
   1146 	strcpy(psc->sc_tulip.sc_name, "Cogent multi-port");
   1147 	psc->sc_flags |= TULIP_PCI_SHAREDINTR|TULIP_PCI_SHAREDROM;
   1148 }
   1149 
   1150 void
   1151 tlp_pci_accton_21040_quirks(psc, enaddr)
   1152 	struct tulip_pci_softc *psc;
   1153 	const u_int8_t *enaddr;
   1154 {
   1155 
   1156 	strcpy(psc->sc_tulip.sc_name, "ACCTON EN1203");
   1157 }
   1158 
   1159 void	tlp_pci_asante_21140_reset __P((struct tulip_softc *));
   1160 
   1161 void
   1162 tlp_pci_asante_21140_quirks(psc, enaddr)
   1163 	struct tulip_pci_softc *psc;
   1164 	const u_int8_t *enaddr;
   1165 {
   1166 	struct tulip_softc *sc = &psc->sc_tulip;
   1167 
   1168 	/*
   1169 	 * Some Asante boards don't use the ISV SROM format.  For
   1170 	 * those that don't, we initialize the GPIO direction bits,
   1171 	 * and provide our own reset hook, which resets the MII.
   1172 	 *
   1173 	 * All of these boards use SIO-attached-MII media.
   1174 	 */
   1175 	if (sc->sc_mediasw == &tlp_2114x_isv_mediasw)
   1176 		return;
   1177 
   1178 	strcpy(sc->sc_name, "Asante");
   1179 
   1180 	sc->sc_gp_dir = 0xbf;
   1181 	sc->sc_reset = tlp_pci_asante_21140_reset;
   1182 	sc->sc_mediasw = &tlp_sio_mii_mediasw;
   1183 }
   1184 
   1185 void
   1186 tlp_pci_asante_21140_reset(sc)
   1187 	struct tulip_softc *sc;
   1188 {
   1189 
   1190 	TULIP_WRITE(sc, CSR_GPP, GPP_GPC | sc->sc_gp_dir);
   1191 	TULIP_WRITE(sc, CSR_GPP, 0x8);
   1192 	delay(100);
   1193 	TULIP_WRITE(sc, CSR_GPP, 0);
   1194 }
   1195 
   1196 void	tlp_pci_cobalt_21142_reset __P((struct tulip_softc *));
   1197 
   1198 void
   1199 tlp_pci_cobalt_21142_quirks(psc, enaddr)
   1200 	struct tulip_pci_softc *psc;
   1201 	const u_int8_t *enaddr;
   1202 {
   1203 	struct tulip_softc *sc = &psc->sc_tulip;
   1204 
   1205 	/*
   1206 	 * Cobalt Networks interfaces are just MII-on-SIO.
   1207 	 */
   1208 	sc->sc_reset = tlp_pci_cobalt_21142_reset;
   1209 	sc->sc_mediasw = &tlp_sio_mii_mediasw;
   1210 
   1211 	/*
   1212 	 * The Cobalt systems tend to fall back to store-and-forward
   1213 	 * pretty quickly, so we select that from the beginning to
   1214 	 * avoid initial timeouts.
   1215 	 */
   1216 	sc->sc_txthresh = TXTH_SF;
   1217 }
   1218 
   1219 void
   1220 tlp_pci_cobalt_21142_reset(sc)
   1221 	struct tulip_softc *sc;
   1222 {
   1223 	/*
   1224 	 * Reset PHY.
   1225 	 */
   1226 	TULIP_WRITE(sc, CSR_SIAGEN, SIAGEN_CWE | (1 << 16));
   1227 	delay(10);
   1228 	TULIP_WRITE(sc, CSR_SIAGEN, SIAGEN_CWE);
   1229 	delay(10);
   1230 }
   1231 
   1232 void
   1233 tlp_pci_algor_21142_quirks(psc, enaddr)
   1234 	struct tulip_pci_softc *psc;
   1235 	const u_int8_t *enaddr;
   1236 {
   1237 	struct tulip_softc *sc = &psc->sc_tulip;
   1238 
   1239 	/*
   1240 	 * Algorithmics boards just have MII-on-SIO.
   1241 	 *
   1242 	 * XXX They also have AUI on the serial interface.
   1243 	 * XXX Deal with this.
   1244 	 */
   1245 	sc->sc_mediasw = &tlp_sio_mii_mediasw;
   1246 }
   1247 
   1248 void
   1249 tlp_pci_adaptec_quirks(psc, enaddr)
   1250 	struct tulip_pci_softc *psc;
   1251 	const u_int8_t *enaddr;
   1252 {
   1253 	struct tulip_softc *sc = &psc->sc_tulip;
   1254 	uint8_t *srom = sc->sc_srom;
   1255 	uint16_t id1, id2;
   1256 
   1257 	id1 = TULIP_ROM_GETW(srom, 0);
   1258 	id2 = TULIP_ROM_GETW(srom, 2);
   1259 	if (id1 != 0x1109) {
   1260 		goto unknown;
   1261 	}
   1262 
   1263 	switch (id2) {
   1264 	case 0x1900:
   1265 		strcpy(psc->sc_tulip.sc_name, "Adaptec ANA-6911");
   1266 		break;
   1267 
   1268 	case 0x2400:
   1269 		strcpy(psc->sc_tulip.sc_name, "Adaptec ANA-6944A");
   1270 		psc->sc_flags |= TULIP_PCI_SHAREDINTR|TULIP_PCI_SHAREDROM;
   1271 		break;
   1272 
   1273 	case 0x2b00:
   1274 		strcpy(psc->sc_tulip.sc_name, "Adaptec ANA-6911A");
   1275 		break;
   1276 
   1277 	case 0x3000:
   1278 		strcpy(psc->sc_tulip.sc_name, "Adaptec ANA-6922");
   1279 		psc->sc_flags |= TULIP_PCI_SHAREDINTR|TULIP_PCI_SHAREDROM;
   1280 		break;
   1281 
   1282 	default:
   1283 unknown:
   1284 		printf("%s: unknown Adaptec/Cogent board ID 0x%04x/0x%04x\n",
   1285 		    sc->sc_dev.dv_xname, id1, id2);
   1286 	}
   1287 }
   1288