Home | History | Annotate | Line # | Download | only in cardbus
if_ex_cardbus.c revision 1.3.2.2
      1  1.3.2.2    bouyer /*	$NetBSD: if_ex_cardbus.c,v 1.3.2.2 2001/02/11 19:15:18 bouyer 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.1      haya 
     39      1.3  augustss /* #define EX_DEBUG 4 */	/* define to report infomation for debugging */
     40      1.1      haya 
     41      1.1      haya #include <sys/param.h>
     42      1.1      haya #include <sys/systm.h>
     43      1.1      haya #include <sys/mbuf.h>
     44      1.1      haya #include <sys/socket.h>
     45      1.1      haya #include <sys/ioctl.h>
     46  1.3.2.1    bouyer #include <sys/errno.h>
     47  1.3.2.1    bouyer #include <sys/syslog.h>
     48  1.3.2.1    bouyer #include <sys/select.h>
     49  1.3.2.1    bouyer #include <sys/device.h>
     50      1.1      haya 
     51      1.1      haya #include <net/if.h>
     52      1.1      haya #include <net/if_dl.h>
     53      1.1      haya #include <net/if_ether.h>
     54  1.3.2.1    bouyer #include <net/if_media.h>
     55      1.1      haya 
     56      1.1      haya #include <machine/cpu.h>
     57      1.1      haya #include <machine/bus.h>
     58  1.3.2.1    bouyer 
     59      1.1      haya #include <dev/cardbus/cardbusvar.h>
     60      1.1      haya #include <dev/cardbus/cardbusdevs.h>
     61      1.1      haya 
     62      1.1      haya #include <dev/mii/miivar.h>
     63      1.1      haya 
     64      1.1      haya #include <dev/ic/elink3var.h>
     65      1.1      haya #include <dev/ic/elink3reg.h>
     66      1.1      haya #include <dev/ic/elinkxlreg.h>
     67      1.1      haya #include <dev/ic/elinkxlvar.h>
     68      1.1      haya 
     69      1.1      haya #if defined DEBUG && !defined EX_DEBUG
     70      1.1      haya #define EX_DEBUG
     71      1.1      haya #endif
     72      1.1      haya 
     73      1.1      haya #if defined EX_DEBUG
     74      1.1      haya #define DPRINTF(a) printf a
     75      1.1      haya #else
     76      1.1      haya #define DPRINTF(a)
     77      1.1      haya #endif
     78      1.1      haya 
     79      1.1      haya #define CARDBUS_3C575BTX_FUNCSTAT_PCIREG  CARDBUS_BASE2_REG  /* means 0x18 */
     80      1.1      haya #define EX_CB_INTR 4		/* intr acknowledge reg. CardBus only */
     81      1.1      haya #define EX_CB_INTR_ACK 0x8000 /* intr acknowledge bit */
     82      1.1      haya 
     83  1.3.2.1    bouyer int ex_cardbus_match __P((struct device *, struct cfdata *, void *));
     84  1.3.2.1    bouyer void ex_cardbus_attach __P((struct device *, struct device *,void *));
     85  1.3.2.1    bouyer int ex_cardbus_detach __P((struct device *, int));
     86  1.3.2.1    bouyer void ex_cardbus_intr_ack __P((struct ex_softc *));
     87      1.1      haya 
     88  1.3.2.2    bouyer int ex_cardbus_enable __P((struct ex_softc *));
     89  1.3.2.2    bouyer void ex_cardbus_disable __P((struct ex_softc *));
     90  1.3.2.2    bouyer void ex_cardbus_power __P((struct ex_softc *, int));
     91      1.1      haya 
     92      1.1      haya struct ex_cardbus_softc {
     93  1.3.2.1    bouyer 	struct ex_softc sc_softc;
     94      1.1      haya 
     95  1.3.2.1    bouyer 	cardbus_devfunc_t sc_ct;
     96  1.3.2.1    bouyer 	int sc_intrline;
     97  1.3.2.1    bouyer 	u_int8_t sc_cardbus_flags;
     98      1.1      haya #define EX_REATTACH		0x01
     99      1.1      haya #define EX_ABSENT		0x02
    100  1.3.2.1    bouyer 	u_int8_t sc_cardtype;
    101  1.3.2.1    bouyer #define EX_CB_BOOMERANG		1
    102  1.3.2.1    bouyer #define EX_CB_CYCLONE		2
    103  1.3.2.1    bouyer 
    104  1.3.2.1    bouyer 	/* CardBus function status space.  575B requests it. */
    105  1.3.2.1    bouyer 	bus_space_tag_t sc_funct;
    106  1.3.2.1    bouyer 	bus_space_handle_t sc_funch;
    107  1.3.2.1    bouyer 	bus_size_t sc_funcsize;
    108  1.3.2.1    bouyer 
    109  1.3.2.1    bouyer 	bus_size_t sc_mapsize;		/* the size of mapped bus space region */
    110  1.3.2.2    bouyer 
    111  1.3.2.2    bouyer 	cardbustag_t sc_tag;
    112  1.3.2.2    bouyer 
    113  1.3.2.2    bouyer 	int	sc_csr;			/* CSR bits */
    114  1.3.2.2    bouyer 	int	sc_bar_reg;		/* which BAR to use */
    115  1.3.2.2    bouyer 	pcireg_t sc_bar_val;		/* value of the BAR */
    116  1.3.2.2    bouyer 	int	sc_bar_reg1;		/* which BAR to use */
    117  1.3.2.2    bouyer 	pcireg_t sc_bar_val1;		/* value of the BAR */
    118  1.3.2.2    bouyer 
    119      1.1      haya };
    120      1.1      haya 
    121      1.1      haya struct cfattach ex_cardbus_ca = {
    122  1.3.2.1    bouyer 	sizeof(struct ex_cardbus_softc), ex_cardbus_match,
    123  1.3.2.1    bouyer 	    ex_cardbus_attach, ex_cardbus_detach, ex_activate
    124      1.1      haya };
    125      1.1      haya 
    126  1.3.2.1    bouyer const struct ex_cardbus_product {
    127  1.3.2.1    bouyer 	u_int32_t	ecp_prodid;	/* CardBus product ID */
    128  1.3.2.1    bouyer 	int		ecp_flags;	/* initial softc flags */
    129  1.3.2.1    bouyer 	pcireg_t	ecp_csr;	/* PCI CSR flags */
    130  1.3.2.1    bouyer 	int		ecp_cardtype;	/* card type */
    131  1.3.2.1    bouyer 	const char	*ecp_name;	/* device name */
    132  1.3.2.1    bouyer } ex_cardbus_products[] = {
    133  1.3.2.1    bouyer 	{ CARDBUS_PRODUCT_3COM_3C575TX,
    134  1.3.2.1    bouyer 	  EX_CONF_MII | EX_CONF_EEPROM_OFF | EX_CONF_EEPROM_8BIT,
    135  1.3.2.1    bouyer 	  CARDBUS_COMMAND_IO_ENABLE | CARDBUS_COMMAND_MASTER_ENABLE,
    136  1.3.2.1    bouyer 	  EX_CB_BOOMERANG,
    137  1.3.2.1    bouyer 	  "3c575-TX Ethernet" },
    138  1.3.2.1    bouyer 
    139  1.3.2.1    bouyer 	{ CARDBUS_PRODUCT_3COM_3C575BTX,
    140  1.3.2.1    bouyer 	  EX_CONF_90XB|EX_CONF_MII|EX_CONF_INV_LED_POLARITY |
    141  1.3.2.1    bouyer 	    EX_CONF_EEPROM_OFF | EX_CONF_EEPROM_8BIT,
    142  1.3.2.1    bouyer 	  CARDBUS_COMMAND_IO_ENABLE | CARDBUS_COMMAND_MEM_ENABLE |
    143  1.3.2.1    bouyer 	      CARDBUS_COMMAND_MASTER_ENABLE,
    144  1.3.2.1    bouyer 	  EX_CB_CYCLONE,
    145  1.3.2.1    bouyer 	  "3c575B-TX Ethernet" },
    146  1.3.2.1    bouyer 
    147  1.3.2.1    bouyer 	{ CARDBUS_PRODUCT_3COM_3C575CTX,
    148  1.3.2.1    bouyer 	  EX_CONF_90XB | EX_CONF_PHY_POWER | EX_CONF_EEPROM_OFF |
    149  1.3.2.1    bouyer 	    EX_CONF_EEPROM_8BIT,
    150  1.3.2.1    bouyer 	  CARDBUS_COMMAND_IO_ENABLE | CARDBUS_COMMAND_MEM_ENABLE |
    151  1.3.2.1    bouyer 	      CARDBUS_COMMAND_MASTER_ENABLE,
    152  1.3.2.1    bouyer 	  EX_CB_CYCLONE,
    153  1.3.2.1    bouyer 	  "3c575CT Ethernet" },
    154  1.3.2.1    bouyer 
    155  1.3.2.1    bouyer 	{ 0,
    156  1.3.2.1    bouyer 	  0,
    157  1.3.2.1    bouyer 	  0,
    158  1.3.2.1    bouyer 	  0,
    159  1.3.2.1    bouyer 	  NULL },
    160  1.3.2.1    bouyer };
    161      1.1      haya 
    162  1.3.2.2    bouyer 
    163  1.3.2.2    bouyer void ex_cardbus_setup __P((struct ex_cardbus_softc *));
    164  1.3.2.2    bouyer 
    165  1.3.2.1    bouyer const struct ex_cardbus_product *ex_cardbus_lookup
    166  1.3.2.1    bouyer     __P((const struct cardbus_attach_args *));
    167      1.1      haya 
    168  1.3.2.1    bouyer const struct ex_cardbus_product *
    169  1.3.2.1    bouyer ex_cardbus_lookup(ca)
    170  1.3.2.1    bouyer 	const struct cardbus_attach_args *ca;
    171      1.1      haya {
    172  1.3.2.1    bouyer 	const struct ex_cardbus_product *ecp;
    173      1.1      haya 
    174  1.3.2.1    bouyer 	if (CARDBUS_VENDOR(ca->ca_id) != CARDBUS_VENDOR_3COM)
    175  1.3.2.1    bouyer 		return (NULL);
    176      1.1      haya 
    177  1.3.2.1    bouyer 	for (ecp = ex_cardbus_products; ecp->ecp_name != NULL; ecp++)
    178  1.3.2.1    bouyer 		if (CARDBUS_PRODUCT(ca->ca_id) == ecp->ecp_prodid)
    179  1.3.2.1    bouyer 			return (ecp);
    180  1.3.2.1    bouyer 	return (NULL);
    181  1.3.2.1    bouyer }
    182      1.1      haya 
    183  1.3.2.1    bouyer int
    184  1.3.2.1    bouyer ex_cardbus_match(parent, cf, aux)
    185  1.3.2.1    bouyer 	struct device *parent;
    186  1.3.2.1    bouyer 	struct cfdata *cf;
    187  1.3.2.1    bouyer 	void *aux;
    188  1.3.2.1    bouyer {
    189  1.3.2.1    bouyer 	struct cardbus_attach_args *ca = aux;
    190      1.1      haya 
    191  1.3.2.1    bouyer 	if (ex_cardbus_lookup(ca) != NULL)
    192  1.3.2.1    bouyer 		return (1);
    193      1.1      haya 
    194  1.3.2.1    bouyer 	return (0);
    195  1.3.2.1    bouyer }
    196      1.1      haya 
    197  1.3.2.1    bouyer void
    198      1.1      haya ex_cardbus_attach(parent, self, aux)
    199  1.3.2.1    bouyer 	struct device *parent;
    200  1.3.2.1    bouyer 	struct device *self;
    201  1.3.2.1    bouyer 	void *aux;
    202      1.1      haya {
    203  1.3.2.1    bouyer 	struct ex_cardbus_softc *csc = (void *)self;
    204  1.3.2.1    bouyer 	struct ex_softc *sc = &csc->sc_softc;
    205  1.3.2.1    bouyer 	struct cardbus_attach_args *ca = aux;
    206  1.3.2.1    bouyer 	cardbus_devfunc_t ct = ca->ca_ct;
    207  1.3.2.2    bouyer #if rbus
    208  1.3.2.2    bouyer #else
    209  1.3.2.1    bouyer 	cardbus_chipset_tag_t cc = ct->ct_cc;
    210  1.3.2.2    bouyer #endif
    211  1.3.2.1    bouyer 	const struct ex_cardbus_product *ecp;
    212  1.3.2.2    bouyer 	bus_addr_t adr, adr1;
    213  1.3.2.1    bouyer 
    214  1.3.2.2    bouyer 	sc->ex_bustype = EX_BUS_CARDBUS;
    215  1.3.2.2    bouyer 	sc->sc_dmat = ca->ca_dmat;
    216  1.3.2.2    bouyer 	csc->sc_ct = ca->ca_ct;
    217  1.3.2.2    bouyer 	csc->sc_intrline = ca->ca_intrline;
    218  1.3.2.2    bouyer 	csc->sc_tag = ca->ca_tag;
    219  1.3.2.1    bouyer 
    220  1.3.2.1    bouyer 	ecp = ex_cardbus_lookup(ca);
    221  1.3.2.1    bouyer 	if (ecp == NULL) {
    222  1.3.2.1    bouyer 		printf("\n");
    223  1.3.2.1    bouyer 		panic("ex_cardbus_attach: impossible");
    224  1.3.2.1    bouyer 	}
    225      1.1      haya 
    226  1.3.2.1    bouyer 	printf(": 3Com %s\n", ecp->ecp_name);
    227      1.1      haya 
    228  1.3.2.1    bouyer 	sc->ex_conf = ecp->ecp_flags;
    229  1.3.2.2    bouyer 	csc->sc_cardtype = ecp->ecp_cardtype;
    230  1.3.2.2    bouyer 	csc->sc_csr = ecp->ecp_csr;
    231      1.1      haya 
    232  1.3.2.2    bouyer 	if (Cardbus_mapreg_map(ct, CARDBUS_BASE0_REG, CARDBUS_MAPREG_TYPE_IO, 0,
    233  1.3.2.2    bouyer 		&sc->sc_iot, &sc->sc_ioh, &adr, &csc->sc_mapsize) == 0) {
    234  1.3.2.1    bouyer #if rbus
    235  1.3.2.1    bouyer #else
    236  1.3.2.2    bouyer 		(*ct->ct_cf->cardbus_io_open)(cc, 0, adr, adr + csc->sc_mapsize);
    237      1.1      haya #endif
    238  1.3.2.2    bouyer 		csc->sc_bar_reg = CARDBUS_BASE0_REG;
    239  1.3.2.2    bouyer 		csc->sc_bar_val = adr | CARDBUS_MAPREG_TYPE_IO;
    240  1.3.2.1    bouyer 
    241  1.3.2.2    bouyer 		if (csc->sc_cardtype == EX_CB_CYCLONE) {
    242  1.3.2.2    bouyer 			/* Map CardBus function status window. */
    243  1.3.2.2    bouyer 			if (Cardbus_mapreg_map(ct,
    244  1.3.2.2    bouyer 				CARDBUS_3C575BTX_FUNCSTAT_PCIREG,
    245  1.3.2.2    bouyer 		    		CARDBUS_MAPREG_TYPE_MEM, 0,
    246  1.3.2.2    bouyer 				 &csc->sc_funct, &csc->sc_funch,
    247  1.3.2.2    bouyer 				 &adr1, &csc->sc_funcsize) == 0) {
    248  1.3.2.2    bouyer 
    249  1.3.2.2    bouyer 				csc->sc_bar_reg1 =
    250  1.3.2.2    bouyer 					CARDBUS_3C575BTX_FUNCSTAT_PCIREG;
    251  1.3.2.2    bouyer 				csc->sc_bar_val1 =
    252  1.3.2.2    bouyer 					adr1 | CARDBUS_MAPREG_TYPE_MEM;
    253  1.3.2.2    bouyer 
    254  1.3.2.2    bouyer 			} else {
    255  1.3.2.2    bouyer 				printf("%s: unable to map function
    256  1.3.2.2    bouyer 					status window\n", self->dv_xname);
    257  1.3.2.2    bouyer 				return;
    258  1.3.2.2    bouyer 			}
    259  1.3.2.1    bouyer 
    260  1.3.2.2    bouyer 			/* Setup interrupt acknowledge hook */
    261  1.3.2.2    bouyer 			sc->intr_ack = ex_cardbus_intr_ack;
    262  1.3.2.1    bouyer 		}
    263  1.3.2.1    bouyer 	}
    264  1.3.2.2    bouyer 	else {
    265  1.3.2.2    bouyer 		printf(": can't map i/o space\n");
    266  1.3.2.2    bouyer 		return;
    267  1.3.2.1    bouyer 	}
    268      1.1      haya 
    269  1.3.2.2    bouyer 	/* Power management hooks. */
    270  1.3.2.2    bouyer 	sc->enable = ex_cardbus_enable;
    271  1.3.2.2    bouyer 	sc->disable = ex_cardbus_disable;
    272  1.3.2.2    bouyer 	sc->power = ex_cardbus_power;
    273  1.3.2.1    bouyer 
    274  1.3.2.2    bouyer 	/*
    275  1.3.2.2    bouyer 	 *  Handle power management nonsense and
    276  1.3.2.2    bouyer 	 * Initialize th configuration register.
    277  1.3.2.2    bouyer 	 */
    278  1.3.2.2    bouyer 	ex_cardbus_setup(csc);
    279  1.3.2.1    bouyer 
    280  1.3.2.1    bouyer 	ex_config(sc);
    281  1.3.2.1    bouyer 
    282  1.3.2.1    bouyer 	if (csc->sc_cardtype == EX_CB_CYCLONE)
    283  1.3.2.1    bouyer 		bus_space_write_4(csc->sc_funct, csc->sc_funch,
    284  1.3.2.1    bouyer 		    EX_CB_INTR, EX_CB_INTR_ACK);
    285      1.1      haya 
    286  1.3.2.2    bouyer 	Cardbus_function_disable(csc->sc_ct);
    287      1.1      haya }
    288      1.1      haya 
    289  1.3.2.1    bouyer void
    290      1.1      haya ex_cardbus_intr_ack(sc)
    291  1.3.2.1    bouyer 	struct ex_softc *sc;
    292      1.1      haya {
    293  1.3.2.1    bouyer 	struct ex_cardbus_softc *csc = (struct ex_cardbus_softc *)sc;
    294      1.1      haya 
    295  1.3.2.1    bouyer 	bus_space_write_4(csc->sc_funct, csc->sc_funch, EX_CB_INTR,
    296  1.3.2.1    bouyer 	    EX_CB_INTR_ACK);
    297  1.3.2.1    bouyer }
    298      1.1      haya 
    299  1.3.2.1    bouyer int
    300      1.1      haya ex_cardbus_detach(self, arg)
    301  1.3.2.1    bouyer 	struct device *self;
    302  1.3.2.1    bouyer 	int arg;
    303      1.1      haya {
    304  1.3.2.1    bouyer 	struct ex_cardbus_softc *csc = (void *)self;
    305  1.3.2.1    bouyer 	struct ex_softc *sc = &csc->sc_softc;
    306  1.3.2.1    bouyer 	struct cardbus_devfunc *ct = csc->sc_ct;
    307  1.3.2.1    bouyer 	int rv;
    308  1.3.2.1    bouyer 
    309  1.3.2.1    bouyer #if defined(DIAGNOSTIC)
    310  1.3.2.1    bouyer 	if (ct == NULL) {
    311  1.3.2.1    bouyer 		panic("%s: data structure lacks\n", sc->sc_dev.dv_xname);
    312  1.3.2.1    bouyer 	}
    313  1.3.2.1    bouyer #endif
    314  1.3.2.1    bouyer 
    315  1.3.2.1    bouyer 	rv = ex_detach(sc);
    316  1.3.2.1    bouyer 	if (rv == 0) {
    317  1.3.2.1    bouyer 		/*
    318  1.3.2.1    bouyer 		 * Unhook the interrupt handler.
    319  1.3.2.1    bouyer 		 */
    320  1.3.2.1    bouyer 		cardbus_intr_disestablish(ct->ct_cc, ct->ct_cf, sc->sc_ih);
    321  1.3.2.1    bouyer 
    322  1.3.2.1    bouyer 		if (csc->sc_cardtype == EX_CB_CYCLONE) {
    323  1.3.2.1    bouyer 			Cardbus_mapreg_unmap(ct,
    324  1.3.2.1    bouyer 			    CARDBUS_3C575BTX_FUNCSTAT_PCIREG,
    325  1.3.2.1    bouyer 			    csc->sc_funct, csc->sc_funch, csc->sc_funcsize);
    326  1.3.2.1    bouyer 		}
    327  1.3.2.1    bouyer 
    328  1.3.2.1    bouyer 		Cardbus_mapreg_unmap(ct, CARDBUS_BASE0_REG, sc->sc_iot,
    329  1.3.2.1    bouyer 		    sc->sc_ioh, csc->sc_mapsize);
    330  1.3.2.1    bouyer 	}
    331  1.3.2.1    bouyer 	return (rv);
    332      1.1      haya }
    333      1.1      haya 
    334  1.3.2.1    bouyer int
    335      1.1      haya ex_cardbus_enable(sc)
    336  1.3.2.1    bouyer 	struct ex_softc *sc;
    337      1.1      haya {
    338  1.3.2.1    bouyer 	struct ex_cardbus_softc *csc = (struct ex_cardbus_softc *)sc;
    339  1.3.2.1    bouyer 	cardbus_function_tag_t cf = csc->sc_ct->ct_cf;
    340  1.3.2.1    bouyer 	cardbus_chipset_tag_t cc = csc->sc_ct->ct_cc;
    341  1.3.2.1    bouyer 
    342  1.3.2.1    bouyer 	Cardbus_function_enable(csc->sc_ct);
    343  1.3.2.2    bouyer 	ex_cardbus_setup(csc);
    344  1.3.2.1    bouyer 
    345  1.3.2.1    bouyer 	sc->sc_ih = cardbus_intr_establish(cc, cf, csc->sc_intrline,
    346  1.3.2.1    bouyer 	    IPL_NET, ex_intr, sc);
    347  1.3.2.1    bouyer 	if (NULL == sc->sc_ih) {
    348  1.3.2.1    bouyer 		printf("%s: couldn't establish interrupt\n",
    349  1.3.2.1    bouyer 		    sc->sc_dev.dv_xname);
    350  1.3.2.1    bouyer 		return (1);
    351  1.3.2.1    bouyer 	}
    352  1.3.2.2    bouyer 	printf("%s: interrupting at %d\n", sc->sc_dev.dv_xname,
    353  1.3.2.2    bouyer 		csc->sc_intrline);
    354      1.1      haya 
    355  1.3.2.1    bouyer 	return (0);
    356      1.1      haya }
    357      1.1      haya 
    358  1.3.2.1    bouyer void
    359      1.1      haya ex_cardbus_disable(sc)
    360  1.3.2.1    bouyer 	struct ex_softc *sc;
    361      1.1      haya {
    362  1.3.2.1    bouyer 	struct ex_cardbus_softc *csc = (struct ex_cardbus_softc *)sc;
    363  1.3.2.1    bouyer 	cardbus_function_tag_t cf = csc->sc_ct->ct_cf;
    364  1.3.2.1    bouyer 	cardbus_chipset_tag_t cc = csc->sc_ct->ct_cc;
    365      1.1      haya 
    366  1.3.2.2    bouyer 	cardbus_intr_disestablish(cc, cf, sc->sc_ih);
    367  1.3.2.2    bouyer 	sc->sc_ih = NULL;
    368  1.3.2.2    bouyer 
    369  1.3.2.1    bouyer  	Cardbus_function_disable(csc->sc_ct);
    370      1.1      haya 
    371      1.1      haya }
    372  1.3.2.2    bouyer 
    373  1.3.2.2    bouyer void
    374  1.3.2.2    bouyer ex_cardbus_power(sc, why)
    375  1.3.2.2    bouyer 	struct ex_softc *sc;
    376  1.3.2.2    bouyer 	int why;
    377  1.3.2.2    bouyer {
    378  1.3.2.2    bouyer 	struct ex_cardbus_softc *csc = (void *) sc;
    379  1.3.2.2    bouyer 
    380  1.3.2.2    bouyer 	if (why == PWR_RESUME) {
    381  1.3.2.2    bouyer 		/*
    382  1.3.2.2    bouyer 		 * Give the PCI configuration registers a kick
    383  1.3.2.2    bouyer 		 * in the head.
    384  1.3.2.2    bouyer 		 */
    385  1.3.2.2    bouyer #ifdef DIAGNOSTIC
    386  1.3.2.2    bouyer 		if (sc->enabled == 0)
    387  1.3.2.2    bouyer 			panic("ex_cardbus_power");
    388  1.3.2.2    bouyer #endif
    389  1.3.2.2    bouyer 		ex_cardbus_setup(csc);
    390  1.3.2.2    bouyer 	}
    391  1.3.2.2    bouyer }
    392  1.3.2.2    bouyer 
    393  1.3.2.2    bouyer void
    394  1.3.2.2    bouyer ex_cardbus_setup(csc)
    395  1.3.2.2    bouyer 	struct ex_cardbus_softc *csc;
    396  1.3.2.2    bouyer {
    397  1.3.2.2    bouyer 	struct ex_softc *sc = &csc->sc_softc;
    398  1.3.2.2    bouyer 	cardbus_devfunc_t ct = csc->sc_ct;
    399  1.3.2.2    bouyer 	cardbus_chipset_tag_t cc = ct->ct_cc;
    400  1.3.2.2    bouyer 	cardbus_function_tag_t cf = ct->ct_cf;
    401  1.3.2.2    bouyer 	cardbusreg_t  reg;
    402  1.3.2.2    bouyer 	int pmreg;
    403  1.3.2.2    bouyer 
    404  1.3.2.2    bouyer 	/* Get it out of power save mode if needed (BIOS bugs). */
    405  1.3.2.2    bouyer 	if (cardbus_get_capability(cc, cf, csc->sc_tag,
    406  1.3.2.2    bouyer 	    PCI_CAP_PWRMGMT, &pmreg, 0)) {
    407  1.3.2.2    bouyer 		reg = cardbus_conf_read(cc, cf, csc->sc_tag, pmreg + 4) & 0x03;
    408  1.3.2.2    bouyer #if 1 /* XXX Probably not right for CardBus. */
    409  1.3.2.2    bouyer 		if (reg == 3) {
    410  1.3.2.2    bouyer 			/*
    411  1.3.2.2    bouyer 			 * The card has lost all configuration data in
    412  1.3.2.2    bouyer 			 * this state, so punt.
    413  1.3.2.2    bouyer 			 */
    414  1.3.2.2    bouyer 			printf("%s: unable to wake up from power state D3\n",
    415  1.3.2.2    bouyer 			    sc->sc_dev.dv_xname);
    416  1.3.2.2    bouyer 			return;
    417  1.3.2.2    bouyer 		}
    418  1.3.2.2    bouyer #endif
    419  1.3.2.2    bouyer 		if (reg != 0) {
    420  1.3.2.2    bouyer 			printf("%s: waking up from power state D%d\n",
    421  1.3.2.2    bouyer 			    sc->sc_dev.dv_xname, reg);
    422  1.3.2.2    bouyer 			cardbus_conf_write(cc, cf, csc->sc_tag,
    423  1.3.2.2    bouyer 			    pmreg + 4, 0);
    424  1.3.2.2    bouyer 		}
    425  1.3.2.2    bouyer 	}
    426  1.3.2.2    bouyer 
    427  1.3.2.2    bouyer 	/* Make sure the right access type is on the CardBus bridge. */
    428  1.3.2.2    bouyer 	(ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_IO_ENABLE);
    429  1.3.2.2    bouyer 	if (csc->sc_cardtype == EX_CB_CYCLONE) {
    430  1.3.2.2    bouyer 		/*
    431  1.3.2.2    bouyer 		 * Make sure CardBus brigde can access memory space.  Usually
    432  1.3.2.2    bouyer 		 * memory access is enabled by BIOS, but some BIOSes do not
    433  1.3.2.2    bouyer 		 * enable it.
    434  1.3.2.2    bouyer 		 */
    435  1.3.2.2    bouyer 		(ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_MEM_ENABLE);
    436  1.3.2.2    bouyer 
    437  1.3.2.2    bouyer 		/* Program the BAR */
    438  1.3.2.2    bouyer 		cardbus_conf_write(cc, cf, csc->sc_tag,
    439  1.3.2.2    bouyer 			csc->sc_bar_reg1, csc->sc_bar_val1);
    440  1.3.2.2    bouyer 	}
    441  1.3.2.2    bouyer 	(ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE);
    442  1.3.2.2    bouyer 
    443  1.3.2.2    bouyer 
    444  1.3.2.2    bouyer 	/* Program the BAR */
    445  1.3.2.2    bouyer 	cardbus_conf_write(cc, cf, csc->sc_tag,
    446  1.3.2.2    bouyer 		csc->sc_bar_reg, csc->sc_bar_val);
    447  1.3.2.2    bouyer 
    448  1.3.2.2    bouyer 	/* Enable the appropriate bits in the CARDBUS CSR. */
    449  1.3.2.2    bouyer 	reg = cardbus_conf_read(cc, cf, csc->sc_tag,
    450  1.3.2.2    bouyer 	    CARDBUS_COMMAND_STATUS_REG);
    451  1.3.2.2    bouyer 	reg |= csc->sc_csr;
    452  1.3.2.2    bouyer 	cardbus_conf_write(cc, cf, csc->sc_tag, CARDBUS_COMMAND_STATUS_REG,
    453  1.3.2.2    bouyer 	    reg);
    454  1.3.2.2    bouyer 
    455  1.3.2.2    bouyer  	/*
    456  1.3.2.2    bouyer 	 * set latency timmer
    457  1.3.2.2    bouyer 	 */
    458  1.3.2.2    bouyer 	reg = cardbus_conf_read(cc, cf, csc->sc_tag, CARDBUS_BHLC_REG);
    459  1.3.2.2    bouyer 	if (CARDBUS_LATTIMER(reg) < 0x20) {
    460  1.3.2.2    bouyer 		/* at least the value of latency timer should 0x20. */
    461  1.3.2.2    bouyer 		DPRINTF(("if_ex_cardbus: lattimer 0x%x -> 0x20\n",
    462  1.3.2.2    bouyer 		    CARDBUS_LATTIMER(reg)));
    463  1.3.2.2    bouyer 		reg &= ~(CARDBUS_LATTIMER_MASK << CARDBUS_LATTIMER_SHIFT);
    464  1.3.2.2    bouyer 		reg |= (0x20 << CARDBUS_LATTIMER_SHIFT);
    465  1.3.2.2    bouyer 		cardbus_conf_write(cc, cf, csc->sc_tag, CARDBUS_BHLC_REG, reg);
    466  1.3.2.2    bouyer 	}
    467  1.3.2.2    bouyer }
    468