if_wi_pcmcia.c revision 1.15 1 1.15 christos /* $NetBSD: if_wi_pcmcia.c,v 1.15 2001/12/04 18:46:30 christos 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.12 lukem
43 1.12 lukem #include <sys/cdefs.h>
44 1.15 christos __KERNEL_RCSID(0, "$NetBSD: if_wi_pcmcia.c,v 1.15 2001/12/04 18:46:30 christos Exp $");
45 1.1 ichiro
46 1.1 ichiro #include <sys/param.h>
47 1.1 ichiro #include <sys/systm.h>
48 1.1 ichiro #include <sys/callout.h>
49 1.1 ichiro #include <sys/device.h>
50 1.1 ichiro #include <sys/socket.h>
51 1.1 ichiro
52 1.1 ichiro #include <net/if.h>
53 1.1 ichiro #include <net/if_ether.h>
54 1.1 ichiro #include <net/if_media.h>
55 1.1 ichiro #include <net/if_ieee80211.h>
56 1.1 ichiro
57 1.1 ichiro #include <machine/cpu.h>
58 1.1 ichiro #include <machine/bus.h>
59 1.1 ichiro #include <machine/intr.h>
60 1.1 ichiro
61 1.1 ichiro #include <dev/ic/wi_ieee.h>
62 1.1 ichiro #include <dev/ic/wireg.h>
63 1.1 ichiro #include <dev/ic/wivar.h>
64 1.1 ichiro
65 1.1 ichiro #include <dev/pcmcia/pcmciareg.h>
66 1.1 ichiro #include <dev/pcmcia/pcmciavar.h>
67 1.1 ichiro #include <dev/pcmcia/pcmciadevs.h>
68 1.1 ichiro
69 1.1 ichiro static int wi_pcmcia_match __P((struct device *, struct cfdata *, void *));
70 1.1 ichiro static void wi_pcmcia_attach __P((struct device *, struct device *, void *));
71 1.1 ichiro static int wi_pcmcia_detach __P((struct device *, int));
72 1.1 ichiro static int wi_pcmcia_enable __P((struct wi_softc *));
73 1.1 ichiro static void wi_pcmcia_disable __P((struct wi_softc *));
74 1.1 ichiro static void wi_pcmcia_powerhook __P((int, void *));
75 1.1 ichiro static void wi_pcmcia_shutdown __P((void *));
76 1.1 ichiro
77 1.1 ichiro static const struct wi_pcmcia_product
78 1.1 ichiro *wi_pcmcia_lookup __P((struct pcmcia_attach_args *pa));
79 1.1 ichiro
80 1.1 ichiro struct wi_pcmcia_softc {
81 1.1 ichiro struct wi_softc sc_wi;
82 1.1 ichiro
83 1.1 ichiro /* PCMCIA-specific */
84 1.1 ichiro struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o space info */
85 1.1 ichiro int sc_io_window; /* our i/o window */
86 1.1 ichiro struct pcmcia_function *sc_pf; /* PCMCIA function */
87 1.1 ichiro void *sc_powerhook; /* power hook descriptor */
88 1.1 ichiro void *sc_sdhook; /* shutdown hook */
89 1.1 ichiro
90 1.1 ichiro };
91 1.1 ichiro
92 1.1 ichiro static int wi_pcmcia_find __P((struct wi_pcmcia_softc *,
93 1.1 ichiro struct pcmcia_attach_args *, struct pcmcia_config_entry *));
94 1.1 ichiro
95 1.1 ichiro struct cfattach wi_pcmcia_ca = {
96 1.1 ichiro sizeof(struct wi_pcmcia_softc), wi_pcmcia_match, wi_pcmcia_attach,
97 1.1 ichiro wi_pcmcia_detach, wi_activate,
98 1.1 ichiro };
99 1.1 ichiro
100 1.1 ichiro static const struct wi_pcmcia_product {
101 1.1 ichiro u_int32_t pp_vendor; /* vendor ID */
102 1.1 ichiro u_int32_t pp_product; /* product ID */
103 1.1 ichiro const char *pp_cisinfo[4]; /* CIS information */
104 1.1 ichiro const char *pp_name; /* product name */
105 1.1 ichiro } wi_pcmcia_products[] = {
106 1.1 ichiro { PCMCIA_VENDOR_LUCENT,
107 1.1 ichiro PCMCIA_PRODUCT_LUCENT_WAVELAN_IEEE,
108 1.1 ichiro PCMCIA_CIS_LUCENT_WAVELAN_IEEE,
109 1.2 ichiro PCMCIA_STR_LUCENT_WAVELAN_IEEE },
110 1.1 ichiro
111 1.1 ichiro { PCMCIA_VENDOR_3COM,
112 1.1 ichiro PCMCIA_PRODUCT_3COM_3CRWE737A,
113 1.1 ichiro PCMCIA_CIS_3COM_3CRWE737A,
114 1.2 ichiro PCMCIA_STR_3COM_3CRWE737A },
115 1.1 ichiro
116 1.1 ichiro { PCMCIA_VENDOR_COREGA,
117 1.1 ichiro PCMCIA_PRODUCT_COREGA_WIRELESS_LAN_PCC_11,
118 1.1 ichiro PCMCIA_CIS_COREGA_WIRELESS_LAN_PCC_11,
119 1.2 ichiro PCMCIA_STR_COREGA_WIRELESS_LAN_PCC_11 },
120 1.1 ichiro
121 1.1 ichiro { PCMCIA_VENDOR_COREGA,
122 1.1 ichiro PCMCIA_PRODUCT_COREGA_WIRELESS_LAN_PCCA_11,
123 1.1 ichiro PCMCIA_CIS_COREGA_WIRELESS_LAN_PCCA_11,
124 1.2 ichiro PCMCIA_STR_COREGA_WIRELESS_LAN_PCCA_11 },
125 1.9 mjl
126 1.9 mjl { PCMCIA_VENDOR_COREGA,
127 1.9 mjl PCMCIA_PRODUCT_COREGA_WIRELESS_LAN_PCCB_11,
128 1.9 mjl PCMCIA_CIS_COREGA_WIRELESS_LAN_PCCB_11,
129 1.9 mjl PCMCIA_STR_COREGA_WIRELESS_LAN_PCCB_11 },
130 1.1 ichiro
131 1.11 imp { PCMCIA_VENDOR_INTEL,
132 1.11 imp PCMCIA_PRODUCT_INTEL_PRO_WLAN_2011,
133 1.11 imp PCMCIA_CIS_INTEL_PRO_WLAN_2011,
134 1.11 imp PCMCIA_STR_INTEL_PRO_WLAN_2011 },
135 1.11 imp
136 1.1 ichiro { PCMCIA_VENDOR_INTERSIL,
137 1.1 ichiro PCMCIA_PRODUCT_INTERSIL_PRISM2,
138 1.1 ichiro PCMCIA_CIS_INTERSIL_PRISM2,
139 1.2 ichiro PCMCIA_STR_INTERSIL_PRISM2 },
140 1.1 ichiro
141 1.1 ichiro { PCMCIA_VENDOR_SAMSUNG,
142 1.1 ichiro PCMCIA_PRODUCT_SAMSUNG_SWL_2000N,
143 1.1 ichiro PCMCIA_CIS_SAMSUNG_SWL_2000N,
144 1.2 ichiro PCMCIA_STR_SAMSUNG_SWL_2000N },
145 1.1 ichiro
146 1.1 ichiro { PCMCIA_VENDOR_LUCENT,
147 1.1 ichiro PCMCIA_PRODUCT_LUCENT_WAVELAN_IEEE,
148 1.1 ichiro PCMCIA_CIS_SMC_2632W,
149 1.2 ichiro PCMCIA_STR_SMC_2632W },
150 1.1 ichiro
151 1.1 ichiro { PCMCIA_VENDOR_LUCENT,
152 1.1 ichiro PCMCIA_PRODUCT_LUCENT_WAVELAN_IEEE,
153 1.13 mrg PCMCIA_CIS_NANOSPEED_PRISM2,
154 1.13 mrg PCMCIA_STR_NANOSPEED_PRISM2 },
155 1.13 mrg
156 1.13 mrg { PCMCIA_VENDOR_LINKSYS2,
157 1.13 mrg PCMCIA_PRODUCT_LINKSYS2_IWN,
158 1.1 ichiro PCMCIA_CIS_NANOSPEED_PRISM2,
159 1.2 ichiro PCMCIA_STR_NANOSPEED_PRISM2 },
160 1.1 ichiro
161 1.1 ichiro { PCMCIA_VENDOR_ELSA,
162 1.1 ichiro PCMCIA_PRODUCT_ELSA_XI300_IEEE,
163 1.1 ichiro PCMCIA_CIS_ELSA_XI300_IEEE,
164 1.2 ichiro PCMCIA_STR_ELSA_XI300_IEEE },
165 1.1 ichiro
166 1.1 ichiro { PCMCIA_VENDOR_COMPAQ,
167 1.1 ichiro PCMCIA_PRODUCT_COMPAQ_NC5004,
168 1.1 ichiro PCMCIA_CIS_COMPAQ_NC5004,
169 1.2 ichiro PCMCIA_STR_COMPAQ_NC5004 },
170 1.1 ichiro
171 1.1 ichiro { PCMCIA_VENDOR_CONTEC,
172 1.1 ichiro PCMCIA_PRODUCT_CONTEC_FX_DS110_PCC,
173 1.1 ichiro PCMCIA_CIS_CONTEC_FX_DS110_PCC,
174 1.2 ichiro PCMCIA_STR_CONTEC_FX_DS110_PCC },
175 1.1 ichiro
176 1.1 ichiro { PCMCIA_VENDOR_TDK,
177 1.1 ichiro PCMCIA_PRODUCT_TDK_LAK_CD011WL,
178 1.1 ichiro PCMCIA_CIS_TDK_LAK_CD011WL,
179 1.2 ichiro PCMCIA_STR_TDK_LAK_CD011WL },
180 1.1 ichiro
181 1.1 ichiro { PCMCIA_VENDOR_LUCENT,
182 1.1 ichiro PCMCIA_PRODUCT_LUCENT_WAVELAN_IEEE,
183 1.1 ichiro PCMCIA_CIS_NEC_CMZ_RT_WP,
184 1.2 ichiro PCMCIA_STR_NEC_CMZ_RT_WP },
185 1.1 ichiro
186 1.1 ichiro { PCMCIA_VENDOR_LUCENT,
187 1.1 ichiro PCMCIA_PRODUCT_LUCENT_WAVELAN_IEEE,
188 1.1 ichiro PCMCIA_CIS_NTT_ME_WLAN,
189 1.2 ichiro PCMCIA_STR_NTT_ME_WLAN },
190 1.1 ichiro
191 1.1 ichiro { PCMCIA_VENDOR_IODATA2,
192 1.1 ichiro PCMCIA_PRODUCT_IODATA2_WNB11PCM,
193 1.1 ichiro PCMCIA_CIS_IODATA2_WNB11PCM,
194 1.2 ichiro PCMCIA_STR_IODATA2_WNB11PCM },
195 1.3 ichiro
196 1.3 ichiro { PCMCIA_VENDOR_BUFFALO,
197 1.3 ichiro PCMCIA_PRODUCT_BUFFALO_WLI_PCM_S11,
198 1.3 ichiro PCMCIA_CIS_BUFFALO_WLI_PCM_S11,
199 1.3 ichiro PCMCIA_STR_BUFFALO_WLI_PCM_S11 },
200 1.14 ichiro
201 1.14 ichiro { PCMCIA_VENDOR_BUFFALO,
202 1.14 ichiro PCMCIA_PRODUCT_BUFFALO_WLI_CF_S11G,
203 1.14 ichiro PCMCIA_CIS_BUFFALO_WLI_CF_S11G,
204 1.14 ichiro PCMCIA_STR_BUFFALO_WLI_CF_S11G },
205 1.4 ichiro
206 1.1 ichiro { PCMCIA_VENDOR_EMTAC,
207 1.1 ichiro PCMCIA_PRODUCT_EMTAC_WLAN,
208 1.1 ichiro PCMCIA_CIS_EMTAC_WLAN,
209 1.2 ichiro PCMCIA_STR_EMTAC_WLAN },
210 1.7 ichiro
211 1.7 ichiro { PCMCIA_VENDOR_INTERSIL,
212 1.7 ichiro PCMCIA_PRODUCT_GEMTEK_WLAN,
213 1.7 ichiro PCMCIA_CIS_GEMTEK_WLAN,
214 1.7 ichiro PCMCIA_STR_GEMTEK_WLAN },
215 1.10 ichiro
216 1.10 ichiro { PCMCIA_VENDOR_ELSA,
217 1.10 ichiro PCMCIA_PRODUCT_ELSA_XI800_IEEE,
218 1.10 ichiro PCMCIA_CIS_ELSA_XI800_IEEE,
219 1.10 ichiro PCMCIA_STR_ELSA_XI800_IEEE },
220 1.15 christos
221 1.15 christos { PCMCIA_VENDOR_SIMPLETECH,
222 1.15 christos PCMCIA_PRODUCT_SIMPLETECH_SPECTRUM24_ALT,
223 1.15 christos PCMCIA_CIS_SIMPLETECH_SPECTRUM24_ALT,
224 1.15 christos PCMCIA_STR_SIMPLETECH_SPECTRUM24_ALT },
225 1.4 ichiro
226 1.1 ichiro { 0,
227 1.1 ichiro 0,
228 1.1 ichiro { NULL, NULL, NULL, NULL },
229 1.2 ichiro NULL }
230 1.1 ichiro };
231 1.1 ichiro
232 1.1 ichiro static const struct wi_pcmcia_product *
233 1.1 ichiro wi_pcmcia_lookup(pa)
234 1.1 ichiro struct pcmcia_attach_args *pa;
235 1.1 ichiro {
236 1.1 ichiro const struct wi_pcmcia_product *pp;
237 1.1 ichiro
238 1.1 ichiro /* match by CIS information */
239 1.1 ichiro for (pp = wi_pcmcia_products; pp->pp_name != NULL; pp++) {
240 1.1 ichiro if (pa->card->cis1_info[0] != NULL &&
241 1.1 ichiro pp->pp_cisinfo[0] != NULL &&
242 1.1 ichiro strcmp(pa->card->cis1_info[0], pp->pp_cisinfo[0]) == 0 &&
243 1.1 ichiro pa->card->cis1_info[1] != NULL &&
244 1.1 ichiro pp->pp_cisinfo[1] != NULL &&
245 1.1 ichiro strcmp(pa->card->cis1_info[1], pp->pp_cisinfo[1]) == 0)
246 1.1 ichiro return pp;
247 1.1 ichiro }
248 1.1 ichiro
249 1.1 ichiro /* match by vendor/product id */
250 1.1 ichiro for (pp = wi_pcmcia_products; pp->pp_name != NULL; pp++) {
251 1.1 ichiro if (pa->manufacturer != PCMCIA_VENDOR_INVALID &&
252 1.1 ichiro pa->manufacturer == pp->pp_vendor &&
253 1.1 ichiro pa->product != PCMCIA_PRODUCT_INVALID &&
254 1.1 ichiro pa->product == pp->pp_product)
255 1.1 ichiro return pp;
256 1.1 ichiro }
257 1.1 ichiro
258 1.1 ichiro return (NULL);
259 1.1 ichiro }
260 1.1 ichiro
261 1.1 ichiro static int
262 1.1 ichiro wi_pcmcia_match(parent, match, aux)
263 1.1 ichiro struct device *parent;
264 1.1 ichiro struct cfdata *match;
265 1.1 ichiro void *aux;
266 1.1 ichiro {
267 1.1 ichiro struct pcmcia_attach_args *pa = aux;
268 1.1 ichiro
269 1.1 ichiro if (wi_pcmcia_lookup(pa) != NULL)
270 1.1 ichiro return (1);
271 1.1 ichiro return (0);
272 1.1 ichiro }
273 1.1 ichiro
274 1.1 ichiro static int
275 1.1 ichiro wi_pcmcia_enable(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 struct pcmcia_function *pf = psc->sc_pf;
280 1.1 ichiro
281 1.1 ichiro /* establish the interrupt. */
282 1.1 ichiro sc->sc_ih = pcmcia_intr_establish(pf, IPL_NET, wi_intr, sc);
283 1.1 ichiro if (sc->sc_ih == NULL) {
284 1.1 ichiro printf("%s: couldn't establish interrupt\n",
285 1.1 ichiro sc->sc_dev.dv_xname);
286 1.1 ichiro return (EIO);
287 1.1 ichiro }
288 1.1 ichiro if (pcmcia_function_enable(pf) != 0) {
289 1.1 ichiro printf("%s: couldn't enable card\n", sc->sc_dev.dv_xname);
290 1.1 ichiro pcmcia_intr_disestablish(pf, sc->sc_ih);
291 1.1 ichiro return (EIO);
292 1.1 ichiro }
293 1.1 ichiro DELAY(1000);
294 1.1 ichiro return (0);
295 1.1 ichiro }
296 1.1 ichiro
297 1.1 ichiro static void
298 1.1 ichiro wi_pcmcia_disable(sc)
299 1.1 ichiro struct wi_softc *sc;
300 1.1 ichiro {
301 1.1 ichiro struct wi_pcmcia_softc *psc = (struct wi_pcmcia_softc *)sc;
302 1.1 ichiro
303 1.1 ichiro pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih);
304 1.1 ichiro pcmcia_function_disable(psc->sc_pf);
305 1.1 ichiro }
306 1.1 ichiro
307 1.1 ichiro static int
308 1.1 ichiro wi_pcmcia_find(psc, pa, cfe)
309 1.1 ichiro struct wi_pcmcia_softc *psc;
310 1.1 ichiro struct pcmcia_attach_args *pa;
311 1.1 ichiro struct pcmcia_config_entry *cfe;
312 1.1 ichiro {
313 1.1 ichiro struct wi_softc *sc = &psc->sc_wi;
314 1.1 ichiro
315 1.1 ichiro /* Allocate/map I/O space. */
316 1.1 ichiro if (pcmcia_io_alloc(psc->sc_pf, cfe->iospace[0].start,
317 1.1 ichiro cfe->iospace[0].length, WI_IOSIZE,
318 1.1 ichiro &psc->sc_pcioh) != 0) {
319 1.1 ichiro printf("%s: can't allocate i/o space\n",
320 1.1 ichiro sc->sc_dev.dv_xname);
321 1.1 ichiro goto fail1;
322 1.1 ichiro }
323 1.1 ichiro printf("%s:", sc->sc_dev.dv_xname);
324 1.1 ichiro if (pcmcia_io_map(psc->sc_pf, PCMCIA_WIDTH_AUTO, 0,
325 1.1 ichiro psc->sc_pcioh.size, &psc->sc_pcioh,
326 1.1 ichiro &psc->sc_io_window) != 0) {
327 1.1 ichiro printf(" can't map i/o space\n");
328 1.1 ichiro goto fail2;
329 1.1 ichiro }
330 1.1 ichiro /* Enable the card */
331 1.1 ichiro pcmcia_function_init(psc->sc_pf, cfe);
332 1.1 ichiro if (pcmcia_function_enable(psc->sc_pf)) {
333 1.1 ichiro printf("%s: function enable failed\n", sc->sc_dev.dv_xname);
334 1.1 ichiro goto fail3;
335 1.1 ichiro }
336 1.1 ichiro
337 1.1 ichiro sc->sc_iot = psc->sc_pcioh.iot;
338 1.1 ichiro sc->sc_ioh = psc->sc_pcioh.ioh;
339 1.1 ichiro
340 1.1 ichiro DELAY(1000);
341 1.1 ichiro return(0);
342 1.1 ichiro
343 1.1 ichiro fail3:
344 1.1 ichiro pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
345 1.1 ichiro fail2:
346 1.1 ichiro pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
347 1.1 ichiro fail1:
348 1.1 ichiro psc->sc_io_window = -1;
349 1.1 ichiro return(1);
350 1.1 ichiro }
351 1.1 ichiro
352 1.1 ichiro static void
353 1.1 ichiro wi_pcmcia_attach(parent, self, aux)
354 1.1 ichiro struct device *parent, *self;
355 1.1 ichiro void *aux;
356 1.1 ichiro {
357 1.1 ichiro struct wi_pcmcia_softc *psc = (void *)self;
358 1.1 ichiro struct wi_softc *sc = &psc->sc_wi;
359 1.1 ichiro const struct wi_pcmcia_product *pp;
360 1.1 ichiro struct pcmcia_attach_args *pa = aux;
361 1.1 ichiro struct pcmcia_config_entry *cfe;
362 1.1 ichiro char devinfo[256];
363 1.1 ichiro
364 1.1 ichiro /* Print out what we are. */
365 1.1 ichiro pcmcia_devinfo(&pa->pf->sc->card, 0, devinfo, sizeof(devinfo));
366 1.1 ichiro printf(": %s\n", devinfo);
367 1.1 ichiro
368 1.1 ichiro psc->sc_pf = pa->pf;
369 1.1 ichiro
370 1.1 ichiro for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL;
371 1.1 ichiro cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
372 1.1 ichiro if (cfe->iftype != PCMCIA_IFTYPE_IO)
373 1.1 ichiro continue;
374 1.1 ichiro if (cfe->iospace[0].length < WI_IOSIZE)
375 1.1 ichiro continue;
376 1.1 ichiro if (wi_pcmcia_find(psc, pa, cfe) == 0)
377 1.1 ichiro break;
378 1.1 ichiro }
379 1.1 ichiro if (cfe == NULL) {
380 1.1 ichiro printf(": no suitable CIS info found\n");
381 1.1 ichiro goto no_config_entry;
382 1.1 ichiro }
383 1.1 ichiro
384 1.1 ichiro pp = wi_pcmcia_lookup(pa);
385 1.1 ichiro if (pp == NULL)
386 1.1 ichiro panic("wi_pcmcia_attach: impossible");
387 1.1 ichiro
388 1.8 ichiro sc->sc_pci = 0;
389 1.1 ichiro sc->sc_enabled = 1;
390 1.1 ichiro sc->sc_enable = wi_pcmcia_enable;
391 1.1 ichiro sc->sc_disable = wi_pcmcia_disable;
392 1.1 ichiro
393 1.1 ichiro /* establish the interrupt. */
394 1.1 ichiro sc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, wi_intr, sc);
395 1.1 ichiro if (sc->sc_ih == NULL) {
396 1.1 ichiro printf("%s: couldn't establish interrupt\n",
397 1.1 ichiro sc->sc_dev.dv_xname);
398 1.1 ichiro goto no_interrupt;
399 1.1 ichiro }
400 1.1 ichiro
401 1.1 ichiro sc->sc_ifp = &sc->sc_ethercom.ec_if;
402 1.1 ichiro if (wi_attach(sc) != 0) {
403 1.1 ichiro printf("%s: failed to attach controller\n",
404 1.1 ichiro sc->sc_dev.dv_xname);
405 1.1 ichiro goto attach_failed;
406 1.1 ichiro }
407 1.1 ichiro
408 1.1 ichiro psc->sc_sdhook = shutdownhook_establish(wi_pcmcia_shutdown, psc);
409 1.1 ichiro psc->sc_powerhook = powerhook_establish(wi_pcmcia_powerhook, psc);
410 1.1 ichiro
411 1.1 ichiro /* disable the card */
412 1.1 ichiro sc->sc_enabled = 0;
413 1.1 ichiro wi_pcmcia_disable(sc);
414 1.2 ichiro
415 1.1 ichiro return;
416 1.1 ichiro
417 1.1 ichiro attach_failed:
418 1.1 ichiro pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih);
419 1.1 ichiro no_interrupt:
420 1.6 onoe pcmcia_function_disable(psc->sc_pf);
421 1.1 ichiro pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
422 1.1 ichiro pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
423 1.1 ichiro no_config_entry:
424 1.1 ichiro psc->sc_io_window = -1;
425 1.1 ichiro }
426 1.1 ichiro
427 1.1 ichiro static int
428 1.1 ichiro wi_pcmcia_detach(self, flags)
429 1.1 ichiro struct device *self;
430 1.1 ichiro int flags;
431 1.1 ichiro {
432 1.1 ichiro struct wi_pcmcia_softc *psc = (struct wi_pcmcia_softc *)self;
433 1.1 ichiro int error;
434 1.1 ichiro
435 1.1 ichiro if (psc->sc_io_window == -1)
436 1.1 ichiro /* Nothing to detach. */
437 1.1 ichiro return (0);
438 1.1 ichiro
439 1.1 ichiro if (psc->sc_powerhook != NULL)
440 1.1 ichiro powerhook_disestablish(psc->sc_powerhook);
441 1.1 ichiro if (psc->sc_sdhook != NULL)
442 1.1 ichiro shutdownhook_disestablish(psc->sc_sdhook);
443 1.1 ichiro
444 1.1 ichiro error = wi_detach(&psc->sc_wi);
445 1.1 ichiro if (error != 0)
446 1.1 ichiro return (error);
447 1.1 ichiro
448 1.1 ichiro /* Unmap our i/o window. */
449 1.1 ichiro pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
450 1.1 ichiro
451 1.1 ichiro /* Free our i/o space. */
452 1.1 ichiro pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
453 1.1 ichiro return (0);
454 1.1 ichiro }
455 1.1 ichiro
456 1.1 ichiro static void
457 1.1 ichiro wi_pcmcia_powerhook(why, arg)
458 1.1 ichiro int why;
459 1.1 ichiro void *arg;
460 1.1 ichiro {
461 1.1 ichiro struct wi_pcmcia_softc *psc = arg;
462 1.1 ichiro struct wi_softc *sc = &psc->sc_wi;
463 1.1 ichiro
464 1.1 ichiro wi_power(sc, why);
465 1.1 ichiro }
466 1.1 ichiro
467 1.1 ichiro static void
468 1.1 ichiro wi_pcmcia_shutdown(arg)
469 1.1 ichiro void *arg;
470 1.1 ichiro {
471 1.1 ichiro struct wi_pcmcia_softc *psc = arg;
472 1.1 ichiro struct wi_softc *sc = &psc->sc_wi;
473 1.1 ichiro
474 1.1 ichiro wi_shutdown(sc);
475 1.1 ichiro }
476