2 * Host AP (software wireless LAN access point) driver for
3 * Intersil Prism2/2.5/3.
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
7 * Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. See README and COPYING for
15 * - there is currently no way of associating TX packets to correct wds device
16 * when TX Exc/OK event occurs, so all tx_packets and some
17 * tx_errors/tx_dropped are added to the main netdevice; using sw_support
18 * field in txdesc might be used to fix this (using Alloc event to increment
19 * tx_packets would need some further info in txfid table)
21 * Buffer Access Path (BAP) usage:
22 * Prism2 cards have two separate BAPs for accessing the card memory. These
23 * should allow concurrent access to two different frames and the driver
24 * previously used BAP0 for sending data and BAP1 for receiving data.
25 * However, there seems to be number of issues with concurrent access and at
26 * least one know hardware bug in using BAP0 and BAP1 concurrently with PCI
27 * Prism2.5. Therefore, the driver now only uses BAP0 for moving data between
28 * host and card memories. BAP0 accesses are protected with local->baplock
29 * (spin_lock_bh) to prevent concurrent use.
34 #include <asm/delay.h>
35 #include <asm/uaccess.h>
37 #include <linux/slab.h>
38 #include <linux/netdevice.h>
39 #include <linux/etherdevice.h>
40 #include <linux/proc_fs.h>
41 #include <linux/if_arp.h>
42 #include <linux/delay.h>
43 #include <linux/random.h>
44 #include <linux/wait.h>
45 #include <linux/sched.h>
46 #include <linux/rtnetlink.h>
47 #include <linux/wireless.h>
48 #include <net/iw_handler.h>
49 #include <net/ieee80211.h>
50 #include <net/ieee80211_crypt.h>
53 #include "hostap_80211.h"
55 #include "hostap_ap.h"
58 /* #define final_version */
60 static int mtu = 1500;
61 module_param(mtu, int, 0444);
62 MODULE_PARM_DESC(mtu, "Maximum transfer unit");
64 static int channel[MAX_PARM_DEVICES] = { 3, DEF_INTS };
65 module_param_array(channel, int, NULL, 0444);
66 MODULE_PARM_DESC(channel, "Initial channel");
68 static char essid[33] = "test";
69 module_param_string(essid, essid, sizeof(essid), 0444);
70 MODULE_PARM_DESC(essid, "Host AP's ESSID");
72 static int iw_mode[MAX_PARM_DEVICES] = { IW_MODE_MASTER, DEF_INTS };
73 module_param_array(iw_mode, int, NULL, 0444);
74 MODULE_PARM_DESC(iw_mode, "Initial operation mode");
76 static int beacon_int[MAX_PARM_DEVICES] = { 100, DEF_INTS };
77 module_param_array(beacon_int, int, NULL, 0444);
78 MODULE_PARM_DESC(beacon_int, "Beacon interval (1 = 1024 usec)");
80 static int dtim_period[MAX_PARM_DEVICES] = { 1, DEF_INTS };
81 module_param_array(dtim_period, int, NULL, 0444);
82 MODULE_PARM_DESC(dtim_period, "DTIM period");
84 static char dev_template[16] = "wlan%d";
85 module_param_string(dev_template, dev_template, sizeof(dev_template), 0444);
86 MODULE_PARM_DESC(dev_template, "Prefix for network device name (default: "
90 #define EXTRA_EVENTS_WTERR 0
92 /* check WTERR events (Wait Time-out) in development versions */
93 #define EXTRA_EVENTS_WTERR HFA384X_EV_WTERR
96 /* Events that will be using BAP0 */
97 #define HFA384X_BAP0_EVENTS \
98 (HFA384X_EV_TXEXC | HFA384X_EV_RX | HFA384X_EV_INFO | HFA384X_EV_TX)
100 /* event mask, i.e., events that will result in an interrupt */
101 #define HFA384X_EVENT_MASK \
102 (HFA384X_BAP0_EVENTS | HFA384X_EV_ALLOC | HFA384X_EV_INFDROP | \
103 HFA384X_EV_CMD | HFA384X_EV_TICK | \
106 /* Default TX control flags: use 802.11 headers and request interrupt for
107 * failed transmits. Frames that request ACK callback, will add
108 * _TX_OK flag and _ALT_RTRY flag may be used to select different retry policy.
110 #define HFA384X_TX_CTRL_FLAGS \
111 (HFA384X_TX_CTRL_802_11 | HFA384X_TX_CTRL_TX_EX)
115 #define HFA384X_CMD_BUSY_TIMEOUT 5000
116 #define HFA384X_BAP_BUSY_TIMEOUT 50000
119 #define HFA384X_CMD_COMPL_TIMEOUT 20000
120 #define HFA384X_DL_COMPL_TIMEOUT 1000000
122 /* Wait times for initialization; yield to other processes to avoid busy
123 * waiting for long time. */
124 #define HFA384X_INIT_TIMEOUT (HZ / 2) /* 500 ms */
125 #define HFA384X_ALLOC_COMPL_TIMEOUT (HZ / 20) /* 50 ms */
128 static void prism2_hw_reset(struct net_device *dev);
129 static void prism2_check_sta_fw_version(local_info_t *local);
131 #ifdef PRISM2_DOWNLOAD_SUPPORT
132 /* hostap_download.c */
133 static int prism2_download_aux_dump(struct net_device *dev,
134 unsigned int addr, int len, u8 *buf);
135 static u8 * prism2_read_pda(struct net_device *dev);
136 static int prism2_download(local_info_t *local,
137 struct prism2_download_param *param);
138 static void prism2_download_free_data(struct prism2_download_data *dl);
139 static int prism2_download_volatile(local_info_t *local,
140 struct prism2_download_data *param);
141 static int prism2_download_genesis(local_info_t *local,
142 struct prism2_download_data *param);
143 static int prism2_get_ram_size(local_info_t *local);
144 #endif /* PRISM2_DOWNLOAD_SUPPORT */
149 #ifndef final_version
150 /* magic value written to SWSUPPORT0 reg. for detecting whether card is still
152 #define HFA384X_MAGIC 0x8A32
156 static u16 hfa384x_read_reg(struct net_device *dev, u16 reg)
158 return HFA384X_INW(reg);
162 static void hfa384x_read_regs(struct net_device *dev,
163 struct hfa384x_regs *regs)
165 regs->cmd = HFA384X_INW(HFA384X_CMD_OFF);
166 regs->evstat = HFA384X_INW(HFA384X_EVSTAT_OFF);
167 regs->offset0 = HFA384X_INW(HFA384X_OFFSET0_OFF);
168 regs->offset1 = HFA384X_INW(HFA384X_OFFSET1_OFF);
169 regs->swsupport0 = HFA384X_INW(HFA384X_SWSUPPORT0_OFF);
174 * __hostap_cmd_queue_free - Free Prism2 command queue entry (private)
175 * @local: pointer to private Host AP driver data
176 * @entry: Prism2 command queue entry to be freed
177 * @del_req: request the entry to be removed
179 * Internal helper function for freeing Prism2 command queue entries.
180 * Caller must have acquired local->cmdlock before calling this function.
182 static inline void __hostap_cmd_queue_free(local_info_t *local,
183 struct hostap_cmd_queue *entry,
188 if (!list_empty(&entry->list)) {
189 list_del_init(&entry->list);
190 local->cmd_queue_len--;
194 if (atomic_dec_and_test(&entry->usecnt) && entry->del_req)
200 * hostap_cmd_queue_free - Free Prism2 command queue entry
201 * @local: pointer to private Host AP driver data
202 * @entry: Prism2 command queue entry to be freed
203 * @del_req: request the entry to be removed
205 * Free a Prism2 command queue entry.
207 static inline void hostap_cmd_queue_free(local_info_t *local,
208 struct hostap_cmd_queue *entry,
213 spin_lock_irqsave(&local->cmdlock, flags);
214 __hostap_cmd_queue_free(local, entry, del_req);
215 spin_unlock_irqrestore(&local->cmdlock, flags);
220 * prism2_clear_cmd_queue - Free all pending Prism2 command queue entries
221 * @local: pointer to private Host AP driver data
223 static void prism2_clear_cmd_queue(local_info_t *local)
225 struct list_head *ptr, *n;
227 struct hostap_cmd_queue *entry;
229 spin_lock_irqsave(&local->cmdlock, flags);
230 list_for_each_safe(ptr, n, &local->cmd_queue) {
231 entry = list_entry(ptr, struct hostap_cmd_queue, list);
232 atomic_inc(&entry->usecnt);
233 printk(KERN_DEBUG "%s: removed pending cmd_queue entry "
234 "(type=%d, cmd=0x%04x, param0=0x%04x)\n",
235 local->dev->name, entry->type, entry->cmd,
237 __hostap_cmd_queue_free(local, entry, 1);
239 if (local->cmd_queue_len) {
240 /* This should not happen; print debug message and clear
242 printk(KERN_DEBUG "%s: cmd_queue_len (%d) not zero after "
243 "flush\n", local->dev->name, local->cmd_queue_len);
244 local->cmd_queue_len = 0;
246 spin_unlock_irqrestore(&local->cmdlock, flags);
251 * hfa384x_cmd_issue - Issue a Prism2 command to the hardware
252 * @dev: pointer to net_device
253 * @entry: Prism2 command queue entry to be issued
255 static int hfa384x_cmd_issue(struct net_device *dev,
256 struct hostap_cmd_queue *entry)
258 struct hostap_interface *iface;
264 iface = netdev_priv(dev);
265 local = iface->local;
267 if (local->func->card_present && !local->func->card_present(local))
271 printk(KERN_DEBUG "%s: driver bug - re-issuing command @%p\n",
275 /* wait until busy bit is clear; this should always be clear since the
276 * commands are serialized */
277 tries = HFA384X_CMD_BUSY_TIMEOUT;
278 while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
282 #ifndef final_version
283 if (tries != HFA384X_CMD_BUSY_TIMEOUT) {
284 prism2_io_debug_error(dev, 1);
285 printk(KERN_DEBUG "%s: hfa384x_cmd_issue: cmd reg was busy "
286 "for %d usec\n", dev->name,
287 HFA384X_CMD_BUSY_TIMEOUT - tries);
291 reg = HFA384X_INW(HFA384X_CMD_OFF);
292 prism2_io_debug_error(dev, 2);
293 printk(KERN_DEBUG "%s: hfa384x_cmd_issue - timeout - "
294 "reg=0x%04x\n", dev->name, reg);
299 spin_lock_irqsave(&local->cmdlock, flags);
300 HFA384X_OUTW(entry->param0, HFA384X_PARAM0_OFF);
301 HFA384X_OUTW(entry->param1, HFA384X_PARAM1_OFF);
302 HFA384X_OUTW(entry->cmd, HFA384X_CMD_OFF);
304 spin_unlock_irqrestore(&local->cmdlock, flags);
311 * hfa384x_cmd - Issue a Prism2 command and wait (sleep) for completion
312 * @dev: pointer to net_device
313 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
314 * @param0: value for Param0 register
315 * @param1: value for Param1 register (pointer; %NULL if not used)
316 * @resp0: pointer for Resp0 data or %NULL if Resp0 is not needed
318 * Issue given command (possibly after waiting in command queue) and sleep
319 * until the command is completed (or timed out or interrupted). This can be
320 * called only from user process context.
322 static int hfa384x_cmd(struct net_device *dev, u16 cmd, u16 param0,
323 u16 *param1, u16 *resp0)
325 struct hostap_interface *iface;
327 int err, res, issue, issued = 0;
329 struct hostap_cmd_queue *entry;
330 DECLARE_WAITQUEUE(wait, current);
332 iface = netdev_priv(dev);
333 local = iface->local;
335 if (in_interrupt()) {
336 printk(KERN_DEBUG "%s: hfa384x_cmd called from interrupt "
337 "context\n", dev->name);
341 if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN) {
342 printk(KERN_DEBUG "%s: hfa384x_cmd: cmd_queue full\n",
347 if (signal_pending(current))
350 entry = (struct hostap_cmd_queue *)
351 kmalloc(sizeof(*entry), GFP_ATOMIC);
353 printk(KERN_DEBUG "%s: hfa384x_cmd - kmalloc failed\n",
357 memset(entry, 0, sizeof(*entry));
358 atomic_set(&entry->usecnt, 1);
359 entry->type = CMD_SLEEP;
361 entry->param0 = param0;
363 entry->param1 = *param1;
364 init_waitqueue_head(&entry->compl);
366 /* prepare to wait for command completion event, but do not sleep yet
368 add_wait_queue(&entry->compl, &wait);
369 set_current_state(TASK_INTERRUPTIBLE);
371 spin_lock_irqsave(&local->cmdlock, flags);
372 issue = list_empty(&local->cmd_queue);
375 list_add_tail(&entry->list, &local->cmd_queue);
376 local->cmd_queue_len++;
377 spin_unlock_irqrestore(&local->cmdlock, flags);
381 goto wait_completion;
383 if (signal_pending(current))
387 if (hfa384x_cmd_issue(dev, entry))
394 if (!err && entry->type != CMD_COMPLETED) {
395 /* sleep until command is completed or timed out */
396 res = schedule_timeout(2 * HZ);
400 if (!err && signal_pending(current))
404 /* the command was issued, so a CmdCompl event should occur
405 * soon; however, there's a pending signal and
406 * schedule_timeout() would be interrupted; wait a short period
407 * of time to avoid removing entry from the list before
412 set_current_state(TASK_RUNNING);
413 remove_wait_queue(&entry->compl, &wait);
415 /* If entry->list is still in the list, it must be removed
416 * first and in this case prism2_cmd_ev() does not yet have
417 * local reference to it, and the data can be kfree()'d
418 * here. If the command completion event is still generated,
419 * it will be assigned to next (possibly) pending command, but
420 * the driver will reset the card anyway due to timeout
422 * If the entry is not in the list prism2_cmd_ev() has a local
423 * reference to it, but keeps cmdlock as long as the data is
424 * needed, so the data can be kfree()'d here. */
426 /* FIX: if the entry->list is in the list, it has not been completed
427 * yet, so removing it here is somewhat wrong.. this could cause
428 * references to freed memory and next list_del() causing NULL pointer
429 * dereference.. it would probably be better to leave the entry in the
430 * list and the list should be emptied during hw reset */
432 spin_lock_irqsave(&local->cmdlock, flags);
433 if (!list_empty(&entry->list)) {
434 printk(KERN_DEBUG "%s: hfa384x_cmd: entry still in list? "
435 "(entry=%p, type=%d, res=%d)\n", dev->name, entry,
437 list_del_init(&entry->list);
438 local->cmd_queue_len--;
440 spin_unlock_irqrestore(&local->cmdlock, flags);
443 printk(KERN_DEBUG "%s: hfa384x_cmd: interrupted; err=%d\n",
449 if (entry->type != CMD_COMPLETED) {
450 u16 reg = HFA384X_INW(HFA384X_EVSTAT_OFF);
451 printk(KERN_DEBUG "%s: hfa384x_cmd: command was not "
452 "completed (res=%d, entry=%p, type=%d, cmd=0x%04x, "
453 "param0=0x%04x, EVSTAT=%04x INTEN=%04x)\n", dev->name,
454 res, entry, entry->type, entry->cmd, entry->param0, reg,
455 HFA384X_INW(HFA384X_INTEN_OFF));
456 if (reg & HFA384X_EV_CMD) {
457 /* Command completion event is pending, but the
458 * interrupt was not delivered - probably an issue
459 * with pcmcia-cs configuration. */
460 printk(KERN_WARNING "%s: interrupt delivery does not "
461 "seem to work\n", dev->name);
463 prism2_io_debug_error(dev, 3);
469 *resp0 = entry->resp0;
470 #ifndef final_version
472 printk(KERN_DEBUG "%s: CMD=0x%04x => res=0x%02x, "
474 dev->name, cmd, entry->res, entry->resp0);
476 #endif /* final_version */
480 hostap_cmd_queue_free(local, entry, 1);
486 * hfa384x_cmd_callback - Issue a Prism2 command; callback when completed
487 * @dev: pointer to net_device
488 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
489 * @param0: value for Param0 register
490 * @callback: command completion callback function (%NULL = no callback)
491 * @context: context data to be given to the callback function
493 * Issue given command (possibly after waiting in command queue) and use
494 * callback function to indicate command completion. This can be called both
495 * from user and interrupt context. The callback function will be called in
496 * hardware IRQ context. It can be %NULL, when no function is called when
497 * command is completed.
499 static int hfa384x_cmd_callback(struct net_device *dev, u16 cmd, u16 param0,
500 void (*callback)(struct net_device *dev,
501 long context, u16 resp0,
505 struct hostap_interface *iface;
509 struct hostap_cmd_queue *entry;
511 iface = netdev_priv(dev);
512 local = iface->local;
514 if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN + 2) {
515 printk(KERN_DEBUG "%s: hfa384x_cmd: cmd_queue full\n",
520 entry = (struct hostap_cmd_queue *)
521 kmalloc(sizeof(*entry), GFP_ATOMIC);
523 printk(KERN_DEBUG "%s: hfa384x_cmd_callback - kmalloc "
524 "failed\n", dev->name);
527 memset(entry, 0, sizeof(*entry));
528 atomic_set(&entry->usecnt, 1);
529 entry->type = CMD_CALLBACK;
531 entry->param0 = param0;
532 entry->callback = callback;
533 entry->context = context;
535 spin_lock_irqsave(&local->cmdlock, flags);
536 issue = list_empty(&local->cmd_queue);
539 list_add_tail(&entry->list, &local->cmd_queue);
540 local->cmd_queue_len++;
541 spin_unlock_irqrestore(&local->cmdlock, flags);
543 if (issue && hfa384x_cmd_issue(dev, entry))
548 hostap_cmd_queue_free(local, entry, ret);
555 * __hfa384x_cmd_no_wait - Issue a Prism2 command (private)
556 * @dev: pointer to net_device
557 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
558 * @param0: value for Param0 register
559 * @io_debug_num: I/O debug error number
561 * Shared helper function for hfa384x_cmd_wait() and hfa384x_cmd_no_wait().
563 static int __hfa384x_cmd_no_wait(struct net_device *dev, u16 cmd, u16 param0,
569 /* wait until busy bit is clear; this should always be clear since the
570 * commands are serialized */
571 tries = HFA384X_CMD_BUSY_TIMEOUT;
572 while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
577 reg = HFA384X_INW(HFA384X_CMD_OFF);
578 prism2_io_debug_error(dev, io_debug_num);
579 printk(KERN_DEBUG "%s: __hfa384x_cmd_no_wait(%d) - timeout - "
580 "reg=0x%04x\n", dev->name, io_debug_num, reg);
585 HFA384X_OUTW(param0, HFA384X_PARAM0_OFF);
586 HFA384X_OUTW(cmd, HFA384X_CMD_OFF);
593 * hfa384x_cmd_wait - Issue a Prism2 command and busy wait for completion
594 * @dev: pointer to net_device
595 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
596 * @param0: value for Param0 register
598 static int hfa384x_cmd_wait(struct net_device *dev, u16 cmd, u16 param0)
603 res = __hfa384x_cmd_no_wait(dev, cmd, param0, 4);
607 /* wait for command completion */
608 if ((cmd & HFA384X_CMDCODE_MASK) == HFA384X_CMDCODE_DOWNLOAD)
609 tries = HFA384X_DL_COMPL_TIMEOUT;
611 tries = HFA384X_CMD_COMPL_TIMEOUT;
613 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) &&
619 reg = HFA384X_INW(HFA384X_EVSTAT_OFF);
620 prism2_io_debug_error(dev, 5);
621 printk(KERN_DEBUG "%s: hfa384x_cmd_wait - timeout2 - "
622 "reg=0x%04x\n", dev->name, reg);
626 res = (HFA384X_INW(HFA384X_STATUS_OFF) &
627 (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) | BIT(9) |
629 #ifndef final_version
631 printk(KERN_DEBUG "%s: CMD=0x%04x => res=0x%02x\n",
632 dev->name, cmd, res);
636 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
643 * hfa384x_cmd_no_wait - Issue a Prism2 command; do not wait for completion
644 * @dev: pointer to net_device
645 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
646 * @param0: value for Param0 register
648 static inline int hfa384x_cmd_no_wait(struct net_device *dev, u16 cmd,
651 return __hfa384x_cmd_no_wait(dev, cmd, param0, 6);
656 * prism2_cmd_ev - Prism2 command completion event handler
657 * @dev: pointer to net_device
659 * Interrupt handler for command completion events. Called by the main
660 * interrupt handler in hardware IRQ context. Read Resp0 and status registers
661 * from the hardware and ACK the event. Depending on the issued command type
662 * either wake up the sleeping process that is waiting for command completion
663 * or call the callback function. Issue the next command, if one is pending.
665 static void prism2_cmd_ev(struct net_device *dev)
667 struct hostap_interface *iface;
669 struct hostap_cmd_queue *entry = NULL;
671 iface = netdev_priv(dev);
672 local = iface->local;
674 spin_lock(&local->cmdlock);
675 if (!list_empty(&local->cmd_queue)) {
676 entry = list_entry(local->cmd_queue.next,
677 struct hostap_cmd_queue, list);
678 atomic_inc(&entry->usecnt);
679 list_del_init(&entry->list);
680 local->cmd_queue_len--;
682 if (!entry->issued) {
683 printk(KERN_DEBUG "%s: Command completion event, but "
684 "cmd not issued\n", dev->name);
685 __hostap_cmd_queue_free(local, entry, 1);
689 spin_unlock(&local->cmdlock);
692 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
693 printk(KERN_DEBUG "%s: Command completion event, but no "
694 "pending commands\n", dev->name);
698 entry->resp0 = HFA384X_INW(HFA384X_RESP0_OFF);
699 entry->res = (HFA384X_INW(HFA384X_STATUS_OFF) &
700 (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) |
701 BIT(9) | BIT(8))) >> 8;
702 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
704 /* TODO: rest of the CmdEv handling could be moved to tasklet */
705 if (entry->type == CMD_SLEEP) {
706 entry->type = CMD_COMPLETED;
707 wake_up_interruptible(&entry->compl);
708 } else if (entry->type == CMD_CALLBACK) {
710 entry->callback(dev, entry->context, entry->resp0,
713 printk(KERN_DEBUG "%s: Invalid command completion type %d\n",
714 dev->name, entry->type);
716 hostap_cmd_queue_free(local, entry, 1);
718 /* issue next command, if pending */
720 spin_lock(&local->cmdlock);
721 if (!list_empty(&local->cmd_queue)) {
722 entry = list_entry(local->cmd_queue.next,
723 struct hostap_cmd_queue, list);
724 if (entry->issuing) {
725 /* hfa384x_cmd() has already started issuing this
726 * command, so do not start here */
730 atomic_inc(&entry->usecnt);
732 spin_unlock(&local->cmdlock);
735 /* issue next command; if command issuing fails, remove the
736 * entry from cmd_queue */
737 int res = hfa384x_cmd_issue(dev, entry);
738 spin_lock(&local->cmdlock);
739 __hostap_cmd_queue_free(local, entry, res);
740 spin_unlock(&local->cmdlock);
745 static int hfa384x_wait_offset(struct net_device *dev, u16 o_off)
747 int tries = HFA384X_BAP_BUSY_TIMEOUT;
748 int res = HFA384X_INW(o_off) & HFA384X_OFFSET_BUSY;
750 while (res && tries > 0) {
753 res = HFA384X_INW(o_off) & HFA384X_OFFSET_BUSY;
759 /* Offset must be even */
760 static int hfa384x_setup_bap(struct net_device *dev, u16 bap, u16 id,
766 if (offset % 2 || bap > 1)
770 o_off = HFA384X_OFFSET1_OFF;
771 s_off = HFA384X_SELECT1_OFF;
773 o_off = HFA384X_OFFSET0_OFF;
774 s_off = HFA384X_SELECT0_OFF;
777 if (hfa384x_wait_offset(dev, o_off)) {
778 prism2_io_debug_error(dev, 7);
779 printk(KERN_DEBUG "%s: hfa384x_setup_bap - timeout before\n",
785 HFA384X_OUTW(id, s_off);
786 HFA384X_OUTW(offset, o_off);
788 if (hfa384x_wait_offset(dev, o_off)) {
789 prism2_io_debug_error(dev, 8);
790 printk(KERN_DEBUG "%s: hfa384x_setup_bap - timeout after\n",
795 #ifndef final_version
796 if (HFA384X_INW(o_off) & HFA384X_OFFSET_ERR) {
797 prism2_io_debug_error(dev, 9);
798 printk(KERN_DEBUG "%s: hfa384x_setup_bap - offset error "
799 "(%d,0x04%x,%d); reg=0x%04x\n",
800 dev->name, bap, id, offset, HFA384X_INW(o_off));
810 static int hfa384x_get_rid(struct net_device *dev, u16 rid, void *buf, int len,
813 struct hostap_interface *iface;
816 struct hfa384x_rid_hdr rec;
818 iface = netdev_priv(dev);
819 local = iface->local;
822 printk(KERN_DEBUG "%s: cannot get RID %04x (len=%d) - no PRI "
823 "f/w\n", dev->name, rid, len);
824 return -ENOTTY; /* Well.. not really correct, but return
825 * something unique enough.. */
828 if ((local->func->card_present && !local->func->card_present(local)) ||
829 local->hw_downloading)
832 res = down_interruptible(&local->rid_bap_sem);
836 res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS, rid, NULL, NULL);
838 printk(KERN_DEBUG "%s: hfa384x_get_rid: CMDCODE_ACCESS failed "
839 "(res=%d, rid=%04x, len=%d)\n",
840 dev->name, res, rid, len);
841 up(&local->rid_bap_sem);
845 spin_lock_bh(&local->baplock);
847 res = hfa384x_setup_bap(dev, BAP0, rid, 0);
849 res = hfa384x_from_bap(dev, BAP0, &rec, sizeof(rec));
851 if (le16_to_cpu(rec.len) == 0) {
852 /* RID not available */
856 rlen = (le16_to_cpu(rec.len) - 1) * 2;
857 if (!res && exact_len && rlen != len) {
858 printk(KERN_DEBUG "%s: hfa384x_get_rid - RID len mismatch: "
859 "rid=0x%04x, len=%d (expected %d)\n",
860 dev->name, rid, rlen, len);
865 res = hfa384x_from_bap(dev, BAP0, buf, len);
867 spin_unlock_bh(&local->baplock);
868 up(&local->rid_bap_sem);
872 printk(KERN_DEBUG "%s: hfa384x_get_rid (rid=%04x, "
873 "len=%d) - failed - res=%d\n", dev->name, rid,
875 if (res == -ETIMEDOUT)
876 prism2_hw_reset(dev);
884 static int hfa384x_set_rid(struct net_device *dev, u16 rid, void *buf, int len)
886 struct hostap_interface *iface;
888 struct hfa384x_rid_hdr rec;
891 iface = netdev_priv(dev);
892 local = iface->local;
895 printk(KERN_DEBUG "%s: cannot set RID %04x (len=%d) - no PRI "
896 "f/w\n", dev->name, rid, len);
897 return -ENOTTY; /* Well.. not really correct, but return
898 * something unique enough.. */
901 if ((local->func->card_present && !local->func->card_present(local)) ||
902 local->hw_downloading)
905 rec.rid = cpu_to_le16(rid);
906 /* RID len in words and +1 for rec.rid */
907 rec.len = cpu_to_le16(len / 2 + len % 2 + 1);
909 res = down_interruptible(&local->rid_bap_sem);
913 spin_lock_bh(&local->baplock);
914 res = hfa384x_setup_bap(dev, BAP0, rid, 0);
916 res = hfa384x_to_bap(dev, BAP0, &rec, sizeof(rec));
918 res = hfa384x_to_bap(dev, BAP0, buf, len);
919 spin_unlock_bh(&local->baplock);
922 printk(KERN_DEBUG "%s: hfa384x_set_rid (rid=%04x, len=%d) - "
923 "failed - res=%d\n", dev->name, rid, len, res);
924 up(&local->rid_bap_sem);
928 res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS_WRITE, rid, NULL, NULL);
929 up(&local->rid_bap_sem);
932 printk(KERN_DEBUG "%s: hfa384x_set_rid: CMDCODE_ACCESS_WRITE "
933 "failed (res=%d, rid=%04x, len=%d)\n",
934 dev->name, res, rid, len);
936 if (res == -ETIMEDOUT)
937 prism2_hw_reset(dev);
944 static void hfa384x_disable_interrupts(struct net_device *dev)
946 /* disable interrupts and clear event status */
947 HFA384X_OUTW(0, HFA384X_INTEN_OFF);
948 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
952 static void hfa384x_enable_interrupts(struct net_device *dev)
954 /* ack pending events and enable interrupts from selected events */
955 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
956 HFA384X_OUTW(HFA384X_EVENT_MASK, HFA384X_INTEN_OFF);
960 static void hfa384x_events_no_bap0(struct net_device *dev)
962 HFA384X_OUTW(HFA384X_EVENT_MASK & ~HFA384X_BAP0_EVENTS,
967 static void hfa384x_events_all(struct net_device *dev)
969 HFA384X_OUTW(HFA384X_EVENT_MASK, HFA384X_INTEN_OFF);
973 static void hfa384x_events_only_cmd(struct net_device *dev)
975 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_INTEN_OFF);
979 static u16 hfa384x_allocate_fid(struct net_device *dev, int len)
984 /* FIX: this could be replace with hfa384x_cmd() if the Alloc event
985 * below would be handled like CmdCompl event (sleep here, wake up from
986 * interrupt handler */
987 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_ALLOC, len)) {
988 printk(KERN_DEBUG "%s: cannot allocate fid, len=%d\n",
993 delay = jiffies + HFA384X_ALLOC_COMPL_TIMEOUT;
994 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC) &&
995 time_before(jiffies, delay))
997 if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC)) {
998 printk("%s: fid allocate, len=%d - timeout\n", dev->name, len);
1002 fid = HFA384X_INW(HFA384X_ALLOCFID_OFF);
1003 HFA384X_OUTW(HFA384X_EV_ALLOC, HFA384X_EVACK_OFF);
1009 static int prism2_reset_port(struct net_device *dev)
1011 struct hostap_interface *iface;
1012 local_info_t *local;
1015 iface = netdev_priv(dev);
1016 local = iface->local;
1018 if (!local->dev_enabled)
1021 res = hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0,
1024 printk(KERN_DEBUG "%s: reset port failed to disable port\n",
1027 res = hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0,
1030 printk(KERN_DEBUG "%s: reset port failed to enable "
1031 "port\n", dev->name);
1034 /* It looks like at least some STA firmware versions reset
1035 * fragmentation threshold back to 2346 after enable command. Restore
1036 * the configured value, if it differs from this default. */
1037 if (local->fragm_threshold != 2346 &&
1038 hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
1039 local->fragm_threshold)) {
1040 printk(KERN_DEBUG "%s: failed to restore fragmentation "
1041 "threshold (%d) after Port0 enable\n",
1042 dev->name, local->fragm_threshold);
1045 /* Some firmwares lose antenna selection settings on reset */
1046 (void) hostap_set_antsel(local);
1052 static int prism2_get_version_info(struct net_device *dev, u16 rid,
1055 struct hfa384x_comp_ident comp;
1056 struct hostap_interface *iface;
1057 local_info_t *local;
1059 iface = netdev_priv(dev);
1060 local = iface->local;
1062 if (local->no_pri) {
1063 /* PRI f/w not yet available - cannot read RIDs */
1066 if (hfa384x_get_rid(dev, rid, &comp, sizeof(comp), 1) < 0) {
1067 printk(KERN_DEBUG "Could not get RID for component %s\n", txt);
1071 printk(KERN_INFO "%s: %s: id=0x%02x v%d.%d.%d\n", dev->name, txt,
1072 __le16_to_cpu(comp.id), __le16_to_cpu(comp.major),
1073 __le16_to_cpu(comp.minor), __le16_to_cpu(comp.variant));
1078 static int prism2_setup_rids(struct net_device *dev)
1080 struct hostap_interface *iface;
1081 local_info_t *local;
1085 iface = netdev_priv(dev);
1086 local = iface->local;
1088 hostap_set_word(dev, HFA384X_RID_TICKTIME, 2000);
1090 if (!local->fw_ap) {
1091 tmp = hostap_get_porttype(local);
1092 ret = hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, tmp);
1094 printk("%s: Port type setting to %d failed\n",
1100 /* Setting SSID to empty string seems to kill the card in Host AP mode
1102 if (local->iw_mode != IW_MODE_MASTER || local->essid[0] != '\0') {
1103 ret = hostap_set_string(dev, HFA384X_RID_CNFOWNSSID,
1106 printk("%s: AP own SSID setting failed\n", dev->name);
1111 ret = hostap_set_word(dev, HFA384X_RID_CNFMAXDATALEN,
1112 PRISM2_DATA_MAXLEN);
1114 printk("%s: MAC data length setting to %d failed\n",
1115 dev->name, PRISM2_DATA_MAXLEN);
1119 if (hfa384x_get_rid(dev, HFA384X_RID_CHANNELLIST, &tmp, 2, 1) < 0) {
1120 printk("%s: Channel list read failed\n", dev->name);
1124 local->channel_mask = __le16_to_cpu(tmp);
1126 if (local->channel < 1 || local->channel > 14 ||
1127 !(local->channel_mask & (1 << (local->channel - 1)))) {
1128 printk(KERN_WARNING "%s: Channel setting out of range "
1129 "(%d)!\n", dev->name, local->channel);
1134 ret = hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel);
1136 printk("%s: Channel setting to %d failed\n",
1137 dev->name, local->channel);
1141 ret = hostap_set_word(dev, HFA384X_RID_CNFBEACONINT,
1144 printk("%s: Beacon interval setting to %d failed\n",
1145 dev->name, local->beacon_int);
1146 /* this may fail with Symbol/Lucent firmware */
1147 if (ret == -ETIMEDOUT)
1151 ret = hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD,
1152 local->dtim_period);
1154 printk("%s: DTIM period setting to %d failed\n",
1155 dev->name, local->dtim_period);
1156 /* this may fail with Symbol/Lucent firmware */
1157 if (ret == -ETIMEDOUT)
1161 ret = hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE,
1164 printk(KERN_INFO "%s: Setting promiscuous mode (%d) failed\n",
1165 dev->name, local->is_promisc);
1167 if (!local->fw_ap) {
1168 ret = hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID,
1171 printk("%s: Desired SSID setting failed\n", dev->name);
1176 /* Setup TXRateControl, defaults to allow use of 1, 2, 5.5, and
1177 * 11 Mbps in automatic TX rate fallback and 1 and 2 Mbps as basic
1179 if (local->tx_rate_control == 0) {
1180 local->tx_rate_control =
1181 HFA384X_RATES_1MBPS |
1182 HFA384X_RATES_2MBPS |
1183 HFA384X_RATES_5MBPS |
1184 HFA384X_RATES_11MBPS;
1186 if (local->basic_rates == 0)
1187 local->basic_rates = HFA384X_RATES_1MBPS | HFA384X_RATES_2MBPS;
1189 if (!local->fw_ap) {
1190 ret = hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
1191 local->tx_rate_control);
1193 printk("%s: TXRateControl setting to %d failed\n",
1194 dev->name, local->tx_rate_control);
1198 ret = hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
1199 local->tx_rate_control);
1201 printk("%s: cnfSupportedRates setting to %d failed\n",
1202 dev->name, local->tx_rate_control);
1205 ret = hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
1206 local->basic_rates);
1208 printk("%s: cnfBasicRates setting to %d failed\n",
1209 dev->name, local->basic_rates);
1212 ret = hostap_set_word(dev, HFA384X_RID_CREATEIBSS, 1);
1214 printk("%s: Create IBSS setting to 1 failed\n",
1219 if (local->name_set)
1220 (void) hostap_set_string(dev, HFA384X_RID_CNFOWNNAME,
1223 if (hostap_set_encryption(local)) {
1224 printk(KERN_INFO "%s: could not configure encryption\n",
1228 (void) hostap_set_antsel(local);
1230 if (hostap_set_roaming(local)) {
1231 printk(KERN_INFO "%s: could not set host roaming\n",
1235 if (local->sta_fw_ver >= PRISM2_FW_VER(1,6,3) &&
1236 hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY, local->enh_sec))
1237 printk(KERN_INFO "%s: cnfEnhSecurity setting to 0x%x failed\n",
1238 dev->name, local->enh_sec);
1240 /* 32-bit tallies were added in STA f/w 0.8.0, but they were apparently
1241 * not working correctly (last seven counters report bogus values).
1242 * This has been fixed in 0.8.2, so enable 32-bit tallies only
1243 * beginning with that firmware version. Another bug fix for 32-bit
1244 * tallies in 1.4.0; should 16-bit tallies be used for some other
1246 if (local->sta_fw_ver >= PRISM2_FW_VER(0,8,2)) {
1247 if (hostap_set_word(dev, HFA384X_RID_CNFTHIRTY2TALLY, 1)) {
1248 printk(KERN_INFO "%s: cnfThirty2Tally setting "
1249 "failed\n", dev->name);
1250 local->tallies32 = 0;
1252 local->tallies32 = 1;
1254 local->tallies32 = 0;
1256 hostap_set_auth_algs(local);
1258 if (hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
1259 local->fragm_threshold)) {
1260 printk(KERN_INFO "%s: setting FragmentationThreshold to %d "
1261 "failed\n", dev->name, local->fragm_threshold);
1264 if (hostap_set_word(dev, HFA384X_RID_RTSTHRESHOLD,
1265 local->rts_threshold)) {
1266 printk(KERN_INFO "%s: setting RTSThreshold to %d failed\n",
1267 dev->name, local->rts_threshold);
1270 if (local->manual_retry_count >= 0 &&
1271 hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
1272 local->manual_retry_count)) {
1273 printk(KERN_INFO "%s: setting cnfAltRetryCount to %d failed\n",
1274 dev->name, local->manual_retry_count);
1277 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1) &&
1278 hfa384x_get_rid(dev, HFA384X_RID_CNFDBMADJUST, &tmp, 2, 1) == 2) {
1279 local->rssi_to_dBm = le16_to_cpu(tmp);
1282 if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->wpa &&
1283 hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1)) {
1284 printk(KERN_INFO "%s: setting ssnHandlingMode to 1 failed\n",
1288 if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->generic_elem &&
1289 hfa384x_set_rid(dev, HFA384X_RID_GENERICELEMENT,
1290 local->generic_elem, local->generic_elem_len)) {
1291 printk(KERN_INFO "%s: setting genericElement failed\n",
1300 static int prism2_hw_init(struct net_device *dev, int initial)
1302 struct hostap_interface *iface;
1303 local_info_t *local;
1305 unsigned long start, delay;
1307 PDEBUG(DEBUG_FLOW, "prism2_hw_init()\n");
1309 iface = netdev_priv(dev);
1310 local = iface->local;
1312 clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits);
1315 /* initialize HFA 384x */
1316 ret = hfa384x_cmd_no_wait(dev, HFA384X_CMDCODE_INIT, 0);
1318 printk(KERN_INFO "%s: first command failed - assuming card "
1319 "does not have primary firmware\n", dev_info);
1322 if (first && (HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
1323 /* EvStat has Cmd bit set in some cases, so retry once if no
1324 * wait was needed */
1325 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
1326 printk(KERN_DEBUG "%s: init command completed too quickly - "
1327 "retrying\n", dev->name);
1333 delay = jiffies + HFA384X_INIT_TIMEOUT;
1334 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) &&
1335 time_before(jiffies, delay))
1337 if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
1338 printk(KERN_DEBUG "%s: assuming no Primary image in "
1339 "flash - card initialization not completed\n",
1342 #ifdef PRISM2_DOWNLOAD_SUPPORT
1343 if (local->sram_type == -1)
1344 local->sram_type = prism2_get_ram_size(local);
1345 #endif /* PRISM2_DOWNLOAD_SUPPORT */
1349 printk(KERN_DEBUG "prism2_hw_init: initialized in %lu ms\n",
1350 (jiffies - start) * 1000 / HZ);
1351 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
1356 static int prism2_hw_init2(struct net_device *dev, int initial)
1358 struct hostap_interface *iface;
1359 local_info_t *local;
1362 iface = netdev_priv(dev);
1363 local = iface->local;
1365 #ifdef PRISM2_DOWNLOAD_SUPPORT
1370 local->pda = prism2_read_pda(dev);
1371 #endif /* PRISM2_DOWNLOAD_SUPPORT */
1373 hfa384x_disable_interrupts(dev);
1375 #ifndef final_version
1376 HFA384X_OUTW(HFA384X_MAGIC, HFA384X_SWSUPPORT0_OFF);
1377 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) {
1378 printk("SWSUPPORT0 write/read failed: %04X != %04X\n",
1379 HFA384X_INW(HFA384X_SWSUPPORT0_OFF), HFA384X_MAGIC);
1384 if (initial || local->pri_only) {
1385 hfa384x_events_only_cmd(dev);
1386 /* get card version information */
1387 if (prism2_get_version_info(dev, HFA384X_RID_NICID, "NIC") ||
1388 prism2_get_version_info(dev, HFA384X_RID_PRIID, "PRI")) {
1389 hfa384x_disable_interrupts(dev);
1393 if (prism2_get_version_info(dev, HFA384X_RID_STAID, "STA")) {
1394 printk(KERN_DEBUG "%s: Failed to read STA f/w version "
1395 "- only Primary f/w present\n", dev->name);
1396 local->pri_only = 1;
1399 local->pri_only = 0;
1400 hfa384x_disable_interrupts(dev);
1403 /* FIX: could convert allocate_fid to use sleeping CmdCompl wait and
1404 * enable interrupts before this. This would also require some sort of
1405 * sleeping AllocEv waiting */
1407 /* allocate TX FIDs */
1408 local->txfid_len = PRISM2_TXFID_LEN;
1409 for (i = 0; i < PRISM2_TXFID_COUNT; i++) {
1410 local->txfid[i] = hfa384x_allocate_fid(dev, local->txfid_len);
1411 if (local->txfid[i] == 0xffff && local->txfid_len > 1600) {
1412 local->txfid[i] = hfa384x_allocate_fid(dev, 1600);
1413 if (local->txfid[i] != 0xffff) {
1414 printk(KERN_DEBUG "%s: Using shorter TX FID "
1415 "(1600 bytes)\n", dev->name);
1416 local->txfid_len = 1600;
1419 if (local->txfid[i] == 0xffff)
1421 local->intransmitfid[i] = PRISM2_TXFID_EMPTY;
1424 hfa384x_events_only_cmd(dev);
1427 struct list_head *ptr;
1428 prism2_check_sta_fw_version(local);
1430 if (hfa384x_get_rid(dev, HFA384X_RID_CNFOWNMACADDR,
1431 &dev->dev_addr, 6, 1) < 0) {
1432 printk("%s: could not get own MAC address\n",
1435 list_for_each(ptr, &local->hostap_interfaces) {
1436 iface = list_entry(ptr, struct hostap_interface, list);
1437 memcpy(iface->dev->dev_addr, dev->dev_addr, ETH_ALEN);
1439 } else if (local->fw_ap)
1440 prism2_check_sta_fw_version(local);
1442 prism2_setup_rids(dev);
1444 /* MAC is now configured, but port 0 is not yet enabled */
1449 printk(KERN_WARNING "%s: Initialization failed\n", dev_info);
1454 static int prism2_hw_enable(struct net_device *dev, int initial)
1456 struct hostap_interface *iface;
1457 local_info_t *local;
1460 iface = netdev_priv(dev);
1461 local = iface->local;
1462 was_resetting = local->hw_resetting;
1464 if (hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL, NULL)) {
1465 printk("%s: MAC port 0 enabling failed\n", dev->name);
1469 local->hw_ready = 1;
1470 local->hw_reset_tries = 0;
1471 local->hw_resetting = 0;
1472 hfa384x_enable_interrupts(dev);
1474 /* at least D-Link DWL-650 seems to require additional port reset
1475 * before it starts acting as an AP, so reset port automatically
1476 * here just in case */
1477 if (initial && prism2_reset_port(dev)) {
1478 printk("%s: MAC port 0 reseting failed\n", dev->name);
1482 if (was_resetting && netif_queue_stopped(dev)) {
1483 /* If hw_reset() was called during pending transmit, netif
1484 * queue was stopped. Wake it up now since the wlan card has
1486 netif_wake_queue(dev);
1493 static int prism2_hw_config(struct net_device *dev, int initial)
1495 struct hostap_interface *iface;
1496 local_info_t *local;
1498 iface = netdev_priv(dev);
1499 local = iface->local;
1501 if (local->hw_downloading)
1504 if (prism2_hw_init(dev, initial)) {
1505 return local->no_pri ? 0 : 1;
1508 if (prism2_hw_init2(dev, initial))
1511 /* Enable firmware if secondary image is loaded and at least one of the
1512 * netdevices is up. */
1513 if (!local->pri_only &&
1514 (initial == 0 || (initial == 2 && local->num_dev_open > 0))) {
1515 if (!local->dev_enabled)
1516 prism2_callback(local, PRISM2_CALLBACK_ENABLE);
1517 local->dev_enabled = 1;
1518 return prism2_hw_enable(dev, initial);
1525 static void prism2_hw_shutdown(struct net_device *dev, int no_disable)
1527 struct hostap_interface *iface;
1528 local_info_t *local;
1530 iface = netdev_priv(dev);
1531 local = iface->local;
1533 /* Allow only command completion events during disable */
1534 hfa384x_events_only_cmd(dev);
1536 local->hw_ready = 0;
1537 if (local->dev_enabled)
1538 prism2_callback(local, PRISM2_CALLBACK_DISABLE);
1539 local->dev_enabled = 0;
1541 if (local->func->card_present && !local->func->card_present(local)) {
1542 printk(KERN_DEBUG "%s: card already removed or not configured "
1543 "during shutdown\n", dev->name);
1547 if ((no_disable & HOSTAP_HW_NO_DISABLE) == 0 &&
1548 hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL, NULL))
1549 printk(KERN_WARNING "%s: Shutdown failed\n", dev_info);
1551 hfa384x_disable_interrupts(dev);
1553 if (no_disable & HOSTAP_HW_ENABLE_CMDCOMPL)
1554 hfa384x_events_only_cmd(dev);
1556 prism2_clear_cmd_queue(local);
1560 static void prism2_hw_reset(struct net_device *dev)
1562 struct hostap_interface *iface;
1563 local_info_t *local;
1566 static long last_reset = 0;
1568 /* do not reset card more than once per second to avoid ending up in a
1569 * busy loop reseting the card */
1570 if (time_before_eq(jiffies, last_reset + HZ))
1572 last_reset = jiffies;
1575 iface = netdev_priv(dev);
1576 local = iface->local;
1578 if (in_interrupt()) {
1579 printk(KERN_DEBUG "%s: driver bug - prism2_hw_reset() called "
1580 "in interrupt context\n", dev->name);
1584 if (local->hw_downloading)
1587 if (local->hw_resetting) {
1588 printk(KERN_WARNING "%s: %s: already resetting card - "
1589 "ignoring reset request\n", dev_info, dev->name);
1593 local->hw_reset_tries++;
1594 if (local->hw_reset_tries > 10) {
1595 printk(KERN_WARNING "%s: too many reset tries, skipping\n",
1600 printk(KERN_WARNING "%s: %s: resetting card\n", dev_info, dev->name);
1601 hfa384x_disable_interrupts(dev);
1602 local->hw_resetting = 1;
1603 if (local->func->cor_sreset) {
1604 /* Host system seems to hang in some cases with high traffic
1605 * load or shared interrupts during COR sreset. Disable shared
1606 * interrupts during reset to avoid these crashes. COS sreset
1607 * takes quite a long time, so it is unfortunate that this
1608 * seems to be needed. Anyway, I do not know of any better way
1609 * of avoiding the crash. */
1610 disable_irq(dev->irq);
1611 local->func->cor_sreset(local);
1612 enable_irq(dev->irq);
1614 prism2_hw_shutdown(dev, 1);
1615 prism2_hw_config(dev, 0);
1616 local->hw_resetting = 0;
1618 #ifdef PRISM2_DOWNLOAD_SUPPORT
1619 if (local->dl_pri) {
1620 printk(KERN_DEBUG "%s: persistent download of primary "
1621 "firmware\n", dev->name);
1622 if (prism2_download_genesis(local, local->dl_pri) < 0)
1623 printk(KERN_WARNING "%s: download (PRI) failed\n",
1627 if (local->dl_sec) {
1628 printk(KERN_DEBUG "%s: persistent download of secondary "
1629 "firmware\n", dev->name);
1630 if (prism2_download_volatile(local, local->dl_sec) < 0)
1631 printk(KERN_WARNING "%s: download (SEC) failed\n",
1634 #endif /* PRISM2_DOWNLOAD_SUPPORT */
1636 /* TODO: restore beacon TIM bits for STAs that have buffered frames */
1640 static void prism2_schedule_reset(local_info_t *local)
1642 schedule_work(&local->reset_queue);
1646 /* Called only as scheduled task after noticing card timeout in interrupt
1648 static void handle_reset_queue(void *data)
1650 local_info_t *local = (local_info_t *) data;
1652 printk(KERN_DEBUG "%s: scheduled card reset\n", local->dev->name);
1653 prism2_hw_reset(local->dev);
1655 if (netif_queue_stopped(local->dev)) {
1658 for (i = 0; i < PRISM2_TXFID_COUNT; i++)
1659 if (local->intransmitfid[i] == PRISM2_TXFID_EMPTY) {
1660 PDEBUG(DEBUG_EXTRA, "prism2_tx_timeout: "
1662 netif_wake_queue(local->dev);
1669 static int prism2_get_txfid_idx(local_info_t *local)
1672 unsigned long flags;
1674 spin_lock_irqsave(&local->txfidlock, flags);
1675 end = idx = local->next_txfid;
1677 if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
1678 local->intransmitfid[idx] = PRISM2_TXFID_RESERVED;
1679 spin_unlock_irqrestore(&local->txfidlock, flags);
1683 if (idx >= PRISM2_TXFID_COUNT)
1685 } while (idx != end);
1686 spin_unlock_irqrestore(&local->txfidlock, flags);
1688 PDEBUG(DEBUG_EXTRA2, "prism2_get_txfid_idx: no room in txfid buf: "
1689 "packet dropped\n");
1690 local->stats.tx_dropped++;
1696 /* Called only from hardware IRQ */
1697 static void prism2_transmit_cb(struct net_device *dev, long context,
1700 struct hostap_interface *iface;
1701 local_info_t *local;
1702 int idx = (int) context;
1704 iface = netdev_priv(dev);
1705 local = iface->local;
1708 printk(KERN_DEBUG "%s: prism2_transmit_cb - res=0x%02x\n",
1713 if (idx < 0 || idx >= PRISM2_TXFID_COUNT) {
1714 printk(KERN_DEBUG "%s: prism2_transmit_cb called with invalid "
1715 "idx=%d\n", dev->name, idx);
1719 if (!test_and_clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
1720 printk(KERN_DEBUG "%s: driver bug: prism2_transmit_cb called "
1721 "with no pending transmit\n", dev->name);
1724 if (netif_queue_stopped(dev)) {
1725 /* ready for next TX, so wake up queue that was stopped in
1726 * prism2_transmit() */
1727 netif_wake_queue(dev);
1730 spin_lock(&local->txfidlock);
1732 /* With reclaim, Resp0 contains new txfid for transmit; the old txfid
1733 * will be automatically allocated for the next TX frame */
1734 local->intransmitfid[idx] = resp0;
1736 PDEBUG(DEBUG_FID, "%s: prism2_transmit_cb: txfid[%d]=0x%04x, "
1737 "resp0=0x%04x, transmit_txfid=0x%04x\n",
1738 dev->name, idx, local->txfid[idx],
1739 resp0, local->intransmitfid[local->next_txfid]);
1742 if (idx >= PRISM2_TXFID_COUNT)
1744 local->next_txfid = idx;
1746 /* check if all TX buffers are occupied */
1748 if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
1749 spin_unlock(&local->txfidlock);
1753 if (idx >= PRISM2_TXFID_COUNT)
1755 } while (idx != local->next_txfid);
1756 spin_unlock(&local->txfidlock);
1758 /* no empty TX buffers, stop queue */
1759 netif_stop_queue(dev);
1763 /* Called only from software IRQ if PCI bus master is not used (with bus master
1764 * this can be called both from software and hardware IRQ) */
1765 static int prism2_transmit(struct net_device *dev, int idx)
1767 struct hostap_interface *iface;
1768 local_info_t *local;
1771 iface = netdev_priv(dev);
1772 local = iface->local;
1774 /* The driver tries to stop netif queue so that there would not be
1775 * more than one attempt to transmit frames going on; check that this
1776 * is really the case */
1778 if (test_and_set_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
1779 printk(KERN_DEBUG "%s: driver bug - prism2_transmit() called "
1780 "when previous TX was pending\n", dev->name);
1784 /* stop the queue for the time that transmit is pending */
1785 netif_stop_queue(dev);
1787 /* transmit packet */
1788 res = hfa384x_cmd_callback(
1790 HFA384X_CMDCODE_TRANSMIT | HFA384X_CMD_TX_RECLAIM,
1792 prism2_transmit_cb, (long) idx);
1795 struct net_device_stats *stats;
1796 printk(KERN_DEBUG "%s: prism2_transmit: CMDCODE_TRANSMIT "
1797 "failed (res=%d)\n", dev->name, res);
1798 stats = hostap_get_stats(dev);
1799 stats->tx_dropped++;
1800 netif_wake_queue(dev);
1803 dev->trans_start = jiffies;
1805 /* Since we did not wait for command completion, the card continues
1806 * to process on the background and we will finish handling when
1807 * command completion event is handled (prism2_cmd_ev() function) */
1813 /* Send IEEE 802.11 frame (convert the header into Prism2 TX descriptor and
1814 * send the payload with this descriptor) */
1815 /* Called only from software IRQ */
1816 static int prism2_tx_80211(struct sk_buff *skb, struct net_device *dev)
1818 struct hostap_interface *iface;
1819 local_info_t *local;
1820 struct hfa384x_tx_frame txdesc;
1821 struct hostap_skb_tx_data *meta;
1822 int hdr_len, data_len, idx, res, ret = -1;
1825 iface = netdev_priv(dev);
1826 local = iface->local;
1828 meta = (struct hostap_skb_tx_data *) skb->cb;
1830 prism2_callback(local, PRISM2_CALLBACK_TX_START);
1832 if ((local->func->card_present && !local->func->card_present(local)) ||
1833 !local->hw_ready || local->hw_downloading || local->pri_only) {
1834 if (net_ratelimit()) {
1835 printk(KERN_DEBUG "%s: prism2_tx_80211: hw not ready -"
1836 " skipping\n", dev->name);
1841 memset(&txdesc, 0, sizeof(txdesc));
1843 /* skb->data starts with txdesc->frame_control */
1845 memcpy(&txdesc.frame_control, skb->data, hdr_len);
1846 fc = le16_to_cpu(txdesc.frame_control);
1847 if (WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA &&
1848 (fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS) &&
1851 memcpy(txdesc.addr4, skb->data + hdr_len, ETH_ALEN);
1852 hdr_len += ETH_ALEN;
1855 tx_control = local->tx_control;
1856 if (meta->tx_cb_idx) {
1857 tx_control |= HFA384X_TX_CTRL_TX_OK;
1858 txdesc.sw_support = cpu_to_le16(meta->tx_cb_idx);
1860 txdesc.tx_control = cpu_to_le16(tx_control);
1861 txdesc.tx_rate = meta->rate;
1863 data_len = skb->len - hdr_len;
1864 txdesc.data_len = cpu_to_le16(data_len);
1865 txdesc.len = cpu_to_be16(data_len);
1867 idx = prism2_get_txfid_idx(local);
1871 if (local->frame_dump & PRISM2_DUMP_TX_HDR)
1872 hostap_dump_tx_header(dev->name, &txdesc);
1874 spin_lock(&local->baplock);
1875 res = hfa384x_setup_bap(dev, BAP0, local->txfid[idx], 0);
1878 res = hfa384x_to_bap(dev, BAP0, &txdesc, sizeof(txdesc));
1880 res = hfa384x_to_bap(dev, BAP0, skb->data + hdr_len,
1881 skb->len - hdr_len);
1882 spin_unlock(&local->baplock);
1885 res = prism2_transmit(dev, idx);
1887 printk(KERN_DEBUG "%s: prism2_tx_80211 - to BAP0 failed\n",
1889 local->intransmitfid[idx] = PRISM2_TXFID_EMPTY;
1890 schedule_work(&local->reset_queue);
1897 prism2_callback(local, PRISM2_CALLBACK_TX_END);
1902 /* Some SMP systems have reported number of odd errors with hostap_pci. fid
1903 * register has changed values between consecutive reads for an unknown reason.
1904 * This should really not happen, so more debugging is needed. This test
1905 * version is a big slower, but it will detect most of such register changes
1906 * and will try to get the correct fid eventually. */
1907 #define EXTRA_FID_READ_TESTS
1909 static u16 prism2_read_fid_reg(struct net_device *dev, u16 reg)
1911 #ifdef EXTRA_FID_READ_TESTS
1912 u16 val, val2, val3;
1915 for (i = 0; i < 10; i++) {
1916 val = HFA384X_INW(reg);
1917 val2 = HFA384X_INW(reg);
1918 val3 = HFA384X_INW(reg);
1920 if (val == val2 && val == val3)
1923 printk(KERN_DEBUG "%s: detected fid change (try=%d, reg=%04x):"
1924 " %04x %04x %04x\n",
1925 dev->name, i, reg, val, val2, val3);
1926 if ((val == val2 || val == val3) && val != 0)
1928 if (val2 == val3 && val2 != 0)
1931 printk(KERN_WARNING "%s: Uhhuh.. could not read good fid from reg "
1932 "%04x (%04x %04x %04x)\n", dev->name, reg, val, val2, val3);
1934 #else /* EXTRA_FID_READ_TESTS */
1935 return HFA384X_INW(reg);
1936 #endif /* EXTRA_FID_READ_TESTS */
1940 /* Called only as a tasklet (software IRQ) */
1941 static void prism2_rx(local_info_t *local)
1943 struct net_device *dev = local->dev;
1944 int res, rx_pending = 0;
1945 u16 len, hdr_len, rxfid, status, macport;
1946 struct net_device_stats *stats;
1947 struct hfa384x_rx_frame rxdesc;
1948 struct sk_buff *skb = NULL;
1950 prism2_callback(local, PRISM2_CALLBACK_RX_START);
1951 stats = hostap_get_stats(dev);
1953 rxfid = prism2_read_fid_reg(dev, HFA384X_RXFID_OFF);
1954 #ifndef final_version
1956 rxfid = HFA384X_INW(HFA384X_RXFID_OFF);
1957 printk(KERN_DEBUG "prism2_rx: rxfid=0 (next 0x%04x)\n",
1960 schedule_work(&local->reset_queue);
1963 /* try to continue with the new rxfid value */
1967 spin_lock(&local->baplock);
1968 res = hfa384x_setup_bap(dev, BAP0, rxfid, 0);
1970 res = hfa384x_from_bap(dev, BAP0, &rxdesc, sizeof(rxdesc));
1973 spin_unlock(&local->baplock);
1974 printk(KERN_DEBUG "%s: copy from BAP0 failed %d\n", dev->name,
1976 if (res == -ETIMEDOUT) {
1977 schedule_work(&local->reset_queue);
1982 len = le16_to_cpu(rxdesc.data_len);
1983 hdr_len = sizeof(rxdesc);
1984 status = le16_to_cpu(rxdesc.status);
1985 macport = (status >> 8) & 0x07;
1987 /* Drop frames with too large reported payload length. Monitor mode
1988 * seems to sometimes pass frames (e.g., ctrl::ack) with signed and
1989 * negative value, so allow also values 65522 .. 65534 (-14 .. -2) for
1991 if (len > PRISM2_DATA_MAXLEN + 8 /* WEP */) {
1992 if (macport == 7 && local->iw_mode == IW_MODE_MONITOR) {
1993 if (len >= (u16) -14) {
1994 hdr_len -= 65535 - len;
1999 spin_unlock(&local->baplock);
2000 printk(KERN_DEBUG "%s: Received frame with invalid "
2001 "length 0x%04x\n", dev->name, len);
2002 hostap_dump_rx_header(dev->name, &rxdesc);
2007 skb = dev_alloc_skb(len + hdr_len);
2009 spin_unlock(&local->baplock);
2010 printk(KERN_DEBUG "%s: RX failed to allocate skb\n",
2015 memcpy(skb_put(skb, hdr_len), &rxdesc, hdr_len);
2018 res = hfa384x_from_bap(dev, BAP0, skb_put(skb, len), len);
2019 spin_unlock(&local->baplock);
2021 printk(KERN_DEBUG "%s: RX failed to read "
2022 "frame data\n", dev->name);
2026 skb_queue_tail(&local->rx_list, skb);
2027 tasklet_schedule(&local->rx_tasklet);
2030 prism2_callback(local, PRISM2_CALLBACK_RX_END);
2032 HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF);
2038 stats->rx_dropped++;
2045 /* Called only as a tasklet (software IRQ) */
2046 static void hostap_rx_skb(local_info_t *local, struct sk_buff *skb)
2048 struct hfa384x_rx_frame *rxdesc;
2049 struct net_device *dev = skb->dev;
2050 struct hostap_80211_rx_status stats;
2051 int hdrlen, rx_hdrlen;
2053 rx_hdrlen = sizeof(*rxdesc);
2054 if (skb->len < sizeof(*rxdesc)) {
2055 /* Allow monitor mode to receive shorter frames */
2056 if (local->iw_mode == IW_MODE_MONITOR &&
2057 skb->len >= sizeof(*rxdesc) - 30) {
2058 rx_hdrlen = skb->len;
2065 rxdesc = (struct hfa384x_rx_frame *) skb->data;
2067 if (local->frame_dump & PRISM2_DUMP_RX_HDR &&
2068 skb->len >= sizeof(*rxdesc))
2069 hostap_dump_rx_header(dev->name, rxdesc);
2071 if (le16_to_cpu(rxdesc->status) & HFA384X_RX_STATUS_FCSERR &&
2072 (!local->monitor_allow_fcserr ||
2073 local->iw_mode != IW_MODE_MONITOR))
2076 if (skb->len > PRISM2_DATA_MAXLEN) {
2077 printk(KERN_DEBUG "%s: RX: len(%d) > MAX(%d)\n",
2078 dev->name, skb->len, PRISM2_DATA_MAXLEN);
2082 stats.mac_time = le32_to_cpu(rxdesc->time);
2083 stats.signal = rxdesc->signal - local->rssi_to_dBm;
2084 stats.noise = rxdesc->silence - local->rssi_to_dBm;
2085 stats.rate = rxdesc->rate;
2087 /* Convert Prism2 RX structure into IEEE 802.11 header */
2088 hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(rxdesc->frame_control));
2089 if (hdrlen > rx_hdrlen)
2092 memmove(skb_pull(skb, rx_hdrlen - hdrlen),
2093 &rxdesc->frame_control, hdrlen);
2095 hostap_80211_rx(dev, skb, &stats);
2103 /* Called only as a tasklet (software IRQ) */
2104 static void hostap_rx_tasklet(unsigned long data)
2106 local_info_t *local = (local_info_t *) data;
2107 struct sk_buff *skb;
2109 while ((skb = skb_dequeue(&local->rx_list)) != NULL)
2110 hostap_rx_skb(local, skb);
2114 /* Called only from hardware IRQ */
2115 static void prism2_alloc_ev(struct net_device *dev)
2117 struct hostap_interface *iface;
2118 local_info_t *local;
2122 iface = netdev_priv(dev);
2123 local = iface->local;
2125 fid = prism2_read_fid_reg(dev, HFA384X_ALLOCFID_OFF);
2127 PDEBUG(DEBUG_FID, "FID: interrupt: ALLOC - fid=0x%04x\n", fid);
2129 spin_lock(&local->txfidlock);
2130 idx = local->next_alloc;
2133 if (local->txfid[idx] == fid) {
2134 PDEBUG(DEBUG_FID, "FID: found matching txfid[%d]\n",
2137 #ifndef final_version
2138 if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY)
2139 printk("Already released txfid found at idx "
2141 if (local->intransmitfid[idx] == PRISM2_TXFID_RESERVED)
2142 printk("Already reserved txfid found at idx "
2145 local->intransmitfid[idx] = PRISM2_TXFID_EMPTY;
2147 local->next_alloc = idx >= PRISM2_TXFID_COUNT ? 0 :
2150 if (!test_bit(HOSTAP_BITS_TRANSMIT, &local->bits) &&
2151 netif_queue_stopped(dev))
2152 netif_wake_queue(dev);
2154 spin_unlock(&local->txfidlock);
2159 if (idx >= PRISM2_TXFID_COUNT)
2161 } while (idx != local->next_alloc);
2163 printk(KERN_WARNING "%s: could not find matching txfid (0x%04x, new "
2164 "read 0x%04x) for alloc event\n", dev->name, fid,
2165 HFA384X_INW(HFA384X_ALLOCFID_OFF));
2166 printk(KERN_DEBUG "TXFIDs:");
2167 for (idx = 0; idx < PRISM2_TXFID_COUNT; idx++)
2168 printk(" %04x[%04x]", local->txfid[idx],
2169 local->intransmitfid[idx]);
2171 spin_unlock(&local->txfidlock);
2173 /* FIX: should probably schedule reset; reference to one txfid was lost
2174 * completely.. Bad things will happen if we run out of txfids
2175 * Actually, this will cause netdev watchdog to notice TX timeout and
2176 * then card reset after all txfids have been leaked. */
2180 /* Called only as a tasklet (software IRQ) */
2181 static void hostap_tx_callback(local_info_t *local,
2182 struct hfa384x_tx_frame *txdesc, int ok,
2185 u16 sw_support, hdrlen, len;
2186 struct sk_buff *skb;
2187 struct hostap_tx_callback_info *cb;
2189 /* Make sure that frame was from us. */
2190 if (memcmp(txdesc->addr2, local->dev->dev_addr, ETH_ALEN)) {
2191 printk(KERN_DEBUG "%s: TX callback - foreign frame\n",
2196 sw_support = le16_to_cpu(txdesc->sw_support);
2198 spin_lock(&local->lock);
2199 cb = local->tx_callback;
2200 while (cb != NULL && cb->idx != sw_support)
2202 spin_unlock(&local->lock);
2205 printk(KERN_DEBUG "%s: could not find TX callback (idx %d)\n",
2206 local->dev->name, sw_support);
2210 hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(txdesc->frame_control));
2211 len = le16_to_cpu(txdesc->data_len);
2212 skb = dev_alloc_skb(hdrlen + len);
2214 printk(KERN_DEBUG "%s: hostap_tx_callback failed to allocate "
2215 "skb\n", local->dev->name);
2219 memcpy(skb_put(skb, hdrlen), (void *) &txdesc->frame_control, hdrlen);
2221 memcpy(skb_put(skb, len), payload, len);
2223 skb->dev = local->dev;
2224 skb->mac.raw = skb->data;
2226 cb->func(skb, ok, cb->data);
2230 /* Called only as a tasklet (software IRQ) */
2231 static int hostap_tx_compl_read(local_info_t *local, int error,
2232 struct hfa384x_tx_frame *txdesc,
2237 struct net_device *dev = local->dev;
2239 fid = prism2_read_fid_reg(dev, HFA384X_TXCOMPLFID_OFF);
2241 PDEBUG(DEBUG_FID, "interrupt: TX (err=%d) - fid=0x%04x\n", fid, error);
2243 spin_lock(&local->baplock);
2244 res = hfa384x_setup_bap(dev, BAP0, fid, 0);
2246 res = hfa384x_from_bap(dev, BAP0, txdesc, sizeof(*txdesc));
2248 PDEBUG(DEBUG_EXTRA, "%s: TX (err=%d) - fid=0x%04x - could not "
2249 "read txdesc\n", dev->name, error, fid);
2250 if (res == -ETIMEDOUT) {
2251 schedule_work(&local->reset_queue);
2256 if (txdesc->sw_support) {
2257 len = le16_to_cpu(txdesc->data_len);
2258 if (len < PRISM2_DATA_MAXLEN) {
2259 *payload = (char *) kmalloc(len, GFP_ATOMIC);
2260 if (*payload == NULL ||
2261 hfa384x_from_bap(dev, BAP0, *payload, len)) {
2262 PDEBUG(DEBUG_EXTRA, "%s: could not read TX "
2263 "frame payload\n", dev->name);
2273 spin_unlock(&local->baplock);
2279 /* Called only as a tasklet (software IRQ) */
2280 static void prism2_tx_ev(local_info_t *local)
2282 struct net_device *dev = local->dev;
2283 char *payload = NULL;
2284 struct hfa384x_tx_frame txdesc;
2286 if (hostap_tx_compl_read(local, 0, &txdesc, &payload))
2289 if (local->frame_dump & PRISM2_DUMP_TX_HDR) {
2290 PDEBUG(DEBUG_EXTRA, "%s: TX - status=0x%04x "
2291 "retry_count=%d tx_rate=%d seq_ctrl=%d "
2293 dev->name, le16_to_cpu(txdesc.status),
2294 txdesc.retry_count, txdesc.tx_rate,
2295 le16_to_cpu(txdesc.seq_ctrl),
2296 le16_to_cpu(txdesc.duration_id));
2299 if (txdesc.sw_support)
2300 hostap_tx_callback(local, &txdesc, 1, payload);
2304 HFA384X_OUTW(HFA384X_EV_TX, HFA384X_EVACK_OFF);
2308 /* Called only as a tasklet (software IRQ) */
2309 static void hostap_sta_tx_exc_tasklet(unsigned long data)
2311 local_info_t *local = (local_info_t *) data;
2312 struct sk_buff *skb;
2314 while ((skb = skb_dequeue(&local->sta_tx_exc_list)) != NULL) {
2315 struct hfa384x_tx_frame *txdesc =
2316 (struct hfa384x_tx_frame *) skb->data;
2318 if (skb->len >= sizeof(*txdesc)) {
2319 /* Convert Prism2 RX structure into IEEE 802.11 header
2321 u16 fc = le16_to_cpu(txdesc->frame_control);
2322 int hdrlen = hostap_80211_get_hdrlen(fc);
2323 memmove(skb_pull(skb, sizeof(*txdesc) - hdrlen),
2324 &txdesc->frame_control, hdrlen);
2326 hostap_handle_sta_tx_exc(local, skb);
2333 /* Called only as a tasklet (software IRQ) */
2334 static void prism2_txexc(local_info_t *local)
2336 struct net_device *dev = local->dev;
2339 char *payload = NULL;
2340 struct hfa384x_tx_frame txdesc;
2342 show_dump = local->frame_dump & PRISM2_DUMP_TXEXC_HDR;
2343 local->stats.tx_errors++;
2345 res = hostap_tx_compl_read(local, 1, &txdesc, &payload);
2346 HFA384X_OUTW(HFA384X_EV_TXEXC, HFA384X_EVACK_OFF);
2350 status = le16_to_cpu(txdesc.status);
2352 /* We produce a TXDROP event only for retry or lifetime
2353 * exceeded, because that's the only status that really mean
2354 * that this particular node went away.
2355 * Other errors means that *we* screwed up. - Jean II */
2356 if (status & (HFA384X_TX_STATUS_RETRYERR | HFA384X_TX_STATUS_AGEDERR))
2358 union iwreq_data wrqu;
2360 /* Copy 802.11 dest address. */
2361 memcpy(wrqu.addr.sa_data, txdesc.addr1, ETH_ALEN);
2362 wrqu.addr.sa_family = ARPHRD_ETHER;
2363 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
2367 if (local->iw_mode == IW_MODE_MASTER ||
2368 local->iw_mode == IW_MODE_REPEAT ||
2369 local->wds_type & HOSTAP_WDS_AP_CLIENT) {
2370 struct sk_buff *skb;
2371 skb = dev_alloc_skb(sizeof(txdesc));
2373 memcpy(skb_put(skb, sizeof(txdesc)), &txdesc,
2375 skb_queue_tail(&local->sta_tx_exc_list, skb);
2376 tasklet_schedule(&local->sta_tx_exc_tasklet);
2380 if (txdesc.sw_support)
2381 hostap_tx_callback(local, &txdesc, 0, payload);
2387 PDEBUG(DEBUG_EXTRA, "%s: TXEXC - status=0x%04x (%s%s%s%s)"
2388 " tx_control=%04x\n",
2390 status & HFA384X_TX_STATUS_RETRYERR ? "[RetryErr]" : "",
2391 status & HFA384X_TX_STATUS_AGEDERR ? "[AgedErr]" : "",
2392 status & HFA384X_TX_STATUS_DISCON ? "[Discon]" : "",
2393 status & HFA384X_TX_STATUS_FORMERR ? "[FormErr]" : "",
2394 le16_to_cpu(txdesc.tx_control));
2396 fc = le16_to_cpu(txdesc.frame_control);
2397 PDEBUG(DEBUG_EXTRA, " retry_count=%d tx_rate=%d fc=0x%04x "
2398 "(%s%s%s::%d%s%s)\n",
2399 txdesc.retry_count, txdesc.tx_rate, fc,
2400 WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_MGMT ? "Mgmt" : "",
2401 WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_CTL ? "Ctrl" : "",
2402 WLAN_FC_GET_TYPE(fc) == IEEE80211_FTYPE_DATA ? "Data" : "",
2403 WLAN_FC_GET_STYPE(fc) >> 4,
2404 fc & IEEE80211_FCTL_TODS ? " ToDS" : "",
2405 fc & IEEE80211_FCTL_FROMDS ? " FromDS" : "");
2406 PDEBUG(DEBUG_EXTRA, " A1=" MACSTR " A2=" MACSTR " A3="
2407 MACSTR " A4=" MACSTR "\n",
2408 MAC2STR(txdesc.addr1), MAC2STR(txdesc.addr2),
2409 MAC2STR(txdesc.addr3), MAC2STR(txdesc.addr4));
2413 /* Called only as a tasklet (software IRQ) */
2414 static void hostap_info_tasklet(unsigned long data)
2416 local_info_t *local = (local_info_t *) data;
2417 struct sk_buff *skb;
2419 while ((skb = skb_dequeue(&local->info_list)) != NULL) {
2420 hostap_info_process(local, skb);
2426 /* Called only as a tasklet (software IRQ) */
2427 static void prism2_info(local_info_t *local)
2429 struct net_device *dev = local->dev;
2432 struct hfa384x_info_frame info;
2433 struct sk_buff *skb;
2435 fid = HFA384X_INW(HFA384X_INFOFID_OFF);
2437 spin_lock(&local->baplock);
2438 res = hfa384x_setup_bap(dev, BAP0, fid, 0);
2440 res = hfa384x_from_bap(dev, BAP0, &info, sizeof(info));
2442 spin_unlock(&local->baplock);
2443 printk(KERN_DEBUG "Could not get info frame (fid=0x%04x)\n",
2445 if (res == -ETIMEDOUT) {
2446 schedule_work(&local->reset_queue);
2451 le16_to_cpus(&info.len);
2452 le16_to_cpus(&info.type);
2453 left = (info.len - 1) * 2;
2455 if (info.len & 0x8000 || info.len == 0 || left > 2060) {
2456 /* data register seems to give 0x8000 in some error cases even
2457 * though busy bit is not set in offset register;
2458 * in addition, length must be at least 1 due to type field */
2459 spin_unlock(&local->baplock);
2460 printk(KERN_DEBUG "%s: Received info frame with invalid "
2461 "length 0x%04x (type 0x%04x)\n", dev->name, info.len,
2466 skb = dev_alloc_skb(sizeof(info) + left);
2468 spin_unlock(&local->baplock);
2469 printk(KERN_DEBUG "%s: Could not allocate skb for info "
2470 "frame\n", dev->name);
2474 memcpy(skb_put(skb, sizeof(info)), &info, sizeof(info));
2475 if (left > 0 && hfa384x_from_bap(dev, BAP0, skb_put(skb, left), left))
2477 spin_unlock(&local->baplock);
2478 printk(KERN_WARNING "%s: Info frame read failed (fid=0x%04x, "
2479 "len=0x%04x, type=0x%04x\n",
2480 dev->name, fid, info.len, info.type);
2484 spin_unlock(&local->baplock);
2486 skb_queue_tail(&local->info_list, skb);
2487 tasklet_schedule(&local->info_tasklet);
2490 HFA384X_OUTW(HFA384X_EV_INFO, HFA384X_EVACK_OFF);
2494 /* Called only as a tasklet (software IRQ) */
2495 static void hostap_bap_tasklet(unsigned long data)
2497 local_info_t *local = (local_info_t *) data;
2498 struct net_device *dev = local->dev;
2502 if (local->func->card_present && !local->func->card_present(local))
2505 set_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits);
2507 /* Process all pending BAP events without generating new interrupts
2509 while (frames-- > 0) {
2510 ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
2511 if (ev == 0xffff || !(ev & HFA384X_BAP0_EVENTS))
2513 if (ev & HFA384X_EV_RX)
2515 if (ev & HFA384X_EV_INFO)
2517 if (ev & HFA384X_EV_TX)
2518 prism2_tx_ev(local);
2519 if (ev & HFA384X_EV_TXEXC)
2520 prism2_txexc(local);
2523 set_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits);
2524 clear_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits);
2526 /* Enable interrupts for new BAP events */
2527 hfa384x_events_all(dev);
2528 clear_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits);
2532 /* Called only from hardware IRQ */
2533 static void prism2_infdrop(struct net_device *dev)
2535 static unsigned long last_inquire = 0;
2537 PDEBUG(DEBUG_EXTRA, "%s: INFDROP event\n", dev->name);
2539 /* some firmware versions seem to get stuck with
2540 * full CommTallies in high traffic load cases; every
2541 * packet will then cause INFDROP event and CommTallies
2542 * info frame will not be sent automatically. Try to
2543 * get out of this state by inquiring CommTallies. */
2544 if (!last_inquire || time_after(jiffies, last_inquire + HZ)) {
2545 hfa384x_cmd_callback(dev, HFA384X_CMDCODE_INQUIRE,
2546 HFA384X_INFO_COMMTALLIES, NULL, 0);
2547 last_inquire = jiffies;
2552 /* Called only from hardware IRQ */
2553 static void prism2_ev_tick(struct net_device *dev)
2555 struct hostap_interface *iface;
2556 local_info_t *local;
2558 static int prev_stuck = 0;
2560 iface = netdev_priv(dev);
2561 local = iface->local;
2563 if (time_after(jiffies, local->last_tick_timer + 5 * HZ) &&
2564 local->last_tick_timer) {
2565 evstat = HFA384X_INW(HFA384X_EVSTAT_OFF);
2566 inten = HFA384X_INW(HFA384X_INTEN_OFF);
2568 printk(KERN_INFO "%s: SW TICK stuck? "
2569 "bits=0x%lx EvStat=%04x IntEn=%04x\n",
2570 dev->name, local->bits, evstat, inten);
2572 local->sw_tick_stuck++;
2573 if ((evstat & HFA384X_BAP0_EVENTS) &&
2574 (inten & HFA384X_BAP0_EVENTS)) {
2575 printk(KERN_INFO "%s: trying to recover from IRQ "
2576 "hang\n", dev->name);
2577 hfa384x_events_no_bap0(dev);
2585 /* Called only from hardware IRQ */
2586 static void prism2_check_magic(local_info_t *local)
2588 /* at least PCI Prism2.5 with bus mastering seems to sometimes
2589 * return 0x0000 in SWSUPPORT0 for unknown reason, but re-reading the
2590 * register once or twice seems to get the correct value.. PCI cards
2591 * cannot anyway be removed during normal operation, so there is not
2592 * really any need for this verification with them. */
2595 #ifndef final_version
2596 static unsigned long last_magic_err = 0;
2597 struct net_device *dev = local->dev;
2599 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) {
2600 if (!local->hw_ready)
2602 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
2603 if (time_after(jiffies, last_magic_err + 10 * HZ)) {
2604 printk("%s: Interrupt, but SWSUPPORT0 does not match: "
2605 "%04X != %04X - card removed?\n", dev->name,
2606 HFA384X_INW(HFA384X_SWSUPPORT0_OFF),
2608 last_magic_err = jiffies;
2609 } else if (net_ratelimit()) {
2610 printk(KERN_DEBUG "%s: interrupt - SWSUPPORT0=%04x "
2611 "MAGIC=%04x\n", dev->name,
2612 HFA384X_INW(HFA384X_SWSUPPORT0_OFF),
2615 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != 0xffff)
2616 schedule_work(&local->reset_queue);
2619 #endif /* final_version */
2620 #endif /* !PRISM2_PCI */
2624 /* Called only from hardware IRQ */
2625 static irqreturn_t prism2_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2627 struct net_device *dev = (struct net_device *) dev_id;
2628 struct hostap_interface *iface;
2629 local_info_t *local;
2633 iface = netdev_priv(dev);
2634 local = iface->local;
2636 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 0);
2638 if (local->func->card_present && !local->func->card_present(local)) {
2639 if (net_ratelimit()) {
2640 printk(KERN_DEBUG "%s: Interrupt, but dev not OK\n",
2646 prism2_check_magic(local);
2649 ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
2651 if (local->shutdown)
2653 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
2654 printk(KERN_DEBUG "%s: prism2_interrupt: ev=0xffff\n",
2659 ev &= HFA384X_INW(HFA384X_INTEN_OFF);
2663 if (ev & HFA384X_EV_CMD) {
2667 /* Above events are needed even before hw is ready, but other
2668 * events should be skipped during initialization. This may
2669 * change for AllocEv if allocate_fid is implemented without
2671 if (!local->hw_ready || local->hw_resetting ||
2672 !local->dev_enabled) {
2673 ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
2674 if (ev & HFA384X_EV_CMD)
2676 if ((ev & HFA384X_EVENT_MASK) == 0)
2678 if (local->dev_enabled && (ev & ~HFA384X_EV_TICK) &&
2680 printk(KERN_DEBUG "%s: prism2_interrupt: hw "
2681 "not ready; skipping events 0x%04x "
2682 "(IntEn=0x%04x)%s%s%s\n",
2684 HFA384X_INW(HFA384X_INTEN_OFF),
2685 !local->hw_ready ? " (!hw_ready)" : "",
2686 local->hw_resetting ?
2687 " (hw_resetting)" : "",
2688 !local->dev_enabled ?
2689 " (!dev_enabled)" : "");
2691 HFA384X_OUTW(ev, HFA384X_EVACK_OFF);
2695 if (ev & HFA384X_EV_TICK) {
2696 prism2_ev_tick(dev);
2697 HFA384X_OUTW(HFA384X_EV_TICK, HFA384X_EVACK_OFF);
2700 if (ev & HFA384X_EV_ALLOC) {
2701 prism2_alloc_ev(dev);
2702 HFA384X_OUTW(HFA384X_EV_ALLOC, HFA384X_EVACK_OFF);
2705 /* Reading data from the card is quite time consuming, so do it
2706 * in tasklets. TX, TXEXC, RX, and INFO events will be ACKed
2707 * and unmasked after needed data has been read completely. */
2708 if (ev & HFA384X_BAP0_EVENTS) {
2709 hfa384x_events_no_bap0(dev);
2710 tasklet_schedule(&local->bap_tasklet);
2713 #ifndef final_version
2714 if (ev & HFA384X_EV_WTERR) {
2715 PDEBUG(DEBUG_EXTRA, "%s: WTERR event\n", dev->name);
2716 HFA384X_OUTW(HFA384X_EV_WTERR, HFA384X_EVACK_OFF);
2718 #endif /* final_version */
2720 if (ev & HFA384X_EV_INFDROP) {
2721 prism2_infdrop(dev);
2722 HFA384X_OUTW(HFA384X_EV_INFDROP, HFA384X_EVACK_OFF);
2727 if (events >= PRISM2_MAX_INTERRUPT_EVENTS) {
2728 PDEBUG(DEBUG_EXTRA, "prism2_interrupt: >%d events "
2729 "(EvStat=0x%04x)\n",
2730 PRISM2_MAX_INTERRUPT_EVENTS,
2731 HFA384X_INW(HFA384X_EVSTAT_OFF));
2735 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 1);
2736 return IRQ_RETVAL(events);
2740 static void prism2_check_sta_fw_version(local_info_t *local)
2742 struct hfa384x_comp_ident comp;
2743 int id, variant, major, minor;
2745 if (hfa384x_get_rid(local->dev, HFA384X_RID_STAID,
2746 &comp, sizeof(comp), 1) < 0)
2750 id = le16_to_cpu(comp.id);
2751 if (id != HFA384X_COMP_ID_STA) {
2752 if (id == HFA384X_COMP_ID_FW_AP)
2757 major = __le16_to_cpu(comp.major);
2758 minor = __le16_to_cpu(comp.minor);
2759 variant = __le16_to_cpu(comp.variant);
2760 local->sta_fw_ver = PRISM2_FW_VER(major, minor, variant);
2762 /* Station firmware versions before 1.4.x seem to have a bug in
2763 * firmware-based WEP encryption when using Host AP mode, so use
2764 * host_encrypt as a default for them. Firmware version 1.4.9 is the
2765 * first one that has been seen to produce correct encryption, but the
2766 * bug might be fixed before that (although, at least 1.4.2 is broken).
2768 local->fw_encrypt_ok = local->sta_fw_ver >= PRISM2_FW_VER(1,4,9);
2770 if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
2771 !local->fw_encrypt_ok) {
2772 printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
2773 "a workaround for firmware bug in Host AP mode WEP\n",
2775 local->host_encrypt = 1;
2778 /* IEEE 802.11 standard compliant WDS frames (4 addresses) were broken
2779 * in station firmware versions before 1.5.x. With these versions, the
2780 * driver uses a workaround with bogus frame format (4th address after
2781 * the payload). This is not compatible with other AP devices. Since
2782 * the firmware bug is fixed in the latest station firmware versions,
2783 * automatically enable standard compliant mode for cards using station
2784 * firmware version 1.5.0 or newer. */
2785 if (local->sta_fw_ver >= PRISM2_FW_VER(1,5,0))
2786 local->wds_type |= HOSTAP_WDS_STANDARD_FRAME;
2788 printk(KERN_DEBUG "%s: defaulting to bogus WDS frame as a "
2789 "workaround for firmware bug in Host AP mode WDS\n",
2793 hostap_check_sta_fw_version(local->ap, local->sta_fw_ver);
2797 static void prism2_crypt_deinit_entries(local_info_t *local, int force)
2799 struct list_head *ptr, *n;
2800 struct ieee80211_crypt_data *entry;
2802 for (ptr = local->crypt_deinit_list.next, n = ptr->next;
2803 ptr != &local->crypt_deinit_list; ptr = n, n = ptr->next) {
2804 entry = list_entry(ptr, struct ieee80211_crypt_data, list);
2806 if (atomic_read(&entry->refcnt) != 0 && !force)
2812 entry->ops->deinit(entry->priv);
2818 static void prism2_crypt_deinit_handler(unsigned long data)
2820 local_info_t *local = (local_info_t *) data;
2821 unsigned long flags;
2823 spin_lock_irqsave(&local->lock, flags);
2824 prism2_crypt_deinit_entries(local, 0);
2825 if (!list_empty(&local->crypt_deinit_list)) {
2826 printk(KERN_DEBUG "%s: entries remaining in delayed crypt "
2827 "deletion list\n", local->dev->name);
2828 local->crypt_deinit_timer.expires = jiffies + HZ;
2829 add_timer(&local->crypt_deinit_timer);
2831 spin_unlock_irqrestore(&local->lock, flags);
2836 static void hostap_passive_scan(unsigned long data)
2838 local_info_t *local = (local_info_t *) data;
2839 struct net_device *dev = local->dev;
2842 if (local->passive_scan_interval <= 0)
2845 if (local->passive_scan_state == PASSIVE_SCAN_LISTEN) {
2848 /* Even though host system does not really know when the WLAN
2849 * MAC is sending frames, try to avoid changing channels for
2850 * passive scanning when a host-generated frame is being
2852 if (test_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
2853 printk(KERN_DEBUG "%s: passive scan detected pending "
2854 "TX - delaying\n", dev->name);
2855 local->passive_scan_timer.expires = jiffies + HZ / 10;
2856 add_timer(&local->passive_scan_timer);
2861 local->passive_scan_channel++;
2862 if (local->passive_scan_channel > 14)
2863 local->passive_scan_channel = 1;
2865 } while (!(local->channel_mask &
2866 (1 << (local->passive_scan_channel - 1))) &&
2869 if (max_tries == 0) {
2870 printk(KERN_INFO "%s: no allowed passive scan channels"
2871 " found\n", dev->name);
2875 printk(KERN_DEBUG "%s: passive scan channel %d\n",
2876 dev->name, local->passive_scan_channel);
2877 channel = local->passive_scan_channel;
2878 local->passive_scan_state = PASSIVE_SCAN_WAIT;
2879 local->passive_scan_timer.expires = jiffies + HZ / 10;
2881 channel = local->channel;
2882 local->passive_scan_state = PASSIVE_SCAN_LISTEN;
2883 local->passive_scan_timer.expires = jiffies +
2884 local->passive_scan_interval * HZ;
2887 if (hfa384x_cmd_callback(dev, HFA384X_CMDCODE_TEST |
2888 (HFA384X_TEST_CHANGE_CHANNEL << 8),
2890 printk(KERN_ERR "%s: passive scan channel set %d "
2891 "failed\n", dev->name, channel);
2893 add_timer(&local->passive_scan_timer);
2897 /* Called only as a scheduled task when communications quality values should
2899 static void handle_comms_qual_update(void *data)
2901 local_info_t *local = data;
2902 prism2_update_comms_qual(local->dev);
2906 /* Software watchdog - called as a timer. Hardware interrupt (Tick event) is
2907 * used to monitor that local->last_tick_timer is being updated. If not,
2908 * interrupt busy-loop is assumed and driver tries to recover by masking out
2910 static void hostap_tick_timer(unsigned long data)
2912 static unsigned long last_inquire = 0;
2913 local_info_t *local = (local_info_t *) data;
2914 local->last_tick_timer = jiffies;
2916 /* Inquire CommTallies every 10 seconds to keep the statistics updated
2917 * more often during low load and when using 32-bit tallies. */
2918 if ((!last_inquire || time_after(jiffies, last_inquire + 10 * HZ)) &&
2919 !local->hw_downloading && local->hw_ready &&
2920 !local->hw_resetting && local->dev_enabled) {
2921 hfa384x_cmd_callback(local->dev, HFA384X_CMDCODE_INQUIRE,
2922 HFA384X_INFO_COMMTALLIES, NULL, 0);
2923 last_inquire = jiffies;
2926 if ((local->last_comms_qual_update == 0 ||
2927 time_after(jiffies, local->last_comms_qual_update + 10 * HZ)) &&
2928 (local->iw_mode == IW_MODE_INFRA ||
2929 local->iw_mode == IW_MODE_ADHOC)) {
2930 schedule_work(&local->comms_qual_update);
2933 local->tick_timer.expires = jiffies + 2 * HZ;
2934 add_timer(&local->tick_timer);
2938 #ifndef PRISM2_NO_PROCFS_DEBUG
2939 static int prism2_registers_proc_read(char *page, char **start, off_t off,
2940 int count, int *eof, void *data)
2943 local_info_t *local = (local_info_t *) data;
2950 #define SHOW_REG(n) \
2951 p += sprintf(p, #n "=%04x\n", hfa384x_read_reg(local->dev, HFA384X_##n##_OFF))
2969 SHOW_REG(TXCOMPLFID);
2970 SHOW_REG(SWSUPPORT0);
2971 SHOW_REG(SWSUPPORT1);
2972 SHOW_REG(SWSUPPORT2);
2976 /* Do not read data registers, because they change the state of the
2977 * MAC (offset += 2) */
2978 /* SHOW_REG(DATA0); */
2979 /* SHOW_REG(DATA1); */
2981 SHOW_REG(AUXOFFSET);
2982 /* SHOW_REG(AUXDATA); */
2986 SHOW_REG(PCI_M0_ADDRH);
2987 SHOW_REG(PCI_M0_ADDRL);
2988 SHOW_REG(PCI_M0_LEN);
2989 SHOW_REG(PCI_M0_CTL);
2990 SHOW_REG(PCI_STATUS);
2991 SHOW_REG(PCI_M1_ADDRH);
2992 SHOW_REG(PCI_M1_ADDRL);
2993 SHOW_REG(PCI_M1_LEN);
2994 SHOW_REG(PCI_M1_CTL);
2995 #endif /* PRISM2_PCI */
2999 #endif /* PRISM2_NO_PROCFS_DEBUG */
3002 struct set_tim_data {
3003 struct list_head list;
3008 static int prism2_set_tim(struct net_device *dev, int aid, int set)
3010 struct list_head *ptr;
3011 struct set_tim_data *new_entry;
3012 struct hostap_interface *iface;
3013 local_info_t *local;
3015 iface = netdev_priv(dev);
3016 local = iface->local;
3018 new_entry = (struct set_tim_data *)
3019 kmalloc(sizeof(*new_entry), GFP_ATOMIC);
3020 if (new_entry == NULL) {
3021 printk(KERN_DEBUG "%s: prism2_set_tim: kmalloc failed\n",
3025 memset(new_entry, 0, sizeof(*new_entry));
3026 new_entry->aid = aid;
3027 new_entry->set = set;
3029 spin_lock_bh(&local->set_tim_lock);
3030 list_for_each(ptr, &local->set_tim_list) {
3031 struct set_tim_data *entry =
3032 list_entry(ptr, struct set_tim_data, list);
3033 if (entry->aid == aid) {
3034 PDEBUG(DEBUG_PS2, "%s: prism2_set_tim: aid=%d "
3036 local->dev->name, aid, entry->set, set);
3044 list_add_tail(&new_entry->list, &local->set_tim_list);
3045 spin_unlock_bh(&local->set_tim_lock);
3047 schedule_work(&local->set_tim_queue);
3053 static void handle_set_tim_queue(void *data)
3055 local_info_t *local = (local_info_t *) data;
3056 struct set_tim_data *entry;
3061 spin_lock_bh(&local->set_tim_lock);
3062 if (!list_empty(&local->set_tim_list)) {
3063 entry = list_entry(local->set_tim_list.next,
3064 struct set_tim_data, list);
3065 list_del(&entry->list);
3067 spin_unlock_bh(&local->set_tim_lock);
3071 PDEBUG(DEBUG_PS2, "%s: handle_set_tim_queue: aid=%d set=%d\n",
3072 local->dev->name, entry->aid, entry->set);
3077 if (hostap_set_word(local->dev, HFA384X_RID_CNFTIMCTRL, val)) {
3078 printk(KERN_DEBUG "%s: set_tim failed (aid=%d "
3080 local->dev->name, entry->aid, entry->set);
3088 static void prism2_clear_set_tim_queue(local_info_t *local)
3090 struct list_head *ptr, *n;
3092 list_for_each_safe(ptr, n, &local->set_tim_list) {
3093 struct set_tim_data *entry;
3094 entry = list_entry(ptr, struct set_tim_data, list);
3095 list_del(&entry->list);
3102 * HostAP uses two layers of net devices, where the inner
3103 * layer gets called all the time from the outer layer.
3104 * This is a natural nesting, which needs a split lock type.
3106 static struct lock_class_key hostap_netdev_xmit_lock_key;
3109 static struct net_device *
3110 prism2_init_local_data(struct prism2_helper_functions *funcs, int card_idx,
3111 struct device *sdev)
3113 struct net_device *dev;
3114 struct hostap_interface *iface;
3115 struct local_info *local;
3121 len = strlen(dev_template);
3122 if (len >= IFNAMSIZ || strstr(dev_template, "%d") == NULL) {
3123 printk(KERN_WARNING "hostap: Invalid dev_template='%s'\n",
3128 len = sizeof(struct hostap_interface) +
3129 3 + sizeof(struct local_info) +
3130 3 + sizeof(struct ap_data);
3132 dev = alloc_etherdev(len);
3136 iface = netdev_priv(dev);
3137 local = (struct local_info *) ((((long) (iface + 1)) + 3) & ~3);
3138 local->ap = (struct ap_data *) ((((long) (local + 1)) + 3) & ~3);
3139 local->dev = iface->dev = dev;
3140 iface->local = local;
3141 iface->type = HOSTAP_INTERFACE_MASTER;
3142 INIT_LIST_HEAD(&local->hostap_interfaces);
3144 local->hw_module = THIS_MODULE;
3146 #ifdef PRISM2_IO_DEBUG
3147 local->io_debug_enabled = 1;
3148 #endif /* PRISM2_IO_DEBUG */
3150 local->func = funcs;
3151 local->func->cmd = hfa384x_cmd;
3152 local->func->read_regs = hfa384x_read_regs;
3153 local->func->get_rid = hfa384x_get_rid;
3154 local->func->set_rid = hfa384x_set_rid;
3155 local->func->hw_enable = prism2_hw_enable;
3156 local->func->hw_config = prism2_hw_config;
3157 local->func->hw_reset = prism2_hw_reset;
3158 local->func->hw_shutdown = prism2_hw_shutdown;
3159 local->func->reset_port = prism2_reset_port;
3160 local->func->schedule_reset = prism2_schedule_reset;
3161 #ifdef PRISM2_DOWNLOAD_SUPPORT
3162 local->func->read_aux = prism2_download_aux_dump;
3163 local->func->download = prism2_download;
3164 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3165 local->func->tx = prism2_tx_80211;
3166 local->func->set_tim = prism2_set_tim;
3167 local->func->need_tx_headroom = 0; /* no need to add txdesc in
3168 * skb->data (FIX: maybe for DMA bus
3173 rwlock_init(&local->iface_lock);
3174 spin_lock_init(&local->txfidlock);
3175 spin_lock_init(&local->cmdlock);
3176 spin_lock_init(&local->baplock);
3177 spin_lock_init(&local->lock);
3178 init_MUTEX(&local->rid_bap_sem);
3180 if (card_idx < 0 || card_idx >= MAX_PARM_DEVICES)
3182 local->card_idx = card_idx;
3184 len = strlen(essid);
3185 memcpy(local->essid, essid,
3186 len > MAX_SSID_LEN ? MAX_SSID_LEN : len);
3187 local->essid[MAX_SSID_LEN] = '\0';
3188 i = GET_INT_PARM(iw_mode, card_idx);
3189 if ((i >= IW_MODE_ADHOC && i <= IW_MODE_REPEAT) ||
3190 i == IW_MODE_MONITOR) {
3193 printk(KERN_WARNING "prism2: Unknown iw_mode %d; using "
3194 "IW_MODE_MASTER\n", i);
3195 local->iw_mode = IW_MODE_MASTER;
3197 local->channel = GET_INT_PARM(channel, card_idx);
3198 local->beacon_int = GET_INT_PARM(beacon_int, card_idx);
3199 local->dtim_period = GET_INT_PARM(dtim_period, card_idx);
3200 local->wds_max_connections = 16;
3201 local->tx_control = HFA384X_TX_CTRL_FLAGS;
3202 local->manual_retry_count = -1;
3203 local->rts_threshold = 2347;
3204 local->fragm_threshold = 2346;
3205 local->rssi_to_dBm = 100; /* default; to be overriden by
3206 * cnfDbmAdjust, if available */
3207 local->auth_algs = PRISM2_AUTH_OPEN | PRISM2_AUTH_SHARED_KEY;
3208 local->sram_type = -1;
3209 local->scan_channel_mask = 0xffff;
3211 /* Initialize task queue structures */
3212 INIT_WORK(&local->reset_queue, handle_reset_queue, local);
3213 INIT_WORK(&local->set_multicast_list_queue,
3214 hostap_set_multicast_list_queue, local->dev);
3216 INIT_WORK(&local->set_tim_queue, handle_set_tim_queue, local);
3217 INIT_LIST_HEAD(&local->set_tim_list);
3218 spin_lock_init(&local->set_tim_lock);
3220 INIT_WORK(&local->comms_qual_update, handle_comms_qual_update, local);
3222 /* Initialize tasklets for handling hardware IRQ related operations
3223 * outside hw IRQ handler */
3224 #define HOSTAP_TASKLET_INIT(q, f, d) \
3225 do { memset((q), 0, sizeof(*(q))); (q)->func = (f); (q)->data = (d); } \
3227 HOSTAP_TASKLET_INIT(&local->bap_tasklet, hostap_bap_tasklet,
3228 (unsigned long) local);
3230 HOSTAP_TASKLET_INIT(&local->info_tasklet, hostap_info_tasklet,
3231 (unsigned long) local);
3232 hostap_info_init(local);
3234 HOSTAP_TASKLET_INIT(&local->rx_tasklet,
3235 hostap_rx_tasklet, (unsigned long) local);
3236 skb_queue_head_init(&local->rx_list);
3238 HOSTAP_TASKLET_INIT(&local->sta_tx_exc_tasklet,
3239 hostap_sta_tx_exc_tasklet, (unsigned long) local);
3240 skb_queue_head_init(&local->sta_tx_exc_list);
3242 INIT_LIST_HEAD(&local->cmd_queue);
3243 init_waitqueue_head(&local->hostscan_wq);
3244 INIT_LIST_HEAD(&local->crypt_deinit_list);
3245 init_timer(&local->crypt_deinit_timer);
3246 local->crypt_deinit_timer.data = (unsigned long) local;
3247 local->crypt_deinit_timer.function = prism2_crypt_deinit_handler;
3249 init_timer(&local->passive_scan_timer);
3250 local->passive_scan_timer.data = (unsigned long) local;
3251 local->passive_scan_timer.function = hostap_passive_scan;
3253 init_timer(&local->tick_timer);
3254 local->tick_timer.data = (unsigned long) local;
3255 local->tick_timer.function = hostap_tick_timer;
3256 local->tick_timer.expires = jiffies + 2 * HZ;
3257 add_timer(&local->tick_timer);
3259 INIT_LIST_HEAD(&local->bss_list);
3261 hostap_setup_dev(dev, local, 1);
3262 local->saved_eth_header_parse = dev->hard_header_parse;
3264 dev->hard_start_xmit = hostap_master_start_xmit;
3265 dev->type = ARPHRD_IEEE80211;
3266 dev->hard_header_parse = hostap_80211_header_parse;
3269 ret = dev_alloc_name(dev, "wifi%d");
3270 SET_NETDEV_DEV(dev, sdev);
3272 ret = register_netdevice(dev);
3274 lockdep_set_class(&dev->_xmit_lock, &hostap_netdev_xmit_lock_key);
3277 printk(KERN_WARNING "%s: register netdevice failed!\n",
3281 printk(KERN_INFO "%s: Registered netdevice %s\n", dev_info, dev->name);
3283 #ifndef PRISM2_NO_PROCFS_DEBUG
3284 create_proc_read_entry("registers", 0, local->proc,
3285 prism2_registers_proc_read, local);
3286 #endif /* PRISM2_NO_PROCFS_DEBUG */
3288 hostap_init_data(local);
3297 static int hostap_hw_ready(struct net_device *dev)
3299 struct hostap_interface *iface;
3300 struct local_info *local;
3302 iface = netdev_priv(dev);
3303 local = iface->local;
3304 local->ddev = hostap_add_interface(local, HOSTAP_INTERFACE_MAIN, 0,
3308 if (local->iw_mode == IW_MODE_INFRA ||
3309 local->iw_mode == IW_MODE_ADHOC) {
3310 netif_carrier_off(local->dev);
3311 netif_carrier_off(local->ddev);
3313 hostap_init_proc(local);
3314 hostap_init_ap_proc(local);
3322 static void prism2_free_local_data(struct net_device *dev)
3324 struct hostap_tx_callback_info *tx_cb, *tx_cb_prev;
3326 struct hostap_interface *iface;
3327 struct local_info *local;
3328 struct list_head *ptr, *n;
3333 iface = netdev_priv(dev);
3334 local = iface->local;
3336 /* Unregister all netdevs before freeing local data. */
3337 list_for_each_safe(ptr, n, &local->hostap_interfaces) {
3338 iface = list_entry(ptr, struct hostap_interface, list);
3339 if (iface->type == HOSTAP_INTERFACE_MASTER) {
3340 /* special handling for this interface below */
3343 hostap_remove_interface(iface->dev, 0, 1);
3346 unregister_netdev(local->dev);
3348 flush_scheduled_work();
3350 if (timer_pending(&local->crypt_deinit_timer))
3351 del_timer(&local->crypt_deinit_timer);
3352 prism2_crypt_deinit_entries(local, 1);
3354 if (timer_pending(&local->passive_scan_timer))
3355 del_timer(&local->passive_scan_timer);
3357 if (timer_pending(&local->tick_timer))
3358 del_timer(&local->tick_timer);
3360 prism2_clear_cmd_queue(local);
3362 skb_queue_purge(&local->info_list);
3363 skb_queue_purge(&local->rx_list);
3364 skb_queue_purge(&local->sta_tx_exc_list);
3366 if (local->dev_enabled)
3367 prism2_callback(local, PRISM2_CALLBACK_DISABLE);
3369 for (i = 0; i < WEP_KEYS; i++) {
3370 struct ieee80211_crypt_data *crypt = local->crypt[i];
3373 crypt->ops->deinit(crypt->priv);
3375 local->crypt[i] = NULL;
3379 if (local->ap != NULL)
3380 hostap_free_data(local->ap);
3382 #ifndef PRISM2_NO_PROCFS_DEBUG
3383 if (local->proc != NULL)
3384 remove_proc_entry("registers", local->proc);
3385 #endif /* PRISM2_NO_PROCFS_DEBUG */
3386 hostap_remove_proc(local);
3388 tx_cb = local->tx_callback;
3389 while (tx_cb != NULL) {
3391 tx_cb = tx_cb->next;
3395 hostap_set_hostapd(local, 0, 0);
3396 hostap_set_hostapd_sta(local, 0, 0);
3398 for (i = 0; i < PRISM2_FRAG_CACHE_LEN; i++) {
3399 if (local->frag_cache[i].skb != NULL)
3400 dev_kfree_skb(local->frag_cache[i].skb);
3403 #ifdef PRISM2_DOWNLOAD_SUPPORT
3404 prism2_download_free_data(local->dl_pri);
3405 prism2_download_free_data(local->dl_sec);
3406 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3408 prism2_clear_set_tim_queue(local);
3410 list_for_each_safe(ptr, n, &local->bss_list) {
3411 struct hostap_bss_info *bss =
3412 list_entry(ptr, struct hostap_bss_info, list);
3417 kfree(local->last_scan_results);
3418 kfree(local->generic_elem);
3420 free_netdev(local->dev);
3425 static void prism2_suspend(struct net_device *dev)
3427 struct hostap_interface *iface;
3428 struct local_info *local;
3429 union iwreq_data wrqu;
3432 local = iface->local;
3434 /* Send disconnect event, e.g., to trigger reassociation after resume
3435 * if wpa_supplicant is used. */
3436 memset(&wrqu, 0, sizeof(wrqu));
3437 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3438 wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL);
3440 /* Disable hardware and firmware */
3441 prism2_hw_shutdown(dev, 0);
3443 #endif /* PRISM2_PLX */
3446 /* These might at some point be compiled separately and used as separate
3447 * kernel modules or linked into one */
3448 #ifdef PRISM2_DOWNLOAD_SUPPORT
3449 #include "hostap_download.c"
3450 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3452 #ifdef PRISM2_CALLBACK
3453 /* External hostap_callback.c file can be used to, e.g., blink activity led.
3454 * This can use platform specific code and must define prism2_callback()
3455 * function (if PRISM2_CALLBACK is not defined, these function calls are not
3457 #include "hostap_callback.c"
3458 #endif /* PRISM2_CALLBACK */