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