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