Home | History | Annotate | Line # | Download | only in cardbus
if_rtk_cardbus.c revision 1.15.2.5
      1  1.15.2.5    skrll /*	$NetBSD: if_rtk_cardbus.c,v 1.15.2.5 2005/03/04 16:41:05 skrll Exp $	*/
      2       1.2  thorpej 
      3       1.1     haya /*
      4       1.1     haya  * Copyright (c) 2000 Masanori Kanaoka
      5       1.1     haya  * All rights reserved.
      6       1.1     haya  *
      7       1.1     haya  * Redistribution and use in source and binary forms, with or without
      8       1.1     haya  * modification, are permitted provided that the following conditions
      9       1.1     haya  * are met:
     10       1.1     haya  * 1. Redistributions of source code must retain the above copyright
     11       1.1     haya  *    notice, this list of conditions and the following disclaimer.
     12       1.1     haya  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1     haya  *    notice, this list of conditions and the following disclaimer in the
     14       1.1     haya  *    documentation and/or other materials provided with the distribution.
     15       1.1     haya  * 3. The name of the author may not be used to endorse or promote products
     16       1.1     haya  *    derived from this software without specific prior written permission.
     17       1.1     haya  *
     18       1.1     haya  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19       1.1     haya  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20       1.1     haya  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21       1.1     haya  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22       1.1     haya  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23       1.1     haya  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24       1.1     haya  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25       1.1     haya  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26       1.1     haya  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     27       1.1     haya  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28       1.1     haya  */
     29       1.1     haya 
     30       1.1     haya /*
     31       1.1     haya  * if_rtk_cardbus.c:
     32  1.15.2.1    skrll  *	Cardbus specific routines for Realtek 8139 ethernet adapter.
     33  1.15.2.5    skrll  *	Tested for
     34       1.1     haya  *		- elecom-Laneed	LD-10/100CBA (Accton MPX5030)
     35  1.15.2.1    skrll  *		- MELCO		LPC3-TX-CB   (Realtek 8139)
     36       1.1     haya  */
     37       1.6    lukem 
     38       1.6    lukem #include <sys/cdefs.h>
     39  1.15.2.5    skrll __KERNEL_RCSID(0, "$NetBSD: if_rtk_cardbus.c,v 1.15.2.5 2005/03/04 16:41:05 skrll Exp $");
     40       1.1     haya 
     41       1.1     haya #include "opt_inet.h"
     42       1.1     haya #include "opt_ns.h"
     43       1.1     haya #include "bpfilter.h"
     44       1.1     haya #include "rnd.h"
     45       1.1     haya 
     46       1.1     haya #include <sys/param.h>
     47       1.1     haya #include <sys/systm.h>
     48       1.1     haya #include <sys/callout.h>
     49       1.1     haya #include <sys/device.h>
     50       1.1     haya #include <sys/sockio.h>
     51       1.1     haya #include <sys/mbuf.h>
     52       1.1     haya #include <sys/malloc.h>
     53       1.1     haya #include <sys/kernel.h>
     54       1.1     haya #include <sys/socket.h>
     55       1.1     haya 
     56       1.1     haya #include <net/if.h>
     57       1.1     haya #include <net/if_arp.h>
     58       1.1     haya #include <net/if_ether.h>
     59       1.1     haya #include <net/if_dl.h>
     60       1.1     haya #include <net/if_media.h>
     61       1.1     haya #ifdef INET
     62       1.1     haya #include <netinet/in.h>
     63       1.1     haya #include <netinet/if_inarp.h>
     64       1.1     haya #endif
     65       1.1     haya #ifdef NS
     66       1.1     haya #include <netns/ns.h>
     67       1.1     haya #include <netns/ns_if.h>
     68       1.1     haya #endif
     69       1.1     haya 
     70       1.1     haya #if NBPFILTER > 0
     71       1.1     haya #include <net/bpf.h>
     72       1.1     haya #endif
     73       1.1     haya #if NRND > 0
     74       1.1     haya #include <sys/rnd.h>
     75       1.1     haya #endif
     76       1.1     haya 
     77       1.1     haya #include <machine/bus.h>
     78       1.1     haya 
     79       1.1     haya #include <dev/pci/pcireg.h>
     80       1.1     haya #include <dev/pci/pcivar.h>
     81       1.1     haya #include <dev/pci/pcidevs.h>
     82       1.1     haya 
     83       1.1     haya #include <dev/cardbus/cardbusvar.h>
     84  1.15.2.1    skrll #include <dev/pci/pcidevs.h>
     85       1.1     haya 
     86       1.1     haya #include <dev/mii/mii.h>
     87       1.1     haya #include <dev/mii/miivar.h>
     88       1.1     haya 
     89       1.1     haya /*
     90       1.1     haya  * Default to using PIO access for this driver. On SMP systems,
     91       1.1     haya  * there appear to be problems with memory mapped mode: it looks like
     92       1.1     haya  * doing too many memory mapped access back to back in rapid succession
     93       1.1     haya  * can hang the bus. I'm inclined to blame this on crummy design/construction
     94  1.15.2.1    skrll  * on the part of Realtek. Memory mapped mode does appear to work on
     95       1.1     haya  * uniprocessor systems though.
     96       1.1     haya  */
     97  1.15.2.5    skrll #define RTK_USEIOSPACE
     98       1.1     haya 
     99       1.1     haya #include <dev/ic/rtl81x9reg.h>
    100       1.1     haya #include <dev/ic/rtl81x9var.h>
    101       1.1     haya 
    102       1.1     haya /*
    103       1.1     haya  * Various supported device vendors/types and their names.
    104       1.1     haya  */
    105       1.2  thorpej static const struct rtk_type rtk_cardbus_devs[] = {
    106  1.15.2.1    skrll 	{ PCI_VENDOR_ACCTON, PCI_PRODUCT_ACCTON_MPX5030,
    107  1.15.2.1    skrll 		RTK_8139, "Accton MPX 5030/5038 10/100BaseTX" },
    108  1.15.2.1    skrll 	{ PCI_VENDOR_DLINK, PCI_PRODUCT_DLINK_DFE690TXD,
    109  1.15.2.1    skrll 		RTK_8139, "D-Link DFE-690TXD 10/100BaseTX" },
    110  1.15.2.1    skrll 	{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8138,
    111  1.15.2.1    skrll 		RTK_8139, "Realtek 8138 10/100BaseTX" },
    112  1.15.2.1    skrll 	{ PCI_VENDOR_REALTEK, PCI_PRODUCT_REALTEK_RT8139,
    113  1.15.2.1    skrll 		RTK_8139, "Realtek 8139 10/100BaseTX" },
    114  1.15.2.1    skrll 	{ PCI_VENDOR_COREGA, PCI_PRODUCT_COREGA_CB_TXD,
    115  1.15.2.1    skrll 		RTK_8139, "Corega FEther CB-TXD 10/100BaseTX" },
    116  1.15.2.1    skrll 	{ PCI_VENDOR_COREGA, PCI_PRODUCT_COREGA_2CB_TXD,
    117  1.15.2.1    skrll 		RTK_8139, "Corega FEther II CB-TXD 10/100BaseTX" },
    118  1.15.2.1    skrll 	{ PCI_VENDOR_PLANEX, PCI_PRODUCT_PLANEX_FNW_3603_TX,
    119  1.15.2.1    skrll 		RTK_8139, "Planex FNW-3603 10/100BaseTX" },
    120  1.15.2.1    skrll 	{ PCI_VENDOR_PLANEX, PCI_PRODUCT_PLANEX_FNW_3800_TX,
    121  1.15.2.1    skrll 		RTK_8139, "Planex 10/100BaseTX FNW-3800-TX" },
    122  1.15.2.1    skrll 	{ PCI_VENDOR_ABOCOM, PCI_PRODUCT_ABOCOM_FE2000VX,
    123  1.15.2.1    skrll 		RTK_8139, "AboCom FE2000VX 10/100BaseTX" },
    124      1.14   ichiro 
    125  1.15.2.1    skrll 	{ 0, 0, 0, NULL }
    126       1.1     haya };
    127       1.1     haya 
    128  1.15.2.4    skrll static int rtk_cardbus_match(struct device *, struct cfdata *, void *);
    129  1.15.2.4    skrll static void rtk_cardbus_attach(struct device *, struct device *, void *);
    130  1.15.2.4    skrll static int rtk_cardbus_detach(struct device *, int);
    131       1.1     haya 
    132       1.2  thorpej struct rtk_cardbus_softc {
    133  1.15.2.5    skrll 	struct rtk_softc sc_rtk;	/* real rtk softc */
    134       1.1     haya 
    135       1.1     haya 	/* CardBus-specific goo. */
    136       1.1     haya 	void *sc_ih;
    137       1.1     haya 	cardbus_devfunc_t sc_ct;
    138       1.1     haya 	cardbustag_t sc_tag;
    139       1.1     haya 	int sc_csr;
    140       1.1     haya 	int sc_cben;
    141       1.1     haya 	int sc_bar_reg;
    142       1.1     haya 	pcireg_t sc_bar_val;
    143       1.1     haya 	bus_size_t sc_mapsize;
    144       1.1     haya 	int sc_intrline;
    145       1.1     haya };
    146       1.1     haya 
    147      1.10  thorpej CFATTACH_DECL(rtk_cardbus, sizeof(struct rtk_cardbus_softc),
    148      1.11  thorpej     rtk_cardbus_match, rtk_cardbus_attach, rtk_cardbus_detach, rtk_activate);
    149       1.1     haya 
    150       1.3  tsutsui const struct rtk_type *rtk_cardbus_lookup
    151  1.15.2.4    skrll 	(const struct cardbus_attach_args *);
    152       1.3  tsutsui 
    153  1.15.2.4    skrll void rtk_cardbus_setup		(struct rtk_cardbus_softc *);
    154       1.3  tsutsui 
    155  1.15.2.4    skrll int rtk_cardbus_enable		(struct rtk_softc *);
    156  1.15.2.4    skrll void rtk_cardbus_disable(struct rtk_softc *);
    157  1.15.2.4    skrll void rtk_cardbus_power		(struct rtk_softc *, int);
    158       1.2  thorpej const struct rtk_type *
    159       1.2  thorpej rtk_cardbus_lookup(ca)
    160       1.1     haya 	const struct cardbus_attach_args *ca;
    161       1.1     haya {
    162       1.2  thorpej 	const struct rtk_type *t;
    163       1.1     haya 
    164  1.15.2.5    skrll 	for (t = rtk_cardbus_devs; t->rtk_name != NULL; t++){
    165       1.2  thorpej 		if (CARDBUS_VENDOR(ca->ca_id) == t->rtk_vid &&
    166       1.2  thorpej 		    CARDBUS_PRODUCT(ca->ca_id) == t->rtk_did) {
    167       1.1     haya 			return (t);
    168       1.1     haya 		}
    169       1.1     haya 	}
    170       1.1     haya 	return (NULL);
    171       1.1     haya }
    172       1.1     haya 
    173       1.1     haya int
    174       1.2  thorpej rtk_cardbus_match(parent, match, aux)
    175       1.1     haya 	struct device *parent;
    176       1.1     haya 	struct cfdata *match;
    177       1.1     haya 	void *aux;
    178       1.1     haya {
    179       1.1     haya 	struct cardbus_attach_args *ca = aux;
    180       1.1     haya 
    181       1.2  thorpej 	if (rtk_cardbus_lookup(ca) != NULL)
    182       1.1     haya 		return (1);
    183       1.2  thorpej 
    184       1.1     haya 	return (0);
    185       1.1     haya }
    186       1.1     haya 
    187       1.1     haya 
    188       1.1     haya void
    189       1.2  thorpej rtk_cardbus_attach(parent, self, aux)
    190       1.1     haya 	struct device *parent, *self;
    191       1.1     haya 	void *aux;
    192       1.1     haya {
    193       1.2  thorpej 	struct rtk_cardbus_softc *csc = (struct rtk_cardbus_softc *)self;
    194       1.2  thorpej 	struct rtk_softc *sc = &csc->sc_rtk;
    195       1.1     haya 	struct cardbus_attach_args *ca = aux;
    196       1.1     haya 	cardbus_devfunc_t ct = ca->ca_ct;
    197       1.2  thorpej 	const struct rtk_type *t;
    198       1.1     haya 	bus_addr_t adr;
    199       1.1     haya 
    200       1.1     haya 	sc->sc_dmat = ca->ca_dmat;
    201       1.1     haya 	csc->sc_ct = ct;
    202       1.1     haya 	csc->sc_tag = ca->ca_tag;
    203       1.1     haya 	csc->sc_intrline = ca->ca_intrline;
    204       1.1     haya 
    205  1.15.2.5    skrll 	t = rtk_cardbus_lookup(ca);
    206  1.15.2.5    skrll 	if (t == NULL) {
    207  1.15.2.5    skrll 		printf("\n");
    208       1.2  thorpej 		panic("rtk_cardbus_attach: impossible");
    209  1.15.2.5    skrll 	 }
    210  1.15.2.5    skrll 	printf(": %s\n", t->rtk_name);
    211  1.15.2.5    skrll 
    212       1.3  tsutsui 	/*
    213       1.3  tsutsui 	 * Power management hooks.
    214       1.3  tsutsui 	 */
    215       1.3  tsutsui 	sc->sc_enable = rtk_cardbus_enable;
    216       1.3  tsutsui 	sc->sc_disable = rtk_cardbus_disable;
    217       1.3  tsutsui 	sc->sc_power = rtk_cardbus_power;
    218       1.3  tsutsui 
    219       1.3  tsutsui 	/*
    220       1.3  tsutsui 	 * Map control/status registers.
    221       1.3  tsutsui 	 */
    222       1.3  tsutsui 	csc->sc_csr = CARDBUS_COMMAND_MASTER_ENABLE;
    223       1.3  tsutsui #ifdef RTK_USEIOSPACE
    224       1.3  tsutsui 	if (Cardbus_mapreg_map(ct, RTK_PCI_LOIO, CARDBUS_MAPREG_TYPE_IO, 0,
    225       1.3  tsutsui 	    &sc->rtk_btag, &sc->rtk_bhandle, &adr, &csc->sc_mapsize) == 0) {
    226       1.3  tsutsui #if rbus
    227       1.3  tsutsui #else
    228       1.3  tsutsui 		(*ct->ct_cf->cardbus_io_open)(cc, 0, adr, adr+csc->sc_mapsize);
    229       1.3  tsutsui #endif
    230       1.3  tsutsui 		csc->sc_cben = CARDBUS_IO_ENABLE;
    231       1.3  tsutsui 		csc->sc_csr |= CARDBUS_COMMAND_IO_ENABLE;
    232       1.3  tsutsui 		csc->sc_bar_reg = RTK_PCI_LOIO;
    233       1.3  tsutsui 		csc->sc_bar_val = adr | CARDBUS_MAPREG_TYPE_IO;
    234       1.3  tsutsui 	}
    235       1.3  tsutsui #else
    236       1.3  tsutsui 	if (Cardbus_mapreg_map(ct, RTK_PCI_LOMEM, CARDBUS_MAPREG_TYPE_MEM, 0,
    237       1.3  tsutsui 	    &sc->rtk_btag, &sc->rtk_bhandle, &adr, &csc->sc_mapsize) == 0) {
    238       1.3  tsutsui #if rbus
    239       1.3  tsutsui #else
    240       1.3  tsutsui 		(*ct->ct_cf->cardbus_mem_open)(cc, 0, adr, adr+csc->sc_mapsize);
    241       1.3  tsutsui #endif
    242       1.3  tsutsui 		csc->sc_cben = CARDBUS_MEM_ENABLE;
    243       1.3  tsutsui 		csc->sc_csr |= CARDBUS_COMMAND_MEM_ENABLE;
    244       1.3  tsutsui 		csc->sc_bar_reg = RTK_PCI_LOMEM;
    245       1.3  tsutsui 		csc->sc_bar_val = adr | CARDBUS_MAPREG_TYPE_MEM;
    246       1.3  tsutsui 	}
    247       1.3  tsutsui #endif
    248       1.3  tsutsui 	else {
    249       1.3  tsutsui 		printf("%s: unable to map deviceregisters\n",
    250       1.3  tsutsui 			 sc->sc_dev.dv_xname);
    251       1.3  tsutsui 		return;
    252       1.3  tsutsui 	}
    253       1.3  tsutsui 	/*
    254       1.3  tsutsui 	 * Handle power management nonsense and initialize the
    255       1.3  tsutsui 	 * configuration registers.
    256       1.3  tsutsui 	 */
    257       1.3  tsutsui 	rtk_cardbus_setup(csc);
    258  1.15.2.1    skrll 	sc->rtk_type = t->rtk_basetype;
    259       1.3  tsutsui 
    260       1.3  tsutsui 	rtk_attach(sc);
    261       1.3  tsutsui 
    262       1.3  tsutsui 	/*
    263       1.3  tsutsui 	 * Power down the socket.
    264       1.3  tsutsui 	 */
    265       1.3  tsutsui 	Cardbus_function_disable(csc->sc_ct);
    266       1.3  tsutsui }
    267       1.3  tsutsui 
    268  1.15.2.5    skrll int
    269       1.3  tsutsui rtk_cardbus_detach(self, flags)
    270       1.3  tsutsui 	struct device *self;
    271       1.3  tsutsui 	int flags;
    272       1.3  tsutsui {
    273       1.3  tsutsui 	struct rtk_cardbus_softc *csc = (void *) self;
    274       1.3  tsutsui 	struct rtk_softc *sc = &csc->sc_rtk;
    275       1.3  tsutsui 	struct cardbus_devfunc *ct = csc->sc_ct;
    276       1.3  tsutsui 	int	rv;
    277       1.3  tsutsui 
    278       1.3  tsutsui #ifdef DIAGNOSTIC
    279       1.3  tsutsui 	if (ct == NULL)
    280       1.8   provos 		panic("%s: data structure lacks", sc->sc_dev.dv_xname);
    281       1.3  tsutsui #endif
    282       1.3  tsutsui 	rv = rtk_detach(sc);
    283       1.3  tsutsui 	if (rv)
    284       1.3  tsutsui 		return (rv);
    285       1.3  tsutsui 	/*
    286  1.15.2.1    skrll 	 * Unhook the interrupt handler.
    287       1.3  tsutsui 	 */
    288       1.3  tsutsui 	if (csc->sc_ih != NULL)
    289       1.3  tsutsui 		cardbus_intr_disestablish(ct->ct_cc, ct->ct_cf, csc->sc_ih);
    290  1.15.2.5    skrll 
    291       1.3  tsutsui 	/*
    292       1.3  tsutsui 	 * Release bus space and close window.
    293       1.3  tsutsui 	 */
    294       1.3  tsutsui 	if (csc->sc_bar_reg != 0)
    295       1.3  tsutsui 		Cardbus_mapreg_unmap(ct, csc->sc_bar_reg,
    296       1.3  tsutsui 			sc->rtk_btag, sc->rtk_bhandle, csc->sc_mapsize);
    297       1.3  tsutsui 
    298       1.3  tsutsui 	return (0);
    299       1.3  tsutsui }
    300       1.3  tsutsui 
    301  1.15.2.5    skrll void
    302       1.3  tsutsui rtk_cardbus_setup(csc)
    303       1.3  tsutsui 	struct rtk_cardbus_softc *csc;
    304       1.3  tsutsui {
    305       1.3  tsutsui 	struct rtk_softc *sc = &csc->sc_rtk;
    306       1.3  tsutsui 	cardbus_devfunc_t ct = csc->sc_ct;
    307       1.3  tsutsui 	cardbus_chipset_tag_t cc = ct->ct_cc;
    308       1.3  tsutsui 	cardbus_function_tag_t cf = ct->ct_cf;
    309       1.3  tsutsui 	pcireg_t	reg,command;
    310       1.3  tsutsui 	int		pmreg;
    311       1.1     haya 
    312       1.1     haya 	/*
    313       1.1     haya 	 * Handle power management nonsense.
    314       1.1     haya 	 */
    315       1.1     haya 	if (cardbus_get_capability(cc, cf, csc->sc_tag,
    316       1.1     haya 	    PCI_CAP_PWRMGMT, &pmreg, 0)) {
    317  1.15.2.1    skrll 		command = cardbus_conf_read(cc, cf, csc->sc_tag,
    318  1.15.2.1    skrll 		    pmreg + PCI_PMCSR);
    319       1.3  tsutsui 		if (command & RTK_PSTATE_MASK) {
    320       1.1     haya 			pcireg_t		iobase, membase, irq;
    321       1.1     haya 
    322       1.1     haya 			/* Save important PCI config data. */
    323       1.1     haya 			iobase = cardbus_conf_read(cc, cf, csc->sc_tag,
    324       1.3  tsutsui 			    RTK_PCI_LOIO);
    325       1.1     haya 			membase = cardbus_conf_read(cc, cf,csc->sc_tag,
    326       1.3  tsutsui 			    RTK_PCI_LOMEM);
    327       1.1     haya 			irq = cardbus_conf_read(cc, cf,csc->sc_tag,
    328      1.13  tsutsui 			    CARDBUS_INTERRUPT_REG);
    329       1.1     haya 
    330       1.1     haya 			/* Reset the power state. */
    331      1.13  tsutsui 			printf("%s: chip is in D%d power mode "
    332       1.1     haya 			    "-- setting to D0\n", sc->sc_dev.dv_xname,
    333       1.3  tsutsui 			    command & RTK_PSTATE_MASK);
    334  1.15.2.1    skrll 			command &= ~RTK_PSTATE_MASK;
    335       1.1     haya 			cardbus_conf_write(cc, cf, csc->sc_tag,
    336  1.15.2.1    skrll 			    pmreg + PCI_PMCSR, command);
    337       1.1     haya 
    338       1.1     haya 			/* Restore PCI config data. */
    339       1.1     haya 			cardbus_conf_write(cc, cf, csc->sc_tag,
    340       1.3  tsutsui 			    RTK_PCI_LOIO, iobase);
    341       1.1     haya 			cardbus_conf_write(cc, cf, csc->sc_tag,
    342       1.3  tsutsui 			    RTK_PCI_LOMEM, membase);
    343       1.1     haya 			cardbus_conf_write(cc, cf, csc->sc_tag,
    344      1.13  tsutsui 			    CARDBUS_INTERRUPT_REG, irq);
    345       1.1     haya 		}
    346       1.1     haya 	}
    347       1.3  tsutsui 
    348       1.1     haya 	/* Program the BAR */
    349       1.1     haya 	cardbus_conf_write(cc, cf, csc->sc_tag,
    350       1.1     haya 		csc->sc_bar_reg, csc->sc_bar_val);
    351       1.1     haya 
    352  1.15.2.1    skrll 	/* Make sure the right access type is on the CardBus bridge. */
    353  1.15.2.1    skrll 	(*ct->ct_cf->cardbus_ctrl)(cc, csc->sc_cben);
    354  1.15.2.1    skrll 	(*ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE);
    355  1.15.2.1    skrll 
    356       1.1     haya 	/* Enable the appropriate bits in the CARDBUS CSR. */
    357  1.15.2.5    skrll 	reg = cardbus_conf_read(cc, cf, csc->sc_tag,
    358       1.1     haya 	    CARDBUS_COMMAND_STATUS_REG);
    359       1.1     haya 	reg &= ~(CARDBUS_COMMAND_IO_ENABLE|CARDBUS_COMMAND_MEM_ENABLE);
    360       1.1     haya 	reg |= csc->sc_csr;
    361  1.15.2.5    skrll 	cardbus_conf_write(cc, cf, csc->sc_tag,
    362       1.1     haya 	    CARDBUS_COMMAND_STATUS_REG, reg);
    363       1.1     haya 
    364       1.1     haya 	/*
    365       1.1     haya 	 * Make sure the latency timer is set to some reasonable
    366       1.1     haya 	 * value.
    367       1.1     haya 	 */
    368       1.1     haya 	reg = cardbus_conf_read(cc, cf, csc->sc_tag, CARDBUS_BHLC_REG);
    369       1.1     haya 	if (CARDBUS_LATTIMER(reg) < 0x20) {
    370       1.1     haya 		reg &= ~(CARDBUS_LATTIMER_MASK << CARDBUS_LATTIMER_SHIFT);
    371       1.1     haya 		reg |= (0x20 << CARDBUS_LATTIMER_SHIFT);
    372       1.1     haya 		cardbus_conf_write(cc, cf, csc->sc_tag, CARDBUS_BHLC_REG, reg);
    373       1.1     haya 	}
    374       1.3  tsutsui }
    375       1.1     haya 
    376  1.15.2.5    skrll int
    377       1.3  tsutsui rtk_cardbus_enable(sc)
    378       1.3  tsutsui 	struct rtk_softc *sc;
    379       1.3  tsutsui {
    380       1.3  tsutsui 	struct rtk_cardbus_softc *csc = (void *) sc;
    381       1.3  tsutsui 	cardbus_devfunc_t ct = csc->sc_ct;
    382       1.3  tsutsui 	cardbus_chipset_tag_t cc = ct->ct_cc;
    383       1.3  tsutsui 	cardbus_function_tag_t cf = ct->ct_cf;
    384       1.3  tsutsui 
    385       1.3  tsutsui 	/*
    386       1.3  tsutsui 	 * Power on the socket.
    387       1.3  tsutsui 	 */
    388       1.3  tsutsui 	Cardbus_function_enable(ct);
    389       1.3  tsutsui 
    390       1.3  tsutsui 	/*
    391       1.3  tsutsui 	 * Set up the PCI configuration registers.
    392       1.3  tsutsui 	 */
    393       1.3  tsutsui 	rtk_cardbus_setup(csc);
    394       1.1     haya 
    395       1.3  tsutsui 	/*
    396       1.3  tsutsui 	 * Map and establish the interrupt.
    397       1.3  tsutsui 	 */
    398       1.3  tsutsui 	csc->sc_ih = cardbus_intr_establish(cc, cf, csc->sc_intrline,
    399       1.3  tsutsui 		IPL_NET, rtk_intr, sc);
    400       1.1     haya 	if (csc->sc_ih == NULL) {
    401       1.1     haya 		printf("%s: unable to establish interrupt at %d\n",
    402       1.3  tsutsui 			sc->sc_dev.dv_xname, csc->sc_intrline);
    403       1.3  tsutsui 		Cardbus_function_disable(csc->sc_ct);
    404       1.3  tsutsui 		return (1);
    405       1.1     haya 	}
    406       1.3  tsutsui 	printf("%s: interrupting at %d\n", sc->sc_dev.dv_xname,
    407       1.3  tsutsui 		csc->sc_intrline);
    408       1.3  tsutsui 	return (0);
    409       1.3  tsutsui }
    410       1.3  tsutsui 
    411  1.15.2.5    skrll void
    412       1.3  tsutsui rtk_cardbus_disable(sc)
    413       1.3  tsutsui 	struct rtk_softc *sc;
    414       1.3  tsutsui {
    415       1.3  tsutsui 	struct rtk_cardbus_softc *csc = (void *) sc;
    416       1.3  tsutsui 	cardbus_devfunc_t ct = csc->sc_ct;
    417       1.3  tsutsui 	cardbus_chipset_tag_t cc = ct->ct_cc;
    418       1.3  tsutsui 	cardbus_function_tag_t cf = ct->ct_cf;
    419       1.3  tsutsui 
    420       1.3  tsutsui 	/* Unhook the interrupt handler. */
    421       1.3  tsutsui 	cardbus_intr_disestablish(cc, cf, csc->sc_ih);
    422  1.15.2.1    skrll 	csc->sc_ih = NULL;
    423       1.1     haya 
    424       1.3  tsutsui 	/* Power down the socket. */
    425       1.3  tsutsui 	Cardbus_function_disable(ct);
    426       1.3  tsutsui }
    427       1.3  tsutsui 
    428  1.15.2.5    skrll void
    429       1.3  tsutsui rtk_cardbus_power(sc, why)
    430       1.3  tsutsui 	struct rtk_softc *sc;
    431       1.3  tsutsui 	int why;
    432       1.3  tsutsui {
    433       1.3  tsutsui 	struct rtk_cardbus_softc *csc = (void *) sc;
    434       1.3  tsutsui 
    435       1.3  tsutsui 	if (why == PWR_RESUME) {
    436       1.3  tsutsui 		/*
    437       1.3  tsutsui 		 * Give the PCI configuration registers a kick
    438       1.3  tsutsui 		 * in the head.
    439       1.3  tsutsui 		 */
    440       1.3  tsutsui #ifdef DIAGNOSTIC
    441       1.3  tsutsui 		if (RTK_IS_ENABLED(sc) == 0)
    442       1.3  tsutsui 			panic("rtk_cardbus_power");
    443       1.3  tsutsui #endif
    444       1.3  tsutsui 		rtk_cardbus_setup(csc);
    445       1.3  tsutsui 	}
    446       1.1     haya }
    447