Home | History | Annotate | Line # | Download | only in pci
if_tlp_pci.c revision 1.8
      1 /*	$NetBSD: if_tlp_pci.c,v 1.8 1999/09/14 22:25:49 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 
     96 struct tulip_pci_softc {
     97 	struct tulip_softc sc_tulip;	/* real Tulip softc */
     98 
     99 	/* PCI-specific goo. */
    100 	void	*sc_ih;			/* interrupt handle */
    101 
    102 	pci_chipset_tag_t sc_pc;	/* our PCI chipset */
    103 	pcitag_t sc_pcitag;		/* our PCI tag */
    104 
    105 	int	sc_pcidev;		/* PCI device number */
    106 
    107 	int	sc_flags;		/* flags; see below */
    108 
    109 	LIST_HEAD(, tulip_pci_softc) sc_intrslaves;
    110 	LIST_ENTRY(tulip_pci_softc) sc_intrq;
    111 
    112 	/* Our {ROM,interrupt} master. */
    113 	struct tulip_pci_softc *sc_master;
    114 };
    115 
    116 /* sc_flags */
    117 #define	TULIP_PCI_SHAREDINTR	0x01	/* interrupt is shared */
    118 #define	TULIP_PCI_SLAVEINTR	0x02	/* interrupt is slave */
    119 #define	TULIP_PCI_SHAREDROM	0x04	/* ROM is shared */
    120 #define	TULIP_PCI_SLAVEROM	0x08	/* slave of shared ROM */
    121 
    122 int	tlp_pci_match __P((struct device *, struct cfdata *, void *));
    123 void	tlp_pci_attach __P((struct device *, struct device *, void *));
    124 
    125 struct cfattach tlp_pci_ca = {
    126 	sizeof(struct tulip_pci_softc), tlp_pci_match, tlp_pci_attach,
    127 };
    128 
    129 const struct tulip_pci_product {
    130 	u_int32_t	tpp_vendor;	/* PCI vendor ID */
    131 	u_int32_t	tpp_product;	/* PCI product ID */
    132 	tulip_chip_t	tpp_chip;	/* base Tulip chip type */
    133 } tlp_pci_products[] = {
    134 #ifdef TLP_MATCH_21040
    135 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21040,
    136 	  TULIP_CHIP_21040 },
    137 #endif
    138 #ifdef TLP_MATCH_21041
    139 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21041,
    140 	  TULIP_CHIP_21041 },
    141 #endif
    142 #ifdef TLP_MATCH_21140
    143 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21140,
    144 	  TULIP_CHIP_21140 },
    145 #endif
    146 #ifdef TLP_MATCH_21142
    147 	{ PCI_VENDOR_DEC,		PCI_PRODUCT_DEC_21142,
    148 	  TULIP_CHIP_21142 },
    149 #endif
    150 
    151 	{ PCI_VENDOR_LITEON,		PCI_PRODUCT_LITEON_82C168,
    152 	  TULIP_CHIP_82C168 },
    153 
    154 #if 0
    155 	/*
    156 	 * Note: This is like a MX98715A with Wake-On-LAN and a
    157 	 * 128-bit multicast hash table.
    158 	 */
    159 	{ PCI_VENDOR_LITEON,		PCI_PRODUCT_LITEON_82C115,
    160 	  TULIP_CHIP_82C115 },
    161 #endif
    162 
    163 #if 0
    164 	{ PCI_VENDOR_MACRONIX,		PCI_PRODUCT_MACRONIX_MX98713,
    165 	  TULIP_CHIP_MX98713 },
    166 	{ PCI_VENDOR_MACRONIX,		PCI_PRODUCT_MACRONIX_MX987x5,
    167 	  TULIP_CHIP_MX98715 },
    168 
    169 	{ PCI_VENDOR_COMPEX,		PCI_PRODUCT_COMPEX_RL100TX,
    170 	  TULIP_CHIP_MX98713 },
    171 #endif
    172 
    173 	{ PCI_VENDOR_WINBOND,		PCI_PRODUCT_WINBOND_W89C840F,
    174 	  TULIP_CHIP_WB89C840F },
    175 	{ PCI_VENDOR_COMPEX,		PCI_PRODUCT_COMPEX_RL100ATX,
    176 	  TULIP_CHIP_WB89C840F },
    177 
    178 #if 0
    179 	{ PCI_VENDOR_DAVICOM,		PCI_PRODUCT_DAVICOM_DM9102,
    180 	  TULIP_CHIP_DM9102 },
    181 
    182 	{ PCI_VENDOR_ADMTEK,		PCI_PRODUCT_ADMTEK_AL981,
    183 	  TULIP_CHIP_AL981 },
    184 
    185 	{ PCI_VENDOR_ASIX,		PCI_PRODUCT_ASIX_AX88140A,
    186 	  TULIP_CHIP_AX88140 },
    187 #endif
    188 
    189 	{ 0,				0,
    190 	  TULIP_CHIP_INVALID },
    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_znyx_21040_quirks __P((struct tulip_pci_softc *,
    200 	    const u_int8_t *));
    201 void	tlp_pci_smc_21040_quirks __P((struct tulip_pci_softc *,
    202 	    const u_int8_t *));
    203 void	tlp_pci_cogent_21040_quirks __P((struct tulip_pci_softc *,
    204 	    const u_int8_t *));
    205 void	tlp_pci_accton_21040_quirks __P((struct tulip_pci_softc *,
    206 	    const u_int8_t *));
    207 
    208 const struct tlp_pci_quirks tlp_pci_21040_quirks[] = {
    209 	{ tlp_pci_znyx_21040_quirks,	{ 0x00, 0xc0, 0x95 } },
    210 	{ tlp_pci_smc_21040_quirks,	{ 0x00, 0x00, 0xc0 } },
    211 	{ tlp_pci_cogent_21040_quirks,	{ 0x00, 0x00, 0x92 } },
    212 	{ tlp_pci_accton_21040_quirks,	{ 0x00, 0x00, 0xe8 } },
    213 	{ NULL,				{ 0, 0, 0 } }
    214 };
    215 
    216 const char *tlp_pci_chip_names[] = TULIP_CHIP_NAMES;
    217 
    218 int	tlp_pci_shared_intr __P((void *));
    219 
    220 const struct tulip_pci_product *tlp_pci_lookup
    221     __P((const struct pci_attach_args *));
    222 void tlp_pci_get_quirks __P((struct tulip_pci_softc *, const u_int8_t *,
    223     const struct tlp_pci_quirks *));
    224 void tlp_pci_check_slaved __P((struct tulip_pci_softc *, int, int));
    225 
    226 const struct tulip_pci_product *
    227 tlp_pci_lookup(pa)
    228 	const struct pci_attach_args *pa;
    229 {
    230 	const struct tulip_pci_product *tpp;
    231 
    232 	for (tpp = tlp_pci_products;
    233 	     tlp_pci_chip_names[tpp->tpp_chip] != NULL;
    234 	     tpp++) {
    235 		if (PCI_VENDOR(pa->pa_id) == tpp->tpp_vendor &&
    236 		    PCI_PRODUCT(pa->pa_id) == tpp->tpp_product)
    237 			return (tpp);
    238 	}
    239 	return (NULL);
    240 }
    241 
    242 void
    243 tlp_pci_get_quirks(psc, enaddr, tpq)
    244 	struct tulip_pci_softc *psc;
    245 	const u_int8_t *enaddr;
    246 	const struct tlp_pci_quirks *tpq;
    247 {
    248 
    249 	for (; tpq->tpq_func != NULL; tpq++) {
    250 		if (tpq->tpq_oui[0] == enaddr[0] &&
    251 		    tpq->tpq_oui[1] == enaddr[1] &&
    252 		    tpq->tpq_oui[2] == enaddr[2]) {
    253 			(*tpq->tpq_func)(psc, enaddr);
    254 			return;
    255 		}
    256 	}
    257 }
    258 
    259 void
    260 tlp_pci_check_slaved(psc, shared, slaved)
    261 	struct tulip_pci_softc *psc;
    262 	int shared, slaved;
    263 {
    264 	extern struct cfdriver tlp_cd;
    265 	struct tulip_pci_softc *cur, *best = NULL;
    266 	struct tulip_softc *sc = &psc->sc_tulip;
    267 	int i;
    268 
    269 	/*
    270 	 * First of all, find the lowest pcidev numbered device on our
    271 	 * bus marked as a shared ROM.  That should be our master.
    272 	 */
    273 	for (i = 0; i < tlp_cd.cd_ndevs; i++) {
    274 		if ((cur = tlp_cd.cd_devs[i]) == NULL)
    275 			continue;
    276 		if (cur->sc_tulip.sc_dev.dv_parent != sc->sc_dev.dv_parent)
    277 			continue;
    278 		if ((cur->sc_flags & shared) == 0)
    279 			continue;
    280 		if (best == NULL || best->sc_pcidev > cur->sc_pcidev)
    281 			best = cur;
    282 	}
    283 
    284 	if (best != NULL) {
    285 		psc->sc_master = best;
    286 		psc->sc_flags |= (shared | slaved);
    287 	}
    288 }
    289 
    290 int
    291 tlp_pci_match(parent, match, aux)
    292 	struct device *parent;
    293 	struct cfdata *match;
    294 	void *aux;
    295 {
    296 	struct pci_attach_args *pa = aux;
    297 
    298 	if (tlp_pci_lookup(pa) != NULL)
    299 		return (10);	/* beat if_de.c */
    300 
    301 	return (0);
    302 }
    303 
    304 void
    305 tlp_pci_attach(parent, self, aux)
    306 	struct device *parent, *self;
    307 	void *aux;
    308 {
    309 	struct tulip_pci_softc *psc = (void *) self;
    310 	struct tulip_softc *sc = &psc->sc_tulip;
    311 	struct pci_attach_args *pa = aux;
    312 	pci_chipset_tag_t pc = pa->pa_pc;
    313 	pci_intr_handle_t ih;
    314 	const char *intrstr = NULL;
    315 	bus_space_tag_t iot, memt;
    316 	bus_space_handle_t ioh, memh;
    317 	int ioh_valid, memh_valid, i, j;
    318 	const struct tulip_pci_product *tpp;
    319 	u_int8_t enaddr[ETHER_ADDR_LEN];
    320 	u_int32_t val;
    321 
    322 	psc->sc_pcidev = pa->pa_device;
    323 	psc->sc_pc = pa->pa_pc;
    324 	psc->sc_pcitag = pa->pa_tag;
    325 
    326 	LIST_INIT(&psc->sc_intrslaves);
    327 
    328 	/*
    329 	 * Map the device.
    330 	 */
    331 	ioh_valid = (pci_mapreg_map(pa, TULIP_PCI_IOBA,
    332 	    PCI_MAPREG_TYPE_IO, 0,
    333 	    &iot, &ioh, NULL, NULL) == 0);
    334 	memh_valid = (pci_mapreg_map(pa, TULIP_PCI_MMBA,
    335 	    PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
    336 	    &memt, &memh, NULL, NULL) == 0);
    337 
    338 	if (memh_valid) {
    339 		sc->sc_st = memt;
    340 		sc->sc_sh = memh;
    341 	} else if (ioh_valid) {
    342 		sc->sc_st = iot;
    343 		sc->sc_sh = ioh;
    344 	} else {
    345 		printf(": unable to map device registers\n");
    346 		return;
    347 	}
    348 
    349 	tpp = tlp_pci_lookup(pa);
    350 	if (tpp == NULL) {
    351 		printf("\n");
    352 		panic("tlp_pci_attach: impossible");
    353 	}
    354 	sc->sc_chip = tpp->tpp_chip;
    355 
    356 	/*
    357 	 * By default, Tulip registers are 8 bytes long (4 bytes
    358 	 * followed by a 4 byte pad).
    359 	 */
    360 	sc->sc_regshift = 3;
    361 
    362 	/*
    363 	 * Get revision info, and set some chip-specific variables.
    364 	 */
    365 	sc->sc_rev = PCI_REVISION(pa->pa_class);
    366 	switch (sc->sc_chip) {
    367 	case TULIP_CHIP_21140:
    368 		if (sc->sc_rev >= 0x20)
    369 			sc->sc_chip = TULIP_CHIP_21140A;
    370 		break;
    371 
    372 	case TULIP_CHIP_21142:
    373 		if (sc->sc_rev >= 0x20)
    374 			sc->sc_chip = TULIP_CHIP_21143;
    375 		break;
    376 
    377 	case TULIP_CHIP_82C168:
    378 		if (sc->sc_rev >= 0x20)
    379 			sc->sc_chip = TULIP_CHIP_82C169;
    380 		break;
    381 
    382 	case TULIP_CHIP_MX98713:
    383 		if (sc->sc_rev >= 0x10)
    384 			sc->sc_chip = TULIP_CHIP_MX98713A;
    385 		break;
    386 
    387 	case TULIP_CHIP_MX98715:
    388 		if (sc->sc_rev >= 0x30)
    389 			sc->sc_chip = TULIP_CHIP_MX98725;
    390 		break;
    391 
    392 	case TULIP_CHIP_WB89C840F:
    393 		sc->sc_regshift = 2;
    394 		break;
    395 
    396 	case TULIP_CHIP_AX88140:
    397 		if (sc->sc_rev >= 0x10)
    398 			sc->sc_chip = TULIP_CHIP_AX88141;
    399 		break;
    400 
    401 	default:
    402 		/* Nothing. */
    403 	}
    404 
    405 	printf(": %s Ethernet, pass %d.%d\n",
    406 	    tlp_pci_chip_names[sc->sc_chip],
    407 	    (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
    408 
    409 	sc->sc_dmat = pa->pa_dmat;
    410 
    411 	/*
    412 	 * Make sure bus mastering is enabled.
    413 	 */
    414 	pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
    415 	    pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
    416 	    PCI_COMMAND_MASTER_ENABLE);
    417 
    418 	/*
    419 	 * Get the cacheline size.
    420 	 */
    421 	sc->sc_cacheline = PCI_CACHELINE(pci_conf_read(pc, pa->pa_tag,
    422 	    PCI_BHLC_REG));
    423 
    424 	/*
    425 	 * Read the contents of the Ethernet Address ROM/SROM.
    426 	 */
    427 	memset(sc->sc_srom, 0, sizeof(sc->sc_srom));
    428 	switch (sc->sc_chip) {
    429 	case TULIP_CHIP_21040:
    430 		TULIP_WRITE(sc, CSR_MIIROM, MIIROM_SROMCS);
    431 		for (i = 0; i < sizeof(sc->sc_srom); i++) {
    432 			for (j = 0; j < 10000; j++) {
    433 				val = TULIP_READ(sc, CSR_MIIROM);
    434 				if ((val & MIIROM_DN) == 0)
    435 					break;
    436 			}
    437 			sc->sc_srom[i] = val & MIIROM_DATA;
    438 		}
    439 		break;
    440 
    441 	case TULIP_CHIP_82C168:
    442 	case TULIP_CHIP_82C169:
    443 	    {
    444 		u_int16_t *rombuf = (u_int16_t *)sc->sc_srom;
    445 
    446 		/*
    447 		 * The Lite-On PNIC stores the Ethernet address in
    448 		 * the first 3 words of the EEPROM.  EEPROM access
    449 		 * is not like the other Tulip chips.
    450 		 */
    451 		for (i = 0; i < 3; i++) {
    452 			TULIP_WRITE(sc, CSR_PNIC_SROMCTL,
    453 			    PNIC_SROMCTL_READ | i);
    454 			for (j = 0; j < 500; j++) {
    455 				delay(2);
    456 				val = TULIP_READ(sc, CSR_MIIROM);
    457 				if ((val & PNIC_MIIROM_BUSY) == 0)
    458 					break;
    459 			}
    460 			if (val & PNIC_MIIROM_BUSY) {
    461 				printf("%s: EEPROM timed out\n",
    462 				    sc->sc_dev.dv_xname);
    463 				return;
    464 			}
    465 			rombuf[i] = bswap16(val & PNIC_MIIROM_DATA);
    466 		}
    467 		break;
    468 	    }
    469 
    470 	default:
    471 		tlp_read_srom(sc, 0, sizeof(sc->sc_srom) >> 2,
    472 		    (u_int16_t *)sc->sc_srom);
    473 	}
    474 
    475 	/*
    476 	 * Deal with chip/board quirks.  This includes setting up
    477 	 * the mediasw, and extracting the Ethernet address from
    478 	 * the rombuf.
    479 	 *
    480 	 * XXX Eventually, handle master/slave interrupts on the
    481 	 * XXX multi-port boards which require that.
    482 	 */
    483 	switch (sc->sc_chip) {
    484 	case TULIP_CHIP_21040:
    485 		/* Check for a slaved ROM on a multi-port board. */
    486 		tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDROM,
    487 		    TULIP_PCI_SLAVEROM);
    488 		if (psc->sc_flags & TULIP_PCI_SLAVEROM)
    489 			memcpy(sc->sc_srom, psc->sc_master->sc_tulip.sc_srom,
    490 			    sizeof(sc->sc_srom));
    491 
    492 		/*
    493 		 * Parse the Ethernet Address ROM.
    494 		 */
    495 		if (tlp_parse_old_srom(sc, enaddr) == 0) {
    496 			printf("%s: unable to decode Ethernet Address ROM\n",
    497 			    sc->sc_dev.dv_xname);
    498 			return;
    499 		}
    500 
    501 		/*
    502 		 * If we have a slaved ROM, adjust the Ethernet address.
    503 		 */
    504 		if (psc->sc_flags & TULIP_PCI_SLAVEROM)
    505 			enaddr[5] +=
    506 			    psc->sc_pcidev - psc->sc_master->sc_pcidev;
    507 
    508 		/*
    509 		 * All 21040 boards start out with the same
    510 		 * media switch.
    511 		 */
    512 		sc->sc_mediasw = &tlp_21040_mediasw;
    513 
    514 		/*
    515 		 * Deal with any quirks this board might have.
    516 		 */
    517 		tlp_pci_get_quirks(psc, enaddr, tlp_pci_21040_quirks);
    518 		break;
    519 
    520 	case TULIP_CHIP_82C168:
    521 	case TULIP_CHIP_82C169:
    522 		/*
    523 		 * Lite-On PNIC's Ethernet address is the first 6
    524 		 * bytes of its EEPROM.
    525 		 */
    526 		memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
    527 
    528 		/*
    529 		 * Lite-On PNICs always use the same mediasw; we
    530 		 * select MII vs. internal NWAY automatically.
    531 		 */
    532 		sc->sc_mediasw = &tlp_pnic_mediasw;
    533 		break;
    534 
    535 	case TULIP_CHIP_WB89C840F:
    536 		/*
    537 		 * Winbond 89C840F's Ethernet address is the first
    538 		 * 6 bytes of its EEPROM.
    539 		 */
    540 		memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
    541 
    542 		/*
    543 		 * Winbond 89C840F has an MII attached to the SIO.
    544 		 */
    545 		sc->sc_mediasw = &tlp_sio_mii_mediasw;
    546 		break;
    547 
    548 	default:
    549 		printf("%s: sorry, unable to handle your board\n",
    550 		    sc->sc_dev.dv_xname);
    551 		return;
    552 	}
    553 
    554 	/*
    555 	 * Handle shared interrupts.
    556 	 */
    557 	if (psc->sc_flags & TULIP_PCI_SHAREDINTR) {
    558 		if (psc->sc_master)
    559 			psc->sc_flags |= TULIP_PCI_SLAVEINTR;
    560 		else {
    561 			tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDINTR,
    562 			    TULIP_PCI_SLAVEINTR);
    563 			if (psc->sc_master == NULL)
    564 				psc->sc_master = psc;
    565 		}
    566 		LIST_INSERT_HEAD(&psc->sc_master->sc_intrslaves,
    567 		    psc, sc_intrq);
    568 	}
    569 
    570 	if (psc->sc_flags & TULIP_PCI_SLAVEINTR) {
    571 		printf("%s: sharing interrupt with %s\n",
    572 		    sc->sc_dev.dv_xname,
    573 		    psc->sc_master->sc_tulip.sc_dev.dv_xname);
    574 	} else {
    575 		/*
    576 		 * Map and establish our interrupt.
    577 		 */
    578 		if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
    579 		    pa->pa_intrline, &ih)) {
    580 			printf("%s: unable to map interrupt\n",
    581 			    sc->sc_dev.dv_xname);
    582 			return;
    583 		}
    584 		intrstr = pci_intr_string(pc, ih);
    585 		psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET,
    586 		    (psc->sc_flags & TULIP_PCI_SHAREDINTR) ?
    587 		    tlp_pci_shared_intr : tlp_intr, sc);
    588 		if (psc->sc_ih == NULL) {
    589 			printf("%s: unable to establish interrupt",
    590 			    sc->sc_dev.dv_xname);
    591 			if (intrstr != NULL)
    592 				printf(" at %s", intrstr);
    593 			printf("\n");
    594 			return;
    595 		}
    596 		printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
    597 		    intrstr);
    598 	}
    599 
    600 	/*
    601 	 * Finish off the attach.
    602 	 */
    603 	tlp_attach(sc, enaddr);
    604 }
    605 
    606 int
    607 tlp_pci_shared_intr(arg)
    608 	void *arg;
    609 {
    610 	struct tulip_pci_softc *master = arg, *slave;
    611 	int rv = 0;
    612 
    613 	for (slave = LIST_FIRST(&master->sc_intrslaves);
    614 	     slave != NULL;
    615 	     slave = LIST_NEXT(slave, sc_intrq))
    616 		rv |= tlp_intr(&slave->sc_tulip);
    617 
    618 	return (rv);
    619 }
    620 
    621 void
    622 tlp_pci_znyx_21040_quirks(psc, enaddr)
    623 	struct tulip_pci_softc *psc;
    624 	const u_int8_t *enaddr;
    625 {
    626 	struct tulip_softc *sc = &psc->sc_tulip;
    627 	u_int16_t id = 0;
    628 
    629 	if (sc->sc_srom[32] == 0x4a && sc->sc_srom[33] == 0x52) {
    630 		id = sc->sc_srom[37] | (sc->sc_srom[36] << 8);
    631 		switch (id) {
    632  zx312:
    633 		case 0x0602:	/* ZX312 */
    634 			strcpy(sc->sc_name, "ZNYX ZX312");
    635 			return;
    636 
    637 		case 0x0622:	/* ZX312T */
    638 			strcpy(sc->sc_name, "ZNYX ZX312T");
    639 			sc->sc_mediasw = &tlp_21040_tp_mediasw;
    640 			return;
    641 
    642  zx314_inta:
    643 		case 0x0701:	/* ZX314 INTA */
    644 			psc->sc_flags |= TULIP_PCI_SHAREDINTR;
    645 			/* FALLTHROUGH */
    646 		case 0x0711:	/* ZX314 */
    647 			strcpy(sc->sc_name, "ZNYX ZX314");
    648 			psc->sc_flags |= TULIP_PCI_SHAREDROM;
    649 			sc->sc_mediasw = &tlp_21040_tp_mediasw;
    650 			return;
    651 
    652  zx315_inta:
    653 		case 0x0801:	/* ZX315 INTA */
    654 			psc->sc_flags |= TULIP_PCI_SHAREDINTR;
    655 			/* FALLTHROUGH */
    656 		case 0x0811:	/* ZX315 */
    657 			strcpy(sc->sc_name, "ZNYX ZX315");
    658 			psc->sc_flags |= TULIP_PCI_SHAREDROM;
    659 			return;
    660 
    661 		default:
    662 			id = 0;
    663 		}
    664 	}
    665 
    666 	/*
    667 	 * Deal with boards that have broken ROMs.
    668 	 */
    669 	if (id == 0) {
    670 		if ((enaddr[3] & ~3) == 0xf0 && (enaddr[5] & 3) == 0x00)
    671 			goto zx314_inta;
    672 		if ((enaddr[3] & ~3) == 0xf4 && (enaddr[5] & 1) == 0x00)
    673 			goto zx315_inta;
    674 		if ((enaddr[3] & ~3) == 0xec)
    675 			goto zx312;
    676 	}
    677 
    678 	strcpy(sc->sc_name, "ZNYX ZX31x");
    679 }
    680 
    681 void
    682 tlp_pci_smc_21040_quirks(psc, enaddr)
    683 	struct tulip_pci_softc *psc;
    684 	const u_int8_t *enaddr;
    685 {
    686 	struct tulip_softc *sc = &psc->sc_tulip;
    687 	u_int16_t id1, id2, ei;
    688 	int auibnc = 0, utp = 0;
    689 	char *cp;
    690 
    691 	id1 = sc->sc_srom[0x60] | (sc->sc_srom[0x61] << 8);
    692 	id2 = sc->sc_srom[0x62] | (sc->sc_srom[0x63] << 8);
    693 	ei  = sc->sc_srom[0x66] | (sc->sc_srom[0x67] << 8);
    694 
    695 	strcpy(sc->sc_name, "SMC 8432");
    696 	cp = &sc->sc_name[8];
    697 
    698 	if ((id1 & 1) == 0) {
    699 		*cp++ = 'B';
    700 		auibnc = 1;
    701 	}
    702 	if ((id1 & 0xff) > 0x32) {
    703 		*cp++ = 'T';
    704 		utp = 1;
    705 	}
    706 	if ((id1 & 0x4000) == 0) {
    707 		*cp++ = 'A';
    708 		auibnc = 1;
    709 	}
    710 	if (id2 == 0x15) {
    711 		sc->sc_name[7] = '4';
    712 		*cp++ = '-';
    713 		*cp++ = 'C';
    714 		*cp++ = 'H';
    715 		*cp++ = ei ? '2' : '1';
    716 	}
    717 	*cp = '\0';
    718 
    719 	if (utp != 0 && auibnc == 0)
    720 		sc->sc_mediasw = &tlp_21040_tp_mediasw;
    721 	else if (utp == 0 && auibnc != 0)
    722 		sc->sc_mediasw = &tlp_21040_auibnc_mediasw;
    723 }
    724 
    725 void
    726 tlp_pci_cogent_21040_quirks(psc, enaddr)
    727 	struct tulip_pci_softc *psc;
    728 	const u_int8_t *enaddr;
    729 {
    730 
    731 	strcpy(psc->sc_tulip.sc_name, "Cogent multi-port");
    732 	psc->sc_flags |= TULIP_PCI_SHAREDINTR|TULIP_PCI_SHAREDROM;
    733 }
    734 
    735 void
    736 tlp_pci_accton_21040_quirks(psc, enaddr)
    737 	struct tulip_pci_softc *psc;
    738 	const u_int8_t *enaddr;
    739 {
    740 
    741 	strcpy(psc->sc_tulip.sc_name, "ACCTON EN1203");
    742 }
    743