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