Home | History | Annotate | Line # | Download | only in cardbus
if_tlp_cardbus.c revision 1.60
      1 /*	$NetBSD: if_tlp_cardbus.c,v 1.60 2009/03/14 15:36:16 dsl Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 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  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * CardBus bus front-end for the Digital Semiconductor ``Tulip'' (21x4x)
     35  * Ethernet controller family driver.
     36  */
     37 
     38 #include <sys/cdefs.h>
     39 __KERNEL_RCSID(0, "$NetBSD: if_tlp_cardbus.c,v 1.60 2009/03/14 15:36:16 dsl Exp $");
     40 
     41 #include "opt_inet.h"
     42 #include "bpfilter.h"
     43 
     44 #include <sys/param.h>
     45 #include <sys/systm.h>
     46 #include <sys/mbuf.h>
     47 #include <sys/malloc.h>
     48 #include <sys/kernel.h>
     49 #include <sys/socket.h>
     50 #include <sys/ioctl.h>
     51 #include <sys/errno.h>
     52 #include <sys/device.h>
     53 
     54 #include <machine/endian.h>
     55 
     56 #include <net/if.h>
     57 #include <net/if_dl.h>
     58 #include <net/if_media.h>
     59 #include <net/if_ether.h>
     60 
     61 #if NBPFILTER > 0
     62 #include <net/bpf.h>
     63 #endif
     64 
     65 #ifdef INET
     66 #include <netinet/in.h>
     67 #include <netinet/if_inarp.h>
     68 #endif
     69 
     70 
     71 #include <sys/bus.h>
     72 #include <sys/intr.h>
     73 
     74 #include <dev/mii/miivar.h>
     75 #include <dev/mii/mii_bitbang.h>
     76 
     77 #include <dev/ic/tulipreg.h>
     78 #include <dev/ic/tulipvar.h>
     79 
     80 #include <dev/pci/pcivar.h>
     81 #include <dev/pci/pcireg.h>
     82 #include <dev/pci/pcidevs.h>
     83 
     84 #include <dev/cardbus/cardbusvar.h>
     85 #include <dev/pci/pcidevs.h>
     86 
     87 /*
     88  * PCI configuration space registers used by the Tulip.
     89  */
     90 #define	TULIP_PCI_IOBA		0x10	/* i/o mapped base */
     91 #define	TULIP_PCI_MMBA		0x14	/* memory mapped base */
     92 #define	TULIP_PCI_CFDA		0x40	/* configuration driver area */
     93 
     94 #define	CFDA_SLEEP		0x80000000	/* sleep mode */
     95 #define	CFDA_SNOOZE		0x40000000	/* snooze mode */
     96 
     97 struct tulip_cardbus_softc {
     98 	struct tulip_softc sc_tulip;	/* real Tulip softc */
     99 
    100 	/* CardBus-specific goo. */
    101 	void	*sc_ih;			/* interrupt handle */
    102 	cardbus_devfunc_t sc_ct;	/* our CardBus devfuncs */
    103 	cardbustag_t sc_tag;		/* our CardBus tag */
    104 	int	sc_csr;			/* CSR bits */
    105 	bus_size_t sc_mapsize;		/* the size of mapped bus space
    106 					   region */
    107 
    108 	int	sc_cben;		/* CardBus enables */
    109 	int	sc_bar_reg;		/* which BAR to use */
    110 	pcireg_t sc_bar_val;		/* value of the BAR */
    111 
    112 	cardbus_intr_line_t sc_intrline; /* interrupt line */
    113 };
    114 
    115 int	tlp_cardbus_match(struct device *, struct cfdata *, void *);
    116 void	tlp_cardbus_attach(struct device *, struct device *, void *);
    117 int	tlp_cardbus_detach(struct device *, int);
    118 
    119 CFATTACH_DECL(tlp_cardbus, sizeof(struct tulip_cardbus_softc),
    120     tlp_cardbus_match, tlp_cardbus_attach, tlp_cardbus_detach, tlp_activate);
    121 
    122 const struct tulip_cardbus_product {
    123 	u_int32_t	tcp_vendor;	/* PCI vendor ID */
    124 	u_int32_t	tcp_product;	/* PCI product ID */
    125 	tulip_chip_t	tcp_chip;	/* base Tulip chip type */
    126 } tlp_cardbus_products[] = {
    127 	{ PCI_VENDOR_DEC,	PCI_PRODUCT_DEC_21142,
    128 	  TULIP_CHIP_21142 },
    129 
    130 	{ PCI_VENDOR_XIRCOM,	PCI_PRODUCT_XIRCOM_X3201_3_21143,
    131 	  TULIP_CHIP_X3201_3 },
    132 
    133 	{ PCI_VENDOR_ADMTEK,	PCI_PRODUCT_ADMTEK_AN983,
    134 	  TULIP_CHIP_AN985 },
    135 
    136 	{ PCI_VENDOR_ACCTON,	PCI_PRODUCT_ACCTON_EN2242,
    137 	  TULIP_CHIP_AN985 },
    138 
    139 	{ PCI_VENDOR_ABOCOM,	PCI_PRODUCT_ABOCOM_FE2500,
    140 	  TULIP_CHIP_AN985 },
    141 
    142 	{ PCI_VENDOR_ABOCOM,	PCI_PRODUCT_ABOCOM_PCM200,
    143 	  TULIP_CHIP_AN985 },
    144 
    145 	{ PCI_VENDOR_ABOCOM,	PCI_PRODUCT_ABOCOM_FE2500MX,
    146 	  TULIP_CHIP_AN985 },
    147 
    148 	{ PCI_VENDOR_HAWKING,	PCI_PRODUCT_HAWKING_PN672TX,
    149 	  TULIP_CHIP_AN985 },
    150 
    151 	{ PCI_VENDOR_ADMTEK,	PCI_PRODUCT_ADMTEK_AN985,
    152 	  TULIP_CHIP_AN985 },
    153 
    154 	{ PCI_VENDOR_MICROSOFT,	PCI_PRODUCT_MICROSOFT_MN120,
    155 	  TULIP_CHIP_AN985 },
    156 
    157 	{ PCI_VENDOR_LINKSYS, PCI_PRODUCT_LINKSYS_PCMPC200,
    158 	  TULIP_CHIP_AN985 },
    159 
    160 	{ 0,				0,
    161 	  TULIP_CHIP_INVALID },
    162 };
    163 
    164 struct tlp_cardbus_quirks {
    165 	void		(*tpq_func)(struct tulip_cardbus_softc *,
    166 			    const u_int8_t *);
    167 	u_int8_t	tpq_oui[3];
    168 };
    169 
    170 void	tlp_cardbus_lxt_quirks(struct tulip_cardbus_softc *,
    171 	    const u_int8_t *);
    172 
    173 const struct tlp_cardbus_quirks tlp_cardbus_21142_quirks[] = {
    174 	{ tlp_cardbus_lxt_quirks,	{ 0x00, 0x40, 0x05 } },
    175 	{ NULL,				{ 0, 0, 0 } }
    176 };
    177 
    178 void	tlp_cardbus_setup(struct tulip_cardbus_softc *);
    179 
    180 int	tlp_cardbus_enable(struct tulip_softc *);
    181 void	tlp_cardbus_disable(struct tulip_softc *);
    182 void	tlp_cardbus_power(struct tulip_softc *, int);
    183 
    184 void	tlp_cardbus_x3201_reset(struct tulip_softc *);
    185 
    186 const struct tulip_cardbus_product *tlp_cardbus_lookup
    187    (const struct cardbus_attach_args *);
    188 void tlp_cardbus_get_quirks(struct tulip_cardbus_softc *,
    189     const u_int8_t *, const struct tlp_cardbus_quirks *);
    190 
    191 const struct tulip_cardbus_product *
    192 tlp_cardbus_lookup(const struct cardbus_attach_args *ca)
    193 {
    194 	const struct tulip_cardbus_product *tcp;
    195 
    196 	for (tcp = tlp_cardbus_products;
    197 	     tlp_chip_names[tcp->tcp_chip] != NULL;
    198 	     tcp++) {
    199 		if (PCI_VENDOR(ca->ca_id) == tcp->tcp_vendor &&
    200 		    PCI_PRODUCT(ca->ca_id) == tcp->tcp_product)
    201 			return (tcp);
    202 	}
    203 	return (NULL);
    204 }
    205 
    206 void
    207 tlp_cardbus_get_quirks(struct tulip_cardbus_softc *csc, const u_int8_t *enaddr, const struct tlp_cardbus_quirks *tpq)
    208 {
    209 
    210 	for (; tpq->tpq_func != NULL; tpq++) {
    211 		if (tpq->tpq_oui[0] == enaddr[0] &&
    212 		    tpq->tpq_oui[1] == enaddr[1] &&
    213 		    tpq->tpq_oui[2] == enaddr[2]) {
    214 			(*tpq->tpq_func)(csc, enaddr);
    215 			return;
    216 		}
    217 	}
    218 }
    219 
    220 int
    221 tlp_cardbus_match(struct device *parent, struct cfdata *match,
    222     void *aux)
    223 {
    224 	struct cardbus_attach_args *ca = aux;
    225 
    226 	if (tlp_cardbus_lookup(ca) != NULL)
    227 		return (1);
    228 
    229 	return (0);
    230 }
    231 
    232 void
    233 tlp_cardbus_attach(struct device *parent, struct device *self,
    234     void *aux)
    235 {
    236 	struct tulip_cardbus_softc *csc = device_private(self);
    237 	struct tulip_softc *sc = &csc->sc_tulip;
    238 	struct cardbus_attach_args *ca = aux;
    239 	cardbus_devfunc_t ct = ca->ca_ct;
    240 	const struct tulip_cardbus_product *tcp;
    241 	u_int8_t enaddr[ETHER_ADDR_LEN];
    242 	bus_addr_t adr;
    243 	pcireg_t reg;
    244 
    245 	sc->sc_devno = 0;
    246 	sc->sc_dmat = ca->ca_dmat;
    247 	csc->sc_ct = ct;
    248 	csc->sc_tag = ca->ca_tag;
    249 
    250 	tcp = tlp_cardbus_lookup(ca);
    251 	if (tcp == NULL) {
    252 		printf("\n");
    253 		panic("tlp_cardbus_attach: impossible");
    254 	}
    255 	sc->sc_chip = tcp->tcp_chip;
    256 
    257 	/*
    258 	 * By default, Tulip registers are 8 bytes long (4 bytes
    259 	 * followed by a 4 byte pad).
    260 	 */
    261 	sc->sc_regshift = 3;
    262 
    263 	/*
    264 	 * Power management hooks.
    265 	 */
    266 	sc->sc_enable = tlp_cardbus_enable;
    267 	sc->sc_disable = tlp_cardbus_disable;
    268 	sc->sc_power = tlp_cardbus_power;
    269 
    270 	/*
    271 	 * Get revision info, and set some chip-specific variables.
    272 	 */
    273 	sc->sc_rev = PCI_REVISION(ca->ca_class);
    274 	switch (sc->sc_chip) {
    275 	case TULIP_CHIP_21142:
    276 		if (sc->sc_rev >= 0x20)
    277 			sc->sc_chip = TULIP_CHIP_21143;
    278 		break;
    279 
    280 	case TULIP_CHIP_AN985:
    281 		/*
    282 		 * The AN983 and AN985 are very similar, and are
    283 		 * differentiated by a "signature" register that
    284 		 * is like, but not identical, to a PCI ID register.
    285 		 */
    286 		reg = cardbus_conf_read(ct->ct_cc, ct->ct_cf, csc->sc_tag,
    287 		    0x80);
    288 		switch (reg) {
    289 		case 0x09811317:
    290 			sc->sc_chip = TULIP_CHIP_AN985;
    291 			break;
    292 
    293 		case 0x09851317:
    294 			sc->sc_chip = TULIP_CHIP_AN983;
    295 			break;
    296 
    297 		}
    298 		break;
    299 
    300 	default:
    301 		/* Nothing. -- to make gcc happy */
    302 		break;
    303 	}
    304 
    305 	printf(": %s Ethernet, pass %d.%d\n",
    306 	    tlp_chip_names[sc->sc_chip],
    307 	    (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
    308 
    309 	/*
    310 	 * Map the device.
    311 	 */
    312 	csc->sc_csr = CARDBUS_COMMAND_MASTER_ENABLE;
    313 	if (Cardbus_mapreg_map(ct, TULIP_PCI_MMBA,
    314 	    CARDBUS_MAPREG_TYPE_MEM, 0, &sc->sc_st, &sc->sc_sh, &adr,
    315 	    &csc->sc_mapsize) == 0) {
    316 #if rbus
    317 #else
    318 		(*ct->ct_cf->cardbus_mem_open)(cc, 0, adr, adr+csc->sc_mapsize);
    319 #endif
    320 		csc->sc_cben = CARDBUS_MEM_ENABLE;
    321 		csc->sc_csr |= CARDBUS_COMMAND_MEM_ENABLE;
    322 		csc->sc_bar_reg = TULIP_PCI_MMBA;
    323 		csc->sc_bar_val = adr | CARDBUS_MAPREG_TYPE_MEM;
    324 	} else if (Cardbus_mapreg_map(ct, TULIP_PCI_IOBA,
    325 	    CARDBUS_MAPREG_TYPE_IO, 0, &sc->sc_st, &sc->sc_sh, &adr,
    326 	    &csc->sc_mapsize) == 0) {
    327 #if rbus
    328 #else
    329 		(*ct->ct_cf->cardbus_io_open)(cc, 0, adr, adr+csc->sc_mapsize);
    330 #endif
    331 		csc->sc_cben = CARDBUS_IO_ENABLE;
    332 		csc->sc_csr |= CARDBUS_COMMAND_IO_ENABLE;
    333 		csc->sc_bar_reg = TULIP_PCI_IOBA;
    334 		csc->sc_bar_val = adr | CARDBUS_MAPREG_TYPE_IO;
    335 	} else {
    336 		aprint_error_dev(&sc->sc_dev, "unable to map device registers\n");
    337 		return;
    338 	}
    339 
    340 	/*
    341 	 * Bring the chip out of powersave mode and initialize the
    342 	 * configuration registers.
    343 	 */
    344 	tlp_cardbus_setup(csc);
    345 
    346 	/*
    347 	 * Read the contents of the Ethernet Address ROM/SROM.
    348 	 */
    349 	switch (sc->sc_chip) {
    350 	case TULIP_CHIP_X3201_3:
    351 		/*
    352 		 * No SROM on this chip.
    353 		 */
    354 		break;
    355 
    356 	default:
    357 		if (tlp_read_srom(sc) == 0)
    358 			goto cant_cope;
    359 		break;
    360 	}
    361 
    362 	/*
    363 	 * Deal with chip/board quirks.  This includes setting up
    364 	 * the mediasw, and extracting the Ethernet address from
    365 	 * the rombuf.
    366 	 */
    367 	switch (sc->sc_chip) {
    368 	case TULIP_CHIP_21142:
    369 	case TULIP_CHIP_21143:
    370 		/* Check for new format SROM. */
    371 		if (tlp_isv_srom_enaddr(sc, enaddr) != 0) {
    372 			/*
    373 			 * We start out with the 2114x ISV media switch.
    374 			 * When we search for quirks, we may change to
    375 			 * a different switch.
    376 			 */
    377 			sc->sc_mediasw = &tlp_2114x_isv_mediasw;
    378 		} else if (tlp_parse_old_srom(sc, enaddr) == 0) {
    379 			/*
    380 			 * Not an ISV SROM, and not in old DEC Address
    381 			 * ROM format.  Try to snarf it out of the CIS.
    382 			 */
    383 			if (ca->ca_cis.funce.network.netid_present == 0)
    384 				goto cant_cope;
    385 
    386 			/* Grab the MAC address from the CIS. */
    387 			memcpy(enaddr, ca->ca_cis.funce.network.netid,
    388 			    sizeof(enaddr));
    389 		}
    390 
    391 		/*
    392 		 * Deal with any quirks this board might have.
    393 		 */
    394 		tlp_cardbus_get_quirks(csc, enaddr, tlp_cardbus_21142_quirks);
    395 
    396 		/*
    397 		 * If we don't already have a media switch, default to
    398 		 * MII-over-SIO, with no special reset routine.
    399 		 */
    400 		if (sc->sc_mediasw == NULL) {
    401 			printf("%s: defaulting to MII-over-SIO; no bets...\n",
    402 			    device_xname(&sc->sc_dev));
    403 			sc->sc_mediasw = &tlp_sio_mii_mediasw;
    404 		}
    405 		break;
    406 
    407 	case TULIP_CHIP_AN983:
    408 	case TULIP_CHIP_AN985:
    409 		/*
    410 		 * The ADMtek AN985's Ethernet address is located
    411 		 * at offset 8 of its EEPROM.
    412 		 */
    413 		memcpy(enaddr, &sc->sc_srom[8], ETHER_ADDR_LEN);
    414 
    415 		/*
    416 		 * The ADMtek AN985 can be configured in Single-Chip
    417 		 * mode or MAC-only mode.  Single-Chip uses the built-in
    418 		 * PHY, MAC-only has an external PHY (usually HomePNA).
    419 		 * The selection is based on an EEPROM setting, and both
    420 		 * PHYs are access via MII attached to SIO.
    421 		 *
    422 		 * The AN985 "ghosts" the internal PHY onto all
    423 		 * MII addresses, so we have to use a media init
    424 		 * routine that limits the search.
    425 		 * XXX How does this work with MAC-only mode?
    426 		 */
    427 		sc->sc_mediasw = &tlp_an985_mediasw;
    428 		break;
    429 
    430 	case TULIP_CHIP_X3201_3:
    431 		/*
    432 		 * The X3201 doesn't have an SROM.  Lift the MAC address
    433 		 * from the CIS.  Also, we have a special media switch:
    434 		 * MII-on-SIO, plus some special GPIO setup.
    435 		 */
    436 		memcpy(enaddr, ca->ca_cis.funce.network.netid, sizeof(enaddr));
    437 		sc->sc_reset = tlp_cardbus_x3201_reset;
    438 		sc->sc_mediasw = &tlp_sio_mii_mediasw;
    439 		break;
    440 
    441 	default:
    442  cant_cope:
    443 		printf("%s: sorry, unable to handle your board\n",
    444 		    device_xname(&sc->sc_dev));
    445 		return;
    446 	}
    447 
    448 	/* Remember which interrupt line. */
    449 	csc->sc_intrline = ca->ca_intrline;
    450 
    451 	/*
    452 	 * Finish off the attach.
    453 	 */
    454 	tlp_attach(sc, enaddr);
    455 
    456 	/*
    457 	 * Power down the socket.
    458 	 */
    459 	Cardbus_function_disable(csc->sc_ct);
    460 }
    461 
    462 int
    463 tlp_cardbus_detach(struct device *self, int flags)
    464 {
    465 	struct tulip_cardbus_softc *csc = device_private(self);
    466 	struct tulip_softc *sc = &csc->sc_tulip;
    467 	struct cardbus_devfunc *ct = csc->sc_ct;
    468 	int rv;
    469 
    470 #if defined(DIAGNOSTIC)
    471 	if (ct == NULL)
    472 		panic("%s: data structure lacks", device_xname(&sc->sc_dev));
    473 #endif
    474 
    475 	rv = tlp_detach(sc);
    476 	if (rv)
    477 		return (rv);
    478 
    479 	/*
    480 	 * Unhook the interrupt handler.
    481 	 */
    482 	if (csc->sc_ih != NULL)
    483 		cardbus_intr_disestablish(ct->ct_cc, ct->ct_cf, csc->sc_ih);
    484 
    485 	/*
    486 	 * Release bus space and close window.
    487 	 */
    488 	if (csc->sc_bar_reg != 0)
    489 		Cardbus_mapreg_unmap(ct, csc->sc_bar_reg,
    490 		    sc->sc_st, sc->sc_sh, csc->sc_mapsize);
    491 
    492 	return (0);
    493 }
    494 
    495 int
    496 tlp_cardbus_enable(struct tulip_softc *sc)
    497 {
    498 	struct tulip_cardbus_softc *csc = (void *) sc;
    499 	cardbus_devfunc_t ct = csc->sc_ct;
    500 	cardbus_chipset_tag_t cc = ct->ct_cc;
    501 	cardbus_function_tag_t cf = ct->ct_cf;
    502 
    503 	/*
    504 	 * Power on the socket.
    505 	 */
    506 	Cardbus_function_enable(ct);
    507 
    508 	/*
    509 	 * Set up the PCI configuration registers.
    510 	 */
    511 	tlp_cardbus_setup(csc);
    512 
    513 	/*
    514 	 * Map and establish the interrupt.
    515 	 */
    516 	csc->sc_ih = cardbus_intr_establish(cc, cf, csc->sc_intrline, IPL_NET,
    517 	    tlp_intr, sc);
    518 	if (csc->sc_ih == NULL) {
    519 		aprint_error_dev(&sc->sc_dev,
    520 				 "unable to establish interrupt\n");
    521 		Cardbus_function_disable(csc->sc_ct);
    522 		return (1);
    523 	}
    524 	return (0);
    525 }
    526 
    527 void
    528 tlp_cardbus_disable(struct tulip_softc *sc)
    529 {
    530 	struct tulip_cardbus_softc *csc = (void *) sc;
    531 	cardbus_devfunc_t ct = csc->sc_ct;
    532 	cardbus_chipset_tag_t cc = ct->ct_cc;
    533 	cardbus_function_tag_t cf = ct->ct_cf;
    534 
    535 	/* Unhook the interrupt handler. */
    536 	cardbus_intr_disestablish(cc, cf, csc->sc_ih);
    537 	csc->sc_ih = NULL;
    538 
    539 	/* Power down the socket. */
    540 	Cardbus_function_disable(ct);
    541 }
    542 
    543 void
    544 tlp_cardbus_power(struct tulip_softc *sc, int why)
    545 {
    546 
    547 	switch (why) {
    548 	case PWR_RESUME:
    549 		tlp_cardbus_enable(sc);
    550 		break;
    551 	case PWR_SUSPEND:
    552 		tlp_cardbus_disable(sc);
    553 		break;
    554 	}
    555 }
    556 
    557 void
    558 tlp_cardbus_setup(struct tulip_cardbus_softc *csc)
    559 {
    560 	struct tulip_softc *sc = &csc->sc_tulip;
    561 	cardbus_devfunc_t ct = csc->sc_ct;
    562 	cardbus_chipset_tag_t cc = ct->ct_cc;
    563 	cardbus_function_tag_t cf = ct->ct_cf;
    564 	pcireg_t reg;
    565 
    566 	/*
    567 	 * Check to see if the device is in power-save mode, and
    568 	 * bring it out if necessary.
    569 	 */
    570 	switch (sc->sc_chip) {
    571 	case TULIP_CHIP_21142:
    572 	case TULIP_CHIP_21143:
    573 	case TULIP_CHIP_X3201_3:
    574 		/*
    575 		 * Clear the "sleep mode" bit in the CFDA register.
    576 		 */
    577 		reg = cardbus_conf_read(cc, cf, csc->sc_tag, TULIP_PCI_CFDA);
    578 		if (reg & (CFDA_SLEEP|CFDA_SNOOZE))
    579 			cardbus_conf_write(cc, cf, csc->sc_tag, TULIP_PCI_CFDA,
    580 			    reg & ~(CFDA_SLEEP|CFDA_SNOOZE));
    581 		break;
    582 
    583 	default:
    584 		/* Nothing. -- to make gcc happy */
    585 		break;
    586 	}
    587 
    588 	(void)cardbus_set_powerstate(ct, csc->sc_tag, PCI_PWR_D0);
    589 
    590 	/* Program the BAR. */
    591 	cardbus_conf_write(cc, cf, csc->sc_tag, csc->sc_bar_reg,
    592 	    csc->sc_bar_val);
    593 
    594 	/* Make sure the right access type is on the CardBus bridge. */
    595 	(*ct->ct_cf->cardbus_ctrl)(cc, csc->sc_cben);
    596 	(*ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE);
    597 
    598 	/* Enable the appropriate bits in the PCI CSR. */
    599 	reg = cardbus_conf_read(cc, cf, csc->sc_tag, PCI_COMMAND_STATUS_REG);
    600 	reg &= ~(PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE);
    601 	reg |= csc->sc_csr;
    602 	cardbus_conf_write(cc, cf, csc->sc_tag, PCI_COMMAND_STATUS_REG, reg);
    603 
    604 	/*
    605 	 * Make sure the latency timer is set to some reasonable
    606 	 * value.
    607 	 */
    608 	reg = cardbus_conf_read(cc, cf, csc->sc_tag, PCI_BHLC_REG);
    609 	if (PCI_LATTIMER(reg) < 0x20) {
    610 		reg &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
    611 		reg |= (0x20 << PCI_LATTIMER_SHIFT);
    612 		cardbus_conf_write(cc, cf, csc->sc_tag, PCI_BHLC_REG, reg);
    613 	}
    614 }
    615 
    616 void
    617 tlp_cardbus_x3201_reset(struct tulip_softc *sc)
    618 {
    619 	u_int32_t reg;
    620 
    621 	reg = TULIP_READ(sc, CSR_SIAGEN);
    622 
    623 	/* make GP[2,0] outputs */
    624 	TULIP_WRITE(sc, CSR_SIAGEN, (reg & ~SIAGEN_MD) | SIAGEN_CWE |
    625 	    0x00050000);
    626 	TULIP_WRITE(sc, CSR_SIAGEN, (reg & ~SIAGEN_CWE) | SIAGEN_MD);
    627 }
    628 
    629 void
    630 tlp_cardbus_lxt_quirks(struct tulip_cardbus_softc *csc,
    631     const u_int8_t *enaddr)
    632 {
    633 	struct tulip_softc *sc = &csc->sc_tulip;
    634 
    635 	sc->sc_mediasw = &tlp_sio_mii_mediasw;
    636 }
    637