blob: 866142af7d92f1fee5d245babe173b50fbef70fd [file] [log] [blame]
Jouni Malinenff1d2762005-05-12 22:54:16 -04001#define PRISM2_PCCARD
2
3#include <linux/config.h>
Jouni Malinenff1d2762005-05-12 22:54:16 -04004#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
Jouni Malinenff1d2762005-05-12 22:54:16 -040015#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
26static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)";
27static dev_info_t dev_info = "hostap_cs";
28static dev_link_t *dev_list = NULL;
29
30MODULE_AUTHOR("Jouni Malinen");
31MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN "
32 "cards (PC Card).");
33MODULE_SUPPORTED_DEVICE("Intersil Prism2-based WLAN cards (PC Card)");
34MODULE_LICENSE("GPL");
Jouni Malinenf06ac312005-07-30 12:50:00 -070035MODULE_VERSION(PRISM2_VERSION);
Jouni Malinenff1d2762005-05-12 22:54:16 -040036
37
Jouni Malinenff1d2762005-05-12 22:54:16 -040038static int ignore_cis_vcc;
39module_param(ignore_cis_vcc, int, 0444);
40MODULE_PARM_DESC(ignore_cis_vcc, "Ignore broken CIS VCC entry");
41
42
Jouni Malinen67e0e472005-08-14 19:08:41 -070043/* struct local_info::hw_priv */
44struct hostap_cs_priv {
45 dev_node_t node;
46 dev_link_t *link;
47 int sandisk_connectplus;
48};
49
50
Jouni Malinenff1d2762005-05-12 22:54:16 -040051#ifdef PRISM2_IO_DEBUG
52
53static 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
67static 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
83static 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
97static 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
113static 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
128static 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
162static 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
182static 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
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100206static void prism2_detach(struct pcmcia_device *p_dev);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400207static void prism2_release(u_long arg);
208static int prism2_event(event_t event, int priority,
209 event_callback_args_t *args);
210
211
212static int prism2_pccard_card_present(local_info_t *local)
213{
Jouni Malinen67e0e472005-08-14 19:08:41 -0700214 struct hostap_cs_priv *hw_priv = local->hw_priv;
Kalle Valoa8eef8a2005-08-28 22:46:57 +0300215 if (hw_priv != NULL && hw_priv->link != NULL &&
Jouni Malinen67e0e472005-08-14 19:08:41 -0700216 ((hw_priv->link->state & (DEV_PRESENT | DEV_CONFIG)) ==
Jouni Malinenff1d2762005-05-12 22:54:16 -0400217 (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
232static void sandisk_set_iobase(local_info_t *local)
233{
234 int res;
235 conf_reg_t reg;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700236 struct hostap_cs_priv *hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400237
238 reg.Function = 0;
239 reg.Action = CS_WRITE;
240 reg.Offset = 0x10; /* 0x3f0 IO base 1 */
Jouni Malinen67e0e472005-08-14 19:08:41 -0700241 reg.Value = hw_priv->link->io.BasePort1 & 0x00ff;
242 res = pcmcia_access_configuration_register(hw_priv->link->handle,
243 &reg);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400244 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 */
Jouni Malinen67e0e472005-08-14 19:08:41 -0700253 reg.Value = (hw_priv->link->io.BasePort1 & 0xff00) >> 8;
254 res = pcmcia_access_configuration_register(hw_priv->link->handle,
255 &reg);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400256 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
263static 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
278static 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];
Jouni Malinen67e0e472005-08-14 19:08:41 -0700287 struct hostap_cs_priv *hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400288
Jouni Malinen67e0e472005-08-14 19:08:41 -0700289 if (hw_priv->link->io.NumPorts1 < 0x42) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400290 /* 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;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700306 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) ||
Jouni Malinenff1d2762005-05-12 22:54:16 -0400309 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;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700316 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) ||
Jouni Malinenff1d2762005-05-12 22:54:16 -0400319 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);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700327 hw_priv->sandisk_connectplus = 1;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400328
329 reg.Function = 0;
330 reg.Action = CS_WRITE;
331 reg.Offset = CISREG_COR;
332 reg.Value = COR_SOFT_RESET;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700333 res = pcmcia_access_configuration_register(hw_priv->link->handle,
334 &reg);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400335 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;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700350 res = pcmcia_access_configuration_register(hw_priv->link->handle,
351 &reg);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400352 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
366done:
367 kfree(parse);
368 return ret;
369}
370
371
372static void prism2_pccard_cor_sreset(local_info_t *local)
373{
374 int res;
375 conf_reg_t reg;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700376 struct hostap_cs_priv *hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400377
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;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700385 res = pcmcia_access_configuration_register(hw_priv->link->handle,
386 &reg);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400387 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;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700397 res = pcmcia_access_configuration_register(hw_priv->link->handle,
398 &reg);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400399 if (res != CS_SUCCESS) {
400 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n",
401 res);
402 return;
403 }
404
Jouni Malinen67e0e472005-08-14 19:08:41 -0700405 mdelay(hw_priv->sandisk_connectplus ? 5 : 2);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400406
407 reg.Value &= ~COR_SOFT_RESET;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700408 if (hw_priv->sandisk_connectplus)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400409 reg.Value |= COR_IREQ_ENA;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700410 res = pcmcia_access_configuration_register(hw_priv->link->handle,
411 &reg);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400412 if (res != CS_SUCCESS) {
413 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n",
414 res);
415 return;
416 }
417
Jouni Malinen67e0e472005-08-14 19:08:41 -0700418 mdelay(hw_priv->sandisk_connectplus ? 5 : 2);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400419
Jouni Malinen67e0e472005-08-14 19:08:41 -0700420 if (hw_priv->sandisk_connectplus)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400421 sandisk_set_iobase(local);
422}
423
424
425static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
426{
427 int res;
428 conf_reg_t reg;
429 int old_cor;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700430 struct hostap_cs_priv *hw_priv = local->hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400431
432 if (!prism2_pccard_card_present(local))
433 return;
434
Jouni Malinen67e0e472005-08-14 19:08:41 -0700435 if (hw_priv->sandisk_connectplus) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400436 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;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700444 res = pcmcia_access_configuration_register(hw_priv->link->handle,
445 &reg);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400446 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;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700457 res = pcmcia_access_configuration_register(hw_priv->link->handle,
458 &reg);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400459 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;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700471 res = pcmcia_access_configuration_register(hw_priv->link->handle,
472 &reg);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400473 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;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700483 res = pcmcia_access_configuration_register(hw_priv->link->handle,
484 &reg);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400485 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
Jouni Malinenff1d2762005-05-12 22:54:16 -0400495static struct prism2_helper_functions prism2_pccard_funcs =
496{
497 .card_present = prism2_pccard_card_present,
498 .cor_sreset = prism2_pccard_cor_sreset,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400499 .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 */
506static 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;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400526 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);
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100531 prism2_detach(link->handle);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400532 return NULL;
533 }
534 return link;
535}
536
537
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100538static void prism2_detach(struct pcmcia_device *p_dev)
Jouni Malinenff1d2762005-05-12 22:54:16 -0400539{
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100540 dev_link_t *link = dev_to_instance(p_dev);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400541 dev_link_t **linkp;
542
543 PDEBUG(DEBUG_FLOW, "prism2_detach\n");
544
545 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
546 if (*linkp == link)
547 break;
548 if (*linkp == NULL) {
549 printk(KERN_WARNING "%s: Attempt to detach non-existing "
550 "PCMCIA client\n", dev_info);
551 return;
552 }
553
554 if (link->state & DEV_CONFIG) {
555 prism2_release((u_long)link);
556 }
557
Jouni Malinenff1d2762005-05-12 22:54:16 -0400558 *linkp = link->next;
559 /* release net devices */
560 if (link->priv) {
Jouni Malinenc3551842005-10-02 17:19:00 -0700561 struct hostap_cs_priv *hw_priv;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700562 struct net_device *dev;
563 struct hostap_interface *iface;
564 dev = link->priv;
565 iface = netdev_priv(dev);
Jouni Malinenc3551842005-10-02 17:19:00 -0700566 hw_priv = iface->local->hw_priv;
Jouni Malinen67e0e472005-08-14 19:08:41 -0700567 prism2_free_local_data(dev);
Jouni Malinenc3551842005-10-02 17:19:00 -0700568 kfree(hw_priv);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400569 }
570 kfree(link);
571}
572
573
574#define CS_CHECK(fn, ret) \
575do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
576
577#define CFG_CHECK2(fn, retf) \
578do { int ret = (retf); \
579if (ret != 0) { \
580 PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", ret); \
581 cs_error(link->handle, fn, ret); \
582 goto next_entry; \
583} \
584} while (0)
585
586
587/* run after a CARD_INSERTION event is received to configure the PCMCIA
588 * socket and make the device available to the system */
589static int prism2_config(dev_link_t *link)
590{
591 struct net_device *dev;
592 struct hostap_interface *iface;
593 local_info_t *local;
594 int ret = 1;
595 tuple_t tuple;
596 cisparse_t *parse;
597 int last_fn, last_ret;
598 u_char buf[64];
599 config_info_t conf;
600 cistpl_cftable_entry_t dflt = { 0 };
Jouni Malinen67e0e472005-08-14 19:08:41 -0700601 struct hostap_cs_priv *hw_priv;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400602
603 PDEBUG(DEBUG_FLOW, "prism2_config()\n");
604
605 parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700606 hw_priv = kmalloc(sizeof(*hw_priv), GFP_KERNEL);
607 if (parse == NULL || hw_priv == NULL) {
608 kfree(parse);
609 kfree(hw_priv);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400610 ret = -ENOMEM;
611 goto failed;
612 }
Jouni Malinen67e0e472005-08-14 19:08:41 -0700613 memset(hw_priv, 0, sizeof(*hw_priv));
Jouni Malinenff1d2762005-05-12 22:54:16 -0400614
615 tuple.DesiredTuple = CISTPL_CONFIG;
616 tuple.Attributes = 0;
617 tuple.TupleData = buf;
618 tuple.TupleDataMax = sizeof(buf);
619 tuple.TupleOffset = 0;
620 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple));
621 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link->handle, &tuple));
622 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link->handle, &tuple, parse));
623 link->conf.ConfigBase = parse->config.base;
624 link->conf.Present = parse->config.rmask[0];
625
626 CS_CHECK(GetConfigurationInfo,
627 pcmcia_get_configuration_info(link->handle, &conf));
628 PDEBUG(DEBUG_HW, "%s: %s Vcc=%d (from config)\n", dev_info,
629 ignore_cis_vcc ? "ignoring" : "setting", conf.Vcc);
630 link->conf.Vcc = conf.Vcc;
631
632 /* Look for an appropriate configuration table entry in the CIS */
633 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
634 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple));
635 for (;;) {
636 cistpl_cftable_entry_t *cfg = &(parse->cftable_entry);
637 CFG_CHECK2(GetTupleData,
638 pcmcia_get_tuple_data(link->handle, &tuple));
639 CFG_CHECK2(ParseTuple,
640 pcmcia_parse_tuple(link->handle, &tuple, parse));
641
642 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
643 dflt = *cfg;
644 if (cfg->index == 0)
645 goto next_entry;
646 link->conf.ConfigIndex = cfg->index;
647 PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X "
648 "(default 0x%02X)\n", cfg->index, dflt.index);
Jeff Garzik74fae822005-07-31 13:08:32 -0400649
Jouni Malinenff1d2762005-05-12 22:54:16 -0400650 /* Does this card need audio output? */
651 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
652 link->conf.Attributes |= CONF_ENABLE_SPKR;
653 link->conf.Status = CCSR_AUDIO_ENA;
654 }
Jeff Garzik74fae822005-07-31 13:08:32 -0400655
Jouni Malinenff1d2762005-05-12 22:54:16 -0400656 /* Use power settings for Vcc and Vpp if present */
657 /* Note that the CIS values need to be rescaled */
658 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
659 if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] /
660 10000 && !ignore_cis_vcc) {
661 PDEBUG(DEBUG_EXTRA, " Vcc mismatch - skipping"
662 " this entry\n");
663 goto next_entry;
664 }
665 } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
666 if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] /
667 10000 && !ignore_cis_vcc) {
668 PDEBUG(DEBUG_EXTRA, " Vcc (default) mismatch "
669 "- skipping this entry\n");
670 goto next_entry;
671 }
672 }
673
674 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
675 link->conf.Vpp1 = link->conf.Vpp2 =
676 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
677 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
678 link->conf.Vpp1 = link->conf.Vpp2 =
679 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
680
681 /* Do we need to allocate an interrupt? */
682 if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
683 link->conf.Attributes |= CONF_ENABLE_IRQ;
684 else if (!(link->conf.Attributes & CONF_ENABLE_IRQ)) {
685 /* At least Compaq WL200 does not have IRQInfo1 set,
686 * but it does not work without interrupts.. */
687 printk("Config has no IRQ info, but trying to enable "
688 "IRQ anyway..\n");
689 link->conf.Attributes |= CONF_ENABLE_IRQ;
690 }
691
692 /* IO window settings */
693 PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d "
694 "dflt.io.nwin=%d\n",
695 cfg->io.nwin, dflt.io.nwin);
696 link->io.NumPorts1 = link->io.NumPorts2 = 0;
697 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
698 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
699 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
700 PDEBUG(DEBUG_EXTRA, "io->flags = 0x%04X, "
701 "io.base=0x%04x, len=%d\n", io->flags,
702 io->win[0].base, io->win[0].len);
703 if (!(io->flags & CISTPL_IO_8BIT))
704 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
705 if (!(io->flags & CISTPL_IO_16BIT))
706 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
707 link->io.IOAddrLines = io->flags &
708 CISTPL_IO_LINES_MASK;
709 link->io.BasePort1 = io->win[0].base;
710 link->io.NumPorts1 = io->win[0].len;
711 if (io->nwin > 1) {
712 link->io.Attributes2 = link->io.Attributes1;
713 link->io.BasePort2 = io->win[1].base;
714 link->io.NumPorts2 = io->win[1].len;
715 }
716 }
717
718 /* This reserves IO space but doesn't actually enable it */
719 CFG_CHECK2(RequestIO,
720 pcmcia_request_io(link->handle, &link->io));
721
722 /* This configuration table entry is OK */
723 break;
724
725 next_entry:
726 CS_CHECK(GetNextTuple,
727 pcmcia_get_next_tuple(link->handle, &tuple));
728 }
729
730 /* Need to allocate net_device before requesting IRQ handler */
Dave Hansen0cd545d2005-07-30 12:49:58 -0700731 dev = prism2_init_local_data(&prism2_pccard_funcs, 0,
732 &handle_to_dev(link->handle));
Jouni Malinenff1d2762005-05-12 22:54:16 -0400733 if (dev == NULL)
734 goto failed;
735 link->priv = dev;
736
Jouni Malinenfbff8682005-08-28 17:53:32 -0700737 iface = netdev_priv(dev);
738 local = iface->local;
739 local->hw_priv = hw_priv;
740 hw_priv->link = link;
741 strcpy(hw_priv->node.dev_name, dev->name);
742 link->dev = &hw_priv->node;
743
Jouni Malinenff1d2762005-05-12 22:54:16 -0400744 /*
745 * Allocate an interrupt line. Note that this does not assign a
746 * handler to the interrupt, unless the 'Handler' member of the
747 * irq structure is initialized.
748 */
749 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
Jouni Malinenff1d2762005-05-12 22:54:16 -0400750 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
Jar0ef79ee2005-07-30 12:49:57 -0700751 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400752 link->irq.Handler = prism2_interrupt;
753 link->irq.Instance = dev;
754 CS_CHECK(RequestIRQ,
755 pcmcia_request_irq(link->handle, &link->irq));
756 }
757
758 /*
759 * This actually configures the PCMCIA socket -- setting up
760 * the I/O windows and the interrupt mapping, and putting the
761 * card and host interface into "Memory and IO" mode.
762 */
763 CS_CHECK(RequestConfiguration,
764 pcmcia_request_configuration(link->handle, &link->conf));
765
766 dev->irq = link->irq.AssignedIRQ;
767 dev->base_addr = link->io.BasePort1;
768
769 /* Finally, report what we've done */
770 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d",
771 dev_info, link->conf.ConfigIndex,
772 link->conf.Vcc / 10, link->conf.Vcc % 10);
773 if (link->conf.Vpp1)
774 printk(", Vpp %d.%d", link->conf.Vpp1 / 10,
775 link->conf.Vpp1 % 10);
776 if (link->conf.Attributes & CONF_ENABLE_IRQ)
777 printk(", irq %d", link->irq.AssignedIRQ);
778 if (link->io.NumPorts1)
779 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
780 link->io.BasePort1+link->io.NumPorts1-1);
781 if (link->io.NumPorts2)
782 printk(" & 0x%04x-0x%04x", link->io.BasePort2,
783 link->io.BasePort2+link->io.NumPorts2-1);
784 printk("\n");
785
786 link->state |= DEV_CONFIG;
787 link->state &= ~DEV_CONFIG_PENDING;
788
Jouni Malinenff1d2762005-05-12 22:54:16 -0400789 local->shutdown = 0;
790
791 sandisk_enable_wireless(dev);
792
793 ret = prism2_hw_config(dev, 1);
794 if (!ret) {
795 ret = hostap_hw_ready(dev);
796 if (ret == 0 && local->ddev)
Jouni Malinen67e0e472005-08-14 19:08:41 -0700797 strcpy(hw_priv->node.dev_name, local->ddev->name);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400798 }
799 kfree(parse);
800 return ret;
801
802 cs_failed:
803 cs_error(link->handle, last_fn, last_ret);
804
805 failed:
806 kfree(parse);
Jouni Malinen67e0e472005-08-14 19:08:41 -0700807 kfree(hw_priv);
Jouni Malinenff1d2762005-05-12 22:54:16 -0400808 prism2_release((u_long)link);
809 return ret;
810}
811
812
813static void prism2_release(u_long arg)
814{
815 dev_link_t *link = (dev_link_t *)arg;
816
817 PDEBUG(DEBUG_FLOW, "prism2_release\n");
818
819 if (link->priv) {
820 struct net_device *dev = link->priv;
821 struct hostap_interface *iface;
822
823 iface = netdev_priv(dev);
824 if (link->state & DEV_CONFIG)
825 prism2_hw_shutdown(dev, 0);
826 iface->local->shutdown = 1;
827 }
828
829 if (link->win)
830 pcmcia_release_window(link->win);
831 pcmcia_release_configuration(link->handle);
832 if (link->io.NumPorts1)
833 pcmcia_release_io(link->handle, &link->io);
834 if (link->irq.AssignedIRQ)
835 pcmcia_release_irq(link->handle, &link->irq);
836
837 link->state &= ~DEV_CONFIG;
838
839 PDEBUG(DEBUG_FLOW, "release - done\n");
840}
841
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100842static int hostap_cs_suspend(struct pcmcia_device *p_dev)
843{
844 dev_link_t *link = dev_to_instance(p_dev);
845 struct net_device *dev = (struct net_device *) link->priv;
846 int dev_open = 0;
847
848 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info);
849
850 link->state |= DEV_SUSPEND;
851
852 if (link->state & DEV_CONFIG) {
853 struct hostap_interface *iface = netdev_priv(dev);
854 if (iface && iface->local)
855 dev_open = iface->local->num_dev_open > 0;
856 if (dev_open) {
857 netif_stop_queue(dev);
858 netif_device_detach(dev);
859 }
860 prism2_suspend(dev);
861 pcmcia_release_configuration(link->handle);
862 }
863
864 return 0;
865}
866
867static int hostap_cs_resume(struct pcmcia_device *p_dev)
868{
869 dev_link_t *link = dev_to_instance(p_dev);
870 struct net_device *dev = (struct net_device *) link->priv;
871 int dev_open = 0;
872
873 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info);
874
875 link->state &= ~DEV_SUSPEND;
876 if (link->state & DEV_CONFIG) {
877 struct hostap_interface *iface = netdev_priv(dev);
878 if (iface && iface->local)
879 dev_open = iface->local->num_dev_open > 0;
880
881 pcmcia_request_configuration(link->handle, &link->conf);
882
883 prism2_hw_shutdown(dev, 1);
884 prism2_hw_config(dev, dev_open ? 0 : 1);
885 if (dev_open) {
886 netif_device_attach(dev);
887 netif_start_queue(dev);
888 }
889 }
890
891 return 0;
892}
Jouni Malinenff1d2762005-05-12 22:54:16 -0400893
894static int prism2_event(event_t event, int priority,
895 event_callback_args_t *args)
896{
897 dev_link_t *link = args->client_data;
Jouni Malinenff1d2762005-05-12 22:54:16 -0400898
899 switch (event) {
900 case CS_EVENT_CARD_INSERTION:
901 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_INSERTION\n", dev_info);
902 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
903 if (prism2_config(link)) {
904 PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n");
905 }
906 break;
907
Jouni Malinenff1d2762005-05-12 22:54:16 -0400908 default:
909 PDEBUG(DEBUG_EXTRA, "%s: prism2_event() - unknown event %d\n",
910 dev_info, event);
911 break;
912 }
913 return 0;
914}
915
916
Henrik Brix Andersen093853c2005-07-30 12:49:59 -0700917static struct pcmcia_device_id hostap_cs_ids[] = {
918 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100),
919 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300),
920 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777),
921 PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000),
922 PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002),
923 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002),
924 PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002),
Richard Purdie1e4adbd2005-08-04 00:16:27 +0100925 PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030b),
Henrik Brix Andersen093853c2005-07-30 12:49:59 -0700926 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612),
927 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613),
928 PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002),
929 PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002),
930 PCMCIA_DEVICE_MANF_CARD(0x02d2, 0x0001),
931 PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x0001),
932 PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300),
933 PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000),
934 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
935 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
936 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010),
937 PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus",
938 0x7a954bd9, 0x74be00c6),
939 PCMCIA_DEVICE_PROD_ID1234(
940 "Intersil", "PRISM 2_5 PCMCIA ADAPTER", "ISL37300P",
941 "Eval-RevA",
942 0x4b801a17, 0x6345a0bf, 0xc9049a39, 0xc23adc0e),
943 PCMCIA_DEVICE_PROD_ID123(
944 "Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02",
945 0xe6ec52ce, 0x08649af2, 0x4b74baa0),
946 PCMCIA_DEVICE_PROD_ID123(
947 "D", "Link DWL-650 11Mbps WLAN Card", "Version 01.02",
948 0x71b18589, 0xb6f1b0ab, 0x4b74baa0),
949 PCMCIA_DEVICE_PROD_ID123(
950 "Instant Wireless ", " Network PC CARD", "Version 01.02",
951 0x11d901af, 0x6e9bd926, 0x4b74baa0),
952 PCMCIA_DEVICE_PROD_ID123(
953 "SMC", "SMC2632W", "Version 01.02",
954 0xc4f8b18b, 0x474a1f2a, 0x4b74baa0),
Richard Purdie1e4adbd2005-08-04 00:16:27 +0100955 PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G",
Jouni Malinen6c5b90d2005-08-28 10:51:36 -0700956 0x2decece3, 0x82067c18),
Henrik Brix Andersen093853c2005-07-30 12:49:59 -0700957 PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card",
958 0x54f7c49c, 0x15a75e5b),
959 PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE",
960 0x74c5e40d, 0xdb472a18),
961 PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card",
962 0x0733cc81, 0x0c52f395),
963 PCMCIA_DEVICE_PROD_ID12(
964 "ZoomAir 11Mbps High", "Rate wireless Networking",
965 0x273fe3db, 0x32a1eaee),
966 PCMCIA_DEVICE_NULL
967};
968MODULE_DEVICE_TABLE(pcmcia, hostap_cs_ids);
969
970
Jouni Malinenff1d2762005-05-12 22:54:16 -0400971static struct pcmcia_driver hostap_driver = {
972 .drv = {
973 .name = "hostap_cs",
974 },
975 .attach = prism2_attach,
Dominik Brodowskicc3b4862005-11-14 21:23:14 +0100976 .remove = prism2_detach,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400977 .owner = THIS_MODULE,
Jouni Malinen47e362c2005-07-30 12:49:55 -0700978 .event = prism2_event,
Henrik Brix Andersen093853c2005-07-30 12:49:59 -0700979 .id_table = hostap_cs_ids,
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100980 .suspend = hostap_cs_suspend,
981 .resume = hostap_cs_resume,
Jouni Malinenff1d2762005-05-12 22:54:16 -0400982};
983
984static int __init init_prism2_pccard(void)
985{
986 printk(KERN_INFO "%s: %s\n", dev_info, version);
987 return pcmcia_register_driver(&hostap_driver);
988}
989
990static void __exit exit_prism2_pccard(void)
991{
992 pcmcia_unregister_driver(&hostap_driver);
993 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
994}
995
996
997module_init(init_prism2_pccard);
998module_exit(exit_prism2_pccard);