if_wi_pcmcia.c revision 1.13 1 1.13 mrg /* $NetBSD: if_wi_pcmcia.c,v 1.13 2001/11/18 04:27:49 mrg 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.13 mrg __KERNEL_RCSID(0, "$NetBSD: if_wi_pcmcia.c,v 1.13 2001/11/18 04:27:49 mrg 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.4 ichiro
201 1.1 ichiro { PCMCIA_VENDOR_EMTAC,
202 1.1 ichiro PCMCIA_PRODUCT_EMTAC_WLAN,
203 1.1 ichiro PCMCIA_CIS_EMTAC_WLAN,
204 1.2 ichiro PCMCIA_STR_EMTAC_WLAN },
205 1.7 ichiro
206 1.7 ichiro { PCMCIA_VENDOR_INTERSIL,
207 1.7 ichiro PCMCIA_PRODUCT_GEMTEK_WLAN,
208 1.7 ichiro PCMCIA_CIS_GEMTEK_WLAN,
209 1.7 ichiro PCMCIA_STR_GEMTEK_WLAN },
210 1.10 ichiro
211 1.10 ichiro { PCMCIA_VENDOR_ELSA,
212 1.10 ichiro PCMCIA_PRODUCT_ELSA_XI800_IEEE,
213 1.10 ichiro PCMCIA_CIS_ELSA_XI800_IEEE,
214 1.10 ichiro PCMCIA_STR_ELSA_XI800_IEEE },
215 1.4 ichiro
216 1.1 ichiro { 0,
217 1.1 ichiro 0,
218 1.1 ichiro { NULL, NULL, NULL, NULL },
219 1.2 ichiro NULL }
220 1.1 ichiro };
221 1.1 ichiro
222 1.1 ichiro static const struct wi_pcmcia_product *
223 1.1 ichiro wi_pcmcia_lookup(pa)
224 1.1 ichiro struct pcmcia_attach_args *pa;
225 1.1 ichiro {
226 1.1 ichiro const struct wi_pcmcia_product *pp;
227 1.1 ichiro
228 1.1 ichiro /* match by CIS information */
229 1.1 ichiro for (pp = wi_pcmcia_products; pp->pp_name != NULL; pp++) {
230 1.1 ichiro if (pa->card->cis1_info[0] != NULL &&
231 1.1 ichiro pp->pp_cisinfo[0] != NULL &&
232 1.1 ichiro strcmp(pa->card->cis1_info[0], pp->pp_cisinfo[0]) == 0 &&
233 1.1 ichiro pa->card->cis1_info[1] != NULL &&
234 1.1 ichiro pp->pp_cisinfo[1] != NULL &&
235 1.1 ichiro strcmp(pa->card->cis1_info[1], pp->pp_cisinfo[1]) == 0)
236 1.1 ichiro return pp;
237 1.1 ichiro }
238 1.1 ichiro
239 1.1 ichiro /* match by vendor/product id */
240 1.1 ichiro for (pp = wi_pcmcia_products; pp->pp_name != NULL; pp++) {
241 1.1 ichiro if (pa->manufacturer != PCMCIA_VENDOR_INVALID &&
242 1.1 ichiro pa->manufacturer == pp->pp_vendor &&
243 1.1 ichiro pa->product != PCMCIA_PRODUCT_INVALID &&
244 1.1 ichiro pa->product == pp->pp_product)
245 1.1 ichiro return pp;
246 1.1 ichiro }
247 1.1 ichiro
248 1.1 ichiro return (NULL);
249 1.1 ichiro }
250 1.1 ichiro
251 1.1 ichiro static int
252 1.1 ichiro wi_pcmcia_match(parent, match, aux)
253 1.1 ichiro struct device *parent;
254 1.1 ichiro struct cfdata *match;
255 1.1 ichiro void *aux;
256 1.1 ichiro {
257 1.1 ichiro struct pcmcia_attach_args *pa = aux;
258 1.1 ichiro
259 1.1 ichiro if (wi_pcmcia_lookup(pa) != NULL)
260 1.1 ichiro return (1);
261 1.1 ichiro return (0);
262 1.1 ichiro }
263 1.1 ichiro
264 1.1 ichiro static int
265 1.1 ichiro wi_pcmcia_enable(sc)
266 1.1 ichiro struct wi_softc *sc;
267 1.1 ichiro {
268 1.1 ichiro struct wi_pcmcia_softc *psc = (struct wi_pcmcia_softc *)sc;
269 1.1 ichiro struct pcmcia_function *pf = psc->sc_pf;
270 1.1 ichiro
271 1.1 ichiro /* establish the interrupt. */
272 1.1 ichiro sc->sc_ih = pcmcia_intr_establish(pf, IPL_NET, wi_intr, sc);
273 1.1 ichiro if (sc->sc_ih == NULL) {
274 1.1 ichiro printf("%s: couldn't establish interrupt\n",
275 1.1 ichiro sc->sc_dev.dv_xname);
276 1.1 ichiro return (EIO);
277 1.1 ichiro }
278 1.1 ichiro if (pcmcia_function_enable(pf) != 0) {
279 1.1 ichiro printf("%s: couldn't enable card\n", sc->sc_dev.dv_xname);
280 1.1 ichiro pcmcia_intr_disestablish(pf, sc->sc_ih);
281 1.1 ichiro return (EIO);
282 1.1 ichiro }
283 1.1 ichiro DELAY(1000);
284 1.1 ichiro return (0);
285 1.1 ichiro }
286 1.1 ichiro
287 1.1 ichiro static void
288 1.1 ichiro wi_pcmcia_disable(sc)
289 1.1 ichiro struct wi_softc *sc;
290 1.1 ichiro {
291 1.1 ichiro struct wi_pcmcia_softc *psc = (struct wi_pcmcia_softc *)sc;
292 1.1 ichiro
293 1.1 ichiro pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih);
294 1.1 ichiro pcmcia_function_disable(psc->sc_pf);
295 1.1 ichiro }
296 1.1 ichiro
297 1.1 ichiro static int
298 1.1 ichiro wi_pcmcia_find(psc, pa, cfe)
299 1.1 ichiro struct wi_pcmcia_softc *psc;
300 1.1 ichiro struct pcmcia_attach_args *pa;
301 1.1 ichiro struct pcmcia_config_entry *cfe;
302 1.1 ichiro {
303 1.1 ichiro struct wi_softc *sc = &psc->sc_wi;
304 1.1 ichiro
305 1.1 ichiro /* Allocate/map I/O space. */
306 1.1 ichiro if (pcmcia_io_alloc(psc->sc_pf, cfe->iospace[0].start,
307 1.1 ichiro cfe->iospace[0].length, WI_IOSIZE,
308 1.1 ichiro &psc->sc_pcioh) != 0) {
309 1.1 ichiro printf("%s: can't allocate i/o space\n",
310 1.1 ichiro sc->sc_dev.dv_xname);
311 1.1 ichiro goto fail1;
312 1.1 ichiro }
313 1.1 ichiro printf("%s:", sc->sc_dev.dv_xname);
314 1.1 ichiro if (pcmcia_io_map(psc->sc_pf, PCMCIA_WIDTH_AUTO, 0,
315 1.1 ichiro psc->sc_pcioh.size, &psc->sc_pcioh,
316 1.1 ichiro &psc->sc_io_window) != 0) {
317 1.1 ichiro printf(" can't map i/o space\n");
318 1.1 ichiro goto fail2;
319 1.1 ichiro }
320 1.1 ichiro /* Enable the card */
321 1.1 ichiro pcmcia_function_init(psc->sc_pf, cfe);
322 1.1 ichiro if (pcmcia_function_enable(psc->sc_pf)) {
323 1.1 ichiro printf("%s: function enable failed\n", sc->sc_dev.dv_xname);
324 1.1 ichiro goto fail3;
325 1.1 ichiro }
326 1.1 ichiro
327 1.1 ichiro sc->sc_iot = psc->sc_pcioh.iot;
328 1.1 ichiro sc->sc_ioh = psc->sc_pcioh.ioh;
329 1.1 ichiro
330 1.1 ichiro DELAY(1000);
331 1.1 ichiro return(0);
332 1.1 ichiro
333 1.1 ichiro fail3:
334 1.1 ichiro pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
335 1.1 ichiro fail2:
336 1.1 ichiro pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
337 1.1 ichiro fail1:
338 1.1 ichiro psc->sc_io_window = -1;
339 1.1 ichiro return(1);
340 1.1 ichiro }
341 1.1 ichiro
342 1.1 ichiro static void
343 1.1 ichiro wi_pcmcia_attach(parent, self, aux)
344 1.1 ichiro struct device *parent, *self;
345 1.1 ichiro void *aux;
346 1.1 ichiro {
347 1.1 ichiro struct wi_pcmcia_softc *psc = (void *)self;
348 1.1 ichiro struct wi_softc *sc = &psc->sc_wi;
349 1.1 ichiro const struct wi_pcmcia_product *pp;
350 1.1 ichiro struct pcmcia_attach_args *pa = aux;
351 1.1 ichiro struct pcmcia_config_entry *cfe;
352 1.1 ichiro char devinfo[256];
353 1.1 ichiro
354 1.1 ichiro /* Print out what we are. */
355 1.1 ichiro pcmcia_devinfo(&pa->pf->sc->card, 0, devinfo, sizeof(devinfo));
356 1.1 ichiro printf(": %s\n", devinfo);
357 1.1 ichiro
358 1.1 ichiro psc->sc_pf = pa->pf;
359 1.1 ichiro
360 1.1 ichiro for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL;
361 1.1 ichiro cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
362 1.1 ichiro if (cfe->iftype != PCMCIA_IFTYPE_IO)
363 1.1 ichiro continue;
364 1.1 ichiro if (cfe->iospace[0].length < WI_IOSIZE)
365 1.1 ichiro continue;
366 1.1 ichiro if (wi_pcmcia_find(psc, pa, cfe) == 0)
367 1.1 ichiro break;
368 1.1 ichiro }
369 1.1 ichiro if (cfe == NULL) {
370 1.1 ichiro printf(": no suitable CIS info found\n");
371 1.1 ichiro goto no_config_entry;
372 1.1 ichiro }
373 1.1 ichiro
374 1.1 ichiro pp = wi_pcmcia_lookup(pa);
375 1.1 ichiro if (pp == NULL)
376 1.1 ichiro panic("wi_pcmcia_attach: impossible");
377 1.1 ichiro
378 1.8 ichiro sc->sc_pci = 0;
379 1.1 ichiro sc->sc_enabled = 1;
380 1.1 ichiro sc->sc_enable = wi_pcmcia_enable;
381 1.1 ichiro sc->sc_disable = wi_pcmcia_disable;
382 1.1 ichiro
383 1.1 ichiro /* establish the interrupt. */
384 1.1 ichiro sc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, wi_intr, sc);
385 1.1 ichiro if (sc->sc_ih == NULL) {
386 1.1 ichiro printf("%s: couldn't establish interrupt\n",
387 1.1 ichiro sc->sc_dev.dv_xname);
388 1.1 ichiro goto no_interrupt;
389 1.1 ichiro }
390 1.1 ichiro
391 1.1 ichiro sc->sc_ifp = &sc->sc_ethercom.ec_if;
392 1.1 ichiro if (wi_attach(sc) != 0) {
393 1.1 ichiro printf("%s: failed to attach controller\n",
394 1.1 ichiro sc->sc_dev.dv_xname);
395 1.1 ichiro goto attach_failed;
396 1.1 ichiro }
397 1.1 ichiro
398 1.1 ichiro psc->sc_sdhook = shutdownhook_establish(wi_pcmcia_shutdown, psc);
399 1.1 ichiro psc->sc_powerhook = powerhook_establish(wi_pcmcia_powerhook, psc);
400 1.1 ichiro
401 1.1 ichiro /* disable the card */
402 1.1 ichiro sc->sc_enabled = 0;
403 1.1 ichiro wi_pcmcia_disable(sc);
404 1.2 ichiro
405 1.1 ichiro return;
406 1.1 ichiro
407 1.1 ichiro attach_failed:
408 1.1 ichiro pcmcia_intr_disestablish(psc->sc_pf, sc->sc_ih);
409 1.1 ichiro no_interrupt:
410 1.6 onoe pcmcia_function_disable(psc->sc_pf);
411 1.1 ichiro pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
412 1.1 ichiro pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
413 1.1 ichiro no_config_entry:
414 1.1 ichiro psc->sc_io_window = -1;
415 1.1 ichiro }
416 1.1 ichiro
417 1.1 ichiro static int
418 1.1 ichiro wi_pcmcia_detach(self, flags)
419 1.1 ichiro struct device *self;
420 1.1 ichiro int flags;
421 1.1 ichiro {
422 1.1 ichiro struct wi_pcmcia_softc *psc = (struct wi_pcmcia_softc *)self;
423 1.1 ichiro int error;
424 1.1 ichiro
425 1.1 ichiro if (psc->sc_io_window == -1)
426 1.1 ichiro /* Nothing to detach. */
427 1.1 ichiro return (0);
428 1.1 ichiro
429 1.1 ichiro if (psc->sc_powerhook != NULL)
430 1.1 ichiro powerhook_disestablish(psc->sc_powerhook);
431 1.1 ichiro if (psc->sc_sdhook != NULL)
432 1.1 ichiro shutdownhook_disestablish(psc->sc_sdhook);
433 1.1 ichiro
434 1.1 ichiro error = wi_detach(&psc->sc_wi);
435 1.1 ichiro if (error != 0)
436 1.1 ichiro return (error);
437 1.1 ichiro
438 1.1 ichiro /* Unmap our i/o window. */
439 1.1 ichiro pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
440 1.1 ichiro
441 1.1 ichiro /* Free our i/o space. */
442 1.1 ichiro pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
443 1.1 ichiro return (0);
444 1.1 ichiro }
445 1.1 ichiro
446 1.1 ichiro static void
447 1.1 ichiro wi_pcmcia_powerhook(why, arg)
448 1.1 ichiro int why;
449 1.1 ichiro void *arg;
450 1.1 ichiro {
451 1.1 ichiro struct wi_pcmcia_softc *psc = arg;
452 1.1 ichiro struct wi_softc *sc = &psc->sc_wi;
453 1.1 ichiro
454 1.1 ichiro wi_power(sc, why);
455 1.1 ichiro }
456 1.1 ichiro
457 1.1 ichiro static void
458 1.1 ichiro wi_pcmcia_shutdown(arg)
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_shutdown(sc);
465 1.1 ichiro }
466