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