Home | History | Annotate | Line # | Download | only in cardbus
if_ex_cardbus.c revision 1.32
      1  1.32   mycroft /*	$NetBSD: if_ex_cardbus.c,v 1.32 2004/07/22 17:30:43 mycroft Exp $	*/
      2   1.1      haya 
      3   1.1      haya /*
      4   1.1      haya  * CardBus specific routines for 3Com 3C575-family CardBus ethernet adapter
      5   1.1      haya  *
      6   1.1      haya  * Copyright (c) 1998 and 1999
      7   1.1      haya  *       HAYAKAWA Koichi.  All rights reserved.
      8   1.1      haya  *
      9   1.1      haya  * Redistribution and use in source and binary forms, with or without
     10   1.1      haya  * modification, are permitted provided that the following conditions
     11   1.1      haya  * are met:
     12   1.1      haya  * 1. Redistributions of source code must retain the above copyright
     13   1.1      haya  *    notice, this list of conditions and the following disclaimer.
     14   1.1      haya  * 2. Redistributions in binary form must reproduce the above copyright
     15   1.1      haya  *    notice, this list of conditions and the following disclaimer in the
     16   1.1      haya  *    documentation and/or other materials provided with the distribution.
     17   1.1      haya  * 3. All advertising materials mentioning features or use of this software
     18   1.1      haya  *    must display the following acknowledgement:
     19   1.1      haya  *      This product includes software developed by the author.
     20   1.1      haya  * 4. Neither the name of the author nor the names of any co-contributors
     21   1.1      haya  *    may be used to endorse or promote products derived from this software
     22   1.1      haya  *    without specific prior written permission.
     23   1.1      haya  *
     24   1.1      haya  * THIS SOFTWARE IS PROVIDED BY HAYAKAWA KOICHI ``AS IS'' AND
     25   1.1      haya  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26   1.1      haya  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27   1.1      haya  * ARE DISCLAIMED.  IN NO EVENT SHALL TAKESHI OHASHI OR CONTRIBUTORS BE LIABLE
     28   1.1      haya  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29   1.1      haya  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30   1.1      haya  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31   1.1      haya  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32   1.1      haya  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33   1.1      haya  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34   1.1      haya  * SUCH DAMAGE.
     35   1.1      haya  *
     36   1.1      haya  *
     37   1.1      haya  */
     38  1.23     lukem 
     39  1.23     lukem #include <sys/cdefs.h>
     40  1.32   mycroft __KERNEL_RCSID(0, "$NetBSD: if_ex_cardbus.c,v 1.32 2004/07/22 17:30:43 mycroft Exp $");
     41   1.1      haya 
     42  1.22       wiz /* #define EX_DEBUG 4 */	/* define to report information for debugging */
     43   1.1      haya 
     44   1.1      haya #include <sys/param.h>
     45   1.1      haya #include <sys/systm.h>
     46   1.9   thorpej #include <sys/mbuf.h>
     47   1.9   thorpej #include <sys/socket.h>
     48   1.1      haya #include <sys/ioctl.h>
     49   1.1      haya #include <sys/errno.h>
     50   1.1      haya #include <sys/syslog.h>
     51   1.9   thorpej #include <sys/select.h>
     52   1.9   thorpej #include <sys/device.h>
     53   1.1      haya 
     54   1.1      haya #include <net/if.h>
     55   1.1      haya #include <net/if_dl.h>
     56   1.9   thorpej #include <net/if_ether.h>
     57   1.1      haya #include <net/if_media.h>
     58   1.1      haya 
     59   1.1      haya #include <machine/cpu.h>
     60   1.1      haya #include <machine/bus.h>
     61   1.5      haya 
     62   1.1      haya #include <dev/cardbus/cardbusvar.h>
     63   1.1      haya #include <dev/cardbus/cardbusdevs.h>
     64   1.1      haya 
     65   1.1      haya #include <dev/mii/miivar.h>
     66   1.1      haya 
     67   1.1      haya #include <dev/ic/elink3var.h>
     68   1.1      haya #include <dev/ic/elink3reg.h>
     69   1.1      haya #include <dev/ic/elinkxlreg.h>
     70   1.1      haya #include <dev/ic/elinkxlvar.h>
     71   1.1      haya 
     72   1.1      haya #if defined DEBUG && !defined EX_DEBUG
     73   1.1      haya #define EX_DEBUG
     74   1.1      haya #endif
     75   1.1      haya 
     76   1.1      haya #if defined EX_DEBUG
     77   1.1      haya #define DPRINTF(a) printf a
     78   1.1      haya #else
     79   1.1      haya #define DPRINTF(a)
     80   1.1      haya #endif
     81   1.1      haya 
     82   1.1      haya #define CARDBUS_3C575BTX_FUNCSTAT_PCIREG  CARDBUS_BASE2_REG  /* means 0x18 */
     83   1.1      haya #define EX_CB_INTR 4		/* intr acknowledge reg. CardBus only */
     84   1.1      haya #define EX_CB_INTR_ACK 0x8000 /* intr acknowledge bit */
     85   1.1      haya 
     86   1.9   thorpej int ex_cardbus_match __P((struct device *, struct cfdata *, void *));
     87   1.9   thorpej void ex_cardbus_attach __P((struct device *, struct device *,void *));
     88   1.9   thorpej int ex_cardbus_detach __P((struct device *, int));
     89   1.9   thorpej void ex_cardbus_intr_ack __P((struct ex_softc *));
     90   1.1      haya 
     91  1.19   thorpej int ex_cardbus_enable __P((struct ex_softc *));
     92  1.19   thorpej void ex_cardbus_disable __P((struct ex_softc *));
     93  1.19   thorpej void ex_cardbus_power __P((struct ex_softc *, int));
     94   1.1      haya 
     95   1.1      haya struct ex_cardbus_softc {
     96   1.9   thorpej 	struct ex_softc sc_softc;
     97   1.1      haya 
     98   1.9   thorpej 	cardbus_devfunc_t sc_ct;
     99   1.9   thorpej 	int sc_intrline;
    100   1.9   thorpej 	u_int8_t sc_cardbus_flags;
    101   1.1      haya #define EX_REATTACH		0x01
    102   1.1      haya #define EX_ABSENT		0x02
    103   1.9   thorpej 	u_int8_t sc_cardtype;
    104  1.16      haya #define EX_CB_BOOMERANG		1
    105  1.16      haya #define EX_CB_CYCLONE		2
    106   1.1      haya 
    107   1.9   thorpej 	/* CardBus function status space.  575B requests it. */
    108   1.9   thorpej 	bus_space_tag_t sc_funct;
    109   1.9   thorpej 	bus_space_handle_t sc_funch;
    110  1.11  augustss 	bus_size_t sc_funcsize;
    111  1.11  augustss 
    112  1.11  augustss 	bus_size_t sc_mapsize;		/* the size of mapped bus space region */
    113  1.19   thorpej 
    114  1.19   thorpej 	cardbustag_t sc_tag;
    115  1.19   thorpej 
    116  1.19   thorpej 	int	sc_csr;			/* CSR bits */
    117  1.19   thorpej 	int	sc_bar_reg;		/* which BAR to use */
    118  1.19   thorpej 	pcireg_t sc_bar_val;		/* value of the BAR */
    119  1.19   thorpej 	int	sc_bar_reg1;		/* which BAR to use */
    120  1.19   thorpej 	pcireg_t sc_bar_val1;		/* value of the BAR */
    121  1.19   thorpej 
    122   1.1      haya };
    123   1.1      haya 
    124  1.26   thorpej CFATTACH_DECL(ex_cardbus, sizeof(struct ex_cardbus_softc),
    125  1.27   thorpej     ex_cardbus_match, ex_cardbus_attach, ex_cardbus_detach, ex_activate);
    126   1.9   thorpej 
    127   1.9   thorpej const struct ex_cardbus_product {
    128   1.9   thorpej 	u_int32_t	ecp_prodid;	/* CardBus product ID */
    129   1.9   thorpej 	int		ecp_flags;	/* initial softc flags */
    130   1.9   thorpej 	pcireg_t	ecp_csr;	/* PCI CSR flags */
    131   1.9   thorpej 	int		ecp_cardtype;	/* card type */
    132   1.9   thorpej 	const char	*ecp_name;	/* device name */
    133   1.9   thorpej } ex_cardbus_products[] = {
    134   1.9   thorpej 	{ CARDBUS_PRODUCT_3COM_3C575TX,
    135  1.18      fvdl 	  EX_CONF_MII | EX_CONF_EEPROM_OFF | EX_CONF_EEPROM_8BIT,
    136   1.9   thorpej 	  CARDBUS_COMMAND_IO_ENABLE | CARDBUS_COMMAND_MASTER_ENABLE,
    137  1.16      haya 	  EX_CB_BOOMERANG,
    138   1.9   thorpej 	  "3c575-TX Ethernet" },
    139   1.9   thorpej 
    140   1.9   thorpej 	{ CARDBUS_PRODUCT_3COM_3C575BTX,
    141  1.18      fvdl 	  EX_CONF_90XB|EX_CONF_MII|EX_CONF_INV_LED_POLARITY |
    142  1.18      fvdl 	    EX_CONF_EEPROM_OFF | EX_CONF_EEPROM_8BIT,
    143   1.9   thorpej 	  CARDBUS_COMMAND_IO_ENABLE | CARDBUS_COMMAND_MEM_ENABLE |
    144   1.9   thorpej 	      CARDBUS_COMMAND_MASTER_ENABLE,
    145  1.16      haya 	  EX_CB_CYCLONE,
    146   1.9   thorpej 	  "3c575B-TX Ethernet" },
    147   1.9   thorpej 
    148  1.15      haya 	{ CARDBUS_PRODUCT_3COM_3C575CTX,
    149  1.18      fvdl 	  EX_CONF_90XB | EX_CONF_PHY_POWER | EX_CONF_EEPROM_OFF |
    150  1.18      fvdl 	    EX_CONF_EEPROM_8BIT,
    151  1.15      haya 	  CARDBUS_COMMAND_IO_ENABLE | CARDBUS_COMMAND_MEM_ENABLE |
    152  1.15      haya 	      CARDBUS_COMMAND_MASTER_ENABLE,
    153  1.16      haya 	  EX_CB_CYCLONE,
    154  1.15      haya 	  "3c575CT Ethernet" },
    155  1.15      haya 
    156  1.31   mycroft 	{ CARDBUS_PRODUCT_3COM_3C656_E,
    157  1.31   mycroft 	  EX_CONF_90XB | EX_CONF_PHY_POWER | EX_CONF_EEPROM_OFF |
    158  1.32   mycroft 	    EX_CONF_EEPROM_8BIT | EX_CONF_INV_LED_POLARITY,
    159  1.31   mycroft 	  CARDBUS_COMMAND_IO_ENABLE | CARDBUS_COMMAND_MEM_ENABLE |
    160  1.31   mycroft 	      CARDBUS_COMMAND_MASTER_ENABLE,
    161  1.31   mycroft 	  EX_CB_CYCLONE,
    162  1.31   mycroft 	  "3c656-TX Ethernet" },
    163  1.31   mycroft 
    164  1.31   mycroft 	{ CARDBUS_PRODUCT_3COM_3C656B_E,
    165  1.31   mycroft 	  EX_CONF_90XB | EX_CONF_PHY_POWER | EX_CONF_EEPROM_OFF |
    166  1.32   mycroft 	    EX_CONF_EEPROM_8BIT | EX_CONF_INV_LED_POLARITY,
    167  1.31   mycroft 	  CARDBUS_COMMAND_IO_ENABLE | CARDBUS_COMMAND_MEM_ENABLE |
    168  1.31   mycroft 	      CARDBUS_COMMAND_MASTER_ENABLE,
    169  1.31   mycroft 	  EX_CB_CYCLONE,
    170  1.31   mycroft 	  "3c656B-TX Ethernet" },
    171  1.31   mycroft 
    172  1.31   mycroft 	{ CARDBUS_PRODUCT_3COM_3C656C_E,
    173  1.31   mycroft 	  EX_CONF_90XB | EX_CONF_PHY_POWER | EX_CONF_EEPROM_OFF |
    174  1.31   mycroft 	    EX_CONF_EEPROM_8BIT,
    175  1.31   mycroft 	  CARDBUS_COMMAND_IO_ENABLE | CARDBUS_COMMAND_MEM_ENABLE |
    176  1.31   mycroft 	      CARDBUS_COMMAND_MASTER_ENABLE,
    177  1.31   mycroft 	  EX_CB_CYCLONE,
    178  1.31   mycroft 	  "3c656C-TX Ethernet" },
    179  1.31   mycroft 
    180   1.9   thorpej 	{ 0,
    181  1.14   thorpej 	  0,
    182   1.9   thorpej 	  0,
    183   1.9   thorpej 	  0,
    184   1.9   thorpej 	  NULL },
    185   1.1      haya };
    186   1.1      haya 
    187  1.19   thorpej 
    188  1.19   thorpej void ex_cardbus_setup __P((struct ex_cardbus_softc *));
    189  1.19   thorpej 
    190   1.9   thorpej const struct ex_cardbus_product *ex_cardbus_lookup
    191   1.9   thorpej     __P((const struct cardbus_attach_args *));
    192   1.9   thorpej 
    193   1.9   thorpej const struct ex_cardbus_product *
    194   1.9   thorpej ex_cardbus_lookup(ca)
    195   1.9   thorpej 	const struct cardbus_attach_args *ca;
    196   1.9   thorpej {
    197   1.9   thorpej 	const struct ex_cardbus_product *ecp;
    198   1.9   thorpej 
    199   1.9   thorpej 	if (CARDBUS_VENDOR(ca->ca_id) != CARDBUS_VENDOR_3COM)
    200   1.9   thorpej 		return (NULL);
    201   1.1      haya 
    202   1.9   thorpej 	for (ecp = ex_cardbus_products; ecp->ecp_name != NULL; ecp++)
    203   1.9   thorpej 		if (CARDBUS_PRODUCT(ca->ca_id) == ecp->ecp_prodid)
    204   1.9   thorpej 			return (ecp);
    205   1.9   thorpej 	return (NULL);
    206   1.9   thorpej }
    207   1.1      haya 
    208   1.9   thorpej int
    209   1.1      haya ex_cardbus_match(parent, cf, aux)
    210   1.9   thorpej 	struct device *parent;
    211   1.9   thorpej 	struct cfdata *cf;
    212   1.9   thorpej 	void *aux;
    213   1.1      haya {
    214   1.9   thorpej 	struct cardbus_attach_args *ca = aux;
    215   1.9   thorpej 
    216   1.9   thorpej 	if (ex_cardbus_lookup(ca) != NULL)
    217   1.9   thorpej 		return (1);
    218   1.1      haya 
    219   1.9   thorpej 	return (0);
    220   1.1      haya }
    221   1.1      haya 
    222   1.9   thorpej void
    223   1.9   thorpej ex_cardbus_attach(parent, self, aux)
    224   1.9   thorpej 	struct device *parent;
    225   1.9   thorpej 	struct device *self;
    226   1.9   thorpej 	void *aux;
    227   1.9   thorpej {
    228  1.17      haya 	struct ex_cardbus_softc *csc = (void *)self;
    229  1.17      haya 	struct ex_softc *sc = &csc->sc_softc;
    230   1.9   thorpej 	struct cardbus_attach_args *ca = aux;
    231   1.9   thorpej 	cardbus_devfunc_t ct = ca->ca_ct;
    232  1.19   thorpej #if rbus
    233  1.19   thorpej #else
    234   1.9   thorpej 	cardbus_chipset_tag_t cc = ct->ct_cc;
    235  1.19   thorpej #endif
    236   1.9   thorpej 	const struct ex_cardbus_product *ecp;
    237  1.19   thorpej 	bus_addr_t adr, adr1;
    238   1.9   thorpej 
    239  1.19   thorpej 	sc->ex_bustype = EX_BUS_CARDBUS;
    240  1.19   thorpej 	sc->sc_dmat = ca->ca_dmat;
    241  1.19   thorpej 	csc->sc_ct = ca->ca_ct;
    242  1.19   thorpej 	csc->sc_intrline = ca->ca_intrline;
    243  1.19   thorpej 	csc->sc_tag = ca->ca_tag;
    244   1.9   thorpej 
    245   1.9   thorpej 	ecp = ex_cardbus_lookup(ca);
    246   1.9   thorpej 	if (ecp == NULL) {
    247   1.9   thorpej 		printf("\n");
    248   1.9   thorpej 		panic("ex_cardbus_attach: impossible");
    249   1.9   thorpej 	}
    250   1.1      haya 
    251   1.9   thorpej 	printf(": 3Com %s\n", ecp->ecp_name);
    252   1.1      haya 
    253   1.9   thorpej 	sc->ex_conf = ecp->ecp_flags;
    254  1.19   thorpej 	csc->sc_cardtype = ecp->ecp_cardtype;
    255  1.19   thorpej 	csc->sc_csr = ecp->ecp_csr;
    256   1.1      haya 
    257  1.19   thorpej 	if (Cardbus_mapreg_map(ct, CARDBUS_BASE0_REG, CARDBUS_MAPREG_TYPE_IO, 0,
    258  1.19   thorpej 		&sc->sc_iot, &sc->sc_ioh, &adr, &csc->sc_mapsize) == 0) {
    259   1.1      haya #if rbus
    260   1.1      haya #else
    261  1.19   thorpej 		(*ct->ct_cf->cardbus_io_open)(cc, 0, adr, adr + csc->sc_mapsize);
    262   1.1      haya #endif
    263  1.19   thorpej 		csc->sc_bar_reg = CARDBUS_BASE0_REG;
    264  1.19   thorpej 		csc->sc_bar_val = adr | CARDBUS_MAPREG_TYPE_IO;
    265   1.1      haya 
    266  1.19   thorpej 		if (csc->sc_cardtype == EX_CB_CYCLONE) {
    267  1.19   thorpej 			/* Map CardBus function status window. */
    268  1.19   thorpej 			if (Cardbus_mapreg_map(ct,
    269  1.19   thorpej 				CARDBUS_3C575BTX_FUNCSTAT_PCIREG,
    270  1.19   thorpej 		    		CARDBUS_MAPREG_TYPE_MEM, 0,
    271  1.19   thorpej 				 &csc->sc_funct, &csc->sc_funch,
    272  1.19   thorpej 				 &adr1, &csc->sc_funcsize) == 0) {
    273  1.19   thorpej 
    274  1.19   thorpej 				csc->sc_bar_reg1 =
    275  1.19   thorpej 					CARDBUS_3C575BTX_FUNCSTAT_PCIREG;
    276  1.19   thorpej 				csc->sc_bar_val1 =
    277  1.19   thorpej 					adr1 | CARDBUS_MAPREG_TYPE_MEM;
    278  1.19   thorpej 
    279  1.19   thorpej 			} else {
    280  1.21       mrg 				printf("%s: unable to map function "
    281  1.21       mrg 					"status window\n", self->dv_xname);
    282  1.19   thorpej 				return;
    283  1.19   thorpej 			}
    284   1.9   thorpej 
    285  1.19   thorpej 			/* Setup interrupt acknowledge hook */
    286  1.19   thorpej 			sc->intr_ack = ex_cardbus_intr_ack;
    287   1.9   thorpej 		}
    288   1.9   thorpej 	}
    289  1.19   thorpej 	else {
    290  1.19   thorpej 		printf(": can't map i/o space\n");
    291  1.19   thorpej 		return;
    292   1.9   thorpej 	}
    293   1.1      haya 
    294  1.19   thorpej 	/* Power management hooks. */
    295  1.19   thorpej 	sc->enable = ex_cardbus_enable;
    296  1.19   thorpej 	sc->disable = ex_cardbus_disable;
    297  1.19   thorpej 	sc->power = ex_cardbus_power;
    298   1.1      haya 
    299  1.19   thorpej 	/*
    300  1.19   thorpej 	 *  Handle power management nonsense and
    301  1.20   kanaoka 	 * initialize the configuration registers.
    302  1.19   thorpej 	 */
    303  1.19   thorpej 	ex_cardbus_setup(csc);
    304   1.1      haya 
    305   1.9   thorpej 	ex_config(sc);
    306   1.9   thorpej 
    307  1.17      haya 	if (csc->sc_cardtype == EX_CB_CYCLONE)
    308  1.17      haya 		bus_space_write_4(csc->sc_funct, csc->sc_funch,
    309   1.9   thorpej 		    EX_CB_INTR, EX_CB_INTR_ACK);
    310   1.1      haya 
    311  1.19   thorpej 	Cardbus_function_disable(csc->sc_ct);
    312   1.1      haya }
    313   1.1      haya 
    314   1.9   thorpej void
    315   1.1      haya ex_cardbus_intr_ack(sc)
    316   1.9   thorpej 	struct ex_softc *sc;
    317   1.1      haya {
    318  1.17      haya 	struct ex_cardbus_softc *csc = (struct ex_cardbus_softc *)sc;
    319   1.9   thorpej 
    320  1.17      haya 	bus_space_write_4(csc->sc_funct, csc->sc_funch, EX_CB_INTR,
    321   1.9   thorpej 	    EX_CB_INTR_ACK);
    322   1.1      haya }
    323   1.1      haya 
    324   1.9   thorpej int
    325   1.1      haya ex_cardbus_detach(self, arg)
    326   1.9   thorpej 	struct device *self;
    327   1.9   thorpej 	int arg;
    328   1.1      haya {
    329  1.17      haya 	struct ex_cardbus_softc *csc = (void *)self;
    330  1.17      haya 	struct ex_softc *sc = &csc->sc_softc;
    331  1.17      haya 	struct cardbus_devfunc *ct = csc->sc_ct;
    332  1.11  augustss 	int rv;
    333   1.1      haya 
    334  1.11  augustss #if defined(DIAGNOSTIC)
    335  1.11  augustss 	if (ct == NULL) {
    336  1.24    provos 		panic("%s: data structure lacks", sc->sc_dev.dv_xname);
    337  1.11  augustss 	}
    338  1.11  augustss #endif
    339  1.10      haya 
    340  1.11  augustss 	rv = ex_detach(sc);
    341  1.11  augustss 	if (rv == 0) {
    342  1.11  augustss 		/*
    343  1.11  augustss 		 * Unhook the interrupt handler.
    344  1.11  augustss 		 */
    345  1.11  augustss 		cardbus_intr_disestablish(ct->ct_cc, ct->ct_cf, sc->sc_ih);
    346   1.1      haya 
    347  1.17      haya 		if (csc->sc_cardtype == EX_CB_CYCLONE) {
    348  1.12   thorpej 			Cardbus_mapreg_unmap(ct,
    349  1.12   thorpej 			    CARDBUS_3C575BTX_FUNCSTAT_PCIREG,
    350  1.17      haya 			    csc->sc_funct, csc->sc_funch, csc->sc_funcsize);
    351  1.11  augustss 		}
    352   1.1      haya 
    353  1.12   thorpej 		Cardbus_mapreg_unmap(ct, CARDBUS_BASE0_REG, sc->sc_iot,
    354  1.17      haya 		    sc->sc_ioh, csc->sc_mapsize);
    355  1.11  augustss 	}
    356  1.11  augustss 	return (rv);
    357   1.1      haya }
    358   1.1      haya 
    359   1.9   thorpej int
    360   1.1      haya ex_cardbus_enable(sc)
    361   1.9   thorpej 	struct ex_softc *sc;
    362   1.1      haya {
    363   1.9   thorpej 	struct ex_cardbus_softc *csc = (struct ex_cardbus_softc *)sc;
    364   1.9   thorpej 	cardbus_function_tag_t cf = csc->sc_ct->ct_cf;
    365   1.9   thorpej 	cardbus_chipset_tag_t cc = csc->sc_ct->ct_cc;
    366   1.9   thorpej 
    367   1.9   thorpej 	Cardbus_function_enable(csc->sc_ct);
    368  1.19   thorpej 	ex_cardbus_setup(csc);
    369   1.9   thorpej 
    370   1.9   thorpej 	sc->sc_ih = cardbus_intr_establish(cc, cf, csc->sc_intrline,
    371   1.9   thorpej 	    IPL_NET, ex_intr, sc);
    372   1.9   thorpej 	if (NULL == sc->sc_ih) {
    373   1.9   thorpej 		printf("%s: couldn't establish interrupt\n",
    374   1.9   thorpej 		    sc->sc_dev.dv_xname);
    375   1.9   thorpej 		return (1);
    376   1.9   thorpej 	}
    377  1.19   thorpej 	printf("%s: interrupting at %d\n", sc->sc_dev.dv_xname,
    378  1.19   thorpej 		csc->sc_intrline);
    379   1.1      haya 
    380   1.9   thorpej 	return (0);
    381   1.1      haya }
    382   1.1      haya 
    383   1.9   thorpej void
    384   1.1      haya ex_cardbus_disable(sc)
    385   1.9   thorpej 	struct ex_softc *sc;
    386   1.1      haya {
    387   1.9   thorpej 	struct ex_cardbus_softc *csc = (struct ex_cardbus_softc *)sc;
    388   1.9   thorpej 	cardbus_function_tag_t cf = csc->sc_ct->ct_cf;
    389   1.9   thorpej 	cardbus_chipset_tag_t cc = csc->sc_ct->ct_cc;
    390   1.1      haya 
    391  1.19   thorpej 	cardbus_intr_disestablish(cc, cf, sc->sc_ih);
    392  1.19   thorpej 	sc->sc_ih = NULL;
    393  1.19   thorpej 
    394   1.9   thorpej  	Cardbus_function_disable(csc->sc_ct);
    395   1.1      haya 
    396   1.1      haya }
    397  1.19   thorpej 
    398  1.19   thorpej void
    399  1.19   thorpej ex_cardbus_power(sc, why)
    400  1.19   thorpej 	struct ex_softc *sc;
    401  1.19   thorpej 	int why;
    402  1.19   thorpej {
    403  1.19   thorpej 	struct ex_cardbus_softc *csc = (void *) sc;
    404  1.19   thorpej 
    405  1.19   thorpej 	if (why == PWR_RESUME) {
    406  1.19   thorpej 		/*
    407  1.19   thorpej 		 * Give the PCI configuration registers a kick
    408  1.19   thorpej 		 * in the head.
    409  1.19   thorpej 		 */
    410  1.19   thorpej #ifdef DIAGNOSTIC
    411  1.19   thorpej 		if (sc->enabled == 0)
    412  1.19   thorpej 			panic("ex_cardbus_power");
    413  1.19   thorpej #endif
    414  1.19   thorpej 		ex_cardbus_setup(csc);
    415  1.19   thorpej 	}
    416  1.19   thorpej }
    417  1.19   thorpej 
    418  1.19   thorpej void
    419  1.19   thorpej ex_cardbus_setup(csc)
    420  1.19   thorpej 	struct ex_cardbus_softc *csc;
    421  1.19   thorpej {
    422  1.19   thorpej 	struct ex_softc *sc = &csc->sc_softc;
    423  1.19   thorpej 	cardbus_devfunc_t ct = csc->sc_ct;
    424  1.19   thorpej 	cardbus_chipset_tag_t cc = ct->ct_cc;
    425  1.19   thorpej 	cardbus_function_tag_t cf = ct->ct_cf;
    426  1.19   thorpej 	cardbusreg_t  reg;
    427  1.19   thorpej 
    428  1.29  christos 	(void)cardbus_setpowerstate(sc->sc_dev.dv_xname, ct, csc->sc_tag,
    429  1.29  christos 	    PCI_PWR_D0);
    430  1.19   thorpej 
    431  1.30   mycroft 	/* Program the BAR */
    432  1.30   mycroft 	cardbus_conf_write(cc, cf, csc->sc_tag,
    433  1.30   mycroft 		csc->sc_bar_reg, csc->sc_bar_val);
    434  1.19   thorpej 	/* Make sure the right access type is on the CardBus bridge. */
    435  1.19   thorpej 	(ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_IO_ENABLE);
    436  1.19   thorpej 	if (csc->sc_cardtype == EX_CB_CYCLONE) {
    437  1.30   mycroft 		/* Program the BAR */
    438  1.30   mycroft 		cardbus_conf_write(cc, cf, csc->sc_tag,
    439  1.30   mycroft 			csc->sc_bar_reg1, csc->sc_bar_val1);
    440  1.19   thorpej 		/*
    441  1.19   thorpej 		 * Make sure CardBus brigde can access memory space.  Usually
    442  1.19   thorpej 		 * memory access is enabled by BIOS, but some BIOSes do not
    443  1.19   thorpej 		 * enable it.
    444  1.19   thorpej 		 */
    445  1.19   thorpej 		(ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_MEM_ENABLE);
    446  1.19   thorpej 	}
    447  1.19   thorpej 	(ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE);
    448  1.19   thorpej 
    449  1.19   thorpej 	/* Enable the appropriate bits in the CARDBUS CSR. */
    450  1.19   thorpej 	reg = cardbus_conf_read(cc, cf, csc->sc_tag,
    451  1.19   thorpej 	    CARDBUS_COMMAND_STATUS_REG);
    452  1.19   thorpej 	reg |= csc->sc_csr;
    453  1.19   thorpej 	cardbus_conf_write(cc, cf, csc->sc_tag, CARDBUS_COMMAND_STATUS_REG,
    454  1.19   thorpej 	    reg);
    455  1.19   thorpej 
    456  1.19   thorpej  	/*
    457  1.28       wiz 	 * set latency timer
    458  1.19   thorpej 	 */
    459  1.19   thorpej 	reg = cardbus_conf_read(cc, cf, csc->sc_tag, CARDBUS_BHLC_REG);
    460  1.19   thorpej 	if (CARDBUS_LATTIMER(reg) < 0x20) {
    461  1.19   thorpej 		/* at least the value of latency timer should 0x20. */
    462  1.19   thorpej 		DPRINTF(("if_ex_cardbus: lattimer 0x%x -> 0x20\n",
    463  1.19   thorpej 		    CARDBUS_LATTIMER(reg)));
    464  1.19   thorpej 		reg &= ~(CARDBUS_LATTIMER_MASK << CARDBUS_LATTIMER_SHIFT);
    465  1.19   thorpej 		reg |= (0x20 << CARDBUS_LATTIMER_SHIFT);
    466  1.19   thorpej 		cardbus_conf_write(cc, cf, csc->sc_tag, CARDBUS_BHLC_REG, reg);
    467  1.19   thorpej 	}
    468  1.19   thorpej }
    469