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