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 <j@w1.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/lib80211.h>
52 #include "hostap_80211.h"
54 #include "hostap_ap.h"
57 /* #define final_version */
59 static int mtu
= 1500;
60 module_param(mtu
, int, 0444);
61 MODULE_PARM_DESC(mtu
, "Maximum transfer unit");
63 static int channel
[MAX_PARM_DEVICES
] = { 3, DEF_INTS
};
64 module_param_array(channel
, int, NULL
, 0444);
65 MODULE_PARM_DESC(channel
, "Initial channel");
67 static char essid
[33] = "test";
68 module_param_string(essid
, essid
, sizeof(essid
), 0444);
69 MODULE_PARM_DESC(essid
, "Host AP's ESSID");
71 static int iw_mode
[MAX_PARM_DEVICES
] = { IW_MODE_MASTER
, DEF_INTS
};
72 module_param_array(iw_mode
, int, NULL
, 0444);
73 MODULE_PARM_DESC(iw_mode
, "Initial operation mode");
75 static int beacon_int
[MAX_PARM_DEVICES
] = { 100, DEF_INTS
};
76 module_param_array(beacon_int
, int, NULL
, 0444);
77 MODULE_PARM_DESC(beacon_int
, "Beacon interval (1 = 1024 usec)");
79 static int dtim_period
[MAX_PARM_DEVICES
] = { 1, DEF_INTS
};
80 module_param_array(dtim_period
, int, NULL
, 0444);
81 MODULE_PARM_DESC(dtim_period
, "DTIM period");
83 static char dev_template
[16] = "wlan%d";
84 module_param_string(dev_template
, dev_template
, sizeof(dev_template
), 0444);
85 MODULE_PARM_DESC(dev_template
, "Prefix for network device name (default: "
89 #define EXTRA_EVENTS_WTERR 0
91 /* check WTERR events (Wait Time-out) in development versions */
92 #define EXTRA_EVENTS_WTERR HFA384X_EV_WTERR
95 /* Events that will be using BAP0 */
96 #define HFA384X_BAP0_EVENTS \
97 (HFA384X_EV_TXEXC | HFA384X_EV_RX | HFA384X_EV_INFO | HFA384X_EV_TX)
99 /* event mask, i.e., events that will result in an interrupt */
100 #define HFA384X_EVENT_MASK \
101 (HFA384X_BAP0_EVENTS | HFA384X_EV_ALLOC | HFA384X_EV_INFDROP | \
102 HFA384X_EV_CMD | HFA384X_EV_TICK | \
105 /* Default TX control flags: use 802.11 headers and request interrupt for
106 * failed transmits. Frames that request ACK callback, will add
107 * _TX_OK flag and _ALT_RTRY flag may be used to select different retry policy.
109 #define HFA384X_TX_CTRL_FLAGS \
110 (HFA384X_TX_CTRL_802_11 | HFA384X_TX_CTRL_TX_EX)
114 #define HFA384X_CMD_BUSY_TIMEOUT 5000
115 #define HFA384X_BAP_BUSY_TIMEOUT 50000
118 #define HFA384X_CMD_COMPL_TIMEOUT 20000
119 #define HFA384X_DL_COMPL_TIMEOUT 1000000
121 /* Wait times for initialization; yield to other processes to avoid busy
122 * waiting for long time. */
123 #define HFA384X_INIT_TIMEOUT (HZ / 2) /* 500 ms */
124 #define HFA384X_ALLOC_COMPL_TIMEOUT (HZ / 20) /* 50 ms */
127 static void prism2_hw_reset(struct net_device
*dev
);
128 static void prism2_check_sta_fw_version(local_info_t
*local
);
130 #ifdef PRISM2_DOWNLOAD_SUPPORT
131 /* hostap_download.c */
132 static int prism2_download_aux_dump(struct net_device
*dev
,
133 unsigned int addr
, int len
, u8
*buf
);
134 static u8
* prism2_read_pda(struct net_device
*dev
);
135 static int prism2_download(local_info_t
*local
,
136 struct prism2_download_param
*param
);
137 static void prism2_download_free_data(struct prism2_download_data
*dl
);
138 static int prism2_download_volatile(local_info_t
*local
,
139 struct prism2_download_data
*param
);
140 static int prism2_download_genesis(local_info_t
*local
,
141 struct prism2_download_data
*param
);
142 static int prism2_get_ram_size(local_info_t
*local
);
143 #endif /* PRISM2_DOWNLOAD_SUPPORT */
148 #ifndef final_version
149 /* magic value written to SWSUPPORT0 reg. for detecting whether card is still
151 #define HFA384X_MAGIC 0x8A32
155 static u16
hfa384x_read_reg(struct net_device
*dev
, u16 reg
)
157 return HFA384X_INW(reg
);
161 static void hfa384x_read_regs(struct net_device
*dev
,
162 struct hfa384x_regs
*regs
)
164 regs
->cmd
= HFA384X_INW(HFA384X_CMD_OFF
);
165 regs
->evstat
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
166 regs
->offset0
= HFA384X_INW(HFA384X_OFFSET0_OFF
);
167 regs
->offset1
= HFA384X_INW(HFA384X_OFFSET1_OFF
);
168 regs
->swsupport0
= HFA384X_INW(HFA384X_SWSUPPORT0_OFF
);
173 * __hostap_cmd_queue_free - Free Prism2 command queue entry (private)
174 * @local: pointer to private Host AP driver data
175 * @entry: Prism2 command queue entry to be freed
176 * @del_req: request the entry to be removed
178 * Internal helper function for freeing Prism2 command queue entries.
179 * Caller must have acquired local->cmdlock before calling this function.
181 static inline void __hostap_cmd_queue_free(local_info_t
*local
,
182 struct hostap_cmd_queue
*entry
,
187 if (!list_empty(&entry
->list
)) {
188 list_del_init(&entry
->list
);
189 local
->cmd_queue_len
--;
193 if (atomic_dec_and_test(&entry
->usecnt
) && entry
->del_req
)
199 * hostap_cmd_queue_free - Free Prism2 command queue entry
200 * @local: pointer to private Host AP driver data
201 * @entry: Prism2 command queue entry to be freed
202 * @del_req: request the entry to be removed
204 * Free a Prism2 command queue entry.
206 static inline void hostap_cmd_queue_free(local_info_t
*local
,
207 struct hostap_cmd_queue
*entry
,
212 spin_lock_irqsave(&local
->cmdlock
, flags
);
213 __hostap_cmd_queue_free(local
, entry
, del_req
);
214 spin_unlock_irqrestore(&local
->cmdlock
, flags
);
219 * prism2_clear_cmd_queue - Free all pending Prism2 command queue entries
220 * @local: pointer to private Host AP driver data
222 static void prism2_clear_cmd_queue(local_info_t
*local
)
224 struct list_head
*ptr
, *n
;
226 struct hostap_cmd_queue
*entry
;
228 spin_lock_irqsave(&local
->cmdlock
, flags
);
229 list_for_each_safe(ptr
, n
, &local
->cmd_queue
) {
230 entry
= list_entry(ptr
, struct hostap_cmd_queue
, list
);
231 atomic_inc(&entry
->usecnt
);
232 printk(KERN_DEBUG
"%s: removed pending cmd_queue entry "
233 "(type=%d, cmd=0x%04x, param0=0x%04x)\n",
234 local
->dev
->name
, entry
->type
, entry
->cmd
,
236 __hostap_cmd_queue_free(local
, entry
, 1);
238 if (local
->cmd_queue_len
) {
239 /* This should not happen; print debug message and clear
241 printk(KERN_DEBUG
"%s: cmd_queue_len (%d) not zero after "
242 "flush\n", local
->dev
->name
, local
->cmd_queue_len
);
243 local
->cmd_queue_len
= 0;
245 spin_unlock_irqrestore(&local
->cmdlock
, flags
);
250 * hfa384x_cmd_issue - Issue a Prism2 command to the hardware
251 * @dev: pointer to net_device
252 * @entry: Prism2 command queue entry to be issued
254 static int hfa384x_cmd_issue(struct net_device
*dev
,
255 struct hostap_cmd_queue
*entry
)
257 struct hostap_interface
*iface
;
263 iface
= netdev_priv(dev
);
264 local
= iface
->local
;
266 if (local
->func
->card_present
&& !local
->func
->card_present(local
))
270 printk(KERN_DEBUG
"%s: driver bug - re-issuing command @%p\n",
274 /* wait until busy bit is clear; this should always be clear since the
275 * commands are serialized */
276 tries
= HFA384X_CMD_BUSY_TIMEOUT
;
277 while (HFA384X_INW(HFA384X_CMD_OFF
) & HFA384X_CMD_BUSY
&& tries
> 0) {
281 #ifndef final_version
282 if (tries
!= HFA384X_CMD_BUSY_TIMEOUT
) {
283 prism2_io_debug_error(dev
, 1);
284 printk(KERN_DEBUG
"%s: hfa384x_cmd_issue: cmd reg was busy "
285 "for %d usec\n", dev
->name
,
286 HFA384X_CMD_BUSY_TIMEOUT
- tries
);
290 reg
= HFA384X_INW(HFA384X_CMD_OFF
);
291 prism2_io_debug_error(dev
, 2);
292 printk(KERN_DEBUG
"%s: hfa384x_cmd_issue - timeout - "
293 "reg=0x%04x\n", dev
->name
, reg
);
298 spin_lock_irqsave(&local
->cmdlock
, flags
);
299 HFA384X_OUTW(entry
->param0
, HFA384X_PARAM0_OFF
);
300 HFA384X_OUTW(entry
->param1
, HFA384X_PARAM1_OFF
);
301 HFA384X_OUTW(entry
->cmd
, HFA384X_CMD_OFF
);
303 spin_unlock_irqrestore(&local
->cmdlock
, flags
);
310 * hfa384x_cmd - Issue a Prism2 command and wait (sleep) for completion
311 * @dev: pointer to net_device
312 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
313 * @param0: value for Param0 register
314 * @param1: value for Param1 register (pointer; %NULL if not used)
315 * @resp0: pointer for Resp0 data or %NULL if Resp0 is not needed
317 * Issue given command (possibly after waiting in command queue) and sleep
318 * until the command is completed (or timed out or interrupted). This can be
319 * called only from user process context.
321 static int hfa384x_cmd(struct net_device
*dev
, u16 cmd
, u16 param0
,
322 u16
*param1
, u16
*resp0
)
324 struct hostap_interface
*iface
;
326 int err
, res
, issue
, issued
= 0;
328 struct hostap_cmd_queue
*entry
;
329 DECLARE_WAITQUEUE(wait
, current
);
331 iface
= netdev_priv(dev
);
332 local
= iface
->local
;
334 if (in_interrupt()) {
335 printk(KERN_DEBUG
"%s: hfa384x_cmd called from interrupt "
336 "context\n", dev
->name
);
340 if (local
->cmd_queue_len
>= HOSTAP_CMD_QUEUE_MAX_LEN
) {
341 printk(KERN_DEBUG
"%s: hfa384x_cmd: cmd_queue full\n",
346 if (signal_pending(current
))
349 entry
= kzalloc(sizeof(*entry
), GFP_ATOMIC
);
351 printk(KERN_DEBUG
"%s: hfa384x_cmd - kmalloc failed\n",
355 atomic_set(&entry
->usecnt
, 1);
356 entry
->type
= CMD_SLEEP
;
358 entry
->param0
= param0
;
360 entry
->param1
= *param1
;
361 init_waitqueue_head(&entry
->compl);
363 /* prepare to wait for command completion event, but do not sleep yet
365 add_wait_queue(&entry
->compl, &wait
);
366 set_current_state(TASK_INTERRUPTIBLE
);
368 spin_lock_irqsave(&local
->cmdlock
, flags
);
369 issue
= list_empty(&local
->cmd_queue
);
372 list_add_tail(&entry
->list
, &local
->cmd_queue
);
373 local
->cmd_queue_len
++;
374 spin_unlock_irqrestore(&local
->cmdlock
, flags
);
378 goto wait_completion
;
380 if (signal_pending(current
))
384 if (hfa384x_cmd_issue(dev
, entry
))
391 if (!err
&& entry
->type
!= CMD_COMPLETED
) {
392 /* sleep until command is completed or timed out */
393 res
= schedule_timeout(2 * HZ
);
397 if (!err
&& signal_pending(current
))
401 /* the command was issued, so a CmdCompl event should occur
402 * soon; however, there's a pending signal and
403 * schedule_timeout() would be interrupted; wait a short period
404 * of time to avoid removing entry from the list before
409 set_current_state(TASK_RUNNING
);
410 remove_wait_queue(&entry
->compl, &wait
);
412 /* If entry->list is still in the list, it must be removed
413 * first and in this case prism2_cmd_ev() does not yet have
414 * local reference to it, and the data can be kfree()'d
415 * here. If the command completion event is still generated,
416 * it will be assigned to next (possibly) pending command, but
417 * the driver will reset the card anyway due to timeout
419 * If the entry is not in the list prism2_cmd_ev() has a local
420 * reference to it, but keeps cmdlock as long as the data is
421 * needed, so the data can be kfree()'d here. */
423 /* FIX: if the entry->list is in the list, it has not been completed
424 * yet, so removing it here is somewhat wrong.. this could cause
425 * references to freed memory and next list_del() causing NULL pointer
426 * dereference.. it would probably be better to leave the entry in the
427 * list and the list should be emptied during hw reset */
429 spin_lock_irqsave(&local
->cmdlock
, flags
);
430 if (!list_empty(&entry
->list
)) {
431 printk(KERN_DEBUG
"%s: hfa384x_cmd: entry still in list? "
432 "(entry=%p, type=%d, res=%d)\n", dev
->name
, entry
,
434 list_del_init(&entry
->list
);
435 local
->cmd_queue_len
--;
437 spin_unlock_irqrestore(&local
->cmdlock
, flags
);
440 printk(KERN_DEBUG
"%s: hfa384x_cmd: interrupted; err=%d\n",
446 if (entry
->type
!= CMD_COMPLETED
) {
447 u16 reg
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
448 printk(KERN_DEBUG
"%s: hfa384x_cmd: command was not "
449 "completed (res=%d, entry=%p, type=%d, cmd=0x%04x, "
450 "param0=0x%04x, EVSTAT=%04x INTEN=%04x)\n", dev
->name
,
451 res
, entry
, entry
->type
, entry
->cmd
, entry
->param0
, reg
,
452 HFA384X_INW(HFA384X_INTEN_OFF
));
453 if (reg
& HFA384X_EV_CMD
) {
454 /* Command completion event is pending, but the
455 * interrupt was not delivered - probably an issue
456 * with pcmcia-cs configuration. */
457 printk(KERN_WARNING
"%s: interrupt delivery does not "
458 "seem to work\n", dev
->name
);
460 prism2_io_debug_error(dev
, 3);
466 *resp0
= entry
->resp0
;
467 #ifndef final_version
469 printk(KERN_DEBUG
"%s: CMD=0x%04x => res=0x%02x, "
471 dev
->name
, cmd
, entry
->res
, entry
->resp0
);
473 #endif /* final_version */
477 hostap_cmd_queue_free(local
, entry
, 1);
483 * hfa384x_cmd_callback - Issue a Prism2 command; callback when completed
484 * @dev: pointer to net_device
485 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
486 * @param0: value for Param0 register
487 * @callback: command completion callback function (%NULL = no callback)
488 * @context: context data to be given to the callback function
490 * Issue given command (possibly after waiting in command queue) and use
491 * callback function to indicate command completion. This can be called both
492 * from user and interrupt context. The callback function will be called in
493 * hardware IRQ context. It can be %NULL, when no function is called when
494 * command is completed.
496 static int hfa384x_cmd_callback(struct net_device
*dev
, u16 cmd
, u16 param0
,
497 void (*callback
)(struct net_device
*dev
,
498 long context
, u16 resp0
,
502 struct hostap_interface
*iface
;
506 struct hostap_cmd_queue
*entry
;
508 iface
= netdev_priv(dev
);
509 local
= iface
->local
;
511 if (local
->cmd_queue_len
>= HOSTAP_CMD_QUEUE_MAX_LEN
+ 2) {
512 printk(KERN_DEBUG
"%s: hfa384x_cmd: cmd_queue full\n",
517 entry
= kzalloc(sizeof(*entry
), GFP_ATOMIC
);
519 printk(KERN_DEBUG
"%s: hfa384x_cmd_callback - kmalloc "
520 "failed\n", dev
->name
);
523 atomic_set(&entry
->usecnt
, 1);
524 entry
->type
= CMD_CALLBACK
;
526 entry
->param0
= param0
;
527 entry
->callback
= callback
;
528 entry
->context
= context
;
530 spin_lock_irqsave(&local
->cmdlock
, flags
);
531 issue
= list_empty(&local
->cmd_queue
);
534 list_add_tail(&entry
->list
, &local
->cmd_queue
);
535 local
->cmd_queue_len
++;
536 spin_unlock_irqrestore(&local
->cmdlock
, flags
);
538 if (issue
&& hfa384x_cmd_issue(dev
, entry
))
543 hostap_cmd_queue_free(local
, entry
, ret
);
550 * __hfa384x_cmd_no_wait - Issue a Prism2 command (private)
551 * @dev: pointer to net_device
552 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
553 * @param0: value for Param0 register
554 * @io_debug_num: I/O debug error number
556 * Shared helper function for hfa384x_cmd_wait() and hfa384x_cmd_no_wait().
558 static int __hfa384x_cmd_no_wait(struct net_device
*dev
, u16 cmd
, u16 param0
,
564 /* wait until busy bit is clear; this should always be clear since the
565 * commands are serialized */
566 tries
= HFA384X_CMD_BUSY_TIMEOUT
;
567 while (HFA384X_INW(HFA384X_CMD_OFF
) & HFA384X_CMD_BUSY
&& tries
> 0) {
572 reg
= HFA384X_INW(HFA384X_CMD_OFF
);
573 prism2_io_debug_error(dev
, io_debug_num
);
574 printk(KERN_DEBUG
"%s: __hfa384x_cmd_no_wait(%d) - timeout - "
575 "reg=0x%04x\n", dev
->name
, io_debug_num
, reg
);
580 HFA384X_OUTW(param0
, HFA384X_PARAM0_OFF
);
581 HFA384X_OUTW(cmd
, HFA384X_CMD_OFF
);
588 * hfa384x_cmd_wait - Issue a Prism2 command and busy wait for completion
589 * @dev: pointer to net_device
590 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
591 * @param0: value for Param0 register
593 static int hfa384x_cmd_wait(struct net_device
*dev
, u16 cmd
, u16 param0
)
598 res
= __hfa384x_cmd_no_wait(dev
, cmd
, param0
, 4);
602 /* wait for command completion */
603 if ((cmd
& HFA384X_CMDCODE_MASK
) == HFA384X_CMDCODE_DOWNLOAD
)
604 tries
= HFA384X_DL_COMPL_TIMEOUT
;
606 tries
= HFA384X_CMD_COMPL_TIMEOUT
;
608 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_CMD
) &&
614 reg
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
615 prism2_io_debug_error(dev
, 5);
616 printk(KERN_DEBUG
"%s: hfa384x_cmd_wait - timeout2 - "
617 "reg=0x%04x\n", dev
->name
, reg
);
621 res
= (HFA384X_INW(HFA384X_STATUS_OFF
) &
622 (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) | BIT(9) |
624 #ifndef final_version
626 printk(KERN_DEBUG
"%s: CMD=0x%04x => res=0x%02x\n",
627 dev
->name
, cmd
, res
);
631 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_EVACK_OFF
);
638 * hfa384x_cmd_no_wait - Issue a Prism2 command; do not wait for completion
639 * @dev: pointer to net_device
640 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
641 * @param0: value for Param0 register
643 static inline int hfa384x_cmd_no_wait(struct net_device
*dev
, u16 cmd
,
646 return __hfa384x_cmd_no_wait(dev
, cmd
, param0
, 6);
651 * prism2_cmd_ev - Prism2 command completion event handler
652 * @dev: pointer to net_device
654 * Interrupt handler for command completion events. Called by the main
655 * interrupt handler in hardware IRQ context. Read Resp0 and status registers
656 * from the hardware and ACK the event. Depending on the issued command type
657 * either wake up the sleeping process that is waiting for command completion
658 * or call the callback function. Issue the next command, if one is pending.
660 static void prism2_cmd_ev(struct net_device
*dev
)
662 struct hostap_interface
*iface
;
664 struct hostap_cmd_queue
*entry
= NULL
;
666 iface
= netdev_priv(dev
);
667 local
= iface
->local
;
669 spin_lock(&local
->cmdlock
);
670 if (!list_empty(&local
->cmd_queue
)) {
671 entry
= list_entry(local
->cmd_queue
.next
,
672 struct hostap_cmd_queue
, list
);
673 atomic_inc(&entry
->usecnt
);
674 list_del_init(&entry
->list
);
675 local
->cmd_queue_len
--;
677 if (!entry
->issued
) {
678 printk(KERN_DEBUG
"%s: Command completion event, but "
679 "cmd not issued\n", dev
->name
);
680 __hostap_cmd_queue_free(local
, entry
, 1);
684 spin_unlock(&local
->cmdlock
);
687 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_EVACK_OFF
);
688 printk(KERN_DEBUG
"%s: Command completion event, but no "
689 "pending commands\n", dev
->name
);
693 entry
->resp0
= HFA384X_INW(HFA384X_RESP0_OFF
);
694 entry
->res
= (HFA384X_INW(HFA384X_STATUS_OFF
) &
695 (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) |
696 BIT(9) | BIT(8))) >> 8;
697 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_EVACK_OFF
);
699 /* TODO: rest of the CmdEv handling could be moved to tasklet */
700 if (entry
->type
== CMD_SLEEP
) {
701 entry
->type
= CMD_COMPLETED
;
702 wake_up_interruptible(&entry
->compl);
703 } else if (entry
->type
== CMD_CALLBACK
) {
705 entry
->callback(dev
, entry
->context
, entry
->resp0
,
708 printk(KERN_DEBUG
"%s: Invalid command completion type %d\n",
709 dev
->name
, entry
->type
);
711 hostap_cmd_queue_free(local
, entry
, 1);
713 /* issue next command, if pending */
715 spin_lock(&local
->cmdlock
);
716 if (!list_empty(&local
->cmd_queue
)) {
717 entry
= list_entry(local
->cmd_queue
.next
,
718 struct hostap_cmd_queue
, list
);
719 if (entry
->issuing
) {
720 /* hfa384x_cmd() has already started issuing this
721 * command, so do not start here */
725 atomic_inc(&entry
->usecnt
);
727 spin_unlock(&local
->cmdlock
);
730 /* issue next command; if command issuing fails, remove the
731 * entry from cmd_queue */
732 int res
= hfa384x_cmd_issue(dev
, entry
);
733 spin_lock(&local
->cmdlock
);
734 __hostap_cmd_queue_free(local
, entry
, res
);
735 spin_unlock(&local
->cmdlock
);
740 static int hfa384x_wait_offset(struct net_device
*dev
, u16 o_off
)
742 int tries
= HFA384X_BAP_BUSY_TIMEOUT
;
743 int res
= HFA384X_INW(o_off
) & HFA384X_OFFSET_BUSY
;
745 while (res
&& tries
> 0) {
748 res
= HFA384X_INW(o_off
) & HFA384X_OFFSET_BUSY
;
754 /* Offset must be even */
755 static int hfa384x_setup_bap(struct net_device
*dev
, u16 bap
, u16 id
,
761 if (offset
% 2 || bap
> 1)
765 o_off
= HFA384X_OFFSET1_OFF
;
766 s_off
= HFA384X_SELECT1_OFF
;
768 o_off
= HFA384X_OFFSET0_OFF
;
769 s_off
= HFA384X_SELECT0_OFF
;
772 if (hfa384x_wait_offset(dev
, o_off
)) {
773 prism2_io_debug_error(dev
, 7);
774 printk(KERN_DEBUG
"%s: hfa384x_setup_bap - timeout before\n",
780 HFA384X_OUTW(id
, s_off
);
781 HFA384X_OUTW(offset
, o_off
);
783 if (hfa384x_wait_offset(dev
, o_off
)) {
784 prism2_io_debug_error(dev
, 8);
785 printk(KERN_DEBUG
"%s: hfa384x_setup_bap - timeout after\n",
790 #ifndef final_version
791 if (HFA384X_INW(o_off
) & HFA384X_OFFSET_ERR
) {
792 prism2_io_debug_error(dev
, 9);
793 printk(KERN_DEBUG
"%s: hfa384x_setup_bap - offset error "
794 "(%d,0x04%x,%d); reg=0x%04x\n",
795 dev
->name
, bap
, id
, offset
, HFA384X_INW(o_off
));
805 static int hfa384x_get_rid(struct net_device
*dev
, u16 rid
, void *buf
, int len
,
808 struct hostap_interface
*iface
;
811 struct hfa384x_rid_hdr rec
;
813 iface
= netdev_priv(dev
);
814 local
= iface
->local
;
817 printk(KERN_DEBUG
"%s: cannot get RID %04x (len=%d) - no PRI "
818 "f/w\n", dev
->name
, rid
, len
);
819 return -ENOTTY
; /* Well.. not really correct, but return
820 * something unique enough.. */
823 if ((local
->func
->card_present
&& !local
->func
->card_present(local
)) ||
824 local
->hw_downloading
)
827 res
= mutex_lock_interruptible(&local
->rid_bap_mtx
);
831 res
= hfa384x_cmd(dev
, HFA384X_CMDCODE_ACCESS
, rid
, NULL
, NULL
);
833 printk(KERN_DEBUG
"%s: hfa384x_get_rid: CMDCODE_ACCESS failed "
834 "(res=%d, rid=%04x, len=%d)\n",
835 dev
->name
, res
, rid
, len
);
836 mutex_unlock(&local
->rid_bap_mtx
);
840 spin_lock_bh(&local
->baplock
);
842 res
= hfa384x_setup_bap(dev
, BAP0
, rid
, 0);
844 res
= hfa384x_from_bap(dev
, BAP0
, &rec
, sizeof(rec
));
846 if (le16_to_cpu(rec
.len
) == 0) {
847 /* RID not available */
851 rlen
= (le16_to_cpu(rec
.len
) - 1) * 2;
852 if (!res
&& exact_len
&& rlen
!= len
) {
853 printk(KERN_DEBUG
"%s: hfa384x_get_rid - RID len mismatch: "
854 "rid=0x%04x, len=%d (expected %d)\n",
855 dev
->name
, rid
, rlen
, len
);
860 res
= hfa384x_from_bap(dev
, BAP0
, buf
, len
);
862 spin_unlock_bh(&local
->baplock
);
863 mutex_unlock(&local
->rid_bap_mtx
);
867 printk(KERN_DEBUG
"%s: hfa384x_get_rid (rid=%04x, "
868 "len=%d) - failed - res=%d\n", dev
->name
, rid
,
870 if (res
== -ETIMEDOUT
)
871 prism2_hw_reset(dev
);
879 static int hfa384x_set_rid(struct net_device
*dev
, u16 rid
, void *buf
, int len
)
881 struct hostap_interface
*iface
;
883 struct hfa384x_rid_hdr rec
;
886 iface
= netdev_priv(dev
);
887 local
= iface
->local
;
890 printk(KERN_DEBUG
"%s: cannot set RID %04x (len=%d) - no PRI "
891 "f/w\n", dev
->name
, rid
, len
);
892 return -ENOTTY
; /* Well.. not really correct, but return
893 * something unique enough.. */
896 if ((local
->func
->card_present
&& !local
->func
->card_present(local
)) ||
897 local
->hw_downloading
)
900 rec
.rid
= cpu_to_le16(rid
);
901 /* RID len in words and +1 for rec.rid */
902 rec
.len
= cpu_to_le16(len
/ 2 + len
% 2 + 1);
904 res
= mutex_lock_interruptible(&local
->rid_bap_mtx
);
908 spin_lock_bh(&local
->baplock
);
909 res
= hfa384x_setup_bap(dev
, BAP0
, rid
, 0);
911 res
= hfa384x_to_bap(dev
, BAP0
, &rec
, sizeof(rec
));
913 res
= hfa384x_to_bap(dev
, BAP0
, buf
, len
);
914 spin_unlock_bh(&local
->baplock
);
917 printk(KERN_DEBUG
"%s: hfa384x_set_rid (rid=%04x, len=%d) - "
918 "failed - res=%d\n", dev
->name
, rid
, len
, res
);
919 mutex_unlock(&local
->rid_bap_mtx
);
923 res
= hfa384x_cmd(dev
, HFA384X_CMDCODE_ACCESS_WRITE
, rid
, NULL
, NULL
);
924 mutex_unlock(&local
->rid_bap_mtx
);
927 printk(KERN_DEBUG
"%s: hfa384x_set_rid: CMDCODE_ACCESS_WRITE "
928 "failed (res=%d, rid=%04x, len=%d)\n",
929 dev
->name
, res
, rid
, len
);
931 if (res
== -ETIMEDOUT
)
932 prism2_hw_reset(dev
);
939 static void hfa384x_disable_interrupts(struct net_device
*dev
)
941 /* disable interrupts and clear event status */
942 HFA384X_OUTW(0, HFA384X_INTEN_OFF
);
943 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF
);
947 static void hfa384x_enable_interrupts(struct net_device
*dev
)
949 /* ack pending events and enable interrupts from selected events */
950 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF
);
951 HFA384X_OUTW(HFA384X_EVENT_MASK
, HFA384X_INTEN_OFF
);
955 static void hfa384x_events_no_bap0(struct net_device
*dev
)
957 HFA384X_OUTW(HFA384X_EVENT_MASK
& ~HFA384X_BAP0_EVENTS
,
962 static void hfa384x_events_all(struct net_device
*dev
)
964 HFA384X_OUTW(HFA384X_EVENT_MASK
, HFA384X_INTEN_OFF
);
968 static void hfa384x_events_only_cmd(struct net_device
*dev
)
970 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_INTEN_OFF
);
974 static u16
hfa384x_allocate_fid(struct net_device
*dev
, int len
)
979 /* FIX: this could be replace with hfa384x_cmd() if the Alloc event
980 * below would be handled like CmdCompl event (sleep here, wake up from
981 * interrupt handler */
982 if (hfa384x_cmd_wait(dev
, HFA384X_CMDCODE_ALLOC
, len
)) {
983 printk(KERN_DEBUG
"%s: cannot allocate fid, len=%d\n",
988 delay
= jiffies
+ HFA384X_ALLOC_COMPL_TIMEOUT
;
989 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_ALLOC
) &&
990 time_before(jiffies
, delay
))
992 if (!(HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_ALLOC
)) {
993 printk("%s: fid allocate, len=%d - timeout\n", dev
->name
, len
);
997 fid
= HFA384X_INW(HFA384X_ALLOCFID_OFF
);
998 HFA384X_OUTW(HFA384X_EV_ALLOC
, HFA384X_EVACK_OFF
);
1004 static int prism2_reset_port(struct net_device
*dev
)
1006 struct hostap_interface
*iface
;
1007 local_info_t
*local
;
1010 iface
= netdev_priv(dev
);
1011 local
= iface
->local
;
1013 if (!local
->dev_enabled
)
1016 res
= hfa384x_cmd(dev
, HFA384X_CMDCODE_DISABLE
, 0,
1019 printk(KERN_DEBUG
"%s: reset port failed to disable port\n",
1022 res
= hfa384x_cmd(dev
, HFA384X_CMDCODE_ENABLE
, 0,
1025 printk(KERN_DEBUG
"%s: reset port failed to enable "
1026 "port\n", dev
->name
);
1029 /* It looks like at least some STA firmware versions reset
1030 * fragmentation threshold back to 2346 after enable command. Restore
1031 * the configured value, if it differs from this default. */
1032 if (local
->fragm_threshold
!= 2346 &&
1033 hostap_set_word(dev
, HFA384X_RID_FRAGMENTATIONTHRESHOLD
,
1034 local
->fragm_threshold
)) {
1035 printk(KERN_DEBUG
"%s: failed to restore fragmentation "
1036 "threshold (%d) after Port0 enable\n",
1037 dev
->name
, local
->fragm_threshold
);
1040 /* Some firmwares lose antenna selection settings on reset */
1041 (void) hostap_set_antsel(local
);
1047 static int prism2_get_version_info(struct net_device
*dev
, u16 rid
,
1050 struct hfa384x_comp_ident comp
;
1051 struct hostap_interface
*iface
;
1052 local_info_t
*local
;
1054 iface
= netdev_priv(dev
);
1055 local
= iface
->local
;
1057 if (local
->no_pri
) {
1058 /* PRI f/w not yet available - cannot read RIDs */
1061 if (hfa384x_get_rid(dev
, rid
, &comp
, sizeof(comp
), 1) < 0) {
1062 printk(KERN_DEBUG
"Could not get RID for component %s\n", txt
);
1066 printk(KERN_INFO
"%s: %s: id=0x%02x v%d.%d.%d\n", dev
->name
, txt
,
1067 __le16_to_cpu(comp
.id
), __le16_to_cpu(comp
.major
),
1068 __le16_to_cpu(comp
.minor
), __le16_to_cpu(comp
.variant
));
1073 static int prism2_setup_rids(struct net_device
*dev
)
1075 struct hostap_interface
*iface
;
1076 local_info_t
*local
;
1080 iface
= netdev_priv(dev
);
1081 local
= iface
->local
;
1083 hostap_set_word(dev
, HFA384X_RID_TICKTIME
, 2000);
1085 if (!local
->fw_ap
) {
1086 u16 tmp1
= hostap_get_porttype(local
);
1087 ret
= hostap_set_word(dev
, HFA384X_RID_CNFPORTTYPE
, tmp1
);
1089 printk("%s: Port type setting to %d failed\n",
1095 /* Setting SSID to empty string seems to kill the card in Host AP mode
1097 if (local
->iw_mode
!= IW_MODE_MASTER
|| local
->essid
[0] != '\0') {
1098 ret
= hostap_set_string(dev
, HFA384X_RID_CNFOWNSSID
,
1101 printk("%s: AP own SSID setting failed\n", dev
->name
);
1106 ret
= hostap_set_word(dev
, HFA384X_RID_CNFMAXDATALEN
,
1107 PRISM2_DATA_MAXLEN
);
1109 printk("%s: MAC data length setting to %d failed\n",
1110 dev
->name
, PRISM2_DATA_MAXLEN
);
1114 if (hfa384x_get_rid(dev
, HFA384X_RID_CHANNELLIST
, &tmp
, 2, 1) < 0) {
1115 printk("%s: Channel list read failed\n", dev
->name
);
1119 local
->channel_mask
= le16_to_cpu(tmp
);
1121 if (local
->channel
< 1 || local
->channel
> 14 ||
1122 !(local
->channel_mask
& (1 << (local
->channel
- 1)))) {
1123 printk(KERN_WARNING
"%s: Channel setting out of range "
1124 "(%d)!\n", dev
->name
, local
->channel
);
1129 ret
= hostap_set_word(dev
, HFA384X_RID_CNFOWNCHANNEL
, local
->channel
);
1131 printk("%s: Channel setting to %d failed\n",
1132 dev
->name
, local
->channel
);
1136 ret
= hostap_set_word(dev
, HFA384X_RID_CNFBEACONINT
,
1139 printk("%s: Beacon interval setting to %d failed\n",
1140 dev
->name
, local
->beacon_int
);
1141 /* this may fail with Symbol/Lucent firmware */
1142 if (ret
== -ETIMEDOUT
)
1146 ret
= hostap_set_word(dev
, HFA384X_RID_CNFOWNDTIMPERIOD
,
1147 local
->dtim_period
);
1149 printk("%s: DTIM period setting to %d failed\n",
1150 dev
->name
, local
->dtim_period
);
1151 /* this may fail with Symbol/Lucent firmware */
1152 if (ret
== -ETIMEDOUT
)
1156 ret
= hostap_set_word(dev
, HFA384X_RID_PROMISCUOUSMODE
,
1159 printk(KERN_INFO
"%s: Setting promiscuous mode (%d) failed\n",
1160 dev
->name
, local
->is_promisc
);
1162 if (!local
->fw_ap
) {
1163 ret
= hostap_set_string(dev
, HFA384X_RID_CNFDESIREDSSID
,
1166 printk("%s: Desired SSID setting failed\n", dev
->name
);
1171 /* Setup TXRateControl, defaults to allow use of 1, 2, 5.5, and
1172 * 11 Mbps in automatic TX rate fallback and 1 and 2 Mbps as basic
1174 if (local
->tx_rate_control
== 0) {
1175 local
->tx_rate_control
=
1176 HFA384X_RATES_1MBPS
|
1177 HFA384X_RATES_2MBPS
|
1178 HFA384X_RATES_5MBPS
|
1179 HFA384X_RATES_11MBPS
;
1181 if (local
->basic_rates
== 0)
1182 local
->basic_rates
= HFA384X_RATES_1MBPS
| HFA384X_RATES_2MBPS
;
1184 if (!local
->fw_ap
) {
1185 ret
= hostap_set_word(dev
, HFA384X_RID_TXRATECONTROL
,
1186 local
->tx_rate_control
);
1188 printk("%s: TXRateControl setting to %d failed\n",
1189 dev
->name
, local
->tx_rate_control
);
1193 ret
= hostap_set_word(dev
, HFA384X_RID_CNFSUPPORTEDRATES
,
1194 local
->tx_rate_control
);
1196 printk("%s: cnfSupportedRates setting to %d failed\n",
1197 dev
->name
, local
->tx_rate_control
);
1200 ret
= hostap_set_word(dev
, HFA384X_RID_CNFBASICRATES
,
1201 local
->basic_rates
);
1203 printk("%s: cnfBasicRates setting to %d failed\n",
1204 dev
->name
, local
->basic_rates
);
1207 ret
= hostap_set_word(dev
, HFA384X_RID_CREATEIBSS
, 1);
1209 printk("%s: Create IBSS setting to 1 failed\n",
1214 if (local
->name_set
)
1215 (void) hostap_set_string(dev
, HFA384X_RID_CNFOWNNAME
,
1218 if (hostap_set_encryption(local
)) {
1219 printk(KERN_INFO
"%s: could not configure encryption\n",
1223 (void) hostap_set_antsel(local
);
1225 if (hostap_set_roaming(local
)) {
1226 printk(KERN_INFO
"%s: could not set host roaming\n",
1230 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,6,3) &&
1231 hostap_set_word(dev
, HFA384X_RID_CNFENHSECURITY
, local
->enh_sec
))
1232 printk(KERN_INFO
"%s: cnfEnhSecurity setting to 0x%x failed\n",
1233 dev
->name
, local
->enh_sec
);
1235 /* 32-bit tallies were added in STA f/w 0.8.0, but they were apparently
1236 * not working correctly (last seven counters report bogus values).
1237 * This has been fixed in 0.8.2, so enable 32-bit tallies only
1238 * beginning with that firmware version. Another bug fix for 32-bit
1239 * tallies in 1.4.0; should 16-bit tallies be used for some other
1241 if (local
->sta_fw_ver
>= PRISM2_FW_VER(0,8,2)) {
1242 if (hostap_set_word(dev
, HFA384X_RID_CNFTHIRTY2TALLY
, 1)) {
1243 printk(KERN_INFO
"%s: cnfThirty2Tally setting "
1244 "failed\n", dev
->name
);
1245 local
->tallies32
= 0;
1247 local
->tallies32
= 1;
1249 local
->tallies32
= 0;
1251 hostap_set_auth_algs(local
);
1253 if (hostap_set_word(dev
, HFA384X_RID_FRAGMENTATIONTHRESHOLD
,
1254 local
->fragm_threshold
)) {
1255 printk(KERN_INFO
"%s: setting FragmentationThreshold to %d "
1256 "failed\n", dev
->name
, local
->fragm_threshold
);
1259 if (hostap_set_word(dev
, HFA384X_RID_RTSTHRESHOLD
,
1260 local
->rts_threshold
)) {
1261 printk(KERN_INFO
"%s: setting RTSThreshold to %d failed\n",
1262 dev
->name
, local
->rts_threshold
);
1265 if (local
->manual_retry_count
>= 0 &&
1266 hostap_set_word(dev
, HFA384X_RID_CNFALTRETRYCOUNT
,
1267 local
->manual_retry_count
)) {
1268 printk(KERN_INFO
"%s: setting cnfAltRetryCount to %d failed\n",
1269 dev
->name
, local
->manual_retry_count
);
1272 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,3,1) &&
1273 hfa384x_get_rid(dev
, HFA384X_RID_CNFDBMADJUST
, &tmp
, 2, 1) == 2) {
1274 local
->rssi_to_dBm
= le16_to_cpu(tmp
);
1277 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,7,0) && local
->wpa
&&
1278 hostap_set_word(dev
, HFA384X_RID_SSNHANDLINGMODE
, 1)) {
1279 printk(KERN_INFO
"%s: setting ssnHandlingMode to 1 failed\n",
1283 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,7,0) && local
->generic_elem
&&
1284 hfa384x_set_rid(dev
, HFA384X_RID_GENERICELEMENT
,
1285 local
->generic_elem
, local
->generic_elem_len
)) {
1286 printk(KERN_INFO
"%s: setting genericElement failed\n",
1295 static int prism2_hw_init(struct net_device
*dev
, int initial
)
1297 struct hostap_interface
*iface
;
1298 local_info_t
*local
;
1300 unsigned long start
, delay
;
1302 PDEBUG(DEBUG_FLOW
, "prism2_hw_init()\n");
1304 iface
= netdev_priv(dev
);
1305 local
= iface
->local
;
1307 clear_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
);
1310 /* initialize HFA 384x */
1311 ret
= hfa384x_cmd_no_wait(dev
, HFA384X_CMDCODE_INIT
, 0);
1313 printk(KERN_INFO
"%s: first command failed - assuming card "
1314 "does not have primary firmware\n", dev_info
);
1317 if (first
&& (HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_CMD
)) {
1318 /* EvStat has Cmd bit set in some cases, so retry once if no
1319 * wait was needed */
1320 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_EVACK_OFF
);
1321 printk(KERN_DEBUG
"%s: init command completed too quickly - "
1322 "retrying\n", dev
->name
);
1328 delay
= jiffies
+ HFA384X_INIT_TIMEOUT
;
1329 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_CMD
) &&
1330 time_before(jiffies
, delay
))
1332 if (!(HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_CMD
)) {
1333 printk(KERN_DEBUG
"%s: assuming no Primary image in "
1334 "flash - card initialization not completed\n",
1337 #ifdef PRISM2_DOWNLOAD_SUPPORT
1338 if (local
->sram_type
== -1)
1339 local
->sram_type
= prism2_get_ram_size(local
);
1340 #endif /* PRISM2_DOWNLOAD_SUPPORT */
1344 printk(KERN_DEBUG
"prism2_hw_init: initialized in %lu ms\n",
1345 (jiffies
- start
) * 1000 / HZ
);
1346 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_EVACK_OFF
);
1351 static int prism2_hw_init2(struct net_device
*dev
, int initial
)
1353 struct hostap_interface
*iface
;
1354 local_info_t
*local
;
1357 iface
= netdev_priv(dev
);
1358 local
= iface
->local
;
1360 #ifdef PRISM2_DOWNLOAD_SUPPORT
1365 local
->pda
= prism2_read_pda(dev
);
1366 #endif /* PRISM2_DOWNLOAD_SUPPORT */
1368 hfa384x_disable_interrupts(dev
);
1370 #ifndef final_version
1371 HFA384X_OUTW(HFA384X_MAGIC
, HFA384X_SWSUPPORT0_OFF
);
1372 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF
) != HFA384X_MAGIC
) {
1373 printk("SWSUPPORT0 write/read failed: %04X != %04X\n",
1374 HFA384X_INW(HFA384X_SWSUPPORT0_OFF
), HFA384X_MAGIC
);
1379 if (initial
|| local
->pri_only
) {
1380 hfa384x_events_only_cmd(dev
);
1381 /* get card version information */
1382 if (prism2_get_version_info(dev
, HFA384X_RID_NICID
, "NIC") ||
1383 prism2_get_version_info(dev
, HFA384X_RID_PRIID
, "PRI")) {
1384 hfa384x_disable_interrupts(dev
);
1388 if (prism2_get_version_info(dev
, HFA384X_RID_STAID
, "STA")) {
1389 printk(KERN_DEBUG
"%s: Failed to read STA f/w version "
1390 "- only Primary f/w present\n", dev
->name
);
1391 local
->pri_only
= 1;
1394 local
->pri_only
= 0;
1395 hfa384x_disable_interrupts(dev
);
1398 /* FIX: could convert allocate_fid to use sleeping CmdCompl wait and
1399 * enable interrupts before this. This would also require some sort of
1400 * sleeping AllocEv waiting */
1402 /* allocate TX FIDs */
1403 local
->txfid_len
= PRISM2_TXFID_LEN
;
1404 for (i
= 0; i
< PRISM2_TXFID_COUNT
; i
++) {
1405 local
->txfid
[i
] = hfa384x_allocate_fid(dev
, local
->txfid_len
);
1406 if (local
->txfid
[i
] == 0xffff && local
->txfid_len
> 1600) {
1407 local
->txfid
[i
] = hfa384x_allocate_fid(dev
, 1600);
1408 if (local
->txfid
[i
] != 0xffff) {
1409 printk(KERN_DEBUG
"%s: Using shorter TX FID "
1410 "(1600 bytes)\n", dev
->name
);
1411 local
->txfid_len
= 1600;
1414 if (local
->txfid
[i
] == 0xffff)
1416 local
->intransmitfid
[i
] = PRISM2_TXFID_EMPTY
;
1419 hfa384x_events_only_cmd(dev
);
1422 struct list_head
*ptr
;
1423 prism2_check_sta_fw_version(local
);
1425 if (hfa384x_get_rid(dev
, HFA384X_RID_CNFOWNMACADDR
,
1426 dev
->dev_addr
, 6, 1) < 0) {
1427 printk("%s: could not get own MAC address\n",
1430 list_for_each(ptr
, &local
->hostap_interfaces
) {
1431 iface
= list_entry(ptr
, struct hostap_interface
, list
);
1432 memcpy(iface
->dev
->dev_addr
, dev
->dev_addr
, ETH_ALEN
);
1434 } else if (local
->fw_ap
)
1435 prism2_check_sta_fw_version(local
);
1437 prism2_setup_rids(dev
);
1439 /* MAC is now configured, but port 0 is not yet enabled */
1444 printk(KERN_WARNING
"%s: Initialization failed\n", dev_info
);
1449 static int prism2_hw_enable(struct net_device
*dev
, int initial
)
1451 struct hostap_interface
*iface
;
1452 local_info_t
*local
;
1455 iface
= netdev_priv(dev
);
1456 local
= iface
->local
;
1457 was_resetting
= local
->hw_resetting
;
1459 if (hfa384x_cmd(dev
, HFA384X_CMDCODE_ENABLE
, 0, NULL
, NULL
)) {
1460 printk("%s: MAC port 0 enabling failed\n", dev
->name
);
1464 local
->hw_ready
= 1;
1465 local
->hw_reset_tries
= 0;
1466 local
->hw_resetting
= 0;
1467 hfa384x_enable_interrupts(dev
);
1469 /* at least D-Link DWL-650 seems to require additional port reset
1470 * before it starts acting as an AP, so reset port automatically
1471 * here just in case */
1472 if (initial
&& prism2_reset_port(dev
)) {
1473 printk("%s: MAC port 0 reseting failed\n", dev
->name
);
1477 if (was_resetting
&& netif_queue_stopped(dev
)) {
1478 /* If hw_reset() was called during pending transmit, netif
1479 * queue was stopped. Wake it up now since the wlan card has
1481 netif_wake_queue(dev
);
1488 static int prism2_hw_config(struct net_device
*dev
, int initial
)
1490 struct hostap_interface
*iface
;
1491 local_info_t
*local
;
1493 iface
= netdev_priv(dev
);
1494 local
= iface
->local
;
1496 if (local
->hw_downloading
)
1499 if (prism2_hw_init(dev
, initial
)) {
1500 return local
->no_pri
? 0 : 1;
1503 if (prism2_hw_init2(dev
, initial
))
1506 /* Enable firmware if secondary image is loaded and at least one of the
1507 * netdevices is up. */
1508 if (!local
->pri_only
&&
1509 (initial
== 0 || (initial
== 2 && local
->num_dev_open
> 0))) {
1510 if (!local
->dev_enabled
)
1511 prism2_callback(local
, PRISM2_CALLBACK_ENABLE
);
1512 local
->dev_enabled
= 1;
1513 return prism2_hw_enable(dev
, initial
);
1520 static void prism2_hw_shutdown(struct net_device
*dev
, int no_disable
)
1522 struct hostap_interface
*iface
;
1523 local_info_t
*local
;
1525 iface
= netdev_priv(dev
);
1526 local
= iface
->local
;
1528 /* Allow only command completion events during disable */
1529 hfa384x_events_only_cmd(dev
);
1531 local
->hw_ready
= 0;
1532 if (local
->dev_enabled
)
1533 prism2_callback(local
, PRISM2_CALLBACK_DISABLE
);
1534 local
->dev_enabled
= 0;
1536 if (local
->func
->card_present
&& !local
->func
->card_present(local
)) {
1537 printk(KERN_DEBUG
"%s: card already removed or not configured "
1538 "during shutdown\n", dev
->name
);
1542 if ((no_disable
& HOSTAP_HW_NO_DISABLE
) == 0 &&
1543 hfa384x_cmd(dev
, HFA384X_CMDCODE_DISABLE
, 0, NULL
, NULL
))
1544 printk(KERN_WARNING
"%s: Shutdown failed\n", dev_info
);
1546 hfa384x_disable_interrupts(dev
);
1548 if (no_disable
& HOSTAP_HW_ENABLE_CMDCOMPL
)
1549 hfa384x_events_only_cmd(dev
);
1551 prism2_clear_cmd_queue(local
);
1555 static void prism2_hw_reset(struct net_device
*dev
)
1557 struct hostap_interface
*iface
;
1558 local_info_t
*local
;
1561 iface
= netdev_priv(dev
);
1562 local
= iface
->local
;
1564 if (in_interrupt()) {
1565 printk(KERN_DEBUG
"%s: driver bug - prism2_hw_reset() called "
1566 "in interrupt context\n", dev
->name
);
1570 if (local
->hw_downloading
)
1573 if (local
->hw_resetting
) {
1574 printk(KERN_WARNING
"%s: %s: already resetting card - "
1575 "ignoring reset request\n", dev_info
, dev
->name
);
1579 local
->hw_reset_tries
++;
1580 if (local
->hw_reset_tries
> 10) {
1581 printk(KERN_WARNING
"%s: too many reset tries, skipping\n",
1586 printk(KERN_WARNING
"%s: %s: resetting card\n", dev_info
, dev
->name
);
1587 hfa384x_disable_interrupts(dev
);
1588 local
->hw_resetting
= 1;
1589 if (local
->func
->cor_sreset
) {
1590 /* Host system seems to hang in some cases with high traffic
1591 * load or shared interrupts during COR sreset. Disable shared
1592 * interrupts during reset to avoid these crashes. COS sreset
1593 * takes quite a long time, so it is unfortunate that this
1594 * seems to be needed. Anyway, I do not know of any better way
1595 * of avoiding the crash. */
1596 disable_irq(dev
->irq
);
1597 local
->func
->cor_sreset(local
);
1598 enable_irq(dev
->irq
);
1600 prism2_hw_shutdown(dev
, 1);
1601 prism2_hw_config(dev
, 0);
1602 local
->hw_resetting
= 0;
1604 #ifdef PRISM2_DOWNLOAD_SUPPORT
1605 if (local
->dl_pri
) {
1606 printk(KERN_DEBUG
"%s: persistent download of primary "
1607 "firmware\n", dev
->name
);
1608 if (prism2_download_genesis(local
, local
->dl_pri
) < 0)
1609 printk(KERN_WARNING
"%s: download (PRI) failed\n",
1613 if (local
->dl_sec
) {
1614 printk(KERN_DEBUG
"%s: persistent download of secondary "
1615 "firmware\n", dev
->name
);
1616 if (prism2_download_volatile(local
, local
->dl_sec
) < 0)
1617 printk(KERN_WARNING
"%s: download (SEC) failed\n",
1620 #endif /* PRISM2_DOWNLOAD_SUPPORT */
1622 /* TODO: restore beacon TIM bits for STAs that have buffered frames */
1626 static void prism2_schedule_reset(local_info_t
*local
)
1628 schedule_work(&local
->reset_queue
);
1632 /* Called only as scheduled task after noticing card timeout in interrupt
1634 static void handle_reset_queue(struct work_struct
*work
)
1636 local_info_t
*local
= container_of(work
, local_info_t
, reset_queue
);
1638 printk(KERN_DEBUG
"%s: scheduled card reset\n", local
->dev
->name
);
1639 prism2_hw_reset(local
->dev
);
1641 if (netif_queue_stopped(local
->dev
)) {
1644 for (i
= 0; i
< PRISM2_TXFID_COUNT
; i
++)
1645 if (local
->intransmitfid
[i
] == PRISM2_TXFID_EMPTY
) {
1646 PDEBUG(DEBUG_EXTRA
, "prism2_tx_timeout: "
1648 netif_wake_queue(local
->dev
);
1655 static int prism2_get_txfid_idx(local_info_t
*local
)
1658 unsigned long flags
;
1660 spin_lock_irqsave(&local
->txfidlock
, flags
);
1661 end
= idx
= local
->next_txfid
;
1663 if (local
->intransmitfid
[idx
] == PRISM2_TXFID_EMPTY
) {
1664 local
->intransmitfid
[idx
] = PRISM2_TXFID_RESERVED
;
1665 spin_unlock_irqrestore(&local
->txfidlock
, flags
);
1669 if (idx
>= PRISM2_TXFID_COUNT
)
1671 } while (idx
!= end
);
1672 spin_unlock_irqrestore(&local
->txfidlock
, flags
);
1674 PDEBUG(DEBUG_EXTRA2
, "prism2_get_txfid_idx: no room in txfid buf: "
1675 "packet dropped\n");
1676 local
->dev
->stats
.tx_dropped
++;
1682 /* Called only from hardware IRQ */
1683 static void prism2_transmit_cb(struct net_device
*dev
, long context
,
1686 struct hostap_interface
*iface
;
1687 local_info_t
*local
;
1688 int idx
= (int) context
;
1690 iface
= netdev_priv(dev
);
1691 local
= iface
->local
;
1694 printk(KERN_DEBUG
"%s: prism2_transmit_cb - res=0x%02x\n",
1699 if (idx
< 0 || idx
>= PRISM2_TXFID_COUNT
) {
1700 printk(KERN_DEBUG
"%s: prism2_transmit_cb called with invalid "
1701 "idx=%d\n", dev
->name
, idx
);
1705 if (!test_and_clear_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
)) {
1706 printk(KERN_DEBUG
"%s: driver bug: prism2_transmit_cb called "
1707 "with no pending transmit\n", dev
->name
);
1710 if (netif_queue_stopped(dev
)) {
1711 /* ready for next TX, so wake up queue that was stopped in
1712 * prism2_transmit() */
1713 netif_wake_queue(dev
);
1716 spin_lock(&local
->txfidlock
);
1718 /* With reclaim, Resp0 contains new txfid for transmit; the old txfid
1719 * will be automatically allocated for the next TX frame */
1720 local
->intransmitfid
[idx
] = resp0
;
1722 PDEBUG(DEBUG_FID
, "%s: prism2_transmit_cb: txfid[%d]=0x%04x, "
1723 "resp0=0x%04x, transmit_txfid=0x%04x\n",
1724 dev
->name
, idx
, local
->txfid
[idx
],
1725 resp0
, local
->intransmitfid
[local
->next_txfid
]);
1728 if (idx
>= PRISM2_TXFID_COUNT
)
1730 local
->next_txfid
= idx
;
1732 /* check if all TX buffers are occupied */
1734 if (local
->intransmitfid
[idx
] == PRISM2_TXFID_EMPTY
) {
1735 spin_unlock(&local
->txfidlock
);
1739 if (idx
>= PRISM2_TXFID_COUNT
)
1741 } while (idx
!= local
->next_txfid
);
1742 spin_unlock(&local
->txfidlock
);
1744 /* no empty TX buffers, stop queue */
1745 netif_stop_queue(dev
);
1749 /* Called only from software IRQ if PCI bus master is not used (with bus master
1750 * this can be called both from software and hardware IRQ) */
1751 static int prism2_transmit(struct net_device
*dev
, int idx
)
1753 struct hostap_interface
*iface
;
1754 local_info_t
*local
;
1757 iface
= netdev_priv(dev
);
1758 local
= iface
->local
;
1760 /* The driver tries to stop netif queue so that there would not be
1761 * more than one attempt to transmit frames going on; check that this
1762 * is really the case */
1764 if (test_and_set_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
)) {
1765 printk(KERN_DEBUG
"%s: driver bug - prism2_transmit() called "
1766 "when previous TX was pending\n", dev
->name
);
1770 /* stop the queue for the time that transmit is pending */
1771 netif_stop_queue(dev
);
1773 /* transmit packet */
1774 res
= hfa384x_cmd_callback(
1776 HFA384X_CMDCODE_TRANSMIT
| HFA384X_CMD_TX_RECLAIM
,
1778 prism2_transmit_cb
, (long) idx
);
1781 printk(KERN_DEBUG
"%s: prism2_transmit: CMDCODE_TRANSMIT "
1782 "failed (res=%d)\n", dev
->name
, res
);
1783 dev
->stats
.tx_dropped
++;
1784 netif_wake_queue(dev
);
1787 dev
->trans_start
= jiffies
;
1789 /* Since we did not wait for command completion, the card continues
1790 * to process on the background and we will finish handling when
1791 * command completion event is handled (prism2_cmd_ev() function) */
1797 /* Send IEEE 802.11 frame (convert the header into Prism2 TX descriptor and
1798 * send the payload with this descriptor) */
1799 /* Called only from software IRQ */
1800 static int prism2_tx_80211(struct sk_buff
*skb
, struct net_device
*dev
)
1802 struct hostap_interface
*iface
;
1803 local_info_t
*local
;
1804 struct hfa384x_tx_frame txdesc
;
1805 struct hostap_skb_tx_data
*meta
;
1806 int hdr_len
, data_len
, idx
, res
, ret
= -1;
1809 iface
= netdev_priv(dev
);
1810 local
= iface
->local
;
1812 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
1814 prism2_callback(local
, PRISM2_CALLBACK_TX_START
);
1816 if ((local
->func
->card_present
&& !local
->func
->card_present(local
)) ||
1817 !local
->hw_ready
|| local
->hw_downloading
|| local
->pri_only
) {
1818 if (net_ratelimit()) {
1819 printk(KERN_DEBUG
"%s: prism2_tx_80211: hw not ready -"
1820 " skipping\n", dev
->name
);
1825 memset(&txdesc
, 0, sizeof(txdesc
));
1827 /* skb->data starts with txdesc->frame_control */
1829 skb_copy_from_linear_data(skb
, &txdesc
.frame_control
, hdr_len
);
1830 fc
= le16_to_cpu(txdesc
.frame_control
);
1831 if (ieee80211_is_data(txdesc
.frame_control
) &&
1832 ieee80211_has_a4(txdesc
.frame_control
) &&
1835 skb_copy_from_linear_data_offset(skb
, hdr_len
, txdesc
.addr4
,
1837 hdr_len
+= ETH_ALEN
;
1840 tx_control
= local
->tx_control
;
1841 if (meta
->tx_cb_idx
) {
1842 tx_control
|= HFA384X_TX_CTRL_TX_OK
;
1843 txdesc
.sw_support
= cpu_to_le32(meta
->tx_cb_idx
);
1845 txdesc
.tx_control
= cpu_to_le16(tx_control
);
1846 txdesc
.tx_rate
= meta
->rate
;
1848 data_len
= skb
->len
- hdr_len
;
1849 txdesc
.data_len
= cpu_to_le16(data_len
);
1850 txdesc
.len
= cpu_to_be16(data_len
);
1852 idx
= prism2_get_txfid_idx(local
);
1856 if (local
->frame_dump
& PRISM2_DUMP_TX_HDR
)
1857 hostap_dump_tx_header(dev
->name
, &txdesc
);
1859 spin_lock(&local
->baplock
);
1860 res
= hfa384x_setup_bap(dev
, BAP0
, local
->txfid
[idx
], 0);
1863 res
= hfa384x_to_bap(dev
, BAP0
, &txdesc
, sizeof(txdesc
));
1865 res
= hfa384x_to_bap(dev
, BAP0
, skb
->data
+ hdr_len
,
1866 skb
->len
- hdr_len
);
1867 spin_unlock(&local
->baplock
);
1870 res
= prism2_transmit(dev
, idx
);
1872 printk(KERN_DEBUG
"%s: prism2_tx_80211 - to BAP0 failed\n",
1874 local
->intransmitfid
[idx
] = PRISM2_TXFID_EMPTY
;
1875 schedule_work(&local
->reset_queue
);
1882 prism2_callback(local
, PRISM2_CALLBACK_TX_END
);
1887 /* Some SMP systems have reported number of odd errors with hostap_pci. fid
1888 * register has changed values between consecutive reads for an unknown reason.
1889 * This should really not happen, so more debugging is needed. This test
1890 * version is a bit slower, but it will detect most of such register changes
1891 * and will try to get the correct fid eventually. */
1892 #define EXTRA_FID_READ_TESTS
1894 static u16
prism2_read_fid_reg(struct net_device
*dev
, u16 reg
)
1896 #ifdef EXTRA_FID_READ_TESTS
1897 u16 val
, val2
, val3
;
1900 for (i
= 0; i
< 10; i
++) {
1901 val
= HFA384X_INW(reg
);
1902 val2
= HFA384X_INW(reg
);
1903 val3
= HFA384X_INW(reg
);
1905 if (val
== val2
&& val
== val3
)
1908 printk(KERN_DEBUG
"%s: detected fid change (try=%d, reg=%04x):"
1909 " %04x %04x %04x\n",
1910 dev
->name
, i
, reg
, val
, val2
, val3
);
1911 if ((val
== val2
|| val
== val3
) && val
!= 0)
1913 if (val2
== val3
&& val2
!= 0)
1916 printk(KERN_WARNING
"%s: Uhhuh.. could not read good fid from reg "
1917 "%04x (%04x %04x %04x)\n", dev
->name
, reg
, val
, val2
, val3
);
1919 #else /* EXTRA_FID_READ_TESTS */
1920 return HFA384X_INW(reg
);
1921 #endif /* EXTRA_FID_READ_TESTS */
1925 /* Called only as a tasklet (software IRQ) */
1926 static void prism2_rx(local_info_t
*local
)
1928 struct net_device
*dev
= local
->dev
;
1929 int res
, rx_pending
= 0;
1930 u16 len
, hdr_len
, rxfid
, status
, macport
;
1931 struct hfa384x_rx_frame rxdesc
;
1932 struct sk_buff
*skb
= NULL
;
1934 prism2_callback(local
, PRISM2_CALLBACK_RX_START
);
1936 rxfid
= prism2_read_fid_reg(dev
, HFA384X_RXFID_OFF
);
1937 #ifndef final_version
1939 rxfid
= HFA384X_INW(HFA384X_RXFID_OFF
);
1940 printk(KERN_DEBUG
"prism2_rx: rxfid=0 (next 0x%04x)\n",
1943 schedule_work(&local
->reset_queue
);
1946 /* try to continue with the new rxfid value */
1950 spin_lock(&local
->baplock
);
1951 res
= hfa384x_setup_bap(dev
, BAP0
, rxfid
, 0);
1953 res
= hfa384x_from_bap(dev
, BAP0
, &rxdesc
, sizeof(rxdesc
));
1956 spin_unlock(&local
->baplock
);
1957 printk(KERN_DEBUG
"%s: copy from BAP0 failed %d\n", dev
->name
,
1959 if (res
== -ETIMEDOUT
) {
1960 schedule_work(&local
->reset_queue
);
1965 len
= le16_to_cpu(rxdesc
.data_len
);
1966 hdr_len
= sizeof(rxdesc
);
1967 status
= le16_to_cpu(rxdesc
.status
);
1968 macport
= (status
>> 8) & 0x07;
1970 /* Drop frames with too large reported payload length. Monitor mode
1971 * seems to sometimes pass frames (e.g., ctrl::ack) with signed and
1972 * negative value, so allow also values 65522 .. 65534 (-14 .. -2) for
1974 if (len
> PRISM2_DATA_MAXLEN
+ 8 /* WEP */) {
1975 if (macport
== 7 && local
->iw_mode
== IW_MODE_MONITOR
) {
1976 if (len
>= (u16
) -14) {
1977 hdr_len
-= 65535 - len
;
1982 spin_unlock(&local
->baplock
);
1983 printk(KERN_DEBUG
"%s: Received frame with invalid "
1984 "length 0x%04x\n", dev
->name
, len
);
1985 hostap_dump_rx_header(dev
->name
, &rxdesc
);
1990 skb
= dev_alloc_skb(len
+ hdr_len
);
1992 spin_unlock(&local
->baplock
);
1993 printk(KERN_DEBUG
"%s: RX failed to allocate skb\n",
1998 memcpy(skb_put(skb
, hdr_len
), &rxdesc
, hdr_len
);
2001 res
= hfa384x_from_bap(dev
, BAP0
, skb_put(skb
, len
), len
);
2002 spin_unlock(&local
->baplock
);
2004 printk(KERN_DEBUG
"%s: RX failed to read "
2005 "frame data\n", dev
->name
);
2009 skb_queue_tail(&local
->rx_list
, skb
);
2010 tasklet_schedule(&local
->rx_tasklet
);
2013 prism2_callback(local
, PRISM2_CALLBACK_RX_END
);
2015 HFA384X_OUTW(HFA384X_EV_RX
, HFA384X_EVACK_OFF
);
2021 dev
->stats
.rx_dropped
++;
2028 /* Called only as a tasklet (software IRQ) */
2029 static void hostap_rx_skb(local_info_t
*local
, struct sk_buff
*skb
)
2031 struct hfa384x_rx_frame
*rxdesc
;
2032 struct net_device
*dev
= skb
->dev
;
2033 struct hostap_80211_rx_status stats
;
2034 int hdrlen
, rx_hdrlen
;
2036 rx_hdrlen
= sizeof(*rxdesc
);
2037 if (skb
->len
< sizeof(*rxdesc
)) {
2038 /* Allow monitor mode to receive shorter frames */
2039 if (local
->iw_mode
== IW_MODE_MONITOR
&&
2040 skb
->len
>= sizeof(*rxdesc
) - 30) {
2041 rx_hdrlen
= skb
->len
;
2048 rxdesc
= (struct hfa384x_rx_frame
*) skb
->data
;
2050 if (local
->frame_dump
& PRISM2_DUMP_RX_HDR
&&
2051 skb
->len
>= sizeof(*rxdesc
))
2052 hostap_dump_rx_header(dev
->name
, rxdesc
);
2054 if (le16_to_cpu(rxdesc
->status
) & HFA384X_RX_STATUS_FCSERR
&&
2055 (!local
->monitor_allow_fcserr
||
2056 local
->iw_mode
!= IW_MODE_MONITOR
))
2059 if (skb
->len
> PRISM2_DATA_MAXLEN
) {
2060 printk(KERN_DEBUG
"%s: RX: len(%d) > MAX(%d)\n",
2061 dev
->name
, skb
->len
, PRISM2_DATA_MAXLEN
);
2065 stats
.mac_time
= le32_to_cpu(rxdesc
->time
);
2066 stats
.signal
= rxdesc
->signal
- local
->rssi_to_dBm
;
2067 stats
.noise
= rxdesc
->silence
- local
->rssi_to_dBm
;
2068 stats
.rate
= rxdesc
->rate
;
2070 /* Convert Prism2 RX structure into IEEE 802.11 header */
2071 hdrlen
= hostap_80211_get_hdrlen(rxdesc
->frame_control
);
2072 if (hdrlen
> rx_hdrlen
)
2075 memmove(skb_pull(skb
, rx_hdrlen
- hdrlen
),
2076 &rxdesc
->frame_control
, hdrlen
);
2078 hostap_80211_rx(dev
, skb
, &stats
);
2086 /* Called only as a tasklet (software IRQ) */
2087 static void hostap_rx_tasklet(unsigned long data
)
2089 local_info_t
*local
= (local_info_t
*) data
;
2090 struct sk_buff
*skb
;
2092 while ((skb
= skb_dequeue(&local
->rx_list
)) != NULL
)
2093 hostap_rx_skb(local
, skb
);
2097 /* Called only from hardware IRQ */
2098 static void prism2_alloc_ev(struct net_device
*dev
)
2100 struct hostap_interface
*iface
;
2101 local_info_t
*local
;
2105 iface
= netdev_priv(dev
);
2106 local
= iface
->local
;
2108 fid
= prism2_read_fid_reg(dev
, HFA384X_ALLOCFID_OFF
);
2110 PDEBUG(DEBUG_FID
, "FID: interrupt: ALLOC - fid=0x%04x\n", fid
);
2112 spin_lock(&local
->txfidlock
);
2113 idx
= local
->next_alloc
;
2116 if (local
->txfid
[idx
] == fid
) {
2117 PDEBUG(DEBUG_FID
, "FID: found matching txfid[%d]\n",
2120 #ifndef final_version
2121 if (local
->intransmitfid
[idx
] == PRISM2_TXFID_EMPTY
)
2122 printk("Already released txfid found at idx "
2124 if (local
->intransmitfid
[idx
] == PRISM2_TXFID_RESERVED
)
2125 printk("Already reserved txfid found at idx "
2128 local
->intransmitfid
[idx
] = PRISM2_TXFID_EMPTY
;
2130 local
->next_alloc
= idx
>= PRISM2_TXFID_COUNT
? 0 :
2133 if (!test_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
) &&
2134 netif_queue_stopped(dev
))
2135 netif_wake_queue(dev
);
2137 spin_unlock(&local
->txfidlock
);
2142 if (idx
>= PRISM2_TXFID_COUNT
)
2144 } while (idx
!= local
->next_alloc
);
2146 printk(KERN_WARNING
"%s: could not find matching txfid (0x%04x, new "
2147 "read 0x%04x) for alloc event\n", dev
->name
, fid
,
2148 HFA384X_INW(HFA384X_ALLOCFID_OFF
));
2149 printk(KERN_DEBUG
"TXFIDs:");
2150 for (idx
= 0; idx
< PRISM2_TXFID_COUNT
; idx
++)
2151 printk(" %04x[%04x]", local
->txfid
[idx
],
2152 local
->intransmitfid
[idx
]);
2154 spin_unlock(&local
->txfidlock
);
2156 /* FIX: should probably schedule reset; reference to one txfid was lost
2157 * completely.. Bad things will happen if we run out of txfids
2158 * Actually, this will cause netdev watchdog to notice TX timeout and
2159 * then card reset after all txfids have been leaked. */
2163 /* Called only as a tasklet (software IRQ) */
2164 static void hostap_tx_callback(local_info_t
*local
,
2165 struct hfa384x_tx_frame
*txdesc
, int ok
,
2168 u16 sw_support
, hdrlen
, len
;
2169 struct sk_buff
*skb
;
2170 struct hostap_tx_callback_info
*cb
;
2172 /* Make sure that frame was from us. */
2173 if (memcmp(txdesc
->addr2
, local
->dev
->dev_addr
, ETH_ALEN
)) {
2174 printk(KERN_DEBUG
"%s: TX callback - foreign frame\n",
2179 sw_support
= le32_to_cpu(txdesc
->sw_support
);
2181 spin_lock(&local
->lock
);
2182 cb
= local
->tx_callback
;
2183 while (cb
!= NULL
&& cb
->idx
!= sw_support
)
2185 spin_unlock(&local
->lock
);
2188 printk(KERN_DEBUG
"%s: could not find TX callback (idx %d)\n",
2189 local
->dev
->name
, sw_support
);
2193 hdrlen
= hostap_80211_get_hdrlen(txdesc
->frame_control
);
2194 len
= le16_to_cpu(txdesc
->data_len
);
2195 skb
= dev_alloc_skb(hdrlen
+ len
);
2197 printk(KERN_DEBUG
"%s: hostap_tx_callback failed to allocate "
2198 "skb\n", local
->dev
->name
);
2202 memcpy(skb_put(skb
, hdrlen
), (void *) &txdesc
->frame_control
, hdrlen
);
2204 memcpy(skb_put(skb
, len
), payload
, len
);
2206 skb
->dev
= local
->dev
;
2207 skb_reset_mac_header(skb
);
2209 cb
->func(skb
, ok
, cb
->data
);
2213 /* Called only as a tasklet (software IRQ) */
2214 static int hostap_tx_compl_read(local_info_t
*local
, int error
,
2215 struct hfa384x_tx_frame
*txdesc
,
2220 struct net_device
*dev
= local
->dev
;
2222 fid
= prism2_read_fid_reg(dev
, HFA384X_TXCOMPLFID_OFF
);
2224 PDEBUG(DEBUG_FID
, "interrupt: TX (err=%d) - fid=0x%04x\n", fid
, error
);
2226 spin_lock(&local
->baplock
);
2227 res
= hfa384x_setup_bap(dev
, BAP0
, fid
, 0);
2229 res
= hfa384x_from_bap(dev
, BAP0
, txdesc
, sizeof(*txdesc
));
2231 PDEBUG(DEBUG_EXTRA
, "%s: TX (err=%d) - fid=0x%04x - could not "
2232 "read txdesc\n", dev
->name
, error
, fid
);
2233 if (res
== -ETIMEDOUT
) {
2234 schedule_work(&local
->reset_queue
);
2239 if (txdesc
->sw_support
) {
2240 len
= le16_to_cpu(txdesc
->data_len
);
2241 if (len
< PRISM2_DATA_MAXLEN
) {
2242 *payload
= kmalloc(len
, GFP_ATOMIC
);
2243 if (*payload
== NULL
||
2244 hfa384x_from_bap(dev
, BAP0
, *payload
, len
)) {
2245 PDEBUG(DEBUG_EXTRA
, "%s: could not read TX "
2246 "frame payload\n", dev
->name
);
2256 spin_unlock(&local
->baplock
);
2262 /* Called only as a tasklet (software IRQ) */
2263 static void prism2_tx_ev(local_info_t
*local
)
2265 struct net_device
*dev
= local
->dev
;
2266 char *payload
= NULL
;
2267 struct hfa384x_tx_frame txdesc
;
2269 if (hostap_tx_compl_read(local
, 0, &txdesc
, &payload
))
2272 if (local
->frame_dump
& PRISM2_DUMP_TX_HDR
) {
2273 PDEBUG(DEBUG_EXTRA
, "%s: TX - status=0x%04x "
2274 "retry_count=%d tx_rate=%d seq_ctrl=%d "
2276 dev
->name
, le16_to_cpu(txdesc
.status
),
2277 txdesc
.retry_count
, txdesc
.tx_rate
,
2278 le16_to_cpu(txdesc
.seq_ctrl
),
2279 le16_to_cpu(txdesc
.duration_id
));
2282 if (txdesc
.sw_support
)
2283 hostap_tx_callback(local
, &txdesc
, 1, payload
);
2287 HFA384X_OUTW(HFA384X_EV_TX
, HFA384X_EVACK_OFF
);
2291 /* Called only as a tasklet (software IRQ) */
2292 static void hostap_sta_tx_exc_tasklet(unsigned long data
)
2294 local_info_t
*local
= (local_info_t
*) data
;
2295 struct sk_buff
*skb
;
2297 while ((skb
= skb_dequeue(&local
->sta_tx_exc_list
)) != NULL
) {
2298 struct hfa384x_tx_frame
*txdesc
=
2299 (struct hfa384x_tx_frame
*) skb
->data
;
2301 if (skb
->len
>= sizeof(*txdesc
)) {
2302 /* Convert Prism2 RX structure into IEEE 802.11 header
2304 int hdrlen
= hostap_80211_get_hdrlen(txdesc
->frame_control
);
2305 memmove(skb_pull(skb
, sizeof(*txdesc
) - hdrlen
),
2306 &txdesc
->frame_control
, hdrlen
);
2308 hostap_handle_sta_tx_exc(local
, skb
);
2315 /* Called only as a tasklet (software IRQ) */
2316 static void prism2_txexc(local_info_t
*local
)
2318 struct net_device
*dev
= local
->dev
;
2321 char *payload
= NULL
;
2322 struct hfa384x_tx_frame txdesc
;
2324 show_dump
= local
->frame_dump
& PRISM2_DUMP_TXEXC_HDR
;
2325 dev
->stats
.tx_errors
++;
2327 res
= hostap_tx_compl_read(local
, 1, &txdesc
, &payload
);
2328 HFA384X_OUTW(HFA384X_EV_TXEXC
, HFA384X_EVACK_OFF
);
2332 status
= le16_to_cpu(txdesc
.status
);
2334 /* We produce a TXDROP event only for retry or lifetime
2335 * exceeded, because that's the only status that really mean
2336 * that this particular node went away.
2337 * Other errors means that *we* screwed up. - Jean II */
2338 if (status
& (HFA384X_TX_STATUS_RETRYERR
| HFA384X_TX_STATUS_AGEDERR
))
2340 union iwreq_data wrqu
;
2342 /* Copy 802.11 dest address. */
2343 memcpy(wrqu
.addr
.sa_data
, txdesc
.addr1
, ETH_ALEN
);
2344 wrqu
.addr
.sa_family
= ARPHRD_ETHER
;
2345 wireless_send_event(dev
, IWEVTXDROP
, &wrqu
, NULL
);
2349 if (local
->iw_mode
== IW_MODE_MASTER
||
2350 local
->iw_mode
== IW_MODE_REPEAT
||
2351 local
->wds_type
& HOSTAP_WDS_AP_CLIENT
) {
2352 struct sk_buff
*skb
;
2353 skb
= dev_alloc_skb(sizeof(txdesc
));
2355 memcpy(skb_put(skb
, sizeof(txdesc
)), &txdesc
,
2357 skb_queue_tail(&local
->sta_tx_exc_list
, skb
);
2358 tasklet_schedule(&local
->sta_tx_exc_tasklet
);
2362 if (txdesc
.sw_support
)
2363 hostap_tx_callback(local
, &txdesc
, 0, payload
);
2369 PDEBUG(DEBUG_EXTRA
, "%s: TXEXC - status=0x%04x (%s%s%s%s)"
2370 " tx_control=%04x\n",
2372 status
& HFA384X_TX_STATUS_RETRYERR
? "[RetryErr]" : "",
2373 status
& HFA384X_TX_STATUS_AGEDERR
? "[AgedErr]" : "",
2374 status
& HFA384X_TX_STATUS_DISCON
? "[Discon]" : "",
2375 status
& HFA384X_TX_STATUS_FORMERR
? "[FormErr]" : "",
2376 le16_to_cpu(txdesc
.tx_control
));
2378 fc
= le16_to_cpu(txdesc
.frame_control
);
2379 PDEBUG(DEBUG_EXTRA
, " retry_count=%d tx_rate=%d fc=0x%04x "
2380 "(%s%s%s::%d%s%s)\n",
2381 txdesc
.retry_count
, txdesc
.tx_rate
, fc
,
2382 ieee80211_is_mgmt(txdesc
.frame_control
) ? "Mgmt" : "",
2383 ieee80211_is_ctl(txdesc
.frame_control
) ? "Ctrl" : "",
2384 ieee80211_is_data(txdesc
.frame_control
) ? "Data" : "",
2385 (fc
& IEEE80211_FCTL_STYPE
) >> 4,
2386 ieee80211_has_tods(txdesc
.frame_control
) ? " ToDS" : "",
2387 ieee80211_has_fromds(txdesc
.frame_control
) ? " FromDS" : "");
2388 PDEBUG(DEBUG_EXTRA
, " A1=%pM A2=%pM A3=%pM A4=%pM\n",
2389 txdesc
.addr1
, txdesc
.addr2
,
2390 txdesc
.addr3
, txdesc
.addr4
);
2394 /* Called only as a tasklet (software IRQ) */
2395 static void hostap_info_tasklet(unsigned long data
)
2397 local_info_t
*local
= (local_info_t
*) data
;
2398 struct sk_buff
*skb
;
2400 while ((skb
= skb_dequeue(&local
->info_list
)) != NULL
) {
2401 hostap_info_process(local
, skb
);
2407 /* Called only as a tasklet (software IRQ) */
2408 static void prism2_info(local_info_t
*local
)
2410 struct net_device
*dev
= local
->dev
;
2413 struct hfa384x_info_frame info
;
2414 struct sk_buff
*skb
;
2416 fid
= HFA384X_INW(HFA384X_INFOFID_OFF
);
2418 spin_lock(&local
->baplock
);
2419 res
= hfa384x_setup_bap(dev
, BAP0
, fid
, 0);
2421 res
= hfa384x_from_bap(dev
, BAP0
, &info
, sizeof(info
));
2423 spin_unlock(&local
->baplock
);
2424 printk(KERN_DEBUG
"Could not get info frame (fid=0x%04x)\n",
2426 if (res
== -ETIMEDOUT
) {
2427 schedule_work(&local
->reset_queue
);
2432 left
= (le16_to_cpu(info
.len
) - 1) * 2;
2434 if (info
.len
& cpu_to_le16(0x8000) || info
.len
== 0 || left
> 2060) {
2435 /* data register seems to give 0x8000 in some error cases even
2436 * though busy bit is not set in offset register;
2437 * in addition, length must be at least 1 due to type field */
2438 spin_unlock(&local
->baplock
);
2439 printk(KERN_DEBUG
"%s: Received info frame with invalid "
2440 "length 0x%04x (type 0x%04x)\n", dev
->name
,
2441 le16_to_cpu(info
.len
), le16_to_cpu(info
.type
));
2445 skb
= dev_alloc_skb(sizeof(info
) + left
);
2447 spin_unlock(&local
->baplock
);
2448 printk(KERN_DEBUG
"%s: Could not allocate skb for info "
2449 "frame\n", dev
->name
);
2453 memcpy(skb_put(skb
, sizeof(info
)), &info
, sizeof(info
));
2454 if (left
> 0 && hfa384x_from_bap(dev
, BAP0
, skb_put(skb
, left
), left
))
2456 spin_unlock(&local
->baplock
);
2457 printk(KERN_WARNING
"%s: Info frame read failed (fid=0x%04x, "
2458 "len=0x%04x, type=0x%04x\n", dev
->name
, fid
,
2459 le16_to_cpu(info
.len
), le16_to_cpu(info
.type
));
2463 spin_unlock(&local
->baplock
);
2465 skb_queue_tail(&local
->info_list
, skb
);
2466 tasklet_schedule(&local
->info_tasklet
);
2469 HFA384X_OUTW(HFA384X_EV_INFO
, HFA384X_EVACK_OFF
);
2473 /* Called only as a tasklet (software IRQ) */
2474 static void hostap_bap_tasklet(unsigned long data
)
2476 local_info_t
*local
= (local_info_t
*) data
;
2477 struct net_device
*dev
= local
->dev
;
2481 if (local
->func
->card_present
&& !local
->func
->card_present(local
))
2484 set_bit(HOSTAP_BITS_BAP_TASKLET
, &local
->bits
);
2486 /* Process all pending BAP events without generating new interrupts
2488 while (frames
-- > 0) {
2489 ev
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
2490 if (ev
== 0xffff || !(ev
& HFA384X_BAP0_EVENTS
))
2492 if (ev
& HFA384X_EV_RX
)
2494 if (ev
& HFA384X_EV_INFO
)
2496 if (ev
& HFA384X_EV_TX
)
2497 prism2_tx_ev(local
);
2498 if (ev
& HFA384X_EV_TXEXC
)
2499 prism2_txexc(local
);
2502 set_bit(HOSTAP_BITS_BAP_TASKLET2
, &local
->bits
);
2503 clear_bit(HOSTAP_BITS_BAP_TASKLET
, &local
->bits
);
2505 /* Enable interrupts for new BAP events */
2506 hfa384x_events_all(dev
);
2507 clear_bit(HOSTAP_BITS_BAP_TASKLET2
, &local
->bits
);
2511 /* Called only from hardware IRQ */
2512 static void prism2_infdrop(struct net_device
*dev
)
2514 static unsigned long last_inquire
= 0;
2516 PDEBUG(DEBUG_EXTRA
, "%s: INFDROP event\n", dev
->name
);
2518 /* some firmware versions seem to get stuck with
2519 * full CommTallies in high traffic load cases; every
2520 * packet will then cause INFDROP event and CommTallies
2521 * info frame will not be sent automatically. Try to
2522 * get out of this state by inquiring CommTallies. */
2523 if (!last_inquire
|| time_after(jiffies
, last_inquire
+ HZ
)) {
2524 hfa384x_cmd_callback(dev
, HFA384X_CMDCODE_INQUIRE
,
2525 HFA384X_INFO_COMMTALLIES
, NULL
, 0);
2526 last_inquire
= jiffies
;
2531 /* Called only from hardware IRQ */
2532 static void prism2_ev_tick(struct net_device
*dev
)
2534 struct hostap_interface
*iface
;
2535 local_info_t
*local
;
2537 static int prev_stuck
= 0;
2539 iface
= netdev_priv(dev
);
2540 local
= iface
->local
;
2542 if (time_after(jiffies
, local
->last_tick_timer
+ 5 * HZ
) &&
2543 local
->last_tick_timer
) {
2544 evstat
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
2545 inten
= HFA384X_INW(HFA384X_INTEN_OFF
);
2547 printk(KERN_INFO
"%s: SW TICK stuck? "
2548 "bits=0x%lx EvStat=%04x IntEn=%04x\n",
2549 dev
->name
, local
->bits
, evstat
, inten
);
2551 local
->sw_tick_stuck
++;
2552 if ((evstat
& HFA384X_BAP0_EVENTS
) &&
2553 (inten
& HFA384X_BAP0_EVENTS
)) {
2554 printk(KERN_INFO
"%s: trying to recover from IRQ "
2555 "hang\n", dev
->name
);
2556 hfa384x_events_no_bap0(dev
);
2564 /* Called only from hardware IRQ */
2565 static void prism2_check_magic(local_info_t
*local
)
2567 /* at least PCI Prism2.5 with bus mastering seems to sometimes
2568 * return 0x0000 in SWSUPPORT0 for unknown reason, but re-reading the
2569 * register once or twice seems to get the correct value.. PCI cards
2570 * cannot anyway be removed during normal operation, so there is not
2571 * really any need for this verification with them. */
2574 #ifndef final_version
2575 static unsigned long last_magic_err
= 0;
2576 struct net_device
*dev
= local
->dev
;
2578 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF
) != HFA384X_MAGIC
) {
2579 if (!local
->hw_ready
)
2581 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF
);
2582 if (time_after(jiffies
, last_magic_err
+ 10 * HZ
)) {
2583 printk("%s: Interrupt, but SWSUPPORT0 does not match: "
2584 "%04X != %04X - card removed?\n", dev
->name
,
2585 HFA384X_INW(HFA384X_SWSUPPORT0_OFF
),
2587 last_magic_err
= jiffies
;
2588 } else if (net_ratelimit()) {
2589 printk(KERN_DEBUG
"%s: interrupt - SWSUPPORT0=%04x "
2590 "MAGIC=%04x\n", dev
->name
,
2591 HFA384X_INW(HFA384X_SWSUPPORT0_OFF
),
2594 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF
) != 0xffff)
2595 schedule_work(&local
->reset_queue
);
2598 #endif /* final_version */
2599 #endif /* !PRISM2_PCI */
2603 /* Called only from hardware IRQ */
2604 static irqreturn_t
prism2_interrupt(int irq
, void *dev_id
)
2606 struct net_device
*dev
= dev_id
;
2607 struct hostap_interface
*iface
;
2608 local_info_t
*local
;
2612 iface
= netdev_priv(dev
);
2613 local
= iface
->local
;
2615 /* Detect early interrupt before driver is fully configued */
2616 spin_lock(&local
->irq_init_lock
);
2617 if (!dev
->base_addr
) {
2618 if (net_ratelimit()) {
2619 printk(KERN_DEBUG
"%s: Interrupt, but dev not configured\n",
2622 spin_unlock(&local
->irq_init_lock
);
2625 spin_unlock(&local
->irq_init_lock
);
2627 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_INTERRUPT
, 0, 0);
2629 if (local
->func
->card_present
&& !local
->func
->card_present(local
)) {
2630 if (net_ratelimit()) {
2631 printk(KERN_DEBUG
"%s: Interrupt, but dev not OK\n",
2637 prism2_check_magic(local
);
2640 ev
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
2642 if (local
->shutdown
)
2644 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF
);
2645 printk(KERN_DEBUG
"%s: prism2_interrupt: ev=0xffff\n",
2650 ev
&= HFA384X_INW(HFA384X_INTEN_OFF
);
2654 if (ev
& HFA384X_EV_CMD
) {
2658 /* Above events are needed even before hw is ready, but other
2659 * events should be skipped during initialization. This may
2660 * change for AllocEv if allocate_fid is implemented without
2662 if (!local
->hw_ready
|| local
->hw_resetting
||
2663 !local
->dev_enabled
) {
2664 ev
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
2665 if (ev
& HFA384X_EV_CMD
)
2667 if ((ev
& HFA384X_EVENT_MASK
) == 0)
2669 if (local
->dev_enabled
&& (ev
& ~HFA384X_EV_TICK
) &&
2671 printk(KERN_DEBUG
"%s: prism2_interrupt: hw "
2672 "not ready; skipping events 0x%04x "
2673 "(IntEn=0x%04x)%s%s%s\n",
2675 HFA384X_INW(HFA384X_INTEN_OFF
),
2676 !local
->hw_ready
? " (!hw_ready)" : "",
2677 local
->hw_resetting
?
2678 " (hw_resetting)" : "",
2679 !local
->dev_enabled
?
2680 " (!dev_enabled)" : "");
2682 HFA384X_OUTW(ev
, HFA384X_EVACK_OFF
);
2686 if (ev
& HFA384X_EV_TICK
) {
2687 prism2_ev_tick(dev
);
2688 HFA384X_OUTW(HFA384X_EV_TICK
, HFA384X_EVACK_OFF
);
2691 if (ev
& HFA384X_EV_ALLOC
) {
2692 prism2_alloc_ev(dev
);
2693 HFA384X_OUTW(HFA384X_EV_ALLOC
, HFA384X_EVACK_OFF
);
2696 /* Reading data from the card is quite time consuming, so do it
2697 * in tasklets. TX, TXEXC, RX, and INFO events will be ACKed
2698 * and unmasked after needed data has been read completely. */
2699 if (ev
& HFA384X_BAP0_EVENTS
) {
2700 hfa384x_events_no_bap0(dev
);
2701 tasklet_schedule(&local
->bap_tasklet
);
2704 #ifndef final_version
2705 if (ev
& HFA384X_EV_WTERR
) {
2706 PDEBUG(DEBUG_EXTRA
, "%s: WTERR event\n", dev
->name
);
2707 HFA384X_OUTW(HFA384X_EV_WTERR
, HFA384X_EVACK_OFF
);
2709 #endif /* final_version */
2711 if (ev
& HFA384X_EV_INFDROP
) {
2712 prism2_infdrop(dev
);
2713 HFA384X_OUTW(HFA384X_EV_INFDROP
, HFA384X_EVACK_OFF
);
2718 if (events
>= PRISM2_MAX_INTERRUPT_EVENTS
) {
2719 PDEBUG(DEBUG_EXTRA
, "prism2_interrupt: >%d events "
2720 "(EvStat=0x%04x)\n",
2721 PRISM2_MAX_INTERRUPT_EVENTS
,
2722 HFA384X_INW(HFA384X_EVSTAT_OFF
));
2726 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_INTERRUPT
, 0, 1);
2727 return IRQ_RETVAL(events
);
2731 static void prism2_check_sta_fw_version(local_info_t
*local
)
2733 struct hfa384x_comp_ident comp
;
2734 int id
, variant
, major
, minor
;
2736 if (hfa384x_get_rid(local
->dev
, HFA384X_RID_STAID
,
2737 &comp
, sizeof(comp
), 1) < 0)
2741 id
= le16_to_cpu(comp
.id
);
2742 if (id
!= HFA384X_COMP_ID_STA
) {
2743 if (id
== HFA384X_COMP_ID_FW_AP
)
2748 major
= __le16_to_cpu(comp
.major
);
2749 minor
= __le16_to_cpu(comp
.minor
);
2750 variant
= __le16_to_cpu(comp
.variant
);
2751 local
->sta_fw_ver
= PRISM2_FW_VER(major
, minor
, variant
);
2753 /* Station firmware versions before 1.4.x seem to have a bug in
2754 * firmware-based WEP encryption when using Host AP mode, so use
2755 * host_encrypt as a default for them. Firmware version 1.4.9 is the
2756 * first one that has been seen to produce correct encryption, but the
2757 * bug might be fixed before that (although, at least 1.4.2 is broken).
2759 local
->fw_encrypt_ok
= local
->sta_fw_ver
>= PRISM2_FW_VER(1,4,9);
2761 if (local
->iw_mode
== IW_MODE_MASTER
&& !local
->host_encrypt
&&
2762 !local
->fw_encrypt_ok
) {
2763 printk(KERN_DEBUG
"%s: defaulting to host-based encryption as "
2764 "a workaround for firmware bug in Host AP mode WEP\n",
2766 local
->host_encrypt
= 1;
2769 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,5,0))
2770 local
->wds_type
|= HOSTAP_WDS_STANDARD_FRAME
;
2772 printk(KERN_DEBUG
"%s: defaulting to bogus WDS frame as a "
2773 "workaround for firmware bug in Host AP mode WDS\n",
2777 hostap_check_sta_fw_version(local
->ap
, local
->sta_fw_ver
);
2781 static void hostap_passive_scan(unsigned long data
)
2783 local_info_t
*local
= (local_info_t
*) data
;
2784 struct net_device
*dev
= local
->dev
;
2787 if (local
->passive_scan_interval
<= 0)
2790 if (local
->passive_scan_state
== PASSIVE_SCAN_LISTEN
) {
2793 /* Even though host system does not really know when the WLAN
2794 * MAC is sending frames, try to avoid changing channels for
2795 * passive scanning when a host-generated frame is being
2797 if (test_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
)) {
2798 printk(KERN_DEBUG
"%s: passive scan detected pending "
2799 "TX - delaying\n", dev
->name
);
2800 local
->passive_scan_timer
.expires
= jiffies
+ HZ
/ 10;
2801 add_timer(&local
->passive_scan_timer
);
2806 local
->passive_scan_channel
++;
2807 if (local
->passive_scan_channel
> 14)
2808 local
->passive_scan_channel
= 1;
2810 } while (!(local
->channel_mask
&
2811 (1 << (local
->passive_scan_channel
- 1))) &&
2814 if (max_tries
== 0) {
2815 printk(KERN_INFO
"%s: no allowed passive scan channels"
2816 " found\n", dev
->name
);
2820 printk(KERN_DEBUG
"%s: passive scan channel %d\n",
2821 dev
->name
, local
->passive_scan_channel
);
2822 chan
= local
->passive_scan_channel
;
2823 local
->passive_scan_state
= PASSIVE_SCAN_WAIT
;
2824 local
->passive_scan_timer
.expires
= jiffies
+ HZ
/ 10;
2826 chan
= local
->channel
;
2827 local
->passive_scan_state
= PASSIVE_SCAN_LISTEN
;
2828 local
->passive_scan_timer
.expires
= jiffies
+
2829 local
->passive_scan_interval
* HZ
;
2832 if (hfa384x_cmd_callback(dev
, HFA384X_CMDCODE_TEST
|
2833 (HFA384X_TEST_CHANGE_CHANNEL
<< 8),
2835 printk(KERN_ERR
"%s: passive scan channel set %d "
2836 "failed\n", dev
->name
, chan
);
2838 add_timer(&local
->passive_scan_timer
);
2842 /* Called only as a scheduled task when communications quality values should
2844 static void handle_comms_qual_update(struct work_struct
*work
)
2846 local_info_t
*local
=
2847 container_of(work
, local_info_t
, comms_qual_update
);
2848 prism2_update_comms_qual(local
->dev
);
2852 /* Software watchdog - called as a timer. Hardware interrupt (Tick event) is
2853 * used to monitor that local->last_tick_timer is being updated. If not,
2854 * interrupt busy-loop is assumed and driver tries to recover by masking out
2856 static void hostap_tick_timer(unsigned long data
)
2858 static unsigned long last_inquire
= 0;
2859 local_info_t
*local
= (local_info_t
*) data
;
2860 local
->last_tick_timer
= jiffies
;
2862 /* Inquire CommTallies every 10 seconds to keep the statistics updated
2863 * more often during low load and when using 32-bit tallies. */
2864 if ((!last_inquire
|| time_after(jiffies
, last_inquire
+ 10 * HZ
)) &&
2865 !local
->hw_downloading
&& local
->hw_ready
&&
2866 !local
->hw_resetting
&& local
->dev_enabled
) {
2867 hfa384x_cmd_callback(local
->dev
, HFA384X_CMDCODE_INQUIRE
,
2868 HFA384X_INFO_COMMTALLIES
, NULL
, 0);
2869 last_inquire
= jiffies
;
2872 if ((local
->last_comms_qual_update
== 0 ||
2873 time_after(jiffies
, local
->last_comms_qual_update
+ 10 * HZ
)) &&
2874 (local
->iw_mode
== IW_MODE_INFRA
||
2875 local
->iw_mode
== IW_MODE_ADHOC
)) {
2876 schedule_work(&local
->comms_qual_update
);
2879 local
->tick_timer
.expires
= jiffies
+ 2 * HZ
;
2880 add_timer(&local
->tick_timer
);
2884 #ifndef PRISM2_NO_PROCFS_DEBUG
2885 static int prism2_registers_proc_read(char *page
, char **start
, off_t off
,
2886 int count
, int *eof
, void *data
)
2889 local_info_t
*local
= (local_info_t
*) data
;
2896 #define SHOW_REG(n) \
2897 p += sprintf(p, #n "=%04x\n", hfa384x_read_reg(local->dev, HFA384X_##n##_OFF))
2915 SHOW_REG(TXCOMPLFID
);
2916 SHOW_REG(SWSUPPORT0
);
2917 SHOW_REG(SWSUPPORT1
);
2918 SHOW_REG(SWSUPPORT2
);
2922 /* Do not read data registers, because they change the state of the
2923 * MAC (offset += 2) */
2924 /* SHOW_REG(DATA0); */
2925 /* SHOW_REG(DATA1); */
2927 SHOW_REG(AUXOFFSET
);
2928 /* SHOW_REG(AUXDATA); */
2932 SHOW_REG(PCI_M0_ADDRH
);
2933 SHOW_REG(PCI_M0_ADDRL
);
2934 SHOW_REG(PCI_M0_LEN
);
2935 SHOW_REG(PCI_M0_CTL
);
2936 SHOW_REG(PCI_STATUS
);
2937 SHOW_REG(PCI_M1_ADDRH
);
2938 SHOW_REG(PCI_M1_ADDRL
);
2939 SHOW_REG(PCI_M1_LEN
);
2940 SHOW_REG(PCI_M1_CTL
);
2941 #endif /* PRISM2_PCI */
2945 #endif /* PRISM2_NO_PROCFS_DEBUG */
2948 struct set_tim_data
{
2949 struct list_head list
;
2954 static int prism2_set_tim(struct net_device
*dev
, int aid
, int set
)
2956 struct list_head
*ptr
;
2957 struct set_tim_data
*new_entry
;
2958 struct hostap_interface
*iface
;
2959 local_info_t
*local
;
2961 iface
= netdev_priv(dev
);
2962 local
= iface
->local
;
2964 new_entry
= kzalloc(sizeof(*new_entry
), GFP_ATOMIC
);
2965 if (new_entry
== NULL
) {
2966 printk(KERN_DEBUG
"%s: prism2_set_tim: kmalloc failed\n",
2970 new_entry
->aid
= aid
;
2971 new_entry
->set
= set
;
2973 spin_lock_bh(&local
->set_tim_lock
);
2974 list_for_each(ptr
, &local
->set_tim_list
) {
2975 struct set_tim_data
*entry
=
2976 list_entry(ptr
, struct set_tim_data
, list
);
2977 if (entry
->aid
== aid
) {
2978 PDEBUG(DEBUG_PS2
, "%s: prism2_set_tim: aid=%d "
2980 local
->dev
->name
, aid
, entry
->set
, set
);
2988 list_add_tail(&new_entry
->list
, &local
->set_tim_list
);
2989 spin_unlock_bh(&local
->set_tim_lock
);
2991 schedule_work(&local
->set_tim_queue
);
2997 static void handle_set_tim_queue(struct work_struct
*work
)
2999 local_info_t
*local
= container_of(work
, local_info_t
, set_tim_queue
);
3000 struct set_tim_data
*entry
;
3005 spin_lock_bh(&local
->set_tim_lock
);
3006 if (!list_empty(&local
->set_tim_list
)) {
3007 entry
= list_entry(local
->set_tim_list
.next
,
3008 struct set_tim_data
, list
);
3009 list_del(&entry
->list
);
3011 spin_unlock_bh(&local
->set_tim_lock
);
3015 PDEBUG(DEBUG_PS2
, "%s: handle_set_tim_queue: aid=%d set=%d\n",
3016 local
->dev
->name
, entry
->aid
, entry
->set
);
3021 if (hostap_set_word(local
->dev
, HFA384X_RID_CNFTIMCTRL
, val
)) {
3022 printk(KERN_DEBUG
"%s: set_tim failed (aid=%d "
3024 local
->dev
->name
, entry
->aid
, entry
->set
);
3032 static void prism2_clear_set_tim_queue(local_info_t
*local
)
3034 struct list_head
*ptr
, *n
;
3036 list_for_each_safe(ptr
, n
, &local
->set_tim_list
) {
3037 struct set_tim_data
*entry
;
3038 entry
= list_entry(ptr
, struct set_tim_data
, list
);
3039 list_del(&entry
->list
);
3046 * HostAP uses two layers of net devices, where the inner
3047 * layer gets called all the time from the outer layer.
3048 * This is a natural nesting, which needs a split lock type.
3050 static struct lock_class_key hostap_netdev_xmit_lock_key
;
3051 static struct lock_class_key hostap_netdev_addr_lock_key
;
3053 static void prism2_set_lockdep_class_one(struct net_device
*dev
,
3054 struct netdev_queue
*txq
,
3057 lockdep_set_class(&txq
->_xmit_lock
,
3058 &hostap_netdev_xmit_lock_key
);
3061 static void prism2_set_lockdep_class(struct net_device
*dev
)
3063 lockdep_set_class(&dev
->addr_list_lock
,
3064 &hostap_netdev_addr_lock_key
);
3065 netdev_for_each_tx_queue(dev
, prism2_set_lockdep_class_one
, NULL
);
3068 static struct net_device
*
3069 prism2_init_local_data(struct prism2_helper_functions
*funcs
, int card_idx
,
3070 struct device
*sdev
)
3072 struct net_device
*dev
;
3073 struct hostap_interface
*iface
;
3074 struct local_info
*local
;
3080 len
= strlen(dev_template
);
3081 if (len
>= IFNAMSIZ
|| strstr(dev_template
, "%d") == NULL
) {
3082 printk(KERN_WARNING
"hostap: Invalid dev_template='%s'\n",
3087 len
= sizeof(struct hostap_interface
) +
3088 3 + sizeof(struct local_info
) +
3089 3 + sizeof(struct ap_data
);
3091 dev
= alloc_etherdev(len
);
3095 iface
= netdev_priv(dev
);
3096 local
= (struct local_info
*) ((((long) (iface
+ 1)) + 3) & ~3);
3097 local
->ap
= (struct ap_data
*) ((((long) (local
+ 1)) + 3) & ~3);
3098 local
->dev
= iface
->dev
= dev
;
3099 iface
->local
= local
;
3100 iface
->type
= HOSTAP_INTERFACE_MASTER
;
3101 INIT_LIST_HEAD(&local
->hostap_interfaces
);
3103 local
->hw_module
= THIS_MODULE
;
3105 #ifdef PRISM2_IO_DEBUG
3106 local
->io_debug_enabled
= 1;
3107 #endif /* PRISM2_IO_DEBUG */
3109 local
->func
= funcs
;
3110 local
->func
->cmd
= hfa384x_cmd
;
3111 local
->func
->read_regs
= hfa384x_read_regs
;
3112 local
->func
->get_rid
= hfa384x_get_rid
;
3113 local
->func
->set_rid
= hfa384x_set_rid
;
3114 local
->func
->hw_enable
= prism2_hw_enable
;
3115 local
->func
->hw_config
= prism2_hw_config
;
3116 local
->func
->hw_reset
= prism2_hw_reset
;
3117 local
->func
->hw_shutdown
= prism2_hw_shutdown
;
3118 local
->func
->reset_port
= prism2_reset_port
;
3119 local
->func
->schedule_reset
= prism2_schedule_reset
;
3120 #ifdef PRISM2_DOWNLOAD_SUPPORT
3121 local
->func
->read_aux
= prism2_download_aux_dump
;
3122 local
->func
->download
= prism2_download
;
3123 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3124 local
->func
->tx
= prism2_tx_80211
;
3125 local
->func
->set_tim
= prism2_set_tim
;
3126 local
->func
->need_tx_headroom
= 0; /* no need to add txdesc in
3127 * skb->data (FIX: maybe for DMA bus
3132 rwlock_init(&local
->iface_lock
);
3133 spin_lock_init(&local
->txfidlock
);
3134 spin_lock_init(&local
->cmdlock
);
3135 spin_lock_init(&local
->baplock
);
3136 spin_lock_init(&local
->lock
);
3137 spin_lock_init(&local
->irq_init_lock
);
3138 mutex_init(&local
->rid_bap_mtx
);
3140 if (card_idx
< 0 || card_idx
>= MAX_PARM_DEVICES
)
3142 local
->card_idx
= card_idx
;
3144 len
= strlen(essid
);
3145 memcpy(local
->essid
, essid
,
3146 len
> MAX_SSID_LEN
? MAX_SSID_LEN
: len
);
3147 local
->essid
[MAX_SSID_LEN
] = '\0';
3148 i
= GET_INT_PARM(iw_mode
, card_idx
);
3149 if ((i
>= IW_MODE_ADHOC
&& i
<= IW_MODE_REPEAT
) ||
3150 i
== IW_MODE_MONITOR
) {
3153 printk(KERN_WARNING
"prism2: Unknown iw_mode %d; using "
3154 "IW_MODE_MASTER\n", i
);
3155 local
->iw_mode
= IW_MODE_MASTER
;
3157 local
->channel
= GET_INT_PARM(channel
, card_idx
);
3158 local
->beacon_int
= GET_INT_PARM(beacon_int
, card_idx
);
3159 local
->dtim_period
= GET_INT_PARM(dtim_period
, card_idx
);
3160 local
->wds_max_connections
= 16;
3161 local
->tx_control
= HFA384X_TX_CTRL_FLAGS
;
3162 local
->manual_retry_count
= -1;
3163 local
->rts_threshold
= 2347;
3164 local
->fragm_threshold
= 2346;
3165 local
->rssi_to_dBm
= 100; /* default; to be overriden by
3166 * cnfDbmAdjust, if available */
3167 local
->auth_algs
= PRISM2_AUTH_OPEN
| PRISM2_AUTH_SHARED_KEY
;
3168 local
->sram_type
= -1;
3169 local
->scan_channel_mask
= 0xffff;
3170 local
->monitor_type
= PRISM2_MONITOR_RADIOTAP
;
3172 /* Initialize task queue structures */
3173 INIT_WORK(&local
->reset_queue
, handle_reset_queue
);
3174 INIT_WORK(&local
->set_multicast_list_queue
,
3175 hostap_set_multicast_list_queue
);
3177 INIT_WORK(&local
->set_tim_queue
, handle_set_tim_queue
);
3178 INIT_LIST_HEAD(&local
->set_tim_list
);
3179 spin_lock_init(&local
->set_tim_lock
);
3181 INIT_WORK(&local
->comms_qual_update
, handle_comms_qual_update
);
3183 /* Initialize tasklets for handling hardware IRQ related operations
3184 * outside hw IRQ handler */
3185 #define HOSTAP_TASKLET_INIT(q, f, d) \
3186 do { memset((q), 0, sizeof(*(q))); (q)->func = (f); (q)->data = (d); } \
3188 HOSTAP_TASKLET_INIT(&local
->bap_tasklet
, hostap_bap_tasklet
,
3189 (unsigned long) local
);
3191 HOSTAP_TASKLET_INIT(&local
->info_tasklet
, hostap_info_tasklet
,
3192 (unsigned long) local
);
3193 hostap_info_init(local
);
3195 HOSTAP_TASKLET_INIT(&local
->rx_tasklet
,
3196 hostap_rx_tasklet
, (unsigned long) local
);
3197 skb_queue_head_init(&local
->rx_list
);
3199 HOSTAP_TASKLET_INIT(&local
->sta_tx_exc_tasklet
,
3200 hostap_sta_tx_exc_tasklet
, (unsigned long) local
);
3201 skb_queue_head_init(&local
->sta_tx_exc_list
);
3203 INIT_LIST_HEAD(&local
->cmd_queue
);
3204 init_waitqueue_head(&local
->hostscan_wq
);
3206 lib80211_crypt_info_init(&local
->crypt_info
, dev
->name
, &local
->lock
);
3208 init_timer(&local
->passive_scan_timer
);
3209 local
->passive_scan_timer
.data
= (unsigned long) local
;
3210 local
->passive_scan_timer
.function
= hostap_passive_scan
;
3212 init_timer(&local
->tick_timer
);
3213 local
->tick_timer
.data
= (unsigned long) local
;
3214 local
->tick_timer
.function
= hostap_tick_timer
;
3215 local
->tick_timer
.expires
= jiffies
+ 2 * HZ
;
3216 add_timer(&local
->tick_timer
);
3218 INIT_LIST_HEAD(&local
->bss_list
);
3220 hostap_setup_dev(dev
, local
, HOSTAP_INTERFACE_MASTER
);
3222 dev
->type
= ARPHRD_IEEE80211
;
3223 dev
->header_ops
= &hostap_80211_ops
;
3226 ret
= dev_alloc_name(dev
, "wifi%d");
3227 SET_NETDEV_DEV(dev
, sdev
);
3229 ret
= register_netdevice(dev
);
3231 prism2_set_lockdep_class(dev
);
3234 printk(KERN_WARNING
"%s: register netdevice failed!\n",
3238 printk(KERN_INFO
"%s: Registered netdevice %s\n", dev_info
, dev
->name
);
3240 hostap_init_data(local
);
3249 static int hostap_hw_ready(struct net_device
*dev
)
3251 struct hostap_interface
*iface
;
3252 struct local_info
*local
;
3254 iface
= netdev_priv(dev
);
3255 local
= iface
->local
;
3256 local
->ddev
= hostap_add_interface(local
, HOSTAP_INTERFACE_MAIN
, 0,
3260 if (local
->iw_mode
== IW_MODE_INFRA
||
3261 local
->iw_mode
== IW_MODE_ADHOC
) {
3262 netif_carrier_off(local
->dev
);
3263 netif_carrier_off(local
->ddev
);
3265 hostap_init_proc(local
);
3266 #ifndef PRISM2_NO_PROCFS_DEBUG
3267 create_proc_read_entry("registers", 0, local
->proc
,
3268 prism2_registers_proc_read
, local
);
3269 #endif /* PRISM2_NO_PROCFS_DEBUG */
3270 hostap_init_ap_proc(local
);
3278 static void prism2_free_local_data(struct net_device
*dev
)
3280 struct hostap_tx_callback_info
*tx_cb
, *tx_cb_prev
;
3282 struct hostap_interface
*iface
;
3283 struct local_info
*local
;
3284 struct list_head
*ptr
, *n
;
3289 iface
= netdev_priv(dev
);
3290 local
= iface
->local
;
3292 /* Unregister all netdevs before freeing local data. */
3293 list_for_each_safe(ptr
, n
, &local
->hostap_interfaces
) {
3294 iface
= list_entry(ptr
, struct hostap_interface
, list
);
3295 if (iface
->type
== HOSTAP_INTERFACE_MASTER
) {
3296 /* special handling for this interface below */
3299 hostap_remove_interface(iface
->dev
, 0, 1);
3302 unregister_netdev(local
->dev
);
3304 flush_scheduled_work();
3306 lib80211_crypt_info_free(&local
->crypt_info
);
3308 if (timer_pending(&local
->passive_scan_timer
))
3309 del_timer(&local
->passive_scan_timer
);
3311 if (timer_pending(&local
->tick_timer
))
3312 del_timer(&local
->tick_timer
);
3314 prism2_clear_cmd_queue(local
);
3316 skb_queue_purge(&local
->info_list
);
3317 skb_queue_purge(&local
->rx_list
);
3318 skb_queue_purge(&local
->sta_tx_exc_list
);
3320 if (local
->dev_enabled
)
3321 prism2_callback(local
, PRISM2_CALLBACK_DISABLE
);
3323 if (local
->ap
!= NULL
)
3324 hostap_free_data(local
->ap
);
3326 #ifndef PRISM2_NO_PROCFS_DEBUG
3327 if (local
->proc
!= NULL
)
3328 remove_proc_entry("registers", local
->proc
);
3329 #endif /* PRISM2_NO_PROCFS_DEBUG */
3330 hostap_remove_proc(local
);
3332 tx_cb
= local
->tx_callback
;
3333 while (tx_cb
!= NULL
) {
3335 tx_cb
= tx_cb
->next
;
3339 hostap_set_hostapd(local
, 0, 0);
3340 hostap_set_hostapd_sta(local
, 0, 0);
3342 for (i
= 0; i
< PRISM2_FRAG_CACHE_LEN
; i
++) {
3343 if (local
->frag_cache
[i
].skb
!= NULL
)
3344 dev_kfree_skb(local
->frag_cache
[i
].skb
);
3347 #ifdef PRISM2_DOWNLOAD_SUPPORT
3348 prism2_download_free_data(local
->dl_pri
);
3349 prism2_download_free_data(local
->dl_sec
);
3350 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3352 prism2_clear_set_tim_queue(local
);
3354 list_for_each_safe(ptr
, n
, &local
->bss_list
) {
3355 struct hostap_bss_info
*bss
=
3356 list_entry(ptr
, struct hostap_bss_info
, list
);
3361 kfree(local
->last_scan_results
);
3362 kfree(local
->generic_elem
);
3364 free_netdev(local
->dev
);
3368 #if (defined(PRISM2_PCI) && defined(CONFIG_PM)) || defined(PRISM2_PCCARD)
3369 static void prism2_suspend(struct net_device
*dev
)
3371 struct hostap_interface
*iface
;
3372 struct local_info
*local
;
3373 union iwreq_data wrqu
;
3375 iface
= netdev_priv(dev
);
3376 local
= iface
->local
;
3378 /* Send disconnect event, e.g., to trigger reassociation after resume
3379 * if wpa_supplicant is used. */
3380 memset(&wrqu
, 0, sizeof(wrqu
));
3381 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
3382 wireless_send_event(local
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
3384 /* Disable hardware and firmware */
3385 prism2_hw_shutdown(dev
, 0);
3387 #endif /* (PRISM2_PCI && CONFIG_PM) || PRISM2_PCCARD */
3390 /* These might at some point be compiled separately and used as separate
3391 * kernel modules or linked into one */
3392 #ifdef PRISM2_DOWNLOAD_SUPPORT
3393 #include "hostap_download.c"
3394 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3396 #ifdef PRISM2_CALLBACK
3397 /* External hostap_callback.c file can be used to, e.g., blink activity led.
3398 * This can use platform specific code and must define prism2_callback()
3399 * function (if PRISM2_CALLBACK is not defined, these function calls are not
3401 #include "hostap_callback.c"
3402 #endif /* PRISM2_CALLBACK */