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