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
);
935 hostap_restore_power(dev
);
940 static void hfa384x_disable_interrupts(struct net_device
*dev
)
942 /* disable interrupts and clear event status */
943 HFA384X_OUTW(0, HFA384X_INTEN_OFF
);
944 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF
);
948 static void hfa384x_enable_interrupts(struct net_device
*dev
)
950 /* ack pending events and enable interrupts from selected events */
951 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF
);
952 HFA384X_OUTW(HFA384X_EVENT_MASK
, HFA384X_INTEN_OFF
);
956 static void hfa384x_events_no_bap0(struct net_device
*dev
)
958 HFA384X_OUTW(HFA384X_EVENT_MASK
& ~HFA384X_BAP0_EVENTS
,
963 static void hfa384x_events_all(struct net_device
*dev
)
965 HFA384X_OUTW(HFA384X_EVENT_MASK
, HFA384X_INTEN_OFF
);
969 static void hfa384x_events_only_cmd(struct net_device
*dev
)
971 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_INTEN_OFF
);
975 static u16
hfa384x_allocate_fid(struct net_device
*dev
, int len
)
980 /* FIX: this could be replace with hfa384x_cmd() if the Alloc event
981 * below would be handled like CmdCompl event (sleep here, wake up from
982 * interrupt handler */
983 if (hfa384x_cmd_wait(dev
, HFA384X_CMDCODE_ALLOC
, len
)) {
984 printk(KERN_DEBUG
"%s: cannot allocate fid, len=%d\n",
989 delay
= jiffies
+ HFA384X_ALLOC_COMPL_TIMEOUT
;
990 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_ALLOC
) &&
991 time_before(jiffies
, delay
))
993 if (!(HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_ALLOC
)) {
994 printk("%s: fid allocate, len=%d - timeout\n", dev
->name
, len
);
998 fid
= HFA384X_INW(HFA384X_ALLOCFID_OFF
);
999 HFA384X_OUTW(HFA384X_EV_ALLOC
, HFA384X_EVACK_OFF
);
1005 static int prism2_reset_port(struct net_device
*dev
)
1007 struct hostap_interface
*iface
;
1008 local_info_t
*local
;
1011 iface
= netdev_priv(dev
);
1012 local
= iface
->local
;
1014 if (!local
->dev_enabled
)
1017 res
= hfa384x_cmd(dev
, HFA384X_CMDCODE_DISABLE
, 0,
1020 printk(KERN_DEBUG
"%s: reset port failed to disable port\n",
1023 res
= hfa384x_cmd(dev
, HFA384X_CMDCODE_ENABLE
, 0,
1026 printk(KERN_DEBUG
"%s: reset port failed to enable "
1027 "port\n", dev
->name
);
1030 /* It looks like at least some STA firmware versions reset
1031 * fragmentation threshold back to 2346 after enable command. Restore
1032 * the configured value, if it differs from this default. */
1033 if (local
->fragm_threshold
!= 2346 &&
1034 hostap_set_word(dev
, HFA384X_RID_FRAGMENTATIONTHRESHOLD
,
1035 local
->fragm_threshold
)) {
1036 printk(KERN_DEBUG
"%s: failed to restore fragmentation "
1037 "threshold (%d) after Port0 enable\n",
1038 dev
->name
, local
->fragm_threshold
);
1041 /* Some firmwares lose antenna selection settings on reset */
1042 (void) hostap_set_antsel(local
);
1048 static int prism2_get_version_info(struct net_device
*dev
, u16 rid
,
1051 struct hfa384x_comp_ident comp
;
1052 struct hostap_interface
*iface
;
1053 local_info_t
*local
;
1055 iface
= netdev_priv(dev
);
1056 local
= iface
->local
;
1058 if (local
->no_pri
) {
1059 /* PRI f/w not yet available - cannot read RIDs */
1062 if (hfa384x_get_rid(dev
, rid
, &comp
, sizeof(comp
), 1) < 0) {
1063 printk(KERN_DEBUG
"Could not get RID for component %s\n", txt
);
1067 printk(KERN_INFO
"%s: %s: id=0x%02x v%d.%d.%d\n", dev
->name
, txt
,
1068 __le16_to_cpu(comp
.id
), __le16_to_cpu(comp
.major
),
1069 __le16_to_cpu(comp
.minor
), __le16_to_cpu(comp
.variant
));
1074 static int prism2_setup_rids(struct net_device
*dev
)
1076 struct hostap_interface
*iface
;
1077 local_info_t
*local
;
1081 iface
= netdev_priv(dev
);
1082 local
= iface
->local
;
1084 hostap_set_word(dev
, HFA384X_RID_TICKTIME
, 2000);
1086 if (!local
->fw_ap
) {
1087 u16 tmp1
= hostap_get_porttype(local
);
1088 ret
= hostap_set_word(dev
, HFA384X_RID_CNFPORTTYPE
, tmp1
);
1090 printk("%s: Port type setting to %d failed\n",
1096 /* Setting SSID to empty string seems to kill the card in Host AP mode
1098 if (local
->iw_mode
!= IW_MODE_MASTER
|| local
->essid
[0] != '\0') {
1099 ret
= hostap_set_string(dev
, HFA384X_RID_CNFOWNSSID
,
1102 printk("%s: AP own SSID setting failed\n", dev
->name
);
1107 ret
= hostap_set_word(dev
, HFA384X_RID_CNFMAXDATALEN
,
1108 PRISM2_DATA_MAXLEN
);
1110 printk("%s: MAC data length setting to %d failed\n",
1111 dev
->name
, PRISM2_DATA_MAXLEN
);
1115 if (hfa384x_get_rid(dev
, HFA384X_RID_CHANNELLIST
, &tmp
, 2, 1) < 0) {
1116 printk("%s: Channel list read failed\n", dev
->name
);
1120 local
->channel_mask
= le16_to_cpu(tmp
);
1122 if (local
->channel
< 1 || local
->channel
> 14 ||
1123 !(local
->channel_mask
& (1 << (local
->channel
- 1)))) {
1124 printk(KERN_WARNING
"%s: Channel setting out of range "
1125 "(%d)!\n", dev
->name
, local
->channel
);
1130 ret
= hostap_set_word(dev
, HFA384X_RID_CNFOWNCHANNEL
, local
->channel
);
1132 printk("%s: Channel setting to %d failed\n",
1133 dev
->name
, local
->channel
);
1137 ret
= hostap_set_word(dev
, HFA384X_RID_CNFBEACONINT
,
1140 printk("%s: Beacon interval setting to %d failed\n",
1141 dev
->name
, local
->beacon_int
);
1142 /* this may fail with Symbol/Lucent firmware */
1143 if (ret
== -ETIMEDOUT
)
1147 ret
= hostap_set_word(dev
, HFA384X_RID_CNFOWNDTIMPERIOD
,
1148 local
->dtim_period
);
1150 printk("%s: DTIM period setting to %d failed\n",
1151 dev
->name
, local
->dtim_period
);
1152 /* this may fail with Symbol/Lucent firmware */
1153 if (ret
== -ETIMEDOUT
)
1157 ret
= hostap_set_word(dev
, HFA384X_RID_PROMISCUOUSMODE
,
1160 printk(KERN_INFO
"%s: Setting promiscuous mode (%d) failed\n",
1161 dev
->name
, local
->is_promisc
);
1163 if (!local
->fw_ap
) {
1164 ret
= hostap_set_string(dev
, HFA384X_RID_CNFDESIREDSSID
,
1167 printk("%s: Desired SSID setting failed\n", dev
->name
);
1172 /* Setup TXRateControl, defaults to allow use of 1, 2, 5.5, and
1173 * 11 Mbps in automatic TX rate fallback and 1 and 2 Mbps as basic
1175 if (local
->tx_rate_control
== 0) {
1176 local
->tx_rate_control
=
1177 HFA384X_RATES_1MBPS
|
1178 HFA384X_RATES_2MBPS
|
1179 HFA384X_RATES_5MBPS
|
1180 HFA384X_RATES_11MBPS
;
1182 if (local
->basic_rates
== 0)
1183 local
->basic_rates
= HFA384X_RATES_1MBPS
| HFA384X_RATES_2MBPS
;
1185 if (!local
->fw_ap
) {
1186 ret
= hostap_set_word(dev
, HFA384X_RID_TXRATECONTROL
,
1187 local
->tx_rate_control
);
1189 printk("%s: TXRateControl setting to %d failed\n",
1190 dev
->name
, local
->tx_rate_control
);
1194 ret
= hostap_set_word(dev
, HFA384X_RID_CNFSUPPORTEDRATES
,
1195 local
->tx_rate_control
);
1197 printk("%s: cnfSupportedRates setting to %d failed\n",
1198 dev
->name
, local
->tx_rate_control
);
1201 ret
= hostap_set_word(dev
, HFA384X_RID_CNFBASICRATES
,
1202 local
->basic_rates
);
1204 printk("%s: cnfBasicRates setting to %d failed\n",
1205 dev
->name
, local
->basic_rates
);
1208 ret
= hostap_set_word(dev
, HFA384X_RID_CREATEIBSS
, 1);
1210 printk("%s: Create IBSS setting to 1 failed\n",
1215 if (local
->name_set
)
1216 (void) hostap_set_string(dev
, HFA384X_RID_CNFOWNNAME
,
1219 if (hostap_set_encryption(local
)) {
1220 printk(KERN_INFO
"%s: could not configure encryption\n",
1224 (void) hostap_set_antsel(local
);
1226 if (hostap_set_roaming(local
)) {
1227 printk(KERN_INFO
"%s: could not set host roaming\n",
1231 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,6,3) &&
1232 hostap_set_word(dev
, HFA384X_RID_CNFENHSECURITY
, local
->enh_sec
))
1233 printk(KERN_INFO
"%s: cnfEnhSecurity setting to 0x%x failed\n",
1234 dev
->name
, local
->enh_sec
);
1236 /* 32-bit tallies were added in STA f/w 0.8.0, but they were apparently
1237 * not working correctly (last seven counters report bogus values).
1238 * This has been fixed in 0.8.2, so enable 32-bit tallies only
1239 * beginning with that firmware version. Another bug fix for 32-bit
1240 * tallies in 1.4.0; should 16-bit tallies be used for some other
1242 if (local
->sta_fw_ver
>= PRISM2_FW_VER(0,8,2)) {
1243 if (hostap_set_word(dev
, HFA384X_RID_CNFTHIRTY2TALLY
, 1)) {
1244 printk(KERN_INFO
"%s: cnfThirty2Tally setting "
1245 "failed\n", dev
->name
);
1246 local
->tallies32
= 0;
1248 local
->tallies32
= 1;
1250 local
->tallies32
= 0;
1252 hostap_set_auth_algs(local
);
1254 if (hostap_set_word(dev
, HFA384X_RID_FRAGMENTATIONTHRESHOLD
,
1255 local
->fragm_threshold
)) {
1256 printk(KERN_INFO
"%s: setting FragmentationThreshold to %d "
1257 "failed\n", dev
->name
, local
->fragm_threshold
);
1260 if (hostap_set_word(dev
, HFA384X_RID_RTSTHRESHOLD
,
1261 local
->rts_threshold
)) {
1262 printk(KERN_INFO
"%s: setting RTSThreshold to %d failed\n",
1263 dev
->name
, local
->rts_threshold
);
1266 if (local
->manual_retry_count
>= 0 &&
1267 hostap_set_word(dev
, HFA384X_RID_CNFALTRETRYCOUNT
,
1268 local
->manual_retry_count
)) {
1269 printk(KERN_INFO
"%s: setting cnfAltRetryCount to %d failed\n",
1270 dev
->name
, local
->manual_retry_count
);
1273 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,3,1) &&
1274 hfa384x_get_rid(dev
, HFA384X_RID_CNFDBMADJUST
, &tmp
, 2, 1) == 2) {
1275 local
->rssi_to_dBm
= le16_to_cpu(tmp
);
1278 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,7,0) && local
->wpa
&&
1279 hostap_set_word(dev
, HFA384X_RID_SSNHANDLINGMODE
, 1)) {
1280 printk(KERN_INFO
"%s: setting ssnHandlingMode to 1 failed\n",
1284 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,7,0) && local
->generic_elem
&&
1285 hfa384x_set_rid(dev
, HFA384X_RID_GENERICELEMENT
,
1286 local
->generic_elem
, local
->generic_elem_len
)) {
1287 printk(KERN_INFO
"%s: setting genericElement failed\n",
1296 static int prism2_hw_init(struct net_device
*dev
, int initial
)
1298 struct hostap_interface
*iface
;
1299 local_info_t
*local
;
1301 unsigned long start
, delay
;
1303 PDEBUG(DEBUG_FLOW
, "prism2_hw_init()\n");
1305 iface
= netdev_priv(dev
);
1306 local
= iface
->local
;
1308 clear_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
);
1311 /* initialize HFA 384x */
1312 ret
= hfa384x_cmd_no_wait(dev
, HFA384X_CMDCODE_INIT
, 0);
1314 printk(KERN_INFO
"%s: first command failed - assuming card "
1315 "does not have primary firmware\n", dev_info
);
1318 if (first
&& (HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_CMD
)) {
1319 /* EvStat has Cmd bit set in some cases, so retry once if no
1320 * wait was needed */
1321 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_EVACK_OFF
);
1322 printk(KERN_DEBUG
"%s: init command completed too quickly - "
1323 "retrying\n", dev
->name
);
1329 delay
= jiffies
+ HFA384X_INIT_TIMEOUT
;
1330 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_CMD
) &&
1331 time_before(jiffies
, delay
))
1333 if (!(HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_CMD
)) {
1334 printk(KERN_DEBUG
"%s: assuming no Primary image in "
1335 "flash - card initialization not completed\n",
1338 #ifdef PRISM2_DOWNLOAD_SUPPORT
1339 if (local
->sram_type
== -1)
1340 local
->sram_type
= prism2_get_ram_size(local
);
1341 #endif /* PRISM2_DOWNLOAD_SUPPORT */
1345 printk(KERN_DEBUG
"prism2_hw_init: initialized in %lu ms\n",
1346 (jiffies
- start
) * 1000 / HZ
);
1347 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_EVACK_OFF
);
1352 static int prism2_hw_init2(struct net_device
*dev
, int initial
)
1354 struct hostap_interface
*iface
;
1355 local_info_t
*local
;
1358 iface
= netdev_priv(dev
);
1359 local
= iface
->local
;
1361 #ifdef PRISM2_DOWNLOAD_SUPPORT
1366 local
->pda
= prism2_read_pda(dev
);
1367 #endif /* PRISM2_DOWNLOAD_SUPPORT */
1369 hfa384x_disable_interrupts(dev
);
1371 #ifndef final_version
1372 HFA384X_OUTW(HFA384X_MAGIC
, HFA384X_SWSUPPORT0_OFF
);
1373 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF
) != HFA384X_MAGIC
) {
1374 printk("SWSUPPORT0 write/read failed: %04X != %04X\n",
1375 HFA384X_INW(HFA384X_SWSUPPORT0_OFF
), HFA384X_MAGIC
);
1380 if (initial
|| local
->pri_only
) {
1381 hfa384x_events_only_cmd(dev
);
1382 /* get card version information */
1383 if (prism2_get_version_info(dev
, HFA384X_RID_NICID
, "NIC") ||
1384 prism2_get_version_info(dev
, HFA384X_RID_PRIID
, "PRI")) {
1385 hfa384x_disable_interrupts(dev
);
1389 if (prism2_get_version_info(dev
, HFA384X_RID_STAID
, "STA")) {
1390 printk(KERN_DEBUG
"%s: Failed to read STA f/w version "
1391 "- only Primary f/w present\n", dev
->name
);
1392 local
->pri_only
= 1;
1395 local
->pri_only
= 0;
1396 hfa384x_disable_interrupts(dev
);
1399 /* FIX: could convert allocate_fid to use sleeping CmdCompl wait and
1400 * enable interrupts before this. This would also require some sort of
1401 * sleeping AllocEv waiting */
1403 /* allocate TX FIDs */
1404 local
->txfid_len
= PRISM2_TXFID_LEN
;
1405 for (i
= 0; i
< PRISM2_TXFID_COUNT
; i
++) {
1406 local
->txfid
[i
] = hfa384x_allocate_fid(dev
, local
->txfid_len
);
1407 if (local
->txfid
[i
] == 0xffff && local
->txfid_len
> 1600) {
1408 local
->txfid
[i
] = hfa384x_allocate_fid(dev
, 1600);
1409 if (local
->txfid
[i
] != 0xffff) {
1410 printk(KERN_DEBUG
"%s: Using shorter TX FID "
1411 "(1600 bytes)\n", dev
->name
);
1412 local
->txfid_len
= 1600;
1415 if (local
->txfid
[i
] == 0xffff)
1417 local
->intransmitfid
[i
] = PRISM2_TXFID_EMPTY
;
1420 hfa384x_events_only_cmd(dev
);
1423 struct list_head
*ptr
;
1424 prism2_check_sta_fw_version(local
);
1426 if (hfa384x_get_rid(dev
, HFA384X_RID_CNFOWNMACADDR
,
1427 dev
->dev_addr
, 6, 1) < 0) {
1428 printk("%s: could not get own MAC address\n",
1431 list_for_each(ptr
, &local
->hostap_interfaces
) {
1432 iface
= list_entry(ptr
, struct hostap_interface
, list
);
1433 memcpy(iface
->dev
->dev_addr
, dev
->dev_addr
, ETH_ALEN
);
1435 } else if (local
->fw_ap
)
1436 prism2_check_sta_fw_version(local
);
1438 prism2_setup_rids(dev
);
1440 /* MAC is now configured, but port 0 is not yet enabled */
1445 printk(KERN_WARNING
"%s: Initialization failed\n", dev_info
);
1450 static int prism2_hw_enable(struct net_device
*dev
, int initial
)
1452 struct hostap_interface
*iface
;
1453 local_info_t
*local
;
1456 iface
= netdev_priv(dev
);
1457 local
= iface
->local
;
1458 was_resetting
= local
->hw_resetting
;
1460 if (hfa384x_cmd(dev
, HFA384X_CMDCODE_ENABLE
, 0, NULL
, NULL
)) {
1461 printk("%s: MAC port 0 enabling failed\n", dev
->name
);
1465 local
->hw_ready
= 1;
1466 local
->hw_reset_tries
= 0;
1467 local
->hw_resetting
= 0;
1468 hfa384x_enable_interrupts(dev
);
1470 /* at least D-Link DWL-650 seems to require additional port reset
1471 * before it starts acting as an AP, so reset port automatically
1472 * here just in case */
1473 if (initial
&& prism2_reset_port(dev
)) {
1474 printk("%s: MAC port 0 reseting failed\n", dev
->name
);
1478 if (was_resetting
&& netif_queue_stopped(dev
)) {
1479 /* If hw_reset() was called during pending transmit, netif
1480 * queue was stopped. Wake it up now since the wlan card has
1482 netif_wake_queue(dev
);
1489 static int prism2_hw_config(struct net_device
*dev
, int initial
)
1491 struct hostap_interface
*iface
;
1492 local_info_t
*local
;
1494 iface
= netdev_priv(dev
);
1495 local
= iface
->local
;
1497 if (local
->hw_downloading
)
1500 if (prism2_hw_init(dev
, initial
)) {
1501 return local
->no_pri
? 0 : 1;
1504 if (prism2_hw_init2(dev
, initial
))
1507 /* Enable firmware if secondary image is loaded and at least one of the
1508 * netdevices is up. */
1509 if (!local
->pri_only
&&
1510 (initial
== 0 || (initial
== 2 && local
->num_dev_open
> 0))) {
1511 if (!local
->dev_enabled
)
1512 prism2_callback(local
, PRISM2_CALLBACK_ENABLE
);
1513 local
->dev_enabled
= 1;
1514 return prism2_hw_enable(dev
, initial
);
1521 static void prism2_hw_shutdown(struct net_device
*dev
, int no_disable
)
1523 struct hostap_interface
*iface
;
1524 local_info_t
*local
;
1526 iface
= netdev_priv(dev
);
1527 local
= iface
->local
;
1529 /* Allow only command completion events during disable */
1530 hfa384x_events_only_cmd(dev
);
1532 local
->hw_ready
= 0;
1533 if (local
->dev_enabled
)
1534 prism2_callback(local
, PRISM2_CALLBACK_DISABLE
);
1535 local
->dev_enabled
= 0;
1537 if (local
->func
->card_present
&& !local
->func
->card_present(local
)) {
1538 printk(KERN_DEBUG
"%s: card already removed or not configured "
1539 "during shutdown\n", dev
->name
);
1543 if ((no_disable
& HOSTAP_HW_NO_DISABLE
) == 0 &&
1544 hfa384x_cmd(dev
, HFA384X_CMDCODE_DISABLE
, 0, NULL
, NULL
))
1545 printk(KERN_WARNING
"%s: Shutdown failed\n", dev_info
);
1547 hfa384x_disable_interrupts(dev
);
1549 if (no_disable
& HOSTAP_HW_ENABLE_CMDCOMPL
)
1550 hfa384x_events_only_cmd(dev
);
1552 prism2_clear_cmd_queue(local
);
1556 static void prism2_hw_reset(struct net_device
*dev
)
1558 struct hostap_interface
*iface
;
1559 local_info_t
*local
;
1562 static long last_reset
= 0;
1564 /* do not reset card more than once per second to avoid ending up in a
1565 * busy loop reseting the card */
1566 if (time_before_eq(jiffies
, last_reset
+ HZ
))
1568 last_reset
= jiffies
;
1571 iface
= netdev_priv(dev
);
1572 local
= iface
->local
;
1574 if (in_interrupt()) {
1575 printk(KERN_DEBUG
"%s: driver bug - prism2_hw_reset() called "
1576 "in interrupt context\n", dev
->name
);
1580 if (local
->hw_downloading
)
1583 if (local
->hw_resetting
) {
1584 printk(KERN_WARNING
"%s: %s: already resetting card - "
1585 "ignoring reset request\n", dev_info
, dev
->name
);
1589 local
->hw_reset_tries
++;
1590 if (local
->hw_reset_tries
> 10) {
1591 printk(KERN_WARNING
"%s: too many reset tries, skipping\n",
1596 printk(KERN_WARNING
"%s: %s: resetting card\n", dev_info
, dev
->name
);
1597 hfa384x_disable_interrupts(dev
);
1598 local
->hw_resetting
= 1;
1599 if (local
->func
->cor_sreset
) {
1600 /* Host system seems to hang in some cases with high traffic
1601 * load or shared interrupts during COR sreset. Disable shared
1602 * interrupts during reset to avoid these crashes. COS sreset
1603 * takes quite a long time, so it is unfortunate that this
1604 * seems to be needed. Anyway, I do not know of any better way
1605 * of avoiding the crash. */
1606 disable_irq(dev
->irq
);
1607 local
->func
->cor_sreset(local
);
1608 enable_irq(dev
->irq
);
1610 prism2_hw_shutdown(dev
, 1);
1611 prism2_hw_config(dev
, 0);
1612 local
->hw_resetting
= 0;
1614 #ifdef PRISM2_DOWNLOAD_SUPPORT
1615 if (local
->dl_pri
) {
1616 printk(KERN_DEBUG
"%s: persistent download of primary "
1617 "firmware\n", dev
->name
);
1618 if (prism2_download_genesis(local
, local
->dl_pri
) < 0)
1619 printk(KERN_WARNING
"%s: download (PRI) failed\n",
1623 if (local
->dl_sec
) {
1624 printk(KERN_DEBUG
"%s: persistent download of secondary "
1625 "firmware\n", dev
->name
);
1626 if (prism2_download_volatile(local
, local
->dl_sec
) < 0)
1627 printk(KERN_WARNING
"%s: download (SEC) failed\n",
1630 #endif /* PRISM2_DOWNLOAD_SUPPORT */
1632 /* TODO: restore beacon TIM bits for STAs that have buffered frames */
1636 static void prism2_schedule_reset(local_info_t
*local
)
1638 schedule_work(&local
->reset_queue
);
1642 /* Called only as scheduled task after noticing card timeout in interrupt
1644 static void handle_reset_queue(struct work_struct
*work
)
1646 local_info_t
*local
= container_of(work
, local_info_t
, reset_queue
);
1648 printk(KERN_DEBUG
"%s: scheduled card reset\n", local
->dev
->name
);
1649 prism2_hw_reset(local
->dev
);
1651 if (netif_queue_stopped(local
->dev
)) {
1654 for (i
= 0; i
< PRISM2_TXFID_COUNT
; i
++)
1655 if (local
->intransmitfid
[i
] == PRISM2_TXFID_EMPTY
) {
1656 PDEBUG(DEBUG_EXTRA
, "prism2_tx_timeout: "
1658 netif_wake_queue(local
->dev
);
1665 static int prism2_get_txfid_idx(local_info_t
*local
)
1668 unsigned long flags
;
1670 spin_lock_irqsave(&local
->txfidlock
, flags
);
1671 end
= idx
= local
->next_txfid
;
1673 if (local
->intransmitfid
[idx
] == PRISM2_TXFID_EMPTY
) {
1674 local
->intransmitfid
[idx
] = PRISM2_TXFID_RESERVED
;
1675 spin_unlock_irqrestore(&local
->txfidlock
, flags
);
1679 if (idx
>= PRISM2_TXFID_COUNT
)
1681 } while (idx
!= end
);
1682 spin_unlock_irqrestore(&local
->txfidlock
, flags
);
1684 PDEBUG(DEBUG_EXTRA2
, "prism2_get_txfid_idx: no room in txfid buf: "
1685 "packet dropped\n");
1686 local
->dev
->stats
.tx_dropped
++;
1692 /* Called only from hardware IRQ */
1693 static void prism2_transmit_cb(struct net_device
*dev
, long context
,
1696 struct hostap_interface
*iface
;
1697 local_info_t
*local
;
1698 int idx
= (int) context
;
1700 iface
= netdev_priv(dev
);
1701 local
= iface
->local
;
1704 printk(KERN_DEBUG
"%s: prism2_transmit_cb - res=0x%02x\n",
1709 if (idx
< 0 || idx
>= PRISM2_TXFID_COUNT
) {
1710 printk(KERN_DEBUG
"%s: prism2_transmit_cb called with invalid "
1711 "idx=%d\n", dev
->name
, idx
);
1715 if (!test_and_clear_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
)) {
1716 printk(KERN_DEBUG
"%s: driver bug: prism2_transmit_cb called "
1717 "with no pending transmit\n", dev
->name
);
1720 if (netif_queue_stopped(dev
)) {
1721 /* ready for next TX, so wake up queue that was stopped in
1722 * prism2_transmit() */
1723 netif_wake_queue(dev
);
1726 spin_lock(&local
->txfidlock
);
1728 /* With reclaim, Resp0 contains new txfid for transmit; the old txfid
1729 * will be automatically allocated for the next TX frame */
1730 local
->intransmitfid
[idx
] = resp0
;
1732 PDEBUG(DEBUG_FID
, "%s: prism2_transmit_cb: txfid[%d]=0x%04x, "
1733 "resp0=0x%04x, transmit_txfid=0x%04x\n",
1734 dev
->name
, idx
, local
->txfid
[idx
],
1735 resp0
, local
->intransmitfid
[local
->next_txfid
]);
1738 if (idx
>= PRISM2_TXFID_COUNT
)
1740 local
->next_txfid
= idx
;
1742 /* check if all TX buffers are occupied */
1744 if (local
->intransmitfid
[idx
] == PRISM2_TXFID_EMPTY
) {
1745 spin_unlock(&local
->txfidlock
);
1749 if (idx
>= PRISM2_TXFID_COUNT
)
1751 } while (idx
!= local
->next_txfid
);
1752 spin_unlock(&local
->txfidlock
);
1754 /* no empty TX buffers, stop queue */
1755 netif_stop_queue(dev
);
1759 /* Called only from software IRQ if PCI bus master is not used (with bus master
1760 * this can be called both from software and hardware IRQ) */
1761 static int prism2_transmit(struct net_device
*dev
, int idx
)
1763 struct hostap_interface
*iface
;
1764 local_info_t
*local
;
1767 iface
= netdev_priv(dev
);
1768 local
= iface
->local
;
1770 /* The driver tries to stop netif queue so that there would not be
1771 * more than one attempt to transmit frames going on; check that this
1772 * is really the case */
1774 if (test_and_set_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
)) {
1775 printk(KERN_DEBUG
"%s: driver bug - prism2_transmit() called "
1776 "when previous TX was pending\n", dev
->name
);
1780 /* stop the queue for the time that transmit is pending */
1781 netif_stop_queue(dev
);
1783 /* transmit packet */
1784 res
= hfa384x_cmd_callback(
1786 HFA384X_CMDCODE_TRANSMIT
| HFA384X_CMD_TX_RECLAIM
,
1788 prism2_transmit_cb
, (long) idx
);
1791 printk(KERN_DEBUG
"%s: prism2_transmit: CMDCODE_TRANSMIT "
1792 "failed (res=%d)\n", dev
->name
, res
);
1793 dev
->stats
.tx_dropped
++;
1794 netif_wake_queue(dev
);
1797 dev
->trans_start
= jiffies
;
1799 /* Since we did not wait for command completion, the card continues
1800 * to process on the background and we will finish handling when
1801 * command completion event is handled (prism2_cmd_ev() function) */
1807 /* Send IEEE 802.11 frame (convert the header into Prism2 TX descriptor and
1808 * send the payload with this descriptor) */
1809 /* Called only from software IRQ */
1810 static int prism2_tx_80211(struct sk_buff
*skb
, struct net_device
*dev
)
1812 struct hostap_interface
*iface
;
1813 local_info_t
*local
;
1814 struct hfa384x_tx_frame txdesc
;
1815 struct hostap_skb_tx_data
*meta
;
1816 int hdr_len
, data_len
, idx
, res
, ret
= -1;
1819 iface
= netdev_priv(dev
);
1820 local
= iface
->local
;
1822 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
1824 prism2_callback(local
, PRISM2_CALLBACK_TX_START
);
1826 if ((local
->func
->card_present
&& !local
->func
->card_present(local
)) ||
1827 !local
->hw_ready
|| local
->hw_downloading
|| local
->pri_only
) {
1828 if (net_ratelimit()) {
1829 printk(KERN_DEBUG
"%s: prism2_tx_80211: hw not ready -"
1830 " skipping\n", dev
->name
);
1835 memset(&txdesc
, 0, sizeof(txdesc
));
1837 /* skb->data starts with txdesc->frame_control */
1839 skb_copy_from_linear_data(skb
, &txdesc
.frame_control
, hdr_len
);
1840 fc
= le16_to_cpu(txdesc
.frame_control
);
1841 if (ieee80211_is_data(txdesc
.frame_control
) &&
1842 ieee80211_has_a4(txdesc
.frame_control
) &&
1845 skb_copy_from_linear_data_offset(skb
, hdr_len
, txdesc
.addr4
,
1847 hdr_len
+= ETH_ALEN
;
1850 tx_control
= local
->tx_control
;
1851 if (meta
->tx_cb_idx
) {
1852 tx_control
|= HFA384X_TX_CTRL_TX_OK
;
1853 txdesc
.sw_support
= cpu_to_le32(meta
->tx_cb_idx
);
1855 txdesc
.tx_control
= cpu_to_le16(tx_control
);
1856 txdesc
.tx_rate
= meta
->rate
;
1858 data_len
= skb
->len
- hdr_len
;
1859 txdesc
.data_len
= cpu_to_le16(data_len
);
1860 txdesc
.len
= cpu_to_be16(data_len
);
1862 idx
= prism2_get_txfid_idx(local
);
1866 if (local
->frame_dump
& PRISM2_DUMP_TX_HDR
)
1867 hostap_dump_tx_header(dev
->name
, &txdesc
);
1869 spin_lock(&local
->baplock
);
1870 res
= hfa384x_setup_bap(dev
, BAP0
, local
->txfid
[idx
], 0);
1873 res
= hfa384x_to_bap(dev
, BAP0
, &txdesc
, sizeof(txdesc
));
1875 res
= hfa384x_to_bap(dev
, BAP0
, skb
->data
+ hdr_len
,
1876 skb
->len
- hdr_len
);
1877 spin_unlock(&local
->baplock
);
1880 res
= prism2_transmit(dev
, idx
);
1882 printk(KERN_DEBUG
"%s: prism2_tx_80211 - to BAP0 failed\n",
1884 local
->intransmitfid
[idx
] = PRISM2_TXFID_EMPTY
;
1885 schedule_work(&local
->reset_queue
);
1892 prism2_callback(local
, PRISM2_CALLBACK_TX_END
);
1897 /* Some SMP systems have reported number of odd errors with hostap_pci. fid
1898 * register has changed values between consecutive reads for an unknown reason.
1899 * This should really not happen, so more debugging is needed. This test
1900 * version is a bit slower, but it will detect most of such register changes
1901 * and will try to get the correct fid eventually. */
1902 #define EXTRA_FID_READ_TESTS
1904 static u16
prism2_read_fid_reg(struct net_device
*dev
, u16 reg
)
1906 #ifdef EXTRA_FID_READ_TESTS
1907 u16 val
, val2
, val3
;
1910 for (i
= 0; i
< 10; i
++) {
1911 val
= HFA384X_INW(reg
);
1912 val2
= HFA384X_INW(reg
);
1913 val3
= HFA384X_INW(reg
);
1915 if (val
== val2
&& val
== val3
)
1918 printk(KERN_DEBUG
"%s: detected fid change (try=%d, reg=%04x):"
1919 " %04x %04x %04x\n",
1920 dev
->name
, i
, reg
, val
, val2
, val3
);
1921 if ((val
== val2
|| val
== val3
) && val
!= 0)
1923 if (val2
== val3
&& val2
!= 0)
1926 printk(KERN_WARNING
"%s: Uhhuh.. could not read good fid from reg "
1927 "%04x (%04x %04x %04x)\n", dev
->name
, reg
, val
, val2
, val3
);
1929 #else /* EXTRA_FID_READ_TESTS */
1930 return HFA384X_INW(reg
);
1931 #endif /* EXTRA_FID_READ_TESTS */
1935 /* Called only as a tasklet (software IRQ) */
1936 static void prism2_rx(local_info_t
*local
)
1938 struct net_device
*dev
= local
->dev
;
1939 int res
, rx_pending
= 0;
1940 u16 len
, hdr_len
, rxfid
, status
, macport
;
1941 struct hfa384x_rx_frame rxdesc
;
1942 struct sk_buff
*skb
= NULL
;
1944 prism2_callback(local
, PRISM2_CALLBACK_RX_START
);
1946 rxfid
= prism2_read_fid_reg(dev
, HFA384X_RXFID_OFF
);
1947 #ifndef final_version
1949 rxfid
= HFA384X_INW(HFA384X_RXFID_OFF
);
1950 printk(KERN_DEBUG
"prism2_rx: rxfid=0 (next 0x%04x)\n",
1953 schedule_work(&local
->reset_queue
);
1956 /* try to continue with the new rxfid value */
1960 spin_lock(&local
->baplock
);
1961 res
= hfa384x_setup_bap(dev
, BAP0
, rxfid
, 0);
1963 res
= hfa384x_from_bap(dev
, BAP0
, &rxdesc
, sizeof(rxdesc
));
1966 spin_unlock(&local
->baplock
);
1967 printk(KERN_DEBUG
"%s: copy from BAP0 failed %d\n", dev
->name
,
1969 if (res
== -ETIMEDOUT
) {
1970 schedule_work(&local
->reset_queue
);
1975 len
= le16_to_cpu(rxdesc
.data_len
);
1976 hdr_len
= sizeof(rxdesc
);
1977 status
= le16_to_cpu(rxdesc
.status
);
1978 macport
= (status
>> 8) & 0x07;
1980 /* Drop frames with too large reported payload length. Monitor mode
1981 * seems to sometimes pass frames (e.g., ctrl::ack) with signed and
1982 * negative value, so allow also values 65522 .. 65534 (-14 .. -2) for
1984 if (len
> PRISM2_DATA_MAXLEN
+ 8 /* WEP */) {
1985 if (macport
== 7 && local
->iw_mode
== IW_MODE_MONITOR
) {
1986 if (len
>= (u16
) -14) {
1987 hdr_len
-= 65535 - len
;
1992 spin_unlock(&local
->baplock
);
1993 printk(KERN_DEBUG
"%s: Received frame with invalid "
1994 "length 0x%04x\n", dev
->name
, len
);
1995 hostap_dump_rx_header(dev
->name
, &rxdesc
);
2000 skb
= dev_alloc_skb(len
+ hdr_len
);
2002 spin_unlock(&local
->baplock
);
2003 printk(KERN_DEBUG
"%s: RX failed to allocate skb\n",
2008 memcpy(skb_put(skb
, hdr_len
), &rxdesc
, hdr_len
);
2011 res
= hfa384x_from_bap(dev
, BAP0
, skb_put(skb
, len
), len
);
2012 spin_unlock(&local
->baplock
);
2014 printk(KERN_DEBUG
"%s: RX failed to read "
2015 "frame data\n", dev
->name
);
2019 skb_queue_tail(&local
->rx_list
, skb
);
2020 tasklet_schedule(&local
->rx_tasklet
);
2023 prism2_callback(local
, PRISM2_CALLBACK_RX_END
);
2025 HFA384X_OUTW(HFA384X_EV_RX
, HFA384X_EVACK_OFF
);
2031 dev
->stats
.rx_dropped
++;
2038 /* Called only as a tasklet (software IRQ) */
2039 static void hostap_rx_skb(local_info_t
*local
, struct sk_buff
*skb
)
2041 struct hfa384x_rx_frame
*rxdesc
;
2042 struct net_device
*dev
= skb
->dev
;
2043 struct hostap_80211_rx_status stats
;
2044 int hdrlen
, rx_hdrlen
;
2046 rx_hdrlen
= sizeof(*rxdesc
);
2047 if (skb
->len
< sizeof(*rxdesc
)) {
2048 /* Allow monitor mode to receive shorter frames */
2049 if (local
->iw_mode
== IW_MODE_MONITOR
&&
2050 skb
->len
>= sizeof(*rxdesc
) - 30) {
2051 rx_hdrlen
= skb
->len
;
2058 rxdesc
= (struct hfa384x_rx_frame
*) skb
->data
;
2060 if (local
->frame_dump
& PRISM2_DUMP_RX_HDR
&&
2061 skb
->len
>= sizeof(*rxdesc
))
2062 hostap_dump_rx_header(dev
->name
, rxdesc
);
2064 if (le16_to_cpu(rxdesc
->status
) & HFA384X_RX_STATUS_FCSERR
&&
2065 (!local
->monitor_allow_fcserr
||
2066 local
->iw_mode
!= IW_MODE_MONITOR
))
2069 if (skb
->len
> PRISM2_DATA_MAXLEN
) {
2070 printk(KERN_DEBUG
"%s: RX: len(%d) > MAX(%d)\n",
2071 dev
->name
, skb
->len
, PRISM2_DATA_MAXLEN
);
2075 stats
.mac_time
= le32_to_cpu(rxdesc
->time
);
2076 stats
.signal
= rxdesc
->signal
- local
->rssi_to_dBm
;
2077 stats
.noise
= rxdesc
->silence
- local
->rssi_to_dBm
;
2078 stats
.rate
= rxdesc
->rate
;
2080 /* Convert Prism2 RX structure into IEEE 802.11 header */
2081 hdrlen
= hostap_80211_get_hdrlen(rxdesc
->frame_control
);
2082 if (hdrlen
> rx_hdrlen
)
2085 memmove(skb_pull(skb
, rx_hdrlen
- hdrlen
),
2086 &rxdesc
->frame_control
, hdrlen
);
2088 hostap_80211_rx(dev
, skb
, &stats
);
2096 /* Called only as a tasklet (software IRQ) */
2097 static void hostap_rx_tasklet(unsigned long data
)
2099 local_info_t
*local
= (local_info_t
*) data
;
2100 struct sk_buff
*skb
;
2102 while ((skb
= skb_dequeue(&local
->rx_list
)) != NULL
)
2103 hostap_rx_skb(local
, skb
);
2107 /* Called only from hardware IRQ */
2108 static void prism2_alloc_ev(struct net_device
*dev
)
2110 struct hostap_interface
*iface
;
2111 local_info_t
*local
;
2115 iface
= netdev_priv(dev
);
2116 local
= iface
->local
;
2118 fid
= prism2_read_fid_reg(dev
, HFA384X_ALLOCFID_OFF
);
2120 PDEBUG(DEBUG_FID
, "FID: interrupt: ALLOC - fid=0x%04x\n", fid
);
2122 spin_lock(&local
->txfidlock
);
2123 idx
= local
->next_alloc
;
2126 if (local
->txfid
[idx
] == fid
) {
2127 PDEBUG(DEBUG_FID
, "FID: found matching txfid[%d]\n",
2130 #ifndef final_version
2131 if (local
->intransmitfid
[idx
] == PRISM2_TXFID_EMPTY
)
2132 printk("Already released txfid found at idx "
2134 if (local
->intransmitfid
[idx
] == PRISM2_TXFID_RESERVED
)
2135 printk("Already reserved txfid found at idx "
2138 local
->intransmitfid
[idx
] = PRISM2_TXFID_EMPTY
;
2140 local
->next_alloc
= idx
>= PRISM2_TXFID_COUNT
? 0 :
2143 if (!test_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
) &&
2144 netif_queue_stopped(dev
))
2145 netif_wake_queue(dev
);
2147 spin_unlock(&local
->txfidlock
);
2152 if (idx
>= PRISM2_TXFID_COUNT
)
2154 } while (idx
!= local
->next_alloc
);
2156 printk(KERN_WARNING
"%s: could not find matching txfid (0x%04x, new "
2157 "read 0x%04x) for alloc event\n", dev
->name
, fid
,
2158 HFA384X_INW(HFA384X_ALLOCFID_OFF
));
2159 printk(KERN_DEBUG
"TXFIDs:");
2160 for (idx
= 0; idx
< PRISM2_TXFID_COUNT
; idx
++)
2161 printk(" %04x[%04x]", local
->txfid
[idx
],
2162 local
->intransmitfid
[idx
]);
2164 spin_unlock(&local
->txfidlock
);
2166 /* FIX: should probably schedule reset; reference to one txfid was lost
2167 * completely.. Bad things will happen if we run out of txfids
2168 * Actually, this will cause netdev watchdog to notice TX timeout and
2169 * then card reset after all txfids have been leaked. */
2173 /* Called only as a tasklet (software IRQ) */
2174 static void hostap_tx_callback(local_info_t
*local
,
2175 struct hfa384x_tx_frame
*txdesc
, int ok
,
2178 u16 sw_support
, hdrlen
, len
;
2179 struct sk_buff
*skb
;
2180 struct hostap_tx_callback_info
*cb
;
2182 /* Make sure that frame was from us. */
2183 if (memcmp(txdesc
->addr2
, local
->dev
->dev_addr
, ETH_ALEN
)) {
2184 printk(KERN_DEBUG
"%s: TX callback - foreign frame\n",
2189 sw_support
= le32_to_cpu(txdesc
->sw_support
);
2191 spin_lock(&local
->lock
);
2192 cb
= local
->tx_callback
;
2193 while (cb
!= NULL
&& cb
->idx
!= sw_support
)
2195 spin_unlock(&local
->lock
);
2198 printk(KERN_DEBUG
"%s: could not find TX callback (idx %d)\n",
2199 local
->dev
->name
, sw_support
);
2203 hdrlen
= hostap_80211_get_hdrlen(txdesc
->frame_control
);
2204 len
= le16_to_cpu(txdesc
->data_len
);
2205 skb
= dev_alloc_skb(hdrlen
+ len
);
2207 printk(KERN_DEBUG
"%s: hostap_tx_callback failed to allocate "
2208 "skb\n", local
->dev
->name
);
2212 memcpy(skb_put(skb
, hdrlen
), (void *) &txdesc
->frame_control
, hdrlen
);
2214 memcpy(skb_put(skb
, len
), payload
, len
);
2216 skb
->dev
= local
->dev
;
2217 skb_reset_mac_header(skb
);
2219 cb
->func(skb
, ok
, cb
->data
);
2223 /* Called only as a tasklet (software IRQ) */
2224 static int hostap_tx_compl_read(local_info_t
*local
, int error
,
2225 struct hfa384x_tx_frame
*txdesc
,
2230 struct net_device
*dev
= local
->dev
;
2232 fid
= prism2_read_fid_reg(dev
, HFA384X_TXCOMPLFID_OFF
);
2234 PDEBUG(DEBUG_FID
, "interrupt: TX (err=%d) - fid=0x%04x\n", fid
, error
);
2236 spin_lock(&local
->baplock
);
2237 res
= hfa384x_setup_bap(dev
, BAP0
, fid
, 0);
2239 res
= hfa384x_from_bap(dev
, BAP0
, txdesc
, sizeof(*txdesc
));
2241 PDEBUG(DEBUG_EXTRA
, "%s: TX (err=%d) - fid=0x%04x - could not "
2242 "read txdesc\n", dev
->name
, error
, fid
);
2243 if (res
== -ETIMEDOUT
) {
2244 schedule_work(&local
->reset_queue
);
2249 if (txdesc
->sw_support
) {
2250 len
= le16_to_cpu(txdesc
->data_len
);
2251 if (len
< PRISM2_DATA_MAXLEN
) {
2252 *payload
= kmalloc(len
, GFP_ATOMIC
);
2253 if (*payload
== NULL
||
2254 hfa384x_from_bap(dev
, BAP0
, *payload
, len
)) {
2255 PDEBUG(DEBUG_EXTRA
, "%s: could not read TX "
2256 "frame payload\n", dev
->name
);
2266 spin_unlock(&local
->baplock
);
2272 /* Called only as a tasklet (software IRQ) */
2273 static void prism2_tx_ev(local_info_t
*local
)
2275 struct net_device
*dev
= local
->dev
;
2276 char *payload
= NULL
;
2277 struct hfa384x_tx_frame txdesc
;
2279 if (hostap_tx_compl_read(local
, 0, &txdesc
, &payload
))
2282 if (local
->frame_dump
& PRISM2_DUMP_TX_HDR
) {
2283 PDEBUG(DEBUG_EXTRA
, "%s: TX - status=0x%04x "
2284 "retry_count=%d tx_rate=%d seq_ctrl=%d "
2286 dev
->name
, le16_to_cpu(txdesc
.status
),
2287 txdesc
.retry_count
, txdesc
.tx_rate
,
2288 le16_to_cpu(txdesc
.seq_ctrl
),
2289 le16_to_cpu(txdesc
.duration_id
));
2292 if (txdesc
.sw_support
)
2293 hostap_tx_callback(local
, &txdesc
, 1, payload
);
2297 HFA384X_OUTW(HFA384X_EV_TX
, HFA384X_EVACK_OFF
);
2301 /* Called only as a tasklet (software IRQ) */
2302 static void hostap_sta_tx_exc_tasklet(unsigned long data
)
2304 local_info_t
*local
= (local_info_t
*) data
;
2305 struct sk_buff
*skb
;
2307 while ((skb
= skb_dequeue(&local
->sta_tx_exc_list
)) != NULL
) {
2308 struct hfa384x_tx_frame
*txdesc
=
2309 (struct hfa384x_tx_frame
*) skb
->data
;
2311 if (skb
->len
>= sizeof(*txdesc
)) {
2312 /* Convert Prism2 RX structure into IEEE 802.11 header
2314 int hdrlen
= hostap_80211_get_hdrlen(txdesc
->frame_control
);
2315 memmove(skb_pull(skb
, sizeof(*txdesc
) - hdrlen
),
2316 &txdesc
->frame_control
, hdrlen
);
2318 hostap_handle_sta_tx_exc(local
, skb
);
2325 /* Called only as a tasklet (software IRQ) */
2326 static void prism2_txexc(local_info_t
*local
)
2328 struct net_device
*dev
= local
->dev
;
2331 char *payload
= NULL
;
2332 struct hfa384x_tx_frame txdesc
;
2334 show_dump
= local
->frame_dump
& PRISM2_DUMP_TXEXC_HDR
;
2335 dev
->stats
.tx_errors
++;
2337 res
= hostap_tx_compl_read(local
, 1, &txdesc
, &payload
);
2338 HFA384X_OUTW(HFA384X_EV_TXEXC
, HFA384X_EVACK_OFF
);
2342 status
= le16_to_cpu(txdesc
.status
);
2344 /* We produce a TXDROP event only for retry or lifetime
2345 * exceeded, because that's the only status that really mean
2346 * that this particular node went away.
2347 * Other errors means that *we* screwed up. - Jean II */
2348 if (status
& (HFA384X_TX_STATUS_RETRYERR
| HFA384X_TX_STATUS_AGEDERR
))
2350 union iwreq_data wrqu
;
2352 /* Copy 802.11 dest address. */
2353 memcpy(wrqu
.addr
.sa_data
, txdesc
.addr1
, ETH_ALEN
);
2354 wrqu
.addr
.sa_family
= ARPHRD_ETHER
;
2355 wireless_send_event(dev
, IWEVTXDROP
, &wrqu
, NULL
);
2359 if (local
->iw_mode
== IW_MODE_MASTER
||
2360 local
->iw_mode
== IW_MODE_REPEAT
||
2361 local
->wds_type
& HOSTAP_WDS_AP_CLIENT
) {
2362 struct sk_buff
*skb
;
2363 skb
= dev_alloc_skb(sizeof(txdesc
));
2365 memcpy(skb_put(skb
, sizeof(txdesc
)), &txdesc
,
2367 skb_queue_tail(&local
->sta_tx_exc_list
, skb
);
2368 tasklet_schedule(&local
->sta_tx_exc_tasklet
);
2372 if (txdesc
.sw_support
)
2373 hostap_tx_callback(local
, &txdesc
, 0, payload
);
2379 PDEBUG(DEBUG_EXTRA
, "%s: TXEXC - status=0x%04x (%s%s%s%s)"
2380 " tx_control=%04x\n",
2382 status
& HFA384X_TX_STATUS_RETRYERR
? "[RetryErr]" : "",
2383 status
& HFA384X_TX_STATUS_AGEDERR
? "[AgedErr]" : "",
2384 status
& HFA384X_TX_STATUS_DISCON
? "[Discon]" : "",
2385 status
& HFA384X_TX_STATUS_FORMERR
? "[FormErr]" : "",
2386 le16_to_cpu(txdesc
.tx_control
));
2388 fc
= le16_to_cpu(txdesc
.frame_control
);
2389 PDEBUG(DEBUG_EXTRA
, " retry_count=%d tx_rate=%d fc=0x%04x "
2390 "(%s%s%s::%d%s%s)\n",
2391 txdesc
.retry_count
, txdesc
.tx_rate
, fc
,
2392 ieee80211_is_mgmt(txdesc
.frame_control
) ? "Mgmt" : "",
2393 ieee80211_is_ctl(txdesc
.frame_control
) ? "Ctrl" : "",
2394 ieee80211_is_data(txdesc
.frame_control
) ? "Data" : "",
2395 (fc
& IEEE80211_FCTL_STYPE
) >> 4,
2396 ieee80211_has_tods(txdesc
.frame_control
) ? " ToDS" : "",
2397 ieee80211_has_fromds(txdesc
.frame_control
) ? " FromDS" : "");
2398 PDEBUG(DEBUG_EXTRA
, " A1=%pM A2=%pM A3=%pM A4=%pM\n",
2399 txdesc
.addr1
, txdesc
.addr2
,
2400 txdesc
.addr3
, txdesc
.addr4
);
2404 /* Called only as a tasklet (software IRQ) */
2405 static void hostap_info_tasklet(unsigned long data
)
2407 local_info_t
*local
= (local_info_t
*) data
;
2408 struct sk_buff
*skb
;
2410 while ((skb
= skb_dequeue(&local
->info_list
)) != NULL
) {
2411 hostap_info_process(local
, skb
);
2417 /* Called only as a tasklet (software IRQ) */
2418 static void prism2_info(local_info_t
*local
)
2420 struct net_device
*dev
= local
->dev
;
2423 struct hfa384x_info_frame info
;
2424 struct sk_buff
*skb
;
2426 fid
= HFA384X_INW(HFA384X_INFOFID_OFF
);
2428 spin_lock(&local
->baplock
);
2429 res
= hfa384x_setup_bap(dev
, BAP0
, fid
, 0);
2431 res
= hfa384x_from_bap(dev
, BAP0
, &info
, sizeof(info
));
2433 spin_unlock(&local
->baplock
);
2434 printk(KERN_DEBUG
"Could not get info frame (fid=0x%04x)\n",
2436 if (res
== -ETIMEDOUT
) {
2437 schedule_work(&local
->reset_queue
);
2442 left
= (le16_to_cpu(info
.len
) - 1) * 2;
2444 if (info
.len
& cpu_to_le16(0x8000) || info
.len
== 0 || left
> 2060) {
2445 /* data register seems to give 0x8000 in some error cases even
2446 * though busy bit is not set in offset register;
2447 * in addition, length must be at least 1 due to type field */
2448 spin_unlock(&local
->baplock
);
2449 printk(KERN_DEBUG
"%s: Received info frame with invalid "
2450 "length 0x%04x (type 0x%04x)\n", dev
->name
,
2451 le16_to_cpu(info
.len
), le16_to_cpu(info
.type
));
2455 skb
= dev_alloc_skb(sizeof(info
) + left
);
2457 spin_unlock(&local
->baplock
);
2458 printk(KERN_DEBUG
"%s: Could not allocate skb for info "
2459 "frame\n", dev
->name
);
2463 memcpy(skb_put(skb
, sizeof(info
)), &info
, sizeof(info
));
2464 if (left
> 0 && hfa384x_from_bap(dev
, BAP0
, skb_put(skb
, left
), left
))
2466 spin_unlock(&local
->baplock
);
2467 printk(KERN_WARNING
"%s: Info frame read failed (fid=0x%04x, "
2468 "len=0x%04x, type=0x%04x\n", dev
->name
, fid
,
2469 le16_to_cpu(info
.len
), le16_to_cpu(info
.type
));
2473 spin_unlock(&local
->baplock
);
2475 skb_queue_tail(&local
->info_list
, skb
);
2476 tasklet_schedule(&local
->info_tasklet
);
2479 HFA384X_OUTW(HFA384X_EV_INFO
, HFA384X_EVACK_OFF
);
2483 /* Called only as a tasklet (software IRQ) */
2484 static void hostap_bap_tasklet(unsigned long data
)
2486 local_info_t
*local
= (local_info_t
*) data
;
2487 struct net_device
*dev
= local
->dev
;
2491 if (local
->func
->card_present
&& !local
->func
->card_present(local
))
2494 set_bit(HOSTAP_BITS_BAP_TASKLET
, &local
->bits
);
2496 /* Process all pending BAP events without generating new interrupts
2498 while (frames
-- > 0) {
2499 ev
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
2500 if (ev
== 0xffff || !(ev
& HFA384X_BAP0_EVENTS
))
2502 if (ev
& HFA384X_EV_RX
)
2504 if (ev
& HFA384X_EV_INFO
)
2506 if (ev
& HFA384X_EV_TX
)
2507 prism2_tx_ev(local
);
2508 if (ev
& HFA384X_EV_TXEXC
)
2509 prism2_txexc(local
);
2512 set_bit(HOSTAP_BITS_BAP_TASKLET2
, &local
->bits
);
2513 clear_bit(HOSTAP_BITS_BAP_TASKLET
, &local
->bits
);
2515 /* Enable interrupts for new BAP events */
2516 hfa384x_events_all(dev
);
2517 clear_bit(HOSTAP_BITS_BAP_TASKLET2
, &local
->bits
);
2521 /* Called only from hardware IRQ */
2522 static void prism2_infdrop(struct net_device
*dev
)
2524 static unsigned long last_inquire
= 0;
2526 PDEBUG(DEBUG_EXTRA
, "%s: INFDROP event\n", dev
->name
);
2528 /* some firmware versions seem to get stuck with
2529 * full CommTallies in high traffic load cases; every
2530 * packet will then cause INFDROP event and CommTallies
2531 * info frame will not be sent automatically. Try to
2532 * get out of this state by inquiring CommTallies. */
2533 if (!last_inquire
|| time_after(jiffies
, last_inquire
+ HZ
)) {
2534 hfa384x_cmd_callback(dev
, HFA384X_CMDCODE_INQUIRE
,
2535 HFA384X_INFO_COMMTALLIES
, NULL
, 0);
2536 last_inquire
= jiffies
;
2541 /* Called only from hardware IRQ */
2542 static void prism2_ev_tick(struct net_device
*dev
)
2544 struct hostap_interface
*iface
;
2545 local_info_t
*local
;
2547 static int prev_stuck
= 0;
2549 iface
= netdev_priv(dev
);
2550 local
= iface
->local
;
2552 if (time_after(jiffies
, local
->last_tick_timer
+ 5 * HZ
) &&
2553 local
->last_tick_timer
) {
2554 evstat
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
2555 inten
= HFA384X_INW(HFA384X_INTEN_OFF
);
2557 printk(KERN_INFO
"%s: SW TICK stuck? "
2558 "bits=0x%lx EvStat=%04x IntEn=%04x\n",
2559 dev
->name
, local
->bits
, evstat
, inten
);
2561 local
->sw_tick_stuck
++;
2562 if ((evstat
& HFA384X_BAP0_EVENTS
) &&
2563 (inten
& HFA384X_BAP0_EVENTS
)) {
2564 printk(KERN_INFO
"%s: trying to recover from IRQ "
2565 "hang\n", dev
->name
);
2566 hfa384x_events_no_bap0(dev
);
2574 /* Called only from hardware IRQ */
2575 static void prism2_check_magic(local_info_t
*local
)
2577 /* at least PCI Prism2.5 with bus mastering seems to sometimes
2578 * return 0x0000 in SWSUPPORT0 for unknown reason, but re-reading the
2579 * register once or twice seems to get the correct value.. PCI cards
2580 * cannot anyway be removed during normal operation, so there is not
2581 * really any need for this verification with them. */
2584 #ifndef final_version
2585 static unsigned long last_magic_err
= 0;
2586 struct net_device
*dev
= local
->dev
;
2588 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF
) != HFA384X_MAGIC
) {
2589 if (!local
->hw_ready
)
2591 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF
);
2592 if (time_after(jiffies
, last_magic_err
+ 10 * HZ
)) {
2593 printk("%s: Interrupt, but SWSUPPORT0 does not match: "
2594 "%04X != %04X - card removed?\n", dev
->name
,
2595 HFA384X_INW(HFA384X_SWSUPPORT0_OFF
),
2597 last_magic_err
= jiffies
;
2598 } else if (net_ratelimit()) {
2599 printk(KERN_DEBUG
"%s: interrupt - SWSUPPORT0=%04x "
2600 "MAGIC=%04x\n", dev
->name
,
2601 HFA384X_INW(HFA384X_SWSUPPORT0_OFF
),
2604 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF
) != 0xffff)
2605 schedule_work(&local
->reset_queue
);
2608 #endif /* final_version */
2609 #endif /* !PRISM2_PCI */
2613 /* Called only from hardware IRQ */
2614 static irqreturn_t
prism2_interrupt(int irq
, void *dev_id
)
2616 struct net_device
*dev
= dev_id
;
2617 struct hostap_interface
*iface
;
2618 local_info_t
*local
;
2622 iface
= netdev_priv(dev
);
2623 local
= iface
->local
;
2625 /* Detect early interrupt before driver is fully configured */
2626 spin_lock(&local
->irq_init_lock
);
2627 if (!dev
->base_addr
) {
2628 if (net_ratelimit()) {
2629 printk(KERN_DEBUG
"%s: Interrupt, but dev not configured\n",
2632 spin_unlock(&local
->irq_init_lock
);
2635 spin_unlock(&local
->irq_init_lock
);
2637 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_INTERRUPT
, 0, 0);
2639 if (local
->func
->card_present
&& !local
->func
->card_present(local
)) {
2640 if (net_ratelimit()) {
2641 printk(KERN_DEBUG
"%s: Interrupt, but dev not OK\n",
2647 prism2_check_magic(local
);
2650 ev
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
2652 if (local
->shutdown
)
2654 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF
);
2655 printk(KERN_DEBUG
"%s: prism2_interrupt: ev=0xffff\n",
2660 ev
&= HFA384X_INW(HFA384X_INTEN_OFF
);
2664 if (ev
& HFA384X_EV_CMD
) {
2668 /* Above events are needed even before hw is ready, but other
2669 * events should be skipped during initialization. This may
2670 * change for AllocEv if allocate_fid is implemented without
2672 if (!local
->hw_ready
|| local
->hw_resetting
||
2673 !local
->dev_enabled
) {
2674 ev
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
2675 if (ev
& HFA384X_EV_CMD
)
2677 if ((ev
& HFA384X_EVENT_MASK
) == 0)
2679 if (local
->dev_enabled
&& (ev
& ~HFA384X_EV_TICK
) &&
2681 printk(KERN_DEBUG
"%s: prism2_interrupt: hw "
2682 "not ready; skipping events 0x%04x "
2683 "(IntEn=0x%04x)%s%s%s\n",
2685 HFA384X_INW(HFA384X_INTEN_OFF
),
2686 !local
->hw_ready
? " (!hw_ready)" : "",
2687 local
->hw_resetting
?
2688 " (hw_resetting)" : "",
2689 !local
->dev_enabled
?
2690 " (!dev_enabled)" : "");
2692 HFA384X_OUTW(ev
, HFA384X_EVACK_OFF
);
2696 if (ev
& HFA384X_EV_TICK
) {
2697 prism2_ev_tick(dev
);
2698 HFA384X_OUTW(HFA384X_EV_TICK
, HFA384X_EVACK_OFF
);
2701 if (ev
& HFA384X_EV_ALLOC
) {
2702 prism2_alloc_ev(dev
);
2703 HFA384X_OUTW(HFA384X_EV_ALLOC
, HFA384X_EVACK_OFF
);
2706 /* Reading data from the card is quite time consuming, so do it
2707 * in tasklets. TX, TXEXC, RX, and INFO events will be ACKed
2708 * and unmasked after needed data has been read completely. */
2709 if (ev
& HFA384X_BAP0_EVENTS
) {
2710 hfa384x_events_no_bap0(dev
);
2711 tasklet_schedule(&local
->bap_tasklet
);
2714 #ifndef final_version
2715 if (ev
& HFA384X_EV_WTERR
) {
2716 PDEBUG(DEBUG_EXTRA
, "%s: WTERR event\n", dev
->name
);
2717 HFA384X_OUTW(HFA384X_EV_WTERR
, HFA384X_EVACK_OFF
);
2719 #endif /* final_version */
2721 if (ev
& HFA384X_EV_INFDROP
) {
2722 prism2_infdrop(dev
);
2723 HFA384X_OUTW(HFA384X_EV_INFDROP
, HFA384X_EVACK_OFF
);
2728 if (events
>= PRISM2_MAX_INTERRUPT_EVENTS
) {
2729 PDEBUG(DEBUG_EXTRA
, "prism2_interrupt: >%d events "
2730 "(EvStat=0x%04x)\n",
2731 PRISM2_MAX_INTERRUPT_EVENTS
,
2732 HFA384X_INW(HFA384X_EVSTAT_OFF
));
2736 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_INTERRUPT
, 0, 1);
2737 return IRQ_RETVAL(events
);
2741 static void prism2_check_sta_fw_version(local_info_t
*local
)
2743 struct hfa384x_comp_ident comp
;
2744 int id
, variant
, major
, minor
;
2746 if (hfa384x_get_rid(local
->dev
, HFA384X_RID_STAID
,
2747 &comp
, sizeof(comp
), 1) < 0)
2751 id
= le16_to_cpu(comp
.id
);
2752 if (id
!= HFA384X_COMP_ID_STA
) {
2753 if (id
== HFA384X_COMP_ID_FW_AP
)
2758 major
= __le16_to_cpu(comp
.major
);
2759 minor
= __le16_to_cpu(comp
.minor
);
2760 variant
= __le16_to_cpu(comp
.variant
);
2761 local
->sta_fw_ver
= PRISM2_FW_VER(major
, minor
, variant
);
2763 /* Station firmware versions before 1.4.x seem to have a bug in
2764 * firmware-based WEP encryption when using Host AP mode, so use
2765 * host_encrypt as a default for them. Firmware version 1.4.9 is the
2766 * first one that has been seen to produce correct encryption, but the
2767 * bug might be fixed before that (although, at least 1.4.2 is broken).
2769 local
->fw_encrypt_ok
= local
->sta_fw_ver
>= PRISM2_FW_VER(1,4,9);
2771 if (local
->iw_mode
== IW_MODE_MASTER
&& !local
->host_encrypt
&&
2772 !local
->fw_encrypt_ok
) {
2773 printk(KERN_DEBUG
"%s: defaulting to host-based encryption as "
2774 "a workaround for firmware bug in Host AP mode WEP\n",
2776 local
->host_encrypt
= 1;
2779 /* IEEE 802.11 standard compliant WDS frames (4 addresses) were broken
2780 * in station firmware versions before 1.5.x. With these versions, the
2781 * driver uses a workaround with bogus frame format (4th address after
2782 * the payload). This is not compatible with other AP devices. Since
2783 * the firmware bug is fixed in the latest station firmware versions,
2784 * automatically enable standard compliant mode for cards using station
2785 * firmware version 1.5.0 or newer. */
2786 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,5,0))
2787 local
->wds_type
|= HOSTAP_WDS_STANDARD_FRAME
;
2789 printk(KERN_DEBUG
"%s: defaulting to bogus WDS frame as a "
2790 "workaround for firmware bug in Host AP mode WDS\n",
2794 hostap_check_sta_fw_version(local
->ap
, local
->sta_fw_ver
);
2798 static void hostap_passive_scan(unsigned long data
)
2800 local_info_t
*local
= (local_info_t
*) data
;
2801 struct net_device
*dev
= local
->dev
;
2804 if (local
->passive_scan_interval
<= 0)
2807 if (local
->passive_scan_state
== PASSIVE_SCAN_LISTEN
) {
2810 /* Even though host system does not really know when the WLAN
2811 * MAC is sending frames, try to avoid changing channels for
2812 * passive scanning when a host-generated frame is being
2814 if (test_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
)) {
2815 printk(KERN_DEBUG
"%s: passive scan detected pending "
2816 "TX - delaying\n", dev
->name
);
2817 local
->passive_scan_timer
.expires
= jiffies
+ HZ
/ 10;
2818 add_timer(&local
->passive_scan_timer
);
2823 local
->passive_scan_channel
++;
2824 if (local
->passive_scan_channel
> 14)
2825 local
->passive_scan_channel
= 1;
2827 } while (!(local
->channel_mask
&
2828 (1 << (local
->passive_scan_channel
- 1))) &&
2831 if (max_tries
== 0) {
2832 printk(KERN_INFO
"%s: no allowed passive scan channels"
2833 " found\n", dev
->name
);
2837 printk(KERN_DEBUG
"%s: passive scan channel %d\n",
2838 dev
->name
, local
->passive_scan_channel
);
2839 chan
= local
->passive_scan_channel
;
2840 local
->passive_scan_state
= PASSIVE_SCAN_WAIT
;
2841 local
->passive_scan_timer
.expires
= jiffies
+ HZ
/ 10;
2843 chan
= local
->channel
;
2844 local
->passive_scan_state
= PASSIVE_SCAN_LISTEN
;
2845 local
->passive_scan_timer
.expires
= jiffies
+
2846 local
->passive_scan_interval
* HZ
;
2849 if (hfa384x_cmd_callback(dev
, HFA384X_CMDCODE_TEST
|
2850 (HFA384X_TEST_CHANGE_CHANNEL
<< 8),
2852 printk(KERN_ERR
"%s: passive scan channel set %d "
2853 "failed\n", dev
->name
, chan
);
2855 add_timer(&local
->passive_scan_timer
);
2859 /* Called only as a scheduled task when communications quality values should
2861 static void handle_comms_qual_update(struct work_struct
*work
)
2863 local_info_t
*local
=
2864 container_of(work
, local_info_t
, comms_qual_update
);
2865 prism2_update_comms_qual(local
->dev
);
2869 /* Software watchdog - called as a timer. Hardware interrupt (Tick event) is
2870 * used to monitor that local->last_tick_timer is being updated. If not,
2871 * interrupt busy-loop is assumed and driver tries to recover by masking out
2873 static void hostap_tick_timer(unsigned long data
)
2875 static unsigned long last_inquire
= 0;
2876 local_info_t
*local
= (local_info_t
*) data
;
2877 local
->last_tick_timer
= jiffies
;
2879 /* Inquire CommTallies every 10 seconds to keep the statistics updated
2880 * more often during low load and when using 32-bit tallies. */
2881 if ((!last_inquire
|| time_after(jiffies
, last_inquire
+ 10 * HZ
)) &&
2882 !local
->hw_downloading
&& local
->hw_ready
&&
2883 !local
->hw_resetting
&& local
->dev_enabled
) {
2884 hfa384x_cmd_callback(local
->dev
, HFA384X_CMDCODE_INQUIRE
,
2885 HFA384X_INFO_COMMTALLIES
, NULL
, 0);
2886 last_inquire
= jiffies
;
2889 if ((local
->last_comms_qual_update
== 0 ||
2890 time_after(jiffies
, local
->last_comms_qual_update
+ 10 * HZ
)) &&
2891 (local
->iw_mode
== IW_MODE_INFRA
||
2892 local
->iw_mode
== IW_MODE_ADHOC
)) {
2893 schedule_work(&local
->comms_qual_update
);
2896 local
->tick_timer
.expires
= jiffies
+ 2 * HZ
;
2897 add_timer(&local
->tick_timer
);
2901 #ifndef PRISM2_NO_PROCFS_DEBUG
2902 static int prism2_registers_proc_read(char *page
, char **start
, off_t off
,
2903 int count
, int *eof
, void *data
)
2906 local_info_t
*local
= (local_info_t
*) data
;
2913 #define SHOW_REG(n) \
2914 p += sprintf(p, #n "=%04x\n", hfa384x_read_reg(local->dev, HFA384X_##n##_OFF))
2932 SHOW_REG(TXCOMPLFID
);
2933 SHOW_REG(SWSUPPORT0
);
2934 SHOW_REG(SWSUPPORT1
);
2935 SHOW_REG(SWSUPPORT2
);
2939 /* Do not read data registers, because they change the state of the
2940 * MAC (offset += 2) */
2941 /* SHOW_REG(DATA0); */
2942 /* SHOW_REG(DATA1); */
2944 SHOW_REG(AUXOFFSET
);
2945 /* SHOW_REG(AUXDATA); */
2949 SHOW_REG(PCI_M0_ADDRH
);
2950 SHOW_REG(PCI_M0_ADDRL
);
2951 SHOW_REG(PCI_M0_LEN
);
2952 SHOW_REG(PCI_M0_CTL
);
2953 SHOW_REG(PCI_STATUS
);
2954 SHOW_REG(PCI_M1_ADDRH
);
2955 SHOW_REG(PCI_M1_ADDRL
);
2956 SHOW_REG(PCI_M1_LEN
);
2957 SHOW_REG(PCI_M1_CTL
);
2958 #endif /* PRISM2_PCI */
2962 #endif /* PRISM2_NO_PROCFS_DEBUG */
2965 struct set_tim_data
{
2966 struct list_head list
;
2971 static int prism2_set_tim(struct net_device
*dev
, int aid
, int set
)
2973 struct list_head
*ptr
;
2974 struct set_tim_data
*new_entry
;
2975 struct hostap_interface
*iface
;
2976 local_info_t
*local
;
2978 iface
= netdev_priv(dev
);
2979 local
= iface
->local
;
2981 new_entry
= kzalloc(sizeof(*new_entry
), GFP_ATOMIC
);
2982 if (new_entry
== NULL
) {
2983 printk(KERN_DEBUG
"%s: prism2_set_tim: kmalloc failed\n",
2987 new_entry
->aid
= aid
;
2988 new_entry
->set
= set
;
2990 spin_lock_bh(&local
->set_tim_lock
);
2991 list_for_each(ptr
, &local
->set_tim_list
) {
2992 struct set_tim_data
*entry
=
2993 list_entry(ptr
, struct set_tim_data
, list
);
2994 if (entry
->aid
== aid
) {
2995 PDEBUG(DEBUG_PS2
, "%s: prism2_set_tim: aid=%d "
2997 local
->dev
->name
, aid
, entry
->set
, set
);
3005 list_add_tail(&new_entry
->list
, &local
->set_tim_list
);
3006 spin_unlock_bh(&local
->set_tim_lock
);
3008 schedule_work(&local
->set_tim_queue
);
3014 static void handle_set_tim_queue(struct work_struct
*work
)
3016 local_info_t
*local
= container_of(work
, local_info_t
, set_tim_queue
);
3017 struct set_tim_data
*entry
;
3022 spin_lock_bh(&local
->set_tim_lock
);
3023 if (!list_empty(&local
->set_tim_list
)) {
3024 entry
= list_entry(local
->set_tim_list
.next
,
3025 struct set_tim_data
, list
);
3026 list_del(&entry
->list
);
3028 spin_unlock_bh(&local
->set_tim_lock
);
3032 PDEBUG(DEBUG_PS2
, "%s: handle_set_tim_queue: aid=%d set=%d\n",
3033 local
->dev
->name
, entry
->aid
, entry
->set
);
3038 if (hostap_set_word(local
->dev
, HFA384X_RID_CNFTIMCTRL
, val
)) {
3039 printk(KERN_DEBUG
"%s: set_tim failed (aid=%d "
3041 local
->dev
->name
, entry
->aid
, entry
->set
);
3049 static void prism2_clear_set_tim_queue(local_info_t
*local
)
3051 struct list_head
*ptr
, *n
;
3053 list_for_each_safe(ptr
, n
, &local
->set_tim_list
) {
3054 struct set_tim_data
*entry
;
3055 entry
= list_entry(ptr
, struct set_tim_data
, list
);
3056 list_del(&entry
->list
);
3063 * HostAP uses two layers of net devices, where the inner
3064 * layer gets called all the time from the outer layer.
3065 * This is a natural nesting, which needs a split lock type.
3067 static struct lock_class_key hostap_netdev_xmit_lock_key
;
3068 static struct lock_class_key hostap_netdev_addr_lock_key
;
3070 static void prism2_set_lockdep_class_one(struct net_device
*dev
,
3071 struct netdev_queue
*txq
,
3074 lockdep_set_class(&txq
->_xmit_lock
,
3075 &hostap_netdev_xmit_lock_key
);
3078 static void prism2_set_lockdep_class(struct net_device
*dev
)
3080 lockdep_set_class(&dev
->addr_list_lock
,
3081 &hostap_netdev_addr_lock_key
);
3082 netdev_for_each_tx_queue(dev
, prism2_set_lockdep_class_one
, NULL
);
3085 static struct net_device
*
3086 prism2_init_local_data(struct prism2_helper_functions
*funcs
, int card_idx
,
3087 struct device
*sdev
)
3089 struct net_device
*dev
;
3090 struct hostap_interface
*iface
;
3091 struct local_info
*local
;
3097 len
= strlen(dev_template
);
3098 if (len
>= IFNAMSIZ
|| strstr(dev_template
, "%d") == NULL
) {
3099 printk(KERN_WARNING
"hostap: Invalid dev_template='%s'\n",
3104 len
= sizeof(struct hostap_interface
) +
3105 3 + sizeof(struct local_info
) +
3106 3 + sizeof(struct ap_data
);
3108 dev
= alloc_etherdev(len
);
3112 iface
= netdev_priv(dev
);
3113 local
= (struct local_info
*) ((((long) (iface
+ 1)) + 3) & ~3);
3114 local
->ap
= (struct ap_data
*) ((((long) (local
+ 1)) + 3) & ~3);
3115 local
->dev
= iface
->dev
= dev
;
3116 iface
->local
= local
;
3117 iface
->type
= HOSTAP_INTERFACE_MASTER
;
3118 INIT_LIST_HEAD(&local
->hostap_interfaces
);
3120 local
->hw_module
= THIS_MODULE
;
3122 #ifdef PRISM2_IO_DEBUG
3123 local
->io_debug_enabled
= 1;
3124 #endif /* PRISM2_IO_DEBUG */
3126 local
->func
= funcs
;
3127 local
->func
->cmd
= hfa384x_cmd
;
3128 local
->func
->read_regs
= hfa384x_read_regs
;
3129 local
->func
->get_rid
= hfa384x_get_rid
;
3130 local
->func
->set_rid
= hfa384x_set_rid
;
3131 local
->func
->hw_enable
= prism2_hw_enable
;
3132 local
->func
->hw_config
= prism2_hw_config
;
3133 local
->func
->hw_reset
= prism2_hw_reset
;
3134 local
->func
->hw_shutdown
= prism2_hw_shutdown
;
3135 local
->func
->reset_port
= prism2_reset_port
;
3136 local
->func
->schedule_reset
= prism2_schedule_reset
;
3137 #ifdef PRISM2_DOWNLOAD_SUPPORT
3138 local
->func
->read_aux
= prism2_download_aux_dump
;
3139 local
->func
->download
= prism2_download
;
3140 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3141 local
->func
->tx
= prism2_tx_80211
;
3142 local
->func
->set_tim
= prism2_set_tim
;
3143 local
->func
->need_tx_headroom
= 0; /* no need to add txdesc in
3144 * skb->data (FIX: maybe for DMA bus
3149 rwlock_init(&local
->iface_lock
);
3150 spin_lock_init(&local
->txfidlock
);
3151 spin_lock_init(&local
->cmdlock
);
3152 spin_lock_init(&local
->baplock
);
3153 spin_lock_init(&local
->lock
);
3154 spin_lock_init(&local
->irq_init_lock
);
3155 mutex_init(&local
->rid_bap_mtx
);
3157 if (card_idx
< 0 || card_idx
>= MAX_PARM_DEVICES
)
3159 local
->card_idx
= card_idx
;
3161 len
= strlen(essid
);
3162 memcpy(local
->essid
, essid
,
3163 len
> MAX_SSID_LEN
? MAX_SSID_LEN
: len
);
3164 local
->essid
[MAX_SSID_LEN
] = '\0';
3165 i
= GET_INT_PARM(iw_mode
, card_idx
);
3166 if ((i
>= IW_MODE_ADHOC
&& i
<= IW_MODE_REPEAT
) ||
3167 i
== IW_MODE_MONITOR
) {
3170 printk(KERN_WARNING
"prism2: Unknown iw_mode %d; using "
3171 "IW_MODE_MASTER\n", i
);
3172 local
->iw_mode
= IW_MODE_MASTER
;
3174 local
->channel
= GET_INT_PARM(channel
, card_idx
);
3175 local
->beacon_int
= GET_INT_PARM(beacon_int
, card_idx
);
3176 local
->dtim_period
= GET_INT_PARM(dtim_period
, card_idx
);
3177 local
->wds_max_connections
= 16;
3178 local
->tx_control
= HFA384X_TX_CTRL_FLAGS
;
3179 local
->manual_retry_count
= -1;
3180 local
->rts_threshold
= 2347;
3181 local
->fragm_threshold
= 2346;
3182 local
->rssi_to_dBm
= 100; /* default; to be overriden by
3183 * cnfDbmAdjust, if available */
3184 local
->auth_algs
= PRISM2_AUTH_OPEN
| PRISM2_AUTH_SHARED_KEY
;
3185 local
->sram_type
= -1;
3186 local
->scan_channel_mask
= 0xffff;
3187 local
->monitor_type
= PRISM2_MONITOR_RADIOTAP
;
3189 /* Initialize task queue structures */
3190 INIT_WORK(&local
->reset_queue
, handle_reset_queue
);
3191 INIT_WORK(&local
->set_multicast_list_queue
,
3192 hostap_set_multicast_list_queue
);
3194 INIT_WORK(&local
->set_tim_queue
, handle_set_tim_queue
);
3195 INIT_LIST_HEAD(&local
->set_tim_list
);
3196 spin_lock_init(&local
->set_tim_lock
);
3198 INIT_WORK(&local
->comms_qual_update
, handle_comms_qual_update
);
3200 /* Initialize tasklets for handling hardware IRQ related operations
3201 * outside hw IRQ handler */
3202 #define HOSTAP_TASKLET_INIT(q, f, d) \
3203 do { memset((q), 0, sizeof(*(q))); (q)->func = (f); (q)->data = (d); } \
3205 HOSTAP_TASKLET_INIT(&local
->bap_tasklet
, hostap_bap_tasklet
,
3206 (unsigned long) local
);
3208 HOSTAP_TASKLET_INIT(&local
->info_tasklet
, hostap_info_tasklet
,
3209 (unsigned long) local
);
3210 hostap_info_init(local
);
3212 HOSTAP_TASKLET_INIT(&local
->rx_tasklet
,
3213 hostap_rx_tasklet
, (unsigned long) local
);
3214 skb_queue_head_init(&local
->rx_list
);
3216 HOSTAP_TASKLET_INIT(&local
->sta_tx_exc_tasklet
,
3217 hostap_sta_tx_exc_tasklet
, (unsigned long) local
);
3218 skb_queue_head_init(&local
->sta_tx_exc_list
);
3220 INIT_LIST_HEAD(&local
->cmd_queue
);
3221 init_waitqueue_head(&local
->hostscan_wq
);
3223 lib80211_crypt_info_init(&local
->crypt_info
, dev
->name
, &local
->lock
);
3225 init_timer(&local
->passive_scan_timer
);
3226 local
->passive_scan_timer
.data
= (unsigned long) local
;
3227 local
->passive_scan_timer
.function
= hostap_passive_scan
;
3229 init_timer(&local
->tick_timer
);
3230 local
->tick_timer
.data
= (unsigned long) local
;
3231 local
->tick_timer
.function
= hostap_tick_timer
;
3232 local
->tick_timer
.expires
= jiffies
+ 2 * HZ
;
3233 add_timer(&local
->tick_timer
);
3235 INIT_LIST_HEAD(&local
->bss_list
);
3237 hostap_setup_dev(dev
, local
, HOSTAP_INTERFACE_MASTER
);
3239 dev
->type
= ARPHRD_IEEE80211
;
3240 dev
->header_ops
= &hostap_80211_ops
;
3243 ret
= dev_alloc_name(dev
, "wifi%d");
3244 SET_NETDEV_DEV(dev
, sdev
);
3246 ret
= register_netdevice(dev
);
3248 prism2_set_lockdep_class(dev
);
3251 printk(KERN_WARNING
"%s: register netdevice failed!\n",
3255 printk(KERN_INFO
"%s: Registered netdevice %s\n", dev_info
, dev
->name
);
3257 hostap_init_data(local
);
3266 static int hostap_hw_ready(struct net_device
*dev
)
3268 struct hostap_interface
*iface
;
3269 struct local_info
*local
;
3271 iface
= netdev_priv(dev
);
3272 local
= iface
->local
;
3273 local
->ddev
= hostap_add_interface(local
, HOSTAP_INTERFACE_MAIN
, 0,
3277 if (local
->iw_mode
== IW_MODE_INFRA
||
3278 local
->iw_mode
== IW_MODE_ADHOC
) {
3279 netif_carrier_off(local
->dev
);
3280 netif_carrier_off(local
->ddev
);
3282 hostap_init_proc(local
);
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 */
3287 hostap_init_ap_proc(local
);
3295 static void prism2_free_local_data(struct net_device
*dev
)
3297 struct hostap_tx_callback_info
*tx_cb
, *tx_cb_prev
;
3299 struct hostap_interface
*iface
;
3300 struct local_info
*local
;
3301 struct list_head
*ptr
, *n
;
3306 iface
= netdev_priv(dev
);
3307 local
= iface
->local
;
3309 /* Unregister all netdevs before freeing local data. */
3310 list_for_each_safe(ptr
, n
, &local
->hostap_interfaces
) {
3311 iface
= list_entry(ptr
, struct hostap_interface
, list
);
3312 if (iface
->type
== HOSTAP_INTERFACE_MASTER
) {
3313 /* special handling for this interface below */
3316 hostap_remove_interface(iface
->dev
, 0, 1);
3319 unregister_netdev(local
->dev
);
3321 flush_work_sync(&local
->reset_queue
);
3322 flush_work_sync(&local
->set_multicast_list_queue
);
3323 flush_work_sync(&local
->set_tim_queue
);
3324 #ifndef PRISM2_NO_STATION_MODES
3325 flush_work_sync(&local
->info_queue
);
3327 flush_work_sync(&local
->comms_qual_update
);
3329 lib80211_crypt_info_free(&local
->crypt_info
);
3331 if (timer_pending(&local
->passive_scan_timer
))
3332 del_timer(&local
->passive_scan_timer
);
3334 if (timer_pending(&local
->tick_timer
))
3335 del_timer(&local
->tick_timer
);
3337 prism2_clear_cmd_queue(local
);
3339 skb_queue_purge(&local
->info_list
);
3340 skb_queue_purge(&local
->rx_list
);
3341 skb_queue_purge(&local
->sta_tx_exc_list
);
3343 if (local
->dev_enabled
)
3344 prism2_callback(local
, PRISM2_CALLBACK_DISABLE
);
3346 if (local
->ap
!= NULL
)
3347 hostap_free_data(local
->ap
);
3349 #ifndef PRISM2_NO_PROCFS_DEBUG
3350 if (local
->proc
!= NULL
)
3351 remove_proc_entry("registers", local
->proc
);
3352 #endif /* PRISM2_NO_PROCFS_DEBUG */
3353 hostap_remove_proc(local
);
3355 tx_cb
= local
->tx_callback
;
3356 while (tx_cb
!= NULL
) {
3358 tx_cb
= tx_cb
->next
;
3362 hostap_set_hostapd(local
, 0, 0);
3363 hostap_set_hostapd_sta(local
, 0, 0);
3365 for (i
= 0; i
< PRISM2_FRAG_CACHE_LEN
; i
++) {
3366 if (local
->frag_cache
[i
].skb
!= NULL
)
3367 dev_kfree_skb(local
->frag_cache
[i
].skb
);
3370 #ifdef PRISM2_DOWNLOAD_SUPPORT
3371 prism2_download_free_data(local
->dl_pri
);
3372 prism2_download_free_data(local
->dl_sec
);
3373 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3375 prism2_clear_set_tim_queue(local
);
3377 list_for_each_safe(ptr
, n
, &local
->bss_list
) {
3378 struct hostap_bss_info
*bss
=
3379 list_entry(ptr
, struct hostap_bss_info
, list
);
3384 kfree(local
->last_scan_results
);
3385 kfree(local
->generic_elem
);
3387 free_netdev(local
->dev
);
3391 #if (defined(PRISM2_PCI) && defined(CONFIG_PM)) || defined(PRISM2_PCCARD)
3392 static void prism2_suspend(struct net_device
*dev
)
3394 struct hostap_interface
*iface
;
3395 struct local_info
*local
;
3396 union iwreq_data wrqu
;
3398 iface
= netdev_priv(dev
);
3399 local
= iface
->local
;
3401 /* Send disconnect event, e.g., to trigger reassociation after resume
3402 * if wpa_supplicant is used. */
3403 memset(&wrqu
, 0, sizeof(wrqu
));
3404 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
3405 wireless_send_event(local
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
3407 /* Disable hardware and firmware */
3408 prism2_hw_shutdown(dev
, 0);
3410 #endif /* (PRISM2_PCI && CONFIG_PM) || PRISM2_PCCARD */
3413 /* These might at some point be compiled separately and used as separate
3414 * kernel modules or linked into one */
3415 #ifdef PRISM2_DOWNLOAD_SUPPORT
3416 #include "hostap_download.c"
3417 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3419 #ifdef PRISM2_CALLBACK
3420 /* External hostap_callback.c file can be used to, e.g., blink activity led.
3421 * This can use platform specific code and must define prism2_callback()
3422 * function (if PRISM2_CALLBACK is not defined, these function calls are not
3424 #include "hostap_callback.c"
3425 #endif /* PRISM2_CALLBACK */