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