Home | History | Annotate | Line # | Download | only in pcmcia
if_wi_pcmcia.c revision 1.10
      1  1.10  ichiro /* $NetBSD: if_wi_pcmcia.c,v 1.10 2001/10/27 08:16:17 ichiro Exp $ */
      2   1.1  ichiro 
      3   1.1  ichiro /*-
      4   1.1  ichiro  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5   1.1  ichiro  * All rights reserved.
      6   1.1  ichiro  *
      7   1.1  ichiro  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1  ichiro  * by Ichiro FUKUHARA (ichiro (at) ichiro.org).
      9   1.1  ichiro  *
     10   1.1  ichiro  * Redistribution and use in source and binary forms, with or without
     11   1.1  ichiro  * modification, are permitted provided that the following conditions
     12   1.1  ichiro  * are met:
     13   1.1  ichiro  * 1. Redistributions of source code must retain the above copyright
     14   1.1  ichiro  *    notice, this list of conditions and the following disclaimer.
     15   1.1  ichiro  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1  ichiro  *    notice, this list of conditions and the following disclaimer in the
     17   1.1  ichiro  *    documentation and/or other materials provided with the distribution.
     18   1.1  ichiro  * 3. All advertising materials mentioning features or use of this software
     19   1.1  ichiro  *    must display the following acknowledgement:
     20   1.1  ichiro  *        This product includes software developed by the NetBSD
     21   1.1  ichiro  *        Foundation, Inc. and its contributors.
     22   1.1  ichiro  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1  ichiro  *    contributors may be used to endorse or promote products derived
     24   1.1  ichiro  *    from this software without specific prior written permission.
     25   1.1  ichiro  *
     26   1.1  ichiro  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1  ichiro  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1  ichiro  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1  ichiro  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1  ichiro  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1  ichiro  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1  ichiro  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1  ichiro  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1  ichiro  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1  ichiro  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1  ichiro  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1  ichiro  */
     38   1.1  ichiro 
     39   1.1  ichiro /*
     40   1.1  ichiro  * PCMCIA attachment for Lucent & Intersil WaveLAN PCMCIA card
     41   1.1  ichiro  */
     42   1.1  ichiro 
     43   1.1  ichiro #include <sys/param.h>
     44   1.1  ichiro #include <sys/systm.h>
     45   1.1  ichiro #include <sys/callout.h>
     46   1.1  ichiro #include <sys/device.h>
     47   1.1  ichiro #include <sys/socket.h>
     48   1.1  ichiro 
     49   1.1  ichiro #include <net/if.h>
     50   1.1  ichiro #include <net/if_ether.h>
     51   1.1  ichiro #include <net/if_media.h>
     52   1.1  ichiro #include <net/if_ieee80211.h>
     53   1.1  ichiro 
     54   1.1  ichiro #include <machine/cpu.h>
     55   1.1  ichiro #include <machine/bus.h>
     56   1.1  ichiro #include <machine/intr.h>
     57   1.1  ichiro 
     58   1.1  ichiro #include <dev/ic/wi_ieee.h>
     59   1.1  ichiro #include <dev/ic/wireg.h>
     60   1.1  ichiro #include <dev/ic/wivar.h>
     61   1.1  ichiro 
     62   1.1  ichiro #include <dev/pcmcia/pcmciareg.h>
     63   1.1  ichiro #include <dev/pcmcia/pcmciavar.h>
     64   1.1  ichiro #include <dev/pcmcia/pcmciadevs.h>
     65   1.1  ichiro 
     66   1.1  ichiro static int	wi_pcmcia_match __P((struct device *, struct cfdata *, void *));
     67   1.1  ichiro static void	wi_pcmcia_attach __P((struct device *, struct device *, void *));
     68   1.1  ichiro static int	wi_pcmcia_detach __P((struct device *, int));
     69   1.1  ichiro static int	wi_pcmcia_enable __P((struct wi_softc *));
     70   1.1  ichiro static void	wi_pcmcia_disable __P((struct wi_softc *));
     71   1.1  ichiro static void	wi_pcmcia_powerhook __P((int, void *));
     72   1.1  ichiro static void	wi_pcmcia_shutdown __P((void *));
     73   1.1  ichiro 
     74   1.1  ichiro static const struct wi_pcmcia_product
     75   1.1  ichiro 		*wi_pcmcia_lookup __P((struct pcmcia_attach_args *pa));
     76   1.1  ichiro 
     77   1.1  ichiro struct wi_pcmcia_softc {
     78   1.1  ichiro 	struct wi_softc sc_wi;
     79   1.1  ichiro 
     80   1.1  ichiro 	/* PCMCIA-specific */
     81   1.1  ichiro 	struct pcmcia_io_handle sc_pcioh;	/* PCMCIA i/o space info */
     82   1.1  ichiro 	int sc_io_window;			/* our i/o window */
     83   1.1  ichiro 	struct pcmcia_function *sc_pf;		/* PCMCIA function */
     84   1.1  ichiro 	void *sc_powerhook;			/* power hook descriptor */
     85   1.1  ichiro 	void *sc_sdhook;			/* shutdown hook */
     86   1.1  ichiro 
     87   1.1  ichiro };
     88   1.1  ichiro 
     89   1.1  ichiro static int wi_pcmcia_find __P((struct wi_pcmcia_softc *,
     90   1.1  ichiro 	struct pcmcia_attach_args *, struct pcmcia_config_entry *));
     91   1.1  ichiro 
     92   1.1  ichiro struct cfattach wi_pcmcia_ca = {
     93   1.1  ichiro 	sizeof(struct wi_pcmcia_softc), wi_pcmcia_match, wi_pcmcia_attach,
     94   1.1  ichiro 	wi_pcmcia_detach, wi_activate,
     95   1.1  ichiro };
     96   1.1  ichiro 
     97   1.1  ichiro static const struct wi_pcmcia_product {
     98   1.1  ichiro 	u_int32_t	pp_vendor;	/* vendor ID */
     99   1.1  ichiro 	u_int32_t	pp_product;	/* product ID */
    100   1.1  ichiro 	const char	*pp_cisinfo[4];	/* CIS information */
    101   1.1  ichiro 	const char	*pp_name;	/* product name */
    102   1.1  ichiro } wi_pcmcia_products[] = {
    103   1.1  ichiro 	{ PCMCIA_VENDOR_LUCENT,
    104   1.1  ichiro 	  PCMCIA_PRODUCT_LUCENT_WAVELAN_IEEE,
    105   1.1  ichiro 	  PCMCIA_CIS_LUCENT_WAVELAN_IEEE,
    106   1.2  ichiro 	  PCMCIA_STR_LUCENT_WAVELAN_IEEE },
    107   1.1  ichiro 
    108   1.1  ichiro 	{ PCMCIA_VENDOR_3COM,
    109   1.1  ichiro 	  PCMCIA_PRODUCT_3COM_3CRWE737A,
    110   1.1  ichiro 	  PCMCIA_CIS_3COM_3CRWE737A,
    111   1.2  ichiro 	  PCMCIA_STR_3COM_3CRWE737A },
    112   1.1  ichiro 
    113   1.1  ichiro 	{ PCMCIA_VENDOR_COREGA,
    114   1.1  ichiro 	  PCMCIA_PRODUCT_COREGA_WIRELESS_LAN_PCC_11,
    115   1.1  ichiro 	  PCMCIA_CIS_COREGA_WIRELESS_LAN_PCC_11,
    116   1.2  ichiro 	  PCMCIA_STR_COREGA_WIRELESS_LAN_PCC_11 },
    117   1.1  ichiro 
    118   1.1  ichiro 	{ PCMCIA_VENDOR_COREGA,
    119   1.1  ichiro 	  PCMCIA_PRODUCT_COREGA_WIRELESS_LAN_PCCA_11,
    120   1.1  ichiro 	  PCMCIA_CIS_COREGA_WIRELESS_LAN_PCCA_11,
    121   1.2  ichiro 	  PCMCIA_STR_COREGA_WIRELESS_LAN_PCCA_11 },
    122   1.9     mjl 
    123   1.9     mjl 	{ PCMCIA_VENDOR_COREGA,
    124   1.9     mjl 	  PCMCIA_PRODUCT_COREGA_WIRELESS_LAN_PCCB_11,
    125   1.9     mjl 	  PCMCIA_CIS_COREGA_WIRELESS_LAN_PCCB_11,
    126   1.9     mjl 	  PCMCIA_STR_COREGA_WIRELESS_LAN_PCCB_11 },
    127   1.1  ichiro 
    128   1.1  ichiro 	{ PCMCIA_VENDOR_INTERSIL,
    129   1.1  ichiro 	  PCMCIA_PRODUCT_INTERSIL_PRISM2,
    130   1.1  ichiro 	  PCMCIA_CIS_INTERSIL_PRISM2,
    131   1.2  ichiro 	  PCMCIA_STR_INTERSIL_PRISM2 },
    132   1.1  ichiro 
    133   1.1  ichiro 	{ PCMCIA_VENDOR_SAMSUNG,
    134   1.1  ichiro 	  PCMCIA_PRODUCT_SAMSUNG_SWL_2000N,
    135   1.1  ichiro 	  PCMCIA_CIS_SAMSUNG_SWL_2000N,
    136   1.2  ichiro 	  PCMCIA_STR_SAMSUNG_SWL_2000N },
    137   1.1  ichiro 
    138   1.1  ichiro 	{ PCMCIA_VENDOR_LUCENT,
    139   1.1  ichiro 	  PCMCIA_PRODUCT_LUCENT_WAVELAN_IEEE,
    140   1.1  ichiro 	  PCMCIA_CIS_SMC_2632W,
    141   1.2  ichiro 	  PCMCIA_STR_SMC_2632W },
    142   1.1  ichiro 
    143   1.1  ichiro 	{ PCMCIA_VENDOR_LUCENT,
    144   1.1  ichiro 	  PCMCIA_PRODUCT_LUCENT_WAVELAN_IEEE,
    145   1.1  ichiro 	  PCMCIA_CIS_NANOSPEED_PRISM2,
    146   1.2  ichiro 	  PCMCIA_STR_NANOSPEED_PRISM2 },
    147   1.1  ichiro 
    148   1.1  ichiro 	{ PCMCIA_VENDOR_ELSA,
    149   1.1  ichiro 	  PCMCIA_PRODUCT_ELSA_XI300_IEEE,
    150   1.1  ichiro 	  PCMCIA_CIS_ELSA_XI300_IEEE,
    151   1.2  ichiro 	  PCMCIA_STR_ELSA_XI300_IEEE },
    152   1.1  ichiro 
    153   1.1  ichiro 	{ PCMCIA_VENDOR_COMPAQ,
    154   1.1  ichiro 	  PCMCIA_PRODUCT_COMPAQ_NC5004,
    155   1.1  ichiro 	  PCMCIA_CIS_COMPAQ_NC5004,
    156   1.2  ichiro 	  PCMCIA_STR_COMPAQ_NC5004 },
    157   1.1  ichiro 
    158   1.1  ichiro 	{ PCMCIA_VENDOR_CONTEC,
    159   1.1  ichiro 	  PCMCIA_PRODUCT_CONTEC_FX_DS110_PCC,
    160   1.1  ichiro 	  PCMCIA_CIS_CONTEC_FX_DS110_PCC,
    161   1.2  ichiro 	  PCMCIA_STR_CONTEC_FX_DS110_PCC },
    162   1.1  ichiro 
    163   1.1  ichiro 	{ PCMCIA_VENDOR_TDK,
    164   1.1  ichiro 	  PCMCIA_PRODUCT_TDK_LAK_CD011WL,
    165   1.1  ichiro 	  PCMCIA_CIS_TDK_LAK_CD011WL,
    166   1.2  ichiro 	  PCMCIA_STR_TDK_LAK_CD011WL },
    167   1.1  ichiro 
    168   1.1  ichiro 	{ PCMCIA_VENDOR_LUCENT,
    169   1.1  ichiro 	  PCMCIA_PRODUCT_LUCENT_WAVELAN_IEEE,
    170   1.1  ichiro 	  PCMCIA_CIS_NEC_CMZ_RT_WP,
    171   1.2  ichiro 	  PCMCIA_STR_NEC_CMZ_RT_WP },
    172   1.1  ichiro 
    173   1.1  ichiro 	{ PCMCIA_VENDOR_LUCENT,
    174   1.1  ichiro 	  PCMCIA_PRODUCT_LUCENT_WAVELAN_IEEE,
    175   1.1  ichiro 	  PCMCIA_CIS_NTT_ME_WLAN,
    176   1.2  ichiro 	  PCMCIA_STR_NTT_ME_WLAN },
    177   1.1  ichiro 
    178   1.1  ichiro 	{ PCMCIA_VENDOR_IODATA2,
    179   1.1  ichiro 	  PCMCIA_PRODUCT_IODATA2_WNB11PCM,
    180   1.1  ichiro 	  PCMCIA_CIS_IODATA2_WNB11PCM,
    181   1.2  ichiro 	  PCMCIA_STR_IODATA2_WNB11PCM },
    182   1.3  ichiro 
    183   1.3  ichiro 	{ PCMCIA_VENDOR_BUFFALO,
    184   1.3  ichiro 	  PCMCIA_PRODUCT_BUFFALO_WLI_PCM_S11,
    185   1.3  ichiro 	  PCMCIA_CIS_BUFFALO_WLI_PCM_S11,
    186   1.3  ichiro 	  PCMCIA_STR_BUFFALO_WLI_PCM_S11 },
    187   1.4  ichiro 
    188   1.1  ichiro 	{ PCMCIA_VENDOR_EMTAC,
    189   1.1  ichiro 	  PCMCIA_PRODUCT_EMTAC_WLAN,
    190   1.1  ichiro 	  PCMCIA_CIS_EMTAC_WLAN,
    191   1.2  ichiro 	  PCMCIA_STR_EMTAC_WLAN },
    192   1.7  ichiro 
    193   1.7  ichiro 	{ PCMCIA_VENDOR_INTERSIL,
    194   1.7  ichiro 	  PCMCIA_PRODUCT_GEMTEK_WLAN,
    195   1.7  ichiro 	  PCMCIA_CIS_GEMTEK_WLAN,
    196   1.7  ichiro 	  PCMCIA_STR_GEMTEK_WLAN },
    197  1.10  ichiro 
    198  1.10  ichiro 	{ PCMCIA_VENDOR_ELSA,
    199  1.10  ichiro 	  PCMCIA_PRODUCT_ELSA_XI800_IEEE,
    200  1.10  ichiro 	  PCMCIA_CIS_ELSA_XI800_IEEE,
    201  1.10  ichiro 	  PCMCIA_STR_ELSA_XI800_IEEE },
    202   1.4  ichiro 
    203   1.1  ichiro 	{ 0,
    204   1.1  ichiro 	  0,
    205   1.1  ichiro 	  { NULL, NULL, NULL, NULL },
    206   1.2  ichiro 	  NULL }
    207   1.1  ichiro };
    208   1.1  ichiro 
    209   1.1  ichiro static const struct wi_pcmcia_product *
    210   1.1  ichiro wi_pcmcia_lookup(pa)
    211   1.1  ichiro 	struct pcmcia_attach_args *pa;
    212   1.1  ichiro {
    213   1.1  ichiro 	const struct wi_pcmcia_product *pp;
    214   1.1  ichiro 
    215   1.1  ichiro 	/* match by CIS information */
    216   1.1  ichiro 	for (pp = wi_pcmcia_products; pp->pp_name != NULL; pp++) {
    217   1.1  ichiro 		if (pa->card->cis1_info[0] != NULL &&
    218   1.1  ichiro 		    pp->pp_cisinfo[0] != NULL &&
    219   1.1  ichiro 		    strcmp(pa->card->cis1_info[0], pp->pp_cisinfo[0]) == 0 &&
    220   1.1  ichiro 		    pa->card->cis1_info[1] != NULL &&
    221   1.1  ichiro 		    pp->pp_cisinfo[1] != NULL &&
    222   1.1  ichiro 		    strcmp(pa->card->cis1_info[1], pp->pp_cisinfo[1]) == 0)
    223   1.1  ichiro 			return pp;
    224   1.1  ichiro 	}
    225   1.1  ichiro 
    226   1.1  ichiro 	/* match by vendor/product id */
    227   1.1  ichiro 	for (pp = wi_pcmcia_products; pp->pp_name != NULL; pp++) {
    228   1.1  ichiro 		if (pa->manufacturer != PCMCIA_VENDOR_INVALID &&
    229   1.1  ichiro 		    pa->manufacturer == pp->pp_vendor &&
    230   1.1  ichiro 		    pa->product != PCMCIA_PRODUCT_INVALID &&
    231   1.1  ichiro 		    pa->product == pp->pp_product)
    232   1.1  ichiro 			return pp;
    233   1.1  ichiro 	}
    234   1.1  ichiro 
    235   1.1  ichiro 	return (NULL);
    236   1.1  ichiro }
    237   1.1  ichiro 
    238   1.1  ichiro static int
    239   1.1  ichiro wi_pcmcia_match(parent, match, aux)
    240   1.1  ichiro 	struct device *parent;
    241   1.1  ichiro 	struct cfdata *match;
    242   1.1  ichiro 	void *aux;
    243   1.1  ichiro {
    244   1.1  ichiro 	struct pcmcia_attach_args *pa = aux;
    245   1.1  ichiro 
    246   1.1  ichiro 	if (wi_pcmcia_lookup(pa) != NULL)
    247   1.1  ichiro 		return (1);
    248   1.1  ichiro 	return (0);
    249   1.1  ichiro }
    250   1.1  ichiro 
    251   1.1  ichiro static int
    252   1.1  ichiro wi_pcmcia_enable(sc)
    253   1.1  ichiro 	struct wi_softc *sc;
    254   1.1  ichiro {
    255   1.1  ichiro 	struct wi_pcmcia_softc *psc = (struct wi_pcmcia_softc *)sc;
    256   1.1  ichiro 	struct pcmcia_function *pf = psc->sc_pf;
    257   1.1  ichiro 
    258   1.1  ichiro 	/* establish the interrupt. */
    259   1.1  ichiro 	sc->sc_ih = pcmcia_intr_establish(pf, IPL_NET, wi_intr, sc);
    260   1.1  ichiro 	if (sc->sc_ih == NULL) {
    261   1.1  ichiro 		printf("%s: couldn't establish interrupt\n",
    262   1.1  ichiro 		    sc->sc_dev.dv_xname);
    263   1.1  ichiro 		return (EIO);
    264   1.1  ichiro 	}
    265   1.1  ichiro 	if (pcmcia_function_enable(pf) != 0) {
    266   1.1  ichiro 		printf("%s: couldn't enable card\n", sc->sc_dev.dv_xname);
    267   1.1  ichiro 		pcmcia_intr_disestablish(pf, sc->sc_ih);
    268   1.1  ichiro 		return (EIO);
    269   1.1  ichiro 	}
    270   1.1  ichiro 	DELAY(1000);
    271   1.1  ichiro 	return (0);
    272   1.1  ichiro }
    273   1.1  ichiro 
    274   1.1  ichiro static void
    275   1.1  ichiro wi_pcmcia_disable(sc)
    276   1.1  ichiro 	struct wi_softc *sc;
    277   1.1  ichiro {
    278   1.1  ichiro 	struct wi_pcmcia_softc *psc = (struct wi_pcmcia_softc *)sc;
    279   1.1  ichiro 
    280   1.1  ichiro 	pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih);
    281   1.1  ichiro 	pcmcia_function_disable(psc->sc_pf);
    282   1.1  ichiro }
    283   1.1  ichiro 
    284   1.1  ichiro static int
    285   1.1  ichiro wi_pcmcia_find(psc, pa, cfe)
    286   1.1  ichiro 	struct wi_pcmcia_softc *psc;
    287   1.1  ichiro 	struct pcmcia_attach_args *pa;
    288   1.1  ichiro 	struct pcmcia_config_entry *cfe;
    289   1.1  ichiro {
    290   1.1  ichiro 	struct wi_softc *sc = &psc->sc_wi;
    291   1.1  ichiro 
    292   1.1  ichiro 	/* Allocate/map I/O space. */
    293   1.1  ichiro 	if (pcmcia_io_alloc(psc->sc_pf, cfe->iospace[0].start,
    294   1.1  ichiro 	    cfe->iospace[0].length, WI_IOSIZE,
    295   1.1  ichiro 	    &psc->sc_pcioh) != 0) {
    296   1.1  ichiro 		printf("%s: can't allocate i/o space\n",
    297   1.1  ichiro 			sc->sc_dev.dv_xname);
    298   1.1  ichiro 		goto fail1;
    299   1.1  ichiro 	}
    300   1.1  ichiro 	printf("%s:", sc->sc_dev.dv_xname);
    301   1.1  ichiro 	if (pcmcia_io_map(psc->sc_pf, PCMCIA_WIDTH_AUTO, 0,
    302   1.1  ichiro 	    psc->sc_pcioh.size, &psc->sc_pcioh,
    303   1.1  ichiro 	    &psc->sc_io_window) != 0) {
    304   1.1  ichiro 		printf(" can't map i/o space\n");
    305   1.1  ichiro 		goto fail2;
    306   1.1  ichiro 	}
    307   1.1  ichiro 	/* Enable the card */
    308   1.1  ichiro 	pcmcia_function_init(psc->sc_pf, cfe);
    309   1.1  ichiro 	if (pcmcia_function_enable(psc->sc_pf)) {
    310   1.1  ichiro 		printf("%s: function enable failed\n", sc->sc_dev.dv_xname);
    311   1.1  ichiro 		goto fail3;
    312   1.1  ichiro 	}
    313   1.1  ichiro 
    314   1.1  ichiro 	sc->sc_iot = psc->sc_pcioh.iot;
    315   1.1  ichiro 	sc->sc_ioh = psc->sc_pcioh.ioh;
    316   1.1  ichiro 
    317   1.1  ichiro 	DELAY(1000);
    318   1.1  ichiro 	return(0);
    319   1.1  ichiro 
    320   1.1  ichiro fail3:
    321   1.1  ichiro 	pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
    322   1.1  ichiro fail2:
    323   1.1  ichiro 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    324   1.1  ichiro fail1:
    325   1.1  ichiro 	psc->sc_io_window = -1;
    326   1.1  ichiro 	return(1);
    327   1.1  ichiro }
    328   1.1  ichiro 
    329   1.1  ichiro static void
    330   1.1  ichiro wi_pcmcia_attach(parent, self, aux)
    331   1.1  ichiro 	struct device  *parent, *self;
    332   1.1  ichiro 	void           *aux;
    333   1.1  ichiro {
    334   1.1  ichiro 	struct wi_pcmcia_softc *psc = (void *)self;
    335   1.1  ichiro 	struct wi_softc *sc = &psc->sc_wi;
    336   1.1  ichiro 	const struct wi_pcmcia_product *pp;
    337   1.1  ichiro 	struct pcmcia_attach_args *pa = aux;
    338   1.1  ichiro 	struct pcmcia_config_entry *cfe;
    339   1.1  ichiro 	char devinfo[256];
    340   1.1  ichiro 
    341   1.1  ichiro 	/* Print out what we are. */
    342   1.1  ichiro 	pcmcia_devinfo(&pa->pf->sc->card, 0, devinfo, sizeof(devinfo));
    343   1.1  ichiro 	printf(": %s\n", devinfo);
    344   1.1  ichiro 
    345   1.1  ichiro 	psc->sc_pf = pa->pf;
    346   1.1  ichiro 
    347   1.1  ichiro 	for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL;
    348   1.1  ichiro 	     cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
    349   1.1  ichiro 		if (cfe->iftype != PCMCIA_IFTYPE_IO)
    350   1.1  ichiro 			continue;
    351   1.1  ichiro 		if (cfe->iospace[0].length < WI_IOSIZE)
    352   1.1  ichiro 			continue;
    353   1.1  ichiro 		if (wi_pcmcia_find(psc, pa, cfe) == 0)
    354   1.1  ichiro 			break;
    355   1.1  ichiro 	}
    356   1.1  ichiro 	if (cfe == NULL) {
    357   1.1  ichiro 		printf(": no suitable CIS info found\n");
    358   1.1  ichiro 		goto no_config_entry;
    359   1.1  ichiro 	}
    360   1.1  ichiro 
    361   1.1  ichiro 	pp = wi_pcmcia_lookup(pa);
    362   1.1  ichiro 	if (pp == NULL)
    363   1.1  ichiro 		panic("wi_pcmcia_attach: impossible");
    364   1.1  ichiro 
    365   1.8  ichiro 	sc->sc_pci = 0;
    366   1.1  ichiro 	sc->sc_enabled = 1;
    367   1.1  ichiro 	sc->sc_enable = wi_pcmcia_enable;
    368   1.1  ichiro 	sc->sc_disable = wi_pcmcia_disable;
    369   1.1  ichiro 
    370   1.1  ichiro 	/* establish the interrupt. */
    371   1.1  ichiro 	sc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, wi_intr, sc);
    372   1.1  ichiro 	if (sc->sc_ih == NULL) {
    373   1.1  ichiro 		printf("%s: couldn't establish interrupt\n",
    374   1.1  ichiro 		        sc->sc_dev.dv_xname);
    375   1.1  ichiro 		goto no_interrupt;
    376   1.1  ichiro 	}
    377   1.1  ichiro 
    378   1.1  ichiro 	sc->sc_ifp = &sc->sc_ethercom.ec_if;
    379   1.1  ichiro 	if (wi_attach(sc) != 0) {
    380   1.1  ichiro 		printf("%s: failed to attach controller\n",
    381   1.1  ichiro 		    sc->sc_dev.dv_xname);
    382   1.1  ichiro 			goto attach_failed;
    383   1.1  ichiro 	}
    384   1.1  ichiro 
    385   1.1  ichiro 	psc->sc_sdhook    = shutdownhook_establish(wi_pcmcia_shutdown, psc);
    386   1.1  ichiro 	psc->sc_powerhook = powerhook_establish(wi_pcmcia_powerhook, psc);
    387   1.1  ichiro 
    388   1.1  ichiro 	/* disable the card */
    389   1.1  ichiro 	sc->sc_enabled = 0;
    390   1.1  ichiro 	wi_pcmcia_disable(sc);
    391   1.2  ichiro 
    392   1.1  ichiro 	return;
    393   1.1  ichiro 
    394   1.1  ichiro attach_failed:
    395   1.1  ichiro 	pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih);
    396   1.1  ichiro no_interrupt:
    397   1.6    onoe 	pcmcia_function_disable(psc->sc_pf);
    398   1.1  ichiro 	pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
    399   1.1  ichiro 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    400   1.1  ichiro no_config_entry:
    401   1.1  ichiro 	psc->sc_io_window = -1;
    402   1.1  ichiro }
    403   1.1  ichiro 
    404   1.1  ichiro static int
    405   1.1  ichiro wi_pcmcia_detach(self, flags)
    406   1.1  ichiro 	struct device *self;
    407   1.1  ichiro 	int flags;
    408   1.1  ichiro {
    409   1.1  ichiro 	struct wi_pcmcia_softc *psc = (struct wi_pcmcia_softc *)self;
    410   1.1  ichiro 	int error;
    411   1.1  ichiro 
    412   1.1  ichiro 	if (psc->sc_io_window == -1)
    413   1.1  ichiro 		/* Nothing to detach. */
    414   1.1  ichiro 		return (0);
    415   1.1  ichiro 
    416   1.1  ichiro 	if (psc->sc_powerhook != NULL)
    417   1.1  ichiro 		powerhook_disestablish(psc->sc_powerhook);
    418   1.1  ichiro 	if (psc->sc_sdhook != NULL)
    419   1.1  ichiro 		shutdownhook_disestablish(psc->sc_sdhook);
    420   1.1  ichiro 
    421   1.1  ichiro 	error = wi_detach(&psc->sc_wi);
    422   1.1  ichiro 	if (error != 0)
    423   1.1  ichiro 		return (error);
    424   1.1  ichiro 
    425   1.1  ichiro 	/* Unmap our i/o window. */
    426   1.1  ichiro 	pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
    427   1.1  ichiro 
    428   1.1  ichiro 	/* Free our i/o space. */
    429   1.1  ichiro 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
    430   1.1  ichiro 	return (0);
    431   1.1  ichiro }
    432   1.1  ichiro 
    433   1.1  ichiro static void
    434   1.1  ichiro wi_pcmcia_powerhook(why, arg)
    435   1.1  ichiro 	int why;
    436   1.1  ichiro 	void *arg;
    437   1.1  ichiro {
    438   1.1  ichiro 	struct wi_pcmcia_softc *psc = arg;
    439   1.1  ichiro 	struct wi_softc *sc = &psc->sc_wi;
    440   1.1  ichiro 
    441   1.1  ichiro 	wi_power(sc, why);
    442   1.1  ichiro }
    443   1.1  ichiro 
    444   1.1  ichiro static void
    445   1.1  ichiro wi_pcmcia_shutdown(arg)
    446   1.1  ichiro 	void *arg;
    447   1.1  ichiro {
    448   1.1  ichiro 	struct wi_pcmcia_softc *psc = arg;
    449   1.1  ichiro 	struct wi_softc *sc = &psc->sc_wi;
    450   1.1  ichiro 
    451   1.1  ichiro 	wi_shutdown(sc);
    452   1.1  ichiro }
    453