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