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