Commit | Line | Data |
---|---|---|
ff1d2767 JM |
1 | #define PRISM2_PCCARD |
2 | ||
3 | #include <linux/config.h> | |
ff1d2767 JM |
4 | #include <linux/module.h> |
5 | #include <linux/init.h> | |
6 | #include <linux/if.h> | |
7 | #include <linux/wait.h> | |
8 | #include <linux/timer.h> | |
9 | #include <linux/skbuff.h> | |
10 | #include <linux/netdevice.h> | |
11 | #include <linux/workqueue.h> | |
12 | #include <linux/wireless.h> | |
13 | #include <net/iw_handler.h> | |
14 | ||
ff1d2767 JM |
15 | #include <pcmcia/cs_types.h> |
16 | #include <pcmcia/cs.h> | |
17 | #include <pcmcia/cistpl.h> | |
18 | #include <pcmcia/cisreg.h> | |
19 | #include <pcmcia/ds.h> | |
20 | ||
21 | #include <asm/io.h> | |
22 | ||
23 | #include "hostap_wlan.h" | |
24 | ||
25 | ||
26 | static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)"; | |
27 | static dev_info_t dev_info = "hostap_cs"; | |
28 | static dev_link_t *dev_list = NULL; | |
29 | ||
30 | MODULE_AUTHOR("Jouni Malinen"); | |
31 | MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN " | |
32 | "cards (PC Card)."); | |
33 | MODULE_SUPPORTED_DEVICE("Intersil Prism2-based WLAN cards (PC Card)"); | |
34 | MODULE_LICENSE("GPL"); | |
35 | ||
36 | ||
ff1d2767 JM |
37 | static int ignore_cis_vcc; |
38 | module_param(ignore_cis_vcc, int, 0444); | |
39 | MODULE_PARM_DESC(ignore_cis_vcc, "Ignore broken CIS VCC entry"); | |
40 | ||
41 | ||
42 | #ifdef PRISM2_IO_DEBUG | |
43 | ||
44 | static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v) | |
45 | { | |
46 | struct hostap_interface *iface; | |
47 | local_info_t *local; | |
48 | unsigned long flags; | |
49 | ||
50 | iface = netdev_priv(dev); | |
51 | local = iface->local; | |
52 | spin_lock_irqsave(&local->lock, flags); | |
53 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v); | |
54 | outb(v, dev->base_addr + a); | |
55 | spin_unlock_irqrestore(&local->lock, flags); | |
56 | } | |
57 | ||
58 | static inline u8 hfa384x_inb_debug(struct net_device *dev, int a) | |
59 | { | |
60 | struct hostap_interface *iface; | |
61 | local_info_t *local; | |
62 | unsigned long flags; | |
63 | u8 v; | |
64 | ||
65 | iface = netdev_priv(dev); | |
66 | local = iface->local; | |
67 | spin_lock_irqsave(&local->lock, flags); | |
68 | v = inb(dev->base_addr + a); | |
69 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v); | |
70 | spin_unlock_irqrestore(&local->lock, flags); | |
71 | return v; | |
72 | } | |
73 | ||
74 | static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v) | |
75 | { | |
76 | struct hostap_interface *iface; | |
77 | local_info_t *local; | |
78 | unsigned long flags; | |
79 | ||
80 | iface = netdev_priv(dev); | |
81 | local = iface->local; | |
82 | spin_lock_irqsave(&local->lock, flags); | |
83 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v); | |
84 | outw(v, dev->base_addr + a); | |
85 | spin_unlock_irqrestore(&local->lock, flags); | |
86 | } | |
87 | ||
88 | static inline u16 hfa384x_inw_debug(struct net_device *dev, int a) | |
89 | { | |
90 | struct hostap_interface *iface; | |
91 | local_info_t *local; | |
92 | unsigned long flags; | |
93 | u16 v; | |
94 | ||
95 | iface = netdev_priv(dev); | |
96 | local = iface->local; | |
97 | spin_lock_irqsave(&local->lock, flags); | |
98 | v = inw(dev->base_addr + a); | |
99 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v); | |
100 | spin_unlock_irqrestore(&local->lock, flags); | |
101 | return v; | |
102 | } | |
103 | ||
104 | static inline void hfa384x_outsw_debug(struct net_device *dev, int a, | |
105 | u8 *buf, int wc) | |
106 | { | |
107 | struct hostap_interface *iface; | |
108 | local_info_t *local; | |
109 | unsigned long flags; | |
110 | ||
111 | iface = netdev_priv(dev); | |
112 | local = iface->local; | |
113 | spin_lock_irqsave(&local->lock, flags); | |
114 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTSW, a, wc); | |
115 | outsw(dev->base_addr + a, buf, wc); | |
116 | spin_unlock_irqrestore(&local->lock, flags); | |
117 | } | |
118 | ||
119 | static inline void hfa384x_insw_debug(struct net_device *dev, int a, | |
120 | u8 *buf, int wc) | |
121 | { | |
122 | struct hostap_interface *iface; | |
123 | local_info_t *local; | |
124 | unsigned long flags; | |
125 | ||
126 | iface = netdev_priv(dev); | |
127 | local = iface->local; | |
128 | spin_lock_irqsave(&local->lock, flags); | |
129 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INSW, a, wc); | |
130 | insw(dev->base_addr + a, buf, wc); | |
131 | spin_unlock_irqrestore(&local->lock, flags); | |
132 | } | |
133 | ||
134 | #define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v)) | |
135 | #define HFA384X_INB(a) hfa384x_inb_debug(dev, (a)) | |
136 | #define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v)) | |
137 | #define HFA384X_INW(a) hfa384x_inw_debug(dev, (a)) | |
138 | #define HFA384X_OUTSW(a, buf, wc) hfa384x_outsw_debug(dev, (a), (buf), (wc)) | |
139 | #define HFA384X_INSW(a, buf, wc) hfa384x_insw_debug(dev, (a), (buf), (wc)) | |
140 | ||
141 | #else /* PRISM2_IO_DEBUG */ | |
142 | ||
143 | #define HFA384X_OUTB(v,a) outb((v), dev->base_addr + (a)) | |
144 | #define HFA384X_INB(a) inb(dev->base_addr + (a)) | |
145 | #define HFA384X_OUTW(v,a) outw((v), dev->base_addr + (a)) | |
146 | #define HFA384X_INW(a) inw(dev->base_addr + (a)) | |
147 | #define HFA384X_INSW(a, buf, wc) insw(dev->base_addr + (a), buf, wc) | |
148 | #define HFA384X_OUTSW(a, buf, wc) outsw(dev->base_addr + (a), buf, wc) | |
149 | ||
150 | #endif /* PRISM2_IO_DEBUG */ | |
151 | ||
152 | ||
153 | static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf, | |
154 | int len) | |
155 | { | |
156 | u16 d_off; | |
157 | u16 *pos; | |
158 | ||
159 | d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF; | |
160 | pos = (u16 *) buf; | |
161 | ||
162 | if (len / 2) | |
163 | HFA384X_INSW(d_off, buf, len / 2); | |
164 | pos += len / 2; | |
165 | ||
166 | if (len & 1) | |
167 | *((char *) pos) = HFA384X_INB(d_off); | |
168 | ||
169 | return 0; | |
170 | } | |
171 | ||
172 | ||
173 | static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len) | |
174 | { | |
175 | u16 d_off; | |
176 | u16 *pos; | |
177 | ||
178 | d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF; | |
179 | pos = (u16 *) buf; | |
180 | ||
181 | if (len / 2) | |
182 | HFA384X_OUTSW(d_off, buf, len / 2); | |
183 | pos += len / 2; | |
184 | ||
185 | if (len & 1) | |
186 | HFA384X_OUTB(*((char *) pos), d_off); | |
187 | ||
188 | return 0; | |
189 | } | |
190 | ||
191 | ||
192 | /* FIX: This might change at some point.. */ | |
193 | #include "hostap_hw.c" | |
194 | ||
195 | ||
196 | ||
197 | static void prism2_detach(dev_link_t *link); | |
198 | static void prism2_release(u_long arg); | |
199 | static int prism2_event(event_t event, int priority, | |
200 | event_callback_args_t *args); | |
201 | ||
202 | ||
203 | static int prism2_pccard_card_present(local_info_t *local) | |
204 | { | |
205 | if (local->link != NULL && | |
206 | ((local->link->state & (DEV_PRESENT | DEV_CONFIG)) == | |
207 | (DEV_PRESENT | DEV_CONFIG))) | |
208 | return 1; | |
209 | return 0; | |
210 | } | |
211 | ||
212 | ||
213 | /* | |
214 | * SanDisk CompactFlash WLAN Flashcard - Product Manual v1.0 | |
215 | * Document No. 20-10-00058, January 2004 | |
216 | * http://www.sandisk.com/pdf/industrial/ProdManualCFWLANv1.0.pdf | |
217 | */ | |
218 | #define SANDISK_WLAN_ACTIVATION_OFF 0x40 | |
219 | #define SANDISK_HCR_OFF 0x42 | |
220 | ||
221 | ||
222 | static void sandisk_set_iobase(local_info_t *local) | |
223 | { | |
224 | int res; | |
225 | conf_reg_t reg; | |
226 | ||
227 | reg.Function = 0; | |
228 | reg.Action = CS_WRITE; | |
229 | reg.Offset = 0x10; /* 0x3f0 IO base 1 */ | |
230 | reg.Value = local->link->io.BasePort1 & 0x00ff; | |
231 | res = pcmcia_access_configuration_register(local->link->handle, ®); | |
232 | if (res != CS_SUCCESS) { | |
233 | printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -" | |
234 | " res=%d\n", res); | |
235 | } | |
236 | udelay(10); | |
237 | ||
238 | reg.Function = 0; | |
239 | reg.Action = CS_WRITE; | |
240 | reg.Offset = 0x12; /* 0x3f2 IO base 2 */ | |
241 | reg.Value = (local->link->io.BasePort1 & 0xff00) >> 8; | |
242 | res = pcmcia_access_configuration_register(local->link->handle, ®); | |
243 | if (res != CS_SUCCESS) { | |
244 | printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -" | |
245 | " res=%d\n", res); | |
246 | } | |
247 | } | |
248 | ||
249 | ||
250 | static void sandisk_write_hcr(local_info_t *local, int hcr) | |
251 | { | |
252 | struct net_device *dev = local->dev; | |
253 | int i; | |
254 | ||
255 | HFA384X_OUTB(0x80, SANDISK_WLAN_ACTIVATION_OFF); | |
256 | udelay(50); | |
257 | for (i = 0; i < 10; i++) { | |
258 | HFA384X_OUTB(hcr, SANDISK_HCR_OFF); | |
259 | } | |
260 | udelay(55); | |
261 | HFA384X_OUTB(0x45, SANDISK_WLAN_ACTIVATION_OFF); | |
262 | } | |
263 | ||
264 | ||
265 | static int sandisk_enable_wireless(struct net_device *dev) | |
266 | { | |
267 | int res, ret = 0; | |
268 | conf_reg_t reg; | |
269 | struct hostap_interface *iface = dev->priv; | |
270 | local_info_t *local = iface->local; | |
271 | tuple_t tuple; | |
272 | cisparse_t *parse = NULL; | |
273 | u_char buf[64]; | |
274 | ||
275 | if (local->link->io.NumPorts1 < 0x42) { | |
276 | /* Not enough ports to be SanDisk multi-function card */ | |
277 | ret = -ENODEV; | |
278 | goto done; | |
279 | } | |
280 | ||
281 | parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL); | |
282 | if (parse == NULL) { | |
283 | ret = -ENOMEM; | |
284 | goto done; | |
285 | } | |
286 | ||
287 | tuple.DesiredTuple = CISTPL_MANFID; | |
288 | tuple.Attributes = TUPLE_RETURN_COMMON; | |
289 | tuple.TupleData = buf; | |
290 | tuple.TupleDataMax = sizeof(buf); | |
291 | tuple.TupleOffset = 0; | |
292 | if (pcmcia_get_first_tuple(local->link->handle, &tuple) || | |
293 | pcmcia_get_tuple_data(local->link->handle, &tuple) || | |
294 | pcmcia_parse_tuple(local->link->handle, &tuple, parse) || | |
295 | parse->manfid.manf != 0xd601 || parse->manfid.card != 0x0101) { | |
296 | /* No SanDisk manfid found */ | |
297 | ret = -ENODEV; | |
298 | goto done; | |
299 | } | |
300 | ||
301 | tuple.DesiredTuple = CISTPL_LONGLINK_MFC; | |
302 | if (pcmcia_get_first_tuple(local->link->handle, &tuple) || | |
303 | pcmcia_get_tuple_data(local->link->handle, &tuple) || | |
304 | pcmcia_parse_tuple(local->link->handle, &tuple, parse) || | |
305 | parse->longlink_mfc.nfn < 2) { | |
306 | /* No multi-function links found */ | |
307 | ret = -ENODEV; | |
308 | goto done; | |
309 | } | |
310 | ||
311 | printk(KERN_DEBUG "%s: Multi-function SanDisk ConnectPlus detected" | |
312 | " - using vendor-specific initialization\n", dev->name); | |
313 | local->sandisk_connectplus = 1; | |
314 | ||
315 | reg.Function = 0; | |
316 | reg.Action = CS_WRITE; | |
317 | reg.Offset = CISREG_COR; | |
318 | reg.Value = COR_SOFT_RESET; | |
319 | res = pcmcia_access_configuration_register(local->link->handle, ®); | |
320 | if (res != CS_SUCCESS) { | |
321 | printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n", | |
322 | dev->name, res); | |
323 | goto done; | |
324 | } | |
325 | mdelay(5); | |
326 | ||
327 | reg.Function = 0; | |
328 | reg.Action = CS_WRITE; | |
329 | reg.Offset = CISREG_COR; | |
330 | /* | |
331 | * Do not enable interrupts here to avoid some bogus events. Interrupts | |
332 | * will be enabled during the first cor_sreset call. | |
333 | */ | |
334 | reg.Value = COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE | COR_FUNC_ENA; | |
335 | res = pcmcia_access_configuration_register(local->link->handle, ®); | |
336 | if (res != CS_SUCCESS) { | |
337 | printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n", | |
338 | dev->name, res); | |
339 | goto done; | |
340 | } | |
341 | mdelay(5); | |
342 | ||
343 | sandisk_set_iobase(local); | |
344 | ||
345 | HFA384X_OUTB(0xc5, SANDISK_WLAN_ACTIVATION_OFF); | |
346 | udelay(10); | |
347 | HFA384X_OUTB(0x4b, SANDISK_WLAN_ACTIVATION_OFF); | |
348 | udelay(10); | |
349 | ||
350 | done: | |
351 | kfree(parse); | |
352 | return ret; | |
353 | } | |
354 | ||
355 | ||
356 | static void prism2_pccard_cor_sreset(local_info_t *local) | |
357 | { | |
358 | int res; | |
359 | conf_reg_t reg; | |
360 | ||
361 | if (!prism2_pccard_card_present(local)) | |
362 | return; | |
363 | ||
364 | reg.Function = 0; | |
365 | reg.Action = CS_READ; | |
366 | reg.Offset = CISREG_COR; | |
367 | reg.Value = 0; | |
368 | res = pcmcia_access_configuration_register(local->link->handle, ®); | |
369 | if (res != CS_SUCCESS) { | |
370 | printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n", | |
371 | res); | |
372 | return; | |
373 | } | |
374 | printk(KERN_DEBUG "prism2_pccard_cor_sreset: original COR %02x\n", | |
375 | reg.Value); | |
376 | ||
377 | reg.Action = CS_WRITE; | |
378 | reg.Value |= COR_SOFT_RESET; | |
379 | res = pcmcia_access_configuration_register(local->link->handle, ®); | |
380 | if (res != CS_SUCCESS) { | |
381 | printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n", | |
382 | res); | |
383 | return; | |
384 | } | |
385 | ||
386 | mdelay(local->sandisk_connectplus ? 5 : 2); | |
387 | ||
388 | reg.Value &= ~COR_SOFT_RESET; | |
389 | if (local->sandisk_connectplus) | |
390 | reg.Value |= COR_IREQ_ENA; | |
391 | res = pcmcia_access_configuration_register(local->link->handle, ®); | |
392 | if (res != CS_SUCCESS) { | |
393 | printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n", | |
394 | res); | |
395 | return; | |
396 | } | |
397 | ||
398 | mdelay(local->sandisk_connectplus ? 5 : 2); | |
399 | ||
400 | if (local->sandisk_connectplus) | |
401 | sandisk_set_iobase(local); | |
402 | } | |
403 | ||
404 | ||
405 | static void prism2_pccard_genesis_reset(local_info_t *local, int hcr) | |
406 | { | |
407 | int res; | |
408 | conf_reg_t reg; | |
409 | int old_cor; | |
410 | ||
411 | if (!prism2_pccard_card_present(local)) | |
412 | return; | |
413 | ||
414 | if (local->sandisk_connectplus) { | |
415 | sandisk_write_hcr(local, hcr); | |
416 | return; | |
417 | } | |
418 | ||
419 | reg.Function = 0; | |
420 | reg.Action = CS_READ; | |
421 | reg.Offset = CISREG_COR; | |
422 | reg.Value = 0; | |
423 | res = pcmcia_access_configuration_register(local->link->handle, ®); | |
424 | if (res != CS_SUCCESS) { | |
425 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 " | |
426 | "(%d)\n", res); | |
427 | return; | |
428 | } | |
429 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset: original COR %02x\n", | |
430 | reg.Value); | |
431 | old_cor = reg.Value; | |
432 | ||
433 | reg.Action = CS_WRITE; | |
434 | reg.Value |= COR_SOFT_RESET; | |
435 | res = pcmcia_access_configuration_register(local->link->handle, ®); | |
436 | if (res != CS_SUCCESS) { | |
437 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 " | |
438 | "(%d)\n", res); | |
439 | return; | |
440 | } | |
441 | ||
442 | mdelay(10); | |
443 | ||
444 | /* Setup Genesis mode */ | |
445 | reg.Action = CS_WRITE; | |
446 | reg.Value = hcr; | |
447 | reg.Offset = CISREG_CCSR; | |
448 | res = pcmcia_access_configuration_register(local->link->handle, ®); | |
449 | if (res != CS_SUCCESS) { | |
450 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 " | |
451 | "(%d)\n", res); | |
452 | return; | |
453 | } | |
454 | mdelay(10); | |
455 | ||
456 | reg.Action = CS_WRITE; | |
457 | reg.Offset = CISREG_COR; | |
458 | reg.Value = old_cor & ~COR_SOFT_RESET; | |
459 | res = pcmcia_access_configuration_register(local->link->handle, ®); | |
460 | if (res != CS_SUCCESS) { | |
461 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 " | |
462 | "(%d)\n", res); | |
463 | return; | |
464 | } | |
465 | ||
466 | mdelay(10); | |
467 | } | |
468 | ||
469 | ||
470 | static int prism2_pccard_dev_open(local_info_t *local) | |
471 | { | |
472 | local->link->open++; | |
473 | return 0; | |
474 | } | |
475 | ||
476 | ||
477 | static int prism2_pccard_dev_close(local_info_t *local) | |
478 | { | |
479 | if (local == NULL || local->link == NULL) | |
480 | return 1; | |
481 | ||
482 | if (!local->link->open) { | |
483 | printk(KERN_WARNING "%s: prism2_pccard_dev_close(): " | |
484 | "link not open?!\n", local->dev->name); | |
485 | return 1; | |
486 | } | |
487 | ||
488 | local->link->open--; | |
489 | ||
490 | return 0; | |
491 | } | |
492 | ||
493 | ||
494 | static struct prism2_helper_functions prism2_pccard_funcs = | |
495 | { | |
496 | .card_present = prism2_pccard_card_present, | |
497 | .cor_sreset = prism2_pccard_cor_sreset, | |
498 | .dev_open = prism2_pccard_dev_open, | |
499 | .dev_close = prism2_pccard_dev_close, | |
500 | .genesis_reset = prism2_pccard_genesis_reset, | |
501 | .hw_type = HOSTAP_HW_PCCARD, | |
502 | }; | |
503 | ||
504 | ||
505 | /* allocate local data and register with CardServices | |
506 | * initialize dev_link structure, but do not configure the card yet */ | |
507 | static dev_link_t *prism2_attach(void) | |
508 | { | |
509 | dev_link_t *link; | |
510 | client_reg_t client_reg; | |
511 | int ret; | |
512 | ||
513 | link = kmalloc(sizeof(dev_link_t), GFP_KERNEL); | |
514 | if (link == NULL) | |
515 | return NULL; | |
516 | ||
517 | memset(link, 0, sizeof(dev_link_t)); | |
518 | ||
519 | PDEBUG(DEBUG_HW, "%s: setting Vcc=33 (constant)\n", dev_info); | |
520 | link->conf.Vcc = 33; | |
521 | link->conf.IntType = INT_MEMORY_AND_IO; | |
522 | ||
523 | /* register with CardServices */ | |
524 | link->next = dev_list; | |
525 | dev_list = link; | |
526 | client_reg.dev_info = &dev_info; | |
ff1d2767 JM |
527 | client_reg.Version = 0x0210; |
528 | client_reg.event_callback_args.client_data = link; | |
529 | ret = pcmcia_register_client(&link->handle, &client_reg); | |
530 | if (ret != CS_SUCCESS) { | |
531 | cs_error(link->handle, RegisterClient, ret); | |
532 | prism2_detach(link); | |
533 | return NULL; | |
534 | } | |
535 | return link; | |
536 | } | |
537 | ||
538 | ||
539 | static void prism2_detach(dev_link_t *link) | |
540 | { | |
541 | dev_link_t **linkp; | |
542 | ||
543 | PDEBUG(DEBUG_FLOW, "prism2_detach\n"); | |
544 | ||
545 | for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) | |
546 | if (*linkp == link) | |
547 | break; | |
548 | if (*linkp == NULL) { | |
549 | printk(KERN_WARNING "%s: Attempt to detach non-existing " | |
550 | "PCMCIA client\n", dev_info); | |
551 | return; | |
552 | } | |
553 | ||
554 | if (link->state & DEV_CONFIG) { | |
555 | prism2_release((u_long)link); | |
556 | } | |
557 | ||
558 | if (link->handle) { | |
559 | int res = pcmcia_deregister_client(link->handle); | |
560 | if (res) { | |
561 | printk("CardService(DeregisterClient) => %d\n", res); | |
562 | cs_error(link->handle, DeregisterClient, res); | |
563 | } | |
564 | } | |
565 | ||
566 | *linkp = link->next; | |
567 | /* release net devices */ | |
568 | if (link->priv) { | |
569 | prism2_free_local_data((struct net_device *) link->priv); | |
570 | ||
571 | } | |
572 | kfree(link); | |
573 | } | |
574 | ||
575 | ||
576 | #define CS_CHECK(fn, ret) \ | |
577 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) | |
578 | ||
579 | #define CFG_CHECK2(fn, retf) \ | |
580 | do { int ret = (retf); \ | |
581 | if (ret != 0) { \ | |
582 | PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", ret); \ | |
583 | cs_error(link->handle, fn, ret); \ | |
584 | goto next_entry; \ | |
585 | } \ | |
586 | } while (0) | |
587 | ||
588 | ||
589 | /* run after a CARD_INSERTION event is received to configure the PCMCIA | |
590 | * socket and make the device available to the system */ | |
591 | static int prism2_config(dev_link_t *link) | |
592 | { | |
593 | struct net_device *dev; | |
594 | struct hostap_interface *iface; | |
595 | local_info_t *local; | |
596 | int ret = 1; | |
597 | tuple_t tuple; | |
598 | cisparse_t *parse; | |
599 | int last_fn, last_ret; | |
600 | u_char buf[64]; | |
601 | config_info_t conf; | |
602 | cistpl_cftable_entry_t dflt = { 0 }; | |
603 | ||
604 | PDEBUG(DEBUG_FLOW, "prism2_config()\n"); | |
605 | ||
606 | parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL); | |
607 | if (parse == NULL) { | |
608 | ret = -ENOMEM; | |
609 | goto failed; | |
610 | } | |
611 | ||
612 | tuple.DesiredTuple = CISTPL_CONFIG; | |
613 | tuple.Attributes = 0; | |
614 | tuple.TupleData = buf; | |
615 | tuple.TupleDataMax = sizeof(buf); | |
616 | tuple.TupleOffset = 0; | |
617 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple)); | |
618 | CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link->handle, &tuple)); | |
619 | CS_CHECK(ParseTuple, pcmcia_parse_tuple(link->handle, &tuple, parse)); | |
620 | link->conf.ConfigBase = parse->config.base; | |
621 | link->conf.Present = parse->config.rmask[0]; | |
622 | ||
623 | CS_CHECK(GetConfigurationInfo, | |
624 | pcmcia_get_configuration_info(link->handle, &conf)); | |
625 | PDEBUG(DEBUG_HW, "%s: %s Vcc=%d (from config)\n", dev_info, | |
626 | ignore_cis_vcc ? "ignoring" : "setting", conf.Vcc); | |
627 | link->conf.Vcc = conf.Vcc; | |
628 | ||
629 | /* Look for an appropriate configuration table entry in the CIS */ | |
630 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; | |
631 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple)); | |
632 | for (;;) { | |
633 | cistpl_cftable_entry_t *cfg = &(parse->cftable_entry); | |
634 | CFG_CHECK2(GetTupleData, | |
635 | pcmcia_get_tuple_data(link->handle, &tuple)); | |
636 | CFG_CHECK2(ParseTuple, | |
637 | pcmcia_parse_tuple(link->handle, &tuple, parse)); | |
638 | ||
639 | if (cfg->flags & CISTPL_CFTABLE_DEFAULT) | |
640 | dflt = *cfg; | |
641 | if (cfg->index == 0) | |
642 | goto next_entry; | |
643 | link->conf.ConfigIndex = cfg->index; | |
644 | PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X " | |
645 | "(default 0x%02X)\n", cfg->index, dflt.index); | |
646 | ||
647 | /* Does this card need audio output? */ | |
648 | if (cfg->flags & CISTPL_CFTABLE_AUDIO) { | |
649 | link->conf.Attributes |= CONF_ENABLE_SPKR; | |
650 | link->conf.Status = CCSR_AUDIO_ENA; | |
651 | } | |
652 | ||
653 | /* Use power settings for Vcc and Vpp if present */ | |
654 | /* Note that the CIS values need to be rescaled */ | |
655 | if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) { | |
656 | if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / | |
657 | 10000 && !ignore_cis_vcc) { | |
658 | PDEBUG(DEBUG_EXTRA, " Vcc mismatch - skipping" | |
659 | " this entry\n"); | |
660 | goto next_entry; | |
661 | } | |
662 | } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) { | |
663 | if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / | |
664 | 10000 && !ignore_cis_vcc) { | |
665 | PDEBUG(DEBUG_EXTRA, " Vcc (default) mismatch " | |
666 | "- skipping this entry\n"); | |
667 | goto next_entry; | |
668 | } | |
669 | } | |
670 | ||
671 | if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) | |
672 | link->conf.Vpp1 = link->conf.Vpp2 = | |
673 | cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; | |
674 | else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) | |
675 | link->conf.Vpp1 = link->conf.Vpp2 = | |
676 | dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; | |
677 | ||
678 | /* Do we need to allocate an interrupt? */ | |
679 | if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) | |
680 | link->conf.Attributes |= CONF_ENABLE_IRQ; | |
681 | else if (!(link->conf.Attributes & CONF_ENABLE_IRQ)) { | |
682 | /* At least Compaq WL200 does not have IRQInfo1 set, | |
683 | * but it does not work without interrupts.. */ | |
684 | printk("Config has no IRQ info, but trying to enable " | |
685 | "IRQ anyway..\n"); | |
686 | link->conf.Attributes |= CONF_ENABLE_IRQ; | |
687 | } | |
688 | ||
689 | /* IO window settings */ | |
690 | PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d " | |
691 | "dflt.io.nwin=%d\n", | |
692 | cfg->io.nwin, dflt.io.nwin); | |
693 | link->io.NumPorts1 = link->io.NumPorts2 = 0; | |
694 | if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { | |
695 | cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; | |
696 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; | |
697 | PDEBUG(DEBUG_EXTRA, "io->flags = 0x%04X, " | |
698 | "io.base=0x%04x, len=%d\n", io->flags, | |
699 | io->win[0].base, io->win[0].len); | |
700 | if (!(io->flags & CISTPL_IO_8BIT)) | |
701 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; | |
702 | if (!(io->flags & CISTPL_IO_16BIT)) | |
703 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; | |
704 | link->io.IOAddrLines = io->flags & | |
705 | CISTPL_IO_LINES_MASK; | |
706 | link->io.BasePort1 = io->win[0].base; | |
707 | link->io.NumPorts1 = io->win[0].len; | |
708 | if (io->nwin > 1) { | |
709 | link->io.Attributes2 = link->io.Attributes1; | |
710 | link->io.BasePort2 = io->win[1].base; | |
711 | link->io.NumPorts2 = io->win[1].len; | |
712 | } | |
713 | } | |
714 | ||
715 | /* This reserves IO space but doesn't actually enable it */ | |
716 | CFG_CHECK2(RequestIO, | |
717 | pcmcia_request_io(link->handle, &link->io)); | |
718 | ||
719 | /* This configuration table entry is OK */ | |
720 | break; | |
721 | ||
722 | next_entry: | |
723 | CS_CHECK(GetNextTuple, | |
724 | pcmcia_get_next_tuple(link->handle, &tuple)); | |
725 | } | |
726 | ||
727 | /* Need to allocate net_device before requesting IRQ handler */ | |
0cd545d6 DH |
728 | dev = prism2_init_local_data(&prism2_pccard_funcs, 0, |
729 | &handle_to_dev(link->handle)); | |
ff1d2767 JM |
730 | if (dev == NULL) |
731 | goto failed; | |
732 | link->priv = dev; | |
733 | ||
734 | /* | |
735 | * Allocate an interrupt line. Note that this does not assign a | |
736 | * handler to the interrupt, unless the 'Handler' member of the | |
737 | * irq structure is initialized. | |
738 | */ | |
739 | if (link->conf.Attributes & CONF_ENABLE_IRQ) { | |
ff1d2767 | 740 | link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; |
0ef79ee2 | 741 | link->irq.IRQInfo1 = IRQ_LEVEL_ID; |
ff1d2767 JM |
742 | link->irq.Handler = prism2_interrupt; |
743 | link->irq.Instance = dev; | |
744 | CS_CHECK(RequestIRQ, | |
745 | pcmcia_request_irq(link->handle, &link->irq)); | |
746 | } | |
747 | ||
748 | /* | |
749 | * This actually configures the PCMCIA socket -- setting up | |
750 | * the I/O windows and the interrupt mapping, and putting the | |
751 | * card and host interface into "Memory and IO" mode. | |
752 | */ | |
753 | CS_CHECK(RequestConfiguration, | |
754 | pcmcia_request_configuration(link->handle, &link->conf)); | |
755 | ||
756 | dev->irq = link->irq.AssignedIRQ; | |
757 | dev->base_addr = link->io.BasePort1; | |
758 | ||
759 | /* Finally, report what we've done */ | |
760 | printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", | |
761 | dev_info, link->conf.ConfigIndex, | |
762 | link->conf.Vcc / 10, link->conf.Vcc % 10); | |
763 | if (link->conf.Vpp1) | |
764 | printk(", Vpp %d.%d", link->conf.Vpp1 / 10, | |
765 | link->conf.Vpp1 % 10); | |
766 | if (link->conf.Attributes & CONF_ENABLE_IRQ) | |
767 | printk(", irq %d", link->irq.AssignedIRQ); | |
768 | if (link->io.NumPorts1) | |
769 | printk(", io 0x%04x-0x%04x", link->io.BasePort1, | |
770 | link->io.BasePort1+link->io.NumPorts1-1); | |
771 | if (link->io.NumPorts2) | |
772 | printk(" & 0x%04x-0x%04x", link->io.BasePort2, | |
773 | link->io.BasePort2+link->io.NumPorts2-1); | |
774 | printk("\n"); | |
775 | ||
776 | link->state |= DEV_CONFIG; | |
777 | link->state &= ~DEV_CONFIG_PENDING; | |
778 | ||
779 | iface = netdev_priv(dev); | |
780 | local = iface->local; | |
781 | local->link = link; | |
782 | strcpy(local->node.dev_name, dev->name); | |
783 | link->dev = &local->node; | |
784 | ||
785 | local->shutdown = 0; | |
786 | ||
787 | sandisk_enable_wireless(dev); | |
788 | ||
789 | ret = prism2_hw_config(dev, 1); | |
790 | if (!ret) { | |
791 | ret = hostap_hw_ready(dev); | |
792 | if (ret == 0 && local->ddev) | |
793 | strcpy(local->node.dev_name, local->ddev->name); | |
794 | } | |
795 | kfree(parse); | |
796 | return ret; | |
797 | ||
798 | cs_failed: | |
799 | cs_error(link->handle, last_fn, last_ret); | |
800 | ||
801 | failed: | |
802 | kfree(parse); | |
803 | prism2_release((u_long)link); | |
804 | return ret; | |
805 | } | |
806 | ||
807 | ||
808 | static void prism2_release(u_long arg) | |
809 | { | |
810 | dev_link_t *link = (dev_link_t *)arg; | |
811 | ||
812 | PDEBUG(DEBUG_FLOW, "prism2_release\n"); | |
813 | ||
814 | if (link->priv) { | |
815 | struct net_device *dev = link->priv; | |
816 | struct hostap_interface *iface; | |
817 | ||
818 | iface = netdev_priv(dev); | |
819 | if (link->state & DEV_CONFIG) | |
820 | prism2_hw_shutdown(dev, 0); | |
821 | iface->local->shutdown = 1; | |
822 | } | |
823 | ||
824 | if (link->win) | |
825 | pcmcia_release_window(link->win); | |
826 | pcmcia_release_configuration(link->handle); | |
827 | if (link->io.NumPorts1) | |
828 | pcmcia_release_io(link->handle, &link->io); | |
829 | if (link->irq.AssignedIRQ) | |
830 | pcmcia_release_irq(link->handle, &link->irq); | |
831 | ||
832 | link->state &= ~DEV_CONFIG; | |
833 | ||
834 | PDEBUG(DEBUG_FLOW, "release - done\n"); | |
835 | } | |
836 | ||
837 | ||
838 | static int prism2_event(event_t event, int priority, | |
839 | event_callback_args_t *args) | |
840 | { | |
841 | dev_link_t *link = args->client_data; | |
842 | struct net_device *dev = (struct net_device *) link->priv; | |
843 | ||
844 | switch (event) { | |
845 | case CS_EVENT_CARD_INSERTION: | |
846 | PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_INSERTION\n", dev_info); | |
847 | link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; | |
848 | if (prism2_config(link)) { | |
849 | PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n"); | |
850 | } | |
851 | break; | |
852 | ||
853 | case CS_EVENT_CARD_REMOVAL: | |
854 | PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_REMOVAL\n", dev_info); | |
855 | link->state &= ~DEV_PRESENT; | |
856 | if (link->state & DEV_CONFIG) { | |
857 | netif_stop_queue(dev); | |
858 | netif_device_detach(dev); | |
859 | prism2_release((u_long) link); | |
860 | } | |
861 | break; | |
862 | ||
863 | case CS_EVENT_PM_SUSPEND: | |
864 | PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info); | |
865 | link->state |= DEV_SUSPEND; | |
866 | /* fall through */ | |
867 | ||
868 | case CS_EVENT_RESET_PHYSICAL: | |
869 | PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_RESET_PHYSICAL\n", dev_info); | |
870 | if (link->state & DEV_CONFIG) { | |
871 | if (link->open) { | |
872 | netif_stop_queue(dev); | |
873 | netif_device_detach(dev); | |
874 | } | |
875 | prism2_suspend(dev); | |
876 | pcmcia_release_configuration(link->handle); | |
877 | } | |
878 | break; | |
879 | ||
880 | case CS_EVENT_PM_RESUME: | |
881 | PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info); | |
882 | link->state &= ~DEV_SUSPEND; | |
883 | /* fall through */ | |
884 | ||
885 | case CS_EVENT_CARD_RESET: | |
886 | PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_RESET\n", dev_info); | |
887 | if (link->state & DEV_CONFIG) { | |
888 | pcmcia_request_configuration(link->handle, | |
889 | &link->conf); | |
890 | prism2_hw_shutdown(dev, 1); | |
891 | prism2_hw_config(dev, link->open ? 0 : 1); | |
892 | if (link->open) { | |
893 | netif_device_attach(dev); | |
894 | netif_start_queue(dev); | |
895 | } | |
896 | } | |
897 | break; | |
898 | ||
899 | default: | |
900 | PDEBUG(DEBUG_EXTRA, "%s: prism2_event() - unknown event %d\n", | |
901 | dev_info, event); | |
902 | break; | |
903 | } | |
904 | return 0; | |
905 | } | |
906 | ||
907 | ||
908 | static struct pcmcia_driver hostap_driver = { | |
909 | .drv = { | |
910 | .name = "hostap_cs", | |
911 | }, | |
912 | .attach = prism2_attach, | |
913 | .detach = prism2_detach, | |
914 | .owner = THIS_MODULE, | |
47e362cf | 915 | .event = prism2_event, |
ff1d2767 JM |
916 | }; |
917 | ||
918 | static int __init init_prism2_pccard(void) | |
919 | { | |
920 | printk(KERN_INFO "%s: %s\n", dev_info, version); | |
921 | return pcmcia_register_driver(&hostap_driver); | |
922 | } | |
923 | ||
924 | static void __exit exit_prism2_pccard(void) | |
925 | { | |
926 | pcmcia_unregister_driver(&hostap_driver); | |
927 | printk(KERN_INFO "%s: Driver unloaded\n", dev_info); | |
928 | } | |
929 | ||
930 | ||
931 | module_init(init_prism2_pccard); | |
932 | module_exit(exit_prism2_pccard); |