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-2004, Jouni Malinen <jkmaline@cc.hut.fi>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. See README and COPYING for
15 * - there is currently no way of associating TX packets to correct wds device
16 * when TX Exc/OK event occurs, so all tx_packets and some
17 * tx_errors/tx_dropped are added to the main netdevice; using sw_support
18 * field in txdesc might be used to fix this (using Alloc event to increment
19 * tx_packets would need some further info in txfid table)
21 * Buffer Access Path (BAP) usage:
22 * Prism2 cards have two separate BAPs for accessing the card memory. These
23 * should allow concurrent access to two different frames and the driver
24 * previously used BAP0 for sending data and BAP1 for receiving data.
25 * However, there seems to be number of issues with concurrent access and at
26 * least one know hardware bug in using BAP0 and BAP1 concurrently with PCI
27 * Prism2.5. Therefore, the driver now only uses BAP0 for moving data between
28 * host and card memories. BAP0 accesses are protected with local->baplock
29 * (spin_lock_bh) to prevent concurrent use.
33 #include <linux/config.h>
34 #include <linux/version.h>
36 #include <asm/delay.h>
37 #include <asm/uaccess.h>
39 #include <linux/slab.h>
40 #include <linux/netdevice.h>
41 #include <linux/etherdevice.h>
42 #include <linux/proc_fs.h>
43 #include <linux/if_arp.h>
44 #include <linux/delay.h>
45 #include <linux/random.h>
46 #include <linux/wait.h>
47 #include <linux/sched.h>
48 #include <linux/rtnetlink.h>
49 #include <linux/wireless.h>
50 #include <net/iw_handler.h>
54 #include "hostap_80211.h"
56 #include "hostap_ap.h"
59 /* #define final_version */
61 static int mtu
= 1500;
62 module_param(mtu
, int, 0444);
63 MODULE_PARM_DESC(mtu
, "Maximum transfer unit");
65 static int channel
[MAX_PARM_DEVICES
] = { 3, DEF_INTS
};
66 module_param_array(channel
, int, NULL
, 0444);
67 MODULE_PARM_DESC(channel
, "Initial channel");
69 static char essid
[33] = "test";
70 module_param_string(essid
, essid
, sizeof(essid
), 0444);
71 MODULE_PARM_DESC(essid
, "Host AP's ESSID");
73 static int iw_mode
[MAX_PARM_DEVICES
] = { IW_MODE_MASTER
, DEF_INTS
};
74 module_param_array(iw_mode
, int, NULL
, 0444);
75 MODULE_PARM_DESC(iw_mode
, "Initial operation mode");
77 static int beacon_int
[MAX_PARM_DEVICES
] = { 100, DEF_INTS
};
78 module_param_array(beacon_int
, int, NULL
, 0444);
79 MODULE_PARM_DESC(beacon_int
, "Beacon interval (1 = 1024 usec)");
81 static int dtim_period
[MAX_PARM_DEVICES
] = { 1, DEF_INTS
};
82 module_param_array(dtim_period
, int, NULL
, 0444);
83 MODULE_PARM_DESC(dtim_period
, "DTIM period");
85 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
86 static int bus_master_threshold_rx
[MAX_PARM_DEVICES
] = { 100, DEF_INTS
};
87 module_param_array(bus_master_threshold_rx
, int, NULL
, 0444);
88 MODULE_PARM_DESC(bus_master_threshold_rx
, "Packet length threshold for using "
89 "PCI bus master on RX");
91 static int bus_master_threshold_tx
[MAX_PARM_DEVICES
] = { 100, DEF_INTS
};
92 module_param_array(bus_master_threshold_tx
, int, NULL
, 0444);
93 MODULE_PARM_DESC(bus_master_threshold_tx
, "Packet length threshold for using "
94 "PCI bus master on TX");
95 #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
97 static char dev_template
[16] = "wlan%d";
98 module_param_string(dev_template
, dev_template
, sizeof(dev_template
), 0444);
99 MODULE_PARM_DESC(dev_template
, "Prefix for network device name (default: "
103 #define EXTRA_EVENTS_WTERR 0
105 /* check WTERR events (Wait Time-out) in development versions */
106 #define EXTRA_EVENTS_WTERR HFA384X_EV_WTERR
109 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
110 #define EXTRA_EVENTS_BUS_MASTER (HFA384X_EV_PCI_M0 | HFA384X_EV_PCI_M1)
112 #define EXTRA_EVENTS_BUS_MASTER 0
115 /* Events that will be using BAP0 */
116 #define HFA384X_BAP0_EVENTS \
117 (HFA384X_EV_TXEXC | HFA384X_EV_RX | HFA384X_EV_INFO | HFA384X_EV_TX)
119 /* event mask, i.e., events that will result in an interrupt */
120 #define HFA384X_EVENT_MASK \
121 (HFA384X_BAP0_EVENTS | HFA384X_EV_ALLOC | HFA384X_EV_INFDROP | \
122 HFA384X_EV_CMD | HFA384X_EV_TICK | \
123 EXTRA_EVENTS_WTERR | EXTRA_EVENTS_BUS_MASTER)
125 /* Default TX control flags: use 802.11 headers and request interrupt for
126 * failed transmits. Frames that request ACK callback, will add
127 * _TX_OK flag and _ALT_RTRY flag may be used to select different retry policy.
129 #define HFA384X_TX_CTRL_FLAGS \
130 (HFA384X_TX_CTRL_802_11 | HFA384X_TX_CTRL_TX_EX)
134 #define HFA384X_CMD_BUSY_TIMEOUT 5000
135 #define HFA384X_BAP_BUSY_TIMEOUT 50000
138 #define HFA384X_CMD_COMPL_TIMEOUT 20000
139 #define HFA384X_DL_COMPL_TIMEOUT 1000000
141 /* Wait times for initialization; yield to other processes to avoid busy
142 * waiting for long time. */
143 #define HFA384X_INIT_TIMEOUT (HZ / 2) /* 500 ms */
144 #define HFA384X_ALLOC_COMPL_TIMEOUT (HZ / 20) /* 50 ms */
147 static void prism2_hw_reset(struct net_device
*dev
);
148 static void prism2_check_sta_fw_version(local_info_t
*local
);
150 #ifdef PRISM2_DOWNLOAD_SUPPORT
151 /* hostap_download.c */
152 static int prism2_download_aux_dump(struct net_device
*dev
,
153 unsigned int addr
, int len
, u8
*buf
);
154 static u8
* prism2_read_pda(struct net_device
*dev
);
155 static int prism2_download(local_info_t
*local
,
156 struct prism2_download_param
*param
);
157 static void prism2_download_free_data(struct prism2_download_data
*dl
);
158 static int prism2_download_volatile(local_info_t
*local
,
159 struct prism2_download_data
*param
);
160 static int prism2_download_genesis(local_info_t
*local
,
161 struct prism2_download_data
*param
);
162 static int prism2_get_ram_size(local_info_t
*local
);
163 #endif /* PRISM2_DOWNLOAD_SUPPORT */
168 #ifndef final_version
169 /* magic value written to SWSUPPORT0 reg. for detecting whether card is still
171 #define HFA384X_MAGIC 0x8A32
175 static u16
hfa384x_read_reg(struct net_device
*dev
, u16 reg
)
177 return HFA384X_INW(reg
);
181 static void hfa384x_read_regs(struct net_device
*dev
,
182 struct hfa384x_regs
*regs
)
184 regs
->cmd
= HFA384X_INW(HFA384X_CMD_OFF
);
185 regs
->evstat
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
186 regs
->offset0
= HFA384X_INW(HFA384X_OFFSET0_OFF
);
187 regs
->offset1
= HFA384X_INW(HFA384X_OFFSET1_OFF
);
188 regs
->swsupport0
= HFA384X_INW(HFA384X_SWSUPPORT0_OFF
);
193 * __hostap_cmd_queue_free - Free Prism2 command queue entry (private)
194 * @local: pointer to private Host AP driver data
195 * @entry: Prism2 command queue entry to be freed
196 * @del_req: request the entry to be removed
198 * Internal helper function for freeing Prism2 command queue entries.
199 * Caller must have acquired local->cmdlock before calling this function.
201 static inline void __hostap_cmd_queue_free(local_info_t
*local
,
202 struct hostap_cmd_queue
*entry
,
207 if (!list_empty(&entry
->list
)) {
208 list_del_init(&entry
->list
);
209 local
->cmd_queue_len
--;
213 if (atomic_dec_and_test(&entry
->usecnt
) && entry
->del_req
)
219 * hostap_cmd_queue_free - Free Prism2 command queue entry
220 * @local: pointer to private Host AP driver data
221 * @entry: Prism2 command queue entry to be freed
222 * @del_req: request the entry to be removed
224 * Free a Prism2 command queue entry.
226 static inline void hostap_cmd_queue_free(local_info_t
*local
,
227 struct hostap_cmd_queue
*entry
,
232 spin_lock_irqsave(&local
->cmdlock
, flags
);
233 __hostap_cmd_queue_free(local
, entry
, del_req
);
234 spin_unlock_irqrestore(&local
->cmdlock
, flags
);
239 * prism2_clear_cmd_queue - Free all pending Prism2 command queue entries
240 * @local: pointer to private Host AP driver data
242 static void prism2_clear_cmd_queue(local_info_t
*local
)
244 struct list_head
*ptr
, *n
;
246 struct hostap_cmd_queue
*entry
;
248 spin_lock_irqsave(&local
->cmdlock
, flags
);
249 list_for_each_safe(ptr
, n
, &local
->cmd_queue
) {
250 entry
= list_entry(ptr
, struct hostap_cmd_queue
, list
);
251 atomic_inc(&entry
->usecnt
);
252 printk(KERN_DEBUG
"%s: removed pending cmd_queue entry "
253 "(type=%d, cmd=0x%04x, param0=0x%04x)\n",
254 local
->dev
->name
, entry
->type
, entry
->cmd
,
256 __hostap_cmd_queue_free(local
, entry
, 1);
258 if (local
->cmd_queue_len
) {
259 /* This should not happen; print debug message and clear
261 printk(KERN_DEBUG
"%s: cmd_queue_len (%d) not zero after "
262 "flush\n", local
->dev
->name
, local
->cmd_queue_len
);
263 local
->cmd_queue_len
= 0;
265 spin_unlock_irqrestore(&local
->cmdlock
, flags
);
270 * hfa384x_cmd_issue - Issue a Prism2 command to the hardware
271 * @dev: pointer to net_device
272 * @entry: Prism2 command queue entry to be issued
274 static inline int hfa384x_cmd_issue(struct net_device
*dev
,
275 struct hostap_cmd_queue
*entry
)
277 struct hostap_interface
*iface
;
283 iface
= netdev_priv(dev
);
284 local
= iface
->local
;
286 if (local
->func
->card_present
&& !local
->func
->card_present(local
))
290 printk(KERN_DEBUG
"%s: driver bug - re-issuing command @%p\n",
294 /* wait until busy bit is clear; this should always be clear since the
295 * commands are serialized */
296 tries
= HFA384X_CMD_BUSY_TIMEOUT
;
297 while (HFA384X_INW(HFA384X_CMD_OFF
) & HFA384X_CMD_BUSY
&& tries
> 0) {
301 #ifndef final_version
302 if (tries
!= HFA384X_CMD_BUSY_TIMEOUT
) {
303 prism2_io_debug_error(dev
, 1);
304 printk(KERN_DEBUG
"%s: hfa384x_cmd_issue: cmd reg was busy "
305 "for %d usec\n", dev
->name
,
306 HFA384X_CMD_BUSY_TIMEOUT
- tries
);
310 reg
= HFA384X_INW(HFA384X_CMD_OFF
);
311 prism2_io_debug_error(dev
, 2);
312 printk(KERN_DEBUG
"%s: hfa384x_cmd_issue - timeout - "
313 "reg=0x%04x\n", dev
->name
, reg
);
318 spin_lock_irqsave(&local
->cmdlock
, flags
);
319 HFA384X_OUTW(entry
->param0
, HFA384X_PARAM0_OFF
);
320 HFA384X_OUTW(entry
->param1
, HFA384X_PARAM1_OFF
);
321 HFA384X_OUTW(entry
->cmd
, HFA384X_CMD_OFF
);
323 spin_unlock_irqrestore(&local
->cmdlock
, flags
);
330 * hfa384x_cmd - Issue a Prism2 command and wait (sleep) for completion
331 * @dev: pointer to net_device
332 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
333 * @param0: value for Param0 register
334 * @param1: value for Param1 register (pointer; %NULL if not used)
335 * @resp0: pointer for Resp0 data or %NULL if Resp0 is not needed
337 * Issue given command (possibly after waiting in command queue) and sleep
338 * until the command is completed (or timed out or interrupted). This can be
339 * called only from user process context.
341 static int hfa384x_cmd(struct net_device
*dev
, u16 cmd
, u16 param0
,
342 u16
*param1
, u16
*resp0
)
344 struct hostap_interface
*iface
;
346 int err
, res
, issue
, issued
= 0;
348 struct hostap_cmd_queue
*entry
;
349 DECLARE_WAITQUEUE(wait
, current
);
351 iface
= netdev_priv(dev
);
352 local
= iface
->local
;
354 if (in_interrupt()) {
355 printk(KERN_DEBUG
"%s: hfa384x_cmd called from interrupt "
356 "context\n", dev
->name
);
360 if (local
->cmd_queue_len
>= HOSTAP_CMD_QUEUE_MAX_LEN
) {
361 printk(KERN_DEBUG
"%s: hfa384x_cmd: cmd_queue full\n",
366 if (signal_pending(current
))
369 entry
= (struct hostap_cmd_queue
*)
370 kmalloc(sizeof(*entry
), GFP_ATOMIC
);
372 printk(KERN_DEBUG
"%s: hfa384x_cmd - kmalloc failed\n",
376 memset(entry
, 0, sizeof(*entry
));
377 atomic_set(&entry
->usecnt
, 1);
378 entry
->type
= CMD_SLEEP
;
380 entry
->param0
= param0
;
382 entry
->param1
= *param1
;
383 init_waitqueue_head(&entry
->compl);
385 /* prepare to wait for command completion event, but do not sleep yet
387 add_wait_queue(&entry
->compl, &wait
);
388 set_current_state(TASK_INTERRUPTIBLE
);
390 spin_lock_irqsave(&local
->cmdlock
, flags
);
391 issue
= list_empty(&local
->cmd_queue
);
394 list_add_tail(&entry
->list
, &local
->cmd_queue
);
395 local
->cmd_queue_len
++;
396 spin_unlock_irqrestore(&local
->cmdlock
, flags
);
400 goto wait_completion
;
402 if (signal_pending(current
))
406 if (hfa384x_cmd_issue(dev
, entry
))
413 if (!err
&& entry
->type
!= CMD_COMPLETED
) {
414 /* sleep until command is completed or timed out */
415 res
= schedule_timeout(2 * HZ
);
419 if (!err
&& signal_pending(current
))
423 /* the command was issued, so a CmdCompl event should occur
424 * soon; however, there's a pending signal and
425 * schedule_timeout() would be interrupted; wait a short period
426 * of time to avoid removing entry from the list before
431 set_current_state(TASK_RUNNING
);
432 remove_wait_queue(&entry
->compl, &wait
);
434 /* If entry->list is still in the list, it must be removed
435 * first and in this case prism2_cmd_ev() does not yet have
436 * local reference to it, and the data can be kfree()'d
437 * here. If the command completion event is still generated,
438 * it will be assigned to next (possibly) pending command, but
439 * the driver will reset the card anyway due to timeout
441 * If the entry is not in the list prism2_cmd_ev() has a local
442 * reference to it, but keeps cmdlock as long as the data is
443 * needed, so the data can be kfree()'d here. */
445 /* FIX: if the entry->list is in the list, it has not been completed
446 * yet, so removing it here is somewhat wrong.. this could cause
447 * references to freed memory and next list_del() causing NULL pointer
448 * dereference.. it would probably be better to leave the entry in the
449 * list and the list should be emptied during hw reset */
451 spin_lock_irqsave(&local
->cmdlock
, flags
);
452 if (!list_empty(&entry
->list
)) {
453 printk(KERN_DEBUG
"%s: hfa384x_cmd: entry still in list? "
454 "(entry=%p, type=%d, res=%d)\n", dev
->name
, entry
,
456 list_del_init(&entry
->list
);
457 local
->cmd_queue_len
--;
459 spin_unlock_irqrestore(&local
->cmdlock
, flags
);
462 printk(KERN_DEBUG
"%s: hfa384x_cmd: interrupted; err=%d\n",
468 if (entry
->type
!= CMD_COMPLETED
) {
469 u16 reg
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
470 printk(KERN_DEBUG
"%s: hfa384x_cmd: command was not "
471 "completed (res=%d, entry=%p, type=%d, cmd=0x%04x, "
472 "param0=0x%04x, EVSTAT=%04x INTEN=%04x)\n", dev
->name
,
473 res
, entry
, entry
->type
, entry
->cmd
, entry
->param0
, reg
,
474 HFA384X_INW(HFA384X_INTEN_OFF
));
475 if (reg
& HFA384X_EV_CMD
) {
476 /* Command completion event is pending, but the
477 * interrupt was not delivered - probably an issue
478 * with pcmcia-cs configuration. */
479 printk(KERN_WARNING
"%s: interrupt delivery does not "
480 "seem to work\n", dev
->name
);
482 prism2_io_debug_error(dev
, 3);
488 *resp0
= entry
->resp0
;
489 #ifndef final_version
491 printk(KERN_DEBUG
"%s: CMD=0x%04x => res=0x%02x, "
493 dev
->name
, cmd
, entry
->res
, entry
->resp0
);
495 #endif /* final_version */
499 hostap_cmd_queue_free(local
, entry
, 1);
505 * hfa384x_cmd_callback - Issue a Prism2 command; callback when completed
506 * @dev: pointer to net_device
507 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
508 * @param0: value for Param0 register
509 * @callback: command completion callback function (%NULL = no callback)
510 * @context: data pointer to be given to callback function
512 * Issue given command (possibly after waiting in command queue) and use
513 * callback function to indicate command completion. This can be called both
514 * from user and interrupt context. The callback function will be called in
515 * hardware IRQ context. It can be %NULL, when no function is called when
516 * command is completed.
518 static int hfa384x_cmd_callback(struct net_device
*dev
, u16 cmd
, u16 param0
,
519 void (*callback
)(struct net_device
*dev
,
520 void *context
, u16 resp0
,
524 struct hostap_interface
*iface
;
528 struct hostap_cmd_queue
*entry
;
530 iface
= netdev_priv(dev
);
531 local
= iface
->local
;
533 if (local
->cmd_queue_len
>= HOSTAP_CMD_QUEUE_MAX_LEN
+ 2) {
534 printk(KERN_DEBUG
"%s: hfa384x_cmd: cmd_queue full\n",
539 entry
= (struct hostap_cmd_queue
*)
540 kmalloc(sizeof(*entry
), GFP_ATOMIC
);
542 printk(KERN_DEBUG
"%s: hfa384x_cmd_callback - kmalloc "
543 "failed\n", dev
->name
);
546 memset(entry
, 0, sizeof(*entry
));
547 atomic_set(&entry
->usecnt
, 1);
548 entry
->type
= CMD_CALLBACK
;
550 entry
->param0
= param0
;
551 entry
->callback
= callback
;
552 entry
->context
= context
;
554 spin_lock_irqsave(&local
->cmdlock
, flags
);
555 issue
= list_empty(&local
->cmd_queue
);
558 list_add_tail(&entry
->list
, &local
->cmd_queue
);
559 local
->cmd_queue_len
++;
560 spin_unlock_irqrestore(&local
->cmdlock
, flags
);
562 if (issue
&& hfa384x_cmd_issue(dev
, entry
))
567 hostap_cmd_queue_free(local
, entry
, ret
);
574 * __hfa384x_cmd_no_wait - Issue a Prism2 command (private)
575 * @dev: pointer to net_device
576 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
577 * @param0: value for Param0 register
578 * @io_debug_num: I/O debug error number
580 * Shared helper function for hfa384x_cmd_wait() and hfa384x_cmd_no_wait().
582 static int __hfa384x_cmd_no_wait(struct net_device
*dev
, u16 cmd
, u16 param0
,
588 /* wait until busy bit is clear; this should always be clear since the
589 * commands are serialized */
590 tries
= HFA384X_CMD_BUSY_TIMEOUT
;
591 while (HFA384X_INW(HFA384X_CMD_OFF
) & HFA384X_CMD_BUSY
&& tries
> 0) {
596 reg
= HFA384X_INW(HFA384X_CMD_OFF
);
597 prism2_io_debug_error(dev
, io_debug_num
);
598 printk(KERN_DEBUG
"%s: __hfa384x_cmd_no_wait(%d) - timeout - "
599 "reg=0x%04x\n", dev
->name
, io_debug_num
, reg
);
604 HFA384X_OUTW(param0
, HFA384X_PARAM0_OFF
);
605 HFA384X_OUTW(cmd
, HFA384X_CMD_OFF
);
612 * hfa384x_cmd_wait - Issue a Prism2 command and busy wait for completion
613 * @dev: pointer to net_device
614 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
615 * @param0: value for Param0 register
617 static int hfa384x_cmd_wait(struct net_device
*dev
, u16 cmd
, u16 param0
)
622 res
= __hfa384x_cmd_no_wait(dev
, cmd
, param0
, 4);
626 /* wait for command completion */
627 if ((cmd
& HFA384X_CMDCODE_MASK
) == HFA384X_CMDCODE_DOWNLOAD
)
628 tries
= HFA384X_DL_COMPL_TIMEOUT
;
630 tries
= HFA384X_CMD_COMPL_TIMEOUT
;
632 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_CMD
) &&
638 reg
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
639 prism2_io_debug_error(dev
, 5);
640 printk(KERN_DEBUG
"%s: hfa384x_cmd_wait - timeout2 - "
641 "reg=0x%04x\n", dev
->name
, reg
);
645 res
= (HFA384X_INW(HFA384X_STATUS_OFF
) &
646 (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) | BIT(9) |
648 #ifndef final_version
650 printk(KERN_DEBUG
"%s: CMD=0x%04x => res=0x%02x\n",
651 dev
->name
, cmd
, res
);
655 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_EVACK_OFF
);
662 * hfa384x_cmd_no_wait - Issue a Prism2 command; do not wait for completion
663 * @dev: pointer to net_device
664 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
665 * @param0: value for Param0 register
667 static inline int hfa384x_cmd_no_wait(struct net_device
*dev
, u16 cmd
,
670 return __hfa384x_cmd_no_wait(dev
, cmd
, param0
, 6);
675 * prism2_cmd_ev - Prism2 command completion event handler
676 * @dev: pointer to net_device
678 * Interrupt handler for command completion events. Called by the main
679 * interrupt handler in hardware IRQ context. Read Resp0 and status registers
680 * from the hardware and ACK the event. Depending on the issued command type
681 * either wake up the sleeping process that is waiting for command completion
682 * or call the callback function. Issue the next command, if one is pending.
684 static void prism2_cmd_ev(struct net_device
*dev
)
686 struct hostap_interface
*iface
;
688 struct hostap_cmd_queue
*entry
= NULL
;
690 iface
= netdev_priv(dev
);
691 local
= iface
->local
;
693 spin_lock(&local
->cmdlock
);
694 if (!list_empty(&local
->cmd_queue
)) {
695 entry
= list_entry(local
->cmd_queue
.next
,
696 struct hostap_cmd_queue
, list
);
697 atomic_inc(&entry
->usecnt
);
698 list_del_init(&entry
->list
);
699 local
->cmd_queue_len
--;
701 if (!entry
->issued
) {
702 printk(KERN_DEBUG
"%s: Command completion event, but "
703 "cmd not issued\n", dev
->name
);
704 __hostap_cmd_queue_free(local
, entry
, 1);
708 spin_unlock(&local
->cmdlock
);
711 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_EVACK_OFF
);
712 printk(KERN_DEBUG
"%s: Command completion event, but no "
713 "pending commands\n", dev
->name
);
717 entry
->resp0
= HFA384X_INW(HFA384X_RESP0_OFF
);
718 entry
->res
= (HFA384X_INW(HFA384X_STATUS_OFF
) &
719 (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) |
720 BIT(9) | BIT(8))) >> 8;
721 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_EVACK_OFF
);
723 /* TODO: rest of the CmdEv handling could be moved to tasklet */
724 if (entry
->type
== CMD_SLEEP
) {
725 entry
->type
= CMD_COMPLETED
;
726 wake_up_interruptible(&entry
->compl);
727 } else if (entry
->type
== CMD_CALLBACK
) {
729 entry
->callback(dev
, entry
->context
, entry
->resp0
,
732 printk(KERN_DEBUG
"%s: Invalid command completion type %d\n",
733 dev
->name
, entry
->type
);
735 hostap_cmd_queue_free(local
, entry
, 1);
737 /* issue next command, if pending */
739 spin_lock(&local
->cmdlock
);
740 if (!list_empty(&local
->cmd_queue
)) {
741 entry
= list_entry(local
->cmd_queue
.next
,
742 struct hostap_cmd_queue
, list
);
743 if (entry
->issuing
) {
744 /* hfa384x_cmd() has already started issuing this
745 * command, so do not start here */
749 atomic_inc(&entry
->usecnt
);
751 spin_unlock(&local
->cmdlock
);
754 /* issue next command; if command issuing fails, remove the
755 * entry from cmd_queue */
756 int res
= hfa384x_cmd_issue(dev
, entry
);
757 spin_lock(&local
->cmdlock
);
758 __hostap_cmd_queue_free(local
, entry
, res
);
759 spin_unlock(&local
->cmdlock
);
764 static inline int hfa384x_wait_offset(struct net_device
*dev
, u16 o_off
)
766 int tries
= HFA384X_BAP_BUSY_TIMEOUT
;
767 int res
= HFA384X_INW(o_off
) & HFA384X_OFFSET_BUSY
;
769 while (res
&& tries
> 0) {
772 res
= HFA384X_INW(o_off
) & HFA384X_OFFSET_BUSY
;
778 /* Offset must be even */
779 static int hfa384x_setup_bap(struct net_device
*dev
, u16 bap
, u16 id
,
785 if (offset
% 2 || bap
> 1)
789 o_off
= HFA384X_OFFSET1_OFF
;
790 s_off
= HFA384X_SELECT1_OFF
;
792 o_off
= HFA384X_OFFSET0_OFF
;
793 s_off
= HFA384X_SELECT0_OFF
;
796 if (hfa384x_wait_offset(dev
, o_off
)) {
797 prism2_io_debug_error(dev
, 7);
798 printk(KERN_DEBUG
"%s: hfa384x_setup_bap - timeout before\n",
804 HFA384X_OUTW(id
, s_off
);
805 HFA384X_OUTW(offset
, o_off
);
807 if (hfa384x_wait_offset(dev
, o_off
)) {
808 prism2_io_debug_error(dev
, 8);
809 printk(KERN_DEBUG
"%s: hfa384x_setup_bap - timeout after\n",
814 #ifndef final_version
815 if (HFA384X_INW(o_off
) & HFA384X_OFFSET_ERR
) {
816 prism2_io_debug_error(dev
, 9);
817 printk(KERN_DEBUG
"%s: hfa384x_setup_bap - offset error "
818 "(%d,0x04%x,%d); reg=0x%04x\n",
819 dev
->name
, bap
, id
, offset
, HFA384X_INW(o_off
));
829 static int hfa384x_get_rid(struct net_device
*dev
, u16 rid
, void *buf
, int len
,
832 struct hostap_interface
*iface
;
835 struct hfa384x_rid_hdr rec
;
837 iface
= netdev_priv(dev
);
838 local
= iface
->local
;
841 printk(KERN_DEBUG
"%s: cannot get RID %04x (len=%d) - no PRI "
842 "f/w\n", dev
->name
, rid
, len
);
843 return -ENOTTY
; /* Well.. not really correct, but return
844 * something unique enough.. */
847 if ((local
->func
->card_present
&& !local
->func
->card_present(local
)) ||
848 local
->hw_downloading
)
851 res
= down_interruptible(&local
->rid_bap_sem
);
855 res
= hfa384x_cmd(dev
, HFA384X_CMDCODE_ACCESS
, rid
, NULL
, NULL
);
857 printk(KERN_DEBUG
"%s: hfa384x_get_rid: CMDCODE_ACCESS failed "
858 "(res=%d, rid=%04x, len=%d)\n",
859 dev
->name
, res
, rid
, len
);
860 up(&local
->rid_bap_sem
);
864 spin_lock_bh(&local
->baplock
);
866 res
= hfa384x_setup_bap(dev
, BAP0
, rid
, 0);
868 res
= hfa384x_from_bap(dev
, BAP0
, &rec
, sizeof(rec
));
870 if (le16_to_cpu(rec
.len
) == 0) {
871 /* RID not available */
875 rlen
= (le16_to_cpu(rec
.len
) - 1) * 2;
876 if (!res
&& exact_len
&& rlen
!= len
) {
877 printk(KERN_DEBUG
"%s: hfa384x_get_rid - RID len mismatch: "
878 "rid=0x%04x, len=%d (expected %d)\n",
879 dev
->name
, rid
, rlen
, len
);
884 res
= hfa384x_from_bap(dev
, BAP0
, buf
, len
);
886 spin_unlock_bh(&local
->baplock
);
887 up(&local
->rid_bap_sem
);
891 printk(KERN_DEBUG
"%s: hfa384x_get_rid (rid=%04x, "
892 "len=%d) - failed - res=%d\n", dev
->name
, rid
,
894 if (res
== -ETIMEDOUT
)
895 prism2_hw_reset(dev
);
903 static int hfa384x_set_rid(struct net_device
*dev
, u16 rid
, void *buf
, int len
)
905 struct hostap_interface
*iface
;
907 struct hfa384x_rid_hdr rec
;
910 iface
= netdev_priv(dev
);
911 local
= iface
->local
;
914 printk(KERN_DEBUG
"%s: cannot set RID %04x (len=%d) - no PRI "
915 "f/w\n", dev
->name
, rid
, len
);
916 return -ENOTTY
; /* Well.. not really correct, but return
917 * something unique enough.. */
920 if ((local
->func
->card_present
&& !local
->func
->card_present(local
)) ||
921 local
->hw_downloading
)
924 rec
.rid
= cpu_to_le16(rid
);
925 /* RID len in words and +1 for rec.rid */
926 rec
.len
= cpu_to_le16(len
/ 2 + len
% 2 + 1);
928 res
= down_interruptible(&local
->rid_bap_sem
);
932 spin_lock_bh(&local
->baplock
);
933 res
= hfa384x_setup_bap(dev
, BAP0
, rid
, 0);
935 res
= hfa384x_to_bap(dev
, BAP0
, &rec
, sizeof(rec
));
937 res
= hfa384x_to_bap(dev
, BAP0
, buf
, len
);
938 spin_unlock_bh(&local
->baplock
);
941 printk(KERN_DEBUG
"%s: hfa384x_set_rid (rid=%04x, len=%d) - "
942 "failed - res=%d\n", dev
->name
, rid
, len
, res
);
943 up(&local
->rid_bap_sem
);
947 res
= hfa384x_cmd(dev
, HFA384X_CMDCODE_ACCESS_WRITE
, rid
, NULL
, NULL
);
948 up(&local
->rid_bap_sem
);
950 printk(KERN_DEBUG
"%s: hfa384x_set_rid: CMDCODE_ACCESS_WRITE "
951 "failed (res=%d, rid=%04x, len=%d)\n",
952 dev
->name
, res
, rid
, len
);
956 if (res
== -ETIMEDOUT
)
957 prism2_hw_reset(dev
);
963 static void hfa384x_disable_interrupts(struct net_device
*dev
)
965 /* disable interrupts and clear event status */
966 HFA384X_OUTW(0, HFA384X_INTEN_OFF
);
967 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF
);
971 static void hfa384x_enable_interrupts(struct net_device
*dev
)
973 /* ack pending events and enable interrupts from selected events */
974 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF
);
975 HFA384X_OUTW(HFA384X_EVENT_MASK
, HFA384X_INTEN_OFF
);
979 static void hfa384x_events_no_bap0(struct net_device
*dev
)
981 HFA384X_OUTW(HFA384X_EVENT_MASK
& ~HFA384X_BAP0_EVENTS
,
986 static void hfa384x_events_all(struct net_device
*dev
)
988 HFA384X_OUTW(HFA384X_EVENT_MASK
, HFA384X_INTEN_OFF
);
992 static void hfa384x_events_only_cmd(struct net_device
*dev
)
994 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_INTEN_OFF
);
998 static u16
hfa384x_allocate_fid(struct net_device
*dev
, int len
)
1001 unsigned long delay
;
1003 /* FIX: this could be replace with hfa384x_cmd() if the Alloc event
1004 * below would be handled like CmdCompl event (sleep here, wake up from
1005 * interrupt handler */
1006 if (hfa384x_cmd_wait(dev
, HFA384X_CMDCODE_ALLOC
, len
)) {
1007 printk(KERN_DEBUG
"%s: cannot allocate fid, len=%d\n",
1012 delay
= jiffies
+ HFA384X_ALLOC_COMPL_TIMEOUT
;
1013 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_ALLOC
) &&
1014 time_before(jiffies
, delay
))
1016 if (!(HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_ALLOC
)) {
1017 printk("%s: fid allocate, len=%d - timeout\n", dev
->name
, len
);
1021 fid
= HFA384X_INW(HFA384X_ALLOCFID_OFF
);
1022 HFA384X_OUTW(HFA384X_EV_ALLOC
, HFA384X_EVACK_OFF
);
1028 static int prism2_reset_port(struct net_device
*dev
)
1030 struct hostap_interface
*iface
;
1031 local_info_t
*local
;
1034 iface
= netdev_priv(dev
);
1035 local
= iface
->local
;
1037 if (!local
->dev_enabled
)
1040 res
= hfa384x_cmd(dev
, HFA384X_CMDCODE_DISABLE
, 0,
1043 printk(KERN_DEBUG
"%s: reset port failed to disable port\n",
1046 res
= hfa384x_cmd(dev
, HFA384X_CMDCODE_ENABLE
, 0,
1049 printk(KERN_DEBUG
"%s: reset port failed to enable "
1050 "port\n", dev
->name
);
1053 /* It looks like at least some STA firmware versions reset
1054 * fragmentation threshold back to 2346 after enable command. Restore
1055 * the configured value, if it differs from this default. */
1056 if (local
->fragm_threshold
!= 2346 &&
1057 hostap_set_word(dev
, HFA384X_RID_FRAGMENTATIONTHRESHOLD
,
1058 local
->fragm_threshold
)) {
1059 printk(KERN_DEBUG
"%s: failed to restore fragmentation "
1060 "threshold (%d) after Port0 enable\n",
1061 dev
->name
, local
->fragm_threshold
);
1068 static int prism2_get_version_info(struct net_device
*dev
, u16 rid
,
1071 struct hfa384x_comp_ident comp
;
1072 struct hostap_interface
*iface
;
1073 local_info_t
*local
;
1075 iface
= netdev_priv(dev
);
1076 local
= iface
->local
;
1078 if (local
->no_pri
) {
1079 /* PRI f/w not yet available - cannot read RIDs */
1082 if (hfa384x_get_rid(dev
, rid
, &comp
, sizeof(comp
), 1) < 0) {
1083 printk(KERN_DEBUG
"Could not get RID for component %s\n", txt
);
1087 printk(KERN_INFO
"%s: %s: id=0x%02x v%d.%d.%d\n", dev
->name
, txt
,
1088 __le16_to_cpu(comp
.id
), __le16_to_cpu(comp
.major
),
1089 __le16_to_cpu(comp
.minor
), __le16_to_cpu(comp
.variant
));
1094 static int prism2_setup_rids(struct net_device
*dev
)
1096 struct hostap_interface
*iface
;
1097 local_info_t
*local
;
1101 iface
= netdev_priv(dev
);
1102 local
= iface
->local
;
1104 hostap_set_word(dev
, HFA384X_RID_TICKTIME
, 2000);
1106 if (!local
->fw_ap
) {
1107 tmp
= hostap_get_porttype(local
);
1108 ret
= hostap_set_word(dev
, HFA384X_RID_CNFPORTTYPE
, tmp
);
1110 printk("%s: Port type setting to %d failed\n",
1116 /* Setting SSID to empty string seems to kill the card in Host AP mode
1118 if (local
->iw_mode
!= IW_MODE_MASTER
|| local
->essid
[0] != '\0') {
1119 ret
= hostap_set_string(dev
, HFA384X_RID_CNFOWNSSID
,
1122 printk("%s: AP own SSID setting failed\n", dev
->name
);
1127 ret
= hostap_set_word(dev
, HFA384X_RID_CNFMAXDATALEN
,
1128 PRISM2_DATA_MAXLEN
);
1130 printk("%s: MAC data length setting to %d failed\n",
1131 dev
->name
, PRISM2_DATA_MAXLEN
);
1135 if (hfa384x_get_rid(dev
, HFA384X_RID_CHANNELLIST
, &tmp
, 2, 1) < 0) {
1136 printk("%s: Channel list read failed\n", dev
->name
);
1140 local
->channel_mask
= __le16_to_cpu(tmp
);
1142 if (local
->channel
< 1 || local
->channel
> 14 ||
1143 !(local
->channel_mask
& (1 << (local
->channel
- 1)))) {
1144 printk(KERN_WARNING
"%s: Channel setting out of range "
1145 "(%d)!\n", dev
->name
, local
->channel
);
1150 ret
= hostap_set_word(dev
, HFA384X_RID_CNFOWNCHANNEL
, local
->channel
);
1152 printk("%s: Channel setting to %d failed\n",
1153 dev
->name
, local
->channel
);
1157 ret
= hostap_set_word(dev
, HFA384X_RID_CNFBEACONINT
,
1160 printk("%s: Beacon interval setting to %d failed\n",
1161 dev
->name
, local
->beacon_int
);
1162 /* this may fail with Symbol/Lucent firmware */
1163 if (ret
== -ETIMEDOUT
)
1167 ret
= hostap_set_word(dev
, HFA384X_RID_CNFOWNDTIMPERIOD
,
1168 local
->dtim_period
);
1170 printk("%s: DTIM period setting to %d failed\n",
1171 dev
->name
, local
->dtim_period
);
1172 /* this may fail with Symbol/Lucent firmware */
1173 if (ret
== -ETIMEDOUT
)
1177 ret
= hostap_set_word(dev
, HFA384X_RID_PROMISCUOUSMODE
,
1180 printk(KERN_INFO
"%s: Setting promiscuous mode (%d) failed\n",
1181 dev
->name
, local
->is_promisc
);
1183 if (!local
->fw_ap
) {
1184 ret
= hostap_set_string(dev
, HFA384X_RID_CNFDESIREDSSID
,
1187 printk("%s: Desired SSID setting failed\n", dev
->name
);
1192 /* Setup TXRateControl, defaults to allow use of 1, 2, 5.5, and
1193 * 11 Mbps in automatic TX rate fallback and 1 and 2 Mbps as basic
1195 if (local
->tx_rate_control
== 0) {
1196 local
->tx_rate_control
=
1197 HFA384X_RATES_1MBPS
|
1198 HFA384X_RATES_2MBPS
|
1199 HFA384X_RATES_5MBPS
|
1200 HFA384X_RATES_11MBPS
;
1202 if (local
->basic_rates
== 0)
1203 local
->basic_rates
= HFA384X_RATES_1MBPS
| HFA384X_RATES_2MBPS
;
1205 if (!local
->fw_ap
) {
1206 ret
= hostap_set_word(dev
, HFA384X_RID_TXRATECONTROL
,
1207 local
->tx_rate_control
);
1209 printk("%s: TXRateControl setting to %d failed\n",
1210 dev
->name
, local
->tx_rate_control
);
1214 ret
= hostap_set_word(dev
, HFA384X_RID_CNFSUPPORTEDRATES
,
1215 local
->tx_rate_control
);
1217 printk("%s: cnfSupportedRates setting to %d failed\n",
1218 dev
->name
, local
->tx_rate_control
);
1221 ret
= hostap_set_word(dev
, HFA384X_RID_CNFBASICRATES
,
1222 local
->basic_rates
);
1224 printk("%s: cnfBasicRates setting to %d failed\n",
1225 dev
->name
, local
->basic_rates
);
1228 ret
= hostap_set_word(dev
, HFA384X_RID_CREATEIBSS
, 1);
1230 printk("%s: Create IBSS setting to 1 failed\n",
1235 if (local
->name_set
)
1236 (void) hostap_set_string(dev
, HFA384X_RID_CNFOWNNAME
,
1239 if (hostap_set_encryption(local
)) {
1240 printk(KERN_INFO
"%s: could not configure encryption\n",
1244 (void) hostap_set_antsel(local
);
1246 if (hostap_set_roaming(local
)) {
1247 printk(KERN_INFO
"%s: could not set host roaming\n",
1251 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,6,3) &&
1252 hostap_set_word(dev
, HFA384X_RID_CNFENHSECURITY
, local
->enh_sec
))
1253 printk(KERN_INFO
"%s: cnfEnhSecurity setting to 0x%x failed\n",
1254 dev
->name
, local
->enh_sec
);
1256 /* 32-bit tallies were added in STA f/w 0.8.0, but they were apparently
1257 * not working correctly (last seven counters report bogus values).
1258 * This has been fixed in 0.8.2, so enable 32-bit tallies only
1259 * beginning with that firmware version. Another bug fix for 32-bit
1260 * tallies in 1.4.0; should 16-bit tallies be used for some other
1262 if (local
->sta_fw_ver
>= PRISM2_FW_VER(0,8,2)) {
1263 if (hostap_set_word(dev
, HFA384X_RID_CNFTHIRTY2TALLY
, 1)) {
1264 printk(KERN_INFO
"%s: cnfThirty2Tally setting "
1265 "failed\n", dev
->name
);
1266 local
->tallies32
= 0;
1268 local
->tallies32
= 1;
1270 local
->tallies32
= 0;
1272 hostap_set_auth_algs(local
);
1274 if (hostap_set_word(dev
, HFA384X_RID_FRAGMENTATIONTHRESHOLD
,
1275 local
->fragm_threshold
)) {
1276 printk(KERN_INFO
"%s: setting FragmentationThreshold to %d "
1277 "failed\n", dev
->name
, local
->fragm_threshold
);
1280 if (hostap_set_word(dev
, HFA384X_RID_RTSTHRESHOLD
,
1281 local
->rts_threshold
)) {
1282 printk(KERN_INFO
"%s: setting RTSThreshold to %d failed\n",
1283 dev
->name
, local
->rts_threshold
);
1286 if (local
->manual_retry_count
>= 0 &&
1287 hostap_set_word(dev
, HFA384X_RID_CNFALTRETRYCOUNT
,
1288 local
->manual_retry_count
)) {
1289 printk(KERN_INFO
"%s: setting cnfAltRetryCount to %d failed\n",
1290 dev
->name
, local
->manual_retry_count
);
1293 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,3,1) &&
1294 hfa384x_get_rid(dev
, HFA384X_RID_CNFDBMADJUST
, &tmp
, 2, 1) == 2) {
1295 local
->rssi_to_dBm
= le16_to_cpu(tmp
);
1298 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,7,0) && local
->wpa
&&
1299 hostap_set_word(dev
, HFA384X_RID_SSNHANDLINGMODE
, 1)) {
1300 printk(KERN_INFO
"%s: setting ssnHandlingMode to 1 failed\n",
1304 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,7,0) && local
->generic_elem
&&
1305 hfa384x_set_rid(dev
, HFA384X_RID_GENERICELEMENT
,
1306 local
->generic_elem
, local
->generic_elem_len
)) {
1307 printk(KERN_INFO
"%s: setting genericElement failed\n",
1316 static int prism2_hw_init(struct net_device
*dev
, int initial
)
1318 struct hostap_interface
*iface
;
1319 local_info_t
*local
;
1321 unsigned long start
, delay
;
1323 PDEBUG(DEBUG_FLOW
, "prism2_hw_init()\n");
1325 iface
= netdev_priv(dev
);
1326 local
= iface
->local
;
1328 clear_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
);
1331 /* initialize HFA 384x */
1332 ret
= hfa384x_cmd_no_wait(dev
, HFA384X_CMDCODE_INIT
, 0);
1334 printk(KERN_INFO
"%s: first command failed - assuming card "
1335 "does not have primary firmware\n", dev_info
);
1338 if (first
&& (HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_CMD
)) {
1339 /* EvStat has Cmd bit set in some cases, so retry once if no
1340 * wait was needed */
1341 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_EVACK_OFF
);
1342 printk(KERN_DEBUG
"%s: init command completed too quickly - "
1343 "retrying\n", dev
->name
);
1349 delay
= jiffies
+ HFA384X_INIT_TIMEOUT
;
1350 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_CMD
) &&
1351 time_before(jiffies
, delay
))
1353 if (!(HFA384X_INW(HFA384X_EVSTAT_OFF
) & HFA384X_EV_CMD
)) {
1354 printk(KERN_DEBUG
"%s: assuming no Primary image in "
1355 "flash - card initialization not completed\n",
1358 #ifdef PRISM2_DOWNLOAD_SUPPORT
1359 if (local
->sram_type
== -1)
1360 local
->sram_type
= prism2_get_ram_size(local
);
1361 #endif /* PRISM2_DOWNLOAD_SUPPORT */
1365 printk(KERN_DEBUG
"prism2_hw_init: initialized in %lu ms\n",
1366 (jiffies
- start
) * 1000 / HZ
);
1367 HFA384X_OUTW(HFA384X_EV_CMD
, HFA384X_EVACK_OFF
);
1372 static int prism2_hw_init2(struct net_device
*dev
, int initial
)
1374 struct hostap_interface
*iface
;
1375 local_info_t
*local
;
1378 iface
= netdev_priv(dev
);
1379 local
= iface
->local
;
1381 #ifdef PRISM2_DOWNLOAD_SUPPORT
1386 local
->pda
= prism2_read_pda(dev
);
1387 #endif /* PRISM2_DOWNLOAD_SUPPORT */
1389 hfa384x_disable_interrupts(dev
);
1391 #ifndef final_version
1392 HFA384X_OUTW(HFA384X_MAGIC
, HFA384X_SWSUPPORT0_OFF
);
1393 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF
) != HFA384X_MAGIC
) {
1394 printk("SWSUPPORT0 write/read failed: %04X != %04X\n",
1395 HFA384X_INW(HFA384X_SWSUPPORT0_OFF
), HFA384X_MAGIC
);
1400 if (initial
|| local
->pri_only
) {
1401 hfa384x_events_only_cmd(dev
);
1402 /* get card version information */
1403 if (prism2_get_version_info(dev
, HFA384X_RID_NICID
, "NIC") ||
1404 prism2_get_version_info(dev
, HFA384X_RID_PRIID
, "PRI")) {
1405 hfa384x_disable_interrupts(dev
);
1409 if (prism2_get_version_info(dev
, HFA384X_RID_STAID
, "STA")) {
1410 printk(KERN_DEBUG
"%s: Failed to read STA f/w version "
1411 "- only Primary f/w present\n", dev
->name
);
1412 local
->pri_only
= 1;
1415 local
->pri_only
= 0;
1416 hfa384x_disable_interrupts(dev
);
1419 /* FIX: could convert allocate_fid to use sleeping CmdCompl wait and
1420 * enable interrupts before this. This would also require some sort of
1421 * sleeping AllocEv waiting */
1423 /* allocate TX FIDs */
1424 local
->txfid_len
= PRISM2_TXFID_LEN
;
1425 for (i
= 0; i
< PRISM2_TXFID_COUNT
; i
++) {
1426 local
->txfid
[i
] = hfa384x_allocate_fid(dev
, local
->txfid_len
);
1427 if (local
->txfid
[i
] == 0xffff && local
->txfid_len
> 1600) {
1428 local
->txfid
[i
] = hfa384x_allocate_fid(dev
, 1600);
1429 if (local
->txfid
[i
] != 0xffff) {
1430 printk(KERN_DEBUG
"%s: Using shorter TX FID "
1431 "(1600 bytes)\n", dev
->name
);
1432 local
->txfid_len
= 1600;
1435 if (local
->txfid
[i
] == 0xffff)
1437 local
->intransmitfid
[i
] = PRISM2_TXFID_EMPTY
;
1440 hfa384x_events_only_cmd(dev
);
1443 struct list_head
*ptr
;
1444 prism2_check_sta_fw_version(local
);
1446 if (hfa384x_get_rid(dev
, HFA384X_RID_CNFOWNMACADDR
,
1447 &dev
->dev_addr
, 6, 1) < 0) {
1448 printk("%s: could not get own MAC address\n",
1451 list_for_each(ptr
, &local
->hostap_interfaces
) {
1452 iface
= list_entry(ptr
, struct hostap_interface
, list
);
1453 memcpy(iface
->dev
->dev_addr
, dev
->dev_addr
, ETH_ALEN
);
1455 } else if (local
->fw_ap
)
1456 prism2_check_sta_fw_version(local
);
1458 prism2_setup_rids(dev
);
1460 /* MAC is now configured, but port 0 is not yet enabled */
1465 printk(KERN_WARNING
"%s: Initialization failed\n", dev_info
);
1470 static int prism2_hw_enable(struct net_device
*dev
, int initial
)
1472 struct hostap_interface
*iface
;
1473 local_info_t
*local
;
1476 iface
= netdev_priv(dev
);
1477 local
= iface
->local
;
1478 was_resetting
= local
->hw_resetting
;
1480 if (hfa384x_cmd(dev
, HFA384X_CMDCODE_ENABLE
, 0, NULL
, NULL
)) {
1481 printk("%s: MAC port 0 enabling failed\n", dev
->name
);
1485 local
->hw_ready
= 1;
1486 local
->hw_reset_tries
= 0;
1487 local
->hw_resetting
= 0;
1488 hfa384x_enable_interrupts(dev
);
1490 /* at least D-Link DWL-650 seems to require additional port reset
1491 * before it starts acting as an AP, so reset port automatically
1492 * here just in case */
1493 if (initial
&& prism2_reset_port(dev
)) {
1494 printk("%s: MAC port 0 reseting failed\n", dev
->name
);
1498 if (was_resetting
&& netif_queue_stopped(dev
)) {
1499 /* If hw_reset() was called during pending transmit, netif
1500 * queue was stopped. Wake it up now since the wlan card has
1502 netif_wake_queue(dev
);
1509 static int prism2_hw_config(struct net_device
*dev
, int initial
)
1511 struct hostap_interface
*iface
;
1512 local_info_t
*local
;
1514 iface
= netdev_priv(dev
);
1515 local
= iface
->local
;
1517 if (local
->hw_downloading
)
1520 if (prism2_hw_init(dev
, initial
)) {
1521 return local
->no_pri
? 0 : 1;
1524 if (prism2_hw_init2(dev
, initial
))
1527 /* Enable firmware if secondary image is loaded and at least one of the
1528 * netdevices is up. */
1529 if (!local
->pri_only
&&
1530 (initial
== 0 || (initial
== 2 && local
->num_dev_open
> 0))) {
1531 if (!local
->dev_enabled
)
1532 prism2_callback(local
, PRISM2_CALLBACK_ENABLE
);
1533 local
->dev_enabled
= 1;
1534 return prism2_hw_enable(dev
, initial
);
1541 static void prism2_hw_shutdown(struct net_device
*dev
, int no_disable
)
1543 struct hostap_interface
*iface
;
1544 local_info_t
*local
;
1546 iface
= netdev_priv(dev
);
1547 local
= iface
->local
;
1549 /* Allow only command completion events during disable */
1550 hfa384x_events_only_cmd(dev
);
1552 local
->hw_ready
= 0;
1553 if (local
->dev_enabled
)
1554 prism2_callback(local
, PRISM2_CALLBACK_DISABLE
);
1555 local
->dev_enabled
= 0;
1557 if (local
->func
->card_present
&& !local
->func
->card_present(local
)) {
1558 printk(KERN_DEBUG
"%s: card already removed or not configured "
1559 "during shutdown\n", dev
->name
);
1563 if ((no_disable
& HOSTAP_HW_NO_DISABLE
) == 0 &&
1564 hfa384x_cmd(dev
, HFA384X_CMDCODE_DISABLE
, 0, NULL
, NULL
))
1565 printk(KERN_WARNING
"%s: Shutdown failed\n", dev_info
);
1567 hfa384x_disable_interrupts(dev
);
1569 if (no_disable
& HOSTAP_HW_ENABLE_CMDCOMPL
)
1570 hfa384x_events_only_cmd(dev
);
1572 prism2_clear_cmd_queue(local
);
1576 static void prism2_hw_reset(struct net_device
*dev
)
1578 struct hostap_interface
*iface
;
1579 local_info_t
*local
;
1582 static long last_reset
= 0;
1584 /* do not reset card more than once per second to avoid ending up in a
1585 * busy loop reseting the card */
1586 if (time_before_eq(jiffies
, last_reset
+ HZ
))
1588 last_reset
= jiffies
;
1591 iface
= netdev_priv(dev
);
1592 local
= iface
->local
;
1594 if (in_interrupt()) {
1595 printk(KERN_DEBUG
"%s: driver bug - prism2_hw_reset() called "
1596 "in interrupt context\n", dev
->name
);
1600 if (local
->hw_downloading
)
1603 if (local
->hw_resetting
) {
1604 printk(KERN_WARNING
"%s: %s: already resetting card - "
1605 "ignoring reset request\n", dev_info
, dev
->name
);
1609 local
->hw_reset_tries
++;
1610 if (local
->hw_reset_tries
> 10) {
1611 printk(KERN_WARNING
"%s: too many reset tries, skipping\n",
1616 printk(KERN_WARNING
"%s: %s: resetting card\n", dev_info
, dev
->name
);
1617 hfa384x_disable_interrupts(dev
);
1618 local
->hw_resetting
= 1;
1619 if (local
->func
->cor_sreset
) {
1620 /* Host system seems to hang in some cases with high traffic
1621 * load or shared interrupts during COR sreset. Disable shared
1622 * interrupts during reset to avoid these crashes. COS sreset
1623 * takes quite a long time, so it is unfortunate that this
1624 * seems to be needed. Anyway, I do not know of any better way
1625 * of avoiding the crash. */
1626 disable_irq(dev
->irq
);
1627 local
->func
->cor_sreset(local
);
1628 enable_irq(dev
->irq
);
1630 prism2_hw_shutdown(dev
, 1);
1631 prism2_hw_config(dev
, 0);
1632 local
->hw_resetting
= 0;
1634 #ifdef PRISM2_DOWNLOAD_SUPPORT
1635 if (local
->dl_pri
) {
1636 printk(KERN_DEBUG
"%s: persistent download of primary "
1637 "firmware\n", dev
->name
);
1638 if (prism2_download_genesis(local
, local
->dl_pri
) < 0)
1639 printk(KERN_WARNING
"%s: download (PRI) failed\n",
1643 if (local
->dl_sec
) {
1644 printk(KERN_DEBUG
"%s: persistent download of secondary "
1645 "firmware\n", dev
->name
);
1646 if (prism2_download_volatile(local
, local
->dl_sec
) < 0)
1647 printk(KERN_WARNING
"%s: download (SEC) failed\n",
1650 #endif /* PRISM2_DOWNLOAD_SUPPORT */
1652 /* TODO: restore beacon TIM bits for STAs that have buffered frames */
1656 static void prism2_schedule_reset(local_info_t
*local
)
1658 schedule_work(&local
->reset_queue
);
1662 /* Called only as scheduled task after noticing card timeout in interrupt
1664 static void handle_reset_queue(void *data
)
1666 local_info_t
*local
= (local_info_t
*) data
;
1668 printk(KERN_DEBUG
"%s: scheduled card reset\n", local
->dev
->name
);
1669 prism2_hw_reset(local
->dev
);
1671 if (netif_queue_stopped(local
->dev
)) {
1674 for (i
= 0; i
< PRISM2_TXFID_COUNT
; i
++)
1675 if (local
->intransmitfid
[i
] == PRISM2_TXFID_EMPTY
) {
1676 PDEBUG(DEBUG_EXTRA
, "prism2_tx_timeout: "
1678 netif_wake_queue(local
->dev
);
1685 static int prism2_get_txfid_idx(local_info_t
*local
)
1688 unsigned long flags
;
1690 spin_lock_irqsave(&local
->txfidlock
, flags
);
1691 end
= idx
= local
->next_txfid
;
1693 if (local
->intransmitfid
[idx
] == PRISM2_TXFID_EMPTY
) {
1694 local
->intransmitfid
[idx
] = PRISM2_TXFID_RESERVED
;
1695 spin_unlock_irqrestore(&local
->txfidlock
, flags
);
1699 if (idx
>= PRISM2_TXFID_COUNT
)
1701 } while (idx
!= end
);
1702 spin_unlock_irqrestore(&local
->txfidlock
, flags
);
1704 PDEBUG(DEBUG_EXTRA2
, "prism2_get_txfid_idx: no room in txfid buf: "
1705 "packet dropped\n");
1706 local
->stats
.tx_dropped
++;
1712 /* Called only from hardware IRQ */
1713 static void prism2_transmit_cb(struct net_device
*dev
, void *context
,
1716 struct hostap_interface
*iface
;
1717 local_info_t
*local
;
1718 int idx
= (int) context
;
1720 iface
= netdev_priv(dev
);
1721 local
= iface
->local
;
1724 printk(KERN_DEBUG
"%s: prism2_transmit_cb - res=0x%02x\n",
1729 if (idx
< 0 || idx
>= PRISM2_TXFID_COUNT
) {
1730 printk(KERN_DEBUG
"%s: prism2_transmit_cb called with invalid "
1731 "idx=%d\n", dev
->name
, idx
);
1735 if (!test_and_clear_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
)) {
1736 printk(KERN_DEBUG
"%s: driver bug: prism2_transmit_cb called "
1737 "with no pending transmit\n", dev
->name
);
1740 if (netif_queue_stopped(dev
)) {
1741 /* ready for next TX, so wake up queue that was stopped in
1742 * prism2_transmit() */
1743 netif_wake_queue(dev
);
1746 spin_lock(&local
->txfidlock
);
1748 /* With reclaim, Resp0 contains new txfid for transmit; the old txfid
1749 * will be automatically allocated for the next TX frame */
1750 local
->intransmitfid
[idx
] = resp0
;
1752 PDEBUG(DEBUG_FID
, "%s: prism2_transmit_cb: txfid[%d]=0x%04x, "
1753 "resp0=0x%04x, transmit_txfid=0x%04x\n",
1754 dev
->name
, idx
, local
->txfid
[idx
],
1755 resp0
, local
->intransmitfid
[local
->next_txfid
]);
1758 if (idx
>= PRISM2_TXFID_COUNT
)
1760 local
->next_txfid
= idx
;
1762 /* check if all TX buffers are occupied */
1764 if (local
->intransmitfid
[idx
] == PRISM2_TXFID_EMPTY
) {
1765 spin_unlock(&local
->txfidlock
);
1769 if (idx
>= PRISM2_TXFID_COUNT
)
1771 } while (idx
!= local
->next_txfid
);
1772 spin_unlock(&local
->txfidlock
);
1774 /* no empty TX buffers, stop queue */
1775 netif_stop_queue(dev
);
1779 /* Called only from software IRQ if PCI bus master is not used (with bus master
1780 * this can be called both from software and hardware IRQ) */
1781 static int prism2_transmit(struct net_device
*dev
, int idx
)
1783 struct hostap_interface
*iface
;
1784 local_info_t
*local
;
1787 iface
= netdev_priv(dev
);
1788 local
= iface
->local
;
1790 /* The driver tries to stop netif queue so that there would not be
1791 * more than one attempt to transmit frames going on; check that this
1792 * is really the case */
1794 if (test_and_set_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
)) {
1795 printk(KERN_DEBUG
"%s: driver bug - prism2_transmit() called "
1796 "when previous TX was pending\n", dev
->name
);
1800 /* stop the queue for the time that transmit is pending */
1801 netif_stop_queue(dev
);
1803 /* transmit packet */
1804 res
= hfa384x_cmd_callback(
1806 HFA384X_CMDCODE_TRANSMIT
| HFA384X_CMD_TX_RECLAIM
,
1808 prism2_transmit_cb
, (void *) idx
);
1811 struct net_device_stats
*stats
;
1812 printk(KERN_DEBUG
"%s: prism2_transmit: CMDCODE_TRANSMIT "
1813 "failed (res=%d)\n", dev
->name
, res
);
1814 stats
= hostap_get_stats(dev
);
1815 stats
->tx_dropped
++;
1816 netif_wake_queue(dev
);
1819 dev
->trans_start
= jiffies
;
1821 /* Since we did not wait for command completion, the card continues
1822 * to process on the background and we will finish handling when
1823 * command completion event is handled (prism2_cmd_ev() function) */
1829 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
1830 /* Called only from hardware IRQ */
1831 static void prism2_tx_cb(struct net_device
*dev
, void *context
,
1834 struct hostap_interface
*iface
;
1835 local_info_t
*local
;
1837 int buf_len
= (int) context
;
1839 iface
= netdev_priv(dev
);
1840 local
= iface
->local
;
1843 printk(KERN_DEBUG
"%s: prism2_tx_cb - res=0x%02x\n",
1848 addr
= virt_to_phys(local
->bus_m0_buf
);
1849 HFA384X_OUTW((addr
& 0xffff0000) >> 16, HFA384X_PCI_M0_ADDRH_OFF
);
1850 HFA384X_OUTW(addr
& 0x0000ffff, HFA384X_PCI_M0_ADDRL_OFF
);
1851 HFA384X_OUTW(buf_len
/ 2, HFA384X_PCI_M0_LEN_OFF
);
1852 HFA384X_OUTW(HFA384X_PCI_CTL_TO_BAP
, HFA384X_PCI_M0_CTL_OFF
);
1854 #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
1857 /* Send IEEE 802.11 frame (convert the header into Prism2 TX descriptor and
1858 * send the payload with this descriptor) */
1859 /* Called only from software IRQ */
1860 static int prism2_tx_80211(struct sk_buff
*skb
, struct net_device
*dev
)
1862 struct hostap_interface
*iface
;
1863 local_info_t
*local
;
1864 struct hfa384x_tx_frame txdesc
;
1865 struct hostap_ieee80211_hdr
*hdr
;
1866 struct hostap_skb_tx_data
*meta
;
1867 int hdr_len
, data_len
, idx
, res
, ret
= -1;
1870 iface
= netdev_priv(dev
);
1871 local
= iface
->local
;
1873 meta
= (struct hostap_skb_tx_data
*) skb
->cb
;
1874 hdr
= (struct hostap_ieee80211_hdr
*) skb
->data
;
1876 prism2_callback(local
, PRISM2_CALLBACK_TX_START
);
1878 if ((local
->func
->card_present
&& !local
->func
->card_present(local
)) ||
1879 !local
->hw_ready
|| local
->hw_downloading
|| local
->pri_only
) {
1880 if (net_ratelimit()) {
1881 printk(KERN_DEBUG
"%s: prism2_tx_80211: hw not ready -"
1882 " skipping\n", dev
->name
);
1887 memset(&txdesc
, 0, sizeof(txdesc
));
1889 /* skb->data starts with txdesc->frame_control */
1891 memcpy(&txdesc
.frame_control
, skb
->data
, hdr_len
);
1892 fc
= le16_to_cpu(txdesc
.frame_control
);
1893 if (WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_DATA
&&
1894 (fc
& WLAN_FC_FROMDS
) && (fc
& WLAN_FC_TODS
) && skb
->len
>= 30) {
1896 memcpy(txdesc
.addr4
, skb
->data
+ hdr_len
, ETH_ALEN
);
1897 hdr_len
+= ETH_ALEN
;
1900 tx_control
= local
->tx_control
;
1901 if (meta
->tx_cb_idx
) {
1902 tx_control
|= HFA384X_TX_CTRL_TX_OK
;
1903 txdesc
.sw_support
= cpu_to_le16(meta
->tx_cb_idx
);
1905 txdesc
.tx_control
= cpu_to_le16(tx_control
);
1906 txdesc
.tx_rate
= meta
->rate
;
1908 data_len
= skb
->len
- hdr_len
;
1909 txdesc
.data_len
= cpu_to_le16(data_len
);
1910 txdesc
.len
= cpu_to_be16(data_len
);
1912 idx
= prism2_get_txfid_idx(local
);
1916 if (local
->frame_dump
& PRISM2_DUMP_TX_HDR
)
1917 hostap_dump_tx_header(dev
->name
, &txdesc
);
1919 spin_lock(&local
->baplock
);
1920 res
= hfa384x_setup_bap(dev
, BAP0
, local
->txfid
[idx
], 0);
1922 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
1923 if (!res
&& skb
->len
>= local
->bus_master_threshold_tx
) {
1927 local
->bus_m0_tx_idx
= idx
;
1929 /* FIX: BAP0 should be locked during bus master transfer, but
1930 * baplock with BH's disabled is not OK for this; netif queue
1931 * stopping is not enough since BAP0 is used also for RID
1934 /* stop the queue for the time that bus mastering on BAP0 is
1936 netif_stop_queue(dev
);
1938 spin_unlock(&local
->baplock
);
1940 /* Copy frame data to bus_m0_buf */
1941 pos
= local
->bus_m0_buf
;
1942 memcpy(pos
, &txdesc
, sizeof(txdesc
));
1943 pos
+= sizeof(txdesc
);
1944 memcpy(pos
, skb
->data
+ hdr_len
, skb
->len
- hdr_len
);
1945 pos
+= skb
->len
- hdr_len
;
1946 buf_len
= pos
- local
->bus_m0_buf
;
1950 #ifdef PRISM2_ENABLE_BEFORE_TX_BUS_MASTER
1951 /* Any RX packet seems to break something with TX bus
1952 * mastering; enable command is enough to fix this.. */
1953 if (hfa384x_cmd_callback(dev
, HFA384X_CMDCODE_ENABLE
, 0,
1954 prism2_tx_cb
, (void *) buf_len
)) {
1955 printk(KERN_DEBUG
"%s: TX: enable port0 failed\n",
1958 #else /* PRISM2_ENABLE_BEFORE_TX_BUS_MASTER */
1959 prism2_tx_cb(dev
, (void *) buf_len
, 0, 0);
1960 #endif /* PRISM2_ENABLE_BEFORE_TX_BUS_MASTER */
1962 /* Bus master transfer will be started from command completion
1963 * event handler and TX handling will be finished by calling
1964 * prism2_transmit() from bus master event handler */
1967 #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
1970 res
= hfa384x_to_bap(dev
, BAP0
, &txdesc
, sizeof(txdesc
));
1972 res
= hfa384x_to_bap(dev
, BAP0
, skb
->data
+ hdr_len
,
1973 skb
->len
- hdr_len
);
1974 spin_unlock(&local
->baplock
);
1977 res
= prism2_transmit(dev
, idx
);
1979 printk(KERN_DEBUG
"%s: prism2_tx_80211 - to BAP0 failed\n",
1981 local
->intransmitfid
[idx
] = PRISM2_TXFID_EMPTY
;
1982 schedule_work(&local
->reset_queue
);
1989 prism2_callback(local
, PRISM2_CALLBACK_TX_END
);
1994 /* Some SMP systems have reported number of odd errors with hostap_pci. fid
1995 * register has changed values between consecutive reads for an unknown reason.
1996 * This should really not happen, so more debugging is needed. This test
1997 * version is a big slower, but it will detect most of such register changes
1998 * and will try to get the correct fid eventually. */
1999 #define EXTRA_FID_READ_TESTS
2001 static inline u16
prism2_read_fid_reg(struct net_device
*dev
, u16 reg
)
2003 #ifdef EXTRA_FID_READ_TESTS
2004 u16 val
, val2
, val3
;
2007 for (i
= 0; i
< 10; i
++) {
2008 val
= HFA384X_INW(reg
);
2009 val2
= HFA384X_INW(reg
);
2010 val3
= HFA384X_INW(reg
);
2012 if (val
== val2
&& val
== val3
)
2015 printk(KERN_DEBUG
"%s: detected fid change (try=%d, reg=%04x):"
2016 " %04x %04x %04x\n",
2017 dev
->name
, i
, reg
, val
, val2
, val3
);
2018 if ((val
== val2
|| val
== val3
) && val
!= 0)
2020 if (val2
== val3
&& val2
!= 0)
2023 printk(KERN_WARNING
"%s: Uhhuh.. could not read good fid from reg "
2024 "%04x (%04x %04x %04x)\n", dev
->name
, reg
, val
, val2
, val3
);
2026 #else /* EXTRA_FID_READ_TESTS */
2027 return HFA384X_INW(reg
);
2028 #endif /* EXTRA_FID_READ_TESTS */
2032 /* Called only as a tasklet (software IRQ) */
2033 static void prism2_rx(local_info_t
*local
)
2035 struct net_device
*dev
= local
->dev
;
2036 int res
, rx_pending
= 0;
2037 u16 len
, hdr_len
, rxfid
, status
, macport
;
2038 struct net_device_stats
*stats
;
2039 struct hfa384x_rx_frame rxdesc
;
2040 struct sk_buff
*skb
= NULL
;
2042 prism2_callback(local
, PRISM2_CALLBACK_RX_START
);
2043 stats
= hostap_get_stats(dev
);
2045 rxfid
= prism2_read_fid_reg(dev
, HFA384X_RXFID_OFF
);
2046 #ifndef final_version
2048 rxfid
= HFA384X_INW(HFA384X_RXFID_OFF
);
2049 printk(KERN_DEBUG
"prism2_rx: rxfid=0 (next 0x%04x)\n",
2052 schedule_work(&local
->reset_queue
);
2055 /* try to continue with the new rxfid value */
2059 spin_lock(&local
->baplock
);
2060 res
= hfa384x_setup_bap(dev
, BAP0
, rxfid
, 0);
2062 res
= hfa384x_from_bap(dev
, BAP0
, &rxdesc
, sizeof(rxdesc
));
2065 spin_unlock(&local
->baplock
);
2066 printk(KERN_DEBUG
"%s: copy from BAP0 failed %d\n", dev
->name
,
2068 if (res
== -ETIMEDOUT
) {
2069 schedule_work(&local
->reset_queue
);
2074 len
= le16_to_cpu(rxdesc
.data_len
);
2075 hdr_len
= sizeof(rxdesc
);
2076 status
= le16_to_cpu(rxdesc
.status
);
2077 macport
= (status
>> 8) & 0x07;
2079 /* Drop frames with too large reported payload length. Monitor mode
2080 * seems to sometimes pass frames (e.g., ctrl::ack) with signed and
2081 * negative value, so allow also values 65522 .. 65534 (-14 .. -2) for
2083 if (len
> PRISM2_DATA_MAXLEN
+ 8 /* WEP */) {
2084 if (macport
== 7 && local
->iw_mode
== IW_MODE_MONITOR
) {
2085 if (len
>= (u16
) -14) {
2086 hdr_len
-= 65535 - len
;
2091 spin_unlock(&local
->baplock
);
2092 printk(KERN_DEBUG
"%s: Received frame with invalid "
2093 "length 0x%04x\n", dev
->name
, len
);
2094 hostap_dump_rx_header(dev
->name
, &rxdesc
);
2099 skb
= dev_alloc_skb(len
+ hdr_len
);
2101 spin_unlock(&local
->baplock
);
2102 printk(KERN_DEBUG
"%s: RX failed to allocate skb\n",
2107 memcpy(skb_put(skb
, hdr_len
), &rxdesc
, hdr_len
);
2109 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
2110 if (len
>= local
->bus_master_threshold_rx
) {
2113 hfa384x_events_no_bap1(dev
);
2115 local
->rx_skb
= skb
;
2116 /* Internal BAP0 offset points to the byte following rxdesc;
2117 * copy rest of the data using bus master */
2118 addr
= virt_to_phys(skb_put(skb
, len
));
2119 HFA384X_OUTW((addr
& 0xffff0000) >> 16,
2120 HFA384X_PCI_M0_ADDRH_OFF
);
2121 HFA384X_OUTW(addr
& 0x0000ffff, HFA384X_PCI_M0_ADDRL_OFF
);
2124 HFA384X_OUTW(len
/ 2, HFA384X_PCI_M0_LEN_OFF
);
2125 HFA384X_OUTW(HFA384X_PCI_CTL_FROM_BAP
, HFA384X_PCI_M0_CTL_OFF
);
2127 /* pci_bus_m1 event will be generated when data transfer is
2128 * complete and the frame will then be added to rx_list and
2129 * rx_tasklet is scheduled */
2132 /* Have to release baplock before returning, although BAP0
2133 * should really not be used before DMA transfer has been
2135 spin_unlock(&local
->baplock
);
2137 #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
2140 res
= hfa384x_from_bap(dev
, BAP0
, skb_put(skb
, len
),
2142 spin_unlock(&local
->baplock
);
2144 printk(KERN_DEBUG
"%s: RX failed to read "
2145 "frame data\n", dev
->name
);
2149 skb_queue_tail(&local
->rx_list
, skb
);
2150 tasklet_schedule(&local
->rx_tasklet
);
2154 prism2_callback(local
, PRISM2_CALLBACK_RX_END
);
2156 HFA384X_OUTW(HFA384X_EV_RX
, HFA384X_EVACK_OFF
);
2162 stats
->rx_dropped
++;
2169 /* Called only as a tasklet (software IRQ) */
2170 static void hostap_rx_skb(local_info_t
*local
, struct sk_buff
*skb
)
2172 struct hfa384x_rx_frame
*rxdesc
;
2173 struct net_device
*dev
= skb
->dev
;
2174 struct hostap_80211_rx_status stats
;
2175 int hdrlen
, rx_hdrlen
;
2177 rx_hdrlen
= sizeof(*rxdesc
);
2178 if (skb
->len
< sizeof(*rxdesc
)) {
2179 /* Allow monitor mode to receive shorter frames */
2180 if (local
->iw_mode
== IW_MODE_MONITOR
&&
2181 skb
->len
>= sizeof(*rxdesc
) - 30) {
2182 rx_hdrlen
= skb
->len
;
2189 rxdesc
= (struct hfa384x_rx_frame
*) skb
->data
;
2191 if (local
->frame_dump
& PRISM2_DUMP_RX_HDR
&&
2192 skb
->len
>= sizeof(*rxdesc
))
2193 hostap_dump_rx_header(dev
->name
, rxdesc
);
2195 if (le16_to_cpu(rxdesc
->status
) & HFA384X_RX_STATUS_FCSERR
&&
2196 (!local
->monitor_allow_fcserr
||
2197 local
->iw_mode
!= IW_MODE_MONITOR
))
2200 if (skb
->len
> PRISM2_DATA_MAXLEN
) {
2201 printk(KERN_DEBUG
"%s: RX: len(%d) > MAX(%d)\n",
2202 dev
->name
, skb
->len
, PRISM2_DATA_MAXLEN
);
2206 stats
.mac_time
= le32_to_cpu(rxdesc
->time
);
2207 stats
.signal
= rxdesc
->signal
- local
->rssi_to_dBm
;
2208 stats
.noise
= rxdesc
->silence
- local
->rssi_to_dBm
;
2209 stats
.rate
= rxdesc
->rate
;
2211 /* Convert Prism2 RX structure into IEEE 802.11 header */
2212 hdrlen
= hostap_80211_get_hdrlen(le16_to_cpu(rxdesc
->frame_control
));
2213 if (hdrlen
> rx_hdrlen
)
2216 memmove(skb_pull(skb
, rx_hdrlen
- hdrlen
),
2217 &rxdesc
->frame_control
, hdrlen
);
2219 hostap_80211_rx(dev
, skb
, &stats
);
2227 /* Called only as a tasklet (software IRQ) */
2228 static void hostap_rx_tasklet(unsigned long data
)
2230 local_info_t
*local
= (local_info_t
*) data
;
2231 struct sk_buff
*skb
;
2233 while ((skb
= skb_dequeue(&local
->rx_list
)) != NULL
)
2234 hostap_rx_skb(local
, skb
);
2238 /* Called only from hardware IRQ */
2239 static void prism2_alloc_ev(struct net_device
*dev
)
2241 struct hostap_interface
*iface
;
2242 local_info_t
*local
;
2246 iface
= netdev_priv(dev
);
2247 local
= iface
->local
;
2249 fid
= prism2_read_fid_reg(dev
, HFA384X_ALLOCFID_OFF
);
2251 PDEBUG(DEBUG_FID
, "FID: interrupt: ALLOC - fid=0x%04x\n", fid
);
2253 spin_lock(&local
->txfidlock
);
2254 idx
= local
->next_alloc
;
2257 if (local
->txfid
[idx
] == fid
) {
2258 PDEBUG(DEBUG_FID
, "FID: found matching txfid[%d]\n",
2261 #ifndef final_version
2262 if (local
->intransmitfid
[idx
] == PRISM2_TXFID_EMPTY
)
2263 printk("Already released txfid found at idx "
2265 if (local
->intransmitfid
[idx
] == PRISM2_TXFID_RESERVED
)
2266 printk("Already reserved txfid found at idx "
2269 local
->intransmitfid
[idx
] = PRISM2_TXFID_EMPTY
;
2271 local
->next_alloc
= idx
>= PRISM2_TXFID_COUNT
? 0 :
2274 if (!test_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
) &&
2275 netif_queue_stopped(dev
))
2276 netif_wake_queue(dev
);
2278 spin_unlock(&local
->txfidlock
);
2283 if (idx
>= PRISM2_TXFID_COUNT
)
2285 } while (idx
!= local
->next_alloc
);
2287 printk(KERN_WARNING
"%s: could not find matching txfid (0x%04x, new "
2288 "read 0x%04x) for alloc event\n", dev
->name
, fid
,
2289 HFA384X_INW(HFA384X_ALLOCFID_OFF
));
2290 printk(KERN_DEBUG
"TXFIDs:");
2291 for (idx
= 0; idx
< PRISM2_TXFID_COUNT
; idx
++)
2292 printk(" %04x[%04x]", local
->txfid
[idx
],
2293 local
->intransmitfid
[idx
]);
2295 spin_unlock(&local
->txfidlock
);
2297 /* FIX: should probably schedule reset; reference to one txfid was lost
2298 * completely.. Bad things will happen if we run out of txfids
2299 * Actually, this will cause netdev watchdog to notice TX timeout and
2300 * then card reset after all txfids have been leaked. */
2304 /* Called only as a tasklet (software IRQ) */
2305 static void hostap_tx_callback(local_info_t
*local
,
2306 struct hfa384x_tx_frame
*txdesc
, int ok
,
2309 u16 sw_support
, hdrlen
, len
;
2310 struct sk_buff
*skb
;
2311 struct hostap_tx_callback_info
*cb
;
2313 /* Make sure that frame was from us. */
2314 if (memcmp(txdesc
->addr2
, local
->dev
->dev_addr
, ETH_ALEN
)) {
2315 printk(KERN_DEBUG
"%s: TX callback - foreign frame\n",
2320 sw_support
= le16_to_cpu(txdesc
->sw_support
);
2322 spin_lock(&local
->lock
);
2323 cb
= local
->tx_callback
;
2324 while (cb
!= NULL
&& cb
->idx
!= sw_support
)
2326 spin_unlock(&local
->lock
);
2329 printk(KERN_DEBUG
"%s: could not find TX callback (idx %d)\n",
2330 local
->dev
->name
, sw_support
);
2334 hdrlen
= hostap_80211_get_hdrlen(le16_to_cpu(txdesc
->frame_control
));
2335 len
= le16_to_cpu(txdesc
->data_len
);
2336 skb
= dev_alloc_skb(hdrlen
+ len
);
2338 printk(KERN_DEBUG
"%s: hostap_tx_callback failed to allocate "
2339 "skb\n", local
->dev
->name
);
2343 memcpy(skb_put(skb
, hdrlen
), (void *) &txdesc
->frame_control
, hdrlen
);
2345 memcpy(skb_put(skb
, len
), payload
, len
);
2347 skb
->dev
= local
->dev
;
2348 skb
->mac
.raw
= skb
->data
;
2350 cb
->func(skb
, ok
, cb
->data
);
2354 /* Called only as a tasklet (software IRQ) */
2355 static int hostap_tx_compl_read(local_info_t
*local
, int error
,
2356 struct hfa384x_tx_frame
*txdesc
,
2361 struct net_device
*dev
= local
->dev
;
2363 fid
= prism2_read_fid_reg(dev
, HFA384X_TXCOMPLFID_OFF
);
2365 PDEBUG(DEBUG_FID
, "interrupt: TX (err=%d) - fid=0x%04x\n", fid
, error
);
2367 spin_lock(&local
->baplock
);
2368 res
= hfa384x_setup_bap(dev
, BAP0
, fid
, 0);
2370 res
= hfa384x_from_bap(dev
, BAP0
, txdesc
, sizeof(*txdesc
));
2372 PDEBUG(DEBUG_EXTRA
, "%s: TX (err=%d) - fid=0x%04x - could not "
2373 "read txdesc\n", dev
->name
, error
, fid
);
2374 if (res
== -ETIMEDOUT
) {
2375 schedule_work(&local
->reset_queue
);
2380 if (txdesc
->sw_support
) {
2381 len
= le16_to_cpu(txdesc
->data_len
);
2382 if (len
< PRISM2_DATA_MAXLEN
) {
2383 *payload
= (char *) kmalloc(len
, GFP_ATOMIC
);
2384 if (*payload
== NULL
||
2385 hfa384x_from_bap(dev
, BAP0
, *payload
, len
)) {
2386 PDEBUG(DEBUG_EXTRA
, "%s: could not read TX "
2387 "frame payload\n", dev
->name
);
2397 spin_unlock(&local
->baplock
);
2403 /* Called only as a tasklet (software IRQ) */
2404 static void prism2_tx_ev(local_info_t
*local
)
2406 struct net_device
*dev
= local
->dev
;
2407 char *payload
= NULL
;
2408 struct hfa384x_tx_frame txdesc
;
2410 if (hostap_tx_compl_read(local
, 0, &txdesc
, &payload
))
2413 if (local
->frame_dump
& PRISM2_DUMP_TX_HDR
) {
2414 PDEBUG(DEBUG_EXTRA
, "%s: TX - status=0x%04x "
2415 "retry_count=%d tx_rate=%d seq_ctrl=%d "
2417 dev
->name
, le16_to_cpu(txdesc
.status
),
2418 txdesc
.retry_count
, txdesc
.tx_rate
,
2419 le16_to_cpu(txdesc
.seq_ctrl
),
2420 le16_to_cpu(txdesc
.duration_id
));
2423 if (txdesc
.sw_support
)
2424 hostap_tx_callback(local
, &txdesc
, 1, payload
);
2428 HFA384X_OUTW(HFA384X_EV_TX
, HFA384X_EVACK_OFF
);
2432 /* Called only as a tasklet (software IRQ) */
2433 static void hostap_sta_tx_exc_tasklet(unsigned long data
)
2435 local_info_t
*local
= (local_info_t
*) data
;
2436 struct sk_buff
*skb
;
2438 while ((skb
= skb_dequeue(&local
->sta_tx_exc_list
)) != NULL
) {
2439 struct hfa384x_tx_frame
*txdesc
=
2440 (struct hfa384x_tx_frame
*) skb
->data
;
2442 if (skb
->len
>= sizeof(*txdesc
)) {
2443 /* Convert Prism2 RX structure into IEEE 802.11 header
2445 u16 fc
= le16_to_cpu(txdesc
->frame_control
);
2446 int hdrlen
= hostap_80211_get_hdrlen(fc
);
2447 memmove(skb_pull(skb
, sizeof(*txdesc
) - hdrlen
),
2448 &txdesc
->frame_control
, hdrlen
);
2450 hostap_handle_sta_tx_exc(local
, skb
);
2457 /* Called only as a tasklet (software IRQ) */
2458 static void prism2_txexc(local_info_t
*local
)
2460 struct net_device
*dev
= local
->dev
;
2463 char *payload
= NULL
;
2464 struct hfa384x_tx_frame txdesc
;
2466 show_dump
= local
->frame_dump
& PRISM2_DUMP_TXEXC_HDR
;
2467 local
->stats
.tx_errors
++;
2469 res
= hostap_tx_compl_read(local
, 1, &txdesc
, &payload
);
2470 HFA384X_OUTW(HFA384X_EV_TXEXC
, HFA384X_EVACK_OFF
);
2474 status
= le16_to_cpu(txdesc
.status
);
2476 /* We produce a TXDROP event only for retry or lifetime
2477 * exceeded, because that's the only status that really mean
2478 * that this particular node went away.
2479 * Other errors means that *we* screwed up. - Jean II */
2480 if (status
& (HFA384X_TX_STATUS_RETRYERR
| HFA384X_TX_STATUS_AGEDERR
))
2482 union iwreq_data wrqu
;
2484 /* Copy 802.11 dest address. */
2485 memcpy(wrqu
.addr
.sa_data
, txdesc
.addr1
, ETH_ALEN
);
2486 wrqu
.addr
.sa_family
= ARPHRD_ETHER
;
2487 wireless_send_event(dev
, IWEVTXDROP
, &wrqu
, NULL
);
2491 if (local
->iw_mode
== IW_MODE_MASTER
||
2492 local
->iw_mode
== IW_MODE_REPEAT
||
2493 local
->wds_type
& HOSTAP_WDS_AP_CLIENT
) {
2494 struct sk_buff
*skb
;
2495 skb
= dev_alloc_skb(sizeof(txdesc
));
2497 memcpy(skb_put(skb
, sizeof(txdesc
)), &txdesc
,
2499 skb_queue_tail(&local
->sta_tx_exc_list
, skb
);
2500 tasklet_schedule(&local
->sta_tx_exc_tasklet
);
2504 if (txdesc
.sw_support
)
2505 hostap_tx_callback(local
, &txdesc
, 0, payload
);
2511 PDEBUG(DEBUG_EXTRA
, "%s: TXEXC - status=0x%04x (%s%s%s%s)"
2512 " tx_control=%04x\n",
2514 status
& HFA384X_TX_STATUS_RETRYERR
? "[RetryErr]" : "",
2515 status
& HFA384X_TX_STATUS_AGEDERR
? "[AgedErr]" : "",
2516 status
& HFA384X_TX_STATUS_DISCON
? "[Discon]" : "",
2517 status
& HFA384X_TX_STATUS_FORMERR
? "[FormErr]" : "",
2518 le16_to_cpu(txdesc
.tx_control
));
2520 fc
= le16_to_cpu(txdesc
.frame_control
);
2521 PDEBUG(DEBUG_EXTRA
, " retry_count=%d tx_rate=%d fc=0x%04x "
2522 "(%s%s%s::%d%s%s)\n",
2523 txdesc
.retry_count
, txdesc
.tx_rate
, fc
,
2524 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_MGMT
? "Mgmt" : "",
2525 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_CTRL
? "Ctrl" : "",
2526 WLAN_FC_GET_TYPE(fc
) == WLAN_FC_TYPE_DATA
? "Data" : "",
2527 WLAN_FC_GET_STYPE(fc
),
2528 fc
& WLAN_FC_TODS
? " ToDS" : "",
2529 fc
& WLAN_FC_FROMDS
? " FromDS" : "");
2530 PDEBUG(DEBUG_EXTRA
, " A1=" MACSTR
" A2=" MACSTR
" A3="
2531 MACSTR
" A4=" MACSTR
"\n",
2532 MAC2STR(txdesc
.addr1
), MAC2STR(txdesc
.addr2
),
2533 MAC2STR(txdesc
.addr3
), MAC2STR(txdesc
.addr4
));
2537 /* Called only as a tasklet (software IRQ) */
2538 static void hostap_info_tasklet(unsigned long data
)
2540 local_info_t
*local
= (local_info_t
*) data
;
2541 struct sk_buff
*skb
;
2543 while ((skb
= skb_dequeue(&local
->info_list
)) != NULL
) {
2544 hostap_info_process(local
, skb
);
2550 /* Called only as a tasklet (software IRQ) */
2551 static void prism2_info(local_info_t
*local
)
2553 struct net_device
*dev
= local
->dev
;
2556 struct hfa384x_info_frame info
;
2557 struct sk_buff
*skb
;
2559 fid
= HFA384X_INW(HFA384X_INFOFID_OFF
);
2561 spin_lock(&local
->baplock
);
2562 res
= hfa384x_setup_bap(dev
, BAP0
, fid
, 0);
2564 res
= hfa384x_from_bap(dev
, BAP0
, &info
, sizeof(info
));
2566 spin_unlock(&local
->baplock
);
2567 printk(KERN_DEBUG
"Could not get info frame (fid=0x%04x)\n",
2569 if (res
== -ETIMEDOUT
) {
2570 schedule_work(&local
->reset_queue
);
2575 le16_to_cpus(&info
.len
);
2576 le16_to_cpus(&info
.type
);
2577 left
= (info
.len
- 1) * 2;
2579 if (info
.len
& 0x8000 || info
.len
== 0 || left
> 2060) {
2580 /* data register seems to give 0x8000 in some error cases even
2581 * though busy bit is not set in offset register;
2582 * in addition, length must be at least 1 due to type field */
2583 spin_unlock(&local
->baplock
);
2584 printk(KERN_DEBUG
"%s: Received info frame with invalid "
2585 "length 0x%04x (type 0x%04x)\n", dev
->name
, info
.len
,
2590 skb
= dev_alloc_skb(sizeof(info
) + left
);
2592 spin_unlock(&local
->baplock
);
2593 printk(KERN_DEBUG
"%s: Could not allocate skb for info "
2594 "frame\n", dev
->name
);
2598 memcpy(skb_put(skb
, sizeof(info
)), &info
, sizeof(info
));
2599 if (left
> 0 && hfa384x_from_bap(dev
, BAP0
, skb_put(skb
, left
), left
))
2601 spin_unlock(&local
->baplock
);
2602 printk(KERN_WARNING
"%s: Info frame read failed (fid=0x%04x, "
2603 "len=0x%04x, type=0x%04x\n",
2604 dev
->name
, fid
, info
.len
, info
.type
);
2608 spin_unlock(&local
->baplock
);
2610 skb_queue_tail(&local
->info_list
, skb
);
2611 tasklet_schedule(&local
->info_tasklet
);
2614 HFA384X_OUTW(HFA384X_EV_INFO
, HFA384X_EVACK_OFF
);
2618 /* Called only as a tasklet (software IRQ) */
2619 static void hostap_bap_tasklet(unsigned long data
)
2621 local_info_t
*local
= (local_info_t
*) data
;
2622 struct net_device
*dev
= local
->dev
;
2626 if (local
->func
->card_present
&& !local
->func
->card_present(local
))
2629 set_bit(HOSTAP_BITS_BAP_TASKLET
, &local
->bits
);
2631 /* Process all pending BAP events without generating new interrupts
2633 while (frames
-- > 0) {
2634 ev
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
2635 if (ev
== 0xffff || !(ev
& HFA384X_BAP0_EVENTS
))
2637 if (ev
& HFA384X_EV_RX
)
2639 if (ev
& HFA384X_EV_INFO
)
2641 if (ev
& HFA384X_EV_TX
)
2642 prism2_tx_ev(local
);
2643 if (ev
& HFA384X_EV_TXEXC
)
2644 prism2_txexc(local
);
2647 set_bit(HOSTAP_BITS_BAP_TASKLET2
, &local
->bits
);
2648 clear_bit(HOSTAP_BITS_BAP_TASKLET
, &local
->bits
);
2650 /* Enable interrupts for new BAP events */
2651 hfa384x_events_all(dev
);
2652 clear_bit(HOSTAP_BITS_BAP_TASKLET2
, &local
->bits
);
2656 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
2657 /* Called only from hardware IRQ */
2658 static void prism2_bus_master_ev(struct net_device
*dev
, int bap
)
2660 struct hostap_interface
*iface
;
2661 local_info_t
*local
;
2663 iface
= netdev_priv(dev
);
2664 local
= iface
->local
;
2667 /* FIX: frame payload was DMA'd to skb->data; might need to
2668 * invalidate data cache for that memory area */
2669 skb_queue_tail(&local
->rx_list
, local
->rx_skb
);
2670 tasklet_schedule(&local
->rx_tasklet
);
2671 HFA384X_OUTW(HFA384X_EV_RX
, HFA384X_EVACK_OFF
);
2673 if (prism2_transmit(dev
, local
->bus_m0_tx_idx
)) {
2674 printk(KERN_DEBUG
"%s: prism2_transmit() failed "
2675 "when called from bus master event\n",
2677 local
->intransmitfid
[local
->bus_m0_tx_idx
] =
2679 schedule_work(&local
->reset_queue
);
2683 #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
2686 /* Called only from hardware IRQ */
2687 static void prism2_infdrop(struct net_device
*dev
)
2689 static unsigned long last_inquire
= 0;
2691 PDEBUG(DEBUG_EXTRA
, "%s: INFDROP event\n", dev
->name
);
2693 /* some firmware versions seem to get stuck with
2694 * full CommTallies in high traffic load cases; every
2695 * packet will then cause INFDROP event and CommTallies
2696 * info frame will not be sent automatically. Try to
2697 * get out of this state by inquiring CommTallies. */
2698 if (!last_inquire
|| time_after(jiffies
, last_inquire
+ HZ
)) {
2699 hfa384x_cmd_callback(dev
, HFA384X_CMDCODE_INQUIRE
,
2700 HFA384X_INFO_COMMTALLIES
, NULL
, NULL
);
2701 last_inquire
= jiffies
;
2706 /* Called only from hardware IRQ */
2707 static void prism2_ev_tick(struct net_device
*dev
)
2709 struct hostap_interface
*iface
;
2710 local_info_t
*local
;
2712 static int prev_stuck
= 0;
2714 iface
= netdev_priv(dev
);
2715 local
= iface
->local
;
2717 if (time_after(jiffies
, local
->last_tick_timer
+ 5 * HZ
) &&
2718 local
->last_tick_timer
) {
2719 evstat
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
2720 inten
= HFA384X_INW(HFA384X_INTEN_OFF
);
2722 printk(KERN_INFO
"%s: SW TICK stuck? "
2723 "bits=0x%lx EvStat=%04x IntEn=%04x\n",
2724 dev
->name
, local
->bits
, evstat
, inten
);
2726 local
->sw_tick_stuck
++;
2727 if ((evstat
& HFA384X_BAP0_EVENTS
) &&
2728 (inten
& HFA384X_BAP0_EVENTS
)) {
2729 printk(KERN_INFO
"%s: trying to recover from IRQ "
2730 "hang\n", dev
->name
);
2731 hfa384x_events_no_bap0(dev
);
2739 /* Called only from hardware IRQ */
2740 static inline void prism2_check_magic(local_info_t
*local
)
2742 /* at least PCI Prism2.5 with bus mastering seems to sometimes
2743 * return 0x0000 in SWSUPPORT0 for unknown reason, but re-reading the
2744 * register once or twice seems to get the correct value.. PCI cards
2745 * cannot anyway be removed during normal operation, so there is not
2746 * really any need for this verification with them. */
2749 #ifndef final_version
2750 static unsigned long last_magic_err
= 0;
2751 struct net_device
*dev
= local
->dev
;
2753 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF
) != HFA384X_MAGIC
) {
2754 if (!local
->hw_ready
)
2756 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF
);
2757 if (time_after(jiffies
, last_magic_err
+ 10 * HZ
)) {
2758 printk("%s: Interrupt, but SWSUPPORT0 does not match: "
2759 "%04X != %04X - card removed?\n", dev
->name
,
2760 HFA384X_INW(HFA384X_SWSUPPORT0_OFF
),
2762 last_magic_err
= jiffies
;
2763 } else if (net_ratelimit()) {
2764 printk(KERN_DEBUG
"%s: interrupt - SWSUPPORT0=%04x "
2765 "MAGIC=%04x\n", dev
->name
,
2766 HFA384X_INW(HFA384X_SWSUPPORT0_OFF
),
2769 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF
) != 0xffff)
2770 schedule_work(&local
->reset_queue
);
2773 #endif /* final_version */
2774 #endif /* !PRISM2_PCI */
2778 /* Called only from hardware IRQ */
2779 static irqreturn_t
prism2_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
2781 struct net_device
*dev
= (struct net_device
*) dev_id
;
2782 struct hostap_interface
*iface
;
2783 local_info_t
*local
;
2787 iface
= netdev_priv(dev
);
2788 local
= iface
->local
;
2790 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_INTERRUPT
, 0, 0);
2792 if (local
->func
->card_present
&& !local
->func
->card_present(local
)) {
2793 if (net_ratelimit()) {
2794 printk(KERN_DEBUG
"%s: Interrupt, but dev not OK\n",
2800 prism2_check_magic(local
);
2803 ev
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
2805 if (local
->shutdown
)
2807 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF
);
2808 printk(KERN_DEBUG
"%s: prism2_interrupt: ev=0xffff\n",
2813 ev
&= HFA384X_INW(HFA384X_INTEN_OFF
);
2817 if (ev
& HFA384X_EV_CMD
) {
2821 /* Above events are needed even before hw is ready, but other
2822 * events should be skipped during initialization. This may
2823 * change for AllocEv if allocate_fid is implemented without
2825 if (!local
->hw_ready
|| local
->hw_resetting
||
2826 !local
->dev_enabled
) {
2827 ev
= HFA384X_INW(HFA384X_EVSTAT_OFF
);
2828 if (ev
& HFA384X_EV_CMD
)
2830 if ((ev
& HFA384X_EVENT_MASK
) == 0)
2832 if (local
->dev_enabled
&& (ev
& ~HFA384X_EV_TICK
) &&
2834 printk(KERN_DEBUG
"%s: prism2_interrupt: hw "
2835 "not ready; skipping events 0x%04x "
2836 "(IntEn=0x%04x)%s%s%s\n",
2838 HFA384X_INW(HFA384X_INTEN_OFF
),
2839 !local
->hw_ready
? " (!hw_ready)" : "",
2840 local
->hw_resetting
?
2841 " (hw_resetting)" : "",
2842 !local
->dev_enabled
?
2843 " (!dev_enabled)" : "");
2845 HFA384X_OUTW(ev
, HFA384X_EVACK_OFF
);
2849 if (ev
& HFA384X_EV_TICK
) {
2850 prism2_ev_tick(dev
);
2851 HFA384X_OUTW(HFA384X_EV_TICK
, HFA384X_EVACK_OFF
);
2854 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
2855 if (ev
& HFA384X_EV_PCI_M0
) {
2856 prism2_bus_master_ev(dev
, BAP0
);
2857 HFA384X_OUTW(HFA384X_EV_PCI_M0
, HFA384X_EVACK_OFF
);
2860 if (ev
& HFA384X_EV_PCI_M1
) {
2861 /* previous RX has been copied can be ACKed now */
2862 HFA384X_OUTW(HFA384X_EV_RX
, HFA384X_EVACK_OFF
);
2864 prism2_bus_master_ev(dev
, BAP1
);
2865 HFA384X_OUTW(HFA384X_EV_PCI_M1
, HFA384X_EVACK_OFF
);
2867 #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
2869 if (ev
& HFA384X_EV_ALLOC
) {
2870 prism2_alloc_ev(dev
);
2871 HFA384X_OUTW(HFA384X_EV_ALLOC
, HFA384X_EVACK_OFF
);
2874 /* Reading data from the card is quite time consuming, so do it
2875 * in tasklets. TX, TXEXC, RX, and INFO events will be ACKed
2876 * and unmasked after needed data has been read completely. */
2877 if (ev
& HFA384X_BAP0_EVENTS
) {
2878 hfa384x_events_no_bap0(dev
);
2879 tasklet_schedule(&local
->bap_tasklet
);
2882 #ifndef final_version
2883 if (ev
& HFA384X_EV_WTERR
) {
2884 PDEBUG(DEBUG_EXTRA
, "%s: WTERR event\n", dev
->name
);
2885 HFA384X_OUTW(HFA384X_EV_WTERR
, HFA384X_EVACK_OFF
);
2887 #endif /* final_version */
2889 if (ev
& HFA384X_EV_INFDROP
) {
2890 prism2_infdrop(dev
);
2891 HFA384X_OUTW(HFA384X_EV_INFDROP
, HFA384X_EVACK_OFF
);
2896 if (events
>= PRISM2_MAX_INTERRUPT_EVENTS
) {
2897 PDEBUG(DEBUG_EXTRA
, "prism2_interrupt: >%d events "
2898 "(EvStat=0x%04x)\n",
2899 PRISM2_MAX_INTERRUPT_EVENTS
,
2900 HFA384X_INW(HFA384X_EVSTAT_OFF
));
2904 prism2_io_debug_add(dev
, PRISM2_IO_DEBUG_CMD_INTERRUPT
, 0, 1);
2905 return IRQ_RETVAL(events
);
2909 static void prism2_check_sta_fw_version(local_info_t
*local
)
2911 struct hfa384x_comp_ident comp
;
2912 int id
, variant
, major
, minor
;
2914 if (hfa384x_get_rid(local
->dev
, HFA384X_RID_STAID
,
2915 &comp
, sizeof(comp
), 1) < 0)
2919 id
= le16_to_cpu(comp
.id
);
2920 if (id
!= HFA384X_COMP_ID_STA
) {
2921 if (id
== HFA384X_COMP_ID_FW_AP
)
2926 major
= __le16_to_cpu(comp
.major
);
2927 minor
= __le16_to_cpu(comp
.minor
);
2928 variant
= __le16_to_cpu(comp
.variant
);
2929 local
->sta_fw_ver
= PRISM2_FW_VER(major
, minor
, variant
);
2931 /* Station firmware versions before 1.4.x seem to have a bug in
2932 * firmware-based WEP encryption when using Host AP mode, so use
2933 * host_encrypt as a default for them. Firmware version 1.4.9 is the
2934 * first one that has been seen to produce correct encryption, but the
2935 * bug might be fixed before that (although, at least 1.4.2 is broken).
2937 local
->fw_encrypt_ok
= local
->sta_fw_ver
>= PRISM2_FW_VER(1,4,9);
2939 if (local
->iw_mode
== IW_MODE_MASTER
&& !local
->host_encrypt
&&
2940 !local
->fw_encrypt_ok
) {
2941 printk(KERN_DEBUG
"%s: defaulting to host-based encryption as "
2942 "a workaround for firmware bug in Host AP mode WEP\n",
2944 local
->host_encrypt
= 1;
2947 /* IEEE 802.11 standard compliant WDS frames (4 addresses) were broken
2948 * in station firmware versions before 1.5.x. With these versions, the
2949 * driver uses a workaround with bogus frame format (4th address after
2950 * the payload). This is not compatible with other AP devices. Since
2951 * the firmware bug is fixed in the latest station firmware versions,
2952 * automatically enable standard compliant mode for cards using station
2953 * firmware version 1.5.0 or newer. */
2954 if (local
->sta_fw_ver
>= PRISM2_FW_VER(1,5,0))
2955 local
->wds_type
|= HOSTAP_WDS_STANDARD_FRAME
;
2957 printk(KERN_DEBUG
"%s: defaulting to bogus WDS frame as a "
2958 "workaround for firmware bug in Host AP mode WDS\n",
2962 hostap_check_sta_fw_version(local
->ap
, local
->sta_fw_ver
);
2966 static void prism2_crypt_deinit_entries(local_info_t
*local
, int force
)
2968 struct list_head
*ptr
, *n
;
2969 struct prism2_crypt_data
*entry
;
2971 for (ptr
= local
->crypt_deinit_list
.next
, n
= ptr
->next
;
2972 ptr
!= &local
->crypt_deinit_list
; ptr
= n
, n
= ptr
->next
) {
2973 entry
= list_entry(ptr
, struct prism2_crypt_data
, list
);
2975 if (atomic_read(&entry
->refcnt
) != 0 && !force
)
2981 entry
->ops
->deinit(entry
->priv
);
2987 static void prism2_crypt_deinit_handler(unsigned long data
)
2989 local_info_t
*local
= (local_info_t
*) data
;
2990 unsigned long flags
;
2992 spin_lock_irqsave(&local
->lock
, flags
);
2993 prism2_crypt_deinit_entries(local
, 0);
2994 if (!list_empty(&local
->crypt_deinit_list
)) {
2995 printk(KERN_DEBUG
"%s: entries remaining in delayed crypt "
2996 "deletion list\n", local
->dev
->name
);
2997 local
->crypt_deinit_timer
.expires
= jiffies
+ HZ
;
2998 add_timer(&local
->crypt_deinit_timer
);
3000 spin_unlock_irqrestore(&local
->lock
, flags
);
3005 static void hostap_passive_scan(unsigned long data
)
3007 local_info_t
*local
= (local_info_t
*) data
;
3008 struct net_device
*dev
= local
->dev
;
3011 if (local
->passive_scan_interval
<= 0)
3014 if (local
->passive_scan_state
== PASSIVE_SCAN_LISTEN
) {
3017 /* Even though host system does not really know when the WLAN
3018 * MAC is sending frames, try to avoid changing channels for
3019 * passive scanning when a host-generated frame is being
3021 if (test_bit(HOSTAP_BITS_TRANSMIT
, &local
->bits
)) {
3022 printk(KERN_DEBUG
"%s: passive scan detected pending "
3023 "TX - delaying\n", dev
->name
);
3024 local
->passive_scan_timer
.expires
= jiffies
+ HZ
/ 10;
3025 add_timer(&local
->passive_scan_timer
);
3030 local
->passive_scan_channel
++;
3031 if (local
->passive_scan_channel
> 14)
3032 local
->passive_scan_channel
= 1;
3034 } while (!(local
->channel_mask
&
3035 (1 << (local
->passive_scan_channel
- 1))) &&
3038 if (max_tries
== 0) {
3039 printk(KERN_INFO
"%s: no allowed passive scan channels"
3040 " found\n", dev
->name
);
3044 printk(KERN_DEBUG
"%s: passive scan channel %d\n",
3045 dev
->name
, local
->passive_scan_channel
);
3046 channel
= local
->passive_scan_channel
;
3047 local
->passive_scan_state
= PASSIVE_SCAN_WAIT
;
3048 local
->passive_scan_timer
.expires
= jiffies
+ HZ
/ 10;
3050 channel
= local
->channel
;
3051 local
->passive_scan_state
= PASSIVE_SCAN_LISTEN
;
3052 local
->passive_scan_timer
.expires
= jiffies
+
3053 local
->passive_scan_interval
* HZ
;
3056 if (hfa384x_cmd_callback(dev
, HFA384X_CMDCODE_TEST
|
3057 (HFA384X_TEST_CHANGE_CHANNEL
<< 8),
3058 channel
, NULL
, NULL
))
3059 printk(KERN_ERR
"%s: passive scan channel set %d "
3060 "failed\n", dev
->name
, channel
);
3062 add_timer(&local
->passive_scan_timer
);
3066 /* Called only as a scheduled task when communications quality values should
3068 static void handle_comms_qual_update(void *data
)
3070 local_info_t
*local
= data
;
3071 prism2_update_comms_qual(local
->dev
);
3075 /* Software watchdog - called as a timer. Hardware interrupt (Tick event) is
3076 * used to monitor that local->last_tick_timer is being updated. If not,
3077 * interrupt busy-loop is assumed and driver tries to recover by masking out
3079 static void hostap_tick_timer(unsigned long data
)
3081 static unsigned long last_inquire
= 0;
3082 local_info_t
*local
= (local_info_t
*) data
;
3083 local
->last_tick_timer
= jiffies
;
3085 /* Inquire CommTallies every 10 seconds to keep the statistics updated
3086 * more often during low load and when using 32-bit tallies. */
3087 if ((!last_inquire
|| time_after(jiffies
, last_inquire
+ 10 * HZ
)) &&
3088 !local
->hw_downloading
&& local
->hw_ready
&&
3089 !local
->hw_resetting
&& local
->dev_enabled
) {
3090 hfa384x_cmd_callback(local
->dev
, HFA384X_CMDCODE_INQUIRE
,
3091 HFA384X_INFO_COMMTALLIES
, NULL
, NULL
);
3092 last_inquire
= jiffies
;
3095 if ((local
->last_comms_qual_update
== 0 ||
3096 time_after(jiffies
, local
->last_comms_qual_update
+ 10 * HZ
)) &&
3097 (local
->iw_mode
== IW_MODE_INFRA
||
3098 local
->iw_mode
== IW_MODE_ADHOC
)) {
3099 schedule_work(&local
->comms_qual_update
);
3102 local
->tick_timer
.expires
= jiffies
+ 2 * HZ
;
3103 add_timer(&local
->tick_timer
);
3107 #ifndef PRISM2_NO_PROCFS_DEBUG
3108 static int prism2_registers_proc_read(char *page
, char **start
, off_t off
,
3109 int count
, int *eof
, void *data
)
3112 local_info_t
*local
= (local_info_t
*) data
;
3119 #define SHOW_REG(n) \
3120 p += sprintf(p, #n "=%04x\n", hfa384x_read_reg(local->dev, HFA384X_##n##_OFF))
3138 SHOW_REG(TXCOMPLFID
);
3139 SHOW_REG(SWSUPPORT0
);
3140 SHOW_REG(SWSUPPORT1
);
3141 SHOW_REG(SWSUPPORT2
);
3145 /* Do not read data registers, because they change the state of the
3146 * MAC (offset += 2) */
3147 /* SHOW_REG(DATA0); */
3148 /* SHOW_REG(DATA1); */
3150 SHOW_REG(AUXOFFSET
);
3151 /* SHOW_REG(AUXDATA); */
3155 SHOW_REG(PCI_M0_ADDRH
);
3156 SHOW_REG(PCI_M0_ADDRL
);
3157 SHOW_REG(PCI_M0_LEN
);
3158 SHOW_REG(PCI_M0_CTL
);
3159 SHOW_REG(PCI_STATUS
);
3160 SHOW_REG(PCI_M1_ADDRH
);
3161 SHOW_REG(PCI_M1_ADDRL
);
3162 SHOW_REG(PCI_M1_LEN
);
3163 SHOW_REG(PCI_M1_CTL
);
3164 #endif /* PRISM2_PCI */
3168 #endif /* PRISM2_NO_PROCFS_DEBUG */
3171 struct set_tim_data
{
3172 struct list_head list
;
3177 static int prism2_set_tim(struct net_device
*dev
, int aid
, int set
)
3179 struct list_head
*ptr
;
3180 struct set_tim_data
*new_entry
;
3181 struct hostap_interface
*iface
;
3182 local_info_t
*local
;
3184 iface
= netdev_priv(dev
);
3185 local
= iface
->local
;
3187 new_entry
= (struct set_tim_data
*)
3188 kmalloc(sizeof(*new_entry
), GFP_ATOMIC
);
3189 if (new_entry
== NULL
) {
3190 printk(KERN_DEBUG
"%s: prism2_set_tim: kmalloc failed\n",
3194 memset(new_entry
, 0, sizeof(*new_entry
));
3195 new_entry
->aid
= aid
;
3196 new_entry
->set
= set
;
3198 spin_lock_bh(&local
->set_tim_lock
);
3199 list_for_each(ptr
, &local
->set_tim_list
) {
3200 struct set_tim_data
*entry
=
3201 list_entry(ptr
, struct set_tim_data
, list
);
3202 if (entry
->aid
== aid
) {
3203 PDEBUG(DEBUG_PS2
, "%s: prism2_set_tim: aid=%d "
3205 local
->dev
->name
, aid
, entry
->set
, set
);
3213 list_add_tail(&new_entry
->list
, &local
->set_tim_list
);
3214 spin_unlock_bh(&local
->set_tim_lock
);
3216 schedule_work(&local
->set_tim_queue
);
3222 static void handle_set_tim_queue(void *data
)
3224 local_info_t
*local
= (local_info_t
*) data
;
3225 struct set_tim_data
*entry
;
3230 spin_lock_bh(&local
->set_tim_lock
);
3231 if (!list_empty(&local
->set_tim_list
)) {
3232 entry
= list_entry(local
->set_tim_list
.next
,
3233 struct set_tim_data
, list
);
3234 list_del(&entry
->list
);
3236 spin_unlock_bh(&local
->set_tim_lock
);
3240 PDEBUG(DEBUG_PS2
, "%s: handle_set_tim_queue: aid=%d set=%d\n",
3241 local
->dev
->name
, entry
->aid
, entry
->set
);
3246 if (hostap_set_word(local
->dev
, HFA384X_RID_CNFTIMCTRL
, val
)) {
3247 printk(KERN_DEBUG
"%s: set_tim failed (aid=%d "
3249 local
->dev
->name
, entry
->aid
, entry
->set
);
3257 static void prism2_clear_set_tim_queue(local_info_t
*local
)
3259 struct list_head
*ptr
, *n
;
3261 list_for_each_safe(ptr
, n
, &local
->set_tim_list
) {
3262 struct set_tim_data
*entry
;
3263 entry
= list_entry(ptr
, struct set_tim_data
, list
);
3264 list_del(&entry
->list
);
3270 static struct net_device
*
3271 prism2_init_local_data(struct prism2_helper_functions
*funcs
, int card_idx
)
3273 struct net_device
*dev
;
3274 struct hostap_interface
*iface
;
3275 struct local_info
*local
;
3281 len
= strlen(dev_template
);
3282 if (len
>= IFNAMSIZ
|| strstr(dev_template
, "%d") == NULL
) {
3283 printk(KERN_WARNING
"hostap: Invalid dev_template='%s'\n",
3288 len
= sizeof(struct hostap_interface
) +
3289 3 + sizeof(struct local_info
) +
3290 3 + sizeof(struct ap_data
);
3292 dev
= alloc_etherdev(len
);
3296 iface
= netdev_priv(dev
);
3297 local
= (struct local_info
*) ((((long) (iface
+ 1)) + 3) & ~3);
3298 local
->ap
= (struct ap_data
*) ((((long) (local
+ 1)) + 3) & ~3);
3299 local
->dev
= iface
->dev
= dev
;
3300 iface
->local
= local
;
3301 iface
->type
= HOSTAP_INTERFACE_MASTER
;
3302 INIT_LIST_HEAD(&local
->hostap_interfaces
);
3304 local
->hw_module
= THIS_MODULE
;
3306 #ifdef PRISM2_IO_DEBUG
3307 local
->io_debug_enabled
= 1;
3308 #endif /* PRISM2_IO_DEBUG */
3310 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
3311 local
->bus_m0_buf
= (u8
*) kmalloc(sizeof(struct hfa384x_tx_frame
) +
3312 PRISM2_DATA_MAXLEN
, GFP_DMA
);
3313 if (local
->bus_m0_buf
== NULL
)
3315 #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
3317 local
->func
= funcs
;
3318 local
->func
->cmd
= hfa384x_cmd
;
3319 local
->func
->read_regs
= hfa384x_read_regs
;
3320 local
->func
->get_rid
= hfa384x_get_rid
;
3321 local
->func
->set_rid
= hfa384x_set_rid
;
3322 local
->func
->hw_enable
= prism2_hw_enable
;
3323 local
->func
->hw_config
= prism2_hw_config
;
3324 local
->func
->hw_reset
= prism2_hw_reset
;
3325 local
->func
->hw_shutdown
= prism2_hw_shutdown
;
3326 local
->func
->reset_port
= prism2_reset_port
;
3327 local
->func
->schedule_reset
= prism2_schedule_reset
;
3328 #ifdef PRISM2_DOWNLOAD_SUPPORT
3329 local
->func
->read_aux
= prism2_download_aux_dump
;
3330 local
->func
->download
= prism2_download
;
3331 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3332 local
->func
->tx
= prism2_tx_80211
;
3333 local
->func
->set_tim
= prism2_set_tim
;
3334 local
->func
->need_tx_headroom
= 0; /* no need to add txdesc in
3335 * skb->data (FIX: maybe for DMA bus
3340 rwlock_init(&local
->iface_lock
);
3341 spin_lock_init(&local
->txfidlock
);
3342 spin_lock_init(&local
->cmdlock
);
3343 spin_lock_init(&local
->baplock
);
3344 spin_lock_init(&local
->lock
);
3345 init_MUTEX(&local
->rid_bap_sem
);
3347 if (card_idx
< 0 || card_idx
>= MAX_PARM_DEVICES
)
3349 local
->card_idx
= card_idx
;
3351 len
= strlen(essid
);
3352 memcpy(local
->essid
, essid
,
3353 len
> MAX_SSID_LEN
? MAX_SSID_LEN
: len
);
3354 local
->essid
[MAX_SSID_LEN
] = '\0';
3355 i
= GET_INT_PARM(iw_mode
, card_idx
);
3356 if ((i
>= IW_MODE_ADHOC
&& i
<= IW_MODE_REPEAT
) ||
3357 i
== IW_MODE_MONITOR
) {
3360 printk(KERN_WARNING
"prism2: Unknown iw_mode %d; using "
3361 "IW_MODE_MASTER\n", i
);
3362 local
->iw_mode
= IW_MODE_MASTER
;
3364 local
->channel
= GET_INT_PARM(channel
, card_idx
);
3365 local
->beacon_int
= GET_INT_PARM(beacon_int
, card_idx
);
3366 local
->dtim_period
= GET_INT_PARM(dtim_period
, card_idx
);
3367 local
->wds_max_connections
= 16;
3368 local
->tx_control
= HFA384X_TX_CTRL_FLAGS
;
3369 local
->manual_retry_count
= -1;
3370 local
->rts_threshold
= 2347;
3371 local
->fragm_threshold
= 2346;
3372 local
->rssi_to_dBm
= 100; /* default; to be overriden by
3373 * cnfDbmAdjust, if available */
3374 local
->auth_algs
= PRISM2_AUTH_OPEN
| PRISM2_AUTH_SHARED_KEY
;
3375 local
->sram_type
= -1;
3376 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
3377 local
->bus_master_threshold_rx
= GET_INT_PARM(bus_master_threshold_rx
,
3379 local
->bus_master_threshold_tx
= GET_INT_PARM(bus_master_threshold_tx
,
3381 #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
3383 /* Initialize task queue structures */
3384 INIT_WORK(&local
->reset_queue
, handle_reset_queue
, local
);
3385 INIT_WORK(&local
->set_multicast_list_queue
,
3386 hostap_set_multicast_list_queue
, local
->dev
);
3388 INIT_WORK(&local
->set_tim_queue
, handle_set_tim_queue
, local
);
3389 INIT_LIST_HEAD(&local
->set_tim_list
);
3390 spin_lock_init(&local
->set_tim_lock
);
3392 INIT_WORK(&local
->comms_qual_update
, handle_comms_qual_update
, local
);
3394 /* Initialize tasklets for handling hardware IRQ related operations
3395 * outside hw IRQ handler */
3396 #define HOSTAP_TASKLET_INIT(q, f, d) \
3397 do { memset((q), 0, sizeof(*(q))); (q)->func = (f); (q)->data = (d); } \
3399 HOSTAP_TASKLET_INIT(&local
->bap_tasklet
, hostap_bap_tasklet
,
3400 (unsigned long) local
);
3402 HOSTAP_TASKLET_INIT(&local
->info_tasklet
, hostap_info_tasklet
,
3403 (unsigned long) local
);
3404 hostap_info_init(local
);
3406 HOSTAP_TASKLET_INIT(&local
->rx_tasklet
,
3407 hostap_rx_tasklet
, (unsigned long) local
);
3408 skb_queue_head_init(&local
->rx_list
);
3410 HOSTAP_TASKLET_INIT(&local
->sta_tx_exc_tasklet
,
3411 hostap_sta_tx_exc_tasklet
, (unsigned long) local
);
3412 skb_queue_head_init(&local
->sta_tx_exc_list
);
3414 INIT_LIST_HEAD(&local
->cmd_queue
);
3415 init_waitqueue_head(&local
->hostscan_wq
);
3416 INIT_LIST_HEAD(&local
->crypt_deinit_list
);
3417 init_timer(&local
->crypt_deinit_timer
);
3418 local
->crypt_deinit_timer
.data
= (unsigned long) local
;
3419 local
->crypt_deinit_timer
.function
= prism2_crypt_deinit_handler
;
3421 init_timer(&local
->passive_scan_timer
);
3422 local
->passive_scan_timer
.data
= (unsigned long) local
;
3423 local
->passive_scan_timer
.function
= hostap_passive_scan
;
3425 init_timer(&local
->tick_timer
);
3426 local
->tick_timer
.data
= (unsigned long) local
;
3427 local
->tick_timer
.function
= hostap_tick_timer
;
3428 local
->tick_timer
.expires
= jiffies
+ 2 * HZ
;
3429 add_timer(&local
->tick_timer
);
3431 INIT_LIST_HEAD(&local
->bss_list
);
3433 hostap_setup_dev(dev
, local
, 1);
3434 local
->saved_eth_header_parse
= dev
->hard_header_parse
;
3436 dev
->hard_start_xmit
= hostap_master_start_xmit
;
3437 dev
->type
= ARPHRD_IEEE80211
;
3438 dev
->hard_header_parse
= hostap_80211_header_parse
;
3441 ret
= dev_alloc_name(dev
, "wifi%d");
3443 ret
= register_netdevice(dev
);
3446 printk(KERN_WARNING
"%s: register netdevice failed!\n",
3450 printk(KERN_INFO
"%s: Registered netdevice %s\n", dev_info
, dev
->name
);
3452 #ifndef PRISM2_NO_PROCFS_DEBUG
3453 create_proc_read_entry("registers", 0, local
->proc
,
3454 prism2_registers_proc_read
, local
);
3455 #endif /* PRISM2_NO_PROCFS_DEBUG */
3457 hostap_init_data(local
);
3461 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
3462 kfree(local
->bus_m0_buf
);
3463 #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
3469 static int hostap_hw_ready(struct net_device
*dev
)
3471 struct hostap_interface
*iface
;
3472 struct local_info
*local
;
3474 iface
= netdev_priv(dev
);
3475 local
= iface
->local
;
3476 local
->ddev
= hostap_add_interface(local
, HOSTAP_INTERFACE_MAIN
, 0,
3480 if (local
->iw_mode
== IW_MODE_INFRA
||
3481 local
->iw_mode
== IW_MODE_ADHOC
) {
3482 netif_carrier_off(local
->dev
);
3483 netif_carrier_off(local
->ddev
);
3485 hostap_init_proc(local
);
3486 hostap_init_ap_proc(local
);
3494 static void prism2_free_local_data(struct net_device
*dev
)
3496 struct hostap_tx_callback_info
*tx_cb
, *tx_cb_prev
;
3498 struct hostap_interface
*iface
;
3499 struct local_info
*local
;
3500 struct list_head
*ptr
, *n
;
3505 iface
= netdev_priv(dev
);
3506 local
= iface
->local
;
3508 flush_scheduled_work();
3510 if (timer_pending(&local
->crypt_deinit_timer
))
3511 del_timer(&local
->crypt_deinit_timer
);
3512 prism2_crypt_deinit_entries(local
, 1);
3514 if (timer_pending(&local
->passive_scan_timer
))
3515 del_timer(&local
->passive_scan_timer
);
3517 if (timer_pending(&local
->tick_timer
))
3518 del_timer(&local
->tick_timer
);
3520 prism2_clear_cmd_queue(local
);
3522 skb_queue_purge(&local
->info_list
);
3523 skb_queue_purge(&local
->rx_list
);
3524 skb_queue_purge(&local
->sta_tx_exc_list
);
3526 if (local
->dev_enabled
)
3527 prism2_callback(local
, PRISM2_CALLBACK_DISABLE
);
3529 for (i
= 0; i
< WEP_KEYS
; i
++) {
3530 struct prism2_crypt_data
*crypt
= local
->crypt
[i
];
3533 crypt
->ops
->deinit(crypt
->priv
);
3535 local
->crypt
[i
] = NULL
;
3539 if (local
->ap
!= NULL
)
3540 hostap_free_data(local
->ap
);
3542 #ifndef PRISM2_NO_PROCFS_DEBUG
3543 if (local
->proc
!= NULL
)
3544 remove_proc_entry("registers", local
->proc
);
3545 #endif /* PRISM2_NO_PROCFS_DEBUG */
3546 hostap_remove_proc(local
);
3548 tx_cb
= local
->tx_callback
;
3549 while (tx_cb
!= NULL
) {
3551 tx_cb
= tx_cb
->next
;
3555 hostap_set_hostapd(local
, 0, 0);
3556 hostap_set_hostapd_sta(local
, 0, 0);
3558 for (i
= 0; i
< PRISM2_FRAG_CACHE_LEN
; i
++) {
3559 if (local
->frag_cache
[i
].skb
!= NULL
)
3560 dev_kfree_skb(local
->frag_cache
[i
].skb
);
3563 #ifdef PRISM2_DOWNLOAD_SUPPORT
3564 prism2_download_free_data(local
->dl_pri
);
3565 prism2_download_free_data(local
->dl_sec
);
3566 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3568 list_for_each_safe(ptr
, n
, &local
->hostap_interfaces
) {
3569 iface
= list_entry(ptr
, struct hostap_interface
, list
);
3570 if (iface
->type
== HOSTAP_INTERFACE_MASTER
) {
3571 /* special handling for this interface below */
3574 hostap_remove_interface(iface
->dev
, 0, 1);
3577 prism2_clear_set_tim_queue(local
);
3579 list_for_each_safe(ptr
, n
, &local
->bss_list
) {
3580 struct hostap_bss_info
*bss
=
3581 list_entry(ptr
, struct hostap_bss_info
, list
);
3585 #if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
3586 kfree(local
->bus_m0_buf
);
3587 #endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
3589 kfree(local
->last_scan_results
);
3590 kfree(local
->generic_elem
);
3592 unregister_netdev(local
->dev
);
3593 free_netdev(local
->dev
);
3598 static void prism2_suspend(struct net_device
*dev
)
3600 struct hostap_interface
*iface
;
3601 struct local_info
*local
;
3602 union iwreq_data wrqu
;
3605 local
= iface
->local
;
3607 /* Send disconnect event, e.g., to trigger reassociation after resume
3608 * if wpa_supplicant is used. */
3609 memset(&wrqu
, 0, sizeof(wrqu
));
3610 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
3611 wireless_send_event(local
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
3613 /* Disable hardware and firmware */
3614 prism2_hw_shutdown(dev
, 0);
3616 #endif /* PRISM2_PLX */
3619 /* These might at some point be compiled separately and used as separate
3620 * kernel modules or linked into one */
3621 #ifdef PRISM2_DOWNLOAD_SUPPORT
3622 #include "hostap_download.c"
3623 #endif /* PRISM2_DOWNLOAD_SUPPORT */
3625 #ifdef PRISM2_CALLBACK
3626 /* External hostap_callback.c file can be used to, e.g., blink activity led.
3627 * This can use platform specific code and must define prism2_callback()
3628 * function (if PRISM2_CALLBACK is not defined, these function calls are not
3630 #include "hostap_callback.c"
3631 #endif /* PRISM2_CALLBACK */