1 /******************************************************************************
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/pci.h>
34 #include <linux/dma-mapping.h>
35 #include <linux/delay.h>
36 #include <linux/skbuff.h>
37 #include <linux/netdevice.h>
38 #include <linux/wireless.h>
39 #include <linux/firmware.h>
40 #include <linux/etherdevice.h>
41 #include <linux/if_arp.h>
43 #include <net/ieee80211_radiotap.h>
44 #include <net/lib80211.h>
45 #include <net/mac80211.h>
47 #include <asm/div64.h>
49 #define DRV_NAME "iwl3945"
51 #include "iwl-commands.h"
53 #include "iwl-3945-fh.h"
54 #include "iwl-helpers.h"
58 static int iwl3945_tx_queue_update_write_ptr(struct iwl_priv
*priv
,
59 struct iwl3945_tx_queue
*txq
);
61 /******************************************************************************
65 ******************************************************************************/
67 /* module parameters */
68 static int iwl3945_param_disable_hw_scan
; /* def: 0 = use 3945's h/w scan */
69 static u32 iwl3945_param_debug
; /* def: 0 = minimal debug log messages */
70 static int iwl3945_param_disable
; /* def: 0 = enable radio */
71 static int iwl3945_param_antenna
; /* def: 0 = both antennas (use diversity) */
72 int iwl3945_param_hwcrypto
; /* def: 0 = use software encryption */
73 int iwl3945_param_queues_num
= IWL39_MAX_NUM_QUEUES
; /* def: 8 Tx queues */
76 * module name, copyright, version, etc.
79 #define DRV_DESCRIPTION \
80 "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
82 #ifdef CONFIG_IWL3945_DEBUG
88 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
94 #define IWL39_VERSION "1.2.26k" VD VS
95 #define DRV_COPYRIGHT "Copyright(c) 2003-2008 Intel Corporation"
96 #define DRV_AUTHOR "<ilw@linux.intel.com>"
97 #define DRV_VERSION IWL39_VERSION
100 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
101 MODULE_VERSION(DRV_VERSION
);
102 MODULE_AUTHOR(DRV_COPYRIGHT
" " DRV_AUTHOR
);
103 MODULE_LICENSE("GPL");
105 static const struct ieee80211_supported_band
*iwl3945_get_band(
106 struct iwl_priv
*priv
, enum ieee80211_band band
)
108 return priv
->hw
->wiphy
->bands
[band
];
111 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
114 * Theory of operation
116 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
117 * of buffer descriptors, each of which points to one or more data buffers for
118 * the device to read from or fill. Driver and device exchange status of each
119 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
120 * entries in each circular buffer, to protect against confusing empty and full
123 * The device reads or writes the data in the queues via the device's several
124 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
126 * For Tx queue, there are low mark and high mark limits. If, after queuing
127 * the packet for Tx, free space become < low mark, Tx queue stopped. When
128 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
131 * The 3945 operates with six queues: One receive queue, one transmit queue
132 * (#4) for sending commands to the device firmware, and four transmit queues
133 * (#0-3) for data tx via EDCA. An additional 2 HCCA queues are unused.
134 ***************************************************/
136 int iwl3945_x2_queue_used(const struct iwl_queue
*q
, int i
)
138 return q
->write_ptr
> q
->read_ptr
?
139 (i
>= q
->read_ptr
&& i
< q
->write_ptr
) :
140 !(i
< q
->read_ptr
&& i
>= q
->write_ptr
);
144 * iwl3945_queue_init - Initialize queue's high/low-water and read/write indexes
146 static int iwl3945_queue_init(struct iwl_priv
*priv
, struct iwl_queue
*q
,
147 int count
, int slots_num
, u32 id
)
150 q
->n_window
= slots_num
;
153 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
154 * and iwl_queue_dec_wrap are broken. */
155 BUG_ON(!is_power_of_2(count
));
157 /* slots_num must be power-of-two size, otherwise
158 * get_cmd_index is broken. */
159 BUG_ON(!is_power_of_2(slots_num
));
161 q
->low_mark
= q
->n_window
/ 4;
165 q
->high_mark
= q
->n_window
/ 8;
166 if (q
->high_mark
< 2)
169 q
->write_ptr
= q
->read_ptr
= 0;
175 * iwl3945_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
177 static int iwl3945_tx_queue_alloc(struct iwl_priv
*priv
,
178 struct iwl3945_tx_queue
*txq
, u32 id
)
180 struct pci_dev
*dev
= priv
->pci_dev
;
182 /* Driver private data, only for Tx (not command) queues,
183 * not shared with device. */
184 if (id
!= IWL_CMD_QUEUE_NUM
) {
185 txq
->txb
= kmalloc(sizeof(txq
->txb
[0]) *
186 TFD_QUEUE_SIZE_MAX
, GFP_KERNEL
);
188 IWL_ERR(priv
, "kmalloc for auxiliary BD "
189 "structures failed\n");
195 /* Circular buffer of transmit frame descriptors (TFDs),
196 * shared with device */
197 txq
->bd
= pci_alloc_consistent(dev
,
198 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
,
202 IWL_ERR(priv
, "pci_alloc_consistent(%zd) failed\n",
203 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
);
218 * iwl3945_tx_queue_init - Allocate and initialize one tx/cmd queue
220 int iwl3945_tx_queue_init(struct iwl_priv
*priv
,
221 struct iwl3945_tx_queue
*txq
, int slots_num
, u32 txq_id
)
223 struct pci_dev
*dev
= priv
->pci_dev
;
228 * Alloc buffer array for commands (Tx or other types of commands).
229 * For the command queue (#4), allocate command space + one big
230 * command for scan, since scan command is very huge; the system will
231 * not have two scans at the same time, so only one is needed.
232 * For data Tx queues (all other queues), no super-size command
235 len
= sizeof(struct iwl_cmd
) * slots_num
;
236 if (txq_id
== IWL_CMD_QUEUE_NUM
)
237 len
+= IWL_MAX_SCAN_SIZE
;
238 txq
->cmd
= pci_alloc_consistent(dev
, len
, &txq
->dma_addr_cmd
);
242 /* Alloc driver data array and TFD circular buffer */
243 rc
= iwl3945_tx_queue_alloc(priv
, txq
, txq_id
);
245 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
249 txq
->need_update
= 0;
251 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
252 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
253 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX
& (TFD_QUEUE_SIZE_MAX
- 1));
255 /* Initialize queue high/low-water, head/tail indexes */
256 iwl3945_queue_init(priv
, &txq
->q
, TFD_QUEUE_SIZE_MAX
, slots_num
, txq_id
);
258 /* Tell device where to find queue, enable DMA channel. */
259 iwl3945_hw_tx_queue_init(priv
, txq
);
265 * iwl3945_tx_queue_free - Deallocate DMA queue.
266 * @txq: Transmit queue to deallocate.
268 * Empty queue by removing and destroying all BD's.
270 * 0-fill, but do not free "txq" descriptor structure.
272 void iwl3945_tx_queue_free(struct iwl_priv
*priv
, struct iwl3945_tx_queue
*txq
)
274 struct iwl_queue
*q
= &txq
->q
;
275 struct pci_dev
*dev
= priv
->pci_dev
;
281 /* first, empty all BD's */
282 for (; q
->write_ptr
!= q
->read_ptr
;
283 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
))
284 iwl3945_hw_txq_free_tfd(priv
, txq
);
286 len
= sizeof(struct iwl_cmd
) * q
->n_window
;
287 if (q
->id
== IWL_CMD_QUEUE_NUM
)
288 len
+= IWL_MAX_SCAN_SIZE
;
290 /* De-alloc array of command/tx buffers */
291 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
293 /* De-alloc circular buffer of TFDs */
295 pci_free_consistent(dev
, sizeof(struct iwl3945_tfd_frame
) *
296 txq
->q
.n_bd
, txq
->bd
, txq
->q
.dma_addr
);
298 /* De-alloc array of per-TFD driver data */
302 /* 0-fill queue descriptor structure */
303 memset(txq
, 0, sizeof(*txq
));
306 /*************** STATION TABLE MANAGEMENT ****
307 * mac80211 should be examined to determine if sta_info is duplicating
308 * the functionality provided here
311 /**************************************************************/
312 #if 0 /* temporary disable till we add real remove station */
314 * iwl3945_remove_station - Remove driver's knowledge of station.
316 * NOTE: This does not remove station from device's station table.
318 static u8
iwl3945_remove_station(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
)
320 int index
= IWL_INVALID_STATION
;
324 spin_lock_irqsave(&priv
->sta_lock
, flags
);
328 else if (is_broadcast_ether_addr(addr
))
329 index
= priv
->hw_params
.bcast_sta_id
;
331 for (i
= IWL_STA_ID
; i
< priv
->hw_params
.max_stations
; i
++)
332 if (priv
->stations_39
[i
].used
&&
333 !compare_ether_addr(priv
->stations_39
[i
].sta
.sta
.addr
,
339 if (unlikely(index
== IWL_INVALID_STATION
))
342 if (priv
->stations_39
[index
].used
) {
343 priv
->stations_39
[index
].used
= 0;
344 priv
->num_stations
--;
347 BUG_ON(priv
->num_stations
< 0);
350 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
356 * iwl3945_clear_stations_table - Clear the driver's station table
358 * NOTE: This does not clear or otherwise alter the device's station table.
360 static void iwl3945_clear_stations_table(struct iwl_priv
*priv
)
364 spin_lock_irqsave(&priv
->sta_lock
, flags
);
366 priv
->num_stations
= 0;
367 memset(priv
->stations_39
, 0, sizeof(priv
->stations_39
));
369 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
373 * iwl3945_add_station - Add station to station tables in driver and device
375 u8
iwl3945_add_station(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
, u8 flags
)
378 int index
= IWL_INVALID_STATION
;
379 struct iwl3945_station_entry
*station
;
380 unsigned long flags_spin
;
383 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
386 else if (is_broadcast_ether_addr(addr
))
387 index
= priv
->hw_params
.bcast_sta_id
;
389 for (i
= IWL_STA_ID
; i
< priv
->hw_params
.max_stations
; i
++) {
390 if (!compare_ether_addr(priv
->stations_39
[i
].sta
.sta
.addr
,
396 if (!priv
->stations_39
[i
].used
&&
397 index
== IWL_INVALID_STATION
)
401 /* These two conditions has the same outcome but keep them separate
402 since they have different meaning */
403 if (unlikely(index
== IWL_INVALID_STATION
)) {
404 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
408 if (priv
->stations_39
[index
].used
&&
409 !compare_ether_addr(priv
->stations_39
[index
].sta
.sta
.addr
, addr
)) {
410 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
414 IWL_DEBUG_ASSOC("Add STA ID %d: %pM\n", index
, addr
);
415 station
= &priv
->stations_39
[index
];
417 priv
->num_stations
++;
419 /* Set up the REPLY_ADD_STA command to send to device */
420 memset(&station
->sta
, 0, sizeof(struct iwl3945_addsta_cmd
));
421 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
422 station
->sta
.mode
= 0;
423 station
->sta
.sta
.sta_id
= index
;
424 station
->sta
.station_flags
= 0;
426 if (priv
->band
== IEEE80211_BAND_5GHZ
)
427 rate
= IWL_RATE_6M_PLCP
;
429 rate
= IWL_RATE_1M_PLCP
;
431 /* Turn on both antennas for the station... */
432 station
->sta
.rate_n_flags
=
433 iwl3945_hw_set_rate_n_flags(rate
, RATE_MCS_ANT_AB_MSK
);
435 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
437 /* Add station to device's station table */
438 iwl3945_send_add_station(priv
, &station
->sta
, flags
);
443 /*************** DRIVER STATUS FUNCTIONS *****/
445 static inline int iwl3945_is_ready(struct iwl_priv
*priv
)
447 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
448 * set but EXIT_PENDING is not */
449 return test_bit(STATUS_READY
, &priv
->status
) &&
450 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) &&
451 !test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
454 static inline int iwl3945_is_alive(struct iwl_priv
*priv
)
456 return test_bit(STATUS_ALIVE
, &priv
->status
);
459 static inline int iwl3945_is_init(struct iwl_priv
*priv
)
461 return test_bit(STATUS_INIT
, &priv
->status
);
464 static inline int iwl3945_is_rfkill_sw(struct iwl_priv
*priv
)
466 return test_bit(STATUS_RF_KILL_SW
, &priv
->status
);
469 static inline int iwl3945_is_rfkill_hw(struct iwl_priv
*priv
)
471 return test_bit(STATUS_RF_KILL_HW
, &priv
->status
);
474 static inline int iwl3945_is_rfkill(struct iwl_priv
*priv
)
476 return iwl3945_is_rfkill_hw(priv
) ||
477 iwl3945_is_rfkill_sw(priv
);
480 static inline int iwl3945_is_ready_rf(struct iwl_priv
*priv
)
483 if (iwl3945_is_rfkill(priv
))
486 return iwl3945_is_ready(priv
);
489 /*************** HOST COMMAND QUEUE FUNCTIONS *****/
491 #define IWL_CMD(x) case x: return #x
492 #define HOST_COMPLETE_TIMEOUT (HZ / 2)
495 * iwl3945_enqueue_hcmd - enqueue a uCode command
496 * @priv: device private data point
497 * @cmd: a point to the ucode command structure
499 * The function returns < 0 values to indicate the operation is
500 * failed. On success, it turns the index (> 0) of command in the
503 static int iwl3945_enqueue_hcmd(struct iwl_priv
*priv
, struct iwl_host_cmd
*cmd
)
505 struct iwl3945_tx_queue
*txq
= &priv
->txq39
[IWL_CMD_QUEUE_NUM
];
506 struct iwl_queue
*q
= &txq
->q
;
507 struct iwl3945_tfd_frame
*tfd
;
509 struct iwl_cmd
*out_cmd
;
511 u16 fix_size
= (u16
)(cmd
->len
+ sizeof(out_cmd
->hdr
));
512 dma_addr_t phys_addr
;
518 /* If any of the command structures end up being larger than
519 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
520 * we will need to increase the size of the TFD entries */
521 BUG_ON((fix_size
> TFD_MAX_PAYLOAD_SIZE
) &&
522 !(cmd
->meta
.flags
& CMD_SIZE_HUGE
));
525 if (iwl3945_is_rfkill(priv
)) {
526 IWL_DEBUG_INFO("Not sending command - RF KILL");
530 if (iwl_queue_space(q
) < ((cmd
->meta
.flags
& CMD_ASYNC
) ? 2 : 1)) {
531 IWL_ERR(priv
, "No space for Tx\n");
535 spin_lock_irqsave(&priv
->hcmd_lock
, flags
);
537 tfd
= &txq
->bd
[q
->write_ptr
];
538 memset(tfd
, 0, sizeof(*tfd
));
540 control_flags
= (u32
*) tfd
;
542 idx
= get_cmd_index(q
, q
->write_ptr
, cmd
->meta
.flags
& CMD_SIZE_HUGE
);
543 out_cmd
= &txq
->cmd
[idx
];
545 out_cmd
->hdr
.cmd
= cmd
->id
;
546 memcpy(&out_cmd
->meta
, &cmd
->meta
, sizeof(cmd
->meta
));
547 memcpy(&out_cmd
->cmd
.payload
, cmd
->data
, cmd
->len
);
549 /* At this point, the out_cmd now has all of the incoming cmd
552 out_cmd
->hdr
.flags
= 0;
553 out_cmd
->hdr
.sequence
= cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM
) |
554 INDEX_TO_SEQ(q
->write_ptr
));
555 if (out_cmd
->meta
.flags
& CMD_SIZE_HUGE
)
556 out_cmd
->hdr
.sequence
|= SEQ_HUGE_FRAME
;
558 phys_addr
= txq
->dma_addr_cmd
+ sizeof(txq
->cmd
[0]) * idx
+
559 offsetof(struct iwl_cmd
, hdr
);
560 iwl3945_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, fix_size
);
562 pad
= U32_PAD(cmd
->len
);
563 count
= TFD_CTL_COUNT_GET(*control_flags
);
564 *control_flags
= TFD_CTL_COUNT_SET(count
) | TFD_CTL_PAD_SET(pad
);
566 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
567 "%d bytes at %d[%d]:%d\n",
568 get_cmd_string(out_cmd
->hdr
.cmd
),
569 out_cmd
->hdr
.cmd
, le16_to_cpu(out_cmd
->hdr
.sequence
),
570 fix_size
, q
->write_ptr
, idx
, IWL_CMD_QUEUE_NUM
);
572 txq
->need_update
= 1;
574 /* Increment and update queue's write index */
575 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
576 ret
= iwl3945_tx_queue_update_write_ptr(priv
, txq
);
578 spin_unlock_irqrestore(&priv
->hcmd_lock
, flags
);
579 return ret
? ret
: idx
;
582 static int iwl3945_send_cmd_async(struct iwl_priv
*priv
,
583 struct iwl_host_cmd
*cmd
)
587 BUG_ON(!(cmd
->meta
.flags
& CMD_ASYNC
));
589 /* An asynchronous command can not expect an SKB to be set. */
590 BUG_ON(cmd
->meta
.flags
& CMD_WANT_SKB
);
592 /* An asynchronous command MUST have a callback. */
593 BUG_ON(!cmd
->meta
.u
.callback
);
595 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
598 ret
= iwl3945_enqueue_hcmd(priv
, cmd
);
601 "Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
602 get_cmd_string(cmd
->id
), ret
);
608 static int iwl3945_send_cmd_sync(struct iwl_priv
*priv
,
609 struct iwl_host_cmd
*cmd
)
614 BUG_ON(cmd
->meta
.flags
& CMD_ASYNC
);
616 /* A synchronous command can not have a callback set. */
617 BUG_ON(cmd
->meta
.u
.callback
!= NULL
);
619 if (test_and_set_bit(STATUS_HCMD_SYNC_ACTIVE
, &priv
->status
)) {
621 "Error sending %s: Already sending a host command\n",
622 get_cmd_string(cmd
->id
));
627 set_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
629 if (cmd
->meta
.flags
& CMD_WANT_SKB
)
630 cmd
->meta
.source
= &cmd
->meta
;
632 cmd_idx
= iwl3945_enqueue_hcmd(priv
, cmd
);
636 "Error sending %s: iwl3945_enqueue_hcmd failed: %d\n",
637 get_cmd_string(cmd
->id
), ret
);
641 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
642 !test_bit(STATUS_HCMD_ACTIVE
, &priv
->status
),
643 HOST_COMPLETE_TIMEOUT
);
645 if (test_bit(STATUS_HCMD_ACTIVE
, &priv
->status
)) {
646 IWL_ERR(priv
, "Error sending %s: time out after %dms\n",
647 get_cmd_string(cmd
->id
),
648 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT
));
650 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
656 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
657 IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
658 get_cmd_string(cmd
->id
));
662 if (test_bit(STATUS_FW_ERROR
, &priv
->status
)) {
663 IWL_DEBUG_INFO("Command %s failed: FW Error\n",
664 get_cmd_string(cmd
->id
));
668 if ((cmd
->meta
.flags
& CMD_WANT_SKB
) && !cmd
->meta
.u
.skb
) {
669 IWL_ERR(priv
, "Error: Response NULL in '%s'\n",
670 get_cmd_string(cmd
->id
));
679 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
680 struct iwl_cmd
*qcmd
;
682 /* Cancel the CMD_WANT_SKB flag for the cmd in the
683 * TX cmd queue. Otherwise in case the cmd comes
684 * in later, it will possibly set an invalid
685 * address (cmd->meta.source). */
686 qcmd
= &priv
->txq39
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_idx
];
687 qcmd
->meta
.flags
&= ~CMD_WANT_SKB
;
690 if (cmd
->meta
.u
.skb
) {
691 dev_kfree_skb_any(cmd
->meta
.u
.skb
);
692 cmd
->meta
.u
.skb
= NULL
;
695 clear_bit(STATUS_HCMD_SYNC_ACTIVE
, &priv
->status
);
699 int iwl3945_send_cmd(struct iwl_priv
*priv
, struct iwl_host_cmd
*cmd
)
701 if (cmd
->meta
.flags
& CMD_ASYNC
)
702 return iwl3945_send_cmd_async(priv
, cmd
);
704 return iwl3945_send_cmd_sync(priv
, cmd
);
707 int iwl3945_send_cmd_pdu(struct iwl_priv
*priv
, u8 id
, u16 len
, const void *data
)
709 struct iwl_host_cmd cmd
= {
715 return iwl3945_send_cmd_sync(priv
, &cmd
);
718 static int __must_check
iwl3945_send_cmd_u32(struct iwl_priv
*priv
, u8 id
, u32 val
)
720 struct iwl_host_cmd cmd
= {
726 return iwl3945_send_cmd_sync(priv
, &cmd
);
729 int iwl3945_send_statistics_request(struct iwl_priv
*priv
)
731 return iwl3945_send_cmd_u32(priv
, REPLY_STATISTICS_CMD
, 0);
735 * iwl3945_set_rxon_channel - Set the phymode and channel values in staging RXON
736 * @band: 2.4 or 5 GHz band
737 * @channel: Any channel valid for the requested band
739 * In addition to setting the staging RXON, priv->band is also set.
741 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
742 * in the staging RXON flag structure based on the band
744 static int iwl3945_set_rxon_channel(struct iwl_priv
*priv
,
745 enum ieee80211_band band
,
748 if (!iwl3945_get_channel_info(priv
, band
, channel
)) {
749 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
754 if ((le16_to_cpu(priv
->staging39_rxon
.channel
) == channel
) &&
755 (priv
->band
== band
))
758 priv
->staging39_rxon
.channel
= cpu_to_le16(channel
);
759 if (band
== IEEE80211_BAND_5GHZ
)
760 priv
->staging39_rxon
.flags
&= ~RXON_FLG_BAND_24G_MSK
;
762 priv
->staging39_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
766 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel
, band
);
772 * iwl3945_check_rxon_cmd - validate RXON structure is valid
774 * NOTE: This is really only useful during development and can eventually
775 * be #ifdef'd out once the driver is stable and folks aren't actively
778 static int iwl3945_check_rxon_cmd(struct iwl_priv
*priv
)
782 struct iwl3945_rxon_cmd
*rxon
= &priv
->staging39_rxon
;
784 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
785 error
|= le32_to_cpu(rxon
->flags
&
786 (RXON_FLG_TGJ_NARROW_BAND_MSK
|
787 RXON_FLG_RADAR_DETECT_MSK
));
789 IWL_WARN(priv
, "check 24G fields %d | %d\n",
792 error
|= (rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
) ?
793 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK
);
795 IWL_WARN(priv
, "check 52 fields %d | %d\n",
797 error
|= le32_to_cpu(rxon
->flags
& RXON_FLG_CCK_MSK
);
799 IWL_WARN(priv
, "check 52 CCK %d | %d\n",
802 error
|= (rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1;
804 IWL_WARN(priv
, "check mac addr %d | %d\n", counter
++, error
);
806 /* make sure basic rates 6Mbps and 1Mbps are supported */
807 error
|= (((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0) &&
808 ((rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0));
810 IWL_WARN(priv
, "check basic rate %d | %d\n", counter
++, error
);
812 error
|= (le16_to_cpu(rxon
->assoc_id
) > 2007);
814 IWL_WARN(priv
, "check assoc id %d | %d\n", counter
++, error
);
816 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
817 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
));
819 IWL_WARN(priv
, "check CCK and short slot %d | %d\n",
822 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
823 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
));
825 IWL_WARN(priv
, "check CCK & auto detect %d | %d\n",
828 error
|= ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
829 RXON_FLG_TGG_PROTECT_MSK
)) == RXON_FLG_TGG_PROTECT_MSK
);
831 IWL_WARN(priv
, "check TGG and auto detect %d | %d\n",
834 if ((rxon
->flags
& RXON_FLG_DIS_DIV_MSK
))
835 error
|= ((rxon
->flags
& (RXON_FLG_ANT_B_MSK
|
836 RXON_FLG_ANT_A_MSK
)) == 0);
838 IWL_WARN(priv
, "check antenna %d %d\n", counter
++, error
);
841 IWL_WARN(priv
, "Tuning to channel %d\n",
842 le16_to_cpu(rxon
->channel
));
845 IWL_ERR(priv
, "Not a valid rxon_assoc_cmd field values\n");
852 * iwl3945_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
853 * @priv: staging_rxon is compared to active_rxon
855 * If the RXON structure is changing enough to require a new tune,
856 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
857 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
859 static int iwl3945_full_rxon_required(struct iwl_priv
*priv
)
862 /* These items are only settable from the full RXON command */
863 if (!(iwl3945_is_associated(priv
)) ||
864 compare_ether_addr(priv
->staging39_rxon
.bssid_addr
,
865 priv
->active39_rxon
.bssid_addr
) ||
866 compare_ether_addr(priv
->staging39_rxon
.node_addr
,
867 priv
->active39_rxon
.node_addr
) ||
868 compare_ether_addr(priv
->staging39_rxon
.wlap_bssid_addr
,
869 priv
->active39_rxon
.wlap_bssid_addr
) ||
870 (priv
->staging39_rxon
.dev_type
!= priv
->active39_rxon
.dev_type
) ||
871 (priv
->staging39_rxon
.channel
!= priv
->active39_rxon
.channel
) ||
872 (priv
->staging39_rxon
.air_propagation
!=
873 priv
->active39_rxon
.air_propagation
) ||
874 (priv
->staging39_rxon
.assoc_id
!= priv
->active39_rxon
.assoc_id
))
877 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
878 * be updated with the RXON_ASSOC command -- however only some
879 * flag transitions are allowed using RXON_ASSOC */
881 /* Check if we are not switching bands */
882 if ((priv
->staging39_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) !=
883 (priv
->active39_rxon
.flags
& RXON_FLG_BAND_24G_MSK
))
886 /* Check if we are switching association toggle */
887 if ((priv
->staging39_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) !=
888 (priv
->active39_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
))
894 static int iwl3945_send_rxon_assoc(struct iwl_priv
*priv
)
897 struct iwl_rx_packet
*res
= NULL
;
898 struct iwl3945_rxon_assoc_cmd rxon_assoc
;
899 struct iwl_host_cmd cmd
= {
900 .id
= REPLY_RXON_ASSOC
,
901 .len
= sizeof(rxon_assoc
),
902 .meta
.flags
= CMD_WANT_SKB
,
905 const struct iwl3945_rxon_cmd
*rxon1
= &priv
->staging39_rxon
;
906 const struct iwl3945_rxon_cmd
*rxon2
= &priv
->active39_rxon
;
908 if ((rxon1
->flags
== rxon2
->flags
) &&
909 (rxon1
->filter_flags
== rxon2
->filter_flags
) &&
910 (rxon1
->cck_basic_rates
== rxon2
->cck_basic_rates
) &&
911 (rxon1
->ofdm_basic_rates
== rxon2
->ofdm_basic_rates
)) {
912 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
916 rxon_assoc
.flags
= priv
->staging39_rxon
.flags
;
917 rxon_assoc
.filter_flags
= priv
->staging39_rxon
.filter_flags
;
918 rxon_assoc
.ofdm_basic_rates
= priv
->staging39_rxon
.ofdm_basic_rates
;
919 rxon_assoc
.cck_basic_rates
= priv
->staging39_rxon
.cck_basic_rates
;
920 rxon_assoc
.reserved
= 0;
922 rc
= iwl3945_send_cmd_sync(priv
, &cmd
);
926 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
927 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
928 IWL_ERR(priv
, "Bad return from REPLY_RXON_ASSOC command\n");
932 priv
->alloc_rxb_skb
--;
933 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
939 * iwl3945_commit_rxon - commit staging_rxon to hardware
941 * The RXON command in staging_rxon is committed to the hardware and
942 * the active_rxon structure is updated with the new data. This
943 * function correctly transitions out of the RXON_ASSOC_MSK state if
944 * a HW tune is required based on the RXON structure changes.
946 static int iwl3945_commit_rxon(struct iwl_priv
*priv
)
948 /* cast away the const for active_rxon in this function */
949 struct iwl3945_rxon_cmd
*active_rxon
= (void *)&priv
->active39_rxon
;
952 if (!iwl3945_is_alive(priv
))
955 /* always get timestamp with Rx frame */
956 priv
->staging39_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
959 priv
->staging39_rxon
.flags
&=
960 ~(RXON_FLG_DIS_DIV_MSK
| RXON_FLG_ANT_SEL_MSK
);
961 priv
->staging39_rxon
.flags
|= iwl3945_get_antenna_flags(priv
);
963 rc
= iwl3945_check_rxon_cmd(priv
);
965 IWL_ERR(priv
, "Invalid RXON configuration. Not committing.\n");
969 /* If we don't need to send a full RXON, we can use
970 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
971 * and other flags for the current radio configuration. */
972 if (!iwl3945_full_rxon_required(priv
)) {
973 rc
= iwl3945_send_rxon_assoc(priv
);
975 IWL_ERR(priv
, "Error setting RXON_ASSOC "
976 "configuration (%d).\n", rc
);
980 memcpy(active_rxon
, &priv
->staging39_rxon
, sizeof(*active_rxon
));
985 /* If we are currently associated and the new config requires
986 * an RXON_ASSOC and the new config wants the associated mask enabled,
987 * we must clear the associated from the active configuration
988 * before we apply the new config */
989 if (iwl3945_is_associated(priv
) &&
990 (priv
->staging39_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
)) {
991 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
992 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
994 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_RXON
,
995 sizeof(struct iwl3945_rxon_cmd
),
996 &priv
->active39_rxon
);
998 /* If the mask clearing failed then we set
999 * active_rxon back to what it was previously */
1001 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
1002 IWL_ERR(priv
, "Error clearing ASSOC_MSK on current "
1003 "configuration (%d).\n", rc
);
1008 IWL_DEBUG_INFO("Sending RXON\n"
1009 "* with%s RXON_FILTER_ASSOC_MSK\n"
1012 ((priv
->staging39_rxon
.filter_flags
&
1013 RXON_FILTER_ASSOC_MSK
) ? "" : "out"),
1014 le16_to_cpu(priv
->staging39_rxon
.channel
),
1015 priv
->staging_rxon
.bssid_addr
);
1017 /* Apply the new configuration */
1018 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_RXON
,
1019 sizeof(struct iwl3945_rxon_cmd
), &priv
->staging39_rxon
);
1021 IWL_ERR(priv
, "Error setting new configuration (%d).\n", rc
);
1025 memcpy(active_rxon
, &priv
->staging39_rxon
, sizeof(*active_rxon
));
1027 iwl3945_clear_stations_table(priv
);
1029 /* If we issue a new RXON command which required a tune then we must
1030 * send a new TXPOWER command or we won't be able to Tx any frames */
1031 rc
= iwl3945_hw_reg_send_txpower(priv
);
1033 IWL_ERR(priv
, "Error setting Tx power (%d).\n", rc
);
1037 /* Add the broadcast address so we can send broadcast frames */
1038 if (iwl3945_add_station(priv
, iwl_bcast_addr
, 0, 0) ==
1039 IWL_INVALID_STATION
) {
1040 IWL_ERR(priv
, "Error adding BROADCAST address for transmit.\n");
1044 /* If we have set the ASSOC_MSK and we are in BSS mode then
1045 * add the IWL_AP_ID to the station rate table */
1046 if (iwl3945_is_associated(priv
) &&
1047 (priv
->iw_mode
== NL80211_IFTYPE_STATION
))
1048 if (iwl3945_add_station(priv
, priv
->active39_rxon
.bssid_addr
, 1, 0)
1049 == IWL_INVALID_STATION
) {
1050 IWL_ERR(priv
, "Error adding AP address for transmit\n");
1054 /* Init the hardware's rate fallback order based on the band */
1055 rc
= iwl3945_init_hw_rate_table(priv
);
1057 IWL_ERR(priv
, "Error setting HW rate table: %02X\n", rc
);
1064 static int iwl3945_send_bt_config(struct iwl_priv
*priv
)
1066 struct iwl_bt_cmd bt_cmd
= {
1074 return iwl3945_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
1075 sizeof(bt_cmd
), &bt_cmd
);
1078 static int iwl3945_send_scan_abort(struct iwl_priv
*priv
)
1081 struct iwl_rx_packet
*res
;
1082 struct iwl_host_cmd cmd
= {
1083 .id
= REPLY_SCAN_ABORT_CMD
,
1084 .meta
.flags
= CMD_WANT_SKB
,
1087 /* If there isn't a scan actively going on in the hardware
1088 * then we are in between scan bands and not actually
1089 * actively scanning, so don't send the abort command */
1090 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
1091 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1095 rc
= iwl3945_send_cmd_sync(priv
, &cmd
);
1097 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1101 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1102 if (res
->u
.status
!= CAN_ABORT_STATUS
) {
1103 /* The scan abort will return 1 for success or
1104 * 2 for "failure". A failure condition can be
1105 * due to simply not being in an active scan which
1106 * can occur if we send the scan abort before we
1107 * the microcode has notified us that a scan is
1109 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res
->u
.status
);
1110 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1111 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
1114 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1119 static int iwl3945_card_state_sync_callback(struct iwl_priv
*priv
,
1120 struct iwl_cmd
*cmd
,
1121 struct sk_buff
*skb
)
1129 * Use: Sets the device's internal card state to enable, disable, or halt
1131 * When in the 'enable' state the card operates as normal.
1132 * When in the 'disable' state, the card enters into a low power mode.
1133 * When in the 'halt' state, the card is shut down and must be fully
1134 * restarted to come back on.
1136 static int iwl3945_send_card_state(struct iwl_priv
*priv
, u32 flags
, u8 meta_flag
)
1138 struct iwl_host_cmd cmd
= {
1139 .id
= REPLY_CARD_STATE_CMD
,
1142 .meta
.flags
= meta_flag
,
1145 if (meta_flag
& CMD_ASYNC
)
1146 cmd
.meta
.u
.callback
= iwl3945_card_state_sync_callback
;
1148 return iwl3945_send_cmd(priv
, &cmd
);
1151 static int iwl3945_add_sta_sync_callback(struct iwl_priv
*priv
,
1152 struct iwl_cmd
*cmd
, struct sk_buff
*skb
)
1154 struct iwl_rx_packet
*res
= NULL
;
1157 IWL_ERR(priv
, "Error: Response NULL in REPLY_ADD_STA.\n");
1161 res
= (struct iwl_rx_packet
*)skb
->data
;
1162 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1163 IWL_ERR(priv
, "Bad return from REPLY_ADD_STA (0x%08X)\n",
1168 switch (res
->u
.add_sta
.status
) {
1169 case ADD_STA_SUCCESS_MSK
:
1175 /* We didn't cache the SKB; let the caller free it */
1179 int iwl3945_send_add_station(struct iwl_priv
*priv
,
1180 struct iwl3945_addsta_cmd
*sta
, u8 flags
)
1182 struct iwl_rx_packet
*res
= NULL
;
1184 struct iwl_host_cmd cmd
= {
1185 .id
= REPLY_ADD_STA
,
1186 .len
= sizeof(struct iwl3945_addsta_cmd
),
1187 .meta
.flags
= flags
,
1191 if (flags
& CMD_ASYNC
)
1192 cmd
.meta
.u
.callback
= iwl3945_add_sta_sync_callback
;
1194 cmd
.meta
.flags
|= CMD_WANT_SKB
;
1196 rc
= iwl3945_send_cmd(priv
, &cmd
);
1198 if (rc
|| (flags
& CMD_ASYNC
))
1201 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1202 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1203 IWL_ERR(priv
, "Bad return from REPLY_ADD_STA (0x%08X)\n",
1209 switch (res
->u
.add_sta
.status
) {
1210 case ADD_STA_SUCCESS_MSK
:
1211 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1215 IWL_WARN(priv
, "REPLY_ADD_STA failed\n");
1220 priv
->alloc_rxb_skb
--;
1221 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1226 static int iwl3945_update_sta_key_info(struct iwl_priv
*priv
,
1227 struct ieee80211_key_conf
*keyconf
,
1230 unsigned long flags
;
1231 __le16 key_flags
= 0;
1233 switch (keyconf
->alg
) {
1235 key_flags
|= STA_KEY_FLG_CCMP
;
1236 key_flags
|= cpu_to_le16(
1237 keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1238 key_flags
&= ~STA_KEY_FLG_INVALID
;
1245 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1246 priv
->stations_39
[sta_id
].keyinfo
.alg
= keyconf
->alg
;
1247 priv
->stations_39
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
1248 memcpy(priv
->stations_39
[sta_id
].keyinfo
.key
, keyconf
->key
,
1251 memcpy(priv
->stations_39
[sta_id
].sta
.key
.key
, keyconf
->key
,
1253 priv
->stations_39
[sta_id
].sta
.key
.key_flags
= key_flags
;
1254 priv
->stations_39
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1255 priv
->stations_39
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1257 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1259 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
1260 iwl3945_send_add_station(priv
, &priv
->stations_39
[sta_id
].sta
, 0);
1264 static int iwl3945_clear_sta_key_info(struct iwl_priv
*priv
, u8 sta_id
)
1266 unsigned long flags
;
1268 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1269 memset(&priv
->stations_39
[sta_id
].keyinfo
, 0, sizeof(struct iwl3945_hw_key
));
1270 memset(&priv
->stations_39
[sta_id
].sta
.key
, 0,
1271 sizeof(struct iwl4965_keyinfo
));
1272 priv
->stations_39
[sta_id
].sta
.key
.key_flags
= STA_KEY_FLG_NO_ENC
;
1273 priv
->stations_39
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1274 priv
->stations_39
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1275 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1277 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
1278 iwl3945_send_add_station(priv
, &priv
->stations_39
[sta_id
].sta
, 0);
1282 static void iwl3945_clear_free_frames(struct iwl_priv
*priv
)
1284 struct list_head
*element
;
1286 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1287 priv
->frames_count
);
1289 while (!list_empty(&priv
->free_frames
)) {
1290 element
= priv
->free_frames
.next
;
1292 kfree(list_entry(element
, struct iwl3945_frame
, list
));
1293 priv
->frames_count
--;
1296 if (priv
->frames_count
) {
1297 IWL_WARN(priv
, "%d frames still in use. Did we lose one?\n",
1298 priv
->frames_count
);
1299 priv
->frames_count
= 0;
1303 static struct iwl3945_frame
*iwl3945_get_free_frame(struct iwl_priv
*priv
)
1305 struct iwl3945_frame
*frame
;
1306 struct list_head
*element
;
1307 if (list_empty(&priv
->free_frames
)) {
1308 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
1310 IWL_ERR(priv
, "Could not allocate frame!\n");
1314 priv
->frames_count
++;
1318 element
= priv
->free_frames
.next
;
1320 return list_entry(element
, struct iwl3945_frame
, list
);
1323 static void iwl3945_free_frame(struct iwl_priv
*priv
, struct iwl3945_frame
*frame
)
1325 memset(frame
, 0, sizeof(*frame
));
1326 list_add(&frame
->list
, &priv
->free_frames
);
1329 unsigned int iwl3945_fill_beacon_frame(struct iwl_priv
*priv
,
1330 struct ieee80211_hdr
*hdr
,
1334 if (!iwl3945_is_associated(priv
) || !priv
->ibss_beacon
||
1335 ((priv
->iw_mode
!= NL80211_IFTYPE_ADHOC
) &&
1336 (priv
->iw_mode
!= NL80211_IFTYPE_AP
)))
1339 if (priv
->ibss_beacon
->len
> left
)
1342 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
1344 return priv
->ibss_beacon
->len
;
1347 static u8
iwl3945_rate_get_lowest_plcp(struct iwl_priv
*priv
)
1353 if (priv
->staging39_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
1354 rate_mask
= priv
->active_rate_basic
& IWL_CCK_RATES_MASK
;
1356 rate_mask
= priv
->active_rate_basic
& IWL_OFDM_RATES_MASK
;
1358 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
1359 i
= iwl3945_rates
[i
].next_ieee
) {
1360 if (rate_mask
& (1 << i
))
1361 return iwl3945_rates
[i
].plcp
;
1364 /* No valid rate was found. Assign the lowest one */
1365 if (priv
->staging39_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
1366 return IWL_RATE_1M_PLCP
;
1368 return IWL_RATE_6M_PLCP
;
1371 static int iwl3945_send_beacon_cmd(struct iwl_priv
*priv
)
1373 struct iwl3945_frame
*frame
;
1374 unsigned int frame_size
;
1378 frame
= iwl3945_get_free_frame(priv
);
1381 IWL_ERR(priv
, "Could not obtain free frame buffer for beacon "
1386 rate
= iwl3945_rate_get_lowest_plcp(priv
);
1388 frame_size
= iwl3945_hw_get_beacon_cmd(priv
, frame
, rate
);
1390 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
1393 iwl3945_free_frame(priv
, frame
);
1398 /******************************************************************************
1400 * EEPROM related functions
1402 ******************************************************************************/
1404 static void get_eeprom_mac(struct iwl_priv
*priv
, u8
*mac
)
1406 memcpy(mac
, priv
->eeprom39
.mac_address
, 6);
1410 * Clear the OWNER_MSK, to establish driver (instead of uCode running on
1411 * embedded controller) as EEPROM reader; each read is a series of pulses
1412 * to/from the EEPROM chip, not a single event, so even reads could conflict
1413 * if they weren't arbitrated by some ownership mechanism. Here, the driver
1414 * simply claims ownership, which should be safe when this function is called
1415 * (i.e. before loading uCode!).
1417 static inline int iwl3945_eeprom_acquire_semaphore(struct iwl_priv
*priv
)
1419 _iwl_clear_bit(priv
, CSR_EEPROM_GP
, CSR_EEPROM_GP_IF_OWNER_MSK
);
1424 * iwl3945_eeprom_init - read EEPROM contents
1426 * Load the EEPROM contents from adapter into priv->eeprom39
1428 * NOTE: This routine uses the non-debug IO access functions.
1430 int iwl3945_eeprom_init(struct iwl_priv
*priv
)
1432 u16
*e
= (u16
*)&priv
->eeprom39
;
1433 u32 gp
= iwl_read32(priv
, CSR_EEPROM_GP
);
1434 int sz
= sizeof(priv
->eeprom39
);
1438 /* The EEPROM structure has several padding buffers within it
1439 * and when adding new EEPROM maps is subject to programmer errors
1440 * which may be very difficult to identify without explicitly
1441 * checking the resulting size of the eeprom map. */
1442 BUILD_BUG_ON(sizeof(priv
->eeprom39
) != IWL_EEPROM_IMAGE_SIZE
);
1444 if ((gp
& CSR_EEPROM_GP_VALID_MSK
) == CSR_EEPROM_GP_BAD_SIGNATURE
) {
1445 IWL_ERR(priv
, "EEPROM not found, EEPROM_GP=0x%08x\n", gp
);
1449 /* Make sure driver (instead of uCode) is allowed to read EEPROM */
1450 ret
= iwl3945_eeprom_acquire_semaphore(priv
);
1452 IWL_ERR(priv
, "Failed to acquire EEPROM semaphore.\n");
1456 /* eeprom is an array of 16bit values */
1457 for (addr
= 0; addr
< sz
; addr
+= sizeof(u16
)) {
1460 _iwl_write32(priv
, CSR_EEPROM_REG
,
1461 CSR_EEPROM_REG_MSK_ADDR
& (addr
<< 1));
1462 _iwl_clear_bit(priv
, CSR_EEPROM_REG
, CSR_EEPROM_REG_BIT_CMD
);
1463 ret
= iwl_poll_direct_bit(priv
, CSR_EEPROM_REG
,
1464 CSR_EEPROM_REG_READ_VALID_MSK
,
1465 IWL_EEPROM_ACCESS_TIMEOUT
);
1467 IWL_ERR(priv
, "Time out reading EEPROM[%d]\n", addr
);
1471 r
= _iwl_read_direct32(priv
, CSR_EEPROM_REG
);
1472 e
[addr
/ 2] = le16_to_cpu((__force __le16
)(r
>> 16));
1478 static void iwl3945_unset_hw_params(struct iwl_priv
*priv
)
1480 if (priv
->shared_virt
)
1481 pci_free_consistent(priv
->pci_dev
,
1482 sizeof(struct iwl3945_shared
),
1488 * iwl3945_supported_rate_to_ie - fill in the supported rate in IE field
1490 * return : set the bit for each supported rate insert in ie
1492 static u16
iwl3945_supported_rate_to_ie(u8
*ie
, u16 supported_rate
,
1493 u16 basic_rate
, int *left
)
1495 u16 ret_rates
= 0, bit
;
1500 for (bit
= 1, i
= 0; i
< IWL_RATE_COUNT
; i
++, bit
<<= 1) {
1501 if (bit
& supported_rate
) {
1503 rates
[*cnt
] = iwl3945_rates
[i
].ieee
|
1504 ((bit
& basic_rate
) ? 0x80 : 0x00);
1508 (*cnt
>= IWL_SUPPORTED_RATES_IE_LEN
))
1517 * iwl3945_fill_probe_req - fill in all required fields and IE for probe request
1519 static u16
iwl3945_fill_probe_req(struct iwl_priv
*priv
,
1520 struct ieee80211_mgmt
*frame
,
1525 u16 active_rates
, ret_rates
, cck_rates
;
1527 /* Make sure there is enough space for the probe request,
1528 * two mandatory IEs and the data */
1534 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
1535 memcpy(frame
->da
, iwl_bcast_addr
, ETH_ALEN
);
1536 memcpy(frame
->sa
, priv
->mac_addr
, ETH_ALEN
);
1537 memcpy(frame
->bssid
, iwl_bcast_addr
, ETH_ALEN
);
1538 frame
->seq_ctrl
= 0;
1540 /* fill in our indirect SSID IE */
1547 pos
= &(frame
->u
.probe_req
.variable
[0]);
1548 *pos
++ = WLAN_EID_SSID
;
1551 /* fill in supported rate */
1557 /* ... fill it in... */
1558 *pos
++ = WLAN_EID_SUPP_RATES
;
1561 priv
->active_rate
= priv
->rates_mask
;
1562 active_rates
= priv
->active_rate
;
1563 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
1565 cck_rates
= IWL_CCK_RATES_MASK
& active_rates
;
1566 ret_rates
= iwl3945_supported_rate_to_ie(pos
, cck_rates
,
1567 priv
->active_rate_basic
, &left
);
1568 active_rates
&= ~ret_rates
;
1570 ret_rates
= iwl3945_supported_rate_to_ie(pos
, active_rates
,
1571 priv
->active_rate_basic
, &left
);
1572 active_rates
&= ~ret_rates
;
1576 if (active_rates
== 0)
1579 /* fill in supported extended rate */
1584 /* ... fill it in... */
1585 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
1587 iwl3945_supported_rate_to_ie(pos
, active_rates
,
1588 priv
->active_rate_basic
, &left
);
1599 static int iwl3945_send_qos_params_command(struct iwl_priv
*priv
,
1600 struct iwl_qosparam_cmd
*qos
)
1603 return iwl3945_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
1604 sizeof(struct iwl_qosparam_cmd
), qos
);
1607 static void iwl3945_reset_qos(struct iwl_priv
*priv
)
1613 unsigned long flags
;
1616 spin_lock_irqsave(&priv
->lock
, flags
);
1617 priv
->qos_data
.qos_active
= 0;
1619 /* QoS always active in AP and ADHOC mode
1620 * In STA mode wait for association
1622 if (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
||
1623 priv
->iw_mode
== NL80211_IFTYPE_AP
)
1624 priv
->qos_data
.qos_active
= 1;
1626 priv
->qos_data
.qos_active
= 0;
1629 /* check for legacy mode */
1630 if ((priv
->iw_mode
== NL80211_IFTYPE_ADHOC
&&
1631 (priv
->active_rate
& IWL_OFDM_RATES_MASK
) == 0) ||
1632 (priv
->iw_mode
== NL80211_IFTYPE_STATION
&&
1633 (priv
->staging39_rxon
.flags
& RXON_FLG_SHORT_SLOT_MSK
) == 0)) {
1638 if (priv
->qos_data
.qos_active
)
1641 priv
->qos_data
.def_qos_parm
.ac
[0].cw_min
= cpu_to_le16(cw_min
);
1642 priv
->qos_data
.def_qos_parm
.ac
[0].cw_max
= cpu_to_le16(cw_max
);
1643 priv
->qos_data
.def_qos_parm
.ac
[0].aifsn
= aifs
;
1644 priv
->qos_data
.def_qos_parm
.ac
[0].edca_txop
= 0;
1645 priv
->qos_data
.def_qos_parm
.ac
[0].reserved1
= 0;
1647 if (priv
->qos_data
.qos_active
) {
1649 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
= cpu_to_le16(cw_min
);
1650 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
= cpu_to_le16(cw_max
);
1651 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 7;
1652 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
= 0;
1653 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1656 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
1657 cpu_to_le16((cw_min
+ 1) / 2 - 1);
1658 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
1659 cpu_to_le16(cw_max
);
1660 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 2;
1662 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1665 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1667 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1670 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
1671 cpu_to_le16((cw_min
+ 1) / 4 - 1);
1672 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
1673 cpu_to_le16((cw_max
+ 1) / 2 - 1);
1674 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 2;
1675 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1677 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1680 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1683 for (i
= 1; i
< 4; i
++) {
1684 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
1685 cpu_to_le16(cw_min
);
1686 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
1687 cpu_to_le16(cw_max
);
1688 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= aifs
;
1689 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
= 0;
1690 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1693 IWL_DEBUG_QOS("set QoS to default \n");
1695 spin_unlock_irqrestore(&priv
->lock
, flags
);
1698 static void iwl3945_activate_qos(struct iwl_priv
*priv
, u8 force
)
1700 unsigned long flags
;
1702 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1705 spin_lock_irqsave(&priv
->lock
, flags
);
1706 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
1708 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
1709 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
1710 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1711 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
1713 if (priv
->qos_data
.qos_active
)
1714 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1715 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
1717 spin_unlock_irqrestore(&priv
->lock
, flags
);
1719 if (force
|| iwl3945_is_associated(priv
)) {
1720 IWL_DEBUG_QOS("send QoS cmd with QoS active %d \n",
1721 priv
->qos_data
.qos_active
);
1723 iwl3945_send_qos_params_command(priv
,
1724 &(priv
->qos_data
.def_qos_parm
));
1729 * Power management (not Tx power!) functions
1731 #define MSEC_TO_USEC 1024
1734 #define NOSLP __constant_cpu_to_le16(0), 0, 0
1735 #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
1736 #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
1737 #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
1738 __constant_cpu_to_le32(X1), \
1739 __constant_cpu_to_le32(X2), \
1740 __constant_cpu_to_le32(X3), \
1741 __constant_cpu_to_le32(X4)}
1743 /* default power management (not Tx power) table values */
1745 static struct iwl_power_vec_entry range_0
[IWL39_POWER_AC
] = {
1746 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1747 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1748 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1749 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
1750 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
1751 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
1755 static struct iwl_power_vec_entry range_1
[IWL39_POWER_AC
] = {
1756 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1757 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
1758 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
1759 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
1760 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
1761 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
1762 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
1763 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
1764 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
1765 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
1768 int iwl3945_power_init_handle(struct iwl_priv
*priv
)
1771 struct iwl3945_power_mgr
*pow_data
;
1772 int size
= sizeof(struct iwl_power_vec_entry
) * IWL39_POWER_AC
;
1775 IWL_DEBUG_POWER("Initialize power \n");
1777 pow_data
= &(priv
->power_data_39
);
1779 memset(pow_data
, 0, sizeof(*pow_data
));
1781 pow_data
->active_index
= IWL_POWER_RANGE_0
;
1782 pow_data
->dtim_val
= 0xffff;
1784 memcpy(&pow_data
->pwr_range_0
[0], &range_0
[0], size
);
1785 memcpy(&pow_data
->pwr_range_1
[0], &range_1
[0], size
);
1787 rc
= pci_read_config_word(priv
->pci_dev
, PCI_LINK_CTRL
, &pci_pm
);
1791 struct iwl_powertable_cmd
*cmd
;
1793 IWL_DEBUG_POWER("adjust power command flags\n");
1795 for (i
= 0; i
< IWL39_POWER_AC
; i
++) {
1796 cmd
= &pow_data
->pwr_range_0
[i
].cmd
;
1799 cmd
->flags
&= ~IWL_POWER_PCI_PM_MSK
;
1801 cmd
->flags
|= IWL_POWER_PCI_PM_MSK
;
1807 static int iwl3945_update_power_cmd(struct iwl_priv
*priv
,
1808 struct iwl_powertable_cmd
*cmd
, u32 mode
)
1813 struct iwl_power_vec_entry
*range
;
1815 struct iwl3945_power_mgr
*pow_data
;
1817 if (mode
> IWL_POWER_INDEX_5
) {
1818 IWL_DEBUG_POWER("Error invalid power mode \n");
1821 pow_data
= &(priv
->power_data_39
);
1823 if (pow_data
->active_index
== IWL_POWER_RANGE_0
)
1824 range
= &pow_data
->pwr_range_0
[0];
1826 range
= &pow_data
->pwr_range_1
[1];
1828 memcpy(cmd
, &range
[mode
].cmd
, sizeof(struct iwl3945_powertable_cmd
));
1830 #ifdef IWL_MAC80211_DISABLE
1831 if (priv
->assoc_network
!= NULL
) {
1832 unsigned long flags
;
1834 period
= priv
->assoc_network
->tim
.tim_period
;
1836 #endif /*IWL_MAC80211_DISABLE */
1837 skip
= range
[mode
].no_dtim
;
1846 cmd
->flags
&= ~IWL_POWER_SLEEP_OVER_DTIM_MSK
;
1848 __le32 slp_itrvl
= cmd
->sleep_interval
[IWL_POWER_VEC_SIZE
- 1];
1849 max_sleep
= (le32_to_cpu(slp_itrvl
) / period
) * period
;
1850 cmd
->flags
|= IWL_POWER_SLEEP_OVER_DTIM_MSK
;
1853 for (i
= 0; i
< IWL_POWER_VEC_SIZE
; i
++) {
1854 if (le32_to_cpu(cmd
->sleep_interval
[i
]) > max_sleep
)
1855 cmd
->sleep_interval
[i
] = cpu_to_le32(max_sleep
);
1858 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd
->flags
);
1859 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd
->tx_data_timeout
));
1860 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd
->rx_data_timeout
));
1861 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
1862 le32_to_cpu(cmd
->sleep_interval
[0]),
1863 le32_to_cpu(cmd
->sleep_interval
[1]),
1864 le32_to_cpu(cmd
->sleep_interval
[2]),
1865 le32_to_cpu(cmd
->sleep_interval
[3]),
1866 le32_to_cpu(cmd
->sleep_interval
[4]));
1871 static int iwl3945_send_power_mode(struct iwl_priv
*priv
, u32 mode
)
1873 u32
uninitialized_var(final_mode
);
1875 struct iwl_powertable_cmd cmd
;
1877 /* If on battery, set to 3,
1878 * if plugged into AC power, set to CAM ("continuously aware mode"),
1879 * else user level */
1881 case IWL39_POWER_BATTERY
:
1882 final_mode
= IWL_POWER_INDEX_3
;
1884 case IWL39_POWER_AC
:
1885 final_mode
= IWL_POWER_MODE_CAM
;
1892 iwl3945_update_power_cmd(priv
, &cmd
, final_mode
);
1894 /* FIXME use get_hcmd_size 3945 command is 4 bytes shorter */
1895 rc
= iwl3945_send_cmd_pdu(priv
, POWER_TABLE_CMD
,
1896 sizeof(struct iwl3945_powertable_cmd
), &cmd
);
1898 if (final_mode
== IWL_POWER_MODE_CAM
)
1899 clear_bit(STATUS_POWER_PMI
, &priv
->status
);
1901 set_bit(STATUS_POWER_PMI
, &priv
->status
);
1907 * iwl3945_scan_cancel - Cancel any currently executing HW scan
1909 * NOTE: priv->mutex is not required before calling this function
1911 static int iwl3945_scan_cancel(struct iwl_priv
*priv
)
1913 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
1914 clear_bit(STATUS_SCANNING
, &priv
->status
);
1918 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1919 if (!test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1920 IWL_DEBUG_SCAN("Queuing scan abort.\n");
1921 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1922 queue_work(priv
->workqueue
, &priv
->abort_scan
);
1925 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
1927 return test_bit(STATUS_SCANNING
, &priv
->status
);
1934 * iwl3945_scan_cancel_timeout - Cancel any currently executing HW scan
1935 * @ms: amount of time to wait (in milliseconds) for scan to abort
1937 * NOTE: priv->mutex must be held before calling this function
1939 static int iwl3945_scan_cancel_timeout(struct iwl_priv
*priv
, unsigned long ms
)
1941 unsigned long now
= jiffies
;
1944 ret
= iwl3945_scan_cancel(priv
);
1946 mutex_unlock(&priv
->mutex
);
1947 while (!time_after(jiffies
, now
+ msecs_to_jiffies(ms
)) &&
1948 test_bit(STATUS_SCANNING
, &priv
->status
))
1950 mutex_lock(&priv
->mutex
);
1952 return test_bit(STATUS_SCANNING
, &priv
->status
);
1958 #define MAX_UCODE_BEACON_INTERVAL 1024
1959 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
1961 static __le16
iwl3945_adjust_beacon_interval(u16 beacon_val
)
1964 u16 beacon_factor
= 0;
1967 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
1968 / MAX_UCODE_BEACON_INTERVAL
;
1969 new_val
= beacon_val
/ beacon_factor
;
1971 return cpu_to_le16(new_val
);
1974 static void iwl3945_setup_rxon_timing(struct iwl_priv
*priv
)
1976 u64 interval_tm_unit
;
1978 unsigned long flags
;
1979 struct ieee80211_conf
*conf
= NULL
;
1982 conf
= ieee80211_get_hw_conf(priv
->hw
);
1984 spin_lock_irqsave(&priv
->lock
, flags
);
1985 priv
->rxon_timing
.timestamp
= cpu_to_le64(priv
->timestamp
);
1986 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
1988 tsf
= priv
->timestamp
;
1990 beacon_int
= priv
->beacon_int
;
1991 spin_unlock_irqrestore(&priv
->lock
, flags
);
1993 if (priv
->iw_mode
== NL80211_IFTYPE_STATION
) {
1994 if (beacon_int
== 0) {
1995 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
1996 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
1998 priv
->rxon_timing
.beacon_interval
=
1999 cpu_to_le16(beacon_int
);
2000 priv
->rxon_timing
.beacon_interval
=
2001 iwl3945_adjust_beacon_interval(
2002 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2005 priv
->rxon_timing
.atim_window
= 0;
2007 priv
->rxon_timing
.beacon_interval
=
2008 iwl3945_adjust_beacon_interval(conf
->beacon_int
);
2009 /* TODO: we need to get atim_window from upper stack
2010 * for now we set to 0 */
2011 priv
->rxon_timing
.atim_window
= 0;
2015 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
2016 result
= do_div(tsf
, interval_tm_unit
);
2017 priv
->rxon_timing
.beacon_init_val
=
2018 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
2021 ("beacon interval %d beacon timer %d beacon tim %d\n",
2022 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
2023 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
2024 le16_to_cpu(priv
->rxon_timing
.atim_window
));
2027 static int iwl3945_scan_initiate(struct iwl_priv
*priv
)
2029 if (!iwl3945_is_ready_rf(priv
)) {
2030 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
2034 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
2035 IWL_DEBUG_SCAN("Scan already in progress.\n");
2039 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
2040 IWL_DEBUG_SCAN("Scan request while abort pending. "
2045 IWL_DEBUG_INFO("Starting scan...\n");
2046 if (priv
->cfg
->sku
& IWL_SKU_G
)
2047 priv
->scan_bands
|= BIT(IEEE80211_BAND_2GHZ
);
2048 if (priv
->cfg
->sku
& IWL_SKU_A
)
2049 priv
->scan_bands
|= BIT(IEEE80211_BAND_5GHZ
);
2050 set_bit(STATUS_SCANNING
, &priv
->status
);
2051 priv
->scan_start
= jiffies
;
2052 priv
->scan_pass_start
= priv
->scan_start
;
2054 queue_work(priv
->workqueue
, &priv
->request_scan
);
2059 static int iwl3945_set_rxon_hwcrypto(struct iwl_priv
*priv
, int hw_decrypt
)
2061 struct iwl3945_rxon_cmd
*rxon
= &priv
->staging39_rxon
;
2064 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
2066 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
2071 static void iwl3945_set_flags_for_phymode(struct iwl_priv
*priv
,
2072 enum ieee80211_band band
)
2074 if (band
== IEEE80211_BAND_5GHZ
) {
2075 priv
->staging39_rxon
.flags
&=
2076 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
2077 | RXON_FLG_CCK_MSK
);
2078 priv
->staging39_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2080 /* Copied from iwl3945_bg_post_associate() */
2081 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
2082 priv
->staging39_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2084 priv
->staging39_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2086 if (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
)
2087 priv
->staging39_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2089 priv
->staging39_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
2090 priv
->staging39_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
2091 priv
->staging39_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
2096 * initialize rxon structure with default values from eeprom
2098 static void iwl3945_connection_init_rx_config(struct iwl_priv
*priv
,
2101 const struct iwl_channel_info
*ch_info
;
2103 memset(&priv
->staging39_rxon
, 0, sizeof(priv
->staging39_rxon
));
2106 case NL80211_IFTYPE_AP
:
2107 priv
->staging39_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
2110 case NL80211_IFTYPE_STATION
:
2111 priv
->staging39_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
2112 priv
->staging39_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
2115 case NL80211_IFTYPE_ADHOC
:
2116 priv
->staging39_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
2117 priv
->staging39_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
2118 priv
->staging39_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
2119 RXON_FILTER_ACCEPT_GRP_MSK
;
2122 case NL80211_IFTYPE_MONITOR
:
2123 priv
->staging39_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
2124 priv
->staging39_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
2125 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
2128 IWL_ERR(priv
, "Unsupported interface type %d\n", mode
);
2133 /* TODO: Figure out when short_preamble would be set and cache from
2135 if (!hw_to_local(priv
->hw
)->short_preamble
)
2136 priv
->staging39_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
2138 priv
->staging39_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
2141 ch_info
= iwl3945_get_channel_info(priv
, priv
->band
,
2142 le16_to_cpu(priv
->active39_rxon
.channel
));
2145 ch_info
= &priv
->channel_info
[0];
2148 * in some case A channels are all non IBSS
2149 * in this case force B/G channel
2151 if ((mode
== NL80211_IFTYPE_ADHOC
) && !(is_channel_ibss(ch_info
)))
2152 ch_info
= &priv
->channel_info
[0];
2154 priv
->staging39_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
2155 if (is_channel_a_band(ch_info
))
2156 priv
->band
= IEEE80211_BAND_5GHZ
;
2158 priv
->band
= IEEE80211_BAND_2GHZ
;
2160 iwl3945_set_flags_for_phymode(priv
, priv
->band
);
2162 priv
->staging39_rxon
.ofdm_basic_rates
=
2163 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2164 priv
->staging39_rxon
.cck_basic_rates
=
2165 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2168 static int iwl3945_set_mode(struct iwl_priv
*priv
, int mode
)
2170 if (mode
== NL80211_IFTYPE_ADHOC
) {
2171 const struct iwl_channel_info
*ch_info
;
2173 ch_info
= iwl3945_get_channel_info(priv
,
2175 le16_to_cpu(priv
->staging39_rxon
.channel
));
2177 if (!ch_info
|| !is_channel_ibss(ch_info
)) {
2178 IWL_ERR(priv
, "channel %d not IBSS channel\n",
2179 le16_to_cpu(priv
->staging39_rxon
.channel
));
2184 iwl3945_connection_init_rx_config(priv
, mode
);
2185 memcpy(priv
->staging39_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
2187 iwl3945_clear_stations_table(priv
);
2189 /* don't commit rxon if rf-kill is on*/
2190 if (!iwl3945_is_ready_rf(priv
))
2193 cancel_delayed_work(&priv
->scan_check
);
2194 if (iwl3945_scan_cancel_timeout(priv
, 100)) {
2195 IWL_WARN(priv
, "Aborted scan still in progress after 100ms\n");
2196 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2200 iwl3945_commit_rxon(priv
);
2205 static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv
*priv
,
2206 struct ieee80211_tx_info
*info
,
2207 struct iwl_cmd
*cmd
,
2208 struct sk_buff
*skb_frag
,
2211 struct iwl3945_hw_key
*keyinfo
=
2212 &priv
->stations_39
[info
->control
.hw_key
->hw_key_idx
].keyinfo
;
2214 switch (keyinfo
->alg
) {
2216 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_CCM
;
2217 memcpy(cmd
->cmd
.tx
.key
, keyinfo
->key
, keyinfo
->keylen
);
2218 IWL_DEBUG_TX("tx_cmd with AES hwcrypto\n");
2223 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_TKIP
;
2226 memcpy(cmd
->cmd
.tx
.tkip_mic
.byte
, skb_frag
->tail
- 8,
2229 memset(cmd
->cmd
.tx
.tkip_mic
.byte
, 0, 8);
2234 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_WEP
|
2235 (info
->control
.hw_key
->hw_key_idx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
;
2237 if (keyinfo
->keylen
== 13)
2238 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
2240 memcpy(&cmd
->cmd
.tx
.key
[3], keyinfo
->key
, keyinfo
->keylen
);
2242 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2243 "with key %d\n", info
->control
.hw_key
->hw_key_idx
);
2247 IWL_ERR(priv
, "Unknown encode alg %d\n", keyinfo
->alg
);
2253 * handle build REPLY_TX command notification.
2255 static void iwl3945_build_tx_cmd_basic(struct iwl_priv
*priv
,
2256 struct iwl_cmd
*cmd
,
2257 struct ieee80211_tx_info
*info
,
2258 struct ieee80211_hdr
*hdr
,
2259 int is_unicast
, u8 std_id
)
2261 __le16 fc
= hdr
->frame_control
;
2262 __le32 tx_flags
= cmd
->cmd
.tx
.tx_flags
;
2263 u8 rc_flags
= info
->control
.rates
[0].flags
;
2265 cmd
->cmd
.tx
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
2266 if (!(info
->flags
& IEEE80211_TX_CTL_NO_ACK
)) {
2267 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
2268 if (ieee80211_is_mgmt(fc
))
2269 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2270 if (ieee80211_is_probe_resp(fc
) &&
2271 !(le16_to_cpu(hdr
->seq_ctrl
) & 0xf))
2272 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
2274 tx_flags
&= (~TX_CMD_FLG_ACK_MSK
);
2275 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2278 cmd
->cmd
.tx
.sta_id
= std_id
;
2279 if (ieee80211_has_morefrags(fc
))
2280 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
2282 if (ieee80211_is_data_qos(fc
)) {
2283 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
2284 cmd
->cmd
.tx
.tid_tspec
= qc
[0] & 0xf;
2285 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL_MSK
;
2287 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2290 if (rc_flags
& IEEE80211_TX_RC_USE_RTS_CTS
) {
2291 tx_flags
|= TX_CMD_FLG_RTS_MSK
;
2292 tx_flags
&= ~TX_CMD_FLG_CTS_MSK
;
2293 } else if (rc_flags
& IEEE80211_TX_RC_USE_CTS_PROTECT
) {
2294 tx_flags
&= ~TX_CMD_FLG_RTS_MSK
;
2295 tx_flags
|= TX_CMD_FLG_CTS_MSK
;
2298 if ((tx_flags
& TX_CMD_FLG_RTS_MSK
) || (tx_flags
& TX_CMD_FLG_CTS_MSK
))
2299 tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
2301 tx_flags
&= ~(TX_CMD_FLG_ANT_SEL_MSK
);
2302 if (ieee80211_is_mgmt(fc
)) {
2303 if (ieee80211_is_assoc_req(fc
) || ieee80211_is_reassoc_req(fc
))
2304 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(3);
2306 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(2);
2308 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= 0;
2309 #ifdef CONFIG_IWL3945_LEDS
2310 priv
->rxtxpackets
+= le16_to_cpu(cmd
->cmd
.tx
.len
);
2314 cmd
->cmd
.tx
.driver_txop
= 0;
2315 cmd
->cmd
.tx
.tx_flags
= tx_flags
;
2316 cmd
->cmd
.tx
.next_frame_len
= 0;
2320 * iwl3945_get_sta_id - Find station's index within station table
2322 static int iwl3945_get_sta_id(struct iwl_priv
*priv
, struct ieee80211_hdr
*hdr
)
2325 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2327 /* If this frame is broadcast or management, use broadcast station id */
2328 if (((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
) ||
2329 is_multicast_ether_addr(hdr
->addr1
))
2330 return priv
->hw_params
.bcast_sta_id
;
2332 switch (priv
->iw_mode
) {
2334 /* If we are a client station in a BSS network, use the special
2335 * AP station entry (that's the only station we communicate with) */
2336 case NL80211_IFTYPE_STATION
:
2339 /* If we are an AP, then find the station, or use BCAST */
2340 case NL80211_IFTYPE_AP
:
2341 sta_id
= iwl3945_hw_find_station(priv
, hdr
->addr1
);
2342 if (sta_id
!= IWL_INVALID_STATION
)
2344 return priv
->hw_params
.bcast_sta_id
;
2346 /* If this frame is going out to an IBSS network, find the station,
2347 * or create a new station table entry */
2348 case NL80211_IFTYPE_ADHOC
: {
2349 /* Create new station table entry */
2350 sta_id
= iwl3945_hw_find_station(priv
, hdr
->addr1
);
2351 if (sta_id
!= IWL_INVALID_STATION
)
2354 sta_id
= iwl3945_add_station(priv
, hdr
->addr1
, 0, CMD_ASYNC
);
2356 if (sta_id
!= IWL_INVALID_STATION
)
2359 IWL_DEBUG_DROP("Station %pM not in station map. "
2360 "Defaulting to broadcast...\n",
2362 iwl_print_hex_dump(priv
, IWL_DL_DROP
, (u8
*) hdr
, sizeof(*hdr
));
2363 return priv
->hw_params
.bcast_sta_id
;
2365 /* If we are in monitor mode, use BCAST. This is required for
2366 * packet injection. */
2367 case NL80211_IFTYPE_MONITOR
:
2368 return priv
->hw_params
.bcast_sta_id
;
2371 IWL_WARN(priv
, "Unknown mode of operation: %d\n",
2373 return priv
->hw_params
.bcast_sta_id
;
2378 * start REPLY_TX command process
2380 static int iwl3945_tx_skb(struct iwl_priv
*priv
, struct sk_buff
*skb
)
2382 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2383 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
2384 struct iwl3945_tfd_frame
*tfd
;
2386 int txq_id
= skb_get_queue_mapping(skb
);
2387 struct iwl3945_tx_queue
*txq
= NULL
;
2388 struct iwl_queue
*q
= NULL
;
2389 dma_addr_t phys_addr
;
2390 dma_addr_t txcmd_phys
;
2391 struct iwl_cmd
*out_cmd
= NULL
;
2392 u16 len
, idx
, len_org
, hdr_len
;
2399 u8 wait_write_ptr
= 0;
2401 unsigned long flags
;
2404 spin_lock_irqsave(&priv
->lock
, flags
);
2405 if (iwl3945_is_rfkill(priv
)) {
2406 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2410 if ((ieee80211_get_tx_rate(priv
->hw
, info
)->hw_value
& 0xFF) == IWL_INVALID_RATE
) {
2411 IWL_ERR(priv
, "ERROR: No TX rate available.\n");
2415 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
2418 fc
= hdr
->frame_control
;
2420 #ifdef CONFIG_IWL3945_DEBUG
2421 if (ieee80211_is_auth(fc
))
2422 IWL_DEBUG_TX("Sending AUTH frame\n");
2423 else if (ieee80211_is_assoc_req(fc
))
2424 IWL_DEBUG_TX("Sending ASSOC frame\n");
2425 else if (ieee80211_is_reassoc_req(fc
))
2426 IWL_DEBUG_TX("Sending REASSOC frame\n");
2429 /* drop all data frame if we are not associated */
2430 if (ieee80211_is_data(fc
) &&
2431 (priv
->iw_mode
!= NL80211_IFTYPE_MONITOR
) && /* packet injection */
2432 (!iwl3945_is_associated(priv
) ||
2433 ((priv
->iw_mode
== NL80211_IFTYPE_STATION
) && !priv
->assoc_id
))) {
2434 IWL_DEBUG_DROP("Dropping - !iwl3945_is_associated\n");
2438 spin_unlock_irqrestore(&priv
->lock
, flags
);
2440 hdr_len
= ieee80211_hdrlen(fc
);
2442 /* Find (or create) index into station table for destination station */
2443 sta_id
= iwl3945_get_sta_id(priv
, hdr
);
2444 if (sta_id
== IWL_INVALID_STATION
) {
2445 IWL_DEBUG_DROP("Dropping - INVALID STATION: %pM\n",
2450 IWL_DEBUG_RATE("station Id %d\n", sta_id
);
2452 if (ieee80211_is_data_qos(fc
)) {
2453 qc
= ieee80211_get_qos_ctl(hdr
);
2454 tid
= qc
[0] & IEEE80211_QOS_CTL_TID_MASK
;
2455 seq_number
= priv
->stations_39
[sta_id
].tid
[tid
].seq_number
&
2457 hdr
->seq_ctrl
= cpu_to_le16(seq_number
) |
2459 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG
));
2463 /* Descriptor for chosen Tx queue */
2464 txq
= &priv
->txq39
[txq_id
];
2467 spin_lock_irqsave(&priv
->lock
, flags
);
2469 /* Set up first empty TFD within this queue's circular TFD buffer */
2470 tfd
= &txq
->bd
[q
->write_ptr
];
2471 memset(tfd
, 0, sizeof(*tfd
));
2472 control_flags
= (u32
*) tfd
;
2473 idx
= get_cmd_index(q
, q
->write_ptr
, 0);
2475 /* Set up driver data for this TFD */
2476 memset(&(txq
->txb
[q
->write_ptr
]), 0, sizeof(struct iwl3945_tx_info
));
2477 txq
->txb
[q
->write_ptr
].skb
[0] = skb
;
2479 /* Init first empty entry in queue's array of Tx/cmd buffers */
2480 out_cmd
= &txq
->cmd
[idx
];
2481 memset(&out_cmd
->hdr
, 0, sizeof(out_cmd
->hdr
));
2482 memset(&out_cmd
->cmd
.tx
, 0, sizeof(out_cmd
->cmd
.tx
));
2485 * Set up the Tx-command (not MAC!) header.
2486 * Store the chosen Tx queue and TFD index within the sequence field;
2487 * after Tx, uCode's Tx response will return this value so driver can
2488 * locate the frame within the tx queue and do post-tx processing.
2490 out_cmd
->hdr
.cmd
= REPLY_TX
;
2491 out_cmd
->hdr
.sequence
= cpu_to_le16((u16
)(QUEUE_TO_SEQ(txq_id
) |
2492 INDEX_TO_SEQ(q
->write_ptr
)));
2494 /* Copy MAC header from skb into command buffer */
2495 memcpy(out_cmd
->cmd
.tx
.hdr
, hdr
, hdr_len
);
2498 * Use the first empty entry in this queue's command buffer array
2499 * to contain the Tx command and MAC header concatenated together
2500 * (payload data will be in another buffer).
2501 * Size of this varies, due to varying MAC header length.
2502 * If end is not dword aligned, we'll have 2 extra bytes at the end
2503 * of the MAC header (device reads on dword boundaries).
2504 * We'll tell device about this padding later.
2506 len
= sizeof(struct iwl3945_tx_cmd
) +
2507 sizeof(struct iwl_cmd_header
) + hdr_len
;
2510 len
= (len
+ 3) & ~3;
2517 /* Physical address of this Tx command's header (not MAC header!),
2518 * within command buffer array. */
2519 txcmd_phys
= txq
->dma_addr_cmd
+ sizeof(struct iwl_cmd
) * idx
+
2520 offsetof(struct iwl_cmd
, hdr
);
2522 /* Add buffer containing Tx command and MAC(!) header to TFD's
2524 iwl3945_hw_txq_attach_buf_to_tfd(priv
, tfd
, txcmd_phys
, len
);
2526 if (info
->control
.hw_key
)
2527 iwl3945_build_tx_cmd_hwcrypto(priv
, info
, out_cmd
, skb
, 0);
2529 /* Set up TFD's 2nd entry to point directly to remainder of skb,
2530 * if any (802.11 null frames have no payload). */
2531 len
= skb
->len
- hdr_len
;
2533 phys_addr
= pci_map_single(priv
->pci_dev
, skb
->data
+ hdr_len
,
2534 len
, PCI_DMA_TODEVICE
);
2535 iwl3945_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, len
);
2539 /* If there is no payload, then we use only one Tx buffer */
2540 *control_flags
= TFD_CTL_COUNT_SET(1);
2542 /* Else use 2 buffers.
2543 * Tell 3945 about any padding after MAC header */
2544 *control_flags
= TFD_CTL_COUNT_SET(2) |
2545 TFD_CTL_PAD_SET(U32_PAD(len
));
2547 /* Total # bytes to be transmitted */
2548 len
= (u16
)skb
->len
;
2549 out_cmd
->cmd
.tx
.len
= cpu_to_le16(len
);
2551 /* TODO need this for burst mode later on */
2552 iwl3945_build_tx_cmd_basic(priv
, out_cmd
, info
, hdr
, unicast
, sta_id
);
2554 /* set is_hcca to 0; it probably will never be implemented */
2555 iwl3945_hw_build_tx_cmd_rate(priv
, out_cmd
, info
, hdr
, sta_id
, 0);
2557 out_cmd
->cmd
.tx
.tx_flags
&= ~TX_CMD_FLG_ANT_A_MSK
;
2558 out_cmd
->cmd
.tx
.tx_flags
&= ~TX_CMD_FLG_ANT_B_MSK
;
2560 if (!ieee80211_has_morefrags(hdr
->frame_control
)) {
2561 txq
->need_update
= 1;
2563 priv
->stations_39
[sta_id
].tid
[tid
].seq_number
= seq_number
;
2566 txq
->need_update
= 0;
2569 iwl_print_hex_dump(priv
, IWL_DL_TX
, out_cmd
->cmd
.payload
,
2570 sizeof(out_cmd
->cmd
.tx
));
2572 iwl_print_hex_dump(priv
, IWL_DL_TX
, (u8
*)out_cmd
->cmd
.tx
.hdr
,
2573 ieee80211_hdrlen(fc
));
2575 /* Tell device the write index *just past* this latest filled TFD */
2576 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
2577 rc
= iwl3945_tx_queue_update_write_ptr(priv
, txq
);
2578 spin_unlock_irqrestore(&priv
->lock
, flags
);
2583 if ((iwl_queue_space(q
) < q
->high_mark
)
2584 && priv
->mac80211_registered
) {
2585 if (wait_write_ptr
) {
2586 spin_lock_irqsave(&priv
->lock
, flags
);
2587 txq
->need_update
= 1;
2588 iwl3945_tx_queue_update_write_ptr(priv
, txq
);
2589 spin_unlock_irqrestore(&priv
->lock
, flags
);
2592 ieee80211_stop_queue(priv
->hw
, skb_get_queue_mapping(skb
));
2598 spin_unlock_irqrestore(&priv
->lock
, flags
);
2603 static void iwl3945_set_rate(struct iwl_priv
*priv
)
2605 const struct ieee80211_supported_band
*sband
= NULL
;
2606 struct ieee80211_rate
*rate
;
2609 sband
= iwl3945_get_band(priv
, priv
->band
);
2611 IWL_ERR(priv
, "Failed to set rate: unable to get hw mode\n");
2615 priv
->active_rate
= 0;
2616 priv
->active_rate_basic
= 0;
2618 IWL_DEBUG_RATE("Setting rates for %s GHz\n",
2619 sband
->band
== IEEE80211_BAND_2GHZ
? "2.4" : "5");
2621 for (i
= 0; i
< sband
->n_bitrates
; i
++) {
2622 rate
= &sband
->bitrates
[i
];
2623 if ((rate
->hw_value
< IWL_RATE_COUNT
) &&
2624 !(rate
->flags
& IEEE80211_CHAN_DISABLED
)) {
2625 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)\n",
2626 rate
->hw_value
, iwl3945_rates
[rate
->hw_value
].plcp
);
2627 priv
->active_rate
|= (1 << rate
->hw_value
);
2631 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2632 priv
->active_rate
, priv
->active_rate_basic
);
2635 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2636 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2639 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
2640 priv
->staging39_rxon
.cck_basic_rates
=
2641 ((priv
->active_rate_basic
&
2642 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
2644 priv
->staging39_rxon
.cck_basic_rates
=
2645 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2647 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
2648 priv
->staging39_rxon
.ofdm_basic_rates
=
2649 ((priv
->active_rate_basic
&
2650 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
2651 IWL_FIRST_OFDM_RATE
) & 0xFF;
2653 priv
->staging39_rxon
.ofdm_basic_rates
=
2654 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2657 static void iwl3945_radio_kill_sw(struct iwl_priv
*priv
, int disable_radio
)
2659 unsigned long flags
;
2661 if (!!disable_radio
== test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
2664 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2665 disable_radio
? "OFF" : "ON");
2667 if (disable_radio
) {
2668 iwl3945_scan_cancel(priv
);
2669 /* FIXME: This is a workaround for AP */
2670 if (priv
->iw_mode
!= NL80211_IFTYPE_AP
) {
2671 spin_lock_irqsave(&priv
->lock
, flags
);
2672 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
2673 CSR_UCODE_SW_BIT_RFKILL
);
2674 spin_unlock_irqrestore(&priv
->lock
, flags
);
2675 iwl3945_send_card_state(priv
, CARD_STATE_CMD_DISABLE
, 0);
2676 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2681 spin_lock_irqsave(&priv
->lock
, flags
);
2682 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2684 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2685 spin_unlock_irqrestore(&priv
->lock
, flags
);
2690 spin_lock_irqsave(&priv
->lock
, flags
);
2691 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
2692 if (!iwl_grab_nic_access(priv
))
2693 iwl_release_nic_access(priv
);
2694 spin_unlock_irqrestore(&priv
->lock
, flags
);
2696 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
2697 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2698 "disabled by HW switch\n");
2703 queue_work(priv
->workqueue
, &priv
->restart
);
2707 void iwl3945_set_decrypted_flag(struct iwl_priv
*priv
, struct sk_buff
*skb
,
2708 u32 decrypt_res
, struct ieee80211_rx_status
*stats
)
2711 le16_to_cpu(((struct ieee80211_hdr
*)skb
->data
)->frame_control
);
2713 if (priv
->active39_rxon
.filter_flags
& RXON_FILTER_DIS_DECRYPT_MSK
)
2716 if (!(fc
& IEEE80211_FCTL_PROTECTED
))
2719 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res
);
2720 switch (decrypt_res
& RX_RES_STATUS_SEC_TYPE_MSK
) {
2721 case RX_RES_STATUS_SEC_TYPE_TKIP
:
2722 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2723 RX_RES_STATUS_BAD_ICV_MIC
)
2724 stats
->flag
|= RX_FLAG_MMIC_ERROR
;
2725 case RX_RES_STATUS_SEC_TYPE_WEP
:
2726 case RX_RES_STATUS_SEC_TYPE_CCMP
:
2727 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2728 RX_RES_STATUS_DECRYPT_OK
) {
2729 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2730 stats
->flag
|= RX_FLAG_DECRYPTED
;
2739 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
2741 #include "iwl-spectrum.h"
2743 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
2744 #define BEACON_TIME_MASK_HIGH 0xFF000000
2745 #define TIME_UNIT 1024
2748 * extended beacon time format
2749 * time in usec will be changed into a 32-bit value in 8:24 format
2750 * the high 1 byte is the beacon counts
2751 * the lower 3 bytes is the time in usec within one beacon interval
2754 static u32
iwl3945_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
2758 u32 interval
= beacon_interval
* 1024;
2760 if (!interval
|| !usec
)
2763 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
2764 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
2766 return (quot
<< 24) + rem
;
2769 /* base is usually what we get from ucode with each received frame,
2770 * the same as HW timer counter counting down
2773 static __le32
iwl3945_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
2775 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
2776 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
2777 u32 interval
= beacon_interval
* TIME_UNIT
;
2778 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
2779 (addon
& BEACON_TIME_MASK_HIGH
);
2781 if (base_low
> addon_low
)
2782 res
+= base_low
- addon_low
;
2783 else if (base_low
< addon_low
) {
2784 res
+= interval
+ base_low
- addon_low
;
2789 return cpu_to_le32(res
);
2792 static int iwl3945_get_measurement(struct iwl_priv
*priv
,
2793 struct ieee80211_measurement_params
*params
,
2796 struct iwl_spectrum_cmd spectrum
;
2797 struct iwl_rx_packet
*res
;
2798 struct iwl_host_cmd cmd
= {
2799 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
2800 .data
= (void *)&spectrum
,
2801 .meta
.flags
= CMD_WANT_SKB
,
2803 u32 add_time
= le64_to_cpu(params
->start_time
);
2805 int spectrum_resp_status
;
2806 int duration
= le16_to_cpu(params
->duration
);
2808 if (iwl3945_is_associated(priv
))
2810 iwl3945_usecs_to_beacons(
2811 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
2812 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2814 memset(&spectrum
, 0, sizeof(spectrum
));
2816 spectrum
.channel_count
= cpu_to_le16(1);
2818 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
2819 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
2820 cmd
.len
= sizeof(spectrum
);
2821 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
2823 if (iwl3945_is_associated(priv
))
2824 spectrum
.start_time
=
2825 iwl3945_add_beacon_time(priv
->last_beacon_time
,
2827 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2829 spectrum
.start_time
= 0;
2831 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
2832 spectrum
.channels
[0].channel
= params
->channel
;
2833 spectrum
.channels
[0].type
= type
;
2834 if (priv
->active39_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
2835 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
2836 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
2838 rc
= iwl3945_send_cmd_sync(priv
, &cmd
);
2842 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
2843 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
2844 IWL_ERR(priv
, "Bad return from REPLY_RX_ON_ASSOC command\n");
2848 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
2849 switch (spectrum_resp_status
) {
2850 case 0: /* Command will be handled */
2851 if (res
->u
.spectrum
.id
!= 0xff) {
2852 IWL_DEBUG_INFO("Replaced existing measurement: %d\n",
2853 res
->u
.spectrum
.id
);
2854 priv
->measurement_status
&= ~MEASUREMENT_READY
;
2856 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
2860 case 1: /* Command will not be handled */
2865 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
2871 static void iwl3945_rx_reply_alive(struct iwl_priv
*priv
,
2872 struct iwl_rx_mem_buffer
*rxb
)
2874 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2875 struct iwl_alive_resp
*palive
;
2876 struct delayed_work
*pwork
;
2878 palive
= &pkt
->u
.alive_frame
;
2880 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
2882 palive
->is_valid
, palive
->ver_type
,
2883 palive
->ver_subtype
);
2885 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
2886 IWL_DEBUG_INFO("Initialization Alive received.\n");
2887 memcpy(&priv
->card_alive_init
, &pkt
->u
.alive_frame
,
2888 sizeof(struct iwl_alive_resp
));
2889 pwork
= &priv
->init_alive_start
;
2891 IWL_DEBUG_INFO("Runtime Alive received.\n");
2892 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
2893 sizeof(struct iwl_alive_resp
));
2894 pwork
= &priv
->alive_start
;
2895 iwl3945_disable_events(priv
);
2898 /* We delay the ALIVE response by 5ms to
2899 * give the HW RF Kill time to activate... */
2900 if (palive
->is_valid
== UCODE_VALID_OK
)
2901 queue_delayed_work(priv
->workqueue
, pwork
,
2902 msecs_to_jiffies(5));
2904 IWL_WARN(priv
, "uCode did not respond OK.\n");
2907 static void iwl3945_rx_reply_add_sta(struct iwl_priv
*priv
,
2908 struct iwl_rx_mem_buffer
*rxb
)
2910 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2912 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt
->u
.status
);
2916 static void iwl3945_rx_reply_error(struct iwl_priv
*priv
,
2917 struct iwl_rx_mem_buffer
*rxb
)
2919 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2921 IWL_ERR(priv
, "Error Reply type 0x%08X cmd %s (0x%02X) "
2922 "seq 0x%04X ser 0x%08X\n",
2923 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
2924 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
2925 pkt
->u
.err_resp
.cmd_id
,
2926 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
2927 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
2930 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2932 static void iwl3945_rx_csa(struct iwl_priv
*priv
, struct iwl_rx_mem_buffer
*rxb
)
2934 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2935 struct iwl3945_rxon_cmd
*rxon
= (void *)&priv
->active39_rxon
;
2936 struct iwl_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
2937 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
2938 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
2939 rxon
->channel
= csa
->channel
;
2940 priv
->staging39_rxon
.channel
= csa
->channel
;
2943 static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv
*priv
,
2944 struct iwl_rx_mem_buffer
*rxb
)
2946 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
2947 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2948 struct iwl_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
2950 if (!report
->state
) {
2951 IWL_DEBUG(IWL_DL_11H
| IWL_DL_INFO
,
2952 "Spectrum Measure Notification: Start\n");
2956 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
2957 priv
->measurement_status
|= MEASUREMENT_READY
;
2961 static void iwl3945_rx_pm_sleep_notif(struct iwl_priv
*priv
,
2962 struct iwl_rx_mem_buffer
*rxb
)
2964 #ifdef CONFIG_IWL3945_DEBUG
2965 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2966 struct iwl_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
2967 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
2968 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
2972 static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv
*priv
,
2973 struct iwl_rx_mem_buffer
*rxb
)
2975 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2976 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
2977 "notification for %s:\n",
2978 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
2979 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, pkt
->u
.raw
,
2980 le32_to_cpu(pkt
->len
));
2983 static void iwl3945_bg_beacon_update(struct work_struct
*work
)
2985 struct iwl_priv
*priv
=
2986 container_of(work
, struct iwl_priv
, beacon_update
);
2987 struct sk_buff
*beacon
;
2989 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
2990 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
);
2993 IWL_ERR(priv
, "update beacon failed\n");
2997 mutex_lock(&priv
->mutex
);
2998 /* new beacon skb is allocated every time; dispose previous.*/
2999 if (priv
->ibss_beacon
)
3000 dev_kfree_skb(priv
->ibss_beacon
);
3002 priv
->ibss_beacon
= beacon
;
3003 mutex_unlock(&priv
->mutex
);
3005 iwl3945_send_beacon_cmd(priv
);
3008 static void iwl3945_rx_beacon_notif(struct iwl_priv
*priv
,
3009 struct iwl_rx_mem_buffer
*rxb
)
3011 #ifdef CONFIG_IWL3945_DEBUG
3012 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3013 struct iwl3945_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
3014 u8 rate
= beacon
->beacon_notify_hdr
.rate
;
3016 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3017 "tsf %d %d rate %d\n",
3018 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
3019 beacon
->beacon_notify_hdr
.failure_frame
,
3020 le32_to_cpu(beacon
->ibss_mgr_status
),
3021 le32_to_cpu(beacon
->high_tsf
),
3022 le32_to_cpu(beacon
->low_tsf
), rate
);
3025 if ((priv
->iw_mode
== NL80211_IFTYPE_AP
) &&
3026 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
3027 queue_work(priv
->workqueue
, &priv
->beacon_update
);
3030 /* Service response to REPLY_SCAN_CMD (0x80) */
3031 static void iwl3945_rx_reply_scan(struct iwl_priv
*priv
,
3032 struct iwl_rx_mem_buffer
*rxb
)
3034 #ifdef CONFIG_IWL3945_DEBUG
3035 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3036 struct iwl_scanreq_notification
*notif
=
3037 (struct iwl_scanreq_notification
*)pkt
->u
.raw
;
3039 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
3043 /* Service SCAN_START_NOTIFICATION (0x82) */
3044 static void iwl3945_rx_scan_start_notif(struct iwl_priv
*priv
,
3045 struct iwl_rx_mem_buffer
*rxb
)
3047 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3048 struct iwl_scanstart_notification
*notif
=
3049 (struct iwl_scanstart_notification
*)pkt
->u
.raw
;
3050 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
3051 IWL_DEBUG_SCAN("Scan start: "
3053 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3055 notif
->band
? "bg" : "a",
3057 notif
->tsf_low
, notif
->status
, notif
->beacon_timer
);
3060 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3061 static void iwl3945_rx_scan_results_notif(struct iwl_priv
*priv
,
3062 struct iwl_rx_mem_buffer
*rxb
)
3064 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3065 struct iwl_scanresults_notification
*notif
=
3066 (struct iwl_scanresults_notification
*)pkt
->u
.raw
;
3068 IWL_DEBUG_SCAN("Scan ch.res: "
3070 "(TSF: 0x%08X:%08X) - %d "
3071 "elapsed=%lu usec (%dms since last)\n",
3073 notif
->band
? "bg" : "a",
3074 le32_to_cpu(notif
->tsf_high
),
3075 le32_to_cpu(notif
->tsf_low
),
3076 le32_to_cpu(notif
->statistics
[0]),
3077 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
3078 jiffies_to_msecs(elapsed_jiffies
3079 (priv
->last_scan_jiffies
, jiffies
)));
3081 priv
->last_scan_jiffies
= jiffies
;
3082 priv
->next_scan_jiffies
= 0;
3085 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
3086 static void iwl3945_rx_scan_complete_notif(struct iwl_priv
*priv
,
3087 struct iwl_rx_mem_buffer
*rxb
)
3089 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3090 struct iwl_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
3092 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3093 scan_notif
->scanned_channels
,
3094 scan_notif
->tsf_low
,
3095 scan_notif
->tsf_high
, scan_notif
->status
);
3097 /* The HW is no longer scanning */
3098 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
3100 /* The scan completion notification came in, so kill that timer... */
3101 cancel_delayed_work(&priv
->scan_check
);
3103 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3104 (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
)) ?
3106 jiffies_to_msecs(elapsed_jiffies
3107 (priv
->scan_pass_start
, jiffies
)));
3109 /* Remove this scanned band from the list of pending
3110 * bands to scan, band G precedes A in order of scanning
3111 * as seen in iwl3945_bg_request_scan */
3112 if (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
))
3113 priv
->scan_bands
&= ~BIT(IEEE80211_BAND_2GHZ
);
3114 else if (priv
->scan_bands
& BIT(IEEE80211_BAND_5GHZ
))
3115 priv
->scan_bands
&= ~BIT(IEEE80211_BAND_5GHZ
);
3117 /* If a request to abort was given, or the scan did not succeed
3118 * then we reset the scan state machine and terminate,
3119 * re-queuing another scan if one has been requested */
3120 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
3121 IWL_DEBUG_INFO("Aborted scan completed.\n");
3122 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
3124 /* If there are more bands on this scan pass reschedule */
3125 if (priv
->scan_bands
> 0)
3129 priv
->last_scan_jiffies
= jiffies
;
3130 priv
->next_scan_jiffies
= 0;
3131 IWL_DEBUG_INFO("Setting scan to off\n");
3133 clear_bit(STATUS_SCANNING
, &priv
->status
);
3135 IWL_DEBUG_INFO("Scan took %dms\n",
3136 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
3138 queue_work(priv
->workqueue
, &priv
->scan_completed
);
3143 priv
->scan_pass_start
= jiffies
;
3144 queue_work(priv
->workqueue
, &priv
->request_scan
);
3147 /* Handle notification from uCode that card's power state is changing
3148 * due to software, hardware, or critical temperature RFKILL */
3149 static void iwl3945_rx_card_state_notif(struct iwl_priv
*priv
,
3150 struct iwl_rx_mem_buffer
*rxb
)
3152 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3153 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
3154 unsigned long status
= priv
->status
;
3156 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3157 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
3158 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
3160 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3161 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3163 if (flags
& HW_CARD_DISABLED
)
3164 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3166 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3169 if (flags
& SW_CARD_DISABLED
)
3170 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3172 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3174 iwl3945_scan_cancel(priv
);
3176 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
3177 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
3178 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
3179 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
3180 queue_work(priv
->workqueue
, &priv
->rf_kill
);
3182 wake_up_interruptible(&priv
->wait_command_queue
);
3186 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
3188 * Setup the RX handlers for each of the reply types sent from the uCode
3191 * This function chains into the hardware specific files for them to setup
3192 * any hardware specific handlers as well.
3194 static void iwl3945_setup_rx_handlers(struct iwl_priv
*priv
)
3196 priv
->rx_handlers
[REPLY_ALIVE
] = iwl3945_rx_reply_alive
;
3197 priv
->rx_handlers
[REPLY_ADD_STA
] = iwl3945_rx_reply_add_sta
;
3198 priv
->rx_handlers
[REPLY_ERROR
] = iwl3945_rx_reply_error
;
3199 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl3945_rx_csa
;
3200 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
3201 iwl3945_rx_spectrum_measure_notif
;
3202 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl3945_rx_pm_sleep_notif
;
3203 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
3204 iwl3945_rx_pm_debug_statistics_notif
;
3205 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl3945_rx_beacon_notif
;
3208 * The same handler is used for both the REPLY to a discrete
3209 * statistics request from the host as well as for the periodic
3210 * statistics notifications (after received beacons) from the uCode.
3212 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl3945_hw_rx_statistics
;
3213 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl3945_hw_rx_statistics
;
3215 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl3945_rx_reply_scan
;
3216 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl3945_rx_scan_start_notif
;
3217 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
3218 iwl3945_rx_scan_results_notif
;
3219 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
3220 iwl3945_rx_scan_complete_notif
;
3221 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl3945_rx_card_state_notif
;
3223 /* Set up hardware specific Rx handlers */
3224 iwl3945_hw_rx_handler_setup(priv
);
3228 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
3229 * When FW advances 'R' index, all entries between old and new 'R' index
3230 * need to be reclaimed.
3232 static void iwl3945_cmd_queue_reclaim(struct iwl_priv
*priv
,
3233 int txq_id
, int index
)
3235 struct iwl3945_tx_queue
*txq
= &priv
->txq39
[txq_id
];
3236 struct iwl_queue
*q
= &txq
->q
;
3239 if ((index
>= q
->n_bd
) || (iwl3945_x2_queue_used(q
, index
) == 0)) {
3240 IWL_ERR(priv
, "Read index for DMA queue txq id (%d), index %d, "
3241 "is out of range [0-%d] %d %d.\n", txq_id
,
3242 index
, q
->n_bd
, q
->write_ptr
, q
->read_ptr
);
3246 for (index
= iwl_queue_inc_wrap(index
, q
->n_bd
); q
->read_ptr
!= index
;
3247 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
)) {
3249 IWL_ERR(priv
, "HCMD skipped: index (%d) %d %d\n", index
,
3250 q
->write_ptr
, q
->read_ptr
);
3251 queue_work(priv
->workqueue
, &priv
->restart
);
3260 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3261 * @rxb: Rx buffer to reclaim
3263 * If an Rx buffer has an async callback associated with it the callback
3264 * will be executed. The attached skb (if present) will only be freed
3265 * if the callback returns 1
3267 static void iwl3945_tx_cmd_complete(struct iwl_priv
*priv
,
3268 struct iwl_rx_mem_buffer
*rxb
)
3270 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
3271 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3272 int txq_id
= SEQ_TO_QUEUE(sequence
);
3273 int index
= SEQ_TO_INDEX(sequence
);
3274 int huge
= !!(pkt
->hdr
.sequence
& SEQ_HUGE_FRAME
);
3276 struct iwl_cmd
*cmd
;
3278 BUG_ON(txq_id
!= IWL_CMD_QUEUE_NUM
);
3280 cmd_index
= get_cmd_index(&priv
->txq39
[IWL_CMD_QUEUE_NUM
].q
, index
, huge
);
3281 cmd
= &priv
->txq39
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_index
];
3283 /* Input error checking is done when commands are added to queue. */
3284 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
3285 cmd
->meta
.source
->u
.skb
= rxb
->skb
;
3287 } else if (cmd
->meta
.u
.callback
&&
3288 !cmd
->meta
.u
.callback(priv
, cmd
, rxb
->skb
))
3291 iwl3945_cmd_queue_reclaim(priv
, txq_id
, index
);
3293 if (!(cmd
->meta
.flags
& CMD_ASYNC
)) {
3294 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
3295 wake_up_interruptible(&priv
->wait_command_queue
);
3299 /************************** RX-FUNCTIONS ****************************/
3301 * Rx theory of operation
3303 * The host allocates 32 DMA target addresses and passes the host address
3304 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
3308 * The host/firmware share two index registers for managing the Rx buffers.
3310 * The READ index maps to the first position that the firmware may be writing
3311 * to -- the driver can read up to (but not including) this position and get
3313 * The READ index is managed by the firmware once the card is enabled.
3315 * The WRITE index maps to the last position the driver has read from -- the
3316 * position preceding WRITE is the last slot the firmware can place a packet.
3318 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
3321 * During initialization, the host sets up the READ queue position to the first
3322 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3324 * When the firmware places a packet in a buffer, it will advance the READ index
3325 * and fire the RX interrupt. The driver can then query the READ index and
3326 * process as many packets as possible, moving the WRITE index forward as it
3327 * resets the Rx queue buffers with new memory.
3329 * The management in the driver is as follows:
3330 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
3331 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
3332 * to replenish the iwl->rxq->rx_free.
3333 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
3334 * iwl->rxq is replenished and the READ INDEX is updated (updating the
3335 * 'processed' and 'read' driver indexes as well)
3336 * + A received packet is processed and handed to the kernel network stack,
3337 * detached from the iwl->rxq. The driver 'processed' index is updated.
3338 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
3339 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
3340 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
3341 * were enough free buffers and RX_STALLED is set it is cleared.
3346 * iwl3945_rx_queue_alloc() Allocates rx_free
3347 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
3348 * iwl3945_rx_queue_restock
3349 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
3350 * queue, updates firmware pointers, and updates
3351 * the WRITE index. If insufficient rx_free buffers
3352 * are available, schedules iwl3945_rx_replenish
3354 * -- enable interrupts --
3355 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
3356 * READ INDEX, detaching the SKB from the pool.
3357 * Moves the packet buffer from queue to rx_used.
3358 * Calls iwl3945_rx_queue_restock to refill any empty
3365 * iwl3945_rx_queue_space - Return number of free slots available in queue.
3367 static int iwl3945_rx_queue_space(const struct iwl_rx_queue
*q
)
3369 int s
= q
->read
- q
->write
;
3372 /* keep some buffer to not confuse full and empty queue */
3380 * iwl3945_rx_queue_update_write_ptr - Update the write pointer for the RX queue
3382 int iwl3945_rx_queue_update_write_ptr(struct iwl_priv
*priv
, struct iwl_rx_queue
*q
)
3386 unsigned long flags
;
3388 spin_lock_irqsave(&q
->lock
, flags
);
3390 if (q
->need_update
== 0)
3393 /* If power-saving is in use, make sure device is awake */
3394 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
3395 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3397 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
3398 iwl_set_bit(priv
, CSR_GP_CNTRL
,
3399 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
3403 rc
= iwl_grab_nic_access(priv
);
3407 /* Device expects a multiple of 8 */
3408 iwl_write_direct32(priv
, FH39_RSCSR_CHNL0_WPTR
,
3410 iwl_release_nic_access(priv
);
3412 /* Else device is assumed to be awake */
3414 /* Device expects a multiple of 8 */
3415 iwl_write32(priv
, FH39_RSCSR_CHNL0_WPTR
, q
->write
& ~0x7);
3421 spin_unlock_irqrestore(&q
->lock
, flags
);
3426 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
3428 static inline __le32
iwl3945_dma_addr2rbd_ptr(struct iwl_priv
*priv
,
3429 dma_addr_t dma_addr
)
3431 return cpu_to_le32((u32
)dma_addr
);
3435 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
3437 * If there are slots in the RX queue that need to be restocked,
3438 * and we have free pre-allocated buffers, fill the ranks as much
3439 * as we can, pulling from rx_free.
3441 * This moves the 'write' index forward to catch up with 'processed', and
3442 * also updates the memory address in the firmware to reference the new
3445 static int iwl3945_rx_queue_restock(struct iwl_priv
*priv
)
3447 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
3448 struct list_head
*element
;
3449 struct iwl_rx_mem_buffer
*rxb
;
3450 unsigned long flags
;
3453 spin_lock_irqsave(&rxq
->lock
, flags
);
3454 write
= rxq
->write
& ~0x7;
3455 while ((iwl3945_rx_queue_space(rxq
) > 0) && (rxq
->free_count
)) {
3456 /* Get next free Rx buffer, remove from free list */
3457 element
= rxq
->rx_free
.next
;
3458 rxb
= list_entry(element
, struct iwl_rx_mem_buffer
, list
);
3461 /* Point to Rx buffer via next RBD in circular buffer */
3462 rxq
->bd
[rxq
->write
] = iwl3945_dma_addr2rbd_ptr(priv
, rxb
->real_dma_addr
);
3463 rxq
->queue
[rxq
->write
] = rxb
;
3464 rxq
->write
= (rxq
->write
+ 1) & RX_QUEUE_MASK
;
3467 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3468 /* If the pre-allocated buffer pool is dropping low, schedule to
3470 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
3471 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
3474 /* If we've added more space for the firmware to place data, tell it.
3475 * Increment device's write pointer in multiples of 8. */
3476 if ((write
!= (rxq
->write
& ~0x7))
3477 || (abs(rxq
->write
- rxq
->read
) > 7)) {
3478 spin_lock_irqsave(&rxq
->lock
, flags
);
3479 rxq
->need_update
= 1;
3480 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3481 rc
= iwl3945_rx_queue_update_write_ptr(priv
, rxq
);
3490 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
3492 * When moving to rx_free an SKB is allocated for the slot.
3494 * Also restock the Rx queue via iwl3945_rx_queue_restock.
3495 * This is called as a scheduled work item (except for during initialization)
3497 static void iwl3945_rx_allocate(struct iwl_priv
*priv
)
3499 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
3500 struct list_head
*element
;
3501 struct iwl_rx_mem_buffer
*rxb
;
3502 unsigned long flags
;
3503 spin_lock_irqsave(&rxq
->lock
, flags
);
3504 while (!list_empty(&rxq
->rx_used
)) {
3505 element
= rxq
->rx_used
.next
;
3506 rxb
= list_entry(element
, struct iwl_rx_mem_buffer
, list
);
3508 /* Alloc a new receive buffer */
3510 alloc_skb(IWL_RX_BUF_SIZE
, __GFP_NOWARN
| GFP_ATOMIC
);
3512 if (net_ratelimit())
3513 IWL_CRIT(priv
, ": Can not allocate SKB buffers\n");
3514 /* We don't reschedule replenish work here -- we will
3515 * call the restock method and if it still needs
3516 * more buffers it will schedule replenish */
3520 /* If radiotap head is required, reserve some headroom here.
3521 * The physical head count is a variable rx_stats->phy_count.
3522 * We reserve 4 bytes here. Plus these extra bytes, the
3523 * headroom of the physical head should be enough for the
3524 * radiotap head that iwl3945 supported. See iwl3945_rt.
3526 skb_reserve(rxb
->skb
, 4);
3528 priv
->alloc_rxb_skb
++;
3531 /* Get physical address of RB/SKB */
3532 rxb
->real_dma_addr
=
3533 pci_map_single(priv
->pci_dev
, rxb
->skb
->data
,
3534 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
3535 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
3538 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3542 * this should be called while priv->lock is locked
3544 static void __iwl3945_rx_replenish(void *data
)
3546 struct iwl_priv
*priv
= data
;
3548 iwl3945_rx_allocate(priv
);
3549 iwl3945_rx_queue_restock(priv
);
3553 void iwl3945_rx_replenish(void *data
)
3555 struct iwl_priv
*priv
= data
;
3556 unsigned long flags
;
3558 iwl3945_rx_allocate(priv
);
3560 spin_lock_irqsave(&priv
->lock
, flags
);
3561 iwl3945_rx_queue_restock(priv
);
3562 spin_unlock_irqrestore(&priv
->lock
, flags
);
3565 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
3566 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
3567 * This free routine walks the list of POOL entries and if SKB is set to
3568 * non NULL it is unmapped and freed
3570 static void iwl3945_rx_queue_free(struct iwl_priv
*priv
, struct iwl_rx_queue
*rxq
)
3573 for (i
= 0; i
< RX_QUEUE_SIZE
+ RX_FREE_BUFFERS
; i
++) {
3574 if (rxq
->pool
[i
].skb
!= NULL
) {
3575 pci_unmap_single(priv
->pci_dev
,
3576 rxq
->pool
[i
].real_dma_addr
,
3577 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
3578 dev_kfree_skb(rxq
->pool
[i
].skb
);
3582 pci_free_consistent(priv
->pci_dev
, 4 * RX_QUEUE_SIZE
, rxq
->bd
,
3587 int iwl3945_rx_queue_alloc(struct iwl_priv
*priv
)
3589 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
3590 struct pci_dev
*dev
= priv
->pci_dev
;
3593 spin_lock_init(&rxq
->lock
);
3594 INIT_LIST_HEAD(&rxq
->rx_free
);
3595 INIT_LIST_HEAD(&rxq
->rx_used
);
3597 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
3598 rxq
->bd
= pci_alloc_consistent(dev
, 4 * RX_QUEUE_SIZE
, &rxq
->dma_addr
);
3602 /* Fill the rx_used queue with _all_ of the Rx buffers */
3603 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++)
3604 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3606 /* Set us so that we have processed and used all buffers, but have
3607 * not restocked the Rx queue with fresh buffers */
3608 rxq
->read
= rxq
->write
= 0;
3609 rxq
->free_count
= 0;
3610 rxq
->need_update
= 0;
3614 void iwl3945_rx_queue_reset(struct iwl_priv
*priv
, struct iwl_rx_queue
*rxq
)
3616 unsigned long flags
;
3618 spin_lock_irqsave(&rxq
->lock
, flags
);
3619 INIT_LIST_HEAD(&rxq
->rx_free
);
3620 INIT_LIST_HEAD(&rxq
->rx_used
);
3621 /* Fill the rx_used queue with _all_ of the Rx buffers */
3622 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++) {
3623 /* In the reset function, these buffers may have been allocated
3624 * to an SKB, so we need to unmap and free potential storage */
3625 if (rxq
->pool
[i
].skb
!= NULL
) {
3626 pci_unmap_single(priv
->pci_dev
,
3627 rxq
->pool
[i
].real_dma_addr
,
3628 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
3629 priv
->alloc_rxb_skb
--;
3630 dev_kfree_skb(rxq
->pool
[i
].skb
);
3631 rxq
->pool
[i
].skb
= NULL
;
3633 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3636 /* Set us so that we have processed and used all buffers, but have
3637 * not restocked the Rx queue with fresh buffers */
3638 rxq
->read
= rxq
->write
= 0;
3639 rxq
->free_count
= 0;
3640 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3643 /* Convert linear signal-to-noise ratio into dB */
3644 static u8 ratio2dB
[100] = {
3645 /* 0 1 2 3 4 5 6 7 8 9 */
3646 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
3647 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
3648 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
3649 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
3650 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
3651 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
3652 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
3653 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
3654 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
3655 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
3658 /* Calculates a relative dB value from a ratio of linear
3659 * (i.e. not dB) signal levels.
3660 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
3661 int iwl3945_calc_db_from_ratio(int sig_ratio
)
3663 /* 1000:1 or higher just report as 60 dB */
3664 if (sig_ratio
>= 1000)
3667 /* 100:1 or higher, divide by 10 and use table,
3668 * add 20 dB to make up for divide by 10 */
3669 if (sig_ratio
>= 100)
3670 return 20 + (int)ratio2dB
[sig_ratio
/10];
3672 /* We shouldn't see this */
3676 /* Use table for ratios 1:1 - 99:1 */
3677 return (int)ratio2dB
[sig_ratio
];
3680 #define PERFECT_RSSI (-20) /* dBm */
3681 #define WORST_RSSI (-95) /* dBm */
3682 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
3684 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
3685 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
3686 * about formulas used below. */
3687 int iwl3945_calc_sig_qual(int rssi_dbm
, int noise_dbm
)
3690 int degradation
= PERFECT_RSSI
- rssi_dbm
;
3692 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
3693 * as indicator; formula is (signal dbm - noise dbm).
3694 * SNR at or above 40 is a great signal (100%).
3695 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
3696 * Weakest usable signal is usually 10 - 15 dB SNR. */
3698 if (rssi_dbm
- noise_dbm
>= 40)
3700 else if (rssi_dbm
< noise_dbm
)
3702 sig_qual
= ((rssi_dbm
- noise_dbm
) * 5) / 2;
3704 /* Else use just the signal level.
3705 * This formula is a least squares fit of data points collected and
3706 * compared with a reference system that had a percentage (%) display
3707 * for signal quality. */
3709 sig_qual
= (100 * (RSSI_RANGE
* RSSI_RANGE
) - degradation
*
3710 (15 * RSSI_RANGE
+ 62 * degradation
)) /
3711 (RSSI_RANGE
* RSSI_RANGE
);
3715 else if (sig_qual
< 1)
3722 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
3724 * Uses the priv->rx_handlers callback function array to invoke
3725 * the appropriate handlers, including command responses,
3726 * frame-received notifications, and other notifications.
3728 static void iwl3945_rx_handle(struct iwl_priv
*priv
)
3730 struct iwl_rx_mem_buffer
*rxb
;
3731 struct iwl_rx_packet
*pkt
;
3732 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
3735 unsigned long flags
;
3739 /* uCode's read index (stored in shared DRAM) indicates the last Rx
3740 * buffer that the driver may process (last buffer filled by ucode). */
3741 r
= iwl3945_hw_get_rx_read(priv
);
3744 if (iwl3945_rx_queue_space(rxq
) > (RX_QUEUE_SIZE
/ 2))
3746 /* Rx interrupt, but nothing sent from uCode */
3748 IWL_DEBUG(IWL_DL_RX
| IWL_DL_ISR
, "r = %d, i = %d\n", r
, i
);
3751 rxb
= rxq
->queue
[i
];
3753 /* If an RXB doesn't have a Rx queue slot associated with it,
3754 * then a bug has been introduced in the queue refilling
3755 * routines -- catch it here */
3756 BUG_ON(rxb
== NULL
);
3758 rxq
->queue
[i
] = NULL
;
3760 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->real_dma_addr
,
3762 PCI_DMA_FROMDEVICE
);
3763 pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
3765 /* Reclaim a command buffer only if this packet is a response
3766 * to a (driver-originated) command.
3767 * If the packet (e.g. Rx frame) originated from uCode,
3768 * there is no command buffer to reclaim.
3769 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
3770 * but apparently a few don't get set; catch them here. */
3771 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
3772 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
3773 (pkt
->hdr
.cmd
!= REPLY_TX
);
3775 /* Based on type of command response or notification,
3776 * handle those that need handling via function in
3777 * rx_handlers table. See iwl3945_setup_rx_handlers() */
3778 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
3779 IWL_DEBUG(IWL_DL_HCMD
| IWL_DL_RX
| IWL_DL_ISR
,
3780 "r = %d, i = %d, %s, 0x%02x\n", r
, i
,
3781 get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
3782 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
3784 /* No handling needed */
3785 IWL_DEBUG(IWL_DL_HCMD
| IWL_DL_RX
| IWL_DL_ISR
,
3786 "r %d i %d No handler needed for %s, 0x%02x\n",
3787 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
3792 /* Invoke any callbacks, transfer the skb to caller, and
3793 * fire off the (possibly) blocking iwl3945_send_cmd()
3794 * as we reclaim the driver command queue */
3795 if (rxb
&& rxb
->skb
)
3796 iwl3945_tx_cmd_complete(priv
, rxb
);
3798 IWL_WARN(priv
, "Claim null rxb?\n");
3801 /* For now we just don't re-use anything. We can tweak this
3802 * later to try and re-use notification packets and SKBs that
3803 * fail to Rx correctly */
3804 if (rxb
->skb
!= NULL
) {
3805 priv
->alloc_rxb_skb
--;
3806 dev_kfree_skb_any(rxb
->skb
);
3810 pci_unmap_single(priv
->pci_dev
, rxb
->real_dma_addr
,
3811 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
3812 spin_lock_irqsave(&rxq
->lock
, flags
);
3813 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
3814 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3815 i
= (i
+ 1) & RX_QUEUE_MASK
;
3816 /* If there are a lot of unused frames,
3817 * restock the Rx queue so ucode won't assert. */
3822 __iwl3945_rx_replenish(priv
);
3828 /* Backtrack one entry */
3830 iwl3945_rx_queue_restock(priv
);
3834 * iwl3945_tx_queue_update_write_ptr - Send new write index to hardware
3836 static int iwl3945_tx_queue_update_write_ptr(struct iwl_priv
*priv
,
3837 struct iwl3945_tx_queue
*txq
)
3841 int txq_id
= txq
->q
.id
;
3843 if (txq
->need_update
== 0)
3846 /* if we're trying to save power */
3847 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
3848 /* wake up nic if it's powered down ...
3849 * uCode will wake up, and interrupt us again, so next
3850 * time we'll skip this part. */
3851 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3853 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
3854 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg
);
3855 iwl_set_bit(priv
, CSR_GP_CNTRL
,
3856 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
3860 /* restore this queue's parameters in nic hardware. */
3861 rc
= iwl_grab_nic_access(priv
);
3864 iwl_write_direct32(priv
, HBUS_TARG_WRPTR
,
3865 txq
->q
.write_ptr
| (txq_id
<< 8));
3866 iwl_release_nic_access(priv
);
3868 /* else not in power-save mode, uCode will never sleep when we're
3869 * trying to tx (during RFKILL, we're not trying to tx). */
3871 iwl_write32(priv
, HBUS_TARG_WRPTR
,
3872 txq
->q
.write_ptr
| (txq_id
<< 8));
3874 txq
->need_update
= 0;
3879 #ifdef CONFIG_IWL3945_DEBUG
3880 static void iwl3945_print_rx_config_cmd(struct iwl_priv
*priv
,
3881 struct iwl3945_rxon_cmd
*rxon
)
3883 IWL_DEBUG_RADIO("RX CONFIG:\n");
3884 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
3885 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
3886 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
3887 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
3888 le32_to_cpu(rxon
->filter_flags
));
3889 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
3890 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
3891 rxon
->ofdm_basic_rates
);
3892 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
3893 IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon
->node_addr
);
3894 IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon
->bssid_addr
);
3895 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
3899 static void iwl3945_enable_interrupts(struct iwl_priv
*priv
)
3901 IWL_DEBUG_ISR("Enabling interrupts\n");
3902 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
3903 iwl_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
3907 /* call this function to flush any scheduled tasklet */
3908 static inline void iwl_synchronize_irq(struct iwl_priv
*priv
)
3910 /* wait to make sure we flush pending tasklet*/
3911 synchronize_irq(priv
->pci_dev
->irq
);
3912 tasklet_kill(&priv
->irq_tasklet
);
3916 static inline void iwl3945_disable_interrupts(struct iwl_priv
*priv
)
3918 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
3920 /* disable interrupts from uCode/NIC to host */
3921 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
3923 /* acknowledge/clear/reset any interrupts still pending
3924 * from uCode or flow handler (Rx/Tx DMA) */
3925 iwl_write32(priv
, CSR_INT
, 0xffffffff);
3926 iwl_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
3927 IWL_DEBUG_ISR("Disabled interrupts\n");
3930 static const char *desc_lookup(int i
)
3938 return "BAD_CHECKSUM";
3940 return "NMI_INTERRUPT";
3944 return "FATAL_ERROR";
3950 #define ERROR_START_OFFSET (1 * sizeof(u32))
3951 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
3953 static void iwl3945_dump_nic_error_log(struct iwl_priv
*priv
)
3956 u32 desc
, time
, count
, base
, data1
;
3957 u32 blink1
, blink2
, ilink1
, ilink2
;
3960 base
= le32_to_cpu(priv
->card_alive
.error_event_table_ptr
);
3962 if (!iwl3945_hw_valid_rtc_data_addr(base
)) {
3963 IWL_ERR(priv
, "Not valid error log pointer 0x%08X\n", base
);
3967 rc
= iwl_grab_nic_access(priv
);
3969 IWL_WARN(priv
, "Can not read from adapter at this time.\n");
3973 count
= iwl_read_targ_mem(priv
, base
);
3975 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
3976 IWL_ERR(priv
, "Start IWL Error Log Dump:\n");
3977 IWL_ERR(priv
, "Status: 0x%08lX, count: %d\n",
3978 priv
->status
, count
);
3981 IWL_ERR(priv
, "Desc Time asrtPC blink2 "
3982 "ilink1 nmiPC Line\n");
3983 for (i
= ERROR_START_OFFSET
;
3984 i
< (count
* ERROR_ELEM_SIZE
) + ERROR_START_OFFSET
;
3985 i
+= ERROR_ELEM_SIZE
) {
3986 desc
= iwl_read_targ_mem(priv
, base
+ i
);
3988 iwl_read_targ_mem(priv
, base
+ i
+ 1 * sizeof(u32
));
3990 iwl_read_targ_mem(priv
, base
+ i
+ 2 * sizeof(u32
));
3992 iwl_read_targ_mem(priv
, base
+ i
+ 3 * sizeof(u32
));
3994 iwl_read_targ_mem(priv
, base
+ i
+ 4 * sizeof(u32
));
3996 iwl_read_targ_mem(priv
, base
+ i
+ 5 * sizeof(u32
));
3998 iwl_read_targ_mem(priv
, base
+ i
+ 6 * sizeof(u32
));
4001 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
4002 desc_lookup(desc
), desc
, time
, blink1
, blink2
,
4003 ilink1
, ilink2
, data1
);
4006 iwl_release_nic_access(priv
);
4010 #define EVENT_START_OFFSET (6 * sizeof(u32))
4013 * iwl3945_print_event_log - Dump error event log to syslog
4015 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
4017 static void iwl3945_print_event_log(struct iwl_priv
*priv
, u32 start_idx
,
4018 u32 num_events
, u32 mode
)
4021 u32 base
; /* SRAM byte address of event log header */
4022 u32 event_size
; /* 2 u32s, or 3 u32s if timestamp recorded */
4023 u32 ptr
; /* SRAM byte address of log data */
4024 u32 ev
, time
, data
; /* event log data */
4026 if (num_events
== 0)
4029 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4032 event_size
= 2 * sizeof(u32
);
4034 event_size
= 3 * sizeof(u32
);
4036 ptr
= base
+ EVENT_START_OFFSET
+ (start_idx
* event_size
);
4038 /* "time" is actually "data" for mode 0 (no timestamp).
4039 * place event id # at far right for easier visual parsing. */
4040 for (i
= 0; i
< num_events
; i
++) {
4041 ev
= iwl_read_targ_mem(priv
, ptr
);
4043 time
= iwl_read_targ_mem(priv
, ptr
);
4047 IWL_ERR(priv
, "0x%08x\t%04u\n", time
, ev
);
4049 data
= iwl_read_targ_mem(priv
, ptr
);
4051 IWL_ERR(priv
, "%010u\t0x%08x\t%04u\n", time
, data
, ev
);
4056 static void iwl3945_dump_nic_event_log(struct iwl_priv
*priv
)
4059 u32 base
; /* SRAM byte address of event log header */
4060 u32 capacity
; /* event log capacity in # entries */
4061 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
4062 u32 num_wraps
; /* # times uCode wrapped to top of log */
4063 u32 next_entry
; /* index of next entry to be written by uCode */
4064 u32 size
; /* # entries that we'll print */
4066 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4067 if (!iwl3945_hw_valid_rtc_data_addr(base
)) {
4068 IWL_ERR(priv
, "Invalid event log pointer 0x%08X\n", base
);
4072 rc
= iwl_grab_nic_access(priv
);
4074 IWL_WARN(priv
, "Can not read from adapter at this time.\n");
4078 /* event log header */
4079 capacity
= iwl_read_targ_mem(priv
, base
);
4080 mode
= iwl_read_targ_mem(priv
, base
+ (1 * sizeof(u32
)));
4081 num_wraps
= iwl_read_targ_mem(priv
, base
+ (2 * sizeof(u32
)));
4082 next_entry
= iwl_read_targ_mem(priv
, base
+ (3 * sizeof(u32
)));
4084 size
= num_wraps
? capacity
: next_entry
;
4086 /* bail out if nothing in log */
4088 IWL_ERR(priv
, "Start IWL Event Log Dump: nothing in log\n");
4089 iwl_release_nic_access(priv
);
4093 IWL_ERR(priv
, "Start IWL Event Log Dump: display count %d, wraps %d\n",
4096 /* if uCode has wrapped back to top of log, start at the oldest entry,
4097 * i.e the next one that uCode would fill. */
4099 iwl3945_print_event_log(priv
, next_entry
,
4100 capacity
- next_entry
, mode
);
4102 /* (then/else) start at top of log */
4103 iwl3945_print_event_log(priv
, 0, next_entry
, mode
);
4105 iwl_release_nic_access(priv
);
4109 * iwl3945_irq_handle_error - called for HW or SW error interrupt from card
4111 static void iwl3945_irq_handle_error(struct iwl_priv
*priv
)
4113 /* Set the FW error flag -- cleared on iwl3945_down */
4114 set_bit(STATUS_FW_ERROR
, &priv
->status
);
4116 /* Cancel currently queued command. */
4117 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
4119 #ifdef CONFIG_IWL3945_DEBUG
4120 if (priv
->debug_level
& IWL_DL_FW_ERRORS
) {
4121 iwl3945_dump_nic_error_log(priv
);
4122 iwl3945_dump_nic_event_log(priv
);
4123 iwl3945_print_rx_config_cmd(priv
, &priv
->staging39_rxon
);
4127 wake_up_interruptible(&priv
->wait_command_queue
);
4129 /* Keep the restart process from trying to send host
4130 * commands by clearing the INIT status bit */
4131 clear_bit(STATUS_READY
, &priv
->status
);
4133 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
4134 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_FW_ERRORS
,
4135 "Restarting adapter due to uCode error.\n");
4137 if (iwl3945_is_associated(priv
)) {
4138 memcpy(&priv
->recovery39_rxon
, &priv
->active39_rxon
,
4139 sizeof(priv
->recovery39_rxon
));
4140 priv
->error_recovering
= 1;
4142 queue_work(priv
->workqueue
, &priv
->restart
);
4146 static void iwl3945_error_recovery(struct iwl_priv
*priv
)
4148 unsigned long flags
;
4150 memcpy(&priv
->staging39_rxon
, &priv
->recovery39_rxon
,
4151 sizeof(priv
->staging39_rxon
));
4152 priv
->staging39_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4153 iwl3945_commit_rxon(priv
);
4155 iwl3945_add_station(priv
, priv
->bssid
, 1, 0);
4157 spin_lock_irqsave(&priv
->lock
, flags
);
4158 priv
->assoc_id
= le16_to_cpu(priv
->staging39_rxon
.assoc_id
);
4159 priv
->error_recovering
= 0;
4160 spin_unlock_irqrestore(&priv
->lock
, flags
);
4163 static void iwl3945_irq_tasklet(struct iwl_priv
*priv
)
4165 u32 inta
, handled
= 0;
4167 unsigned long flags
;
4168 #ifdef CONFIG_IWL3945_DEBUG
4172 spin_lock_irqsave(&priv
->lock
, flags
);
4174 /* Ack/clear/reset pending uCode interrupts.
4175 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4176 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
4177 inta
= iwl_read32(priv
, CSR_INT
);
4178 iwl_write32(priv
, CSR_INT
, inta
);
4180 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4181 * Any new interrupts that happen after this, either while we're
4182 * in this tasklet, or later, will show up in next ISR/tasklet. */
4183 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4184 iwl_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
4186 #ifdef CONFIG_IWL3945_DEBUG
4187 if (priv
->debug_level
& IWL_DL_ISR
) {
4188 /* just for debug */
4189 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
4190 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4191 inta
, inta_mask
, inta_fh
);
4195 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4196 * atomic, make sure that inta covers all the interrupts that
4197 * we've discovered, even if FH interrupt came in just after
4198 * reading CSR_INT. */
4199 if (inta_fh
& CSR39_FH_INT_RX_MASK
)
4200 inta
|= CSR_INT_BIT_FH_RX
;
4201 if (inta_fh
& CSR39_FH_INT_TX_MASK
)
4202 inta
|= CSR_INT_BIT_FH_TX
;
4204 /* Now service all interrupt bits discovered above. */
4205 if (inta
& CSR_INT_BIT_HW_ERR
) {
4206 IWL_ERR(priv
, "Microcode HW error detected. Restarting.\n");
4208 /* Tell the device to stop sending interrupts */
4209 iwl3945_disable_interrupts(priv
);
4211 iwl3945_irq_handle_error(priv
);
4213 handled
|= CSR_INT_BIT_HW_ERR
;
4215 spin_unlock_irqrestore(&priv
->lock
, flags
);
4220 #ifdef CONFIG_IWL3945_DEBUG
4221 if (priv
->debug_level
& (IWL_DL_ISR
)) {
4222 /* NIC fires this, but we don't use it, redundant with WAKEUP */
4223 if (inta
& CSR_INT_BIT_SCD
)
4224 IWL_DEBUG_ISR("Scheduler finished to transmit "
4225 "the frame/frames.\n");
4227 /* Alive notification via Rx interrupt will do the real work */
4228 if (inta
& CSR_INT_BIT_ALIVE
)
4229 IWL_DEBUG_ISR("Alive interrupt\n");
4232 /* Safely ignore these bits for debug checks below */
4233 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
4235 /* Error detected by uCode */
4236 if (inta
& CSR_INT_BIT_SW_ERR
) {
4237 IWL_ERR(priv
, "Microcode SW error detected. "
4238 "Restarting 0x%X.\n", inta
);
4239 iwl3945_irq_handle_error(priv
);
4240 handled
|= CSR_INT_BIT_SW_ERR
;
4243 /* uCode wakes up after power-down sleep */
4244 if (inta
& CSR_INT_BIT_WAKEUP
) {
4245 IWL_DEBUG_ISR("Wakeup interrupt\n");
4246 iwl3945_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
4247 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq39
[0]);
4248 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq39
[1]);
4249 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq39
[2]);
4250 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq39
[3]);
4251 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq39
[4]);
4252 iwl3945_tx_queue_update_write_ptr(priv
, &priv
->txq39
[5]);
4254 handled
|= CSR_INT_BIT_WAKEUP
;
4257 /* All uCode command responses, including Tx command responses,
4258 * Rx "responses" (frame-received notification), and other
4259 * notifications from uCode come through here*/
4260 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
4261 iwl3945_rx_handle(priv
);
4262 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
4265 if (inta
& CSR_INT_BIT_FH_TX
) {
4266 IWL_DEBUG_ISR("Tx interrupt\n");
4268 iwl_write32(priv
, CSR_FH_INT_STATUS
, (1 << 6));
4269 if (!iwl_grab_nic_access(priv
)) {
4270 iwl_write_direct32(priv
, FH39_TCSR_CREDIT
4271 (FH39_SRVC_CHNL
), 0x0);
4272 iwl_release_nic_access(priv
);
4274 handled
|= CSR_INT_BIT_FH_TX
;
4277 if (inta
& ~handled
)
4278 IWL_ERR(priv
, "Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
4280 if (inta
& ~CSR_INI_SET_MASK
) {
4281 IWL_WARN(priv
, "Disabled INTA bits 0x%08x were pending\n",
4282 inta
& ~CSR_INI_SET_MASK
);
4283 IWL_WARN(priv
, " with FH_INT = 0x%08x\n", inta_fh
);
4286 /* Re-enable all interrupts */
4287 /* only Re-enable if disabled by irq */
4288 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
4289 iwl3945_enable_interrupts(priv
);
4291 #ifdef CONFIG_IWL3945_DEBUG
4292 if (priv
->debug_level
& (IWL_DL_ISR
)) {
4293 inta
= iwl_read32(priv
, CSR_INT
);
4294 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
4295 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4296 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
4297 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
4300 spin_unlock_irqrestore(&priv
->lock
, flags
);
4303 static irqreturn_t
iwl3945_isr(int irq
, void *data
)
4305 struct iwl_priv
*priv
= data
;
4306 u32 inta
, inta_mask
;
4311 spin_lock(&priv
->lock
);
4313 /* Disable (but don't clear!) interrupts here to avoid
4314 * back-to-back ISRs and sporadic interrupts from our NIC.
4315 * If we have something to service, the tasklet will re-enable ints.
4316 * If we *don't* have something, we'll re-enable before leaving here. */
4317 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
); /* just for debug */
4318 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
4320 /* Discover which interrupts are active/pending */
4321 inta
= iwl_read32(priv
, CSR_INT
);
4322 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4324 /* Ignore interrupt if there's nothing in NIC to service.
4325 * This may be due to IRQ shared with another device,
4326 * or due to sporadic interrupts thrown from our NIC. */
4327 if (!inta
&& !inta_fh
) {
4328 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
4332 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
4333 /* Hardware disappeared */
4334 IWL_WARN(priv
, "HARDWARE GONE?? INTA == 0x%08x\n", inta
);
4338 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4339 inta
, inta_mask
, inta_fh
);
4341 inta
&= ~CSR_INT_BIT_SCD
;
4343 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
4344 if (likely(inta
|| inta_fh
))
4345 tasklet_schedule(&priv
->irq_tasklet
);
4347 spin_unlock(&priv
->lock
);
4352 /* re-enable interrupts here since we don't have anything to service. */
4353 /* only Re-enable if disabled by irq */
4354 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
4355 iwl3945_enable_interrupts(priv
);
4356 spin_unlock(&priv
->lock
);
4360 /************************** EEPROM BANDS ****************************
4362 * The iwl3945_eeprom_band definitions below provide the mapping from the
4363 * EEPROM contents to the specific channel number supported for each
4366 * For example, iwl3945_priv->eeprom39.band_3_channels[4] from the band_3
4367 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
4368 * The specific geography and calibration information for that channel
4369 * is contained in the eeprom map itself.
4371 * During init, we copy the eeprom information and channel map
4372 * information into priv->channel_info_24/52 and priv->channel_map_24/52
4374 * channel_map_24/52 provides the index in the channel_info array for a
4375 * given channel. We have to have two separate maps as there is channel
4376 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
4379 * A value of 0xff stored in the channel_map indicates that the channel
4380 * is not supported by the hardware at all.
4382 * A value of 0xfe in the channel_map indicates that the channel is not
4383 * valid for Tx with the current hardware. This means that
4384 * while the system can tune and receive on a given channel, it may not
4385 * be able to associate or transmit any frames on that
4386 * channel. There is no corresponding channel information for that
4389 *********************************************************************/
4392 static const u8 iwl3945_eeprom_band_1
[14] = {
4393 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
4397 static const u8 iwl3945_eeprom_band_2
[] = { /* 4915-5080MHz */
4398 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
4401 static const u8 iwl3945_eeprom_band_3
[] = { /* 5170-5320MHz */
4402 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
4405 static const u8 iwl3945_eeprom_band_4
[] = { /* 5500-5700MHz */
4406 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
4409 static const u8 iwl3945_eeprom_band_5
[] = { /* 5725-5825MHz */
4410 145, 149, 153, 157, 161, 165
4413 static void iwl3945_init_band_reference(const struct iwl_priv
*priv
, int band
,
4414 int *eeprom_ch_count
,
4415 const struct iwl_eeprom_channel
4417 const u8
**eeprom_ch_index
)
4420 case 1: /* 2.4GHz band */
4421 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_1
);
4422 *eeprom_ch_info
= priv
->eeprom39
.band_1_channels
;
4423 *eeprom_ch_index
= iwl3945_eeprom_band_1
;
4425 case 2: /* 4.9GHz band */
4426 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_2
);
4427 *eeprom_ch_info
= priv
->eeprom39
.band_2_channels
;
4428 *eeprom_ch_index
= iwl3945_eeprom_band_2
;
4430 case 3: /* 5.2GHz band */
4431 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_3
);
4432 *eeprom_ch_info
= priv
->eeprom39
.band_3_channels
;
4433 *eeprom_ch_index
= iwl3945_eeprom_band_3
;
4435 case 4: /* 5.5GHz band */
4436 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_4
);
4437 *eeprom_ch_info
= priv
->eeprom39
.band_4_channels
;
4438 *eeprom_ch_index
= iwl3945_eeprom_band_4
;
4440 case 5: /* 5.7GHz band */
4441 *eeprom_ch_count
= ARRAY_SIZE(iwl3945_eeprom_band_5
);
4442 *eeprom_ch_info
= priv
->eeprom39
.band_5_channels
;
4443 *eeprom_ch_index
= iwl3945_eeprom_band_5
;
4452 * iwl3945_get_channel_info - Find driver's private channel info
4454 * Based on band and channel number.
4456 const struct iwl_channel_info
*
4457 iwl3945_get_channel_info(const struct iwl_priv
*priv
,
4458 enum ieee80211_band band
, u16 channel
)
4463 case IEEE80211_BAND_5GHZ
:
4464 for (i
= 14; i
< priv
->channel_count
; i
++) {
4465 if (priv
->channel_info
[i
].channel
== channel
)
4466 return &priv
->channel_info
[i
];
4470 case IEEE80211_BAND_2GHZ
:
4471 if (channel
>= 1 && channel
<= 14)
4472 return &priv
->channel_info
[channel
- 1];
4474 case IEEE80211_NUM_BANDS
:
4481 #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
4485 * iwl3945_init_channel_map - Set up driver's info for all possible channels
4487 static int iwl3945_init_channel_map(struct iwl_priv
*priv
)
4489 int eeprom_ch_count
= 0;
4490 const u8
*eeprom_ch_index
= NULL
;
4491 const struct iwl_eeprom_channel
*eeprom_ch_info
= NULL
;
4493 struct iwl_channel_info
*ch_info
;
4495 if (priv
->channel_count
) {
4496 IWL_DEBUG_INFO("Channel map already initialized.\n");
4500 if (priv
->eeprom39
.version
< 0x2f) {
4501 IWL_WARN(priv
, "Unsupported EEPROM version: 0x%04X\n",
4502 priv
->eeprom39
.version
);
4506 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
4508 priv
->channel_count
=
4509 ARRAY_SIZE(iwl3945_eeprom_band_1
) +
4510 ARRAY_SIZE(iwl3945_eeprom_band_2
) +
4511 ARRAY_SIZE(iwl3945_eeprom_band_3
) +
4512 ARRAY_SIZE(iwl3945_eeprom_band_4
) +
4513 ARRAY_SIZE(iwl3945_eeprom_band_5
);
4515 IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv
->channel_count
);
4517 priv
->channel_info
= kzalloc(sizeof(struct iwl_channel_info
) *
4518 priv
->channel_count
, GFP_KERNEL
);
4519 if (!priv
->channel_info
) {
4520 IWL_ERR(priv
, "Could not allocate channel_info\n");
4521 priv
->channel_count
= 0;
4525 ch_info
= priv
->channel_info
;
4527 /* Loop through the 5 EEPROM bands adding them in order to the
4528 * channel map we maintain (that contains additional information than
4529 * what just in the EEPROM) */
4530 for (band
= 1; band
<= 5; band
++) {
4532 iwl3945_init_band_reference(priv
, band
, &eeprom_ch_count
,
4533 &eeprom_ch_info
, &eeprom_ch_index
);
4535 /* Loop through each band adding each of the channels */
4536 for (ch
= 0; ch
< eeprom_ch_count
; ch
++) {
4537 ch_info
->channel
= eeprom_ch_index
[ch
];
4538 ch_info
->band
= (band
== 1) ? IEEE80211_BAND_2GHZ
:
4539 IEEE80211_BAND_5GHZ
;
4541 /* permanently store EEPROM's channel regulatory flags
4542 * and max power in channel info database. */
4543 ch_info
->eeprom
= eeprom_ch_info
[ch
];
4545 /* Copy the run-time flags so they are there even on
4546 * invalid channels */
4547 ch_info
->flags
= eeprom_ch_info
[ch
].flags
;
4549 if (!(is_channel_valid(ch_info
))) {
4550 IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
4554 is_channel_a_band(ch_info
) ?
4560 /* Initialize regulatory-based run-time data */
4561 ch_info
->max_power_avg
= ch_info
->curr_txpow
=
4562 eeprom_ch_info
[ch
].max_power_avg
;
4563 ch_info
->scan_power
= eeprom_ch_info
[ch
].max_power_avg
;
4564 ch_info
->min_power
= 0;
4566 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
4567 " %ddBm): Ad-Hoc %ssupported\n",
4569 is_channel_a_band(ch_info
) ?
4571 CHECK_AND_PRINT(VALID
),
4572 CHECK_AND_PRINT(IBSS
),
4573 CHECK_AND_PRINT(ACTIVE
),
4574 CHECK_AND_PRINT(RADAR
),
4575 CHECK_AND_PRINT(WIDE
),
4576 CHECK_AND_PRINT(DFS
),
4577 eeprom_ch_info
[ch
].flags
,
4578 eeprom_ch_info
[ch
].max_power_avg
,
4579 ((eeprom_ch_info
[ch
].
4580 flags
& EEPROM_CHANNEL_IBSS
)
4581 && !(eeprom_ch_info
[ch
].
4582 flags
& EEPROM_CHANNEL_RADAR
))
4585 /* Set the user_txpower_limit to the highest power
4586 * supported by any channel */
4587 if (eeprom_ch_info
[ch
].max_power_avg
>
4588 priv
->user_txpower_limit
)
4589 priv
->user_txpower_limit
=
4590 eeprom_ch_info
[ch
].max_power_avg
;
4596 /* Set up txpower settings in driver for all channels */
4597 if (iwl3945_txpower_set_from_eeprom(priv
))
4604 * iwl3945_free_channel_map - undo allocations in iwl3945_init_channel_map
4606 static void iwl3945_free_channel_map(struct iwl_priv
*priv
)
4608 kfree(priv
->channel_info
);
4609 priv
->channel_count
= 0;
4612 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
4613 * sending probe req. This should be set long enough to hear probe responses
4614 * from more than one AP. */
4615 #define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */
4616 #define IWL_ACTIVE_DWELL_TIME_52 (20)
4618 #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3)
4619 #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2)
4621 /* For faster active scanning, scan will move to the next channel if fewer than
4622 * PLCP_QUIET_THRESH packets are heard on this channel within
4623 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
4624 * time if it's a quiet channel (nothing responded to our probe, and there's
4625 * no other traffic).
4626 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
4627 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
4628 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(10) /* msec */
4630 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
4631 * Must be set longer than active dwell time.
4632 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
4633 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
4634 #define IWL_PASSIVE_DWELL_TIME_52 (10)
4635 #define IWL_PASSIVE_DWELL_BASE (100)
4636 #define IWL_CHANNEL_TUNE_TIME 5
4638 #define IWL_SCAN_PROBE_MASK(n) (BIT(n) | (BIT(n) - BIT(1)))
4640 static inline u16
iwl3945_get_active_dwell_time(struct iwl_priv
*priv
,
4641 enum ieee80211_band band
,
4644 if (band
== IEEE80211_BAND_5GHZ
)
4645 return IWL_ACTIVE_DWELL_TIME_52
+
4646 IWL_ACTIVE_DWELL_FACTOR_52GHZ
* (n_probes
+ 1);
4648 return IWL_ACTIVE_DWELL_TIME_24
+
4649 IWL_ACTIVE_DWELL_FACTOR_24GHZ
* (n_probes
+ 1);
4652 static u16
iwl3945_get_passive_dwell_time(struct iwl_priv
*priv
,
4653 enum ieee80211_band band
)
4655 u16 passive
= (band
== IEEE80211_BAND_2GHZ
) ?
4656 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_24
:
4657 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_52
;
4659 if (iwl3945_is_associated(priv
)) {
4660 /* If we're associated, we clamp the maximum passive
4661 * dwell time to be 98% of the beacon interval (minus
4662 * 2 * channel tune time) */
4663 passive
= priv
->beacon_int
;
4664 if ((passive
> IWL_PASSIVE_DWELL_BASE
) || !passive
)
4665 passive
= IWL_PASSIVE_DWELL_BASE
;
4666 passive
= (passive
* 98) / 100 - IWL_CHANNEL_TUNE_TIME
* 2;
4672 static int iwl3945_get_channels_for_scan(struct iwl_priv
*priv
,
4673 enum ieee80211_band band
,
4674 u8 is_active
, u8 n_probes
,
4675 struct iwl3945_scan_channel
*scan_ch
)
4677 const struct ieee80211_channel
*channels
= NULL
;
4678 const struct ieee80211_supported_band
*sband
;
4679 const struct iwl_channel_info
*ch_info
;
4680 u16 passive_dwell
= 0;
4681 u16 active_dwell
= 0;
4684 sband
= iwl3945_get_band(priv
, band
);
4688 channels
= sband
->channels
;
4690 active_dwell
= iwl3945_get_active_dwell_time(priv
, band
, n_probes
);
4691 passive_dwell
= iwl3945_get_passive_dwell_time(priv
, band
);
4693 if (passive_dwell
<= active_dwell
)
4694 passive_dwell
= active_dwell
+ 1;
4696 for (i
= 0, added
= 0; i
< sband
->n_channels
; i
++) {
4697 if (channels
[i
].flags
& IEEE80211_CHAN_DISABLED
)
4700 scan_ch
->channel
= channels
[i
].hw_value
;
4702 ch_info
= iwl3945_get_channel_info(priv
, band
, scan_ch
->channel
);
4703 if (!is_channel_valid(ch_info
)) {
4704 IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
4709 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
4710 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
4711 /* If passive , set up for auto-switch
4712 * and use long active_dwell time.
4714 if (!is_active
|| is_channel_passive(ch_info
) ||
4715 (channels
[i
].flags
& IEEE80211_CHAN_PASSIVE_SCAN
)) {
4716 scan_ch
->type
= 0; /* passive */
4717 if (IWL_UCODE_API(priv
->ucode_ver
) == 1)
4718 scan_ch
->active_dwell
= cpu_to_le16(passive_dwell
- 1);
4720 scan_ch
->type
= 1; /* active */
4723 /* Set direct probe bits. These may be used both for active
4724 * scan channels (probes gets sent right away),
4725 * or for passive channels (probes get se sent only after
4726 * hearing clear Rx packet).*/
4727 if (IWL_UCODE_API(priv
->ucode_ver
) >= 2) {
4729 scan_ch
->type
|= IWL_SCAN_PROBE_MASK(n_probes
);
4731 /* uCode v1 does not allow setting direct probe bits on
4732 * passive channel. */
4733 if ((scan_ch
->type
& 1) && n_probes
)
4734 scan_ch
->type
|= IWL_SCAN_PROBE_MASK(n_probes
);
4737 /* Set txpower levels to defaults */
4738 scan_ch
->tpc
.dsp_atten
= 110;
4739 /* scan_pwr_info->tpc.dsp_atten; */
4741 /*scan_pwr_info->tpc.tx_gain; */
4742 if (band
== IEEE80211_BAND_5GHZ
)
4743 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
4745 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
4746 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
4748 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
4752 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
4754 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
4755 (scan_ch
->type
& 1) ?
4756 active_dwell
: passive_dwell
);
4762 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
4766 static void iwl3945_init_hw_rates(struct iwl_priv
*priv
,
4767 struct ieee80211_rate
*rates
)
4771 for (i
= 0; i
< IWL_RATE_COUNT
; i
++) {
4772 rates
[i
].bitrate
= iwl3945_rates
[i
].ieee
* 5;
4773 rates
[i
].hw_value
= i
; /* Rate scaling will work on indexes */
4774 rates
[i
].hw_value_short
= i
;
4776 if ((i
> IWL39_LAST_OFDM_RATE
) || (i
< IWL_FIRST_OFDM_RATE
)) {
4778 * If CCK != 1M then set short preamble rate flag.
4780 rates
[i
].flags
|= (iwl3945_rates
[i
].plcp
== 10) ?
4781 0 : IEEE80211_RATE_SHORT_PREAMBLE
;
4787 * iwl3945_init_geos - Initialize mac80211's geo/channel info based from eeprom
4789 static int iwl3945_init_geos(struct iwl_priv
*priv
)
4791 struct iwl_channel_info
*ch
;
4792 struct ieee80211_supported_band
*sband
;
4793 struct ieee80211_channel
*channels
;
4794 struct ieee80211_channel
*geo_ch
;
4795 struct ieee80211_rate
*rates
;
4798 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_bitrates
||
4799 priv
->bands
[IEEE80211_BAND_5GHZ
].n_bitrates
) {
4800 IWL_DEBUG_INFO("Geography modes already initialized.\n");
4801 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
4805 channels
= kzalloc(sizeof(struct ieee80211_channel
) *
4806 priv
->channel_count
, GFP_KERNEL
);
4810 rates
= kzalloc((sizeof(struct ieee80211_rate
) * (IWL_RATE_COUNT
+ 1)),
4817 /* 5.2GHz channels start after the 2.4GHz channels */
4818 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
4819 sband
->channels
= &channels
[ARRAY_SIZE(iwl3945_eeprom_band_1
)];
4821 sband
->bitrates
= &rates
[IWL_FIRST_OFDM_RATE
];
4822 sband
->n_bitrates
= IWL_RATE_COUNT
- IWL_FIRST_OFDM_RATE
;
4824 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
4825 sband
->channels
= channels
;
4827 sband
->bitrates
= rates
;
4828 sband
->n_bitrates
= IWL_RATE_COUNT
;
4830 priv
->ieee_channels
= channels
;
4831 priv
->ieee_rates
= rates
;
4833 iwl3945_init_hw_rates(priv
, rates
);
4835 for (i
= 0; i
< priv
->channel_count
; i
++) {
4836 ch
= &priv
->channel_info
[i
];
4838 /* FIXME: might be removed if scan is OK*/
4839 if (!is_channel_valid(ch
))
4842 if (is_channel_a_band(ch
))
4843 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
4845 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
4847 geo_ch
= &sband
->channels
[sband
->n_channels
++];
4849 geo_ch
->center_freq
= ieee80211_channel_to_frequency(ch
->channel
);
4850 geo_ch
->max_power
= ch
->max_power_avg
;
4851 geo_ch
->max_antenna_gain
= 0xff;
4852 geo_ch
->hw_value
= ch
->channel
;
4854 if (is_channel_valid(ch
)) {
4855 if (!(ch
->flags
& EEPROM_CHANNEL_IBSS
))
4856 geo_ch
->flags
|= IEEE80211_CHAN_NO_IBSS
;
4858 if (!(ch
->flags
& EEPROM_CHANNEL_ACTIVE
))
4859 geo_ch
->flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
4861 if (ch
->flags
& EEPROM_CHANNEL_RADAR
)
4862 geo_ch
->flags
|= IEEE80211_CHAN_RADAR
;
4864 if (ch
->max_power_avg
> priv
->max_channel_txpower_limit
)
4865 priv
->max_channel_txpower_limit
=
4868 geo_ch
->flags
|= IEEE80211_CHAN_DISABLED
;
4871 /* Save flags for reg domain usage */
4872 geo_ch
->orig_flags
= geo_ch
->flags
;
4874 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
4875 ch
->channel
, geo_ch
->center_freq
,
4876 is_channel_a_band(ch
) ? "5.2" : "2.4",
4877 geo_ch
->flags
& IEEE80211_CHAN_DISABLED
?
4878 "restricted" : "valid",
4882 if ((priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
== 0) &&
4883 priv
->cfg
->sku
& IWL_SKU_A
) {
4884 IWL_INFO(priv
, "Incorrectly detected BG card as ABG. "
4885 "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
4886 priv
->pci_dev
->device
, priv
->pci_dev
->subsystem_device
);
4887 priv
->cfg
->sku
&= ~IWL_SKU_A
;
4890 IWL_INFO(priv
, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
4891 priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
,
4892 priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
);
4894 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
4895 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
4896 &priv
->bands
[IEEE80211_BAND_2GHZ
];
4897 if (priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
4898 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
4899 &priv
->bands
[IEEE80211_BAND_5GHZ
];
4901 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
4907 * iwl3945_free_geos - undo allocations in iwl3945_init_geos
4909 static void iwl3945_free_geos(struct iwl_priv
*priv
)
4911 kfree(priv
->ieee_channels
);
4912 kfree(priv
->ieee_rates
);
4913 clear_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
4916 /******************************************************************************
4918 * uCode download functions
4920 ******************************************************************************/
4922 static void iwl3945_dealloc_ucode_pci(struct iwl_priv
*priv
)
4924 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
4925 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
4926 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
4927 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
4928 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
4929 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
4933 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
4934 * looking at all data.
4936 static int iwl3945_verify_inst_full(struct iwl_priv
*priv
, __le32
*image
, u32 len
)
4943 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
4945 rc
= iwl_grab_nic_access(priv
);
4949 iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
4950 IWL39_RTC_INST_LOWER_BOUND
);
4953 for (; len
> 0; len
-= sizeof(u32
), image
++) {
4954 /* read data comes through single port, auto-incr addr */
4955 /* NOTE: Use the debugless read so we don't flood kernel log
4956 * if IWL_DL_IO is set */
4957 val
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
4958 if (val
!= le32_to_cpu(*image
)) {
4959 IWL_ERR(priv
, "uCode INST section is invalid at "
4960 "offset 0x%x, is 0x%x, s/b 0x%x\n",
4961 save_len
- len
, val
, le32_to_cpu(*image
));
4969 iwl_release_nic_access(priv
);
4972 IWL_DEBUG_INFO("ucode image in INSTRUCTION memory is good\n");
4979 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
4980 * using sample data 100 bytes apart. If these sample points are good,
4981 * it's a pretty good bet that everything between them is good, too.
4983 static int iwl3945_verify_inst_sparse(struct iwl_priv
*priv
, __le32
*image
, u32 len
)
4990 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
4992 rc
= iwl_grab_nic_access(priv
);
4996 for (i
= 0; i
< len
; i
+= 100, image
+= 100/sizeof(u32
)) {
4997 /* read data comes through single port, auto-incr addr */
4998 /* NOTE: Use the debugless read so we don't flood kernel log
4999 * if IWL_DL_IO is set */
5000 iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
5001 i
+ IWL39_RTC_INST_LOWER_BOUND
);
5002 val
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
5003 if (val
!= le32_to_cpu(*image
)) {
5004 #if 0 /* Enable this if you want to see details */
5005 IWL_ERR(priv
, "uCode INST section is invalid at "
5006 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5016 iwl_release_nic_access(priv
);
5023 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
5024 * and verify its contents
5026 static int iwl3945_verify_ucode(struct iwl_priv
*priv
)
5033 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5034 len
= priv
->ucode_boot
.len
;
5035 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
5037 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
5041 /* Try initialize */
5042 image
= (__le32
*)priv
->ucode_init
.v_addr
;
5043 len
= priv
->ucode_init
.len
;
5044 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
5046 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
5050 /* Try runtime/protocol */
5051 image
= (__le32
*)priv
->ucode_code
.v_addr
;
5052 len
= priv
->ucode_code
.len
;
5053 rc
= iwl3945_verify_inst_sparse(priv
, image
, len
);
5055 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
5059 IWL_ERR(priv
, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5061 /* Since nothing seems to match, show first several data entries in
5062 * instruction SRAM, so maybe visual inspection will give a clue.
5063 * Selection of bootstrap image (vs. other images) is arbitrary. */
5064 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5065 len
= priv
->ucode_boot
.len
;
5066 rc
= iwl3945_verify_inst_full(priv
, image
, len
);
5072 /* check contents of special bootstrap uCode SRAM */
5073 static int iwl3945_verify_bsm(struct iwl_priv
*priv
)
5075 __le32
*image
= priv
->ucode_boot
.v_addr
;
5076 u32 len
= priv
->ucode_boot
.len
;
5080 IWL_DEBUG_INFO("Begin verify bsm\n");
5082 /* verify BSM SRAM contents */
5083 val
= iwl_read_prph(priv
, BSM_WR_DWCOUNT_REG
);
5084 for (reg
= BSM_SRAM_LOWER_BOUND
;
5085 reg
< BSM_SRAM_LOWER_BOUND
+ len
;
5086 reg
+= sizeof(u32
), image
++) {
5087 val
= iwl_read_prph(priv
, reg
);
5088 if (val
!= le32_to_cpu(*image
)) {
5089 IWL_ERR(priv
, "BSM uCode verification failed at "
5090 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
5091 BSM_SRAM_LOWER_BOUND
,
5092 reg
- BSM_SRAM_LOWER_BOUND
, len
,
5093 val
, le32_to_cpu(*image
));
5098 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
5104 * iwl3945_load_bsm - Load bootstrap instructions
5108 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
5109 * in special SRAM that does not power down during RFKILL. When powering back
5110 * up after power-saving sleeps (or during initial uCode load), the BSM loads
5111 * the bootstrap program into the on-board processor, and starts it.
5113 * The bootstrap program loads (via DMA) instructions and data for a new
5114 * program from host DRAM locations indicated by the host driver in the
5115 * BSM_DRAM_* registers. Once the new program is loaded, it starts
5118 * When initializing the NIC, the host driver points the BSM to the
5119 * "initialize" uCode image. This uCode sets up some internal data, then
5120 * notifies host via "initialize alive" that it is complete.
5122 * The host then replaces the BSM_DRAM_* pointer values to point to the
5123 * normal runtime uCode instructions and a backup uCode data cache buffer
5124 * (filled initially with starting data values for the on-board processor),
5125 * then triggers the "initialize" uCode to load and launch the runtime uCode,
5126 * which begins normal operation.
5128 * When doing a power-save shutdown, runtime uCode saves data SRAM into
5129 * the backup data cache in DRAM before SRAM is powered down.
5131 * When powering back up, the BSM loads the bootstrap program. This reloads
5132 * the runtime uCode instructions and the backup data cache into SRAM,
5133 * and re-launches the runtime uCode from where it left off.
5135 static int iwl3945_load_bsm(struct iwl_priv
*priv
)
5137 __le32
*image
= priv
->ucode_boot
.v_addr
;
5138 u32 len
= priv
->ucode_boot
.len
;
5148 IWL_DEBUG_INFO("Begin load bsm\n");
5150 /* make sure bootstrap program is no larger than BSM's SRAM size */
5151 if (len
> IWL39_MAX_BSM_SIZE
)
5154 /* Tell bootstrap uCode where to find the "Initialize" uCode
5155 * in host DRAM ... host DRAM physical address bits 31:0 for 3945.
5156 * NOTE: iwl3945_initialize_alive_start() will replace these values,
5157 * after the "initialize" uCode has run, to point to
5158 * runtime/protocol instructions and backup data cache. */
5159 pinst
= priv
->ucode_init
.p_addr
;
5160 pdata
= priv
->ucode_init_data
.p_addr
;
5161 inst_len
= priv
->ucode_init
.len
;
5162 data_len
= priv
->ucode_init_data
.len
;
5164 rc
= iwl_grab_nic_access(priv
);
5168 iwl_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
5169 iwl_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
5170 iwl_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
, inst_len
);
5171 iwl_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
, data_len
);
5173 /* Fill BSM memory with bootstrap instructions */
5174 for (reg_offset
= BSM_SRAM_LOWER_BOUND
;
5175 reg_offset
< BSM_SRAM_LOWER_BOUND
+ len
;
5176 reg_offset
+= sizeof(u32
), image
++)
5177 _iwl_write_prph(priv
, reg_offset
,
5178 le32_to_cpu(*image
));
5180 rc
= iwl3945_verify_bsm(priv
);
5182 iwl_release_nic_access(priv
);
5186 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
5187 iwl_write_prph(priv
, BSM_WR_MEM_SRC_REG
, 0x0);
5188 iwl_write_prph(priv
, BSM_WR_MEM_DST_REG
,
5189 IWL39_RTC_INST_LOWER_BOUND
);
5190 iwl_write_prph(priv
, BSM_WR_DWCOUNT_REG
, len
/ sizeof(u32
));
5192 /* Load bootstrap code into instruction SRAM now,
5193 * to prepare to load "initialize" uCode */
5194 iwl_write_prph(priv
, BSM_WR_CTRL_REG
,
5195 BSM_WR_CTRL_REG_BIT_START
);
5197 /* Wait for load of bootstrap uCode to finish */
5198 for (i
= 0; i
< 100; i
++) {
5199 done
= iwl_read_prph(priv
, BSM_WR_CTRL_REG
);
5200 if (!(done
& BSM_WR_CTRL_REG_BIT_START
))
5205 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i
);
5207 IWL_ERR(priv
, "BSM write did not complete!\n");
5211 /* Enable future boot loads whenever power management unit triggers it
5212 * (e.g. when powering back up after power-save shutdown) */
5213 iwl_write_prph(priv
, BSM_WR_CTRL_REG
,
5214 BSM_WR_CTRL_REG_BIT_START_EN
);
5216 iwl_release_nic_access(priv
);
5221 static void iwl3945_nic_start(struct iwl_priv
*priv
)
5223 /* Remove all resets to allow NIC to operate */
5224 iwl_write32(priv
, CSR_RESET
, 0);
5228 * iwl3945_read_ucode - Read uCode images from disk file.
5230 * Copy into buffers for card to fetch via bus-mastering
5232 static int iwl3945_read_ucode(struct iwl_priv
*priv
)
5234 struct iwl_ucode
*ucode
;
5235 int ret
= -EINVAL
, index
;
5236 const struct firmware
*ucode_raw
;
5237 /* firmware file name contains uCode/driver compatibility version */
5238 const char *name_pre
= priv
->cfg
->fw_name_pre
;
5239 const unsigned int api_max
= priv
->cfg
->ucode_api_max
;
5240 const unsigned int api_min
= priv
->cfg
->ucode_api_min
;
5244 u32 api_ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
5246 /* Ask kernel firmware_class module to get the boot firmware off disk.
5247 * request_firmware() is synchronous, file is in memory on return. */
5248 for (index
= api_max
; index
>= api_min
; index
--) {
5249 sprintf(buf
, "%s%u%s", name_pre
, index
, ".ucode");
5250 ret
= request_firmware(&ucode_raw
, buf
, &priv
->pci_dev
->dev
);
5252 IWL_ERR(priv
, "%s firmware file req failed: %d\n",
5259 if (index
< api_max
)
5260 IWL_ERR(priv
, "Loaded firmware %s, "
5261 "which is deprecated. "
5262 " Please use API v%u instead.\n",
5264 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
5265 buf
, ucode_raw
->size
);
5273 /* Make sure that we got at least our header! */
5274 if (ucode_raw
->size
< sizeof(*ucode
)) {
5275 IWL_ERR(priv
, "File size way too small!\n");
5280 /* Data from ucode file: header followed by uCode images */
5281 ucode
= (void *)ucode_raw
->data
;
5283 priv
->ucode_ver
= le32_to_cpu(ucode
->ver
);
5284 api_ver
= IWL_UCODE_API(priv
->ucode_ver
);
5285 inst_size
= le32_to_cpu(ucode
->inst_size
);
5286 data_size
= le32_to_cpu(ucode
->data_size
);
5287 init_size
= le32_to_cpu(ucode
->init_size
);
5288 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
5289 boot_size
= le32_to_cpu(ucode
->boot_size
);
5291 /* api_ver should match the api version forming part of the
5292 * firmware filename ... but we don't check for that and only rely
5293 * on the API version read from firware header from here on forward */
5295 if (api_ver
< api_min
|| api_ver
> api_max
) {
5296 IWL_ERR(priv
, "Driver unable to support your firmware API. "
5297 "Driver supports v%u, firmware is v%u.\n",
5299 priv
->ucode_ver
= 0;
5303 if (api_ver
!= api_max
)
5304 IWL_ERR(priv
, "Firmware has old API version. Expected %u, "
5305 "got %u. New firmware can be obtained "
5306 "from http://www.intellinuxwireless.org.\n",
5309 IWL_INFO(priv
, "loaded firmware version %u.%u.%u.%u\n",
5310 IWL_UCODE_MAJOR(priv
->ucode_ver
),
5311 IWL_UCODE_MINOR(priv
->ucode_ver
),
5312 IWL_UCODE_API(priv
->ucode_ver
),
5313 IWL_UCODE_SERIAL(priv
->ucode_ver
));
5315 IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n",
5317 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n", inst_size
);
5318 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n", data_size
);
5319 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n", init_size
);
5320 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n", init_data_size
);
5321 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n", boot_size
);
5324 /* Verify size of file vs. image size info in file's header */
5325 if (ucode_raw
->size
< sizeof(*ucode
) +
5326 inst_size
+ data_size
+ init_size
+
5327 init_data_size
+ boot_size
) {
5329 IWL_DEBUG_INFO("uCode file size %d too small\n",
5330 (int)ucode_raw
->size
);
5335 /* Verify that uCode images will fit in card's SRAM */
5336 if (inst_size
> IWL39_MAX_INST_SIZE
) {
5337 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
5343 if (data_size
> IWL39_MAX_DATA_SIZE
) {
5344 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
5349 if (init_size
> IWL39_MAX_INST_SIZE
) {
5350 IWL_DEBUG_INFO("uCode init instr len %d too large to fit in\n",
5355 if (init_data_size
> IWL39_MAX_DATA_SIZE
) {
5356 IWL_DEBUG_INFO("uCode init data len %d too large to fit in\n",
5361 if (boot_size
> IWL39_MAX_BSM_SIZE
) {
5362 IWL_DEBUG_INFO("uCode boot instr len %d too large to fit in\n",
5368 /* Allocate ucode buffers for card's bus-master loading ... */
5370 /* Runtime instructions and 2 copies of data:
5371 * 1) unmodified from disk
5372 * 2) backup cache for save/restore during power-downs */
5373 priv
->ucode_code
.len
= inst_size
;
5374 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
5376 priv
->ucode_data
.len
= data_size
;
5377 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
5379 priv
->ucode_data_backup
.len
= data_size
;
5380 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
5382 if (!priv
->ucode_code
.v_addr
|| !priv
->ucode_data
.v_addr
||
5383 !priv
->ucode_data_backup
.v_addr
)
5386 /* Initialization instructions and data */
5387 if (init_size
&& init_data_size
) {
5388 priv
->ucode_init
.len
= init_size
;
5389 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
5391 priv
->ucode_init_data
.len
= init_data_size
;
5392 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
5394 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
5398 /* Bootstrap (instructions only, no data) */
5400 priv
->ucode_boot
.len
= boot_size
;
5401 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
5403 if (!priv
->ucode_boot
.v_addr
)
5407 /* Copy images into buffers for card's bus-master reads ... */
5409 /* Runtime instructions (first block of data in file) */
5410 src
= &ucode
->data
[0];
5411 len
= priv
->ucode_code
.len
;
5412 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len
);
5413 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
5414 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
5415 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
5417 /* Runtime data (2nd block)
5418 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
5419 src
= &ucode
->data
[inst_size
];
5420 len
= priv
->ucode_data
.len
;
5421 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len
);
5422 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
5423 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
5425 /* Initialization instructions (3rd block) */
5427 src
= &ucode
->data
[inst_size
+ data_size
];
5428 len
= priv
->ucode_init
.len
;
5429 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
5431 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
5434 /* Initialization data (4th block) */
5435 if (init_data_size
) {
5436 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
5437 len
= priv
->ucode_init_data
.len
;
5438 IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
5440 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
5443 /* Bootstrap instructions (5th block) */
5444 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
5445 len
= priv
->ucode_boot
.len
;
5446 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
5448 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
5450 /* We have our copies now, allow OS release its copies */
5451 release_firmware(ucode_raw
);
5455 IWL_ERR(priv
, "failed to allocate pci memory\n");
5457 iwl3945_dealloc_ucode_pci(priv
);
5460 release_firmware(ucode_raw
);
5468 * iwl3945_set_ucode_ptrs - Set uCode address location
5470 * Tell initialization uCode where to find runtime uCode.
5472 * BSM registers initially contain pointers to initialization uCode.
5473 * We need to replace them to load runtime uCode inst and data,
5474 * and to save runtime data when powering down.
5476 static int iwl3945_set_ucode_ptrs(struct iwl_priv
*priv
)
5481 unsigned long flags
;
5483 /* bits 31:0 for 3945 */
5484 pinst
= priv
->ucode_code
.p_addr
;
5485 pdata
= priv
->ucode_data_backup
.p_addr
;
5487 spin_lock_irqsave(&priv
->lock
, flags
);
5488 rc
= iwl_grab_nic_access(priv
);
5490 spin_unlock_irqrestore(&priv
->lock
, flags
);
5494 /* Tell bootstrap uCode where to find image to load */
5495 iwl_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
5496 iwl_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
5497 iwl_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
,
5498 priv
->ucode_data
.len
);
5500 /* Inst byte count must be last to set up, bit 31 signals uCode
5501 * that all new ptr/size info is in place */
5502 iwl_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
,
5503 priv
->ucode_code
.len
| BSM_DRAM_INST_LOAD
);
5505 iwl_release_nic_access(priv
);
5507 spin_unlock_irqrestore(&priv
->lock
, flags
);
5509 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
5515 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
5517 * Called after REPLY_ALIVE notification received from "initialize" uCode.
5519 * Tell "initialize" uCode to go ahead and load the runtime uCode.
5521 static void iwl3945_init_alive_start(struct iwl_priv
*priv
)
5523 /* Check alive response for "valid" sign from uCode */
5524 if (priv
->card_alive_init
.is_valid
!= UCODE_VALID_OK
) {
5525 /* We had an error bringing up the hardware, so take it
5526 * all the way back down so we can try again */
5527 IWL_DEBUG_INFO("Initialize Alive failed.\n");
5531 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
5532 * This is a paranoid check, because we would not have gotten the
5533 * "initialize" alive if code weren't properly loaded. */
5534 if (iwl3945_verify_ucode(priv
)) {
5535 /* Runtime instruction load was bad;
5536 * take it all the way back down so we can try again */
5537 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
5541 /* Send pointers to protocol/runtime uCode image ... init code will
5542 * load and launch runtime uCode, which will send us another "Alive"
5544 IWL_DEBUG_INFO("Initialization Alive received.\n");
5545 if (iwl3945_set_ucode_ptrs(priv
)) {
5546 /* Runtime instruction load won't happen;
5547 * take it all the way back down so we can try again */
5548 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
5554 queue_work(priv
->workqueue
, &priv
->restart
);
5559 static int iwl3945_mac_beacon_update(struct ieee80211_hw
*hw
,
5560 struct sk_buff
*skb
);
5563 * iwl3945_alive_start - called after REPLY_ALIVE notification received
5564 * from protocol/runtime uCode (initialization uCode's
5565 * Alive gets handled by iwl3945_init_alive_start()).
5567 static void iwl3945_alive_start(struct iwl_priv
*priv
)
5570 int thermal_spin
= 0;
5573 IWL_DEBUG_INFO("Runtime Alive received.\n");
5575 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
5576 /* We had an error bringing up the hardware, so take it
5577 * all the way back down so we can try again */
5578 IWL_DEBUG_INFO("Alive failed.\n");
5582 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
5583 * This is a paranoid check, because we would not have gotten the
5584 * "runtime" alive if code weren't properly loaded. */
5585 if (iwl3945_verify_ucode(priv
)) {
5586 /* Runtime instruction load was bad;
5587 * take it all the way back down so we can try again */
5588 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
5592 iwl3945_clear_stations_table(priv
);
5594 rc
= iwl_grab_nic_access(priv
);
5596 IWL_WARN(priv
, "Can not read RFKILL status from adapter\n");
5600 rfkill
= iwl_read_prph(priv
, APMG_RFKILL_REG
);
5601 IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill
);
5602 iwl_release_nic_access(priv
);
5605 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5606 /* if RFKILL is not on, then wait for thermal
5607 * sensor in adapter to kick in */
5608 while (iwl3945_hw_get_temperature(priv
) == 0) {
5614 IWL_DEBUG_INFO("Thermal calibration took %dus\n",
5617 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5619 /* After the ALIVE response, we can send commands to 3945 uCode */
5620 set_bit(STATUS_ALIVE
, &priv
->status
);
5622 /* Clear out the uCode error bit if it is set */
5623 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
5625 if (iwl3945_is_rfkill(priv
))
5628 ieee80211_wake_queues(priv
->hw
);
5630 priv
->active_rate
= priv
->rates_mask
;
5631 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
5633 iwl3945_send_power_mode(priv
, IWL_POWER_LEVEL(priv
->power_mode
));
5635 if (iwl3945_is_associated(priv
)) {
5636 struct iwl3945_rxon_cmd
*active_rxon
=
5637 (struct iwl3945_rxon_cmd
*)(&priv
->active39_rxon
);
5639 memcpy(&priv
->staging39_rxon
, &priv
->active39_rxon
,
5640 sizeof(priv
->staging39_rxon
));
5641 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5643 /* Initialize our rx_config data */
5644 iwl3945_connection_init_rx_config(priv
, priv
->iw_mode
);
5645 memcpy(priv
->staging39_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
5648 /* Configure Bluetooth device coexistence support */
5649 iwl3945_send_bt_config(priv
);
5651 /* Configure the adapter for unassociated operation */
5652 iwl3945_commit_rxon(priv
);
5654 iwl3945_reg_txpower_periodic(priv
);
5656 iwl3945_led_register(priv
);
5658 IWL_DEBUG_INFO("ALIVE processing complete.\n");
5659 set_bit(STATUS_READY
, &priv
->status
);
5660 wake_up_interruptible(&priv
->wait_command_queue
);
5662 if (priv
->error_recovering
)
5663 iwl3945_error_recovery(priv
);
5665 /* reassociate for ADHOC mode */
5666 if (priv
->vif
&& (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
)) {
5667 struct sk_buff
*beacon
= ieee80211_beacon_get(priv
->hw
,
5670 iwl3945_mac_beacon_update(priv
->hw
, beacon
);
5676 queue_work(priv
->workqueue
, &priv
->restart
);
5679 static void iwl3945_cancel_deferred_work(struct iwl_priv
*priv
);
5681 static void __iwl3945_down(struct iwl_priv
*priv
)
5683 unsigned long flags
;
5684 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5685 struct ieee80211_conf
*conf
= NULL
;
5687 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
5689 conf
= ieee80211_get_hw_conf(priv
->hw
);
5692 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5694 iwl3945_led_unregister(priv
);
5695 iwl3945_clear_stations_table(priv
);
5697 /* Unblock any waiting calls */
5698 wake_up_interruptible_all(&priv
->wait_command_queue
);
5700 /* Wipe out the EXIT_PENDING status bit if we are not actually
5701 * exiting the module */
5703 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5705 /* stop and reset the on-board processor */
5706 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
5708 /* tell the device to stop sending interrupts */
5709 spin_lock_irqsave(&priv
->lock
, flags
);
5710 iwl3945_disable_interrupts(priv
);
5711 spin_unlock_irqrestore(&priv
->lock
, flags
);
5712 iwl_synchronize_irq(priv
);
5714 if (priv
->mac80211_registered
)
5715 ieee80211_stop_queues(priv
->hw
);
5717 /* If we have not previously called iwl3945_init() then
5718 * clear all bits but the RF Kill and SUSPEND bits and return */
5719 if (!iwl3945_is_init(priv
)) {
5720 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
5722 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
5724 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
5725 STATUS_GEO_CONFIGURED
|
5726 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
5728 test_bit(STATUS_EXIT_PENDING
, &priv
->status
) <<
5729 STATUS_EXIT_PENDING
;
5733 /* ...otherwise clear out all the status bits but the RF Kill and
5734 * SUSPEND bits and continue taking the NIC down. */
5735 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
5737 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
5739 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
5740 STATUS_GEO_CONFIGURED
|
5741 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
5743 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
5745 test_bit(STATUS_EXIT_PENDING
, &priv
->status
) <<
5746 STATUS_EXIT_PENDING
;
5748 spin_lock_irqsave(&priv
->lock
, flags
);
5749 iwl_clear_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
5750 spin_unlock_irqrestore(&priv
->lock
, flags
);
5752 iwl3945_hw_txq_ctx_stop(priv
);
5753 iwl3945_hw_rxq_stop(priv
);
5755 spin_lock_irqsave(&priv
->lock
, flags
);
5756 if (!iwl_grab_nic_access(priv
)) {
5757 iwl_write_prph(priv
, APMG_CLK_DIS_REG
,
5758 APMG_CLK_VAL_DMA_CLK_RQT
);
5759 iwl_release_nic_access(priv
);
5761 spin_unlock_irqrestore(&priv
->lock
, flags
);
5765 iwl3945_hw_nic_stop_master(priv
);
5766 iwl_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_SW_RESET
);
5767 iwl3945_hw_nic_reset(priv
);
5770 memset(&priv
->card_alive
, 0, sizeof(struct iwl_alive_resp
));
5772 if (priv
->ibss_beacon
)
5773 dev_kfree_skb(priv
->ibss_beacon
);
5774 priv
->ibss_beacon
= NULL
;
5776 /* clear out any free frames */
5777 iwl3945_clear_free_frames(priv
);
5780 static void iwl3945_down(struct iwl_priv
*priv
)
5782 mutex_lock(&priv
->mutex
);
5783 __iwl3945_down(priv
);
5784 mutex_unlock(&priv
->mutex
);
5786 iwl3945_cancel_deferred_work(priv
);
5789 #define MAX_HW_RESTARTS 5
5791 static int __iwl3945_up(struct iwl_priv
*priv
)
5795 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
5796 IWL_WARN(priv
, "Exit pending; will not bring the NIC up\n");
5800 if (test_bit(STATUS_RF_KILL_SW
, &priv
->status
)) {
5801 IWL_WARN(priv
, "Radio disabled by SW RF kill (module "
5806 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
5807 IWL_ERR(priv
, "ucode not available for device bring up\n");
5811 /* If platform's RF_KILL switch is NOT set to KILL */
5812 if (iwl_read32(priv
, CSR_GP_CNTRL
) &
5813 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
5814 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5816 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5817 if (!test_bit(STATUS_IN_SUSPEND
, &priv
->status
)) {
5818 IWL_WARN(priv
, "Radio disabled by HW RF Kill switch\n");
5823 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
5825 rc
= iwl3945_hw_nic_init(priv
);
5827 IWL_ERR(priv
, "Unable to int nic\n");
5831 /* make sure rfkill handshake bits are cleared */
5832 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5833 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
5834 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
5836 /* clear (again), then enable host interrupts */
5837 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
5838 iwl3945_enable_interrupts(priv
);
5840 /* really make sure rfkill handshake bits are cleared */
5841 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5842 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5844 /* Copy original ucode data image from disk into backup cache.
5845 * This will be used to initialize the on-board processor's
5846 * data SRAM for a clean start when the runtime program first loads. */
5847 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
5848 priv
->ucode_data
.len
);
5850 /* We return success when we resume from suspend and rf_kill is on. */
5851 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
5854 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
5856 iwl3945_clear_stations_table(priv
);
5858 /* load bootstrap state machine,
5859 * load bootstrap program into processor's memory,
5860 * prepare to load the "initialize" uCode */
5861 rc
= iwl3945_load_bsm(priv
);
5865 "Unable to set up bootstrap uCode: %d\n", rc
);
5869 /* start card; "initialize" will load runtime ucode */
5870 iwl3945_nic_start(priv
);
5872 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
5877 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5878 __iwl3945_down(priv
);
5879 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5881 /* tried to restart and config the device for as long as our
5882 * patience could withstand */
5883 IWL_ERR(priv
, "Unable to initialize device after %d attempts.\n", i
);
5888 /*****************************************************************************
5890 * Workqueue callbacks
5892 *****************************************************************************/
5894 static void iwl3945_bg_init_alive_start(struct work_struct
*data
)
5896 struct iwl_priv
*priv
=
5897 container_of(data
, struct iwl_priv
, init_alive_start
.work
);
5899 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5902 mutex_lock(&priv
->mutex
);
5903 iwl3945_init_alive_start(priv
);
5904 mutex_unlock(&priv
->mutex
);
5907 static void iwl3945_bg_alive_start(struct work_struct
*data
)
5909 struct iwl_priv
*priv
=
5910 container_of(data
, struct iwl_priv
, alive_start
.work
);
5912 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5915 mutex_lock(&priv
->mutex
);
5916 iwl3945_alive_start(priv
);
5917 mutex_unlock(&priv
->mutex
);
5920 static void iwl3945_bg_rf_kill(struct work_struct
*work
)
5922 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, rf_kill
);
5924 wake_up_interruptible(&priv
->wait_command_queue
);
5926 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5929 mutex_lock(&priv
->mutex
);
5931 if (!iwl3945_is_rfkill(priv
)) {
5932 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
,
5933 "HW and/or SW RF Kill no longer active, restarting "
5935 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5936 queue_work(priv
->workqueue
, &priv
->restart
);
5939 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
5940 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
5941 "disabled by SW switch\n");
5943 IWL_WARN(priv
, "Radio Frequency Kill Switch is On:\n"
5944 "Kill switch must be turned off for "
5945 "wireless networking to work.\n");
5948 mutex_unlock(&priv
->mutex
);
5949 iwl3945_rfkill_set_hw_state(priv
);
5952 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
5954 static void iwl3945_bg_scan_check(struct work_struct
*data
)
5956 struct iwl_priv
*priv
=
5957 container_of(data
, struct iwl_priv
, scan_check
.work
);
5959 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5962 mutex_lock(&priv
->mutex
);
5963 if (test_bit(STATUS_SCANNING
, &priv
->status
) ||
5964 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
5965 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
,
5966 "Scan completion watchdog resetting adapter (%dms)\n",
5967 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG
));
5969 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5970 iwl3945_send_scan_abort(priv
);
5972 mutex_unlock(&priv
->mutex
);
5975 static void iwl3945_bg_request_scan(struct work_struct
*data
)
5977 struct iwl_priv
*priv
=
5978 container_of(data
, struct iwl_priv
, request_scan
);
5979 struct iwl_host_cmd cmd
= {
5980 .id
= REPLY_SCAN_CMD
,
5981 .len
= sizeof(struct iwl3945_scan_cmd
),
5982 .meta
.flags
= CMD_SIZE_HUGE
,
5985 struct iwl3945_scan_cmd
*scan
;
5986 struct ieee80211_conf
*conf
= NULL
;
5988 enum ieee80211_band band
;
5989 DECLARE_SSID_BUF(ssid
);
5991 conf
= ieee80211_get_hw_conf(priv
->hw
);
5993 mutex_lock(&priv
->mutex
);
5995 if (!iwl3945_is_ready(priv
)) {
5996 IWL_WARN(priv
, "request scan called when driver not ready.\n");
6000 /* Make sure the scan wasn't canceled before this queued work
6001 * was given the chance to run... */
6002 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
6005 /* This should never be called or scheduled if there is currently
6006 * a scan active in the hardware. */
6007 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
6008 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
6009 "Ignoring second request.\n");
6014 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
6015 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
6019 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
6020 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6024 if (iwl3945_is_rfkill(priv
)) {
6025 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6029 if (!test_bit(STATUS_READY
, &priv
->status
)) {
6030 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
6034 if (!priv
->scan_bands
) {
6035 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
6039 if (!priv
->scan39
) {
6040 priv
->scan39
= kmalloc(sizeof(struct iwl3945_scan_cmd
) +
6041 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
6042 if (!priv
->scan39
) {
6047 scan
= priv
->scan39
;
6048 memset(scan
, 0, sizeof(struct iwl3945_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
6050 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
6051 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
6053 if (iwl3945_is_associated(priv
)) {
6056 u32 suspend_time
= 100;
6057 u32 scan_suspend_time
= 100;
6058 unsigned long flags
;
6060 IWL_DEBUG_INFO("Scanning while associated...\n");
6062 spin_lock_irqsave(&priv
->lock
, flags
);
6063 interval
= priv
->beacon_int
;
6064 spin_unlock_irqrestore(&priv
->lock
, flags
);
6066 scan
->suspend_time
= 0;
6067 scan
->max_out_time
= cpu_to_le32(200 * 1024);
6069 interval
= suspend_time
;
6071 * suspend time format:
6072 * 0-19: beacon interval in usec (time before exec.)
6074 * 24-31: number of beacons (suspend between channels)
6077 extra
= (suspend_time
/ interval
) << 24;
6078 scan_suspend_time
= 0xFF0FFFFF &
6079 (extra
| ((suspend_time
% interval
) * 1024));
6081 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
6082 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
6083 scan_suspend_time
, interval
);
6086 /* We should add the ability for user to lock to PASSIVE ONLY */
6087 if (priv
->one_direct_scan
) {
6089 ("Kicking off one direct scan for '%s'\n",
6090 print_ssid(ssid
, priv
->direct_ssid
,
6091 priv
->direct_ssid_len
));
6092 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
6093 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
6094 memcpy(scan
->direct_scan
[0].ssid
,
6095 priv
->direct_ssid
, priv
->direct_ssid_len
);
6098 IWL_DEBUG_SCAN("Kicking off one indirect scan.\n");
6100 /* We don't build a direct scan probe request; the uCode will do
6101 * that based on the direct_mask added to each channel entry */
6102 scan
->tx_cmd
.len
= cpu_to_le16(
6103 iwl3945_fill_probe_req(priv
, (struct ieee80211_mgmt
*)scan
->data
,
6104 IWL_MAX_SCAN_SIZE
- sizeof(*scan
)));
6105 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
6106 scan
->tx_cmd
.sta_id
= priv
->hw_params
.bcast_sta_id
;
6107 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
6109 /* flags + rate selection */
6111 if (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
)) {
6112 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
6113 scan
->tx_cmd
.rate
= IWL_RATE_1M_PLCP
;
6114 scan
->good_CRC_th
= 0;
6115 band
= IEEE80211_BAND_2GHZ
;
6116 } else if (priv
->scan_bands
& BIT(IEEE80211_BAND_5GHZ
)) {
6117 scan
->tx_cmd
.rate
= IWL_RATE_6M_PLCP
;
6118 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
6119 band
= IEEE80211_BAND_5GHZ
;
6121 IWL_WARN(priv
, "Invalid scan band count\n");
6125 /* select Rx antennas */
6126 scan
->flags
|= iwl3945_get_antenna_flags(priv
);
6128 if (priv
->iw_mode
== NL80211_IFTYPE_MONITOR
)
6129 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
6131 scan
->channel_count
=
6132 iwl3945_get_channels_for_scan(priv
, band
, 1, /* active */
6134 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
6136 if (scan
->channel_count
== 0) {
6137 IWL_DEBUG_SCAN("channel count %d\n", scan
->channel_count
);
6141 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
6142 scan
->channel_count
* sizeof(struct iwl3945_scan_channel
);
6144 scan
->len
= cpu_to_le16(cmd
.len
);
6146 set_bit(STATUS_SCAN_HW
, &priv
->status
);
6147 rc
= iwl3945_send_cmd_sync(priv
, &cmd
);
6151 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
6152 IWL_SCAN_CHECK_WATCHDOG
);
6154 mutex_unlock(&priv
->mutex
);
6158 /* can not perform scan make sure we clear scanning
6159 * bits from status so next scan request can be performed.
6160 * if we dont clear scanning status bit here all next scan
6163 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
6164 clear_bit(STATUS_SCANNING
, &priv
->status
);
6166 /* inform mac80211 scan aborted */
6167 queue_work(priv
->workqueue
, &priv
->scan_completed
);
6168 mutex_unlock(&priv
->mutex
);
6171 static void iwl3945_bg_up(struct work_struct
*data
)
6173 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, up
);
6175 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6178 mutex_lock(&priv
->mutex
);
6180 mutex_unlock(&priv
->mutex
);
6181 iwl3945_rfkill_set_hw_state(priv
);
6184 static void iwl3945_bg_restart(struct work_struct
*data
)
6186 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
6188 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6192 queue_work(priv
->workqueue
, &priv
->up
);
6195 static void iwl3945_bg_rx_replenish(struct work_struct
*data
)
6197 struct iwl_priv
*priv
=
6198 container_of(data
, struct iwl_priv
, rx_replenish
);
6200 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6203 mutex_lock(&priv
->mutex
);
6204 iwl3945_rx_replenish(priv
);
6205 mutex_unlock(&priv
->mutex
);
6208 #define IWL_DELAY_NEXT_SCAN (HZ*2)
6210 static void iwl3945_post_associate(struct iwl_priv
*priv
)
6213 struct ieee80211_conf
*conf
= NULL
;
6215 if (priv
->iw_mode
== NL80211_IFTYPE_AP
) {
6216 IWL_ERR(priv
, "%s Should not be called in AP mode\n", __func__
);
6221 IWL_DEBUG_ASSOC("Associated as %d to: %pM\n",
6222 priv
->assoc_id
, priv
->active39_rxon
.bssid_addr
);
6224 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6227 if (!priv
->vif
|| !priv
->is_open
)
6230 iwl3945_scan_cancel_timeout(priv
, 200);
6232 conf
= ieee80211_get_hw_conf(priv
->hw
);
6234 priv
->staging39_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6235 iwl3945_commit_rxon(priv
);
6237 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl_rxon_time_cmd
));
6238 iwl3945_setup_rxon_timing(priv
);
6239 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
6240 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
6242 IWL_WARN(priv
, "REPLY_RXON_TIMING failed - "
6243 "Attempting to continue.\n");
6245 priv
->staging39_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
6247 priv
->staging39_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6249 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
6250 priv
->assoc_id
, priv
->beacon_int
);
6252 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6253 priv
->staging39_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
6255 priv
->staging39_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6257 if (priv
->staging39_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6258 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6259 priv
->staging39_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
6261 priv
->staging39_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6263 if (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
)
6264 priv
->staging39_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6268 iwl3945_commit_rxon(priv
);
6270 switch (priv
->iw_mode
) {
6271 case NL80211_IFTYPE_STATION
:
6272 iwl3945_rate_scale_init(priv
->hw
, IWL_AP_ID
);
6275 case NL80211_IFTYPE_ADHOC
:
6278 iwl3945_add_station(priv
, priv
->bssid
, 0, 0);
6279 iwl3945_sync_sta(priv
, IWL_STA_ID
,
6280 (priv
->band
== IEEE80211_BAND_5GHZ
) ?
6281 IWL_RATE_6M_PLCP
: IWL_RATE_1M_PLCP
,
6283 iwl3945_rate_scale_init(priv
->hw
, IWL_STA_ID
);
6284 iwl3945_send_beacon_cmd(priv
);
6289 IWL_ERR(priv
, "%s Should not be called in %d mode\n",
6290 __func__
, priv
->iw_mode
);
6294 iwl3945_activate_qos(priv
, 0);
6296 /* we have just associated, don't start scan too early */
6297 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
6300 static void iwl3945_bg_abort_scan(struct work_struct
*work
)
6302 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, abort_scan
);
6304 if (!iwl3945_is_ready(priv
))
6307 mutex_lock(&priv
->mutex
);
6309 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
6310 iwl3945_send_scan_abort(priv
);
6312 mutex_unlock(&priv
->mutex
);
6315 static int iwl3945_mac_config(struct ieee80211_hw
*hw
, u32 changed
);
6317 static void iwl3945_bg_scan_completed(struct work_struct
*work
)
6319 struct iwl_priv
*priv
=
6320 container_of(work
, struct iwl_priv
, scan_completed
);
6322 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
, "SCAN complete scan\n");
6324 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6327 if (test_bit(STATUS_CONF_PENDING
, &priv
->status
))
6328 iwl3945_mac_config(priv
->hw
, 0);
6330 ieee80211_scan_completed(priv
->hw
);
6332 /* Since setting the TXPOWER may have been deferred while
6333 * performing the scan, fire one off */
6334 mutex_lock(&priv
->mutex
);
6335 iwl3945_hw_reg_send_txpower(priv
);
6336 mutex_unlock(&priv
->mutex
);
6339 /*****************************************************************************
6341 * mac80211 entry point functions
6343 *****************************************************************************/
6345 #define UCODE_READY_TIMEOUT (2 * HZ)
6347 static int iwl3945_mac_start(struct ieee80211_hw
*hw
)
6349 struct iwl_priv
*priv
= hw
->priv
;
6352 IWL_DEBUG_MAC80211("enter\n");
6354 if (pci_enable_device(priv
->pci_dev
)) {
6355 IWL_ERR(priv
, "Fail to pci_enable_device\n");
6358 pci_restore_state(priv
->pci_dev
);
6359 pci_enable_msi(priv
->pci_dev
);
6361 ret
= request_irq(priv
->pci_dev
->irq
, iwl3945_isr
, IRQF_SHARED
,
6364 IWL_ERR(priv
, "Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
6365 goto out_disable_msi
;
6368 /* we should be verifying the device is ready to be opened */
6369 mutex_lock(&priv
->mutex
);
6371 memset(&priv
->staging39_rxon
, 0, sizeof(struct iwl3945_rxon_cmd
));
6372 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
6373 * ucode filename and max sizes are card-specific. */
6375 if (!priv
->ucode_code
.len
) {
6376 ret
= iwl3945_read_ucode(priv
);
6378 IWL_ERR(priv
, "Could not read microcode: %d\n", ret
);
6379 mutex_unlock(&priv
->mutex
);
6380 goto out_release_irq
;
6384 ret
= __iwl3945_up(priv
);
6386 mutex_unlock(&priv
->mutex
);
6388 iwl3945_rfkill_set_hw_state(priv
);
6391 goto out_release_irq
;
6393 IWL_DEBUG_INFO("Start UP work.\n");
6395 if (test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
6398 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
6399 * mac80211 will not be run successfully. */
6400 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
6401 test_bit(STATUS_READY
, &priv
->status
),
6402 UCODE_READY_TIMEOUT
);
6404 if (!test_bit(STATUS_READY
, &priv
->status
)) {
6406 "Wait for START_ALIVE timeout after %dms.\n",
6407 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
6409 goto out_release_irq
;
6414 IWL_DEBUG_MAC80211("leave\n");
6418 free_irq(priv
->pci_dev
->irq
, priv
);
6420 pci_disable_msi(priv
->pci_dev
);
6421 pci_disable_device(priv
->pci_dev
);
6423 IWL_DEBUG_MAC80211("leave - failed\n");
6427 static void iwl3945_mac_stop(struct ieee80211_hw
*hw
)
6429 struct iwl_priv
*priv
= hw
->priv
;
6431 IWL_DEBUG_MAC80211("enter\n");
6433 if (!priv
->is_open
) {
6434 IWL_DEBUG_MAC80211("leave - skip\n");
6440 if (iwl3945_is_ready_rf(priv
)) {
6441 /* stop mac, cancel any scan request and clear
6442 * RXON_FILTER_ASSOC_MSK BIT
6444 mutex_lock(&priv
->mutex
);
6445 iwl3945_scan_cancel_timeout(priv
, 100);
6446 mutex_unlock(&priv
->mutex
);
6451 flush_workqueue(priv
->workqueue
);
6452 free_irq(priv
->pci_dev
->irq
, priv
);
6453 pci_disable_msi(priv
->pci_dev
);
6454 pci_save_state(priv
->pci_dev
);
6455 pci_disable_device(priv
->pci_dev
);
6457 IWL_DEBUG_MAC80211("leave\n");
6460 static int iwl3945_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
6462 struct iwl_priv
*priv
= hw
->priv
;
6464 IWL_DEBUG_MAC80211("enter\n");
6466 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
6467 ieee80211_get_tx_rate(hw
, IEEE80211_SKB_CB(skb
))->bitrate
);
6469 if (iwl3945_tx_skb(priv
, skb
))
6470 dev_kfree_skb_any(skb
);
6472 IWL_DEBUG_MAC80211("leave\n");
6473 return NETDEV_TX_OK
;
6476 static int iwl3945_mac_add_interface(struct ieee80211_hw
*hw
,
6477 struct ieee80211_if_init_conf
*conf
)
6479 struct iwl_priv
*priv
= hw
->priv
;
6480 unsigned long flags
;
6482 IWL_DEBUG_MAC80211("enter: type %d\n", conf
->type
);
6485 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
6489 spin_lock_irqsave(&priv
->lock
, flags
);
6490 priv
->vif
= conf
->vif
;
6491 priv
->iw_mode
= conf
->type
;
6493 spin_unlock_irqrestore(&priv
->lock
, flags
);
6495 mutex_lock(&priv
->mutex
);
6497 if (conf
->mac_addr
) {
6498 IWL_DEBUG_MAC80211("Set: %pM\n", conf
->mac_addr
);
6499 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
6502 if (iwl3945_is_ready(priv
))
6503 iwl3945_set_mode(priv
, conf
->type
);
6505 mutex_unlock(&priv
->mutex
);
6507 IWL_DEBUG_MAC80211("leave\n");
6512 * iwl3945_mac_config - mac80211 config callback
6514 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
6515 * be set inappropriately and the driver currently sets the hardware up to
6516 * use it whenever needed.
6518 static int iwl3945_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
6520 struct iwl_priv
*priv
= hw
->priv
;
6521 const struct iwl_channel_info
*ch_info
;
6522 struct ieee80211_conf
*conf
= &hw
->conf
;
6523 unsigned long flags
;
6526 mutex_lock(&priv
->mutex
);
6527 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
->hw_value
);
6529 if (!iwl3945_is_ready(priv
)) {
6530 IWL_DEBUG_MAC80211("leave - not ready\n");
6535 if (unlikely(!iwl3945_param_disable_hw_scan
&&
6536 test_bit(STATUS_SCANNING
, &priv
->status
))) {
6537 IWL_DEBUG_MAC80211("leave - scanning\n");
6538 set_bit(STATUS_CONF_PENDING
, &priv
->status
);
6539 mutex_unlock(&priv
->mutex
);
6543 spin_lock_irqsave(&priv
->lock
, flags
);
6545 ch_info
= iwl3945_get_channel_info(priv
, conf
->channel
->band
,
6546 conf
->channel
->hw_value
);
6547 if (!is_channel_valid(ch_info
)) {
6548 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this band.\n",
6549 conf
->channel
->hw_value
, conf
->channel
->band
);
6550 IWL_DEBUG_MAC80211("leave - invalid channel\n");
6551 spin_unlock_irqrestore(&priv
->lock
, flags
);
6556 iwl3945_set_rxon_channel(priv
, conf
->channel
->band
, conf
->channel
->hw_value
);
6558 iwl3945_set_flags_for_phymode(priv
, conf
->channel
->band
);
6560 /* The list of supported rates and rate mask can be different
6561 * for each phymode; since the phymode may have changed, reset
6562 * the rate mask to what mac80211 lists */
6563 iwl3945_set_rate(priv
);
6565 spin_unlock_irqrestore(&priv
->lock
, flags
);
6567 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6568 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
6569 iwl3945_hw_channel_switch(priv
, conf
->channel
);
6574 iwl3945_radio_kill_sw(priv
, !conf
->radio_enabled
);
6576 if (!conf
->radio_enabled
) {
6577 IWL_DEBUG_MAC80211("leave - radio disabled\n");
6581 if (iwl3945_is_rfkill(priv
)) {
6582 IWL_DEBUG_MAC80211("leave - RF kill\n");
6587 iwl3945_set_rate(priv
);
6589 if (memcmp(&priv
->active39_rxon
,
6590 &priv
->staging39_rxon
, sizeof(priv
->staging39_rxon
)))
6591 iwl3945_commit_rxon(priv
);
6593 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
6595 IWL_DEBUG_MAC80211("leave\n");
6598 clear_bit(STATUS_CONF_PENDING
, &priv
->status
);
6599 mutex_unlock(&priv
->mutex
);
6603 static void iwl3945_config_ap(struct iwl_priv
*priv
)
6607 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6610 /* The following should be done only at AP bring up */
6611 if (!(iwl3945_is_associated(priv
))) {
6613 /* RXON - unassoc (to set timing command) */
6614 priv
->staging39_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6615 iwl3945_commit_rxon(priv
);
6618 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl_rxon_time_cmd
));
6619 iwl3945_setup_rxon_timing(priv
);
6620 rc
= iwl3945_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
6621 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
6623 IWL_WARN(priv
, "REPLY_RXON_TIMING failed - "
6624 "Attempting to continue.\n");
6626 /* FIXME: what should be the assoc_id for AP? */
6627 priv
->staging39_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6628 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6629 priv
->staging39_rxon
.flags
|=
6630 RXON_FLG_SHORT_PREAMBLE_MSK
;
6632 priv
->staging39_rxon
.flags
&=
6633 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6635 if (priv
->staging39_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6636 if (priv
->assoc_capability
&
6637 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6638 priv
->staging39_rxon
.flags
|=
6639 RXON_FLG_SHORT_SLOT_MSK
;
6641 priv
->staging39_rxon
.flags
&=
6642 ~RXON_FLG_SHORT_SLOT_MSK
;
6644 if (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
)
6645 priv
->staging39_rxon
.flags
&=
6646 ~RXON_FLG_SHORT_SLOT_MSK
;
6648 /* restore RXON assoc */
6649 priv
->staging39_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
6650 iwl3945_commit_rxon(priv
);
6651 iwl3945_add_station(priv
, iwl_bcast_addr
, 0, 0);
6653 iwl3945_send_beacon_cmd(priv
);
6655 /* FIXME - we need to add code here to detect a totally new
6656 * configuration, reset the AP, unassoc, rxon timing, assoc,
6657 * clear sta table, add BCAST sta... */
6660 static int iwl3945_mac_config_interface(struct ieee80211_hw
*hw
,
6661 struct ieee80211_vif
*vif
,
6662 struct ieee80211_if_conf
*conf
)
6664 struct iwl_priv
*priv
= hw
->priv
;
6670 if (priv
->vif
!= vif
) {
6671 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
6675 /* handle this temporarily here */
6676 if (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
&&
6677 conf
->changed
& IEEE80211_IFCC_BEACON
) {
6678 struct sk_buff
*beacon
= ieee80211_beacon_get(hw
, vif
);
6681 mutex_lock(&priv
->mutex
);
6682 rc
= iwl3945_mac_beacon_update(hw
, beacon
);
6683 mutex_unlock(&priv
->mutex
);
6688 if (!iwl3945_is_alive(priv
))
6691 mutex_lock(&priv
->mutex
);
6694 IWL_DEBUG_MAC80211("bssid: %pM\n", conf
->bssid
);
6697 * very dubious code was here; the probe filtering flag is never set:
6699 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
6700 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
6703 if (priv
->iw_mode
== NL80211_IFTYPE_AP
) {
6705 conf
->bssid
= priv
->mac_addr
;
6706 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
6707 IWL_DEBUG_MAC80211("bssid was set to: %pM\n",
6710 if (priv
->ibss_beacon
)
6711 dev_kfree_skb(priv
->ibss_beacon
);
6713 priv
->ibss_beacon
= ieee80211_beacon_get(hw
, vif
);
6716 if (iwl3945_is_rfkill(priv
))
6719 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
6720 !is_multicast_ether_addr(conf
->bssid
)) {
6721 /* If there is currently a HW scan going on in the background
6722 * then we need to cancel it else the RXON below will fail. */
6723 if (iwl3945_scan_cancel_timeout(priv
, 100)) {
6724 IWL_WARN(priv
, "Aborted scan still in progress "
6726 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
6727 mutex_unlock(&priv
->mutex
);
6730 memcpy(priv
->staging39_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
6732 /* TODO: Audit driver for usage of these members and see
6733 * if mac80211 deprecates them (priv->bssid looks like it
6734 * shouldn't be there, but I haven't scanned the IBSS code
6735 * to verify) - jpk */
6736 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
6738 if (priv
->iw_mode
== NL80211_IFTYPE_AP
)
6739 iwl3945_config_ap(priv
);
6741 rc
= iwl3945_commit_rxon(priv
);
6742 if ((priv
->iw_mode
== NL80211_IFTYPE_STATION
) && rc
)
6743 iwl3945_add_station(priv
,
6744 priv
->active39_rxon
.bssid_addr
, 1, 0);
6748 iwl3945_scan_cancel_timeout(priv
, 100);
6749 priv
->staging39_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6750 iwl3945_commit_rxon(priv
);
6754 IWL_DEBUG_MAC80211("leave\n");
6755 mutex_unlock(&priv
->mutex
);
6760 static void iwl3945_configure_filter(struct ieee80211_hw
*hw
,
6761 unsigned int changed_flags
,
6762 unsigned int *total_flags
,
6763 int mc_count
, struct dev_addr_list
*mc_list
)
6765 struct iwl_priv
*priv
= hw
->priv
;
6766 __le32
*filter_flags
= &priv
->staging39_rxon
.filter_flags
;
6768 IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
6769 changed_flags
, *total_flags
);
6771 if (changed_flags
& (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
)) {
6772 if (*total_flags
& (FIF_OTHER_BSS
| FIF_PROMISC_IN_BSS
))
6773 *filter_flags
|= RXON_FILTER_PROMISC_MSK
;
6775 *filter_flags
&= ~RXON_FILTER_PROMISC_MSK
;
6777 if (changed_flags
& FIF_ALLMULTI
) {
6778 if (*total_flags
& FIF_ALLMULTI
)
6779 *filter_flags
|= RXON_FILTER_ACCEPT_GRP_MSK
;
6781 *filter_flags
&= ~RXON_FILTER_ACCEPT_GRP_MSK
;
6783 if (changed_flags
& FIF_CONTROL
) {
6784 if (*total_flags
& FIF_CONTROL
)
6785 *filter_flags
|= RXON_FILTER_CTL2HOST_MSK
;
6787 *filter_flags
&= ~RXON_FILTER_CTL2HOST_MSK
;
6789 if (changed_flags
& FIF_BCN_PRBRESP_PROMISC
) {
6790 if (*total_flags
& FIF_BCN_PRBRESP_PROMISC
)
6791 *filter_flags
|= RXON_FILTER_BCON_AWARE_MSK
;
6793 *filter_flags
&= ~RXON_FILTER_BCON_AWARE_MSK
;
6796 /* We avoid iwl_commit_rxon here to commit the new filter flags
6797 * since mac80211 will call ieee80211_hw_config immediately.
6798 * (mc_list is not supported at this time). Otherwise, we need to
6799 * queue a background iwl_commit_rxon work.
6802 *total_flags
&= FIF_OTHER_BSS
| FIF_ALLMULTI
| FIF_PROMISC_IN_BSS
|
6803 FIF_BCN_PRBRESP_PROMISC
| FIF_CONTROL
;
6806 static void iwl3945_mac_remove_interface(struct ieee80211_hw
*hw
,
6807 struct ieee80211_if_init_conf
*conf
)
6809 struct iwl_priv
*priv
= hw
->priv
;
6811 IWL_DEBUG_MAC80211("enter\n");
6813 mutex_lock(&priv
->mutex
);
6815 if (iwl3945_is_ready_rf(priv
)) {
6816 iwl3945_scan_cancel_timeout(priv
, 100);
6817 priv
->staging39_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6818 iwl3945_commit_rxon(priv
);
6820 if (priv
->vif
== conf
->vif
) {
6822 memset(priv
->bssid
, 0, ETH_ALEN
);
6824 mutex_unlock(&priv
->mutex
);
6826 IWL_DEBUG_MAC80211("leave\n");
6829 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
6831 static void iwl3945_bss_info_changed(struct ieee80211_hw
*hw
,
6832 struct ieee80211_vif
*vif
,
6833 struct ieee80211_bss_conf
*bss_conf
,
6836 struct iwl_priv
*priv
= hw
->priv
;
6838 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes
);
6840 if (changes
& BSS_CHANGED_ERP_PREAMBLE
) {
6841 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
6842 bss_conf
->use_short_preamble
);
6843 if (bss_conf
->use_short_preamble
)
6844 priv
->staging39_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
6846 priv
->staging39_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6849 if (changes
& BSS_CHANGED_ERP_CTS_PROT
) {
6850 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf
->use_cts_prot
);
6851 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
6852 priv
->staging39_rxon
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
6854 priv
->staging39_rxon
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
6857 if (changes
& BSS_CHANGED_ASSOC
) {
6858 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf
->assoc
);
6859 /* This should never happen as this function should
6860 * never be called from interrupt context. */
6861 if (WARN_ON_ONCE(in_interrupt()))
6863 if (bss_conf
->assoc
) {
6864 priv
->assoc_id
= bss_conf
->aid
;
6865 priv
->beacon_int
= bss_conf
->beacon_int
;
6866 priv
->timestamp
= bss_conf
->timestamp
;
6867 priv
->assoc_capability
= bss_conf
->assoc_capability
;
6868 priv
->next_scan_jiffies
= jiffies
+
6869 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC
;
6870 mutex_lock(&priv
->mutex
);
6871 iwl3945_post_associate(priv
);
6872 mutex_unlock(&priv
->mutex
);
6875 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf
->assoc
);
6877 } else if (changes
&& iwl3945_is_associated(priv
) && priv
->assoc_id
) {
6878 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes
);
6879 iwl3945_send_rxon_assoc(priv
);
6884 static int iwl3945_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
6887 unsigned long flags
;
6888 struct iwl_priv
*priv
= hw
->priv
;
6889 DECLARE_SSID_BUF(ssid_buf
);
6891 IWL_DEBUG_MAC80211("enter\n");
6893 mutex_lock(&priv
->mutex
);
6894 spin_lock_irqsave(&priv
->lock
, flags
);
6896 if (!iwl3945_is_ready_rf(priv
)) {
6898 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
6902 /* we don't schedule scan within next_scan_jiffies period */
6903 if (priv
->next_scan_jiffies
&&
6904 time_after(priv
->next_scan_jiffies
, jiffies
)) {
6908 /* if we just finished scan ask for delay for a broadcast scan */
6909 if ((len
== 0) && priv
->last_scan_jiffies
&&
6910 time_after(priv
->last_scan_jiffies
+ IWL_DELAY_NEXT_SCAN
,
6916 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
6917 print_ssid(ssid_buf
, ssid
, len
), (int)len
);
6919 priv
->one_direct_scan
= 1;
6920 priv
->direct_ssid_len
= (u8
)
6921 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
6922 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
6924 priv
->one_direct_scan
= 0;
6926 rc
= iwl3945_scan_initiate(priv
);
6928 IWL_DEBUG_MAC80211("leave\n");
6931 spin_unlock_irqrestore(&priv
->lock
, flags
);
6932 mutex_unlock(&priv
->mutex
);
6937 static int iwl3945_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
6938 const u8
*local_addr
, const u8
*addr
,
6939 struct ieee80211_key_conf
*key
)
6941 struct iwl_priv
*priv
= hw
->priv
;
6945 IWL_DEBUG_MAC80211("enter\n");
6947 if (!iwl3945_param_hwcrypto
) {
6948 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
6952 if (is_zero_ether_addr(addr
))
6953 /* only support pairwise keys */
6956 sta_id
= iwl3945_hw_find_station(priv
, addr
);
6957 if (sta_id
== IWL_INVALID_STATION
) {
6958 IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
6963 mutex_lock(&priv
->mutex
);
6965 iwl3945_scan_cancel_timeout(priv
, 100);
6969 rc
= iwl3945_update_sta_key_info(priv
, key
, sta_id
);
6971 iwl3945_set_rxon_hwcrypto(priv
, 1);
6972 iwl3945_commit_rxon(priv
);
6973 key
->hw_key_idx
= sta_id
;
6974 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
6975 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
6979 rc
= iwl3945_clear_sta_key_info(priv
, sta_id
);
6981 iwl3945_set_rxon_hwcrypto(priv
, 0);
6982 iwl3945_commit_rxon(priv
);
6983 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
6990 IWL_DEBUG_MAC80211("leave\n");
6991 mutex_unlock(&priv
->mutex
);
6996 static int iwl3945_mac_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
6997 const struct ieee80211_tx_queue_params
*params
)
6999 struct iwl_priv
*priv
= hw
->priv
;
7000 unsigned long flags
;
7003 IWL_DEBUG_MAC80211("enter\n");
7005 if (!iwl3945_is_ready_rf(priv
)) {
7006 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7010 if (queue
>= AC_NUM
) {
7011 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
7015 q
= AC_NUM
- 1 - queue
;
7017 spin_lock_irqsave(&priv
->lock
, flags
);
7019 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
7020 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
7021 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
7022 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
7023 cpu_to_le16((params
->txop
* 32));
7025 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
7026 priv
->qos_data
.qos_active
= 1;
7028 spin_unlock_irqrestore(&priv
->lock
, flags
);
7030 mutex_lock(&priv
->mutex
);
7031 if (priv
->iw_mode
== NL80211_IFTYPE_AP
)
7032 iwl3945_activate_qos(priv
, 1);
7033 else if (priv
->assoc_id
&& iwl3945_is_associated(priv
))
7034 iwl3945_activate_qos(priv
, 0);
7036 mutex_unlock(&priv
->mutex
);
7038 IWL_DEBUG_MAC80211("leave\n");
7042 static int iwl3945_mac_get_tx_stats(struct ieee80211_hw
*hw
,
7043 struct ieee80211_tx_queue_stats
*stats
)
7045 struct iwl_priv
*priv
= hw
->priv
;
7047 struct iwl3945_tx_queue
*txq
;
7048 struct iwl_queue
*q
;
7049 unsigned long flags
;
7051 IWL_DEBUG_MAC80211("enter\n");
7053 if (!iwl3945_is_ready_rf(priv
)) {
7054 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7058 spin_lock_irqsave(&priv
->lock
, flags
);
7060 for (i
= 0; i
< AC_NUM
; i
++) {
7061 txq
= &priv
->txq39
[i
];
7063 avail
= iwl_queue_space(q
);
7065 stats
[i
].len
= q
->n_window
- avail
;
7066 stats
[i
].limit
= q
->n_window
- q
->high_mark
;
7067 stats
[i
].count
= q
->n_window
;
7070 spin_unlock_irqrestore(&priv
->lock
, flags
);
7072 IWL_DEBUG_MAC80211("leave\n");
7077 static void iwl3945_mac_reset_tsf(struct ieee80211_hw
*hw
)
7079 struct iwl_priv
*priv
= hw
->priv
;
7080 unsigned long flags
;
7082 mutex_lock(&priv
->mutex
);
7083 IWL_DEBUG_MAC80211("enter\n");
7085 iwl3945_reset_qos(priv
);
7087 spin_lock_irqsave(&priv
->lock
, flags
);
7089 priv
->assoc_capability
= 0;
7090 priv
->call_post_assoc_from_beacon
= 0;
7092 /* new association get rid of ibss beacon skb */
7093 if (priv
->ibss_beacon
)
7094 dev_kfree_skb(priv
->ibss_beacon
);
7096 priv
->ibss_beacon
= NULL
;
7098 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
7099 priv
->timestamp
= 0;
7100 if ((priv
->iw_mode
== NL80211_IFTYPE_STATION
))
7101 priv
->beacon_int
= 0;
7103 spin_unlock_irqrestore(&priv
->lock
, flags
);
7105 if (!iwl3945_is_ready_rf(priv
)) {
7106 IWL_DEBUG_MAC80211("leave - not ready\n");
7107 mutex_unlock(&priv
->mutex
);
7111 /* we are restarting association process
7112 * clear RXON_FILTER_ASSOC_MSK bit
7114 if (priv
->iw_mode
!= NL80211_IFTYPE_AP
) {
7115 iwl3945_scan_cancel_timeout(priv
, 100);
7116 priv
->staging39_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7117 iwl3945_commit_rxon(priv
);
7120 /* Per mac80211.h: This is only used in IBSS mode... */
7121 if (priv
->iw_mode
!= NL80211_IFTYPE_ADHOC
) {
7123 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7124 mutex_unlock(&priv
->mutex
);
7128 iwl3945_set_rate(priv
);
7130 mutex_unlock(&priv
->mutex
);
7132 IWL_DEBUG_MAC80211("leave\n");
7136 static int iwl3945_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
7138 struct iwl_priv
*priv
= hw
->priv
;
7139 unsigned long flags
;
7141 IWL_DEBUG_MAC80211("enter\n");
7143 if (!iwl3945_is_ready_rf(priv
)) {
7144 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7148 if (priv
->iw_mode
!= NL80211_IFTYPE_ADHOC
) {
7149 IWL_DEBUG_MAC80211("leave - not IBSS\n");
7153 spin_lock_irqsave(&priv
->lock
, flags
);
7155 if (priv
->ibss_beacon
)
7156 dev_kfree_skb(priv
->ibss_beacon
);
7158 priv
->ibss_beacon
= skb
;
7162 IWL_DEBUG_MAC80211("leave\n");
7163 spin_unlock_irqrestore(&priv
->lock
, flags
);
7165 iwl3945_reset_qos(priv
);
7167 iwl3945_post_associate(priv
);
7173 /*****************************************************************************
7177 *****************************************************************************/
7179 #ifdef CONFIG_IWL3945_DEBUG
7182 * The following adds a new attribute to the sysfs representation
7183 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
7184 * used for controlling the debug level.
7186 * See the level definitions in iwl for details.
7188 static ssize_t
show_debug_level(struct device
*d
,
7189 struct device_attribute
*attr
, char *buf
)
7191 struct iwl_priv
*priv
= d
->driver_data
;
7193 return sprintf(buf
, "0x%08X\n", priv
->debug_level
);
7195 static ssize_t
store_debug_level(struct device
*d
,
7196 struct device_attribute
*attr
,
7197 const char *buf
, size_t count
)
7199 struct iwl_priv
*priv
= d
->driver_data
;
7203 ret
= strict_strtoul(buf
, 0, &val
);
7205 IWL_INFO(priv
, "%s is not in hex or decimal form.\n", buf
);
7207 priv
->debug_level
= val
;
7209 return strnlen(buf
, count
);
7212 static DEVICE_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
7213 show_debug_level
, store_debug_level
);
7215 #endif /* CONFIG_IWL3945_DEBUG */
7217 static ssize_t
show_temperature(struct device
*d
,
7218 struct device_attribute
*attr
, char *buf
)
7220 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7222 if (!iwl3945_is_alive(priv
))
7225 return sprintf(buf
, "%d\n", iwl3945_hw_get_temperature(priv
));
7228 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
7230 static ssize_t
show_tx_power(struct device
*d
,
7231 struct device_attribute
*attr
, char *buf
)
7233 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7234 return sprintf(buf
, "%d\n", priv
->user_txpower_limit
);
7237 static ssize_t
store_tx_power(struct device
*d
,
7238 struct device_attribute
*attr
,
7239 const char *buf
, size_t count
)
7241 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7242 char *p
= (char *)buf
;
7245 val
= simple_strtoul(p
, &p
, 10);
7247 IWL_INFO(priv
, ": %s is not in decimal form.\n", buf
);
7249 iwl3945_hw_reg_set_txpower(priv
, val
);
7254 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
7256 static ssize_t
show_flags(struct device
*d
,
7257 struct device_attribute
*attr
, char *buf
)
7259 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7261 return sprintf(buf
, "0x%04X\n", priv
->active39_rxon
.flags
);
7264 static ssize_t
store_flags(struct device
*d
,
7265 struct device_attribute
*attr
,
7266 const char *buf
, size_t count
)
7268 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7269 u32 flags
= simple_strtoul(buf
, NULL
, 0);
7271 mutex_lock(&priv
->mutex
);
7272 if (le32_to_cpu(priv
->staging39_rxon
.flags
) != flags
) {
7273 /* Cancel any currently running scans... */
7274 if (iwl3945_scan_cancel_timeout(priv
, 100))
7275 IWL_WARN(priv
, "Could not cancel scan.\n");
7277 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
7279 priv
->staging39_rxon
.flags
= cpu_to_le32(flags
);
7280 iwl3945_commit_rxon(priv
);
7283 mutex_unlock(&priv
->mutex
);
7288 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
7290 static ssize_t
show_filter_flags(struct device
*d
,
7291 struct device_attribute
*attr
, char *buf
)
7293 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7295 return sprintf(buf
, "0x%04X\n",
7296 le32_to_cpu(priv
->active39_rxon
.filter_flags
));
7299 static ssize_t
store_filter_flags(struct device
*d
,
7300 struct device_attribute
*attr
,
7301 const char *buf
, size_t count
)
7303 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7304 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
7306 mutex_lock(&priv
->mutex
);
7307 if (le32_to_cpu(priv
->staging39_rxon
.filter_flags
) != filter_flags
) {
7308 /* Cancel any currently running scans... */
7309 if (iwl3945_scan_cancel_timeout(priv
, 100))
7310 IWL_WARN(priv
, "Could not cancel scan.\n");
7312 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
7313 "0x%04X\n", filter_flags
);
7314 priv
->staging39_rxon
.filter_flags
=
7315 cpu_to_le32(filter_flags
);
7316 iwl3945_commit_rxon(priv
);
7319 mutex_unlock(&priv
->mutex
);
7324 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
7325 store_filter_flags
);
7327 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
7329 static ssize_t
show_measurement(struct device
*d
,
7330 struct device_attribute
*attr
, char *buf
)
7332 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7333 struct iwl_spectrum_notification measure_report
;
7334 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
7335 u8
*data
= (u8
*)&measure_report
;
7336 unsigned long flags
;
7338 spin_lock_irqsave(&priv
->lock
, flags
);
7339 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
7340 spin_unlock_irqrestore(&priv
->lock
, flags
);
7343 memcpy(&measure_report
, &priv
->measure_report
, size
);
7344 priv
->measurement_status
= 0;
7345 spin_unlock_irqrestore(&priv
->lock
, flags
);
7347 while (size
&& (PAGE_SIZE
- len
)) {
7348 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7349 PAGE_SIZE
- len
, 1);
7351 if (PAGE_SIZE
- len
)
7355 size
-= min(size
, 16U);
7361 static ssize_t
store_measurement(struct device
*d
,
7362 struct device_attribute
*attr
,
7363 const char *buf
, size_t count
)
7365 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7366 struct ieee80211_measurement_params params
= {
7367 .channel
= le16_to_cpu(priv
->active39_rxon
.channel
),
7368 .start_time
= cpu_to_le64(priv
->last_tsf
),
7369 .duration
= cpu_to_le16(1),
7371 u8 type
= IWL_MEASURE_BASIC
;
7377 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
7378 channel
= simple_strtoul(p
, NULL
, 0);
7380 params
.channel
= channel
;
7383 while (*p
&& *p
!= ' ')
7386 type
= simple_strtoul(p
+ 1, NULL
, 0);
7389 IWL_DEBUG_INFO("Invoking measurement of type %d on "
7390 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
7391 iwl3945_get_measurement(priv
, ¶ms
, type
);
7396 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
7397 show_measurement
, store_measurement
);
7398 #endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
7400 static ssize_t
store_retry_rate(struct device
*d
,
7401 struct device_attribute
*attr
,
7402 const char *buf
, size_t count
)
7404 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7406 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
7407 if (priv
->retry_rate
<= 0)
7408 priv
->retry_rate
= 1;
7413 static ssize_t
show_retry_rate(struct device
*d
,
7414 struct device_attribute
*attr
, char *buf
)
7416 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7417 return sprintf(buf
, "%d", priv
->retry_rate
);
7420 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
7423 static ssize_t
store_power_level(struct device
*d
,
7424 struct device_attribute
*attr
,
7425 const char *buf
, size_t count
)
7427 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7431 mode
= simple_strtoul(buf
, NULL
, 0);
7432 mutex_lock(&priv
->mutex
);
7434 if (!iwl3945_is_ready(priv
)) {
7439 if ((mode
< 1) || (mode
> IWL39_POWER_LIMIT
) ||
7440 (mode
== IWL39_POWER_AC
))
7441 mode
= IWL39_POWER_AC
;
7443 mode
|= IWL_POWER_ENABLED
;
7445 if (mode
!= priv
->power_mode
) {
7446 rc
= iwl3945_send_power_mode(priv
, IWL_POWER_LEVEL(mode
));
7448 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7451 priv
->power_mode
= mode
;
7457 mutex_unlock(&priv
->mutex
);
7461 #define MAX_WX_STRING 80
7463 /* Values are in microsecond */
7464 static const s32 timeout_duration
[] = {
7471 static const s32 period_duration
[] = {
7479 static ssize_t
show_power_level(struct device
*d
,
7480 struct device_attribute
*attr
, char *buf
)
7482 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7483 int level
= IWL_POWER_LEVEL(priv
->power_mode
);
7486 p
+= sprintf(p
, "%d ", level
);
7488 case IWL_POWER_MODE_CAM
:
7489 case IWL39_POWER_AC
:
7490 p
+= sprintf(p
, "(AC)");
7492 case IWL39_POWER_BATTERY
:
7493 p
+= sprintf(p
, "(BATTERY)");
7497 "(Timeout %dms, Period %dms)",
7498 timeout_duration
[level
- 1] / 1000,
7499 period_duration
[level
- 1] / 1000);
7502 if (!(priv
->power_mode
& IWL_POWER_ENABLED
))
7503 p
+= sprintf(p
, " OFF\n");
7505 p
+= sprintf(p
, " \n");
7511 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
7514 static ssize_t
show_channels(struct device
*d
,
7515 struct device_attribute
*attr
, char *buf
)
7517 /* all this shit doesn't belong into sysfs anyway */
7521 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
7523 static ssize_t
show_statistics(struct device
*d
,
7524 struct device_attribute
*attr
, char *buf
)
7526 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7527 u32 size
= sizeof(struct iwl3945_notif_statistics
);
7528 u32 len
= 0, ofs
= 0;
7529 u8
*data
= (u8
*)&priv
->statistics_39
;
7532 if (!iwl3945_is_alive(priv
))
7535 mutex_lock(&priv
->mutex
);
7536 rc
= iwl3945_send_statistics_request(priv
);
7537 mutex_unlock(&priv
->mutex
);
7541 "Error sending statistics request: 0x%08X\n", rc
);
7545 while (size
&& (PAGE_SIZE
- len
)) {
7546 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7547 PAGE_SIZE
- len
, 1);
7549 if (PAGE_SIZE
- len
)
7553 size
-= min(size
, 16U);
7559 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
7561 static ssize_t
show_antenna(struct device
*d
,
7562 struct device_attribute
*attr
, char *buf
)
7564 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7566 if (!iwl3945_is_alive(priv
))
7569 return sprintf(buf
, "%d\n", priv
->antenna
);
7572 static ssize_t
store_antenna(struct device
*d
,
7573 struct device_attribute
*attr
,
7574 const char *buf
, size_t count
)
7577 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7582 if (sscanf(buf
, "%1i", &ant
) != 1) {
7583 IWL_DEBUG_INFO("not in hex or decimal form.\n");
7587 if ((ant
>= 0) && (ant
<= 2)) {
7588 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant
);
7589 priv
->antenna
= (enum iwl3945_antenna
)ant
;
7591 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant
);
7597 static DEVICE_ATTR(antenna
, S_IWUSR
| S_IRUGO
, show_antenna
, store_antenna
);
7599 static ssize_t
show_status(struct device
*d
,
7600 struct device_attribute
*attr
, char *buf
)
7602 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7603 if (!iwl3945_is_alive(priv
))
7605 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
7608 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
7610 static ssize_t
dump_error_log(struct device
*d
,
7611 struct device_attribute
*attr
,
7612 const char *buf
, size_t count
)
7614 char *p
= (char *)buf
;
7617 iwl3945_dump_nic_error_log((struct iwl_priv
*)d
->driver_data
);
7619 return strnlen(buf
, count
);
7622 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, dump_error_log
);
7624 static ssize_t
dump_event_log(struct device
*d
,
7625 struct device_attribute
*attr
,
7626 const char *buf
, size_t count
)
7628 char *p
= (char *)buf
;
7631 iwl3945_dump_nic_event_log((struct iwl_priv
*)d
->driver_data
);
7633 return strnlen(buf
, count
);
7636 static DEVICE_ATTR(dump_events
, S_IWUSR
, NULL
, dump_event_log
);
7638 /*****************************************************************************
7640 * driver setup and tear down
7642 *****************************************************************************/
7644 static void iwl3945_setup_deferred_work(struct iwl_priv
*priv
)
7646 priv
->workqueue
= create_workqueue(DRV_NAME
);
7648 init_waitqueue_head(&priv
->wait_command_queue
);
7650 INIT_WORK(&priv
->up
, iwl3945_bg_up
);
7651 INIT_WORK(&priv
->restart
, iwl3945_bg_restart
);
7652 INIT_WORK(&priv
->rx_replenish
, iwl3945_bg_rx_replenish
);
7653 INIT_WORK(&priv
->scan_completed
, iwl3945_bg_scan_completed
);
7654 INIT_WORK(&priv
->request_scan
, iwl3945_bg_request_scan
);
7655 INIT_WORK(&priv
->abort_scan
, iwl3945_bg_abort_scan
);
7656 INIT_WORK(&priv
->rf_kill
, iwl3945_bg_rf_kill
);
7657 INIT_WORK(&priv
->beacon_update
, iwl3945_bg_beacon_update
);
7658 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl3945_bg_init_alive_start
);
7659 INIT_DELAYED_WORK(&priv
->alive_start
, iwl3945_bg_alive_start
);
7660 INIT_DELAYED_WORK(&priv
->scan_check
, iwl3945_bg_scan_check
);
7662 iwl3945_hw_setup_deferred_work(priv
);
7664 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
7665 iwl3945_irq_tasklet
, (unsigned long)priv
);
7668 static void iwl3945_cancel_deferred_work(struct iwl_priv
*priv
)
7670 iwl3945_hw_cancel_deferred_work(priv
);
7672 cancel_delayed_work_sync(&priv
->init_alive_start
);
7673 cancel_delayed_work(&priv
->scan_check
);
7674 cancel_delayed_work(&priv
->alive_start
);
7675 cancel_work_sync(&priv
->beacon_update
);
7678 static struct attribute
*iwl3945_sysfs_entries
[] = {
7679 &dev_attr_antenna
.attr
,
7680 &dev_attr_channels
.attr
,
7681 &dev_attr_dump_errors
.attr
,
7682 &dev_attr_dump_events
.attr
,
7683 &dev_attr_flags
.attr
,
7684 &dev_attr_filter_flags
.attr
,
7685 #ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
7686 &dev_attr_measurement
.attr
,
7688 &dev_attr_power_level
.attr
,
7689 &dev_attr_retry_rate
.attr
,
7690 &dev_attr_statistics
.attr
,
7691 &dev_attr_status
.attr
,
7692 &dev_attr_temperature
.attr
,
7693 &dev_attr_tx_power
.attr
,
7694 #ifdef CONFIG_IWL3945_DEBUG
7695 &dev_attr_debug_level
.attr
,
7700 static struct attribute_group iwl3945_attribute_group
= {
7701 .name
= NULL
, /* put in device directory */
7702 .attrs
= iwl3945_sysfs_entries
,
7705 static struct ieee80211_ops iwl3945_hw_ops
= {
7706 .tx
= iwl3945_mac_tx
,
7707 .start
= iwl3945_mac_start
,
7708 .stop
= iwl3945_mac_stop
,
7709 .add_interface
= iwl3945_mac_add_interface
,
7710 .remove_interface
= iwl3945_mac_remove_interface
,
7711 .config
= iwl3945_mac_config
,
7712 .config_interface
= iwl3945_mac_config_interface
,
7713 .configure_filter
= iwl3945_configure_filter
,
7714 .set_key
= iwl3945_mac_set_key
,
7715 .get_tx_stats
= iwl3945_mac_get_tx_stats
,
7716 .conf_tx
= iwl3945_mac_conf_tx
,
7717 .reset_tsf
= iwl3945_mac_reset_tsf
,
7718 .bss_info_changed
= iwl3945_bss_info_changed
,
7719 .hw_scan
= iwl3945_mac_hw_scan
7722 static int iwl3945_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
7725 struct iwl_priv
*priv
;
7726 struct ieee80211_hw
*hw
;
7727 struct iwl_cfg
*cfg
= (struct iwl_cfg
*)(ent
->driver_data
);
7728 unsigned long flags
;
7730 /***********************
7731 * 1. Allocating HW data
7732 * ********************/
7734 /* mac80211 allocates memory for this device instance, including
7735 * space for this driver's private structure */
7736 hw
= ieee80211_alloc_hw(sizeof(struct iwl_priv
), &iwl3945_hw_ops
);
7738 printk(KERN_ERR DRV_NAME
"Can not allocate network device\n");
7743 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
7747 priv
->pci_dev
= pdev
;
7750 if ((iwl3945_param_queues_num
> IWL39_MAX_NUM_QUEUES
) ||
7751 (iwl3945_param_queues_num
< IWL_MIN_NUM_QUEUES
)) {
7753 "invalid queues_num, should be between %d and %d\n",
7754 IWL_MIN_NUM_QUEUES
, IWL39_MAX_NUM_QUEUES
);
7759 /* Disabling hardware scan means that mac80211 will perform scans
7760 * "the hard way", rather than using device's scan. */
7761 if (iwl3945_param_disable_hw_scan
) {
7762 IWL_DEBUG_INFO("Disabling hw_scan\n");
7763 iwl3945_hw_ops
.hw_scan
= NULL
;
7766 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
7767 hw
->rate_control_algorithm
= "iwl-3945-rs";
7768 hw
->sta_data_size
= sizeof(struct iwl3945_sta_priv
);
7770 /* Select antenna (may be helpful if only one antenna is connected) */
7771 priv
->antenna
= (enum iwl3945_antenna
)iwl3945_param_antenna
;
7772 #ifdef CONFIG_IWL3945_DEBUG
7773 priv
->debug_level
= iwl3945_param_debug
;
7774 atomic_set(&priv
->restrict_refcnt
, 0);
7777 /* Tell mac80211 our characteristics */
7778 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
7779 IEEE80211_HW_NOISE_DBM
;
7781 hw
->wiphy
->interface_modes
=
7782 BIT(NL80211_IFTYPE_STATION
) |
7783 BIT(NL80211_IFTYPE_ADHOC
);
7785 hw
->wiphy
->fw_handles_regulatory
= true;
7787 /* 4 EDCA QOS priorities */
7790 /***************************
7791 * 2. Initializing PCI bus
7792 * *************************/
7793 if (pci_enable_device(pdev
)) {
7795 goto out_ieee80211_free_hw
;
7798 pci_set_master(pdev
);
7800 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
7802 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
7804 IWL_WARN(priv
, "No suitable DMA available.\n");
7805 goto out_pci_disable_device
;
7808 pci_set_drvdata(pdev
, priv
);
7809 err
= pci_request_regions(pdev
, DRV_NAME
);
7811 goto out_pci_disable_device
;
7813 /***********************
7814 * 3. Read REV Register
7815 * ********************/
7816 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
7817 if (!priv
->hw_base
) {
7819 goto out_pci_release_regions
;
7822 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
7823 (unsigned long long) pci_resource_len(pdev
, 0));
7824 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
7826 /* We disable the RETRY_TIMEOUT register (0x41) to keep
7827 * PCI Tx retries from interfering with C3 CPU state */
7828 pci_write_config_byte(pdev
, 0x41, 0x00);
7831 iwl_set_bit(priv
, CSR_GIO_CHICKEN_BITS
,
7832 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER
);
7834 iwl_set_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_INIT_DONE
);
7835 err
= iwl_poll_direct_bit(priv
, CSR_GP_CNTRL
,
7836 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
, 25000);
7838 IWL_DEBUG_INFO("Failed to init the card\n");
7839 goto out_remove_sysfs
;
7842 /***********************
7844 * ********************/
7845 /* Read the EEPROM */
7846 err
= iwl3945_eeprom_init(priv
);
7848 IWL_ERR(priv
, "Unable to init EEPROM\n");
7849 goto out_remove_sysfs
;
7851 /* MAC Address location in EEPROM same for 3945/4965 */
7852 get_eeprom_mac(priv
, priv
->mac_addr
);
7853 IWL_DEBUG_INFO("MAC address: %pM\n", priv
->mac_addr
);
7854 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
7856 /***********************
7857 * 5. Setup HW Constants
7858 * ********************/
7859 /* Device-specific setup */
7860 if (iwl3945_hw_set_hw_params(priv
)) {
7861 IWL_ERR(priv
, "failed to set hw settings\n");
7865 /***********************
7867 * ********************/
7868 priv
->retry_rate
= 1;
7869 priv
->ibss_beacon
= NULL
;
7871 spin_lock_init(&priv
->lock
);
7872 spin_lock_init(&priv
->power_data_39
.lock
);
7873 spin_lock_init(&priv
->sta_lock
);
7874 spin_lock_init(&priv
->hcmd_lock
);
7876 INIT_LIST_HEAD(&priv
->free_frames
);
7877 mutex_init(&priv
->mutex
);
7879 /* Clear the driver's (not device's) station table */
7880 iwl3945_clear_stations_table(priv
);
7882 priv
->data_retry_limit
= -1;
7883 priv
->ieee_channels
= NULL
;
7884 priv
->ieee_rates
= NULL
;
7885 priv
->band
= IEEE80211_BAND_2GHZ
;
7887 priv
->iw_mode
= NL80211_IFTYPE_STATION
;
7889 iwl3945_reset_qos(priv
);
7891 priv
->qos_data
.qos_active
= 0;
7892 priv
->qos_data
.qos_cap
.val
= 0;
7895 priv
->rates_mask
= IWL_RATES_MASK
;
7896 /* If power management is turned on, default to AC mode */
7897 priv
->power_mode
= IWL39_POWER_AC
;
7898 priv
->user_txpower_limit
= IWL_DEFAULT_TX_POWER
;
7900 err
= iwl3945_init_channel_map(priv
);
7902 IWL_ERR(priv
, "initializing regulatory failed: %d\n", err
);
7903 goto out_release_irq
;
7906 err
= iwl3945_init_geos(priv
);
7908 IWL_ERR(priv
, "initializing geos failed: %d\n", err
);
7909 goto out_free_channel_map
;
7912 IWL_INFO(priv
, "Detected Intel Wireless WiFi Link %s\n",
7915 /***********************************
7916 * 7. Initialize Module Parameters
7917 * **********************************/
7919 /* Initialize module parameter values here */
7920 /* Disable radio (SW RF KILL) via parameter when loading driver */
7921 if (iwl3945_param_disable
) {
7922 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
7923 IWL_DEBUG_INFO("Radio disabled.\n");
7927 /***********************
7929 * ********************/
7931 spin_lock_irqsave(&priv
->lock
, flags
);
7932 iwl3945_disable_interrupts(priv
);
7933 spin_unlock_irqrestore(&priv
->lock
, flags
);
7935 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
7937 IWL_ERR(priv
, "failed to create sysfs device attributes\n");
7941 iwl3945_set_rxon_channel(priv
, IEEE80211_BAND_2GHZ
, 6);
7942 iwl3945_setup_deferred_work(priv
);
7943 iwl3945_setup_rx_handlers(priv
);
7945 /***********************
7947 * ********************/
7948 pci_save_state(pdev
);
7949 pci_disable_device(pdev
);
7951 /*********************************
7952 * 10. Setup and Register mac80211
7953 * *******************************/
7955 err
= ieee80211_register_hw(priv
->hw
);
7957 IWL_ERR(priv
, "Failed to register network device: %d\n", err
);
7958 goto out_remove_sysfs
;
7961 priv
->hw
->conf
.beacon_int
= 100;
7962 priv
->mac80211_registered
= 1;
7965 err
= iwl3945_rfkill_init(priv
);
7967 IWL_ERR(priv
, "Unable to initialize RFKILL system. "
7968 "Ignoring error: %d\n", err
);
7973 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
7975 iwl3945_free_geos(priv
);
7976 out_free_channel_map
:
7977 iwl3945_free_channel_map(priv
);
7981 destroy_workqueue(priv
->workqueue
);
7982 priv
->workqueue
= NULL
;
7983 iwl3945_unset_hw_params(priv
);
7986 pci_iounmap(pdev
, priv
->hw_base
);
7987 out_pci_release_regions
:
7988 pci_release_regions(pdev
);
7989 out_pci_disable_device
:
7990 pci_disable_device(pdev
);
7991 pci_set_drvdata(pdev
, NULL
);
7992 out_ieee80211_free_hw
:
7993 ieee80211_free_hw(priv
->hw
);
7998 static void __devexit
iwl3945_pci_remove(struct pci_dev
*pdev
)
8000 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
8001 unsigned long flags
;
8006 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
8008 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
8012 /* make sure we flush any pending irq or
8013 * tasklet for the driver
8015 spin_lock_irqsave(&priv
->lock
, flags
);
8016 iwl3945_disable_interrupts(priv
);
8017 spin_unlock_irqrestore(&priv
->lock
, flags
);
8019 iwl_synchronize_irq(priv
);
8021 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl3945_attribute_group
);
8023 iwl3945_rfkill_unregister(priv
);
8024 iwl3945_dealloc_ucode_pci(priv
);
8027 iwl3945_rx_queue_free(priv
, &priv
->rxq
);
8028 iwl3945_hw_txq_ctx_free(priv
);
8030 iwl3945_unset_hw_params(priv
);
8031 iwl3945_clear_stations_table(priv
);
8033 if (priv
->mac80211_registered
)
8034 ieee80211_unregister_hw(priv
->hw
);
8036 /*netif_stop_queue(dev); */
8037 flush_workqueue(priv
->workqueue
);
8039 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
8040 * priv->workqueue... so we can't take down the workqueue
8042 destroy_workqueue(priv
->workqueue
);
8043 priv
->workqueue
= NULL
;
8045 pci_iounmap(pdev
, priv
->hw_base
);
8046 pci_release_regions(pdev
);
8047 pci_disable_device(pdev
);
8048 pci_set_drvdata(pdev
, NULL
);
8050 iwl3945_free_channel_map(priv
);
8051 iwl3945_free_geos(priv
);
8052 kfree(priv
->scan39
);
8053 if (priv
->ibss_beacon
)
8054 dev_kfree_skb(priv
->ibss_beacon
);
8056 ieee80211_free_hw(priv
->hw
);
8061 static int iwl3945_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8063 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
8065 if (priv
->is_open
) {
8066 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
8067 iwl3945_mac_stop(priv
->hw
);
8071 pci_set_power_state(pdev
, PCI_D3hot
);
8076 static int iwl3945_pci_resume(struct pci_dev
*pdev
)
8078 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
8080 pci_set_power_state(pdev
, PCI_D0
);
8083 iwl3945_mac_start(priv
->hw
);
8085 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
8089 #endif /* CONFIG_PM */
8091 /*************** RFKILL FUNCTIONS **********/
8092 #ifdef CONFIG_IWL3945_RFKILL
8093 /* software rf-kill from user */
8094 static int iwl3945_rfkill_soft_rf_kill(void *data
, enum rfkill_state state
)
8096 struct iwl_priv
*priv
= data
;
8102 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
8105 IWL_DEBUG_RF_KILL("we received soft RFKILL set to state %d\n", state
);
8106 mutex_lock(&priv
->mutex
);
8109 case RFKILL_STATE_UNBLOCKED
:
8110 if (iwl3945_is_rfkill_hw(priv
)) {
8114 iwl3945_radio_kill_sw(priv
, 0);
8116 case RFKILL_STATE_SOFT_BLOCKED
:
8117 iwl3945_radio_kill_sw(priv
, 1);
8120 IWL_WARN(priv
, "received unexpected RFKILL state %d\n", state
);
8124 mutex_unlock(&priv
->mutex
);
8129 int iwl3945_rfkill_init(struct iwl_priv
*priv
)
8131 struct device
*device
= wiphy_dev(priv
->hw
->wiphy
);
8134 BUG_ON(device
== NULL
);
8136 IWL_DEBUG_RF_KILL("Initializing RFKILL.\n");
8137 priv
->rfkill
= rfkill_allocate(device
, RFKILL_TYPE_WLAN
);
8138 if (!priv
->rfkill
) {
8139 IWL_ERR(priv
, "Unable to allocate rfkill device.\n");
8144 priv
->rfkill
->name
= priv
->cfg
->name
;
8145 priv
->rfkill
->data
= priv
;
8146 priv
->rfkill
->state
= RFKILL_STATE_UNBLOCKED
;
8147 priv
->rfkill
->toggle_radio
= iwl3945_rfkill_soft_rf_kill
;
8148 priv
->rfkill
->user_claim_unsupported
= 1;
8150 priv
->rfkill
->dev
.class->suspend
= NULL
;
8151 priv
->rfkill
->dev
.class->resume
= NULL
;
8153 ret
= rfkill_register(priv
->rfkill
);
8155 IWL_ERR(priv
, "Unable to register rfkill: %d\n", ret
);
8159 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
8163 if (priv
->rfkill
!= NULL
)
8164 rfkill_free(priv
->rfkill
);
8165 priv
->rfkill
= NULL
;
8168 IWL_DEBUG_RF_KILL("RFKILL initialization complete.\n");
8172 void iwl3945_rfkill_unregister(struct iwl_priv
*priv
)
8175 rfkill_unregister(priv
->rfkill
);
8177 priv
->rfkill
= NULL
;
8180 /* set rf-kill to the right state. */
8181 void iwl3945_rfkill_set_hw_state(struct iwl_priv
*priv
)
8187 if (iwl3945_is_rfkill_hw(priv
)) {
8188 rfkill_force_state(priv
->rfkill
, RFKILL_STATE_HARD_BLOCKED
);
8192 if (!iwl3945_is_rfkill_sw(priv
))
8193 rfkill_force_state(priv
->rfkill
, RFKILL_STATE_UNBLOCKED
);
8195 rfkill_force_state(priv
->rfkill
, RFKILL_STATE_SOFT_BLOCKED
);
8199 /*****************************************************************************
8201 * driver and module entry point
8203 *****************************************************************************/
8205 static struct pci_driver iwl3945_driver
= {
8207 .id_table
= iwl3945_hw_card_ids
,
8208 .probe
= iwl3945_pci_probe
,
8209 .remove
= __devexit_p(iwl3945_pci_remove
),
8211 .suspend
= iwl3945_pci_suspend
,
8212 .resume
= iwl3945_pci_resume
,
8216 static int __init
iwl3945_init(void)
8220 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
8221 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
8223 ret
= iwl3945_rate_control_register();
8225 printk(KERN_ERR DRV_NAME
8226 "Unable to register rate control algorithm: %d\n", ret
);
8230 ret
= pci_register_driver(&iwl3945_driver
);
8232 printk(KERN_ERR DRV_NAME
"Unable to initialize PCI module\n");
8233 goto error_register
;
8239 iwl3945_rate_control_unregister();
8243 static void __exit
iwl3945_exit(void)
8245 pci_unregister_driver(&iwl3945_driver
);
8246 iwl3945_rate_control_unregister();
8249 MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX
));
8251 module_param_named(antenna
, iwl3945_param_antenna
, int, 0444);
8252 MODULE_PARM_DESC(antenna
, "select antenna (1=Main, 2=Aux, default 0 [both])");
8253 module_param_named(disable
, iwl3945_param_disable
, int, 0444);
8254 MODULE_PARM_DESC(disable
, "manually disable the radio (default 0 [radio on])");
8255 module_param_named(hwcrypto
, iwl3945_param_hwcrypto
, int, 0444);
8256 MODULE_PARM_DESC(hwcrypto
,
8257 "using hardware crypto engine (default 0 [software])\n");
8258 module_param_named(debug
, iwl3945_param_debug
, uint
, 0444);
8259 MODULE_PARM_DESC(debug
, "debug output mask");
8260 module_param_named(disable_hw_scan
, iwl3945_param_disable_hw_scan
, int, 0444);
8261 MODULE_PARM_DESC(disable_hw_scan
, "disable hardware scanning (default 0)");
8263 module_param_named(queues_num
, iwl3945_param_queues_num
, int, 0444);
8264 MODULE_PARM_DESC(queues_num
, "number of hw queues.");
8266 module_exit(iwl3945_exit
);
8267 module_init(iwl3945_init
);