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