1 /******************************************************************************
3 * Copyright(c) 2003 - 2007 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 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
31 * NOTE: This file (iwl-base.c) is used to build to multiple hardware targets
32 * by defining IWL to either 3945 or 4965. The Makefile used when building
33 * the base targets will create base-3945.o and base-4965.o
35 * The eventual goal is to move as many of the #if IWL / #endif blocks out of
36 * this file and into the hardware specific implementation files (iwl-XXXX.c)
37 * and leave only the common (non #ifdef sprinkled) code in this file
40 #include <linux/kernel.h>
41 #include <linux/module.h>
42 #include <linux/version.h>
43 #include <linux/init.h>
44 #include <linux/pci.h>
45 #include <linux/dma-mapping.h>
46 #include <linux/delay.h>
47 #include <linux/skbuff.h>
48 #include <linux/netdevice.h>
49 #include <linux/wireless.h>
50 #include <linux/firmware.h>
51 #include <linux/skbuff.h>
52 #include <linux/netdevice.h>
53 #include <linux/etherdevice.h>
54 #include <linux/if_arp.h>
56 #include <net/ieee80211_radiotap.h>
57 #include <net/mac80211.h>
59 #include <asm/div64.h>
65 #include "iwl-helpers.h"
67 #ifdef CONFIG_IWLWIFI_DEBUG
71 /******************************************************************************
75 ******************************************************************************/
77 /* module parameters */
78 int iwl_param_disable_hw_scan
;
80 int iwl_param_disable
; /* def: enable radio */
81 int iwl_param_antenna
; /* def: 0 = both antennas (use diversity) */
82 int iwl_param_hwcrypto
; /* def: using software encryption */
83 int iwl_param_qos_enable
= 1;
84 int iwl_param_queues_num
= IWL_MAX_NUM_QUEUES
;
87 * module name, copyright, version, etc.
88 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
91 #define DRV_DESCRIPTION \
92 "Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
94 #ifdef CONFIG_IWLWIFI_DEBUG
100 #ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT
106 #define IWLWIFI_VERSION "1.1.17k" VD VS
107 #define DRV_COPYRIGHT "Copyright(c) 2003-2007 Intel Corporation"
108 #define DRV_VERSION IWLWIFI_VERSION
110 /* Change firmware file name, using "-" and incrementing number,
111 * *only* when uCode interface or architecture changes so that it
112 * is not compatible with earlier drivers.
113 * This number will also appear in << 8 position of 1st dword of uCode file */
114 #define IWL3945_UCODE_API "-1"
116 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
117 MODULE_VERSION(DRV_VERSION
);
118 MODULE_AUTHOR(DRV_COPYRIGHT
);
119 MODULE_LICENSE("GPL");
121 __le16
*ieee80211_get_qos_ctrl(struct ieee80211_hdr
*hdr
)
123 u16 fc
= le16_to_cpu(hdr
->frame_control
);
124 int hdr_len
= ieee80211_get_hdrlen(fc
);
126 if ((fc
& 0x00cc) == (IEEE80211_STYPE_QOS_DATA
| IEEE80211_FTYPE_DATA
))
127 return (__le16
*) ((u8
*) hdr
+ hdr_len
- QOS_CONTROL_LEN
);
131 static const struct ieee80211_hw_mode
*iwl_get_hw_mode(
132 struct iwl_priv
*priv
, int mode
)
136 for (i
= 0; i
< 3; i
++)
137 if (priv
->modes
[i
].mode
== mode
)
138 return &priv
->modes
[i
];
143 static int iwl_is_empty_essid(const char *essid
, int essid_len
)
145 /* Single white space is for Linksys APs */
146 if (essid_len
== 1 && essid
[0] == ' ')
149 /* Otherwise, if the entire essid is 0, we assume it is hidden */
152 if (essid
[essid_len
] != '\0')
159 static const char *iwl_escape_essid(const char *essid
, u8 essid_len
)
161 static char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
162 const char *s
= essid
;
165 if (iwl_is_empty_essid(essid
, essid_len
)) {
166 memcpy(escaped
, "<hidden>", sizeof("<hidden>"));
170 essid_len
= min(essid_len
, (u8
) IW_ESSID_MAX_SIZE
);
171 while (essid_len
--) {
183 static void iwl_print_hex_dump(int level
, void *p
, u32 len
)
185 #ifdef CONFIG_IWLWIFI_DEBUG
186 if (!(iwl_debug_level
& level
))
189 print_hex_dump(KERN_DEBUG
, "iwl data: ", DUMP_PREFIX_OFFSET
, 16, 1,
194 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
197 * Theory of operation
199 * A queue is a circular buffers with 'Read' and 'Write' pointers.
200 * 2 empty entries always kept in the buffer to protect from overflow.
202 * For Tx queue, there are low mark and high mark limits. If, after queuing
203 * the packet for Tx, free space become < low mark, Tx queue stopped. When
204 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
207 * The IWL operates with six queues, one receive queue in the device's
208 * sram, one transmit queue for sending commands to the device firmware,
209 * and four transmit queues for data.
210 ***************************************************/
212 static int iwl_queue_space(const struct iwl_queue
*q
)
214 int s
= q
->last_used
- q
->first_empty
;
216 if (q
->last_used
> q
->first_empty
)
221 /* keep some reserve to not confuse empty and full situations */
228 /* XXX: n_bd must be power-of-two size */
229 static inline int iwl_queue_inc_wrap(int index
, int n_bd
)
231 return ++index
& (n_bd
- 1);
234 /* XXX: n_bd must be power-of-two size */
235 static inline int iwl_queue_dec_wrap(int index
, int n_bd
)
237 return --index
& (n_bd
- 1);
240 static inline int x2_queue_used(const struct iwl_queue
*q
, int i
)
242 return q
->first_empty
> q
->last_used
?
243 (i
>= q
->last_used
&& i
< q
->first_empty
) :
244 !(i
< q
->last_used
&& i
>= q
->first_empty
);
247 static inline u8
get_cmd_index(struct iwl_queue
*q
, u32 index
, int is_huge
)
252 return index
& (q
->n_window
- 1);
255 static int iwl_queue_init(struct iwl_priv
*priv
, struct iwl_queue
*q
,
256 int count
, int slots_num
, u32 id
)
259 q
->n_window
= slots_num
;
262 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
263 * and iwl_queue_dec_wrap are broken. */
264 BUG_ON(!is_power_of_2(count
));
266 /* slots_num must be power-of-two size, otherwise
267 * get_cmd_index is broken. */
268 BUG_ON(!is_power_of_2(slots_num
));
270 q
->low_mark
= q
->n_window
/ 4;
274 q
->high_mark
= q
->n_window
/ 8;
275 if (q
->high_mark
< 2)
278 q
->first_empty
= q
->last_used
= 0;
283 static int iwl_tx_queue_alloc(struct iwl_priv
*priv
,
284 struct iwl_tx_queue
*txq
, u32 id
)
286 struct pci_dev
*dev
= priv
->pci_dev
;
288 if (id
!= IWL_CMD_QUEUE_NUM
) {
289 txq
->txb
= kmalloc(sizeof(txq
->txb
[0]) *
290 TFD_QUEUE_SIZE_MAX
, GFP_KERNEL
);
292 IWL_ERROR("kmalloc for auxilary BD "
293 "structures failed\n");
299 txq
->bd
= pci_alloc_consistent(dev
,
300 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
,
304 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
305 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
);
321 int iwl_tx_queue_init(struct iwl_priv
*priv
,
322 struct iwl_tx_queue
*txq
, int slots_num
, u32 txq_id
)
324 struct pci_dev
*dev
= priv
->pci_dev
;
328 /* alocate command space + one big command for scan since scan
329 * command is very huge the system will not have two scan at the
331 len
= sizeof(struct iwl_cmd
) * slots_num
;
332 if (txq_id
== IWL_CMD_QUEUE_NUM
)
333 len
+= IWL_MAX_SCAN_SIZE
;
334 txq
->cmd
= pci_alloc_consistent(dev
, len
, &txq
->dma_addr_cmd
);
338 rc
= iwl_tx_queue_alloc(priv
, txq
, txq_id
);
340 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
344 txq
->need_update
= 0;
346 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
347 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
348 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX
& (TFD_QUEUE_SIZE_MAX
- 1));
349 iwl_queue_init(priv
, &txq
->q
, TFD_QUEUE_SIZE_MAX
, slots_num
, txq_id
);
351 iwl_hw_tx_queue_init(priv
, txq
);
357 * iwl_tx_queue_free - Deallocate DMA queue.
358 * @txq: Transmit queue to deallocate.
360 * Empty queue by removing and destroying all BD's.
361 * Free all buffers. txq itself is not freed.
364 void iwl_tx_queue_free(struct iwl_priv
*priv
, struct iwl_tx_queue
*txq
)
366 struct iwl_queue
*q
= &txq
->q
;
367 struct pci_dev
*dev
= priv
->pci_dev
;
373 /* first, empty all BD's */
374 for (; q
->first_empty
!= q
->last_used
;
375 q
->last_used
= iwl_queue_inc_wrap(q
->last_used
, q
->n_bd
))
376 iwl_hw_txq_free_tfd(priv
, txq
);
378 len
= sizeof(struct iwl_cmd
) * q
->n_window
;
379 if (q
->id
== IWL_CMD_QUEUE_NUM
)
380 len
+= IWL_MAX_SCAN_SIZE
;
382 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
384 /* free buffers belonging to queue itself */
386 pci_free_consistent(dev
, sizeof(struct iwl_tfd_frame
) *
387 txq
->q
.n_bd
, txq
->bd
, txq
->q
.dma_addr
);
394 /* 0 fill whole structure */
395 memset(txq
, 0, sizeof(*txq
));
398 const u8 BROADCAST_ADDR
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
400 /*************** STATION TABLE MANAGEMENT ****
402 * NOTE: This needs to be overhauled to better synchronize between
403 * how the iwl-4965.c is using iwl_hw_find_station vs. iwl-3945.c
405 * mac80211 should also be examined to determine if sta_info is duplicating
406 * the functionality provided here
409 /**************************************************************/
410 #if 0 /* temparary disable till we add real remove station */
411 static u8
iwl_remove_station(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
)
413 int index
= IWL_INVALID_STATION
;
417 spin_lock_irqsave(&priv
->sta_lock
, flags
);
421 else if (is_broadcast_ether_addr(addr
))
422 index
= priv
->hw_setting
.bcast_sta_id
;
424 for (i
= IWL_STA_ID
; i
< priv
->hw_setting
.max_stations
; i
++)
425 if (priv
->stations
[i
].used
&&
426 !compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
432 if (unlikely(index
== IWL_INVALID_STATION
))
435 if (priv
->stations
[index
].used
) {
436 priv
->stations
[index
].used
= 0;
437 priv
->num_stations
--;
440 BUG_ON(priv
->num_stations
< 0);
443 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
447 static void iwl_clear_stations_table(struct iwl_priv
*priv
)
451 spin_lock_irqsave(&priv
->sta_lock
, flags
);
453 priv
->num_stations
= 0;
454 memset(priv
->stations
, 0, sizeof(priv
->stations
));
456 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
460 u8
iwl_add_station(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
, u8 flags
)
463 int index
= IWL_INVALID_STATION
;
464 struct iwl_station_entry
*station
;
465 unsigned long flags_spin
;
466 DECLARE_MAC_BUF(mac
);
469 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
472 else if (is_broadcast_ether_addr(addr
))
473 index
= priv
->hw_setting
.bcast_sta_id
;
475 for (i
= IWL_STA_ID
; i
< priv
->hw_setting
.max_stations
; i
++) {
476 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
482 if (!priv
->stations
[i
].used
&&
483 index
== IWL_INVALID_STATION
)
487 /* These twh conditions has the same outcome but keep them separate
488 since they have different meaning */
489 if (unlikely(index
== IWL_INVALID_STATION
)) {
490 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
494 if (priv
->stations
[index
].used
&&
495 !compare_ether_addr(priv
->stations
[index
].sta
.sta
.addr
, addr
)) {
496 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
500 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index
, print_mac(mac
, addr
));
501 station
= &priv
->stations
[index
];
503 priv
->num_stations
++;
505 memset(&station
->sta
, 0, sizeof(struct iwl_addsta_cmd
));
506 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
507 station
->sta
.mode
= 0;
508 station
->sta
.sta
.sta_id
= index
;
509 station
->sta
.station_flags
= 0;
511 rate
= (priv
->phymode
== MODE_IEEE80211A
) ? IWL_RATE_6M_PLCP
:
512 IWL_RATE_1M_PLCP
| priv
->hw_setting
.cck_flag
;
514 /* Turn on both antennas for the station... */
515 station
->sta
.rate_n_flags
=
516 iwl_hw_set_rate_n_flags(rate
, RATE_MCS_ANT_AB_MSK
);
517 station
->current_rate
.rate_n_flags
=
518 le16_to_cpu(station
->sta
.rate_n_flags
);
520 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
521 iwl_send_add_station(priv
, &station
->sta
, flags
);
526 /*************** DRIVER STATUS FUNCTIONS *****/
528 static inline int iwl_is_ready(struct iwl_priv
*priv
)
530 /* The adapter is 'ready' if READY and GEO_CONFIGURED bits are
531 * set but EXIT_PENDING is not */
532 return test_bit(STATUS_READY
, &priv
->status
) &&
533 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) &&
534 !test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
537 static inline int iwl_is_alive(struct iwl_priv
*priv
)
539 return test_bit(STATUS_ALIVE
, &priv
->status
);
542 static inline int iwl_is_init(struct iwl_priv
*priv
)
544 return test_bit(STATUS_INIT
, &priv
->status
);
547 static inline int iwl_is_rfkill(struct iwl_priv
*priv
)
549 return test_bit(STATUS_RF_KILL_HW
, &priv
->status
) ||
550 test_bit(STATUS_RF_KILL_SW
, &priv
->status
);
553 static inline int iwl_is_ready_rf(struct iwl_priv
*priv
)
556 if (iwl_is_rfkill(priv
))
559 return iwl_is_ready(priv
);
562 /*************** HOST COMMAND QUEUE FUNCTIONS *****/
564 #define IWL_CMD(x) case x : return #x
566 static const char *get_cmd_string(u8 cmd
)
569 IWL_CMD(REPLY_ALIVE
);
570 IWL_CMD(REPLY_ERROR
);
572 IWL_CMD(REPLY_RXON_ASSOC
);
573 IWL_CMD(REPLY_QOS_PARAM
);
574 IWL_CMD(REPLY_RXON_TIMING
);
575 IWL_CMD(REPLY_ADD_STA
);
576 IWL_CMD(REPLY_REMOVE_STA
);
577 IWL_CMD(REPLY_REMOVE_ALL_STA
);
578 IWL_CMD(REPLY_3945_RX
);
580 IWL_CMD(REPLY_RATE_SCALE
);
581 IWL_CMD(REPLY_LEDS_CMD
);
582 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD
);
583 IWL_CMD(RADAR_NOTIFICATION
);
584 IWL_CMD(REPLY_QUIET_CMD
);
585 IWL_CMD(REPLY_CHANNEL_SWITCH
);
586 IWL_CMD(CHANNEL_SWITCH_NOTIFICATION
);
587 IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD
);
588 IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION
);
589 IWL_CMD(POWER_TABLE_CMD
);
590 IWL_CMD(PM_SLEEP_NOTIFICATION
);
591 IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC
);
592 IWL_CMD(REPLY_SCAN_CMD
);
593 IWL_CMD(REPLY_SCAN_ABORT_CMD
);
594 IWL_CMD(SCAN_START_NOTIFICATION
);
595 IWL_CMD(SCAN_RESULTS_NOTIFICATION
);
596 IWL_CMD(SCAN_COMPLETE_NOTIFICATION
);
597 IWL_CMD(BEACON_NOTIFICATION
);
598 IWL_CMD(REPLY_TX_BEACON
);
599 IWL_CMD(WHO_IS_AWAKE_NOTIFICATION
);
600 IWL_CMD(QUIET_NOTIFICATION
);
601 IWL_CMD(REPLY_TX_PWR_TABLE_CMD
);
602 IWL_CMD(MEASURE_ABORT_NOTIFICATION
);
603 IWL_CMD(REPLY_BT_CONFIG
);
604 IWL_CMD(REPLY_STATISTICS_CMD
);
605 IWL_CMD(STATISTICS_NOTIFICATION
);
606 IWL_CMD(REPLY_CARD_STATE_CMD
);
607 IWL_CMD(CARD_STATE_NOTIFICATION
);
608 IWL_CMD(MISSED_BEACONS_NOTIFICATION
);
615 #define HOST_COMPLETE_TIMEOUT (HZ / 2)
618 * iwl_enqueue_hcmd - enqueue a uCode command
619 * @priv: device private data point
620 * @cmd: a point to the ucode command structure
622 * The function returns < 0 values to indicate the operation is
623 * failed. On success, it turns the index (> 0) of command in the
626 static int iwl_enqueue_hcmd(struct iwl_priv
*priv
, struct iwl_host_cmd
*cmd
)
628 struct iwl_tx_queue
*txq
= &priv
->txq
[IWL_CMD_QUEUE_NUM
];
629 struct iwl_queue
*q
= &txq
->q
;
630 struct iwl_tfd_frame
*tfd
;
632 struct iwl_cmd
*out_cmd
;
634 u16 fix_size
= (u16
)(cmd
->len
+ sizeof(out_cmd
->hdr
));
635 dma_addr_t phys_addr
;
641 /* If any of the command structures end up being larger than
642 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
643 * we will need to increase the size of the TFD entries */
644 BUG_ON((fix_size
> TFD_MAX_PAYLOAD_SIZE
) &&
645 !(cmd
->meta
.flags
& CMD_SIZE_HUGE
));
647 if (iwl_queue_space(q
) < ((cmd
->meta
.flags
& CMD_ASYNC
) ? 2 : 1)) {
648 IWL_ERROR("No space for Tx\n");
652 spin_lock_irqsave(&priv
->hcmd_lock
, flags
);
654 tfd
= &txq
->bd
[q
->first_empty
];
655 memset(tfd
, 0, sizeof(*tfd
));
657 control_flags
= (u32
*) tfd
;
659 idx
= get_cmd_index(q
, q
->first_empty
, cmd
->meta
.flags
& CMD_SIZE_HUGE
);
660 out_cmd
= &txq
->cmd
[idx
];
662 out_cmd
->hdr
.cmd
= cmd
->id
;
663 memcpy(&out_cmd
->meta
, &cmd
->meta
, sizeof(cmd
->meta
));
664 memcpy(&out_cmd
->cmd
.payload
, cmd
->data
, cmd
->len
);
666 /* At this point, the out_cmd now has all of the incoming cmd
669 out_cmd
->hdr
.flags
= 0;
670 out_cmd
->hdr
.sequence
= cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM
) |
671 INDEX_TO_SEQ(q
->first_empty
));
672 if (out_cmd
->meta
.flags
& CMD_SIZE_HUGE
)
673 out_cmd
->hdr
.sequence
|= cpu_to_le16(SEQ_HUGE_FRAME
);
675 phys_addr
= txq
->dma_addr_cmd
+ sizeof(txq
->cmd
[0]) * idx
+
676 offsetof(struct iwl_cmd
, hdr
);
677 iwl_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, fix_size
);
679 pad
= U32_PAD(cmd
->len
);
680 count
= TFD_CTL_COUNT_GET(*control_flags
);
681 *control_flags
= TFD_CTL_COUNT_SET(count
) | TFD_CTL_PAD_SET(pad
);
683 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
684 "%d bytes at %d[%d]:%d\n",
685 get_cmd_string(out_cmd
->hdr
.cmd
),
686 out_cmd
->hdr
.cmd
, le16_to_cpu(out_cmd
->hdr
.sequence
),
687 fix_size
, q
->first_empty
, idx
, IWL_CMD_QUEUE_NUM
);
689 txq
->need_update
= 1;
690 q
->first_empty
= iwl_queue_inc_wrap(q
->first_empty
, q
->n_bd
);
691 ret
= iwl_tx_queue_update_write_ptr(priv
, txq
);
693 spin_unlock_irqrestore(&priv
->hcmd_lock
, flags
);
694 return ret
? ret
: idx
;
697 int iwl_send_cmd_async(struct iwl_priv
*priv
, struct iwl_host_cmd
*cmd
)
701 BUG_ON(!(cmd
->meta
.flags
& CMD_ASYNC
));
703 /* An asynchronous command can not expect an SKB to be set. */
704 BUG_ON(cmd
->meta
.flags
& CMD_WANT_SKB
);
706 /* An asynchronous command MUST have a callback. */
707 BUG_ON(!cmd
->meta
.u
.callback
);
709 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
712 ret
= iwl_enqueue_hcmd(priv
, cmd
);
714 IWL_ERROR("Error sending %s: iwl_enqueue_hcmd failed: %d\n",
715 get_cmd_string(cmd
->id
), ret
);
721 int iwl_send_cmd_sync(struct iwl_priv
*priv
, struct iwl_host_cmd
*cmd
)
725 static atomic_t entry
= ATOMIC_INIT(0); /* reentrance protection */
727 BUG_ON(cmd
->meta
.flags
& CMD_ASYNC
);
729 /* A synchronous command can not have a callback set. */
730 BUG_ON(cmd
->meta
.u
.callback
!= NULL
);
732 if (atomic_xchg(&entry
, 1)) {
733 IWL_ERROR("Error sending %s: Already sending a host command\n",
734 get_cmd_string(cmd
->id
));
738 set_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
740 if (cmd
->meta
.flags
& CMD_WANT_SKB
)
741 cmd
->meta
.source
= &cmd
->meta
;
743 cmd_idx
= iwl_enqueue_hcmd(priv
, cmd
);
746 IWL_ERROR("Error sending %s: iwl_enqueue_hcmd failed: %d\n",
747 get_cmd_string(cmd
->id
), ret
);
751 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
752 !test_bit(STATUS_HCMD_ACTIVE
, &priv
->status
),
753 HOST_COMPLETE_TIMEOUT
);
755 if (test_bit(STATUS_HCMD_ACTIVE
, &priv
->status
)) {
756 IWL_ERROR("Error sending %s: time out after %dms.\n",
757 get_cmd_string(cmd
->id
),
758 jiffies_to_msecs(HOST_COMPLETE_TIMEOUT
));
760 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
766 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
767 IWL_DEBUG_INFO("Command %s aborted: RF KILL Switch\n",
768 get_cmd_string(cmd
->id
));
772 if (test_bit(STATUS_FW_ERROR
, &priv
->status
)) {
773 IWL_DEBUG_INFO("Command %s failed: FW Error\n",
774 get_cmd_string(cmd
->id
));
778 if ((cmd
->meta
.flags
& CMD_WANT_SKB
) && !cmd
->meta
.u
.skb
) {
779 IWL_ERROR("Error: Response NULL in '%s'\n",
780 get_cmd_string(cmd
->id
));
789 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
790 struct iwl_cmd
*qcmd
;
792 /* Cancel the CMD_WANT_SKB flag for the cmd in the
793 * TX cmd queue. Otherwise in case the cmd comes
794 * in later, it will possibly set an invalid
795 * address (cmd->meta.source). */
796 qcmd
= &priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_idx
];
797 qcmd
->meta
.flags
&= ~CMD_WANT_SKB
;
800 if (cmd
->meta
.u
.skb
) {
801 dev_kfree_skb_any(cmd
->meta
.u
.skb
);
802 cmd
->meta
.u
.skb
= NULL
;
805 atomic_set(&entry
, 0);
809 int iwl_send_cmd(struct iwl_priv
*priv
, struct iwl_host_cmd
*cmd
)
811 /* A command can not be asynchronous AND expect an SKB to be set. */
812 BUG_ON((cmd
->meta
.flags
& CMD_ASYNC
) &&
813 (cmd
->meta
.flags
& CMD_WANT_SKB
));
815 if (cmd
->meta
.flags
& CMD_ASYNC
)
816 return iwl_send_cmd_async(priv
, cmd
);
818 return iwl_send_cmd_sync(priv
, cmd
);
821 int iwl_send_cmd_pdu(struct iwl_priv
*priv
, u8 id
, u16 len
, const void *data
)
823 struct iwl_host_cmd cmd
= {
829 return iwl_send_cmd_sync(priv
, &cmd
);
832 static int __must_check
iwl_send_cmd_u32(struct iwl_priv
*priv
, u8 id
, u32 val
)
834 struct iwl_host_cmd cmd
= {
840 return iwl_send_cmd_sync(priv
, &cmd
);
843 int iwl_send_statistics_request(struct iwl_priv
*priv
)
845 return iwl_send_cmd_u32(priv
, REPLY_STATISTICS_CMD
, 0);
849 * iwl_set_rxon_channel - Set the phymode and channel values in staging RXON
850 * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
851 * @channel: Any channel valid for the requested phymode
853 * In addition to setting the staging RXON, priv->phymode is also set.
855 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
856 * in the staging RXON flag structure based on the phymode
858 static int iwl_set_rxon_channel(struct iwl_priv
*priv
, u8 phymode
, u16 channel
)
860 if (!iwl_get_channel_info(priv
, phymode
, channel
)) {
861 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
866 if ((le16_to_cpu(priv
->staging_rxon
.channel
) == channel
) &&
867 (priv
->phymode
== phymode
))
870 priv
->staging_rxon
.channel
= cpu_to_le16(channel
);
871 if (phymode
== MODE_IEEE80211A
)
872 priv
->staging_rxon
.flags
&= ~RXON_FLG_BAND_24G_MSK
;
874 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
876 priv
->phymode
= phymode
;
878 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel
, phymode
);
884 * iwl_check_rxon_cmd - validate RXON structure is valid
886 * NOTE: This is really only useful during development and can eventually
887 * be #ifdef'd out once the driver is stable and folks aren't actively
890 static int iwl_check_rxon_cmd(struct iwl_rxon_cmd
*rxon
)
895 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
896 error
|= le32_to_cpu(rxon
->flags
&
897 (RXON_FLG_TGJ_NARROW_BAND_MSK
|
898 RXON_FLG_RADAR_DETECT_MSK
));
900 IWL_WARNING("check 24G fields %d | %d\n",
903 error
|= (rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
) ?
904 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK
);
906 IWL_WARNING("check 52 fields %d | %d\n",
908 error
|= le32_to_cpu(rxon
->flags
& RXON_FLG_CCK_MSK
);
910 IWL_WARNING("check 52 CCK %d | %d\n",
913 error
|= (rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1;
915 IWL_WARNING("check mac addr %d | %d\n", counter
++, error
);
917 /* make sure basic rates 6Mbps and 1Mbps are supported */
918 error
|= (((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0) &&
919 ((rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0));
921 IWL_WARNING("check basic rate %d | %d\n", counter
++, error
);
923 error
|= (le16_to_cpu(rxon
->assoc_id
) > 2007);
925 IWL_WARNING("check assoc id %d | %d\n", counter
++, error
);
927 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
928 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
));
930 IWL_WARNING("check CCK and short slot %d | %d\n",
933 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
934 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
));
936 IWL_WARNING("check CCK & auto detect %d | %d\n",
939 error
|= ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
940 RXON_FLG_TGG_PROTECT_MSK
)) == RXON_FLG_TGG_PROTECT_MSK
);
942 IWL_WARNING("check TGG and auto detect %d | %d\n",
945 if ((rxon
->flags
& RXON_FLG_DIS_DIV_MSK
))
946 error
|= ((rxon
->flags
& (RXON_FLG_ANT_B_MSK
|
947 RXON_FLG_ANT_A_MSK
)) == 0);
949 IWL_WARNING("check antenna %d %d\n", counter
++, error
);
952 IWL_WARNING("Tuning to channel %d\n",
953 le16_to_cpu(rxon
->channel
));
956 IWL_ERROR("Not a valid iwl_rxon_assoc_cmd field values\n");
963 * iwl_full_rxon_required - determine if RXON_ASSOC can be used in RXON commit
964 * @priv: staging_rxon is comapred to active_rxon
966 * If the RXON structure is changing sufficient to require a new
967 * tune or to clear and reset the RXON_FILTER_ASSOC_MSK then return 1
968 * to indicate a new tune is required.
970 static int iwl_full_rxon_required(struct iwl_priv
*priv
)
973 /* These items are only settable from the full RXON command */
974 if (!(priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) ||
975 compare_ether_addr(priv
->staging_rxon
.bssid_addr
,
976 priv
->active_rxon
.bssid_addr
) ||
977 compare_ether_addr(priv
->staging_rxon
.node_addr
,
978 priv
->active_rxon
.node_addr
) ||
979 compare_ether_addr(priv
->staging_rxon
.wlap_bssid_addr
,
980 priv
->active_rxon
.wlap_bssid_addr
) ||
981 (priv
->staging_rxon
.dev_type
!= priv
->active_rxon
.dev_type
) ||
982 (priv
->staging_rxon
.channel
!= priv
->active_rxon
.channel
) ||
983 (priv
->staging_rxon
.air_propagation
!=
984 priv
->active_rxon
.air_propagation
) ||
985 (priv
->staging_rxon
.assoc_id
!= priv
->active_rxon
.assoc_id
))
988 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
989 * be updated with the RXON_ASSOC command -- however only some
990 * flag transitions are allowed using RXON_ASSOC */
992 /* Check if we are not switching bands */
993 if ((priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) !=
994 (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
))
997 /* Check if we are switching association toggle */
998 if ((priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) !=
999 (priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
))
1005 static int iwl_send_rxon_assoc(struct iwl_priv
*priv
)
1008 struct iwl_rx_packet
*res
= NULL
;
1009 struct iwl_rxon_assoc_cmd rxon_assoc
;
1010 struct iwl_host_cmd cmd
= {
1011 .id
= REPLY_RXON_ASSOC
,
1012 .len
= sizeof(rxon_assoc
),
1013 .meta
.flags
= CMD_WANT_SKB
,
1014 .data
= &rxon_assoc
,
1016 const struct iwl_rxon_cmd
*rxon1
= &priv
->staging_rxon
;
1017 const struct iwl_rxon_cmd
*rxon2
= &priv
->active_rxon
;
1019 if ((rxon1
->flags
== rxon2
->flags
) &&
1020 (rxon1
->filter_flags
== rxon2
->filter_flags
) &&
1021 (rxon1
->cck_basic_rates
== rxon2
->cck_basic_rates
) &&
1022 (rxon1
->ofdm_basic_rates
== rxon2
->ofdm_basic_rates
)) {
1023 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1027 rxon_assoc
.flags
= priv
->staging_rxon
.flags
;
1028 rxon_assoc
.filter_flags
= priv
->staging_rxon
.filter_flags
;
1029 rxon_assoc
.ofdm_basic_rates
= priv
->staging_rxon
.ofdm_basic_rates
;
1030 rxon_assoc
.cck_basic_rates
= priv
->staging_rxon
.cck_basic_rates
;
1031 rxon_assoc
.reserved
= 0;
1033 rc
= iwl_send_cmd_sync(priv
, &cmd
);
1037 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1038 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1039 IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
1043 priv
->alloc_rxb_skb
--;
1044 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1050 * iwl_commit_rxon - commit staging_rxon to hardware
1052 * The RXON command in staging_rxon is commited to the hardware and
1053 * the active_rxon structure is updated with the new data. This
1054 * function correctly transitions out of the RXON_ASSOC_MSK state if
1055 * a HW tune is required based on the RXON structure changes.
1057 static int iwl_commit_rxon(struct iwl_priv
*priv
)
1059 /* cast away the const for active_rxon in this function */
1060 struct iwl_rxon_cmd
*active_rxon
= (void *)&priv
->active_rxon
;
1062 DECLARE_MAC_BUF(mac
);
1064 if (!iwl_is_alive(priv
))
1067 /* always get timestamp with Rx frame */
1068 priv
->staging_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
1070 /* select antenna */
1071 priv
->staging_rxon
.flags
&=
1072 ~(RXON_FLG_DIS_DIV_MSK
| RXON_FLG_ANT_SEL_MSK
);
1073 priv
->staging_rxon
.flags
|= iwl3945_get_antenna_flags(priv
);
1075 rc
= iwl_check_rxon_cmd(&priv
->staging_rxon
);
1077 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
1081 /* If we don't need to send a full RXON, we can use
1082 * iwl_rxon_assoc_cmd which is used to reconfigure filter
1083 * and other flags for the current radio configuration. */
1084 if (!iwl_full_rxon_required(priv
)) {
1085 rc
= iwl_send_rxon_assoc(priv
);
1087 IWL_ERROR("Error setting RXON_ASSOC "
1088 "configuration (%d).\n", rc
);
1092 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
1097 /* If we are currently associated and the new config requires
1098 * an RXON_ASSOC and the new config wants the associated mask enabled,
1099 * we must clear the associated from the active configuration
1100 * before we apply the new config */
1101 if (iwl_is_associated(priv
) &&
1102 (priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
)) {
1103 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
1104 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
1106 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
1107 sizeof(struct iwl_rxon_cmd
),
1108 &priv
->active_rxon
);
1110 /* If the mask clearing failed then we set
1111 * active_rxon back to what it was previously */
1113 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
1114 IWL_ERROR("Error clearing ASSOC_MSK on current "
1115 "configuration (%d).\n", rc
);
1120 IWL_DEBUG_INFO("Sending RXON\n"
1121 "* with%s RXON_FILTER_ASSOC_MSK\n"
1124 ((priv
->staging_rxon
.filter_flags
&
1125 RXON_FILTER_ASSOC_MSK
) ? "" : "out"),
1126 le16_to_cpu(priv
->staging_rxon
.channel
),
1127 print_mac(mac
, priv
->staging_rxon
.bssid_addr
));
1129 /* Apply the new configuration */
1130 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
1131 sizeof(struct iwl_rxon_cmd
), &priv
->staging_rxon
);
1133 IWL_ERROR("Error setting new configuration (%d).\n", rc
);
1137 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
1139 iwl_clear_stations_table(priv
);
1141 /* If we issue a new RXON command which required a tune then we must
1142 * send a new TXPOWER command or we won't be able to Tx any frames */
1143 rc
= iwl_hw_reg_send_txpower(priv
);
1145 IWL_ERROR("Error setting Tx power (%d).\n", rc
);
1149 /* Add the broadcast address so we can send broadcast frames */
1150 if (iwl_add_station(priv
, BROADCAST_ADDR
, 0, 0) ==
1151 IWL_INVALID_STATION
) {
1152 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
1156 /* If we have set the ASSOC_MSK and we are in BSS mode then
1157 * add the IWL_AP_ID to the station rate table */
1158 if (iwl_is_associated(priv
) &&
1159 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
1160 if (iwl_add_station(priv
, priv
->active_rxon
.bssid_addr
, 1, 0)
1161 == IWL_INVALID_STATION
) {
1162 IWL_ERROR("Error adding AP address for transmit.\n");
1166 /* Init the hardware's rate fallback order based on the
1168 rc
= iwl3945_init_hw_rate_table(priv
);
1170 IWL_ERROR("Error setting HW rate table: %02X\n", rc
);
1177 static int iwl_send_bt_config(struct iwl_priv
*priv
)
1179 struct iwl_bt_cmd bt_cmd
= {
1187 return iwl_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
1188 sizeof(struct iwl_bt_cmd
), &bt_cmd
);
1191 static int iwl_send_scan_abort(struct iwl_priv
*priv
)
1194 struct iwl_rx_packet
*res
;
1195 struct iwl_host_cmd cmd
= {
1196 .id
= REPLY_SCAN_ABORT_CMD
,
1197 .meta
.flags
= CMD_WANT_SKB
,
1200 /* If there isn't a scan actively going on in the hardware
1201 * then we are in between scan bands and not actually
1202 * actively scanning, so don't send the abort command */
1203 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
1204 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1208 rc
= iwl_send_cmd_sync(priv
, &cmd
);
1210 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1214 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1215 if (res
->u
.status
!= CAN_ABORT_STATUS
) {
1216 /* The scan abort will return 1 for success or
1217 * 2 for "failure". A failure condition can be
1218 * due to simply not being in an active scan which
1219 * can occur if we send the scan abort before we
1220 * the microcode has notified us that a scan is
1222 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res
->u
.status
);
1223 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1224 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
1227 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1232 static int iwl_card_state_sync_callback(struct iwl_priv
*priv
,
1233 struct iwl_cmd
*cmd
,
1234 struct sk_buff
*skb
)
1242 * Use: Sets the internal card state to enable, disable, or halt
1244 * When in the 'enable' state the card operates as normal.
1245 * When in the 'disable' state, the card enters into a low power mode.
1246 * When in the 'halt' state, the card is shut down and must be fully
1247 * restarted to come back on.
1249 static int iwl_send_card_state(struct iwl_priv
*priv
, u32 flags
, u8 meta_flag
)
1251 struct iwl_host_cmd cmd
= {
1252 .id
= REPLY_CARD_STATE_CMD
,
1255 .meta
.flags
= meta_flag
,
1258 if (meta_flag
& CMD_ASYNC
)
1259 cmd
.meta
.u
.callback
= iwl_card_state_sync_callback
;
1261 return iwl_send_cmd(priv
, &cmd
);
1264 static int iwl_add_sta_sync_callback(struct iwl_priv
*priv
,
1265 struct iwl_cmd
*cmd
, struct sk_buff
*skb
)
1267 struct iwl_rx_packet
*res
= NULL
;
1270 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1274 res
= (struct iwl_rx_packet
*)skb
->data
;
1275 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1276 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1281 switch (res
->u
.add_sta
.status
) {
1282 case ADD_STA_SUCCESS_MSK
:
1288 /* We didn't cache the SKB; let the caller free it */
1292 int iwl_send_add_station(struct iwl_priv
*priv
,
1293 struct iwl_addsta_cmd
*sta
, u8 flags
)
1295 struct iwl_rx_packet
*res
= NULL
;
1297 struct iwl_host_cmd cmd
= {
1298 .id
= REPLY_ADD_STA
,
1299 .len
= sizeof(struct iwl_addsta_cmd
),
1300 .meta
.flags
= flags
,
1304 if (flags
& CMD_ASYNC
)
1305 cmd
.meta
.u
.callback
= iwl_add_sta_sync_callback
;
1307 cmd
.meta
.flags
|= CMD_WANT_SKB
;
1309 rc
= iwl_send_cmd(priv
, &cmd
);
1311 if (rc
|| (flags
& CMD_ASYNC
))
1314 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1315 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1316 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1322 switch (res
->u
.add_sta
.status
) {
1323 case ADD_STA_SUCCESS_MSK
:
1324 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1328 IWL_WARNING("REPLY_ADD_STA failed\n");
1333 priv
->alloc_rxb_skb
--;
1334 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1339 static int iwl_update_sta_key_info(struct iwl_priv
*priv
,
1340 struct ieee80211_key_conf
*keyconf
,
1343 unsigned long flags
;
1344 __le16 key_flags
= 0;
1346 switch (keyconf
->alg
) {
1348 key_flags
|= STA_KEY_FLG_CCMP
;
1349 key_flags
|= cpu_to_le16(
1350 keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1351 key_flags
&= ~STA_KEY_FLG_INVALID
;
1359 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1360 priv
->stations
[sta_id
].keyinfo
.alg
= keyconf
->alg
;
1361 priv
->stations
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
1362 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
,
1365 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
,
1367 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
1368 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1369 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1371 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1373 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
1374 iwl_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, 0);
1378 static int iwl_clear_sta_key_info(struct iwl_priv
*priv
, u8 sta_id
)
1380 unsigned long flags
;
1382 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1383 memset(&priv
->stations
[sta_id
].keyinfo
, 0, sizeof(struct iwl_hw_key
));
1384 memset(&priv
->stations
[sta_id
].sta
.key
, 0, sizeof(struct iwl_keyinfo
));
1385 priv
->stations
[sta_id
].sta
.key
.key_flags
= STA_KEY_FLG_NO_ENC
;
1386 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1387 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1388 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1390 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
1391 iwl_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, 0);
1395 static void iwl_clear_free_frames(struct iwl_priv
*priv
)
1397 struct list_head
*element
;
1399 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1400 priv
->frames_count
);
1402 while (!list_empty(&priv
->free_frames
)) {
1403 element
= priv
->free_frames
.next
;
1405 kfree(list_entry(element
, struct iwl_frame
, list
));
1406 priv
->frames_count
--;
1409 if (priv
->frames_count
) {
1410 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1411 priv
->frames_count
);
1412 priv
->frames_count
= 0;
1416 static struct iwl_frame
*iwl_get_free_frame(struct iwl_priv
*priv
)
1418 struct iwl_frame
*frame
;
1419 struct list_head
*element
;
1420 if (list_empty(&priv
->free_frames
)) {
1421 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
1423 IWL_ERROR("Could not allocate frame!\n");
1427 priv
->frames_count
++;
1431 element
= priv
->free_frames
.next
;
1433 return list_entry(element
, struct iwl_frame
, list
);
1436 static void iwl_free_frame(struct iwl_priv
*priv
, struct iwl_frame
*frame
)
1438 memset(frame
, 0, sizeof(*frame
));
1439 list_add(&frame
->list
, &priv
->free_frames
);
1442 unsigned int iwl_fill_beacon_frame(struct iwl_priv
*priv
,
1443 struct ieee80211_hdr
*hdr
,
1444 const u8
*dest
, int left
)
1447 if (!iwl_is_associated(priv
) || !priv
->ibss_beacon
||
1448 ((priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) &&
1449 (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
)))
1452 if (priv
->ibss_beacon
->len
> left
)
1455 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
1457 return priv
->ibss_beacon
->len
;
1460 static int iwl_rate_index_from_plcp(int plcp
)
1464 for (i
= 0; i
< IWL_RATE_COUNT
; i
++)
1465 if (iwl_rates
[i
].plcp
== plcp
)
1470 static u8
iwl_rate_get_lowest_plcp(int rate_mask
)
1474 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
1475 i
= iwl_rates
[i
].next_ieee
) {
1476 if (rate_mask
& (1 << i
))
1477 return iwl_rates
[i
].plcp
;
1480 return IWL_RATE_INVALID
;
1483 static int iwl_send_beacon_cmd(struct iwl_priv
*priv
)
1485 struct iwl_frame
*frame
;
1486 unsigned int frame_size
;
1490 frame
= iwl_get_free_frame(priv
);
1493 IWL_ERROR("Could not obtain free frame buffer for beacon "
1498 if (!(priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)) {
1499 rate
= iwl_rate_get_lowest_plcp(priv
->active_rate_basic
&
1501 if (rate
== IWL_INVALID_RATE
)
1502 rate
= IWL_RATE_6M_PLCP
;
1504 rate
= iwl_rate_get_lowest_plcp(priv
->active_rate_basic
& 0xF);
1505 if (rate
== IWL_INVALID_RATE
)
1506 rate
= IWL_RATE_1M_PLCP
;
1509 frame_size
= iwl_hw_get_beacon_cmd(priv
, frame
, rate
);
1511 rc
= iwl_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
1514 iwl_free_frame(priv
, frame
);
1519 /******************************************************************************
1521 * EEPROM related functions
1523 ******************************************************************************/
1525 static void get_eeprom_mac(struct iwl_priv
*priv
, u8
*mac
)
1527 memcpy(mac
, priv
->eeprom
.mac_address
, 6);
1531 * iwl_eeprom_init - read EEPROM contents
1533 * Load the EEPROM from adapter into priv->eeprom
1535 * NOTE: This routine uses the non-debug IO access functions.
1537 int iwl_eeprom_init(struct iwl_priv
*priv
)
1539 u16
*e
= (u16
*)&priv
->eeprom
;
1540 u32 gp
= iwl_read32(priv
, CSR_EEPROM_GP
);
1542 int sz
= sizeof(priv
->eeprom
);
1547 /* The EEPROM structure has several padding buffers within it
1548 * and when adding new EEPROM maps is subject to programmer errors
1549 * which may be very difficult to identify without explicitly
1550 * checking the resulting size of the eeprom map. */
1551 BUILD_BUG_ON(sizeof(priv
->eeprom
) != IWL_EEPROM_IMAGE_SIZE
);
1553 if ((gp
& CSR_EEPROM_GP_VALID_MSK
) == CSR_EEPROM_GP_BAD_SIGNATURE
) {
1554 IWL_ERROR("EEPROM not found, EEPROM_GP=0x%08x", gp
);
1558 rc
= iwl_eeprom_aqcuire_semaphore(priv
);
1560 IWL_ERROR("Failed to aqcuire EEPROM semaphore.\n");
1564 /* eeprom is an array of 16bit values */
1565 for (addr
= 0; addr
< sz
; addr
+= sizeof(u16
)) {
1566 _iwl_write32(priv
, CSR_EEPROM_REG
, addr
<< 1);
1567 _iwl_clear_bit(priv
, CSR_EEPROM_REG
, CSR_EEPROM_REG_BIT_CMD
);
1569 for (i
= 0; i
< IWL_EEPROM_ACCESS_TIMEOUT
;
1570 i
+= IWL_EEPROM_ACCESS_DELAY
) {
1571 r
= _iwl_read_restricted(priv
, CSR_EEPROM_REG
);
1572 if (r
& CSR_EEPROM_REG_READ_VALID_MSK
)
1574 udelay(IWL_EEPROM_ACCESS_DELAY
);
1577 if (!(r
& CSR_EEPROM_REG_READ_VALID_MSK
)) {
1578 IWL_ERROR("Time out reading EEPROM[%d]", addr
);
1581 e
[addr
/ 2] = le16_to_cpu(r
>> 16);
1587 /******************************************************************************
1589 * Misc. internal state and helper functions
1591 ******************************************************************************/
1592 #ifdef CONFIG_IWLWIFI_DEBUG
1595 * iwl_report_frame - dump frame to syslog during debug sessions
1597 * hack this function to show different aspects of received frames,
1598 * including selective frame dumps.
1599 * group100 parameter selects whether to show 1 out of 100 good frames.
1601 * TODO: ieee80211_hdr stuff is common to 3945 and 4965, so frame type
1602 * info output is okay, but some of this stuff (e.g. iwl_rx_frame_stats)
1603 * is 3945-specific and gives bad output for 4965. Need to split the
1604 * functionality, keep common stuff here.
1606 void iwl_report_frame(struct iwl_priv
*priv
,
1607 struct iwl_rx_packet
*pkt
,
1608 struct ieee80211_hdr
*header
, int group100
)
1611 u32 print_summary
= 0;
1612 u32 print_dump
= 0; /* set to 1 to dump all frames' contents */
1629 struct iwl_rx_frame_stats
*rx_stats
= IWL_RX_STATS(pkt
);
1630 struct iwl_rx_frame_hdr
*rx_hdr
= IWL_RX_HDR(pkt
);
1631 struct iwl_rx_frame_end
*rx_end
= IWL_RX_END(pkt
);
1632 u8
*data
= IWL_RX_DATA(pkt
);
1635 fc
= le16_to_cpu(header
->frame_control
);
1636 seq_ctl
= le16_to_cpu(header
->seq_ctrl
);
1639 channel
= le16_to_cpu(rx_hdr
->channel
);
1640 phy_flags
= le16_to_cpu(rx_hdr
->phy_flags
);
1641 rate_sym
= rx_hdr
->rate
;
1642 length
= le16_to_cpu(rx_hdr
->len
);
1644 /* end-of-frame status and timestamp */
1645 status
= le32_to_cpu(rx_end
->status
);
1646 bcn_tmr
= le32_to_cpu(rx_end
->beacon_timestamp
);
1647 tsf_low
= le64_to_cpu(rx_end
->timestamp
) & 0x0ffffffff;
1648 tsf
= le64_to_cpu(rx_end
->timestamp
);
1650 /* signal statistics */
1651 rssi
= rx_stats
->rssi
;
1652 agc
= rx_stats
->agc
;
1653 sig_avg
= le16_to_cpu(rx_stats
->sig_avg
);
1654 noise_diff
= le16_to_cpu(rx_stats
->noise_diff
);
1656 to_us
= !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
1658 /* if data frame is to us and all is good,
1659 * (optionally) print summary for only 1 out of every 100 */
1660 if (to_us
&& (fc
& ~IEEE80211_FCTL_PROTECTED
) ==
1661 (IEEE80211_FCTL_FROMDS
| IEEE80211_FTYPE_DATA
)) {
1664 print_summary
= 1; /* print each frame */
1665 else if (priv
->framecnt_to_us
< 100) {
1666 priv
->framecnt_to_us
++;
1669 priv
->framecnt_to_us
= 0;
1674 /* print summary for all other frames */
1678 if (print_summary
) {
1683 title
= "100Frames";
1684 else if (fc
& IEEE80211_FCTL_RETRY
)
1686 else if (ieee80211_is_assoc_response(fc
))
1688 else if (ieee80211_is_reassoc_response(fc
))
1690 else if (ieee80211_is_probe_response(fc
)) {
1692 print_dump
= 1; /* dump frame contents */
1693 } else if (ieee80211_is_beacon(fc
)) {
1695 print_dump
= 1; /* dump frame contents */
1696 } else if (ieee80211_is_atim(fc
))
1698 else if (ieee80211_is_auth(fc
))
1700 else if (ieee80211_is_deauth(fc
))
1702 else if (ieee80211_is_disassoc(fc
))
1707 rate
= iwl_rate_index_from_plcp(rate_sym
);
1711 rate
= iwl_rates
[rate
].ieee
/ 2;
1713 /* print frame summary.
1714 * MAC addresses show just the last byte (for brevity),
1715 * but you can hack it to show more, if you'd like to. */
1717 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
1718 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
1719 title
, fc
, header
->addr1
[5],
1720 length
, rssi
, channel
, rate
);
1722 /* src/dst addresses assume managed mode */
1723 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
1724 "src=0x%02x, rssi=%u, tim=%lu usec, "
1725 "phy=0x%02x, chnl=%d\n",
1726 title
, fc
, header
->addr1
[5],
1727 header
->addr3
[5], rssi
,
1728 tsf_low
- priv
->scan_start_tsf
,
1729 phy_flags
, channel
);
1733 iwl_print_hex_dump(IWL_DL_RX
, data
, length
);
1737 static void iwl_unset_hw_setting(struct iwl_priv
*priv
)
1739 if (priv
->hw_setting
.shared_virt
)
1740 pci_free_consistent(priv
->pci_dev
,
1741 sizeof(struct iwl_shared
),
1742 priv
->hw_setting
.shared_virt
,
1743 priv
->hw_setting
.shared_phys
);
1747 * iwl_supported_rate_to_ie - fill in the supported rate in IE field
1749 * return : set the bit for each supported rate insert in ie
1751 static u16
iwl_supported_rate_to_ie(u8
*ie
, u16 supported_rate
,
1752 u16 basic_rate
, int max_count
)
1754 u16 ret_rates
= 0, bit
;
1760 for (bit
= 1, i
= 0; i
< IWL_RATE_COUNT
; i
++, bit
<<= 1) {
1761 if (bit
& supported_rate
) {
1763 rates
[*ie
] = iwl_rates
[i
].ieee
|
1764 ((bit
& basic_rate
) ? 0x80 : 0x00);
1766 if (*ie
>= max_count
)
1775 * iwl_fill_probe_req - fill in all required fields and IE for probe request
1777 static u16
iwl_fill_probe_req(struct iwl_priv
*priv
,
1778 struct ieee80211_mgmt
*frame
,
1779 int left
, int is_direct
)
1785 /* Make sure there is enough space for the probe request,
1786 * two mandatory IEs and the data */
1792 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
1793 memcpy(frame
->da
, BROADCAST_ADDR
, ETH_ALEN
);
1794 memcpy(frame
->sa
, priv
->mac_addr
, ETH_ALEN
);
1795 memcpy(frame
->bssid
, BROADCAST_ADDR
, ETH_ALEN
);
1796 frame
->seq_ctrl
= 0;
1798 /* fill in our indirect SSID IE */
1805 pos
= &(frame
->u
.probe_req
.variable
[0]);
1806 *pos
++ = WLAN_EID_SSID
;
1809 /* fill in our direct SSID IE... */
1812 left
-= 2 + priv
->essid_len
;
1815 /* ... fill it in... */
1816 *pos
++ = WLAN_EID_SSID
;
1817 *pos
++ = priv
->essid_len
;
1818 memcpy(pos
, priv
->essid
, priv
->essid_len
);
1819 pos
+= priv
->essid_len
;
1820 len
+= 2 + priv
->essid_len
;
1823 /* fill in supported rate */
1828 /* ... fill it in... */
1829 *pos
++ = WLAN_EID_SUPP_RATES
;
1831 ret_rates
= priv
->active_rate
= priv
->rates_mask
;
1832 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
1834 iwl_supported_rate_to_ie(pos
, priv
->active_rate
,
1835 priv
->active_rate_basic
, left
);
1838 ret_rates
= ~ret_rates
& priv
->active_rate
;
1843 /* fill in supported extended rate */
1848 /* ... fill it in... */
1849 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
1851 iwl_supported_rate_to_ie(pos
, ret_rates
, priv
->active_rate_basic
, left
);
1862 #ifdef CONFIG_IWLWIFI_QOS
1863 static int iwl_send_qos_params_command(struct iwl_priv
*priv
,
1864 struct iwl_qosparam_cmd
*qos
)
1867 return iwl_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
1868 sizeof(struct iwl_qosparam_cmd
), qos
);
1871 static void iwl_reset_qos(struct iwl_priv
*priv
)
1877 unsigned long flags
;
1880 spin_lock_irqsave(&priv
->lock
, flags
);
1881 priv
->qos_data
.qos_active
= 0;
1883 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) {
1884 if (priv
->qos_data
.qos_enable
)
1885 priv
->qos_data
.qos_active
= 1;
1886 if (!(priv
->active_rate
& 0xfff0)) {
1890 } else if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
1891 if (priv
->qos_data
.qos_enable
)
1892 priv
->qos_data
.qos_active
= 1;
1893 } else if (!(priv
->staging_rxon
.flags
& RXON_FLG_SHORT_SLOT_MSK
)) {
1898 if (priv
->qos_data
.qos_active
)
1901 priv
->qos_data
.def_qos_parm
.ac
[0].cw_min
= cpu_to_le16(cw_min
);
1902 priv
->qos_data
.def_qos_parm
.ac
[0].cw_max
= cpu_to_le16(cw_max
);
1903 priv
->qos_data
.def_qos_parm
.ac
[0].aifsn
= aifs
;
1904 priv
->qos_data
.def_qos_parm
.ac
[0].edca_txop
= 0;
1905 priv
->qos_data
.def_qos_parm
.ac
[0].reserved1
= 0;
1907 if (priv
->qos_data
.qos_active
) {
1909 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
= cpu_to_le16(cw_min
);
1910 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
= cpu_to_le16(cw_max
);
1911 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 7;
1912 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
= 0;
1913 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1916 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
1917 cpu_to_le16((cw_min
+ 1) / 2 - 1);
1918 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
1919 cpu_to_le16(cw_max
);
1920 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 2;
1922 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1925 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1927 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1930 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
1931 cpu_to_le16((cw_min
+ 1) / 4 - 1);
1932 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
1933 cpu_to_le16((cw_max
+ 1) / 2 - 1);
1934 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= 2;
1935 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1937 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1940 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
=
1943 for (i
= 1; i
< 4; i
++) {
1944 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_min
=
1945 cpu_to_le16(cw_min
);
1946 priv
->qos_data
.def_qos_parm
.ac
[i
].cw_max
=
1947 cpu_to_le16(cw_max
);
1948 priv
->qos_data
.def_qos_parm
.ac
[i
].aifsn
= aifs
;
1949 priv
->qos_data
.def_qos_parm
.ac
[i
].edca_txop
= 0;
1950 priv
->qos_data
.def_qos_parm
.ac
[i
].reserved1
= 0;
1953 IWL_DEBUG_QOS("set QoS to default \n");
1955 spin_unlock_irqrestore(&priv
->lock
, flags
);
1958 static void iwl_activate_qos(struct iwl_priv
*priv
, u8 force
)
1960 unsigned long flags
;
1965 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1968 if (!priv
->qos_data
.qos_enable
)
1971 spin_lock_irqsave(&priv
->lock
, flags
);
1972 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
1974 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
1975 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
1976 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1977 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
1979 if (priv
->qos_data
.qos_active
)
1980 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1981 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
1983 spin_unlock_irqrestore(&priv
->lock
, flags
);
1985 if (force
|| iwl_is_associated(priv
)) {
1986 IWL_DEBUG_QOS("send QoS cmd with Qos active %d \n",
1987 priv
->qos_data
.qos_active
);
1989 iwl_send_qos_params_command(priv
,
1990 &(priv
->qos_data
.def_qos_parm
));
1994 #endif /* CONFIG_IWLWIFI_QOS */
1996 * Power management (not Tx power!) functions
1998 #define MSEC_TO_USEC 1024
2000 #define NOSLP __constant_cpu_to_le32(0)
2001 #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK
2002 #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
2003 #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
2004 __constant_cpu_to_le32(X1), \
2005 __constant_cpu_to_le32(X2), \
2006 __constant_cpu_to_le32(X3), \
2007 __constant_cpu_to_le32(X4)}
2010 /* default power management (not Tx power) table values */
2012 static struct iwl_power_vec_entry range_0
[IWL_POWER_AC
] = {
2013 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2014 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
2015 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
2016 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
2017 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
2018 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
2022 static struct iwl_power_vec_entry range_1
[IWL_POWER_AC
] = {
2023 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
2024 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
2025 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
2026 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
2027 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
2028 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
2029 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
2030 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
2031 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
2032 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
2035 int iwl_power_init_handle(struct iwl_priv
*priv
)
2038 struct iwl_power_mgr
*pow_data
;
2039 int size
= sizeof(struct iwl_power_vec_entry
) * IWL_POWER_AC
;
2042 IWL_DEBUG_POWER("Initialize power \n");
2044 pow_data
= &(priv
->power_data
);
2046 memset(pow_data
, 0, sizeof(*pow_data
));
2048 pow_data
->active_index
= IWL_POWER_RANGE_0
;
2049 pow_data
->dtim_val
= 0xffff;
2051 memcpy(&pow_data
->pwr_range_0
[0], &range_0
[0], size
);
2052 memcpy(&pow_data
->pwr_range_1
[0], &range_1
[0], size
);
2054 rc
= pci_read_config_word(priv
->pci_dev
, PCI_LINK_CTRL
, &pci_pm
);
2058 struct iwl_powertable_cmd
*cmd
;
2060 IWL_DEBUG_POWER("adjust power command flags\n");
2062 for (i
= 0; i
< IWL_POWER_AC
; i
++) {
2063 cmd
= &pow_data
->pwr_range_0
[i
].cmd
;
2066 cmd
->flags
&= ~IWL_POWER_PCI_PM_MSK
;
2068 cmd
->flags
|= IWL_POWER_PCI_PM_MSK
;
2074 static int iwl_update_power_cmd(struct iwl_priv
*priv
,
2075 struct iwl_powertable_cmd
*cmd
, u32 mode
)
2080 struct iwl_power_vec_entry
*range
;
2082 struct iwl_power_mgr
*pow_data
;
2084 if (mode
> IWL_POWER_INDEX_5
) {
2085 IWL_DEBUG_POWER("Error invalid power mode \n");
2088 pow_data
= &(priv
->power_data
);
2090 if (pow_data
->active_index
== IWL_POWER_RANGE_0
)
2091 range
= &pow_data
->pwr_range_0
[0];
2093 range
= &pow_data
->pwr_range_1
[1];
2095 memcpy(cmd
, &range
[mode
].cmd
, sizeof(struct iwl_powertable_cmd
));
2097 #ifdef IWL_MAC80211_DISABLE
2098 if (priv
->assoc_network
!= NULL
) {
2099 unsigned long flags
;
2101 period
= priv
->assoc_network
->tim
.tim_period
;
2103 #endif /*IWL_MAC80211_DISABLE */
2104 skip
= range
[mode
].no_dtim
;
2113 cmd
->flags
&= ~IWL_POWER_SLEEP_OVER_DTIM_MSK
;
2115 __le32 slp_itrvl
= cmd
->sleep_interval
[IWL_POWER_VEC_SIZE
- 1];
2116 max_sleep
= (le32_to_cpu(slp_itrvl
) / period
) * period
;
2117 cmd
->flags
|= IWL_POWER_SLEEP_OVER_DTIM_MSK
;
2120 for (i
= 0; i
< IWL_POWER_VEC_SIZE
; i
++) {
2121 if (le32_to_cpu(cmd
->sleep_interval
[i
]) > max_sleep
)
2122 cmd
->sleep_interval
[i
] = cpu_to_le32(max_sleep
);
2125 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd
->flags
);
2126 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd
->tx_data_timeout
));
2127 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd
->rx_data_timeout
));
2128 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
2129 le32_to_cpu(cmd
->sleep_interval
[0]),
2130 le32_to_cpu(cmd
->sleep_interval
[1]),
2131 le32_to_cpu(cmd
->sleep_interval
[2]),
2132 le32_to_cpu(cmd
->sleep_interval
[3]),
2133 le32_to_cpu(cmd
->sleep_interval
[4]));
2138 static int iwl_send_power_mode(struct iwl_priv
*priv
, u32 mode
)
2140 u32 final_mode
= mode
;
2142 struct iwl_powertable_cmd cmd
;
2144 /* If on battery, set to 3,
2145 * if plugged into AC power, set to CAM ("continuosly aware mode"),
2146 * else user level */
2148 case IWL_POWER_BATTERY
:
2149 final_mode
= IWL_POWER_INDEX_3
;
2152 final_mode
= IWL_POWER_MODE_CAM
;
2159 iwl_update_power_cmd(priv
, &cmd
, final_mode
);
2161 rc
= iwl_send_cmd_pdu(priv
, POWER_TABLE_CMD
, sizeof(cmd
), &cmd
);
2163 if (final_mode
== IWL_POWER_MODE_CAM
)
2164 clear_bit(STATUS_POWER_PMI
, &priv
->status
);
2166 set_bit(STATUS_POWER_PMI
, &priv
->status
);
2171 int iwl_is_network_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
2173 /* Filter incoming packets to determine if they are targeted toward
2174 * this network, discarding packets coming from ourselves */
2175 switch (priv
->iw_mode
) {
2176 case IEEE80211_IF_TYPE_IBSS
: /* Header: Dest. | Source | BSSID */
2177 /* packets from our adapter are dropped (echo) */
2178 if (!compare_ether_addr(header
->addr2
, priv
->mac_addr
))
2180 /* {broad,multi}cast packets to our IBSS go through */
2181 if (is_multicast_ether_addr(header
->addr1
))
2182 return !compare_ether_addr(header
->addr3
, priv
->bssid
);
2183 /* packets to our adapter go through */
2184 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
2185 case IEEE80211_IF_TYPE_STA
: /* Header: Dest. | AP{BSSID} | Source */
2186 /* packets from our adapter are dropped (echo) */
2187 if (!compare_ether_addr(header
->addr3
, priv
->mac_addr
))
2189 /* {broad,multi}cast packets to our BSS go through */
2190 if (is_multicast_ether_addr(header
->addr1
))
2191 return !compare_ether_addr(header
->addr2
, priv
->bssid
);
2192 /* packets to our adapter go through */
2193 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
2199 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
2201 const char *iwl_get_tx_fail_reason(u32 status
)
2203 switch (status
& TX_STATUS_MSK
) {
2204 case TX_STATUS_SUCCESS
:
2206 TX_STATUS_ENTRY(SHORT_LIMIT
);
2207 TX_STATUS_ENTRY(LONG_LIMIT
);
2208 TX_STATUS_ENTRY(FIFO_UNDERRUN
);
2209 TX_STATUS_ENTRY(MGMNT_ABORT
);
2210 TX_STATUS_ENTRY(NEXT_FRAG
);
2211 TX_STATUS_ENTRY(LIFE_EXPIRE
);
2212 TX_STATUS_ENTRY(DEST_PS
);
2213 TX_STATUS_ENTRY(ABORTED
);
2214 TX_STATUS_ENTRY(BT_RETRY
);
2215 TX_STATUS_ENTRY(STA_INVALID
);
2216 TX_STATUS_ENTRY(FRAG_DROPPED
);
2217 TX_STATUS_ENTRY(TID_DISABLE
);
2218 TX_STATUS_ENTRY(FRAME_FLUSHED
);
2219 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL
);
2220 TX_STATUS_ENTRY(TX_LOCKED
);
2221 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR
);
2228 * iwl_scan_cancel - Cancel any currently executing HW scan
2230 * NOTE: priv->mutex is not required before calling this function
2232 static int iwl_scan_cancel(struct iwl_priv
*priv
)
2234 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
2235 clear_bit(STATUS_SCANNING
, &priv
->status
);
2239 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
2240 if (!test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
2241 IWL_DEBUG_SCAN("Queuing scan abort.\n");
2242 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
2243 queue_work(priv
->workqueue
, &priv
->abort_scan
);
2246 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
2248 return test_bit(STATUS_SCANNING
, &priv
->status
);
2255 * iwl_scan_cancel_timeout - Cancel any currently executing HW scan
2256 * @ms: amount of time to wait (in milliseconds) for scan to abort
2258 * NOTE: priv->mutex must be held before calling this function
2260 static int iwl_scan_cancel_timeout(struct iwl_priv
*priv
, unsigned long ms
)
2262 unsigned long now
= jiffies
;
2265 ret
= iwl_scan_cancel(priv
);
2267 mutex_unlock(&priv
->mutex
);
2268 while (!time_after(jiffies
, now
+ msecs_to_jiffies(ms
)) &&
2269 test_bit(STATUS_SCANNING
, &priv
->status
))
2271 mutex_lock(&priv
->mutex
);
2273 return test_bit(STATUS_SCANNING
, &priv
->status
);
2279 static void iwl_sequence_reset(struct iwl_priv
*priv
)
2281 /* Reset ieee stats */
2283 /* We don't reset the net_device_stats (ieee->stats) on
2286 priv
->last_seq_num
= -1;
2287 priv
->last_frag_num
= -1;
2288 priv
->last_packet_time
= 0;
2290 iwl_scan_cancel(priv
);
2293 #define MAX_UCODE_BEACON_INTERVAL 1024
2294 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
2296 static __le16
iwl_adjust_beacon_interval(u16 beacon_val
)
2299 u16 beacon_factor
= 0;
2302 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
2303 / MAX_UCODE_BEACON_INTERVAL
;
2304 new_val
= beacon_val
/ beacon_factor
;
2306 return cpu_to_le16(new_val
);
2309 static void iwl_setup_rxon_timing(struct iwl_priv
*priv
)
2311 u64 interval_tm_unit
;
2313 unsigned long flags
;
2314 struct ieee80211_conf
*conf
= NULL
;
2317 conf
= ieee80211_get_hw_conf(priv
->hw
);
2319 spin_lock_irqsave(&priv
->lock
, flags
);
2320 priv
->rxon_timing
.timestamp
.dw
[1] = cpu_to_le32(priv
->timestamp1
);
2321 priv
->rxon_timing
.timestamp
.dw
[0] = cpu_to_le32(priv
->timestamp0
);
2323 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
2325 tsf
= priv
->timestamp1
;
2326 tsf
= ((tsf
<< 32) | priv
->timestamp0
);
2328 beacon_int
= priv
->beacon_int
;
2329 spin_unlock_irqrestore(&priv
->lock
, flags
);
2331 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
2332 if (beacon_int
== 0) {
2333 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
2334 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
2336 priv
->rxon_timing
.beacon_interval
=
2337 cpu_to_le16(beacon_int
);
2338 priv
->rxon_timing
.beacon_interval
=
2339 iwl_adjust_beacon_interval(
2340 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2343 priv
->rxon_timing
.atim_window
= 0;
2345 priv
->rxon_timing
.beacon_interval
=
2346 iwl_adjust_beacon_interval(conf
->beacon_int
);
2347 /* TODO: we need to get atim_window from upper stack
2348 * for now we set to 0 */
2349 priv
->rxon_timing
.atim_window
= 0;
2353 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
2354 result
= do_div(tsf
, interval_tm_unit
);
2355 priv
->rxon_timing
.beacon_init_val
=
2356 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
2359 ("beacon interval %d beacon timer %d beacon tim %d\n",
2360 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
2361 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
2362 le16_to_cpu(priv
->rxon_timing
.atim_window
));
2365 static int iwl_scan_initiate(struct iwl_priv
*priv
)
2367 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
2368 IWL_ERROR("APs don't scan.\n");
2372 if (!iwl_is_ready_rf(priv
)) {
2373 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
2377 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
2378 IWL_DEBUG_SCAN("Scan already in progress.\n");
2382 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
2383 IWL_DEBUG_SCAN("Scan request while abort pending. "
2388 IWL_DEBUG_INFO("Starting scan...\n");
2389 priv
->scan_bands
= 2;
2390 set_bit(STATUS_SCANNING
, &priv
->status
);
2391 priv
->scan_start
= jiffies
;
2392 priv
->scan_pass_start
= priv
->scan_start
;
2394 queue_work(priv
->workqueue
, &priv
->request_scan
);
2399 static int iwl_set_rxon_hwcrypto(struct iwl_priv
*priv
, int hw_decrypt
)
2401 struct iwl_rxon_cmd
*rxon
= &priv
->staging_rxon
;
2404 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
2406 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
2411 static void iwl_set_flags_for_phymode(struct iwl_priv
*priv
, u8 phymode
)
2413 if (phymode
== MODE_IEEE80211A
) {
2414 priv
->staging_rxon
.flags
&=
2415 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
2416 | RXON_FLG_CCK_MSK
);
2417 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2419 /* Copied from iwl_bg_post_associate() */
2420 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
2421 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
2423 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2425 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
2426 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
2428 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
2429 priv
->staging_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
2430 priv
->staging_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
2435 * initilize rxon structure with default values fromm eeprom
2437 static void iwl_connection_init_rx_config(struct iwl_priv
*priv
)
2439 const struct iwl_channel_info
*ch_info
;
2441 memset(&priv
->staging_rxon
, 0, sizeof(priv
->staging_rxon
));
2443 switch (priv
->iw_mode
) {
2444 case IEEE80211_IF_TYPE_AP
:
2445 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
2448 case IEEE80211_IF_TYPE_STA
:
2449 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
2450 priv
->staging_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
2453 case IEEE80211_IF_TYPE_IBSS
:
2454 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
2455 priv
->staging_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
2456 priv
->staging_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
2457 RXON_FILTER_ACCEPT_GRP_MSK
;
2460 case IEEE80211_IF_TYPE_MNTR
:
2461 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
2462 priv
->staging_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
2463 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
2468 /* TODO: Figure out when short_preamble would be set and cache from
2470 if (!hw_to_local(priv
->hw
)->short_preamble
)
2471 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
2473 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
2476 ch_info
= iwl_get_channel_info(priv
, priv
->phymode
,
2477 le16_to_cpu(priv
->staging_rxon
.channel
));
2480 ch_info
= &priv
->channel_info
[0];
2483 * in some case A channels are all non IBSS
2484 * in this case force B/G channel
2486 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) &&
2487 !(is_channel_ibss(ch_info
)))
2488 ch_info
= &priv
->channel_info
[0];
2490 priv
->staging_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
2491 if (is_channel_a_band(ch_info
))
2492 priv
->phymode
= MODE_IEEE80211A
;
2494 priv
->phymode
= MODE_IEEE80211G
;
2496 iwl_set_flags_for_phymode(priv
, priv
->phymode
);
2498 priv
->staging_rxon
.ofdm_basic_rates
=
2499 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2500 priv
->staging_rxon
.cck_basic_rates
=
2501 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2504 static int iwl_set_mode(struct iwl_priv
*priv
, int mode
)
2506 if (!iwl_is_ready_rf(priv
))
2509 if (mode
== IEEE80211_IF_TYPE_IBSS
) {
2510 const struct iwl_channel_info
*ch_info
;
2512 ch_info
= iwl_get_channel_info(priv
,
2514 le16_to_cpu(priv
->staging_rxon
.channel
));
2516 if (!ch_info
|| !is_channel_ibss(ch_info
)) {
2517 IWL_ERROR("channel %d not IBSS channel\n",
2518 le16_to_cpu(priv
->staging_rxon
.channel
));
2523 cancel_delayed_work(&priv
->scan_check
);
2524 if (iwl_scan_cancel_timeout(priv
, 100)) {
2525 IWL_WARNING("Aborted scan still in progress after 100ms\n");
2526 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2530 priv
->iw_mode
= mode
;
2532 iwl_connection_init_rx_config(priv
);
2533 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
2535 iwl_clear_stations_table(priv
);
2537 iwl_commit_rxon(priv
);
2542 static void iwl_build_tx_cmd_hwcrypto(struct iwl_priv
*priv
,
2543 struct ieee80211_tx_control
*ctl
,
2544 struct iwl_cmd
*cmd
,
2545 struct sk_buff
*skb_frag
,
2548 struct iwl_hw_key
*keyinfo
= &priv
->stations
[ctl
->key_idx
].keyinfo
;
2550 switch (keyinfo
->alg
) {
2552 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_CCM
;
2553 memcpy(cmd
->cmd
.tx
.key
, keyinfo
->key
, keyinfo
->keylen
);
2554 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2559 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_TKIP
;
2562 memcpy(cmd
->cmd
.tx
.tkip_mic
.byte
, skb_frag
->tail
- 8,
2565 memset(cmd
->cmd
.tx
.tkip_mic
.byte
, 0, 8);
2570 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_WEP
|
2571 (ctl
->key_idx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
;
2573 if (keyinfo
->keylen
== 13)
2574 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
2576 memcpy(&cmd
->cmd
.tx
.key
[3], keyinfo
->key
, keyinfo
->keylen
);
2578 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2579 "with key %d\n", ctl
->key_idx
);
2583 printk(KERN_ERR
"Unknown encode alg %d\n", keyinfo
->alg
);
2589 * handle build REPLY_TX command notification.
2591 static void iwl_build_tx_cmd_basic(struct iwl_priv
*priv
,
2592 struct iwl_cmd
*cmd
,
2593 struct ieee80211_tx_control
*ctrl
,
2594 struct ieee80211_hdr
*hdr
,
2595 int is_unicast
, u8 std_id
)
2598 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2599 __le32 tx_flags
= cmd
->cmd
.tx
.tx_flags
;
2601 cmd
->cmd
.tx
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
2602 if (!(ctrl
->flags
& IEEE80211_TXCTL_NO_ACK
)) {
2603 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
2604 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
)
2605 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2606 if (ieee80211_is_probe_response(fc
) &&
2607 !(le16_to_cpu(hdr
->seq_ctrl
) & 0xf))
2608 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
2610 tx_flags
&= (~TX_CMD_FLG_ACK_MSK
);
2611 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2614 cmd
->cmd
.tx
.sta_id
= std_id
;
2615 if (ieee80211_get_morefrag(hdr
))
2616 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
2618 qc
= ieee80211_get_qos_ctrl(hdr
);
2620 cmd
->cmd
.tx
.tid_tspec
= (u8
) (le16_to_cpu(*qc
) & 0xf);
2621 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL_MSK
;
2623 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2625 if (ctrl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
) {
2626 tx_flags
|= TX_CMD_FLG_RTS_MSK
;
2627 tx_flags
&= ~TX_CMD_FLG_CTS_MSK
;
2628 } else if (ctrl
->flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
) {
2629 tx_flags
&= ~TX_CMD_FLG_RTS_MSK
;
2630 tx_flags
|= TX_CMD_FLG_CTS_MSK
;
2633 if ((tx_flags
& TX_CMD_FLG_RTS_MSK
) || (tx_flags
& TX_CMD_FLG_CTS_MSK
))
2634 tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
2636 tx_flags
&= ~(TX_CMD_FLG_ANT_SEL_MSK
);
2637 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
2638 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_ASSOC_REQ
||
2639 (fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_REASSOC_REQ
)
2640 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
=
2643 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
=
2646 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= 0;
2648 cmd
->cmd
.tx
.driver_txop
= 0;
2649 cmd
->cmd
.tx
.tx_flags
= tx_flags
;
2650 cmd
->cmd
.tx
.next_frame_len
= 0;
2653 static int iwl_get_sta_id(struct iwl_priv
*priv
, struct ieee80211_hdr
*hdr
)
2656 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2658 /* If this frame is broadcast or not data then use the broadcast
2660 if (((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
) ||
2661 is_multicast_ether_addr(hdr
->addr1
))
2662 return priv
->hw_setting
.bcast_sta_id
;
2664 switch (priv
->iw_mode
) {
2666 /* If this frame is part of a BSS network (we're a station), then
2667 * we use the AP's station id */
2668 case IEEE80211_IF_TYPE_STA
:
2671 /* If we are an AP, then find the station, or use BCAST */
2672 case IEEE80211_IF_TYPE_AP
:
2673 sta_id
= iwl_hw_find_station(priv
, hdr
->addr1
);
2674 if (sta_id
!= IWL_INVALID_STATION
)
2676 return priv
->hw_setting
.bcast_sta_id
;
2678 /* If this frame is part of a IBSS network, then we use the
2679 * target specific station id */
2680 case IEEE80211_IF_TYPE_IBSS
: {
2681 DECLARE_MAC_BUF(mac
);
2683 sta_id
= iwl_hw_find_station(priv
, hdr
->addr1
);
2684 if (sta_id
!= IWL_INVALID_STATION
)
2687 sta_id
= iwl_add_station(priv
, hdr
->addr1
, 0, CMD_ASYNC
);
2689 if (sta_id
!= IWL_INVALID_STATION
)
2692 IWL_DEBUG_DROP("Station %s not in station map. "
2693 "Defaulting to broadcast...\n",
2694 print_mac(mac
, hdr
->addr1
));
2695 iwl_print_hex_dump(IWL_DL_DROP
, (u8
*) hdr
, sizeof(*hdr
));
2696 return priv
->hw_setting
.bcast_sta_id
;
2699 IWL_WARNING("Unkown mode of operation: %d", priv
->iw_mode
);
2700 return priv
->hw_setting
.bcast_sta_id
;
2705 * start REPLY_TX command process
2707 static int iwl_tx_skb(struct iwl_priv
*priv
,
2708 struct sk_buff
*skb
, struct ieee80211_tx_control
*ctl
)
2710 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2711 struct iwl_tfd_frame
*tfd
;
2713 int txq_id
= ctl
->queue
;
2714 struct iwl_tx_queue
*txq
= NULL
;
2715 struct iwl_queue
*q
= NULL
;
2716 dma_addr_t phys_addr
;
2717 dma_addr_t txcmd_phys
;
2718 struct iwl_cmd
*out_cmd
= NULL
;
2719 u16 len
, idx
, len_org
;
2720 u8 id
, hdr_len
, unicast
;
2725 u8 wait_write_ptr
= 0;
2726 unsigned long flags
;
2729 spin_lock_irqsave(&priv
->lock
, flags
);
2730 if (iwl_is_rfkill(priv
)) {
2731 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2735 if (!priv
->interface_id
) {
2736 IWL_DEBUG_DROP("Dropping - !priv->interface_id\n");
2740 if ((ctl
->tx_rate
& 0xFF) == IWL_INVALID_RATE
) {
2741 IWL_ERROR("ERROR: No TX rate available.\n");
2745 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
2748 fc
= le16_to_cpu(hdr
->frame_control
);
2750 #ifdef CONFIG_IWLWIFI_DEBUG
2751 if (ieee80211_is_auth(fc
))
2752 IWL_DEBUG_TX("Sending AUTH frame\n");
2753 else if (ieee80211_is_assoc_request(fc
))
2754 IWL_DEBUG_TX("Sending ASSOC frame\n");
2755 else if (ieee80211_is_reassoc_request(fc
))
2756 IWL_DEBUG_TX("Sending REASSOC frame\n");
2759 if (!iwl_is_associated(priv
) &&
2760 ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
)) {
2761 IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n");
2765 spin_unlock_irqrestore(&priv
->lock
, flags
);
2767 hdr_len
= ieee80211_get_hdrlen(fc
);
2768 sta_id
= iwl_get_sta_id(priv
, hdr
);
2769 if (sta_id
== IWL_INVALID_STATION
) {
2770 DECLARE_MAC_BUF(mac
);
2772 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2773 print_mac(mac
, hdr
->addr1
));
2777 IWL_DEBUG_RATE("station Id %d\n", sta_id
);
2779 qc
= ieee80211_get_qos_ctrl(hdr
);
2781 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2782 seq_number
= priv
->stations
[sta_id
].tid
[tid
].seq_number
&
2784 hdr
->seq_ctrl
= cpu_to_le16(seq_number
) |
2786 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG
));
2789 txq
= &priv
->txq
[txq_id
];
2792 spin_lock_irqsave(&priv
->lock
, flags
);
2794 tfd
= &txq
->bd
[q
->first_empty
];
2795 memset(tfd
, 0, sizeof(*tfd
));
2796 control_flags
= (u32
*) tfd
;
2797 idx
= get_cmd_index(q
, q
->first_empty
, 0);
2799 memset(&(txq
->txb
[q
->first_empty
]), 0, sizeof(struct iwl_tx_info
));
2800 txq
->txb
[q
->first_empty
].skb
[0] = skb
;
2801 memcpy(&(txq
->txb
[q
->first_empty
].status
.control
),
2802 ctl
, sizeof(struct ieee80211_tx_control
));
2803 out_cmd
= &txq
->cmd
[idx
];
2804 memset(&out_cmd
->hdr
, 0, sizeof(out_cmd
->hdr
));
2805 memset(&out_cmd
->cmd
.tx
, 0, sizeof(out_cmd
->cmd
.tx
));
2806 out_cmd
->hdr
.cmd
= REPLY_TX
;
2807 out_cmd
->hdr
.sequence
= cpu_to_le16((u16
)(QUEUE_TO_SEQ(txq_id
) |
2808 INDEX_TO_SEQ(q
->first_empty
)));
2809 /* copy frags header */
2810 memcpy(out_cmd
->cmd
.tx
.hdr
, hdr
, hdr_len
);
2812 /* hdr = (struct ieee80211_hdr *)out_cmd->cmd.tx.hdr; */
2813 len
= priv
->hw_setting
.tx_cmd_len
+
2814 sizeof(struct iwl_cmd_header
) + hdr_len
;
2817 len
= (len
+ 3) & ~3;
2824 txcmd_phys
= txq
->dma_addr_cmd
+ sizeof(struct iwl_cmd
) * idx
+
2825 offsetof(struct iwl_cmd
, hdr
);
2827 iwl_hw_txq_attach_buf_to_tfd(priv
, tfd
, txcmd_phys
, len
);
2829 if (!(ctl
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
))
2830 iwl_build_tx_cmd_hwcrypto(priv
, ctl
, out_cmd
, skb
, 0);
2832 /* 802.11 null functions have no payload... */
2833 len
= skb
->len
- hdr_len
;
2835 phys_addr
= pci_map_single(priv
->pci_dev
, skb
->data
+ hdr_len
,
2836 len
, PCI_DMA_TODEVICE
);
2837 iwl_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, len
);
2840 /* If there is no payload, then only one TFD is used */
2842 *control_flags
= TFD_CTL_COUNT_SET(1);
2844 *control_flags
= TFD_CTL_COUNT_SET(2) |
2845 TFD_CTL_PAD_SET(U32_PAD(len
));
2847 len
= (u16
)skb
->len
;
2848 out_cmd
->cmd
.tx
.len
= cpu_to_le16(len
);
2850 /* TODO need this for burst mode later on */
2851 iwl_build_tx_cmd_basic(priv
, out_cmd
, ctl
, hdr
, unicast
, sta_id
);
2853 /* set is_hcca to 0; it probably will never be implemented */
2854 iwl_hw_build_tx_cmd_rate(priv
, out_cmd
, ctl
, hdr
, sta_id
, 0);
2856 out_cmd
->cmd
.tx
.tx_flags
&= ~TX_CMD_FLG_ANT_A_MSK
;
2857 out_cmd
->cmd
.tx
.tx_flags
&= ~TX_CMD_FLG_ANT_B_MSK
;
2859 if (!ieee80211_get_morefrag(hdr
)) {
2860 txq
->need_update
= 1;
2862 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2863 priv
->stations
[sta_id
].tid
[tid
].seq_number
= seq_number
;
2867 txq
->need_update
= 0;
2870 iwl_print_hex_dump(IWL_DL_TX
, out_cmd
->cmd
.payload
,
2871 sizeof(out_cmd
->cmd
.tx
));
2873 iwl_print_hex_dump(IWL_DL_TX
, (u8
*)out_cmd
->cmd
.tx
.hdr
,
2874 ieee80211_get_hdrlen(fc
));
2876 q
->first_empty
= iwl_queue_inc_wrap(q
->first_empty
, q
->n_bd
);
2877 rc
= iwl_tx_queue_update_write_ptr(priv
, txq
);
2878 spin_unlock_irqrestore(&priv
->lock
, flags
);
2883 if ((iwl_queue_space(q
) < q
->high_mark
)
2884 && priv
->mac80211_registered
) {
2885 if (wait_write_ptr
) {
2886 spin_lock_irqsave(&priv
->lock
, flags
);
2887 txq
->need_update
= 1;
2888 iwl_tx_queue_update_write_ptr(priv
, txq
);
2889 spin_unlock_irqrestore(&priv
->lock
, flags
);
2892 ieee80211_stop_queue(priv
->hw
, ctl
->queue
);
2898 spin_unlock_irqrestore(&priv
->lock
, flags
);
2903 static void iwl_set_rate(struct iwl_priv
*priv
)
2905 const struct ieee80211_hw_mode
*hw
= NULL
;
2906 struct ieee80211_rate
*rate
;
2909 hw
= iwl_get_hw_mode(priv
, priv
->phymode
);
2911 priv
->active_rate
= 0;
2912 priv
->active_rate_basic
= 0;
2914 IWL_DEBUG_RATE("Setting rates for 802.11%c\n",
2915 hw
->mode
== MODE_IEEE80211A
?
2916 'a' : ((hw
->mode
== MODE_IEEE80211B
) ? 'b' : 'g'));
2918 for (i
= 0; i
< hw
->num_rates
; i
++) {
2919 rate
= &(hw
->rates
[i
]);
2920 if ((rate
->val
< IWL_RATE_COUNT
) &&
2921 (rate
->flags
& IEEE80211_RATE_SUPPORTED
)) {
2922 IWL_DEBUG_RATE("Adding rate index %d (plcp %d)%s\n",
2923 rate
->val
, iwl_rates
[rate
->val
].plcp
,
2924 (rate
->flags
& IEEE80211_RATE_BASIC
) ?
2926 priv
->active_rate
|= (1 << rate
->val
);
2927 if (rate
->flags
& IEEE80211_RATE_BASIC
)
2928 priv
->active_rate_basic
|= (1 << rate
->val
);
2930 IWL_DEBUG_RATE("Not adding rate %d (plcp %d)\n",
2931 rate
->val
, iwl_rates
[rate
->val
].plcp
);
2934 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2935 priv
->active_rate
, priv
->active_rate_basic
);
2938 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2939 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2942 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
2943 priv
->staging_rxon
.cck_basic_rates
=
2944 ((priv
->active_rate_basic
&
2945 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
2947 priv
->staging_rxon
.cck_basic_rates
=
2948 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2950 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
2951 priv
->staging_rxon
.ofdm_basic_rates
=
2952 ((priv
->active_rate_basic
&
2953 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
2954 IWL_FIRST_OFDM_RATE
) & 0xFF;
2956 priv
->staging_rxon
.ofdm_basic_rates
=
2957 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2960 static void iwl_radio_kill_sw(struct iwl_priv
*priv
, int disable_radio
)
2962 unsigned long flags
;
2964 if (!!disable_radio
== test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
2967 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2968 disable_radio
? "OFF" : "ON");
2970 if (disable_radio
) {
2971 iwl_scan_cancel(priv
);
2972 /* FIXME: This is a workaround for AP */
2973 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
2974 spin_lock_irqsave(&priv
->lock
, flags
);
2975 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
2976 CSR_UCODE_SW_BIT_RFKILL
);
2977 spin_unlock_irqrestore(&priv
->lock
, flags
);
2978 iwl_send_card_state(priv
, CARD_STATE_CMD_DISABLE
, 0);
2979 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2984 spin_lock_irqsave(&priv
->lock
, flags
);
2985 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2987 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2988 spin_unlock_irqrestore(&priv
->lock
, flags
);
2993 spin_lock_irqsave(&priv
->lock
, flags
);
2994 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
2995 if (!iwl_grab_restricted_access(priv
))
2996 iwl_release_restricted_access(priv
);
2997 spin_unlock_irqrestore(&priv
->lock
, flags
);
2999 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
3000 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
3001 "disabled by HW switch\n");
3005 queue_work(priv
->workqueue
, &priv
->restart
);
3009 void iwl_set_decrypted_flag(struct iwl_priv
*priv
, struct sk_buff
*skb
,
3010 u32 decrypt_res
, struct ieee80211_rx_status
*stats
)
3013 le16_to_cpu(((struct ieee80211_hdr
*)skb
->data
)->frame_control
);
3015 if (priv
->active_rxon
.filter_flags
& RXON_FILTER_DIS_DECRYPT_MSK
)
3018 if (!(fc
& IEEE80211_FCTL_PROTECTED
))
3021 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res
);
3022 switch (decrypt_res
& RX_RES_STATUS_SEC_TYPE_MSK
) {
3023 case RX_RES_STATUS_SEC_TYPE_TKIP
:
3024 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
3025 RX_RES_STATUS_BAD_ICV_MIC
)
3026 stats
->flag
|= RX_FLAG_MMIC_ERROR
;
3027 case RX_RES_STATUS_SEC_TYPE_WEP
:
3028 case RX_RES_STATUS_SEC_TYPE_CCMP
:
3029 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
3030 RX_RES_STATUS_DECRYPT_OK
) {
3031 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
3032 stats
->flag
|= RX_FLAG_DECRYPTED
;
3041 void iwl_handle_data_packet_monitor(struct iwl_priv
*priv
,
3042 struct iwl_rx_mem_buffer
*rxb
,
3043 void *data
, short len
,
3044 struct ieee80211_rx_status
*stats
,
3047 struct iwl_rt_rx_hdr
*iwl_rt
;
3049 /* First cache any information we need before we overwrite
3050 * the information provided in the skb from the hardware */
3051 s8 signal
= stats
->ssi
;
3053 int rate
= stats
->rate
;
3054 u64 tsf
= stats
->mactime
;
3055 __le16 phy_flags_hw
= cpu_to_le16(phy_flags
);
3057 /* We received data from the HW, so stop the watchdog */
3058 if (len
> IWL_RX_BUF_SIZE
- sizeof(*iwl_rt
)) {
3059 IWL_DEBUG_DROP("Dropping too large packet in monitor\n");
3063 /* copy the frame data to write after where the radiotap header goes */
3064 iwl_rt
= (void *)rxb
->skb
->data
;
3065 memmove(iwl_rt
->payload
, data
, len
);
3067 iwl_rt
->rt_hdr
.it_version
= PKTHDR_RADIOTAP_VERSION
;
3068 iwl_rt
->rt_hdr
.it_pad
= 0; /* always good to zero */
3070 /* total header + data */
3071 iwl_rt
->rt_hdr
.it_len
= cpu_to_le16(sizeof(*iwl_rt
));
3073 /* Set the size of the skb to the size of the frame */
3074 skb_put(rxb
->skb
, sizeof(*iwl_rt
) + len
);
3076 /* Big bitfield of all the fields we provide in radiotap */
3077 iwl_rt
->rt_hdr
.it_present
=
3078 cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT
) |
3079 (1 << IEEE80211_RADIOTAP_FLAGS
) |
3080 (1 << IEEE80211_RADIOTAP_RATE
) |
3081 (1 << IEEE80211_RADIOTAP_CHANNEL
) |
3082 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL
) |
3083 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE
) |
3084 (1 << IEEE80211_RADIOTAP_ANTENNA
));
3086 /* Zero the flags, we'll add to them as we go */
3087 iwl_rt
->rt_flags
= 0;
3089 iwl_rt
->rt_tsf
= cpu_to_le64(tsf
);
3091 /* Convert to dBm */
3092 iwl_rt
->rt_dbmsignal
= signal
;
3093 iwl_rt
->rt_dbmnoise
= noise
;
3095 /* Convert the channel frequency and set the flags */
3096 iwl_rt
->rt_channelMHz
= cpu_to_le16(stats
->freq
);
3097 if (!(phy_flags_hw
& RX_RES_PHY_FLAGS_BAND_24_MSK
))
3098 iwl_rt
->rt_chbitmask
=
3099 cpu_to_le16((IEEE80211_CHAN_OFDM
| IEEE80211_CHAN_5GHZ
));
3100 else if (phy_flags_hw
& RX_RES_PHY_FLAGS_MOD_CCK_MSK
)
3101 iwl_rt
->rt_chbitmask
=
3102 cpu_to_le16((IEEE80211_CHAN_CCK
| IEEE80211_CHAN_2GHZ
));
3104 iwl_rt
->rt_chbitmask
=
3105 cpu_to_le16((IEEE80211_CHAN_OFDM
| IEEE80211_CHAN_2GHZ
));
3107 rate
= iwl_rate_index_from_plcp(rate
);
3109 iwl_rt
->rt_rate
= 0;
3111 iwl_rt
->rt_rate
= iwl_rates
[rate
].ieee
;
3113 /* antenna number */
3114 iwl_rt
->rt_antenna
=
3115 le16_to_cpu(phy_flags_hw
& RX_RES_PHY_FLAGS_ANTENNA_MSK
) >> 4;
3117 /* set the preamble flag if we have it */
3118 if (phy_flags_hw
& RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK
)
3119 iwl_rt
->rt_flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
3121 IWL_DEBUG_RX("Rx packet of %d bytes.\n", rxb
->skb
->len
);
3123 stats
->flag
|= RX_FLAG_RADIOTAP
;
3124 ieee80211_rx_irqsafe(priv
->hw
, rxb
->skb
, stats
);
3129 #define IWL_PACKET_RETRY_TIME HZ
3131 int is_duplicate_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
3133 u16 sc
= le16_to_cpu(header
->seq_ctrl
);
3134 u16 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
3135 u16 frag
= sc
& IEEE80211_SCTL_FRAG
;
3136 u16
*last_seq
, *last_frag
;
3137 unsigned long *last_time
;
3139 switch (priv
->iw_mode
) {
3140 case IEEE80211_IF_TYPE_IBSS
:{
3141 struct list_head
*p
;
3142 struct iwl_ibss_seq
*entry
= NULL
;
3143 u8
*mac
= header
->addr2
;
3144 int index
= mac
[5] & (IWL_IBSS_MAC_HASH_SIZE
- 1);
3146 __list_for_each(p
, &priv
->ibss_mac_hash
[index
]) {
3148 list_entry(p
, struct iwl_ibss_seq
, list
);
3149 if (!compare_ether_addr(entry
->mac
, mac
))
3152 if (p
== &priv
->ibss_mac_hash
[index
]) {
3153 entry
= kzalloc(sizeof(*entry
), GFP_ATOMIC
);
3156 ("Cannot malloc new mac entry\n");
3159 memcpy(entry
->mac
, mac
, ETH_ALEN
);
3160 entry
->seq_num
= seq
;
3161 entry
->frag_num
= frag
;
3162 entry
->packet_time
= jiffies
;
3163 list_add(&entry
->list
,
3164 &priv
->ibss_mac_hash
[index
]);
3167 last_seq
= &entry
->seq_num
;
3168 last_frag
= &entry
->frag_num
;
3169 last_time
= &entry
->packet_time
;
3172 case IEEE80211_IF_TYPE_STA
:
3173 last_seq
= &priv
->last_seq_num
;
3174 last_frag
= &priv
->last_frag_num
;
3175 last_time
= &priv
->last_packet_time
;
3180 if ((*last_seq
== seq
) &&
3181 time_after(*last_time
+ IWL_PACKET_RETRY_TIME
, jiffies
)) {
3182 if (*last_frag
== frag
)
3184 if (*last_frag
+ 1 != frag
)
3185 /* out-of-order fragment */
3191 *last_time
= jiffies
;
3198 #ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT
3200 #include "iwl-spectrum.h"
3202 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
3203 #define BEACON_TIME_MASK_HIGH 0xFF000000
3204 #define TIME_UNIT 1024
3207 * extended beacon time format
3208 * time in usec will be changed into a 32-bit value in 8:24 format
3209 * the high 1 byte is the beacon counts
3210 * the lower 3 bytes is the time in usec within one beacon interval
3213 static u32
iwl_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
3217 u32 interval
= beacon_interval
* 1024;
3219 if (!interval
|| !usec
)
3222 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
3223 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
3225 return (quot
<< 24) + rem
;
3228 /* base is usually what we get from ucode with each received frame,
3229 * the same as HW timer counter counting down
3232 static __le32
iwl_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
3234 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
3235 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
3236 u32 interval
= beacon_interval
* TIME_UNIT
;
3237 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
3238 (addon
& BEACON_TIME_MASK_HIGH
);
3240 if (base_low
> addon_low
)
3241 res
+= base_low
- addon_low
;
3242 else if (base_low
< addon_low
) {
3243 res
+= interval
+ base_low
- addon_low
;
3248 return cpu_to_le32(res
);
3251 static int iwl_get_measurement(struct iwl_priv
*priv
,
3252 struct ieee80211_measurement_params
*params
,
3255 struct iwl_spectrum_cmd spectrum
;
3256 struct iwl_rx_packet
*res
;
3257 struct iwl_host_cmd cmd
= {
3258 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
3259 .data
= (void *)&spectrum
,
3260 .meta
.flags
= CMD_WANT_SKB
,
3262 u32 add_time
= le64_to_cpu(params
->start_time
);
3264 int spectrum_resp_status
;
3265 int duration
= le16_to_cpu(params
->duration
);
3267 if (iwl_is_associated(priv
))
3269 iwl_usecs_to_beacons(
3270 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
3271 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
3273 memset(&spectrum
, 0, sizeof(spectrum
));
3275 spectrum
.channel_count
= cpu_to_le16(1);
3277 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
3278 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
3279 cmd
.len
= sizeof(spectrum
);
3280 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
3282 if (iwl_is_associated(priv
))
3283 spectrum
.start_time
=
3284 iwl_add_beacon_time(priv
->last_beacon_time
,
3286 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
3288 spectrum
.start_time
= 0;
3290 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
3291 spectrum
.channels
[0].channel
= params
->channel
;
3292 spectrum
.channels
[0].type
= type
;
3293 if (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
3294 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
3295 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
3297 rc
= iwl_send_cmd_sync(priv
, &cmd
);
3301 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
3302 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
3303 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
3307 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
3308 switch (spectrum_resp_status
) {
3309 case 0: /* Command will be handled */
3310 if (res
->u
.spectrum
.id
!= 0xff) {
3312 ("Replaced existing measurement: %d\n",
3313 res
->u
.spectrum
.id
);
3314 priv
->measurement_status
&= ~MEASUREMENT_READY
;
3316 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
3320 case 1: /* Command will not be handled */
3325 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
3331 static void iwl_txstatus_to_ieee(struct iwl_priv
*priv
,
3332 struct iwl_tx_info
*tx_sta
)
3335 tx_sta
->status
.ack_signal
= 0;
3336 tx_sta
->status
.excessive_retries
= 0;
3337 tx_sta
->status
.queue_length
= 0;
3338 tx_sta
->status
.queue_number
= 0;
3341 ieee80211_tx_status_irqsafe(priv
->hw
,
3342 tx_sta
->skb
[0], &(tx_sta
->status
));
3344 ieee80211_tx_status(priv
->hw
,
3345 tx_sta
->skb
[0], &(tx_sta
->status
));
3347 tx_sta
->skb
[0] = NULL
;
3351 * iwl_tx_queue_reclaim - Reclaim Tx queue entries no more used by NIC.
3353 * When FW advances 'R' index, all entries between old and
3354 * new 'R' index need to be reclaimed. As result, some free space
3355 * forms. If there is enough free space (> low mark), wake Tx queue.
3357 int iwl_tx_queue_reclaim(struct iwl_priv
*priv
, int txq_id
, int index
)
3359 struct iwl_tx_queue
*txq
= &priv
->txq
[txq_id
];
3360 struct iwl_queue
*q
= &txq
->q
;
3363 if ((index
>= q
->n_bd
) || (x2_queue_used(q
, index
) == 0)) {
3364 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
3365 "is out of range [0-%d] %d %d.\n", txq_id
,
3366 index
, q
->n_bd
, q
->first_empty
, q
->last_used
);
3370 for (index
= iwl_queue_inc_wrap(index
, q
->n_bd
);
3371 q
->last_used
!= index
;
3372 q
->last_used
= iwl_queue_inc_wrap(q
->last_used
, q
->n_bd
)) {
3373 if (txq_id
!= IWL_CMD_QUEUE_NUM
) {
3374 iwl_txstatus_to_ieee(priv
,
3375 &(txq
->txb
[txq
->q
.last_used
]));
3376 iwl_hw_txq_free_tfd(priv
, txq
);
3377 } else if (nfreed
> 1) {
3378 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index
,
3379 q
->first_empty
, q
->last_used
);
3380 queue_work(priv
->workqueue
, &priv
->restart
);
3385 if (iwl_queue_space(q
) > q
->low_mark
&& (txq_id
>= 0) &&
3386 (txq_id
!= IWL_CMD_QUEUE_NUM
) &&
3387 priv
->mac80211_registered
)
3388 ieee80211_wake_queue(priv
->hw
, txq_id
);
3394 static int iwl_is_tx_success(u32 status
)
3396 return (status
& 0xFF) == 0x1;
3399 /******************************************************************************
3401 * Generic RX handler implementations
3403 ******************************************************************************/
3404 static void iwl_rx_reply_tx(struct iwl_priv
*priv
,
3405 struct iwl_rx_mem_buffer
*rxb
)
3407 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3408 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3409 int txq_id
= SEQ_TO_QUEUE(sequence
);
3410 int index
= SEQ_TO_INDEX(sequence
);
3411 struct iwl_tx_queue
*txq
= &priv
->txq
[txq_id
];
3412 struct ieee80211_tx_status
*tx_status
;
3413 struct iwl_tx_resp
*tx_resp
= (void *)&pkt
->u
.raw
[0];
3414 u32 status
= le32_to_cpu(tx_resp
->status
);
3416 if ((index
>= txq
->q
.n_bd
) || (x2_queue_used(&txq
->q
, index
) == 0)) {
3417 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3418 "is out of range [0-%d] %d %d\n", txq_id
,
3419 index
, txq
->q
.n_bd
, txq
->q
.first_empty
,
3424 tx_status
= &(txq
->txb
[txq
->q
.last_used
].status
);
3426 tx_status
->retry_count
= tx_resp
->failure_frame
;
3427 tx_status
->queue_number
= status
;
3428 tx_status
->queue_length
= tx_resp
->bt_kill_count
;
3429 tx_status
->queue_length
|= tx_resp
->failure_rts
;
3432 iwl_is_tx_success(status
) ? IEEE80211_TX_STATUS_ACK
: 0;
3434 tx_status
->control
.tx_rate
= iwl_rate_index_from_plcp(tx_resp
->rate
);
3436 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n",
3437 txq_id
, iwl_get_tx_fail_reason(status
), status
,
3438 tx_resp
->rate
, tx_resp
->failure_frame
);
3440 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index
);
3442 iwl_tx_queue_reclaim(priv
, txq_id
, index
);
3444 if (iwl_check_bits(status
, TX_ABORT_REQUIRED_MSK
))
3445 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3449 static void iwl_rx_reply_alive(struct iwl_priv
*priv
,
3450 struct iwl_rx_mem_buffer
*rxb
)
3452 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3453 struct iwl_alive_resp
*palive
;
3454 struct delayed_work
*pwork
;
3456 palive
= &pkt
->u
.alive_frame
;
3458 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3460 palive
->is_valid
, palive
->ver_type
,
3461 palive
->ver_subtype
);
3463 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
3464 IWL_DEBUG_INFO("Initialization Alive received.\n");
3465 memcpy(&priv
->card_alive_init
,
3466 &pkt
->u
.alive_frame
,
3467 sizeof(struct iwl_init_alive_resp
));
3468 pwork
= &priv
->init_alive_start
;
3470 IWL_DEBUG_INFO("Runtime Alive received.\n");
3471 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
3472 sizeof(struct iwl_alive_resp
));
3473 pwork
= &priv
->alive_start
;
3474 iwl_disable_events(priv
);
3477 /* We delay the ALIVE response by 5ms to
3478 * give the HW RF Kill time to activate... */
3479 if (palive
->is_valid
== UCODE_VALID_OK
)
3480 queue_delayed_work(priv
->workqueue
, pwork
,
3481 msecs_to_jiffies(5));
3483 IWL_WARNING("uCode did not respond OK.\n");
3486 static void iwl_rx_reply_add_sta(struct iwl_priv
*priv
,
3487 struct iwl_rx_mem_buffer
*rxb
)
3489 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3491 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt
->u
.status
);
3495 static void iwl_rx_reply_error(struct iwl_priv
*priv
,
3496 struct iwl_rx_mem_buffer
*rxb
)
3498 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3500 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3501 "seq 0x%04X ser 0x%08X\n",
3502 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
3503 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
3504 pkt
->u
.err_resp
.cmd_id
,
3505 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
3506 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
3509 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3511 static void iwl_rx_csa(struct iwl_priv
*priv
, struct iwl_rx_mem_buffer
*rxb
)
3513 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3514 struct iwl_rxon_cmd
*rxon
= (void *)&priv
->active_rxon
;
3515 struct iwl_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
3516 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3517 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
3518 rxon
->channel
= csa
->channel
;
3519 priv
->staging_rxon
.channel
= csa
->channel
;
3522 static void iwl_rx_spectrum_measure_notif(struct iwl_priv
*priv
,
3523 struct iwl_rx_mem_buffer
*rxb
)
3525 #ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT
3526 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3527 struct iwl_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
3529 if (!report
->state
) {
3530 IWL_DEBUG(IWL_DL_11H
| IWL_DL_INFO
,
3531 "Spectrum Measure Notification: Start\n");
3535 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
3536 priv
->measurement_status
|= MEASUREMENT_READY
;
3540 static void iwl_rx_pm_sleep_notif(struct iwl_priv
*priv
,
3541 struct iwl_rx_mem_buffer
*rxb
)
3543 #ifdef CONFIG_IWLWIFI_DEBUG
3544 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3545 struct iwl_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
3546 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3547 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
3551 static void iwl_rx_pm_debug_statistics_notif(struct iwl_priv
*priv
,
3552 struct iwl_rx_mem_buffer
*rxb
)
3554 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3555 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3556 "notification for %s:\n",
3557 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
3558 iwl_print_hex_dump(IWL_DL_RADIO
, pkt
->u
.raw
, le32_to_cpu(pkt
->len
));
3561 static void iwl_bg_beacon_update(struct work_struct
*work
)
3563 struct iwl_priv
*priv
=
3564 container_of(work
, struct iwl_priv
, beacon_update
);
3565 struct sk_buff
*beacon
;
3567 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3568 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->interface_id
, NULL
);
3571 IWL_ERROR("update beacon failed\n");
3575 mutex_lock(&priv
->mutex
);
3576 /* new beacon skb is allocated every time; dispose previous.*/
3577 if (priv
->ibss_beacon
)
3578 dev_kfree_skb(priv
->ibss_beacon
);
3580 priv
->ibss_beacon
= beacon
;
3581 mutex_unlock(&priv
->mutex
);
3583 iwl_send_beacon_cmd(priv
);
3586 static void iwl_rx_beacon_notif(struct iwl_priv
*priv
,
3587 struct iwl_rx_mem_buffer
*rxb
)
3589 #ifdef CONFIG_IWLWIFI_DEBUG
3590 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3591 struct iwl_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
3592 u8 rate
= beacon
->beacon_notify_hdr
.rate
;
3594 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3595 "tsf %d %d rate %d\n",
3596 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
3597 beacon
->beacon_notify_hdr
.failure_frame
,
3598 le32_to_cpu(beacon
->ibss_mgr_status
),
3599 le32_to_cpu(beacon
->high_tsf
),
3600 le32_to_cpu(beacon
->low_tsf
), rate
);
3603 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
3604 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
3605 queue_work(priv
->workqueue
, &priv
->beacon_update
);
3608 /* Service response to REPLY_SCAN_CMD (0x80) */
3609 static void iwl_rx_reply_scan(struct iwl_priv
*priv
,
3610 struct iwl_rx_mem_buffer
*rxb
)
3612 #ifdef CONFIG_IWLWIFI_DEBUG
3613 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3614 struct iwl_scanreq_notification
*notif
=
3615 (struct iwl_scanreq_notification
*)pkt
->u
.raw
;
3617 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
3621 /* Service SCAN_START_NOTIFICATION (0x82) */
3622 static void iwl_rx_scan_start_notif(struct iwl_priv
*priv
,
3623 struct iwl_rx_mem_buffer
*rxb
)
3625 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3626 struct iwl_scanstart_notification
*notif
=
3627 (struct iwl_scanstart_notification
*)pkt
->u
.raw
;
3628 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
3629 IWL_DEBUG_SCAN("Scan start: "
3631 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3633 notif
->band
? "bg" : "a",
3635 notif
->tsf_low
, notif
->status
, notif
->beacon_timer
);
3638 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3639 static void iwl_rx_scan_results_notif(struct iwl_priv
*priv
,
3640 struct iwl_rx_mem_buffer
*rxb
)
3642 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3643 struct iwl_scanresults_notification
*notif
=
3644 (struct iwl_scanresults_notification
*)pkt
->u
.raw
;
3646 IWL_DEBUG_SCAN("Scan ch.res: "
3648 "(TSF: 0x%08X:%08X) - %d "
3649 "elapsed=%lu usec (%dms since last)\n",
3651 notif
->band
? "bg" : "a",
3652 le32_to_cpu(notif
->tsf_high
),
3653 le32_to_cpu(notif
->tsf_low
),
3654 le32_to_cpu(notif
->statistics
[0]),
3655 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
3656 jiffies_to_msecs(elapsed_jiffies
3657 (priv
->last_scan_jiffies
, jiffies
)));
3659 priv
->last_scan_jiffies
= jiffies
;
3662 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
3663 static void iwl_rx_scan_complete_notif(struct iwl_priv
*priv
,
3664 struct iwl_rx_mem_buffer
*rxb
)
3666 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3667 struct iwl_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
3669 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3670 scan_notif
->scanned_channels
,
3671 scan_notif
->tsf_low
,
3672 scan_notif
->tsf_high
, scan_notif
->status
);
3674 /* The HW is no longer scanning */
3675 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
3677 /* The scan completion notification came in, so kill that timer... */
3678 cancel_delayed_work(&priv
->scan_check
);
3680 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3681 (priv
->scan_bands
== 2) ? "2.4" : "5.2",
3682 jiffies_to_msecs(elapsed_jiffies
3683 (priv
->scan_pass_start
, jiffies
)));
3685 /* Remove this scanned band from the list
3686 * of pending bands to scan */
3689 /* If a request to abort was given, or the scan did not succeed
3690 * then we reset the scan state machine and terminate,
3691 * re-queuing another scan if one has been requested */
3692 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
3693 IWL_DEBUG_INFO("Aborted scan completed.\n");
3694 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
3696 /* If there are more bands on this scan pass reschedule */
3697 if (priv
->scan_bands
> 0)
3701 priv
->last_scan_jiffies
= jiffies
;
3702 IWL_DEBUG_INFO("Setting scan to off\n");
3704 clear_bit(STATUS_SCANNING
, &priv
->status
);
3706 IWL_DEBUG_INFO("Scan took %dms\n",
3707 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
3709 queue_work(priv
->workqueue
, &priv
->scan_completed
);
3714 priv
->scan_pass_start
= jiffies
;
3715 queue_work(priv
->workqueue
, &priv
->request_scan
);
3718 /* Handle notification from uCode that card's power state is changing
3719 * due to software, hardware, or critical temperature RFKILL */
3720 static void iwl_rx_card_state_notif(struct iwl_priv
*priv
,
3721 struct iwl_rx_mem_buffer
*rxb
)
3723 struct iwl_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3724 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
3725 unsigned long status
= priv
->status
;
3727 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3728 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
3729 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
3731 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3732 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3734 if (flags
& HW_CARD_DISABLED
)
3735 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3737 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3740 if (flags
& SW_CARD_DISABLED
)
3741 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3743 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3745 iwl_scan_cancel(priv
);
3747 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
3748 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
3749 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
3750 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
3751 queue_work(priv
->workqueue
, &priv
->rf_kill
);
3753 wake_up_interruptible(&priv
->wait_command_queue
);
3757 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
3759 * Setup the RX handlers for each of the reply types sent from the uCode
3762 * This function chains into the hardware specific files for them to setup
3763 * any hardware specific handlers as well.
3765 static void iwl_setup_rx_handlers(struct iwl_priv
*priv
)
3767 priv
->rx_handlers
[REPLY_ALIVE
] = iwl_rx_reply_alive
;
3768 priv
->rx_handlers
[REPLY_ADD_STA
] = iwl_rx_reply_add_sta
;
3769 priv
->rx_handlers
[REPLY_ERROR
] = iwl_rx_reply_error
;
3770 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl_rx_csa
;
3771 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
3772 iwl_rx_spectrum_measure_notif
;
3773 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl_rx_pm_sleep_notif
;
3774 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
3775 iwl_rx_pm_debug_statistics_notif
;
3776 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl_rx_beacon_notif
;
3778 /* NOTE: iwl_rx_statistics is different based on whether
3779 * the build is for the 3945 or the 4965. See the
3780 * corresponding implementation in iwl-XXXX.c
3782 * The same handler is used for both the REPLY to a
3783 * discrete statistics request from the host as well as
3784 * for the periodic statistics notification from the uCode
3786 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl_hw_rx_statistics
;
3787 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl_hw_rx_statistics
;
3789 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl_rx_reply_scan
;
3790 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl_rx_scan_start_notif
;
3791 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
3792 iwl_rx_scan_results_notif
;
3793 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
3794 iwl_rx_scan_complete_notif
;
3795 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl_rx_card_state_notif
;
3796 priv
->rx_handlers
[REPLY_TX
] = iwl_rx_reply_tx
;
3798 /* Setup hardware specific Rx handlers */
3799 iwl_hw_rx_handler_setup(priv
);
3803 * iwl_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3804 * @rxb: Rx buffer to reclaim
3806 * If an Rx buffer has an async callback associated with it the callback
3807 * will be executed. The attached skb (if present) will only be freed
3808 * if the callback returns 1
3810 static void iwl_tx_cmd_complete(struct iwl_priv
*priv
,
3811 struct iwl_rx_mem_buffer
*rxb
)
3813 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
3814 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3815 int txq_id
= SEQ_TO_QUEUE(sequence
);
3816 int index
= SEQ_TO_INDEX(sequence
);
3817 int huge
= sequence
& SEQ_HUGE_FRAME
;
3819 struct iwl_cmd
*cmd
;
3821 /* If a Tx command is being handled and it isn't in the actual
3822 * command queue then there a command routing bug has been introduced
3823 * in the queue management code. */
3824 if (txq_id
!= IWL_CMD_QUEUE_NUM
)
3825 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
3826 txq_id
, pkt
->hdr
.cmd
);
3827 BUG_ON(txq_id
!= IWL_CMD_QUEUE_NUM
);
3829 cmd_index
= get_cmd_index(&priv
->txq
[IWL_CMD_QUEUE_NUM
].q
, index
, huge
);
3830 cmd
= &priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_index
];
3832 /* Input error checking is done when commands are added to queue. */
3833 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
3834 cmd
->meta
.source
->u
.skb
= rxb
->skb
;
3836 } else if (cmd
->meta
.u
.callback
&&
3837 !cmd
->meta
.u
.callback(priv
, cmd
, rxb
->skb
))
3840 iwl_tx_queue_reclaim(priv
, txq_id
, index
);
3842 if (!(cmd
->meta
.flags
& CMD_ASYNC
)) {
3843 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
3844 wake_up_interruptible(&priv
->wait_command_queue
);
3848 /************************** RX-FUNCTIONS ****************************/
3850 * Rx theory of operation
3852 * The host allocates 32 DMA target addresses and passes the host address
3853 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
3857 * The host/firmware share two index registers for managing the Rx buffers.
3859 * The READ index maps to the first position that the firmware may be writing
3860 * to -- the driver can read up to (but not including) this position and get
3862 * The READ index is managed by the firmware once the card is enabled.
3864 * The WRITE index maps to the last position the driver has read from -- the
3865 * position preceding WRITE is the last slot the firmware can place a packet.
3867 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
3870 * During initialization the host sets up the READ queue position to the first
3871 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3873 * When the firmware places a packet in a buffer it will advance the READ index
3874 * and fire the RX interrupt. The driver can then query the READ index and
3875 * process as many packets as possible, moving the WRITE index forward as it
3876 * resets the Rx queue buffers with new memory.
3878 * The management in the driver is as follows:
3879 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
3880 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
3881 * to replensish the iwl->rxq->rx_free.
3882 * + In iwl_rx_replenish (scheduled) if 'processed' != 'read' then the
3883 * iwl->rxq is replenished and the READ INDEX is updated (updating the
3884 * 'processed' and 'read' driver indexes as well)
3885 * + A received packet is processed and handed to the kernel network stack,
3886 * detached from the iwl->rxq. The driver 'processed' index is updated.
3887 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
3888 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
3889 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
3890 * were enough free buffers and RX_STALLED is set it is cleared.
3895 * iwl_rx_queue_alloc() Allocates rx_free
3896 * iwl_rx_replenish() Replenishes rx_free list from rx_used, and calls
3897 * iwl_rx_queue_restock
3898 * iwl_rx_queue_restock() Moves available buffers from rx_free into Rx
3899 * queue, updates firmware pointers, and updates
3900 * the WRITE index. If insufficient rx_free buffers
3901 * are available, schedules iwl_rx_replenish
3903 * -- enable interrupts --
3904 * ISR - iwl_rx() Detach iwl_rx_mem_buffers from pool up to the
3905 * READ INDEX, detaching the SKB from the pool.
3906 * Moves the packet buffer from queue to rx_used.
3907 * Calls iwl_rx_queue_restock to refill any empty
3914 * iwl_rx_queue_space - Return number of free slots available in queue.
3916 static int iwl_rx_queue_space(const struct iwl_rx_queue
*q
)
3918 int s
= q
->read
- q
->write
;
3921 /* keep some buffer to not confuse full and empty queue */
3929 * iwl_rx_queue_update_write_ptr - Update the write pointer for the RX queue
3931 * NOTE: This function has 3945 and 4965 specific code sections
3932 * but is declared in base due to the majority of the
3933 * implementation being the same (only a numeric constant is
3937 int iwl_rx_queue_update_write_ptr(struct iwl_priv
*priv
, struct iwl_rx_queue
*q
)
3941 unsigned long flags
;
3943 spin_lock_irqsave(&q
->lock
, flags
);
3945 if (q
->need_update
== 0)
3948 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
3949 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3951 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
3952 iwl_set_bit(priv
, CSR_GP_CNTRL
,
3953 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
3957 rc
= iwl_grab_restricted_access(priv
);
3961 iwl_write_restricted(priv
, FH_RSCSR_CHNL0_WPTR
,
3963 iwl_release_restricted_access(priv
);
3965 iwl_write32(priv
, FH_RSCSR_CHNL0_WPTR
, q
->write
& ~0x7);
3971 spin_unlock_irqrestore(&q
->lock
, flags
);
3976 * iwl_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer pointer.
3978 * NOTE: This function has 3945 and 4965 specific code paths in it.
3980 static inline __le32
iwl_dma_addr2rbd_ptr(struct iwl_priv
*priv
,
3981 dma_addr_t dma_addr
)
3983 return cpu_to_le32((u32
)dma_addr
);
3987 * iwl_rx_queue_restock - refill RX queue from pre-allocated pool
3989 * If there are slots in the RX queue that need to be restocked,
3990 * and we have free pre-allocated buffers, fill the ranks as much
3991 * as we can pulling from rx_free.
3993 * This moves the 'write' index forward to catch up with 'processed', and
3994 * also updates the memory address in the firmware to reference the new
3997 int iwl_rx_queue_restock(struct iwl_priv
*priv
)
3999 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
4000 struct list_head
*element
;
4001 struct iwl_rx_mem_buffer
*rxb
;
4002 unsigned long flags
;
4005 spin_lock_irqsave(&rxq
->lock
, flags
);
4006 write
= rxq
->write
& ~0x7;
4007 while ((iwl_rx_queue_space(rxq
) > 0) && (rxq
->free_count
)) {
4008 element
= rxq
->rx_free
.next
;
4009 rxb
= list_entry(element
, struct iwl_rx_mem_buffer
, list
);
4011 rxq
->bd
[rxq
->write
] = iwl_dma_addr2rbd_ptr(priv
, rxb
->dma_addr
);
4012 rxq
->queue
[rxq
->write
] = rxb
;
4013 rxq
->write
= (rxq
->write
+ 1) & RX_QUEUE_MASK
;
4016 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4017 /* If the pre-allocated buffer pool is dropping low, schedule to
4019 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
4020 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
4023 /* If we've added more space for the firmware to place data, tell it */
4024 if ((write
!= (rxq
->write
& ~0x7))
4025 || (abs(rxq
->write
- rxq
->read
) > 7)) {
4026 spin_lock_irqsave(&rxq
->lock
, flags
);
4027 rxq
->need_update
= 1;
4028 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4029 rc
= iwl_rx_queue_update_write_ptr(priv
, rxq
);
4038 * iwl_rx_replensih - Move all used packet from rx_used to rx_free
4040 * When moving to rx_free an SKB is allocated for the slot.
4042 * Also restock the Rx queue via iwl_rx_queue_restock.
4043 * This is called as a scheduled work item (except for during intialization)
4045 void iwl_rx_replenish(void *data
)
4047 struct iwl_priv
*priv
= data
;
4048 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
4049 struct list_head
*element
;
4050 struct iwl_rx_mem_buffer
*rxb
;
4051 unsigned long flags
;
4052 spin_lock_irqsave(&rxq
->lock
, flags
);
4053 while (!list_empty(&rxq
->rx_used
)) {
4054 element
= rxq
->rx_used
.next
;
4055 rxb
= list_entry(element
, struct iwl_rx_mem_buffer
, list
);
4057 alloc_skb(IWL_RX_BUF_SIZE
, __GFP_NOWARN
| GFP_ATOMIC
);
4059 if (net_ratelimit())
4060 printk(KERN_CRIT DRV_NAME
4061 ": Can not allocate SKB buffers\n");
4062 /* We don't reschedule replenish work here -- we will
4063 * call the restock method and if it still needs
4064 * more buffers it will schedule replenish */
4067 priv
->alloc_rxb_skb
++;
4070 pci_map_single(priv
->pci_dev
, rxb
->skb
->data
,
4071 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
4072 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
4075 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4077 spin_lock_irqsave(&priv
->lock
, flags
);
4078 iwl_rx_queue_restock(priv
);
4079 spin_unlock_irqrestore(&priv
->lock
, flags
);
4082 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
4083 * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
4084 * This free routine walks the list of POOL entries and if SKB is set to
4085 * non NULL it is unmapped and freed
4087 void iwl_rx_queue_free(struct iwl_priv
*priv
, struct iwl_rx_queue
*rxq
)
4090 for (i
= 0; i
< RX_QUEUE_SIZE
+ RX_FREE_BUFFERS
; i
++) {
4091 if (rxq
->pool
[i
].skb
!= NULL
) {
4092 pci_unmap_single(priv
->pci_dev
,
4093 rxq
->pool
[i
].dma_addr
,
4094 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
4095 dev_kfree_skb(rxq
->pool
[i
].skb
);
4099 pci_free_consistent(priv
->pci_dev
, 4 * RX_QUEUE_SIZE
, rxq
->bd
,
4104 int iwl_rx_queue_alloc(struct iwl_priv
*priv
)
4106 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
4107 struct pci_dev
*dev
= priv
->pci_dev
;
4110 spin_lock_init(&rxq
->lock
);
4111 INIT_LIST_HEAD(&rxq
->rx_free
);
4112 INIT_LIST_HEAD(&rxq
->rx_used
);
4113 rxq
->bd
= pci_alloc_consistent(dev
, 4 * RX_QUEUE_SIZE
, &rxq
->dma_addr
);
4116 /* Fill the rx_used queue with _all_ of the Rx buffers */
4117 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++)
4118 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
4119 /* Set us so that we have processed and used all buffers, but have
4120 * not restocked the Rx queue with fresh buffers */
4121 rxq
->read
= rxq
->write
= 0;
4122 rxq
->free_count
= 0;
4123 rxq
->need_update
= 0;
4127 void iwl_rx_queue_reset(struct iwl_priv
*priv
, struct iwl_rx_queue
*rxq
)
4129 unsigned long flags
;
4131 spin_lock_irqsave(&rxq
->lock
, flags
);
4132 INIT_LIST_HEAD(&rxq
->rx_free
);
4133 INIT_LIST_HEAD(&rxq
->rx_used
);
4134 /* Fill the rx_used queue with _all_ of the Rx buffers */
4135 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++) {
4136 /* In the reset function, these buffers may have been allocated
4137 * to an SKB, so we need to unmap and free potential storage */
4138 if (rxq
->pool
[i
].skb
!= NULL
) {
4139 pci_unmap_single(priv
->pci_dev
,
4140 rxq
->pool
[i
].dma_addr
,
4141 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
4142 priv
->alloc_rxb_skb
--;
4143 dev_kfree_skb(rxq
->pool
[i
].skb
);
4144 rxq
->pool
[i
].skb
= NULL
;
4146 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
4149 /* Set us so that we have processed and used all buffers, but have
4150 * not restocked the Rx queue with fresh buffers */
4151 rxq
->read
= rxq
->write
= 0;
4152 rxq
->free_count
= 0;
4153 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4156 /* Convert linear signal-to-noise ratio into dB */
4157 static u8 ratio2dB
[100] = {
4158 /* 0 1 2 3 4 5 6 7 8 9 */
4159 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
4160 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
4161 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
4162 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
4163 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
4164 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
4165 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
4166 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
4167 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
4168 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
4171 /* Calculates a relative dB value from a ratio of linear
4172 * (i.e. not dB) signal levels.
4173 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
4174 int iwl_calc_db_from_ratio(int sig_ratio
)
4176 /* Anything above 1000:1 just report as 60 dB */
4177 if (sig_ratio
> 1000)
4180 /* Above 100:1, divide by 10 and use table,
4181 * add 20 dB to make up for divide by 10 */
4182 if (sig_ratio
> 100)
4183 return (20 + (int)ratio2dB
[sig_ratio
/10]);
4185 /* We shouldn't see this */
4189 /* Use table for ratios 1:1 - 99:1 */
4190 return (int)ratio2dB
[sig_ratio
];
4193 #define PERFECT_RSSI (-20) /* dBm */
4194 #define WORST_RSSI (-95) /* dBm */
4195 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
4197 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
4198 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
4199 * about formulas used below. */
4200 int iwl_calc_sig_qual(int rssi_dbm
, int noise_dbm
)
4203 int degradation
= PERFECT_RSSI
- rssi_dbm
;
4205 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
4206 * as indicator; formula is (signal dbm - noise dbm).
4207 * SNR at or above 40 is a great signal (100%).
4208 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
4209 * Weakest usable signal is usually 10 - 15 dB SNR. */
4211 if (rssi_dbm
- noise_dbm
>= 40)
4213 else if (rssi_dbm
< noise_dbm
)
4215 sig_qual
= ((rssi_dbm
- noise_dbm
) * 5) / 2;
4217 /* Else use just the signal level.
4218 * This formula is a least squares fit of data points collected and
4219 * compared with a reference system that had a percentage (%) display
4220 * for signal quality. */
4222 sig_qual
= (100 * (RSSI_RANGE
* RSSI_RANGE
) - degradation
*
4223 (15 * RSSI_RANGE
+ 62 * degradation
)) /
4224 (RSSI_RANGE
* RSSI_RANGE
);
4228 else if (sig_qual
< 1)
4235 * iwl_rx_handle - Main entry function for receiving responses from the uCode
4237 * Uses the priv->rx_handlers callback function array to invoke
4238 * the appropriate handlers, including command responses,
4239 * frame-received notifications, and other notifications.
4241 static void iwl_rx_handle(struct iwl_priv
*priv
)
4243 struct iwl_rx_mem_buffer
*rxb
;
4244 struct iwl_rx_packet
*pkt
;
4245 struct iwl_rx_queue
*rxq
= &priv
->rxq
;
4248 unsigned long flags
;
4250 r
= iwl_hw_get_rx_read(priv
);
4253 /* Rx interrupt, but nothing sent from uCode */
4255 IWL_DEBUG(IWL_DL_RX
| IWL_DL_ISR
, "r = %d, i = %d\n", r
, i
);
4258 rxb
= rxq
->queue
[i
];
4260 /* If an RXB doesn't have a queue slot associated with it
4261 * then a bug has been introduced in the queue refilling
4262 * routines -- catch it here */
4263 BUG_ON(rxb
== NULL
);
4265 rxq
->queue
[i
] = NULL
;
4267 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
4269 PCI_DMA_FROMDEVICE
);
4270 pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
4272 /* Reclaim a command buffer only if this packet is a response
4273 * to a (driver-originated) command.
4274 * If the packet (e.g. Rx frame) originated from uCode,
4275 * there is no command buffer to reclaim.
4276 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
4277 * but apparently a few don't get set; catch them here. */
4278 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
4279 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
4280 (pkt
->hdr
.cmd
!= REPLY_TX
);
4282 /* Based on type of command response or notification,
4283 * handle those that need handling via function in
4284 * rx_handlers table. See iwl_setup_rx_handlers() */
4285 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
4286 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
4287 "r = %d, i = %d, %s, 0x%02x\n", r
, i
,
4288 get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
4289 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
4291 /* No handling needed */
4292 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
4293 "r %d i %d No handler needed for %s, 0x%02x\n",
4294 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
4299 /* Invoke any callbacks, transfer the skb to caller,
4300 * and fire off the (possibly) blocking iwl_send_cmd()
4301 * as we reclaim the driver command queue */
4302 if (rxb
&& rxb
->skb
)
4303 iwl_tx_cmd_complete(priv
, rxb
);
4305 IWL_WARNING("Claim null rxb?\n");
4308 /* For now we just don't re-use anything. We can tweak this
4309 * later to try and re-use notification packets and SKBs that
4310 * fail to Rx correctly */
4311 if (rxb
->skb
!= NULL
) {
4312 priv
->alloc_rxb_skb
--;
4313 dev_kfree_skb_any(rxb
->skb
);
4317 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
4318 IWL_RX_BUF_SIZE
, PCI_DMA_FROMDEVICE
);
4319 spin_lock_irqsave(&rxq
->lock
, flags
);
4320 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
4321 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4322 i
= (i
+ 1) & RX_QUEUE_MASK
;
4325 /* Backtrack one entry */
4327 iwl_rx_queue_restock(priv
);
4330 int iwl_tx_queue_update_write_ptr(struct iwl_priv
*priv
,
4331 struct iwl_tx_queue
*txq
)
4335 int txq_id
= txq
->q
.id
;
4337 if (txq
->need_update
== 0)
4340 /* if we're trying to save power */
4341 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
4342 /* wake up nic if it's powered down ...
4343 * uCode will wake up, and interrupt us again, so next
4344 * time we'll skip this part. */
4345 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
4347 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
4348 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg
);
4349 iwl_set_bit(priv
, CSR_GP_CNTRL
,
4350 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
4354 /* restore this queue's parameters in nic hardware. */
4355 rc
= iwl_grab_restricted_access(priv
);
4358 iwl_write_restricted(priv
, HBUS_TARG_WRPTR
,
4359 txq
->q
.first_empty
| (txq_id
<< 8));
4360 iwl_release_restricted_access(priv
);
4362 /* else not in power-save mode, uCode will never sleep when we're
4363 * trying to tx (during RFKILL, we're not trying to tx). */
4365 iwl_write32(priv
, HBUS_TARG_WRPTR
,
4366 txq
->q
.first_empty
| (txq_id
<< 8));
4368 txq
->need_update
= 0;
4373 #ifdef CONFIG_IWLWIFI_DEBUG
4374 static void iwl_print_rx_config_cmd(struct iwl_rxon_cmd
*rxon
)
4376 DECLARE_MAC_BUF(mac
);
4378 IWL_DEBUG_RADIO("RX CONFIG:\n");
4379 iwl_print_hex_dump(IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
4380 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
4381 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
4382 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4383 le32_to_cpu(rxon
->filter_flags
));
4384 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
4385 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4386 rxon
->ofdm_basic_rates
);
4387 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
4388 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4389 print_mac(mac
, rxon
->node_addr
));
4390 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4391 print_mac(mac
, rxon
->bssid_addr
));
4392 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
4396 static void iwl_enable_interrupts(struct iwl_priv
*priv
)
4398 IWL_DEBUG_ISR("Enabling interrupts\n");
4399 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
4400 iwl_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
4403 static inline void iwl_disable_interrupts(struct iwl_priv
*priv
)
4405 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
4407 /* disable interrupts from uCode/NIC to host */
4408 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
4410 /* acknowledge/clear/reset any interrupts still pending
4411 * from uCode or flow handler (Rx/Tx DMA) */
4412 iwl_write32(priv
, CSR_INT
, 0xffffffff);
4413 iwl_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
4414 IWL_DEBUG_ISR("Disabled interrupts\n");
4417 static const char *desc_lookup(int i
)
4425 return "BAD_CHECKSUM";
4427 return "NMI_INTERRUPT";
4431 return "FATAL_ERROR";
4437 #define ERROR_START_OFFSET (1 * sizeof(u32))
4438 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
4440 static void iwl_dump_nic_error_log(struct iwl_priv
*priv
)
4443 u32 desc
, time
, count
, base
, data1
;
4444 u32 blink1
, blink2
, ilink1
, ilink2
;
4447 base
= le32_to_cpu(priv
->card_alive
.error_event_table_ptr
);
4449 if (!iwl_hw_valid_rtc_data_addr(base
)) {
4450 IWL_ERROR("Not valid error log pointer 0x%08X\n", base
);
4454 rc
= iwl_grab_restricted_access(priv
);
4456 IWL_WARNING("Can not read from adapter at this time.\n");
4460 count
= iwl_read_restricted_mem(priv
, base
);
4462 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
4463 IWL_ERROR("Start IWL Error Log Dump:\n");
4464 IWL_ERROR("Status: 0x%08lX, Config: %08X count: %d\n",
4465 priv
->status
, priv
->config
, count
);
4468 IWL_ERROR("Desc Time asrtPC blink2 "
4469 "ilink1 nmiPC Line\n");
4470 for (i
= ERROR_START_OFFSET
;
4471 i
< (count
* ERROR_ELEM_SIZE
) + ERROR_START_OFFSET
;
4472 i
+= ERROR_ELEM_SIZE
) {
4473 desc
= iwl_read_restricted_mem(priv
, base
+ i
);
4475 iwl_read_restricted_mem(priv
, base
+ i
+ 1 * sizeof(u32
));
4477 iwl_read_restricted_mem(priv
, base
+ i
+ 2 * sizeof(u32
));
4479 iwl_read_restricted_mem(priv
, base
+ i
+ 3 * sizeof(u32
));
4481 iwl_read_restricted_mem(priv
, base
+ i
+ 4 * sizeof(u32
));
4483 iwl_read_restricted_mem(priv
, base
+ i
+ 5 * sizeof(u32
));
4485 iwl_read_restricted_mem(priv
, base
+ i
+ 6 * sizeof(u32
));
4488 ("%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
4489 desc_lookup(desc
), desc
, time
, blink1
, blink2
,
4490 ilink1
, ilink2
, data1
);
4493 iwl_release_restricted_access(priv
);
4497 #define EVENT_START_OFFSET (4 * sizeof(u32))
4500 * iwl_print_event_log - Dump error event log to syslog
4502 * NOTE: Must be called with iwl_grab_restricted_access() already obtained!
4504 static void iwl_print_event_log(struct iwl_priv
*priv
, u32 start_idx
,
4505 u32 num_events
, u32 mode
)
4508 u32 base
; /* SRAM byte address of event log header */
4509 u32 event_size
; /* 2 u32s, or 3 u32s if timestamp recorded */
4510 u32 ptr
; /* SRAM byte address of log data */
4511 u32 ev
, time
, data
; /* event log data */
4513 if (num_events
== 0)
4516 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4519 event_size
= 2 * sizeof(u32
);
4521 event_size
= 3 * sizeof(u32
);
4523 ptr
= base
+ EVENT_START_OFFSET
+ (start_idx
* event_size
);
4525 /* "time" is actually "data" for mode 0 (no timestamp).
4526 * place event id # at far right for easier visual parsing. */
4527 for (i
= 0; i
< num_events
; i
++) {
4528 ev
= iwl_read_restricted_mem(priv
, ptr
);
4530 time
= iwl_read_restricted_mem(priv
, ptr
);
4533 IWL_ERROR("0x%08x\t%04u\n", time
, ev
); /* data, ev */
4535 data
= iwl_read_restricted_mem(priv
, ptr
);
4537 IWL_ERROR("%010u\t0x%08x\t%04u\n", time
, data
, ev
);
4542 static void iwl_dump_nic_event_log(struct iwl_priv
*priv
)
4545 u32 base
; /* SRAM byte address of event log header */
4546 u32 capacity
; /* event log capacity in # entries */
4547 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
4548 u32 num_wraps
; /* # times uCode wrapped to top of log */
4549 u32 next_entry
; /* index of next entry to be written by uCode */
4550 u32 size
; /* # entries that we'll print */
4552 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4553 if (!iwl_hw_valid_rtc_data_addr(base
)) {
4554 IWL_ERROR("Invalid event log pointer 0x%08X\n", base
);
4558 rc
= iwl_grab_restricted_access(priv
);
4560 IWL_WARNING("Can not read from adapter at this time.\n");
4564 /* event log header */
4565 capacity
= iwl_read_restricted_mem(priv
, base
);
4566 mode
= iwl_read_restricted_mem(priv
, base
+ (1 * sizeof(u32
)));
4567 num_wraps
= iwl_read_restricted_mem(priv
, base
+ (2 * sizeof(u32
)));
4568 next_entry
= iwl_read_restricted_mem(priv
, base
+ (3 * sizeof(u32
)));
4570 size
= num_wraps
? capacity
: next_entry
;
4572 /* bail out if nothing in log */
4574 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
4575 iwl_release_restricted_access(priv
);
4579 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
4582 /* if uCode has wrapped back to top of log, start at the oldest entry,
4583 * i.e the next one that uCode would fill. */
4585 iwl_print_event_log(priv
, next_entry
,
4586 capacity
- next_entry
, mode
);
4588 /* (then/else) start at top of log */
4589 iwl_print_event_log(priv
, 0, next_entry
, mode
);
4591 iwl_release_restricted_access(priv
);
4595 * iwl_irq_handle_error - called for HW or SW error interrupt from card
4597 static void iwl_irq_handle_error(struct iwl_priv
*priv
)
4599 /* Set the FW error flag -- cleared on iwl_down */
4600 set_bit(STATUS_FW_ERROR
, &priv
->status
);
4602 /* Cancel currently queued command. */
4603 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
4605 #ifdef CONFIG_IWLWIFI_DEBUG
4606 if (iwl_debug_level
& IWL_DL_FW_ERRORS
) {
4607 iwl_dump_nic_error_log(priv
);
4608 iwl_dump_nic_event_log(priv
);
4609 iwl_print_rx_config_cmd(&priv
->staging_rxon
);
4613 wake_up_interruptible(&priv
->wait_command_queue
);
4615 /* Keep the restart process from trying to send host
4616 * commands by clearing the INIT status bit */
4617 clear_bit(STATUS_READY
, &priv
->status
);
4619 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
4620 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_FW_ERRORS
,
4621 "Restarting adapter due to uCode error.\n");
4623 if (iwl_is_associated(priv
)) {
4624 memcpy(&priv
->recovery_rxon
, &priv
->active_rxon
,
4625 sizeof(priv
->recovery_rxon
));
4626 priv
->error_recovering
= 1;
4628 queue_work(priv
->workqueue
, &priv
->restart
);
4632 static void iwl_error_recovery(struct iwl_priv
*priv
)
4634 unsigned long flags
;
4636 memcpy(&priv
->staging_rxon
, &priv
->recovery_rxon
,
4637 sizeof(priv
->staging_rxon
));
4638 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4639 iwl_commit_rxon(priv
);
4641 iwl_add_station(priv
, priv
->bssid
, 1, 0);
4643 spin_lock_irqsave(&priv
->lock
, flags
);
4644 priv
->assoc_id
= le16_to_cpu(priv
->staging_rxon
.assoc_id
);
4645 priv
->error_recovering
= 0;
4646 spin_unlock_irqrestore(&priv
->lock
, flags
);
4649 static void iwl_irq_tasklet(struct iwl_priv
*priv
)
4651 u32 inta
, handled
= 0;
4653 unsigned long flags
;
4654 #ifdef CONFIG_IWLWIFI_DEBUG
4658 spin_lock_irqsave(&priv
->lock
, flags
);
4660 /* Ack/clear/reset pending uCode interrupts.
4661 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4662 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
4663 inta
= iwl_read32(priv
, CSR_INT
);
4664 iwl_write32(priv
, CSR_INT
, inta
);
4666 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4667 * Any new interrupts that happen after this, either while we're
4668 * in this tasklet, or later, will show up in next ISR/tasklet. */
4669 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4670 iwl_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
4672 #ifdef CONFIG_IWLWIFI_DEBUG
4673 if (iwl_debug_level
& IWL_DL_ISR
) {
4674 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
); /* just for debug */
4675 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4676 inta
, inta_mask
, inta_fh
);
4680 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4681 * atomic, make sure that inta covers all the interrupts that
4682 * we've discovered, even if FH interrupt came in just after
4683 * reading CSR_INT. */
4684 if (inta_fh
& CSR_FH_INT_RX_MASK
)
4685 inta
|= CSR_INT_BIT_FH_RX
;
4686 if (inta_fh
& CSR_FH_INT_TX_MASK
)
4687 inta
|= CSR_INT_BIT_FH_TX
;
4689 /* Now service all interrupt bits discovered above. */
4690 if (inta
& CSR_INT_BIT_HW_ERR
) {
4691 IWL_ERROR("Microcode HW error detected. Restarting.\n");
4693 /* Tell the device to stop sending interrupts */
4694 iwl_disable_interrupts(priv
);
4696 iwl_irq_handle_error(priv
);
4698 handled
|= CSR_INT_BIT_HW_ERR
;
4700 spin_unlock_irqrestore(&priv
->lock
, flags
);
4705 #ifdef CONFIG_IWLWIFI_DEBUG
4706 if (iwl_debug_level
& (IWL_DL_ISR
)) {
4707 /* NIC fires this, but we don't use it, redundant with WAKEUP */
4708 if (inta
& CSR_INT_BIT_MAC_CLK_ACTV
)
4709 IWL_DEBUG_ISR("Microcode started or stopped.\n");
4711 /* Alive notification via Rx interrupt will do the real work */
4712 if (inta
& CSR_INT_BIT_ALIVE
)
4713 IWL_DEBUG_ISR("Alive interrupt\n");
4716 /* Safely ignore these bits for debug checks below */
4717 inta
&= ~(CSR_INT_BIT_MAC_CLK_ACTV
| CSR_INT_BIT_ALIVE
);
4719 /* HW RF KILL switch toggled (4965 only) */
4720 if (inta
& CSR_INT_BIT_RF_KILL
) {
4722 if (!(iwl_read32(priv
, CSR_GP_CNTRL
) &
4723 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
4726 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
| IWL_DL_ISR
,
4727 "RF_KILL bit toggled to %s.\n",
4728 hw_rf_kill
? "disable radio":"enable radio");
4730 /* Queue restart only if RF_KILL switch was set to "kill"
4731 * when we loaded driver, and is now set to "enable".
4732 * After we're Alive, RF_KILL gets handled by
4733 * iwl_rx_card_state_notif() */
4734 if (!hw_rf_kill
&& !test_bit(STATUS_ALIVE
, &priv
->status
))
4735 queue_work(priv
->workqueue
, &priv
->restart
);
4737 handled
|= CSR_INT_BIT_RF_KILL
;
4740 /* Chip got too hot and stopped itself (4965 only) */
4741 if (inta
& CSR_INT_BIT_CT_KILL
) {
4742 IWL_ERROR("Microcode CT kill error detected.\n");
4743 handled
|= CSR_INT_BIT_CT_KILL
;
4746 /* Error detected by uCode */
4747 if (inta
& CSR_INT_BIT_SW_ERR
) {
4748 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
4750 iwl_irq_handle_error(priv
);
4751 handled
|= CSR_INT_BIT_SW_ERR
;
4754 /* uCode wakes up after power-down sleep */
4755 if (inta
& CSR_INT_BIT_WAKEUP
) {
4756 IWL_DEBUG_ISR("Wakeup interrupt\n");
4757 iwl_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
4758 iwl_tx_queue_update_write_ptr(priv
, &priv
->txq
[0]);
4759 iwl_tx_queue_update_write_ptr(priv
, &priv
->txq
[1]);
4760 iwl_tx_queue_update_write_ptr(priv
, &priv
->txq
[2]);
4761 iwl_tx_queue_update_write_ptr(priv
, &priv
->txq
[3]);
4762 iwl_tx_queue_update_write_ptr(priv
, &priv
->txq
[4]);
4763 iwl_tx_queue_update_write_ptr(priv
, &priv
->txq
[5]);
4765 handled
|= CSR_INT_BIT_WAKEUP
;
4768 /* All uCode command responses, including Tx command responses,
4769 * Rx "responses" (frame-received notification), and other
4770 * notifications from uCode come through here*/
4771 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
4772 iwl_rx_handle(priv
);
4773 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
4776 if (inta
& CSR_INT_BIT_FH_TX
) {
4777 IWL_DEBUG_ISR("Tx interrupt\n");
4779 iwl_write32(priv
, CSR_FH_INT_STATUS
, (1 << 6));
4780 if (!iwl_grab_restricted_access(priv
)) {
4781 iwl_write_restricted(priv
,
4783 (ALM_FH_SRVC_CHNL
), 0x0);
4784 iwl_release_restricted_access(priv
);
4786 handled
|= CSR_INT_BIT_FH_TX
;
4789 if (inta
& ~handled
)
4790 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
4792 if (inta
& ~CSR_INI_SET_MASK
) {
4793 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
4794 inta
& ~CSR_INI_SET_MASK
);
4795 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh
);
4798 /* Re-enable all interrupts */
4799 iwl_enable_interrupts(priv
);
4801 #ifdef CONFIG_IWLWIFI_DEBUG
4802 if (iwl_debug_level
& (IWL_DL_ISR
)) {
4803 inta
= iwl_read32(priv
, CSR_INT
);
4804 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
4805 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4806 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
4807 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
4810 spin_unlock_irqrestore(&priv
->lock
, flags
);
4813 static irqreturn_t
iwl_isr(int irq
, void *data
)
4815 struct iwl_priv
*priv
= data
;
4816 u32 inta
, inta_mask
;
4821 spin_lock(&priv
->lock
);
4823 /* Disable (but don't clear!) interrupts here to avoid
4824 * back-to-back ISRs and sporadic interrupts from our NIC.
4825 * If we have something to service, the tasklet will re-enable ints.
4826 * If we *don't* have something, we'll re-enable before leaving here. */
4827 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
); /* just for debug */
4828 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
4830 /* Discover which interrupts are active/pending */
4831 inta
= iwl_read32(priv
, CSR_INT
);
4832 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4834 /* Ignore interrupt if there's nothing in NIC to service.
4835 * This may be due to IRQ shared with another device,
4836 * or due to sporadic interrupts thrown from our NIC. */
4837 if (!inta
&& !inta_fh
) {
4838 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
4842 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
4843 /* Hardware disappeared */
4844 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta
);
4848 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4849 inta
, inta_mask
, inta_fh
);
4851 /* iwl_irq_tasklet() will service interrupts and re-enable them */
4852 tasklet_schedule(&priv
->irq_tasklet
);
4853 spin_unlock(&priv
->lock
);
4858 /* re-enable interrupts here since we don't have anything to service. */
4859 iwl_enable_interrupts(priv
);
4860 spin_unlock(&priv
->lock
);
4864 /************************** EEPROM BANDS ****************************
4866 * The iwl_eeprom_band definitions below provide the mapping from the
4867 * EEPROM contents to the specific channel number supported for each
4870 * For example, iwl_priv->eeprom.band_3_channels[4] from the band_3
4871 * definition below maps to physical channel 42 in the 5.2GHz spectrum.
4872 * The specific geography and calibration information for that channel
4873 * is contained in the eeprom map itself.
4875 * During init, we copy the eeprom information and channel map
4876 * information into priv->channel_info_24/52 and priv->channel_map_24/52
4878 * channel_map_24/52 provides the index in the channel_info array for a
4879 * given channel. We have to have two separate maps as there is channel
4880 * overlap with the 2.4GHz and 5.2GHz spectrum as seen in band_1 and
4883 * A value of 0xff stored in the channel_map indicates that the channel
4884 * is not supported by the hardware at all.
4886 * A value of 0xfe in the channel_map indicates that the channel is not
4887 * valid for Tx with the current hardware. This means that
4888 * while the system can tune and receive on a given channel, it may not
4889 * be able to associate or transmit any frames on that
4890 * channel. There is no corresponding channel information for that
4893 *********************************************************************/
4896 static const u8 iwl_eeprom_band_1
[14] = {
4897 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
4901 static const u8 iwl_eeprom_band_2
[] = {
4902 183, 184, 185, 187, 188, 189, 192, 196, 7, 8, 11, 12, 16
4905 static const u8 iwl_eeprom_band_3
[] = { /* 5205-5320MHz */
4906 34, 36, 38, 40, 42, 44, 46, 48, 52, 56, 60, 64
4909 static const u8 iwl_eeprom_band_4
[] = { /* 5500-5700MHz */
4910 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140
4913 static const u8 iwl_eeprom_band_5
[] = { /* 5725-5825MHz */
4914 145, 149, 153, 157, 161, 165
4917 static void iwl_init_band_reference(const struct iwl_priv
*priv
, int band
,
4918 int *eeprom_ch_count
,
4919 const struct iwl_eeprom_channel
4921 const u8
**eeprom_ch_index
)
4924 case 1: /* 2.4GHz band */
4925 *eeprom_ch_count
= ARRAY_SIZE(iwl_eeprom_band_1
);
4926 *eeprom_ch_info
= priv
->eeprom
.band_1_channels
;
4927 *eeprom_ch_index
= iwl_eeprom_band_1
;
4929 case 2: /* 5.2GHz band */
4930 *eeprom_ch_count
= ARRAY_SIZE(iwl_eeprom_band_2
);
4931 *eeprom_ch_info
= priv
->eeprom
.band_2_channels
;
4932 *eeprom_ch_index
= iwl_eeprom_band_2
;
4934 case 3: /* 5.2GHz band */
4935 *eeprom_ch_count
= ARRAY_SIZE(iwl_eeprom_band_3
);
4936 *eeprom_ch_info
= priv
->eeprom
.band_3_channels
;
4937 *eeprom_ch_index
= iwl_eeprom_band_3
;
4939 case 4: /* 5.2GHz band */
4940 *eeprom_ch_count
= ARRAY_SIZE(iwl_eeprom_band_4
);
4941 *eeprom_ch_info
= priv
->eeprom
.band_4_channels
;
4942 *eeprom_ch_index
= iwl_eeprom_band_4
;
4944 case 5: /* 5.2GHz band */
4945 *eeprom_ch_count
= ARRAY_SIZE(iwl_eeprom_band_5
);
4946 *eeprom_ch_info
= priv
->eeprom
.band_5_channels
;
4947 *eeprom_ch_index
= iwl_eeprom_band_5
;
4955 const struct iwl_channel_info
*iwl_get_channel_info(const struct iwl_priv
*priv
,
4956 int phymode
, u16 channel
)
4961 case MODE_IEEE80211A
:
4962 for (i
= 14; i
< priv
->channel_count
; i
++) {
4963 if (priv
->channel_info
[i
].channel
== channel
)
4964 return &priv
->channel_info
[i
];
4968 case MODE_IEEE80211B
:
4969 case MODE_IEEE80211G
:
4970 if (channel
>= 1 && channel
<= 14)
4971 return &priv
->channel_info
[channel
- 1];
4979 #define CHECK_AND_PRINT(x) ((eeprom_ch_info[ch].flags & EEPROM_CHANNEL_##x) \
4982 static int iwl_init_channel_map(struct iwl_priv
*priv
)
4984 int eeprom_ch_count
= 0;
4985 const u8
*eeprom_ch_index
= NULL
;
4986 const struct iwl_eeprom_channel
*eeprom_ch_info
= NULL
;
4988 struct iwl_channel_info
*ch_info
;
4990 if (priv
->channel_count
) {
4991 IWL_DEBUG_INFO("Channel map already initialized.\n");
4995 if (priv
->eeprom
.version
< 0x2f) {
4996 IWL_WARNING("Unsupported EEPROM version: 0x%04X\n",
4997 priv
->eeprom
.version
);
5001 IWL_DEBUG_INFO("Initializing regulatory info from EEPROM\n");
5003 priv
->channel_count
=
5004 ARRAY_SIZE(iwl_eeprom_band_1
) +
5005 ARRAY_SIZE(iwl_eeprom_band_2
) +
5006 ARRAY_SIZE(iwl_eeprom_band_3
) +
5007 ARRAY_SIZE(iwl_eeprom_band_4
) +
5008 ARRAY_SIZE(iwl_eeprom_band_5
);
5010 IWL_DEBUG_INFO("Parsing data for %d channels.\n", priv
->channel_count
);
5012 priv
->channel_info
= kzalloc(sizeof(struct iwl_channel_info
) *
5013 priv
->channel_count
, GFP_KERNEL
);
5014 if (!priv
->channel_info
) {
5015 IWL_ERROR("Could not allocate channel_info\n");
5016 priv
->channel_count
= 0;
5020 ch_info
= priv
->channel_info
;
5022 /* Loop through the 5 EEPROM bands adding them in order to the
5023 * channel map we maintain (that contains additional information than
5024 * what just in the EEPROM) */
5025 for (band
= 1; band
<= 5; band
++) {
5027 iwl_init_band_reference(priv
, band
, &eeprom_ch_count
,
5028 &eeprom_ch_info
, &eeprom_ch_index
);
5030 /* Loop through each band adding each of the channels */
5031 for (ch
= 0; ch
< eeprom_ch_count
; ch
++) {
5032 ch_info
->channel
= eeprom_ch_index
[ch
];
5033 ch_info
->phymode
= (band
== 1) ? MODE_IEEE80211B
:
5036 /* permanently store EEPROM's channel regulatory flags
5037 * and max power in channel info database. */
5038 ch_info
->eeprom
= eeprom_ch_info
[ch
];
5040 /* Copy the run-time flags so they are there even on
5041 * invalid channels */
5042 ch_info
->flags
= eeprom_ch_info
[ch
].flags
;
5044 if (!(is_channel_valid(ch_info
))) {
5045 IWL_DEBUG_INFO("Ch. %d Flags %x [%sGHz] - "
5049 is_channel_a_band(ch_info
) ?
5055 /* Initialize regulatory-based run-time data */
5056 ch_info
->max_power_avg
= ch_info
->curr_txpow
=
5057 eeprom_ch_info
[ch
].max_power_avg
;
5058 ch_info
->scan_power
= eeprom_ch_info
[ch
].max_power_avg
;
5059 ch_info
->min_power
= 0;
5061 IWL_DEBUG_INFO("Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
5062 " %ddBm): Ad-Hoc %ssupported\n",
5064 is_channel_a_band(ch_info
) ?
5066 CHECK_AND_PRINT(IBSS
),
5067 CHECK_AND_PRINT(ACTIVE
),
5068 CHECK_AND_PRINT(RADAR
),
5069 CHECK_AND_PRINT(WIDE
),
5070 CHECK_AND_PRINT(NARROW
),
5071 CHECK_AND_PRINT(DFS
),
5072 eeprom_ch_info
[ch
].flags
,
5073 eeprom_ch_info
[ch
].max_power_avg
,
5074 ((eeprom_ch_info
[ch
].
5075 flags
& EEPROM_CHANNEL_IBSS
)
5076 && !(eeprom_ch_info
[ch
].
5077 flags
& EEPROM_CHANNEL_RADAR
))
5080 /* Set the user_txpower_limit to the highest power
5081 * supported by any channel */
5082 if (eeprom_ch_info
[ch
].max_power_avg
>
5083 priv
->user_txpower_limit
)
5084 priv
->user_txpower_limit
=
5085 eeprom_ch_info
[ch
].max_power_avg
;
5091 if (iwl3945_txpower_set_from_eeprom(priv
))
5097 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
5098 * sending probe req. This should be set long enough to hear probe responses
5099 * from more than one AP. */
5100 #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
5101 #define IWL_ACTIVE_DWELL_TIME_52 (10)
5103 /* For faster active scanning, scan will move to the next channel if fewer than
5104 * PLCP_QUIET_THRESH packets are heard on this channel within
5105 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
5106 * time if it's a quiet channel (nothing responded to our probe, and there's
5107 * no other traffic).
5108 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
5109 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
5110 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
5112 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
5113 * Must be set longer than active dwell time.
5114 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
5115 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
5116 #define IWL_PASSIVE_DWELL_TIME_52 (10)
5117 #define IWL_PASSIVE_DWELL_BASE (100)
5118 #define IWL_CHANNEL_TUNE_TIME 5
5120 static inline u16
iwl_get_active_dwell_time(struct iwl_priv
*priv
, int phymode
)
5122 if (phymode
== MODE_IEEE80211A
)
5123 return IWL_ACTIVE_DWELL_TIME_52
;
5125 return IWL_ACTIVE_DWELL_TIME_24
;
5128 static u16
iwl_get_passive_dwell_time(struct iwl_priv
*priv
, int phymode
)
5130 u16 active
= iwl_get_active_dwell_time(priv
, phymode
);
5131 u16 passive
= (phymode
!= MODE_IEEE80211A
) ?
5132 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_24
:
5133 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_52
;
5135 if (iwl_is_associated(priv
)) {
5136 /* If we're associated, we clamp the maximum passive
5137 * dwell time to be 98% of the beacon interval (minus
5138 * 2 * channel tune time) */
5139 passive
= priv
->beacon_int
;
5140 if ((passive
> IWL_PASSIVE_DWELL_BASE
) || !passive
)
5141 passive
= IWL_PASSIVE_DWELL_BASE
;
5142 passive
= (passive
* 98) / 100 - IWL_CHANNEL_TUNE_TIME
* 2;
5145 if (passive
<= active
)
5146 passive
= active
+ 1;
5151 static int iwl_get_channels_for_scan(struct iwl_priv
*priv
, int phymode
,
5152 u8 is_active
, u8 direct_mask
,
5153 struct iwl_scan_channel
*scan_ch
)
5155 const struct ieee80211_channel
*channels
= NULL
;
5156 const struct ieee80211_hw_mode
*hw_mode
;
5157 const struct iwl_channel_info
*ch_info
;
5158 u16 passive_dwell
= 0;
5159 u16 active_dwell
= 0;
5162 hw_mode
= iwl_get_hw_mode(priv
, phymode
);
5166 channels
= hw_mode
->channels
;
5168 active_dwell
= iwl_get_active_dwell_time(priv
, phymode
);
5169 passive_dwell
= iwl_get_passive_dwell_time(priv
, phymode
);
5171 for (i
= 0, added
= 0; i
< hw_mode
->num_channels
; i
++) {
5172 if (channels
[i
].chan
==
5173 le16_to_cpu(priv
->active_rxon
.channel
)) {
5174 if (iwl_is_associated(priv
)) {
5176 ("Skipping current channel %d\n",
5177 le16_to_cpu(priv
->active_rxon
.channel
));
5180 } else if (priv
->only_active_channel
)
5183 scan_ch
->channel
= channels
[i
].chan
;
5185 ch_info
= iwl_get_channel_info(priv
, phymode
, scan_ch
->channel
);
5186 if (!is_channel_valid(ch_info
)) {
5187 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
5192 if (!is_active
|| is_channel_passive(ch_info
) ||
5193 !(channels
[i
].flag
& IEEE80211_CHAN_W_ACTIVE_SCAN
))
5194 scan_ch
->type
= 0; /* passive */
5196 scan_ch
->type
= 1; /* active */
5198 if (scan_ch
->type
& 1)
5199 scan_ch
->type
|= (direct_mask
<< 1);
5201 if (is_channel_narrow(ch_info
))
5202 scan_ch
->type
|= (1 << 7);
5204 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
5205 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
5207 /* Set power levels to defaults */
5208 scan_ch
->tpc
.dsp_atten
= 110;
5209 /* scan_pwr_info->tpc.dsp_atten; */
5211 /*scan_pwr_info->tpc.tx_gain; */
5212 if (phymode
== MODE_IEEE80211A
)
5213 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
5215 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
5216 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
5218 scan_ch->tpc.tx_gain = ((1<<5) | (2 << 3)) | 3;
5222 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
5224 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
5225 (scan_ch
->type
& 1) ?
5226 active_dwell
: passive_dwell
);
5232 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
5236 static void iwl_reset_channel_flag(struct iwl_priv
*priv
)
5239 for (i
= 0; i
< 3; i
++) {
5240 struct ieee80211_hw_mode
*hw_mode
= (void *)&priv
->modes
[i
];
5241 for (j
= 0; j
< hw_mode
->num_channels
; j
++)
5242 hw_mode
->channels
[j
].flag
= hw_mode
->channels
[j
].val
;
5246 static void iwl_init_hw_rates(struct iwl_priv
*priv
,
5247 struct ieee80211_rate
*rates
)
5251 for (i
= 0; i
< IWL_RATE_COUNT
; i
++) {
5252 rates
[i
].rate
= iwl_rates
[i
].ieee
* 5;
5253 rates
[i
].val
= i
; /* Rate scaling will work on indexes */
5255 rates
[i
].flags
= IEEE80211_RATE_SUPPORTED
;
5256 /* Only OFDM have the bits-per-symbol set */
5257 if ((i
<= IWL_LAST_OFDM_RATE
) && (i
>= IWL_FIRST_OFDM_RATE
))
5258 rates
[i
].flags
|= IEEE80211_RATE_OFDM
;
5261 * If CCK 1M then set rate flag to CCK else CCK_2
5262 * which is CCK | PREAMBLE2
5264 rates
[i
].flags
|= (iwl_rates
[i
].plcp
== 10) ?
5265 IEEE80211_RATE_CCK
: IEEE80211_RATE_CCK_2
;
5268 /* Set up which ones are basic rates... */
5269 if (IWL_BASIC_RATES_MASK
& (1 << i
))
5270 rates
[i
].flags
|= IEEE80211_RATE_BASIC
;
5275 * iwl_init_geos - Initialize mac80211's geo/channel info based from eeprom
5277 static int iwl_init_geos(struct iwl_priv
*priv
)
5279 struct iwl_channel_info
*ch
;
5280 struct ieee80211_hw_mode
*modes
;
5281 struct ieee80211_channel
*channels
;
5282 struct ieee80211_channel
*geo_ch
;
5283 struct ieee80211_rate
*rates
;
5293 IWL_DEBUG_INFO("Geography modes already initialized.\n");
5294 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
5298 modes
= kzalloc(sizeof(struct ieee80211_hw_mode
) * mode_count
,
5303 channels
= kzalloc(sizeof(struct ieee80211_channel
) *
5304 priv
->channel_count
, GFP_KERNEL
);
5310 rates
= kzalloc((sizeof(struct ieee80211_rate
) * (IWL_MAX_RATES
+ 1)),
5323 /* 5.2GHz channels start after the 2.4GHz channels */
5324 modes
[A
].mode
= MODE_IEEE80211A
;
5325 modes
[A
].channels
= &channels
[ARRAY_SIZE(iwl_eeprom_band_1
)];
5326 modes
[A
].rates
= rates
;
5327 modes
[A
].num_rates
= 8; /* just OFDM */
5328 modes
[A
].num_channels
= 0;
5330 modes
[B
].mode
= MODE_IEEE80211B
;
5331 modes
[B
].channels
= channels
;
5332 modes
[B
].rates
= &rates
[8];
5333 modes
[B
].num_rates
= 4; /* just CCK */
5334 modes
[B
].num_channels
= 0;
5336 modes
[G
].mode
= MODE_IEEE80211G
;
5337 modes
[G
].channels
= channels
;
5338 modes
[G
].rates
= rates
;
5339 modes
[G
].num_rates
= 12; /* OFDM & CCK */
5340 modes
[G
].num_channels
= 0;
5342 priv
->ieee_channels
= channels
;
5343 priv
->ieee_rates
= rates
;
5345 iwl_init_hw_rates(priv
, rates
);
5347 for (i
= 0, geo_ch
= channels
; i
< priv
->channel_count
; i
++) {
5348 ch
= &priv
->channel_info
[i
];
5350 if (!is_channel_valid(ch
)) {
5351 IWL_DEBUG_INFO("Channel %d [%sGHz] is restricted -- "
5353 ch
->channel
, is_channel_a_band(ch
) ?
5358 if (is_channel_a_band(ch
))
5359 geo_ch
= &modes
[A
].channels
[modes
[A
].num_channels
++];
5361 geo_ch
= &modes
[B
].channels
[modes
[B
].num_channels
++];
5362 modes
[G
].num_channels
++;
5365 geo_ch
->freq
= ieee80211chan2mhz(ch
->channel
);
5366 geo_ch
->chan
= ch
->channel
;
5367 geo_ch
->power_level
= ch
->max_power_avg
;
5368 geo_ch
->antenna_max
= 0xff;
5370 if (is_channel_valid(ch
)) {
5371 geo_ch
->flag
= IEEE80211_CHAN_W_SCAN
;
5372 if (ch
->flags
& EEPROM_CHANNEL_IBSS
)
5373 geo_ch
->flag
|= IEEE80211_CHAN_W_IBSS
;
5375 if (ch
->flags
& EEPROM_CHANNEL_ACTIVE
)
5376 geo_ch
->flag
|= IEEE80211_CHAN_W_ACTIVE_SCAN
;
5378 if (ch
->flags
& EEPROM_CHANNEL_RADAR
)
5379 geo_ch
->flag
|= IEEE80211_CHAN_W_RADAR_DETECT
;
5381 if (ch
->max_power_avg
> priv
->max_channel_txpower_limit
)
5382 priv
->max_channel_txpower_limit
=
5386 geo_ch
->val
= geo_ch
->flag
;
5389 if ((modes
[A
].num_channels
== 0) && priv
->is_abg
) {
5390 printk(KERN_INFO DRV_NAME
5391 ": Incorrectly detected BG card as ABG. Please send "
5392 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
5393 priv
->pci_dev
->device
, priv
->pci_dev
->subsystem_device
);
5397 printk(KERN_INFO DRV_NAME
5398 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
5399 modes
[G
].num_channels
, modes
[A
].num_channels
);
5402 * NOTE: We register these in preference of order -- the
5403 * stack doesn't currently (as of 7.0.6 / Apr 24 '07) pick
5404 * a phymode based on rates or AP capabilities but seems to
5405 * configure it purely on if the channel being configured
5406 * is supported by a mode -- and the first match is taken
5409 if (modes
[G
].num_channels
)
5410 ieee80211_register_hwmode(priv
->hw
, &modes
[G
]);
5411 if (modes
[B
].num_channels
)
5412 ieee80211_register_hwmode(priv
->hw
, &modes
[B
]);
5413 if (modes
[A
].num_channels
)
5414 ieee80211_register_hwmode(priv
->hw
, &modes
[A
]);
5416 priv
->modes
= modes
;
5417 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
5422 /******************************************************************************
5424 * uCode download functions
5426 ******************************************************************************/
5428 static void iwl_dealloc_ucode_pci(struct iwl_priv
*priv
)
5430 if (priv
->ucode_code
.v_addr
!= NULL
) {
5431 pci_free_consistent(priv
->pci_dev
,
5432 priv
->ucode_code
.len
,
5433 priv
->ucode_code
.v_addr
,
5434 priv
->ucode_code
.p_addr
);
5435 priv
->ucode_code
.v_addr
= NULL
;
5437 if (priv
->ucode_data
.v_addr
!= NULL
) {
5438 pci_free_consistent(priv
->pci_dev
,
5439 priv
->ucode_data
.len
,
5440 priv
->ucode_data
.v_addr
,
5441 priv
->ucode_data
.p_addr
);
5442 priv
->ucode_data
.v_addr
= NULL
;
5444 if (priv
->ucode_data_backup
.v_addr
!= NULL
) {
5445 pci_free_consistent(priv
->pci_dev
,
5446 priv
->ucode_data_backup
.len
,
5447 priv
->ucode_data_backup
.v_addr
,
5448 priv
->ucode_data_backup
.p_addr
);
5449 priv
->ucode_data_backup
.v_addr
= NULL
;
5451 if (priv
->ucode_init
.v_addr
!= NULL
) {
5452 pci_free_consistent(priv
->pci_dev
,
5453 priv
->ucode_init
.len
,
5454 priv
->ucode_init
.v_addr
,
5455 priv
->ucode_init
.p_addr
);
5456 priv
->ucode_init
.v_addr
= NULL
;
5458 if (priv
->ucode_init_data
.v_addr
!= NULL
) {
5459 pci_free_consistent(priv
->pci_dev
,
5460 priv
->ucode_init_data
.len
,
5461 priv
->ucode_init_data
.v_addr
,
5462 priv
->ucode_init_data
.p_addr
);
5463 priv
->ucode_init_data
.v_addr
= NULL
;
5465 if (priv
->ucode_boot
.v_addr
!= NULL
) {
5466 pci_free_consistent(priv
->pci_dev
,
5467 priv
->ucode_boot
.len
,
5468 priv
->ucode_boot
.v_addr
,
5469 priv
->ucode_boot
.p_addr
);
5470 priv
->ucode_boot
.v_addr
= NULL
;
5475 * iwl_verify_inst_full - verify runtime uCode image in card vs. host,
5476 * looking at all data.
5478 static int iwl_verify_inst_full(struct iwl_priv
*priv
, __le32
* image
, u32 len
)
5485 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
5487 rc
= iwl_grab_restricted_access(priv
);
5491 iwl_write_restricted(priv
, HBUS_TARG_MEM_RADDR
, RTC_INST_LOWER_BOUND
);
5494 for (; len
> 0; len
-= sizeof(u32
), image
++) {
5495 /* read data comes through single port, auto-incr addr */
5496 /* NOTE: Use the debugless read so we don't flood kernel log
5497 * if IWL_DL_IO is set */
5498 val
= _iwl_read_restricted(priv
, HBUS_TARG_MEM_RDAT
);
5499 if (val
!= le32_to_cpu(*image
)) {
5500 IWL_ERROR("uCode INST section is invalid at "
5501 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5502 save_len
- len
, val
, le32_to_cpu(*image
));
5510 iwl_release_restricted_access(priv
);
5514 ("ucode image in INSTRUCTION memory is good\n");
5521 * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
5522 * using sample data 100 bytes apart. If these sample points are good,
5523 * it's a pretty good bet that everything between them is good, too.
5525 static int iwl_verify_inst_sparse(struct iwl_priv
*priv
, __le32
*image
, u32 len
)
5532 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
5534 rc
= iwl_grab_restricted_access(priv
);
5538 for (i
= 0; i
< len
; i
+= 100, image
+= 100/sizeof(u32
)) {
5539 /* read data comes through single port, auto-incr addr */
5540 /* NOTE: Use the debugless read so we don't flood kernel log
5541 * if IWL_DL_IO is set */
5542 iwl_write_restricted(priv
, HBUS_TARG_MEM_RADDR
,
5543 i
+ RTC_INST_LOWER_BOUND
);
5544 val
= _iwl_read_restricted(priv
, HBUS_TARG_MEM_RDAT
);
5545 if (val
!= le32_to_cpu(*image
)) {
5546 #if 0 /* Enable this if you want to see details */
5547 IWL_ERROR("uCode INST section is invalid at "
5548 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5558 iwl_release_restricted_access(priv
);
5565 * iwl_verify_ucode - determine which instruction image is in SRAM,
5566 * and verify its contents
5568 static int iwl_verify_ucode(struct iwl_priv
*priv
)
5575 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5576 len
= priv
->ucode_boot
.len
;
5577 rc
= iwl_verify_inst_sparse(priv
, image
, len
);
5579 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
5583 /* Try initialize */
5584 image
= (__le32
*)priv
->ucode_init
.v_addr
;
5585 len
= priv
->ucode_init
.len
;
5586 rc
= iwl_verify_inst_sparse(priv
, image
, len
);
5588 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
5592 /* Try runtime/protocol */
5593 image
= (__le32
*)priv
->ucode_code
.v_addr
;
5594 len
= priv
->ucode_code
.len
;
5595 rc
= iwl_verify_inst_sparse(priv
, image
, len
);
5597 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
5601 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5603 /* Show first several data entries in instruction SRAM.
5604 * Selection of bootstrap image is arbitrary. */
5605 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5606 len
= priv
->ucode_boot
.len
;
5607 rc
= iwl_verify_inst_full(priv
, image
, len
);
5613 /* check contents of special bootstrap uCode SRAM */
5614 static int iwl_verify_bsm(struct iwl_priv
*priv
)
5616 __le32
*image
= priv
->ucode_boot
.v_addr
;
5617 u32 len
= priv
->ucode_boot
.len
;
5621 IWL_DEBUG_INFO("Begin verify bsm\n");
5623 /* verify BSM SRAM contents */
5624 val
= iwl_read_restricted_reg(priv
, BSM_WR_DWCOUNT_REG
);
5625 for (reg
= BSM_SRAM_LOWER_BOUND
;
5626 reg
< BSM_SRAM_LOWER_BOUND
+ len
;
5627 reg
+= sizeof(u32
), image
++) {
5628 val
= iwl_read_restricted_reg(priv
, reg
);
5629 if (val
!= le32_to_cpu(*image
)) {
5630 IWL_ERROR("BSM uCode verification failed at "
5631 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
5632 BSM_SRAM_LOWER_BOUND
,
5633 reg
- BSM_SRAM_LOWER_BOUND
, len
,
5634 val
, le32_to_cpu(*image
));
5639 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
5645 * iwl_load_bsm - Load bootstrap instructions
5649 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
5650 * in special SRAM that does not power down during RFKILL. When powering back
5651 * up after power-saving sleeps (or during initial uCode load), the BSM loads
5652 * the bootstrap program into the on-board processor, and starts it.
5654 * The bootstrap program loads (via DMA) instructions and data for a new
5655 * program from host DRAM locations indicated by the host driver in the
5656 * BSM_DRAM_* registers. Once the new program is loaded, it starts
5659 * When initializing the NIC, the host driver points the BSM to the
5660 * "initialize" uCode image. This uCode sets up some internal data, then
5661 * notifies host via "initialize alive" that it is complete.
5663 * The host then replaces the BSM_DRAM_* pointer values to point to the
5664 * normal runtime uCode instructions and a backup uCode data cache buffer
5665 * (filled initially with starting data values for the on-board processor),
5666 * then triggers the "initialize" uCode to load and launch the runtime uCode,
5667 * which begins normal operation.
5669 * When doing a power-save shutdown, runtime uCode saves data SRAM into
5670 * the backup data cache in DRAM before SRAM is powered down.
5672 * When powering back up, the BSM loads the bootstrap program. This reloads
5673 * the runtime uCode instructions and the backup data cache into SRAM,
5674 * and re-launches the runtime uCode from where it left off.
5676 static int iwl_load_bsm(struct iwl_priv
*priv
)
5678 __le32
*image
= priv
->ucode_boot
.v_addr
;
5679 u32 len
= priv
->ucode_boot
.len
;
5689 IWL_DEBUG_INFO("Begin load bsm\n");
5691 /* make sure bootstrap program is no larger than BSM's SRAM size */
5692 if (len
> IWL_MAX_BSM_SIZE
)
5695 /* Tell bootstrap uCode where to find the "Initialize" uCode
5696 * in host DRAM ... bits 31:0 for 3945, bits 35:4 for 4965.
5697 * NOTE: iwl_initialize_alive_start() will replace these values,
5698 * after the "initialize" uCode has run, to point to
5699 * runtime/protocol instructions and backup data cache. */
5700 pinst
= priv
->ucode_init
.p_addr
;
5701 pdata
= priv
->ucode_init_data
.p_addr
;
5702 inst_len
= priv
->ucode_init
.len
;
5703 data_len
= priv
->ucode_init_data
.len
;
5705 rc
= iwl_grab_restricted_access(priv
);
5709 iwl_write_restricted_reg(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
5710 iwl_write_restricted_reg(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
5711 iwl_write_restricted_reg(priv
, BSM_DRAM_INST_BYTECOUNT_REG
, inst_len
);
5712 iwl_write_restricted_reg(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
, data_len
);
5714 /* Fill BSM memory with bootstrap instructions */
5715 for (reg_offset
= BSM_SRAM_LOWER_BOUND
;
5716 reg_offset
< BSM_SRAM_LOWER_BOUND
+ len
;
5717 reg_offset
+= sizeof(u32
), image
++)
5718 _iwl_write_restricted_reg(priv
, reg_offset
,
5719 le32_to_cpu(*image
));
5721 rc
= iwl_verify_bsm(priv
);
5723 iwl_release_restricted_access(priv
);
5727 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
5728 iwl_write_restricted_reg(priv
, BSM_WR_MEM_SRC_REG
, 0x0);
5729 iwl_write_restricted_reg(priv
, BSM_WR_MEM_DST_REG
,
5730 RTC_INST_LOWER_BOUND
);
5731 iwl_write_restricted_reg(priv
, BSM_WR_DWCOUNT_REG
, len
/ sizeof(u32
));
5733 /* Load bootstrap code into instruction SRAM now,
5734 * to prepare to load "initialize" uCode */
5735 iwl_write_restricted_reg(priv
, BSM_WR_CTRL_REG
,
5736 BSM_WR_CTRL_REG_BIT_START
);
5738 /* Wait for load of bootstrap uCode to finish */
5739 for (i
= 0; i
< 100; i
++) {
5740 done
= iwl_read_restricted_reg(priv
, BSM_WR_CTRL_REG
);
5741 if (!(done
& BSM_WR_CTRL_REG_BIT_START
))
5746 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i
);
5748 IWL_ERROR("BSM write did not complete!\n");
5752 /* Enable future boot loads whenever power management unit triggers it
5753 * (e.g. when powering back up after power-save shutdown) */
5754 iwl_write_restricted_reg(priv
, BSM_WR_CTRL_REG
,
5755 BSM_WR_CTRL_REG_BIT_START_EN
);
5757 iwl_release_restricted_access(priv
);
5762 static void iwl_nic_start(struct iwl_priv
*priv
)
5764 /* Remove all resets to allow NIC to operate */
5765 iwl_write32(priv
, CSR_RESET
, 0);
5769 * iwl_read_ucode - Read uCode images from disk file.
5771 * Copy into buffers for card to fetch via bus-mastering
5773 static int iwl_read_ucode(struct iwl_priv
*priv
)
5775 struct iwl_ucode
*ucode
;
5777 const struct firmware
*ucode_raw
;
5778 /* firmware file name contains uCode/driver compatibility version */
5779 const char *name
= "iwlwifi-3945" IWL3945_UCODE_API
".ucode";
5782 u32 ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
5784 /* Ask kernel firmware_class module to get the boot firmware off disk.
5785 * request_firmware() is synchronous, file is in memory on return. */
5786 rc
= request_firmware(&ucode_raw
, name
, &priv
->pci_dev
->dev
);
5788 IWL_ERROR("%s firmware file req failed: Reason %d\n", name
, rc
);
5792 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
5793 name
, ucode_raw
->size
);
5795 /* Make sure that we got at least our header! */
5796 if (ucode_raw
->size
< sizeof(*ucode
)) {
5797 IWL_ERROR("File size way too small!\n");
5802 /* Data from ucode file: header followed by uCode images */
5803 ucode
= (void *)ucode_raw
->data
;
5805 ver
= le32_to_cpu(ucode
->ver
);
5806 inst_size
= le32_to_cpu(ucode
->inst_size
);
5807 data_size
= le32_to_cpu(ucode
->data_size
);
5808 init_size
= le32_to_cpu(ucode
->init_size
);
5809 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
5810 boot_size
= le32_to_cpu(ucode
->boot_size
);
5812 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver
);
5813 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
5815 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
5817 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
5819 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
5821 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
5824 /* Verify size of file vs. image size info in file's header */
5825 if (ucode_raw
->size
< sizeof(*ucode
) +
5826 inst_size
+ data_size
+ init_size
+
5827 init_data_size
+ boot_size
) {
5829 IWL_DEBUG_INFO("uCode file size %d too small\n",
5830 (int)ucode_raw
->size
);
5835 /* Verify that uCode images will fit in card's SRAM */
5836 if (inst_size
> IWL_MAX_INST_SIZE
) {
5837 IWL_DEBUG_INFO("uCode instr len %d too large to fit in card\n",
5843 if (data_size
> IWL_MAX_DATA_SIZE
) {
5844 IWL_DEBUG_INFO("uCode data len %d too large to fit in card\n",
5849 if (init_size
> IWL_MAX_INST_SIZE
) {
5851 ("uCode init instr len %d too large to fit in card\n",
5856 if (init_data_size
> IWL_MAX_DATA_SIZE
) {
5858 ("uCode init data len %d too large to fit in card\n",
5859 (int)init_data_size
);
5863 if (boot_size
> IWL_MAX_BSM_SIZE
) {
5865 ("uCode boot instr len %d too large to fit in bsm\n",
5871 /* Allocate ucode buffers for card's bus-master loading ... */
5873 /* Runtime instructions and 2 copies of data:
5874 * 1) unmodified from disk
5875 * 2) backup cache for save/restore during power-downs */
5876 priv
->ucode_code
.len
= inst_size
;
5877 priv
->ucode_code
.v_addr
=
5878 pci_alloc_consistent(priv
->pci_dev
,
5879 priv
->ucode_code
.len
,
5880 &(priv
->ucode_code
.p_addr
));
5882 priv
->ucode_data
.len
= data_size
;
5883 priv
->ucode_data
.v_addr
=
5884 pci_alloc_consistent(priv
->pci_dev
,
5885 priv
->ucode_data
.len
,
5886 &(priv
->ucode_data
.p_addr
));
5888 priv
->ucode_data_backup
.len
= data_size
;
5889 priv
->ucode_data_backup
.v_addr
=
5890 pci_alloc_consistent(priv
->pci_dev
,
5891 priv
->ucode_data_backup
.len
,
5892 &(priv
->ucode_data_backup
.p_addr
));
5895 /* Initialization instructions and data */
5896 priv
->ucode_init
.len
= init_size
;
5897 priv
->ucode_init
.v_addr
=
5898 pci_alloc_consistent(priv
->pci_dev
,
5899 priv
->ucode_init
.len
,
5900 &(priv
->ucode_init
.p_addr
));
5902 priv
->ucode_init_data
.len
= init_data_size
;
5903 priv
->ucode_init_data
.v_addr
=
5904 pci_alloc_consistent(priv
->pci_dev
,
5905 priv
->ucode_init_data
.len
,
5906 &(priv
->ucode_init_data
.p_addr
));
5908 /* Bootstrap (instructions only, no data) */
5909 priv
->ucode_boot
.len
= boot_size
;
5910 priv
->ucode_boot
.v_addr
=
5911 pci_alloc_consistent(priv
->pci_dev
,
5912 priv
->ucode_boot
.len
,
5913 &(priv
->ucode_boot
.p_addr
));
5915 if (!priv
->ucode_code
.v_addr
|| !priv
->ucode_data
.v_addr
||
5916 !priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
||
5917 !priv
->ucode_boot
.v_addr
|| !priv
->ucode_data_backup
.v_addr
)
5920 /* Copy images into buffers for card's bus-master reads ... */
5922 /* Runtime instructions (first block of data in file) */
5923 src
= &ucode
->data
[0];
5924 len
= priv
->ucode_code
.len
;
5925 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %d\n",
5927 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
5928 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
5929 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
5931 /* Runtime data (2nd block)
5932 * NOTE: Copy into backup buffer will be done in iwl_up() */
5933 src
= &ucode
->data
[inst_size
];
5934 len
= priv
->ucode_data
.len
;
5935 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %d\n",
5937 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
5938 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
5940 /* Initialization instructions (3rd block) */
5942 src
= &ucode
->data
[inst_size
+ data_size
];
5943 len
= priv
->ucode_init
.len
;
5944 IWL_DEBUG_INFO("Copying (but not loading) init instr len %d\n",
5946 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
5949 /* Initialization data (4th block) */
5950 if (init_data_size
) {
5951 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
5952 len
= priv
->ucode_init_data
.len
;
5953 IWL_DEBUG_INFO("Copying (but not loading) init data len %d\n",
5955 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
5958 /* Bootstrap instructions (5th block) */
5959 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
5960 len
= priv
->ucode_boot
.len
;
5961 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %d\n",
5963 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
5965 /* We have our copies now, allow OS release its copies */
5966 release_firmware(ucode_raw
);
5970 IWL_ERROR("failed to allocate pci memory\n");
5972 iwl_dealloc_ucode_pci(priv
);
5975 release_firmware(ucode_raw
);
5983 * iwl_set_ucode_ptrs - Set uCode address location
5985 * Tell initialization uCode where to find runtime uCode.
5987 * BSM registers initially contain pointers to initialization uCode.
5988 * We need to replace them to load runtime uCode inst and data,
5989 * and to save runtime data when powering down.
5991 static int iwl_set_ucode_ptrs(struct iwl_priv
*priv
)
5996 unsigned long flags
;
5998 /* bits 31:0 for 3945 */
5999 pinst
= priv
->ucode_code
.p_addr
;
6000 pdata
= priv
->ucode_data_backup
.p_addr
;
6002 spin_lock_irqsave(&priv
->lock
, flags
);
6003 rc
= iwl_grab_restricted_access(priv
);
6005 spin_unlock_irqrestore(&priv
->lock
, flags
);
6009 /* Tell bootstrap uCode where to find image to load */
6010 iwl_write_restricted_reg(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
6011 iwl_write_restricted_reg(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
6012 iwl_write_restricted_reg(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
,
6013 priv
->ucode_data
.len
);
6015 /* Inst bytecount must be last to set up, bit 31 signals uCode
6016 * that all new ptr/size info is in place */
6017 iwl_write_restricted_reg(priv
, BSM_DRAM_INST_BYTECOUNT_REG
,
6018 priv
->ucode_code
.len
| BSM_DRAM_INST_LOAD
);
6020 iwl_release_restricted_access(priv
);
6022 spin_unlock_irqrestore(&priv
->lock
, flags
);
6024 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
6030 * iwl_init_alive_start - Called after REPLY_ALIVE notification receieved
6032 * Called after REPLY_ALIVE notification received from "initialize" uCode.
6034 * The 4965 "initialize" ALIVE reply contains calibration data for:
6035 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
6036 * (3945 does not contain this data).
6038 * Tell "initialize" uCode to go ahead and load the runtime uCode.
6040 static void iwl_init_alive_start(struct iwl_priv
*priv
)
6042 /* Check alive response for "valid" sign from uCode */
6043 if (priv
->card_alive_init
.is_valid
!= UCODE_VALID_OK
) {
6044 /* We had an error bringing up the hardware, so take it
6045 * all the way back down so we can try again */
6046 IWL_DEBUG_INFO("Initialize Alive failed.\n");
6050 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
6051 * This is a paranoid check, because we would not have gotten the
6052 * "initialize" alive if code weren't properly loaded. */
6053 if (iwl_verify_ucode(priv
)) {
6054 /* Runtime instruction load was bad;
6055 * take it all the way back down so we can try again */
6056 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
6060 /* Send pointers to protocol/runtime uCode image ... init code will
6061 * load and launch runtime uCode, which will send us another "Alive"
6063 IWL_DEBUG_INFO("Initialization Alive received.\n");
6064 if (iwl_set_ucode_ptrs(priv
)) {
6065 /* Runtime instruction load won't happen;
6066 * take it all the way back down so we can try again */
6067 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
6073 queue_work(priv
->workqueue
, &priv
->restart
);
6078 * iwl_alive_start - called after REPLY_ALIVE notification received
6079 * from protocol/runtime uCode (initialization uCode's
6080 * Alive gets handled by iwl_init_alive_start()).
6082 static void iwl_alive_start(struct iwl_priv
*priv
)
6085 int thermal_spin
= 0;
6088 IWL_DEBUG_INFO("Runtime Alive received.\n");
6090 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
6091 /* We had an error bringing up the hardware, so take it
6092 * all the way back down so we can try again */
6093 IWL_DEBUG_INFO("Alive failed.\n");
6097 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
6098 * This is a paranoid check, because we would not have gotten the
6099 * "runtime" alive if code weren't properly loaded. */
6100 if (iwl_verify_ucode(priv
)) {
6101 /* Runtime instruction load was bad;
6102 * take it all the way back down so we can try again */
6103 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
6107 iwl_clear_stations_table(priv
);
6109 rc
= iwl_grab_restricted_access(priv
);
6111 IWL_WARNING("Can not read rfkill status from adapter\n");
6115 rfkill
= iwl_read_restricted_reg(priv
, APMG_RFKILL_REG
);
6116 IWL_DEBUG_INFO("RFKILL status: 0x%x\n", rfkill
);
6117 iwl_release_restricted_access(priv
);
6120 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
6121 /* if rfkill is not on, then wait for thermal
6122 * sensor in adapter to kick in */
6123 while (iwl_hw_get_temperature(priv
) == 0) {
6129 IWL_DEBUG_INFO("Thermal calibration took %dus\n",
6132 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
6134 /* After the ALIVE response, we can process host commands */
6135 set_bit(STATUS_ALIVE
, &priv
->status
);
6137 /* Clear out the uCode error bit if it is set */
6138 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
6140 rc
= iwl_init_channel_map(priv
);
6142 IWL_ERROR("initializing regulatory failed: %d\n", rc
);
6146 iwl_init_geos(priv
);
6148 if (iwl_is_rfkill(priv
))
6151 if (!priv
->mac80211_registered
) {
6152 /* Unlock so any user space entry points can call back into
6153 * the driver without a deadlock... */
6154 mutex_unlock(&priv
->mutex
);
6155 iwl_rate_control_register(priv
->hw
);
6156 rc
= ieee80211_register_hw(priv
->hw
);
6157 priv
->hw
->conf
.beacon_int
= 100;
6158 mutex_lock(&priv
->mutex
);
6161 IWL_ERROR("Failed to register network "
6162 "device (error %d)\n", rc
);
6166 priv
->mac80211_registered
= 1;
6168 iwl_reset_channel_flag(priv
);
6170 ieee80211_start_queues(priv
->hw
);
6172 priv
->active_rate
= priv
->rates_mask
;
6173 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
6175 iwl_send_power_mode(priv
, IWL_POWER_LEVEL(priv
->power_mode
));
6177 if (iwl_is_associated(priv
)) {
6178 struct iwl_rxon_cmd
*active_rxon
=
6179 (struct iwl_rxon_cmd
*)(&priv
->active_rxon
);
6181 memcpy(&priv
->staging_rxon
, &priv
->active_rxon
,
6182 sizeof(priv
->staging_rxon
));
6183 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6185 /* Initialize our rx_config data */
6186 iwl_connection_init_rx_config(priv
);
6187 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
6190 /* Configure BT coexistence */
6191 iwl_send_bt_config(priv
);
6193 /* Configure the adapter for unassociated operation */
6194 iwl_commit_rxon(priv
);
6196 /* At this point, the NIC is initialized and operational */
6197 priv
->notif_missed_beacons
= 0;
6198 set_bit(STATUS_READY
, &priv
->status
);
6200 iwl3945_reg_txpower_periodic(priv
);
6202 IWL_DEBUG_INFO("ALIVE processing complete.\n");
6204 if (priv
->error_recovering
)
6205 iwl_error_recovery(priv
);
6210 queue_work(priv
->workqueue
, &priv
->restart
);
6213 static void iwl_cancel_deferred_work(struct iwl_priv
*priv
);
6215 static void __iwl_down(struct iwl_priv
*priv
)
6217 unsigned long flags
;
6218 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
6219 struct ieee80211_conf
*conf
= NULL
;
6221 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
6223 conf
= ieee80211_get_hw_conf(priv
->hw
);
6226 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
6228 iwl_clear_stations_table(priv
);
6230 /* Unblock any waiting calls */
6231 wake_up_interruptible_all(&priv
->wait_command_queue
);
6233 iwl_cancel_deferred_work(priv
);
6235 /* Wipe out the EXIT_PENDING status bit if we are not actually
6236 * exiting the module */
6238 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
6240 /* stop and reset the on-board processor */
6241 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
6243 /* tell the device to stop sending interrupts */
6244 iwl_disable_interrupts(priv
);
6246 if (priv
->mac80211_registered
)
6247 ieee80211_stop_queues(priv
->hw
);
6249 /* If we have not previously called iwl_init() then
6250 * clear all bits but the RF Kill and SUSPEND bits and return */
6251 if (!iwl_is_init(priv
)) {
6252 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
6254 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
6256 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
6261 /* ...otherwise clear out all the status bits but the RF Kill and
6262 * SUSPEND bits and continue taking the NIC down. */
6263 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
6265 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
6267 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
6269 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
6272 spin_lock_irqsave(&priv
->lock
, flags
);
6273 iwl_clear_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
6274 spin_unlock_irqrestore(&priv
->lock
, flags
);
6276 iwl_hw_txq_ctx_stop(priv
);
6277 iwl_hw_rxq_stop(priv
);
6279 spin_lock_irqsave(&priv
->lock
, flags
);
6280 if (!iwl_grab_restricted_access(priv
)) {
6281 iwl_write_restricted_reg(priv
, APMG_CLK_DIS_REG
,
6282 APMG_CLK_VAL_DMA_CLK_RQT
);
6283 iwl_release_restricted_access(priv
);
6285 spin_unlock_irqrestore(&priv
->lock
, flags
);
6289 iwl_hw_nic_stop_master(priv
);
6290 iwl_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_SW_RESET
);
6291 iwl_hw_nic_reset(priv
);
6294 memset(&priv
->card_alive
, 0, sizeof(struct iwl_alive_resp
));
6296 if (priv
->ibss_beacon
)
6297 dev_kfree_skb(priv
->ibss_beacon
);
6298 priv
->ibss_beacon
= NULL
;
6300 /* clear out any free frames */
6301 iwl_clear_free_frames(priv
);
6304 static void iwl_down(struct iwl_priv
*priv
)
6306 mutex_lock(&priv
->mutex
);
6308 mutex_unlock(&priv
->mutex
);
6311 #define MAX_HW_RESTARTS 5
6313 static int __iwl_up(struct iwl_priv
*priv
)
6315 DECLARE_MAC_BUF(mac
);
6318 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
6319 IWL_WARNING("Exit pending; will not bring the NIC up\n");
6323 if (test_bit(STATUS_RF_KILL_SW
, &priv
->status
)) {
6324 IWL_WARNING("Radio disabled by SW RF kill (module "
6329 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
6331 rc
= iwl_hw_nic_init(priv
);
6333 IWL_ERROR("Unable to int nic\n");
6337 /* make sure rfkill handshake bits are cleared */
6338 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
6339 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
6340 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
6342 /* clear (again), then enable host interrupts */
6343 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
6344 iwl_enable_interrupts(priv
);
6346 /* really make sure rfkill handshake bits are cleared */
6347 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
6348 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
6350 /* Copy original ucode data image from disk into backup cache.
6351 * This will be used to initialize the on-board processor's
6352 * data SRAM for a clean start when the runtime program first loads. */
6353 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
6354 priv
->ucode_data
.len
);
6356 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
6358 iwl_clear_stations_table(priv
);
6360 /* load bootstrap state machine,
6361 * load bootstrap program into processor's memory,
6362 * prepare to load the "initialize" uCode */
6363 rc
= iwl_load_bsm(priv
);
6366 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", rc
);
6370 /* start card; "initialize" will load runtime ucode */
6371 iwl_nic_start(priv
);
6373 /* MAC Address location in EEPROM same for 3945/4965 */
6374 get_eeprom_mac(priv
, priv
->mac_addr
);
6375 IWL_DEBUG_INFO("MAC address: %s\n",
6376 print_mac(mac
, priv
->mac_addr
));
6378 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
6380 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
6385 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
6388 /* tried to restart and config the device for as long as our
6389 * patience could withstand */
6390 IWL_ERROR("Unable to initialize device after %d attempts.\n", i
);
6395 /*****************************************************************************
6397 * Workqueue callbacks
6399 *****************************************************************************/
6401 static void iwl_bg_init_alive_start(struct work_struct
*data
)
6403 struct iwl_priv
*priv
=
6404 container_of(data
, struct iwl_priv
, init_alive_start
.work
);
6406 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6409 mutex_lock(&priv
->mutex
);
6410 iwl_init_alive_start(priv
);
6411 mutex_unlock(&priv
->mutex
);
6414 static void iwl_bg_alive_start(struct work_struct
*data
)
6416 struct iwl_priv
*priv
=
6417 container_of(data
, struct iwl_priv
, alive_start
.work
);
6419 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6422 mutex_lock(&priv
->mutex
);
6423 iwl_alive_start(priv
);
6424 mutex_unlock(&priv
->mutex
);
6427 static void iwl_bg_rf_kill(struct work_struct
*work
)
6429 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, rf_kill
);
6431 wake_up_interruptible(&priv
->wait_command_queue
);
6433 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6436 mutex_lock(&priv
->mutex
);
6438 if (!iwl_is_rfkill(priv
)) {
6439 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
,
6440 "HW and/or SW RF Kill no longer active, restarting "
6442 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6443 queue_work(priv
->workqueue
, &priv
->restart
);
6446 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
6447 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
6448 "disabled by SW switch\n");
6450 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
6451 "Kill switch must be turned off for "
6452 "wireless networking to work.\n");
6454 mutex_unlock(&priv
->mutex
);
6457 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
6459 static void iwl_bg_scan_check(struct work_struct
*data
)
6461 struct iwl_priv
*priv
=
6462 container_of(data
, struct iwl_priv
, scan_check
.work
);
6464 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6467 mutex_lock(&priv
->mutex
);
6468 if (test_bit(STATUS_SCANNING
, &priv
->status
) ||
6469 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
6470 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
,
6471 "Scan completion watchdog resetting adapter (%dms)\n",
6472 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG
));
6473 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6474 queue_work(priv
->workqueue
, &priv
->restart
);
6476 mutex_unlock(&priv
->mutex
);
6479 static void iwl_bg_request_scan(struct work_struct
*data
)
6481 struct iwl_priv
*priv
=
6482 container_of(data
, struct iwl_priv
, request_scan
);
6483 struct iwl_host_cmd cmd
= {
6484 .id
= REPLY_SCAN_CMD
,
6485 .len
= sizeof(struct iwl_scan_cmd
),
6486 .meta
.flags
= CMD_SIZE_HUGE
,
6489 struct iwl_scan_cmd
*scan
;
6490 struct ieee80211_conf
*conf
= NULL
;
6494 conf
= ieee80211_get_hw_conf(priv
->hw
);
6496 mutex_lock(&priv
->mutex
);
6498 if (!iwl_is_ready(priv
)) {
6499 IWL_WARNING("request scan called when driver not ready.\n");
6503 /* Make sure the scan wasn't cancelled before this queued work
6504 * was given the chance to run... */
6505 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
6508 /* This should never be called or scheduled if there is currently
6509 * a scan active in the hardware. */
6510 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
6511 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
6512 "Ignoring second request.\n");
6517 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
6518 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
6522 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
6523 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
6527 if (iwl_is_rfkill(priv
)) {
6528 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
6532 if (!test_bit(STATUS_READY
, &priv
->status
)) {
6533 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
6537 if (!priv
->scan_bands
) {
6538 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
6543 priv
->scan
= kmalloc(sizeof(struct iwl_scan_cmd
) +
6544 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
6551 memset(scan
, 0, sizeof(struct iwl_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
6553 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
6554 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
6556 if (iwl_is_associated(priv
)) {
6559 u32 suspend_time
= 100;
6560 u32 scan_suspend_time
= 100;
6561 unsigned long flags
;
6563 IWL_DEBUG_INFO("Scanning while associated...\n");
6565 spin_lock_irqsave(&priv
->lock
, flags
);
6566 interval
= priv
->beacon_int
;
6567 spin_unlock_irqrestore(&priv
->lock
, flags
);
6569 scan
->suspend_time
= 0;
6570 scan
->max_out_time
= cpu_to_le32(600 * 1024);
6572 interval
= suspend_time
;
6574 * suspend time format:
6575 * 0-19: beacon interval in usec (time before exec.)
6577 * 24-31: number of beacons (suspend between channels)
6580 extra
= (suspend_time
/ interval
) << 24;
6581 scan_suspend_time
= 0xFF0FFFFF &
6582 (extra
| ((suspend_time
% interval
) * 1024));
6584 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
6585 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
6586 scan_suspend_time
, interval
);
6589 /* We should add the ability for user to lock to PASSIVE ONLY */
6590 if (priv
->one_direct_scan
) {
6592 ("Kicking off one direct scan for '%s'\n",
6593 iwl_escape_essid(priv
->direct_ssid
,
6594 priv
->direct_ssid_len
));
6595 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
6596 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
6597 memcpy(scan
->direct_scan
[0].ssid
,
6598 priv
->direct_ssid
, priv
->direct_ssid_len
);
6600 } else if (!iwl_is_associated(priv
)) {
6601 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
6602 scan
->direct_scan
[0].len
= priv
->essid_len
;
6603 memcpy(scan
->direct_scan
[0].ssid
, priv
->essid
, priv
->essid_len
);
6608 /* We don't build a direct scan probe request; the uCode will do
6609 * that based on the direct_mask added to each channel entry */
6610 scan
->tx_cmd
.len
= cpu_to_le16(
6611 iwl_fill_probe_req(priv
, (struct ieee80211_mgmt
*)scan
->data
,
6612 IWL_MAX_SCAN_SIZE
- sizeof(scan
), 0));
6613 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
6614 scan
->tx_cmd
.sta_id
= priv
->hw_setting
.bcast_sta_id
;
6615 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
6617 /* flags + rate selection */
6619 switch (priv
->scan_bands
) {
6621 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
6622 scan
->tx_cmd
.rate
= IWL_RATE_1M_PLCP
;
6623 scan
->good_CRC_th
= 0;
6624 phymode
= MODE_IEEE80211G
;
6628 scan
->tx_cmd
.rate
= IWL_RATE_6M_PLCP
;
6629 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
6630 phymode
= MODE_IEEE80211A
;
6634 IWL_WARNING("Invalid scan band count\n");
6638 /* select Rx antennas */
6639 scan
->flags
|= iwl3945_get_antenna_flags(priv
);
6641 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
)
6642 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
6646 ("Initiating direct scan for %s.\n",
6647 iwl_escape_essid(priv
->essid
, priv
->essid_len
));
6649 IWL_DEBUG_SCAN("Initiating indirect scan.\n");
6651 scan
->channel_count
=
6652 iwl_get_channels_for_scan(
6653 priv
, phymode
, 1, /* active */
6655 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
6657 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
6658 scan
->channel_count
* sizeof(struct iwl_scan_channel
);
6660 scan
->len
= cpu_to_le16(cmd
.len
);
6662 set_bit(STATUS_SCAN_HW
, &priv
->status
);
6663 rc
= iwl_send_cmd_sync(priv
, &cmd
);
6667 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
6668 IWL_SCAN_CHECK_WATCHDOG
);
6670 mutex_unlock(&priv
->mutex
);
6674 /* inform mac80211 sacn aborted */
6675 queue_work(priv
->workqueue
, &priv
->scan_completed
);
6676 mutex_unlock(&priv
->mutex
);
6679 static void iwl_bg_up(struct work_struct
*data
)
6681 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, up
);
6683 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6686 mutex_lock(&priv
->mutex
);
6688 mutex_unlock(&priv
->mutex
);
6691 static void iwl_bg_restart(struct work_struct
*data
)
6693 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
6695 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6699 queue_work(priv
->workqueue
, &priv
->up
);
6702 static void iwl_bg_rx_replenish(struct work_struct
*data
)
6704 struct iwl_priv
*priv
=
6705 container_of(data
, struct iwl_priv
, rx_replenish
);
6707 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6710 mutex_lock(&priv
->mutex
);
6711 iwl_rx_replenish(priv
);
6712 mutex_unlock(&priv
->mutex
);
6715 static void iwl_bg_post_associate(struct work_struct
*data
)
6717 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
,
6718 post_associate
.work
);
6721 struct ieee80211_conf
*conf
= NULL
;
6722 DECLARE_MAC_BUF(mac
);
6724 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
6725 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__
);
6730 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
6732 print_mac(mac
, priv
->active_rxon
.bssid_addr
));
6734 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6737 mutex_lock(&priv
->mutex
);
6739 conf
= ieee80211_get_hw_conf(priv
->hw
);
6741 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6742 iwl_commit_rxon(priv
);
6744 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl_rxon_time_cmd
));
6745 iwl_setup_rxon_timing(priv
);
6746 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
6747 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
6749 IWL_WARNING("REPLY_RXON_TIMING failed - "
6750 "Attempting to continue.\n");
6752 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
6754 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6756 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
6757 priv
->assoc_id
, priv
->beacon_int
);
6759 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6760 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
6762 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6764 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6765 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6766 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
6768 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6770 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6771 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6775 iwl_commit_rxon(priv
);
6777 switch (priv
->iw_mode
) {
6778 case IEEE80211_IF_TYPE_STA
:
6779 iwl_rate_scale_init(priv
->hw
, IWL_AP_ID
);
6782 case IEEE80211_IF_TYPE_IBSS
:
6784 /* clear out the station table */
6785 iwl_clear_stations_table(priv
);
6787 iwl_add_station(priv
, BROADCAST_ADDR
, 0, 0);
6788 iwl_add_station(priv
, priv
->bssid
, 0, 0);
6789 iwl3945_sync_sta(priv
, IWL_STA_ID
,
6790 (priv
->phymode
== MODE_IEEE80211A
)?
6791 IWL_RATE_6M_PLCP
: IWL_RATE_1M_PLCP
,
6793 iwl_rate_scale_init(priv
->hw
, IWL_STA_ID
);
6794 iwl_send_beacon_cmd(priv
);
6799 IWL_ERROR("%s Should not be called in %d mode\n",
6800 __FUNCTION__
, priv
->iw_mode
);
6804 iwl_sequence_reset(priv
);
6806 #ifdef CONFIG_IWLWIFI_QOS
6807 iwl_activate_qos(priv
, 0);
6808 #endif /* CONFIG_IWLWIFI_QOS */
6809 mutex_unlock(&priv
->mutex
);
6812 static void iwl_bg_abort_scan(struct work_struct
*work
)
6814 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
,
6817 if (!iwl_is_ready(priv
))
6820 mutex_lock(&priv
->mutex
);
6822 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
6823 iwl_send_scan_abort(priv
);
6825 mutex_unlock(&priv
->mutex
);
6828 static void iwl_bg_scan_completed(struct work_struct
*work
)
6830 struct iwl_priv
*priv
=
6831 container_of(work
, struct iwl_priv
, scan_completed
);
6833 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
, "SCAN complete scan\n");
6835 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6838 ieee80211_scan_completed(priv
->hw
);
6840 /* Since setting the TXPOWER may have been deferred while
6841 * performing the scan, fire one off */
6842 mutex_lock(&priv
->mutex
);
6843 iwl_hw_reg_send_txpower(priv
);
6844 mutex_unlock(&priv
->mutex
);
6847 /*****************************************************************************
6849 * mac80211 entry point functions
6851 *****************************************************************************/
6853 static int iwl_mac_start(struct ieee80211_hw
*hw
)
6855 struct iwl_priv
*priv
= hw
->priv
;
6857 IWL_DEBUG_MAC80211("enter\n");
6859 /* we should be verifying the device is ready to be opened */
6860 mutex_lock(&priv
->mutex
);
6864 if (!iwl_is_rfkill(priv
))
6865 ieee80211_start_queues(priv
->hw
);
6867 mutex_unlock(&priv
->mutex
);
6868 IWL_DEBUG_MAC80211("leave\n");
6872 static void iwl_mac_stop(struct ieee80211_hw
*hw
)
6874 struct iwl_priv
*priv
= hw
->priv
;
6876 IWL_DEBUG_MAC80211("enter\n");
6878 /*netif_stop_queue(dev); */
6879 flush_workqueue(priv
->workqueue
);
6880 IWL_DEBUG_MAC80211("leave\n");
6883 static int iwl_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
6884 struct ieee80211_tx_control
*ctl
)
6886 struct iwl_priv
*priv
= hw
->priv
;
6888 IWL_DEBUG_MAC80211("enter\n");
6890 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
) {
6891 IWL_DEBUG_MAC80211("leave - monitor\n");
6895 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
6898 if (iwl_tx_skb(priv
, skb
, ctl
))
6899 dev_kfree_skb_any(skb
);
6901 IWL_DEBUG_MAC80211("leave\n");
6905 static int iwl_mac_add_interface(struct ieee80211_hw
*hw
,
6906 struct ieee80211_if_init_conf
*conf
)
6908 struct iwl_priv
*priv
= hw
->priv
;
6909 unsigned long flags
;
6910 DECLARE_MAC_BUF(mac
);
6912 IWL_DEBUG_MAC80211("enter: id %d, type %d\n", conf
->if_id
, conf
->type
);
6914 IWL_DEBUG_MAC80211("enter: MAC %s\n",
6915 print_mac(mac
, conf
->mac_addr
));
6917 if (priv
->interface_id
) {
6918 IWL_DEBUG_MAC80211("leave - interface_id != 0\n");
6922 spin_lock_irqsave(&priv
->lock
, flags
);
6923 priv
->interface_id
= conf
->if_id
;
6925 spin_unlock_irqrestore(&priv
->lock
, flags
);
6927 mutex_lock(&priv
->mutex
);
6928 iwl_set_mode(priv
, conf
->type
);
6930 IWL_DEBUG_MAC80211("leave\n");
6931 mutex_unlock(&priv
->mutex
);
6937 * iwl_mac_config - mac80211 config callback
6939 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
6940 * be set inappropriately and the driver currently sets the hardware up to
6941 * use it whenever needed.
6943 static int iwl_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
6945 struct iwl_priv
*priv
= hw
->priv
;
6946 const struct iwl_channel_info
*ch_info
;
6947 unsigned long flags
;
6949 mutex_lock(&priv
->mutex
);
6950 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
);
6952 if (!iwl_is_ready(priv
)) {
6953 IWL_DEBUG_MAC80211("leave - not ready\n");
6954 mutex_unlock(&priv
->mutex
);
6958 /* TODO: Figure out how to get ieee80211_local->sta_scanning w/ only
6959 * what is exposed through include/ declrations */
6960 if (unlikely(!iwl_param_disable_hw_scan
&&
6961 test_bit(STATUS_SCANNING
, &priv
->status
))) {
6962 IWL_DEBUG_MAC80211("leave - scanning\n");
6963 mutex_unlock(&priv
->mutex
);
6967 spin_lock_irqsave(&priv
->lock
, flags
);
6969 ch_info
= iwl_get_channel_info(priv
, conf
->phymode
, conf
->channel
);
6970 if (!is_channel_valid(ch_info
)) {
6971 IWL_DEBUG_SCAN("Channel %d [%d] is INVALID for this SKU.\n",
6972 conf
->channel
, conf
->phymode
);
6973 IWL_DEBUG_MAC80211("leave - invalid channel\n");
6974 spin_unlock_irqrestore(&priv
->lock
, flags
);
6975 mutex_unlock(&priv
->mutex
);
6979 iwl_set_rxon_channel(priv
, conf
->phymode
, conf
->channel
);
6981 iwl_set_flags_for_phymode(priv
, conf
->phymode
);
6983 /* The list of supported rates and rate mask can be different
6984 * for each phymode; since the phymode may have changed, reset
6985 * the rate mask to what mac80211 lists */
6988 spin_unlock_irqrestore(&priv
->lock
, flags
);
6990 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6991 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
6992 iwl_hw_channel_switch(priv
, conf
->channel
);
6993 mutex_unlock(&priv
->mutex
);
6998 iwl_radio_kill_sw(priv
, !conf
->radio_enabled
);
7000 if (!conf
->radio_enabled
) {
7001 IWL_DEBUG_MAC80211("leave - radio disabled\n");
7002 mutex_unlock(&priv
->mutex
);
7006 if (iwl_is_rfkill(priv
)) {
7007 IWL_DEBUG_MAC80211("leave - RF kill\n");
7008 mutex_unlock(&priv
->mutex
);
7014 if (memcmp(&priv
->active_rxon
,
7015 &priv
->staging_rxon
, sizeof(priv
->staging_rxon
)))
7016 iwl_commit_rxon(priv
);
7018 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
7020 IWL_DEBUG_MAC80211("leave\n");
7022 mutex_unlock(&priv
->mutex
);
7027 static void iwl_config_ap(struct iwl_priv
*priv
)
7031 if (priv
->status
& STATUS_EXIT_PENDING
)
7034 /* The following should be done only at AP bring up */
7035 if ((priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) == 0) {
7037 /* RXON - unassoc (to set timing command) */
7038 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7039 iwl_commit_rxon(priv
);
7042 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl_rxon_time_cmd
));
7043 iwl_setup_rxon_timing(priv
);
7044 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
7045 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
7047 IWL_WARNING("REPLY_RXON_TIMING failed - "
7048 "Attempting to continue.\n");
7050 /* FIXME: what should be the assoc_id for AP? */
7051 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
7052 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
7053 priv
->staging_rxon
.flags
|=
7054 RXON_FLG_SHORT_PREAMBLE_MSK
;
7056 priv
->staging_rxon
.flags
&=
7057 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
7059 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
7060 if (priv
->assoc_capability
&
7061 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
7062 priv
->staging_rxon
.flags
|=
7063 RXON_FLG_SHORT_SLOT_MSK
;
7065 priv
->staging_rxon
.flags
&=
7066 ~RXON_FLG_SHORT_SLOT_MSK
;
7068 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
7069 priv
->staging_rxon
.flags
&=
7070 ~RXON_FLG_SHORT_SLOT_MSK
;
7072 /* restore RXON assoc */
7073 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
7074 iwl_commit_rxon(priv
);
7075 iwl_add_station(priv
, BROADCAST_ADDR
, 0, 0);
7077 iwl_send_beacon_cmd(priv
);
7079 /* FIXME - we need to add code here to detect a totally new
7080 * configuration, reset the AP, unassoc, rxon timing, assoc,
7081 * clear sta table, add BCAST sta... */
7084 static int iwl_mac_config_interface(struct ieee80211_hw
*hw
, int if_id
,
7085 struct ieee80211_if_conf
*conf
)
7087 struct iwl_priv
*priv
= hw
->priv
;
7088 DECLARE_MAC_BUF(mac
);
7089 unsigned long flags
;
7095 /* XXX: this MUST use conf->mac_addr */
7097 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
7098 (!conf
->beacon
|| !conf
->ssid_len
)) {
7100 ("Leaving in AP mode because HostAPD is not ready.\n");
7104 mutex_lock(&priv
->mutex
);
7106 IWL_DEBUG_MAC80211("enter: interface id %d\n", if_id
);
7108 IWL_DEBUG_MAC80211("bssid: %s\n",
7109 print_mac(mac
, conf
->bssid
));
7112 * very dubious code was here; the probe filtering flag is never set:
7114 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
7115 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
7117 if (unlikely(test_bit(STATUS_SCANNING
, &priv
->status
))) {
7118 IWL_DEBUG_MAC80211("leave - scanning\n");
7119 mutex_unlock(&priv
->mutex
);
7123 if (priv
->interface_id
!= if_id
) {
7124 IWL_DEBUG_MAC80211("leave - interface_id != if_id\n");
7125 mutex_unlock(&priv
->mutex
);
7129 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
7131 conf
->bssid
= priv
->mac_addr
;
7132 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
7133 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
7134 print_mac(mac
, conf
->bssid
));
7136 if (priv
->ibss_beacon
)
7137 dev_kfree_skb(priv
->ibss_beacon
);
7139 priv
->ibss_beacon
= conf
->beacon
;
7142 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
7143 !is_multicast_ether_addr(conf
->bssid
)) {
7144 /* If there is currently a HW scan going on in the background
7145 * then we need to cancel it else the RXON below will fail. */
7146 if (iwl_scan_cancel_timeout(priv
, 100)) {
7147 IWL_WARNING("Aborted scan still in progress "
7149 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
7150 mutex_unlock(&priv
->mutex
);
7153 memcpy(priv
->staging_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
7155 /* TODO: Audit driver for usage of these members and see
7156 * if mac80211 deprecates them (priv->bssid looks like it
7157 * shouldn't be there, but I haven't scanned the IBSS code
7158 * to verify) - jpk */
7159 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
7161 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
7162 iwl_config_ap(priv
);
7164 priv
->staging_rxon
.filter_flags
|=
7165 RXON_FILTER_ASSOC_MSK
;
7166 rc
= iwl_commit_rxon(priv
);
7167 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && rc
)
7168 iwl_add_station(priv
,
7169 priv
->active_rxon
.bssid_addr
, 1, 0);
7173 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7174 iwl_commit_rxon(priv
);
7177 spin_lock_irqsave(&priv
->lock
, flags
);
7178 if (!conf
->ssid_len
)
7179 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
7181 memcpy(priv
->essid
, conf
->ssid
, conf
->ssid_len
);
7183 priv
->essid_len
= conf
->ssid_len
;
7184 spin_unlock_irqrestore(&priv
->lock
, flags
);
7186 IWL_DEBUG_MAC80211("leave\n");
7187 mutex_unlock(&priv
->mutex
);
7192 static void iwl_configure_filter(struct ieee80211_hw
*hw
,
7193 unsigned int changed_flags
,
7194 unsigned int *total_flags
,
7195 int mc_count
, struct dev_addr_list
*mc_list
)
7199 * see also iwl_connection_init_rx_config
7204 static void iwl_mac_remove_interface(struct ieee80211_hw
*hw
,
7205 struct ieee80211_if_init_conf
*conf
)
7207 struct iwl_priv
*priv
= hw
->priv
;
7209 IWL_DEBUG_MAC80211("enter\n");
7211 mutex_lock(&priv
->mutex
);
7212 if (priv
->interface_id
== conf
->if_id
) {
7213 priv
->interface_id
= 0;
7214 memset(priv
->bssid
, 0, ETH_ALEN
);
7215 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
7216 priv
->essid_len
= 0;
7218 mutex_unlock(&priv
->mutex
);
7220 IWL_DEBUG_MAC80211("leave\n");
7224 #define IWL_DELAY_NEXT_SCAN (HZ*2)
7225 static int iwl_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
7228 unsigned long flags
;
7229 struct iwl_priv
*priv
= hw
->priv
;
7231 IWL_DEBUG_MAC80211("enter\n");
7233 spin_lock_irqsave(&priv
->lock
, flags
);
7235 if (!iwl_is_ready_rf(priv
)) {
7237 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
7241 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) { /* APs don't scan */
7243 IWL_ERROR("ERROR: APs don't scan\n");
7247 /* if we just finished scan ask for delay */
7248 if (priv
->last_scan_jiffies
&&
7249 time_after(priv
->last_scan_jiffies
+ IWL_DELAY_NEXT_SCAN
,
7255 IWL_DEBUG_SCAN("direct scan for "
7257 iwl_escape_essid(ssid
, len
), (int)len
);
7259 priv
->one_direct_scan
= 1;
7260 priv
->direct_ssid_len
= (u8
)
7261 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
7262 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
7265 rc
= iwl_scan_initiate(priv
);
7267 IWL_DEBUG_MAC80211("leave\n");
7270 spin_unlock_irqrestore(&priv
->lock
, flags
);
7275 static int iwl_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
7276 const u8
*local_addr
, const u8
*addr
,
7277 struct ieee80211_key_conf
*key
)
7279 struct iwl_priv
*priv
= hw
->priv
;
7283 IWL_DEBUG_MAC80211("enter\n");
7285 if (!iwl_param_hwcrypto
) {
7286 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
7290 if (is_zero_ether_addr(addr
))
7291 /* only support pairwise keys */
7294 sta_id
= iwl_hw_find_station(priv
, addr
);
7295 if (sta_id
== IWL_INVALID_STATION
) {
7296 DECLARE_MAC_BUF(mac
);
7298 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
7299 print_mac(mac
, addr
));
7303 mutex_lock(&priv
->mutex
);
7307 rc
= iwl_update_sta_key_info(priv
, key
, sta_id
);
7309 iwl_set_rxon_hwcrypto(priv
, 1);
7310 iwl_commit_rxon(priv
);
7311 key
->hw_key_idx
= sta_id
;
7312 IWL_DEBUG_MAC80211("set_key success, using hwcrypto\n");
7313 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
7317 rc
= iwl_clear_sta_key_info(priv
, sta_id
);
7319 iwl_set_rxon_hwcrypto(priv
, 0);
7320 iwl_commit_rxon(priv
);
7321 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
7328 IWL_DEBUG_MAC80211("leave\n");
7329 mutex_unlock(&priv
->mutex
);
7334 static int iwl_mac_conf_tx(struct ieee80211_hw
*hw
, int queue
,
7335 const struct ieee80211_tx_queue_params
*params
)
7337 struct iwl_priv
*priv
= hw
->priv
;
7338 #ifdef CONFIG_IWLWIFI_QOS
7339 unsigned long flags
;
7341 #endif /* CONFIG_IWL_QOS */
7343 IWL_DEBUG_MAC80211("enter\n");
7345 if (!iwl_is_ready_rf(priv
)) {
7346 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7350 if (queue
>= AC_NUM
) {
7351 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
7355 #ifdef CONFIG_IWLWIFI_QOS
7356 if (!priv
->qos_data
.qos_enable
) {
7357 priv
->qos_data
.qos_active
= 0;
7358 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
7361 q
= AC_NUM
- 1 - queue
;
7363 spin_lock_irqsave(&priv
->lock
, flags
);
7365 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
7366 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
7367 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
7368 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
7369 cpu_to_le16((params
->burst_time
* 100));
7371 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
7372 priv
->qos_data
.qos_active
= 1;
7374 spin_unlock_irqrestore(&priv
->lock
, flags
);
7376 mutex_lock(&priv
->mutex
);
7377 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
7378 iwl_activate_qos(priv
, 1);
7379 else if (priv
->assoc_id
&& iwl_is_associated(priv
))
7380 iwl_activate_qos(priv
, 0);
7382 mutex_unlock(&priv
->mutex
);
7384 #endif /*CONFIG_IWLWIFI_QOS */
7386 IWL_DEBUG_MAC80211("leave\n");
7390 static int iwl_mac_get_tx_stats(struct ieee80211_hw
*hw
,
7391 struct ieee80211_tx_queue_stats
*stats
)
7393 struct iwl_priv
*priv
= hw
->priv
;
7395 struct iwl_tx_queue
*txq
;
7396 struct iwl_queue
*q
;
7397 unsigned long flags
;
7399 IWL_DEBUG_MAC80211("enter\n");
7401 if (!iwl_is_ready_rf(priv
)) {
7402 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7406 spin_lock_irqsave(&priv
->lock
, flags
);
7408 for (i
= 0; i
< AC_NUM
; i
++) {
7409 txq
= &priv
->txq
[i
];
7411 avail
= iwl_queue_space(q
);
7413 stats
->data
[i
].len
= q
->n_window
- avail
;
7414 stats
->data
[i
].limit
= q
->n_window
- q
->high_mark
;
7415 stats
->data
[i
].count
= q
->n_window
;
7418 spin_unlock_irqrestore(&priv
->lock
, flags
);
7420 IWL_DEBUG_MAC80211("leave\n");
7425 static int iwl_mac_get_stats(struct ieee80211_hw
*hw
,
7426 struct ieee80211_low_level_stats
*stats
)
7428 IWL_DEBUG_MAC80211("enter\n");
7429 IWL_DEBUG_MAC80211("leave\n");
7434 static u64
iwl_mac_get_tsf(struct ieee80211_hw
*hw
)
7436 IWL_DEBUG_MAC80211("enter\n");
7437 IWL_DEBUG_MAC80211("leave\n");
7442 static void iwl_mac_reset_tsf(struct ieee80211_hw
*hw
)
7444 struct iwl_priv
*priv
= hw
->priv
;
7445 unsigned long flags
;
7447 mutex_lock(&priv
->mutex
);
7448 IWL_DEBUG_MAC80211("enter\n");
7450 #ifdef CONFIG_IWLWIFI_QOS
7451 iwl_reset_qos(priv
);
7453 cancel_delayed_work(&priv
->post_associate
);
7455 spin_lock_irqsave(&priv
->lock
, flags
);
7457 priv
->assoc_capability
= 0;
7458 priv
->call_post_assoc_from_beacon
= 0;
7460 /* new association get rid of ibss beacon skb */
7461 if (priv
->ibss_beacon
)
7462 dev_kfree_skb(priv
->ibss_beacon
);
7464 priv
->ibss_beacon
= NULL
;
7466 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
7467 priv
->timestamp1
= 0;
7468 priv
->timestamp0
= 0;
7469 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
7470 priv
->beacon_int
= 0;
7472 spin_unlock_irqrestore(&priv
->lock
, flags
);
7474 /* Per mac80211.h: This is only used in IBSS mode... */
7475 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
7476 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7477 mutex_unlock(&priv
->mutex
);
7481 if (!iwl_is_ready_rf(priv
)) {
7482 IWL_DEBUG_MAC80211("leave - not ready\n");
7483 mutex_unlock(&priv
->mutex
);
7487 priv
->only_active_channel
= 0;
7491 mutex_unlock(&priv
->mutex
);
7493 IWL_DEBUG_MAC80211("leave\n");
7497 static int iwl_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
7498 struct ieee80211_tx_control
*control
)
7500 struct iwl_priv
*priv
= hw
->priv
;
7501 unsigned long flags
;
7503 mutex_lock(&priv
->mutex
);
7504 IWL_DEBUG_MAC80211("enter\n");
7506 if (!iwl_is_ready_rf(priv
)) {
7507 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7508 mutex_unlock(&priv
->mutex
);
7512 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
7513 IWL_DEBUG_MAC80211("leave - not IBSS\n");
7514 mutex_unlock(&priv
->mutex
);
7518 spin_lock_irqsave(&priv
->lock
, flags
);
7520 if (priv
->ibss_beacon
)
7521 dev_kfree_skb(priv
->ibss_beacon
);
7523 priv
->ibss_beacon
= skb
;
7527 IWL_DEBUG_MAC80211("leave\n");
7528 spin_unlock_irqrestore(&priv
->lock
, flags
);
7530 #ifdef CONFIG_IWLWIFI_QOS
7531 iwl_reset_qos(priv
);
7534 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
7536 mutex_unlock(&priv
->mutex
);
7541 /*****************************************************************************
7545 *****************************************************************************/
7547 #ifdef CONFIG_IWLWIFI_DEBUG
7550 * The following adds a new attribute to the sysfs representation
7551 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
7552 * used for controlling the debug level.
7554 * See the level definitions in iwl for details.
7557 static ssize_t
show_debug_level(struct device_driver
*d
, char *buf
)
7559 return sprintf(buf
, "0x%08X\n", iwl_debug_level
);
7561 static ssize_t
store_debug_level(struct device_driver
*d
,
7562 const char *buf
, size_t count
)
7564 char *p
= (char *)buf
;
7567 val
= simple_strtoul(p
, &p
, 0);
7569 printk(KERN_INFO DRV_NAME
7570 ": %s is not in hex or decimal form.\n", buf
);
7572 iwl_debug_level
= val
;
7574 return strnlen(buf
, count
);
7577 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
7578 show_debug_level
, store_debug_level
);
7580 #endif /* CONFIG_IWLWIFI_DEBUG */
7582 static ssize_t
show_rf_kill(struct device
*d
,
7583 struct device_attribute
*attr
, char *buf
)
7586 * 0 - RF kill not enabled
7587 * 1 - SW based RF kill active (sysfs)
7588 * 2 - HW based RF kill active
7589 * 3 - Both HW and SW based RF kill active
7591 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7592 int val
= (test_bit(STATUS_RF_KILL_SW
, &priv
->status
) ? 0x1 : 0x0) |
7593 (test_bit(STATUS_RF_KILL_HW
, &priv
->status
) ? 0x2 : 0x0);
7595 return sprintf(buf
, "%i\n", val
);
7598 static ssize_t
store_rf_kill(struct device
*d
,
7599 struct device_attribute
*attr
,
7600 const char *buf
, size_t count
)
7602 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7604 mutex_lock(&priv
->mutex
);
7605 iwl_radio_kill_sw(priv
, buf
[0] == '1');
7606 mutex_unlock(&priv
->mutex
);
7611 static DEVICE_ATTR(rf_kill
, S_IWUSR
| S_IRUGO
, show_rf_kill
, store_rf_kill
);
7613 static ssize_t
show_temperature(struct device
*d
,
7614 struct device_attribute
*attr
, char *buf
)
7616 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7618 if (!iwl_is_alive(priv
))
7621 return sprintf(buf
, "%d\n", iwl_hw_get_temperature(priv
));
7624 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
7626 static ssize_t
show_rs_window(struct device
*d
,
7627 struct device_attribute
*attr
,
7630 struct iwl_priv
*priv
= d
->driver_data
;
7631 return iwl_fill_rs_info(priv
->hw
, buf
, IWL_AP_ID
);
7633 static DEVICE_ATTR(rs_window
, S_IRUGO
, show_rs_window
, NULL
);
7635 static ssize_t
show_tx_power(struct device
*d
,
7636 struct device_attribute
*attr
, char *buf
)
7638 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7639 return sprintf(buf
, "%d\n", priv
->user_txpower_limit
);
7642 static ssize_t
store_tx_power(struct device
*d
,
7643 struct device_attribute
*attr
,
7644 const char *buf
, size_t count
)
7646 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7647 char *p
= (char *)buf
;
7650 val
= simple_strtoul(p
, &p
, 10);
7652 printk(KERN_INFO DRV_NAME
7653 ": %s is not in decimal form.\n", buf
);
7655 iwl_hw_reg_set_txpower(priv
, val
);
7660 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
7662 static ssize_t
show_flags(struct device
*d
,
7663 struct device_attribute
*attr
, char *buf
)
7665 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7667 return sprintf(buf
, "0x%04X\n", priv
->active_rxon
.flags
);
7670 static ssize_t
store_flags(struct device
*d
,
7671 struct device_attribute
*attr
,
7672 const char *buf
, size_t count
)
7674 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7675 u32 flags
= simple_strtoul(buf
, NULL
, 0);
7677 mutex_lock(&priv
->mutex
);
7678 if (le32_to_cpu(priv
->staging_rxon
.flags
) != flags
) {
7679 /* Cancel any currently running scans... */
7680 if (iwl_scan_cancel_timeout(priv
, 100))
7681 IWL_WARNING("Could not cancel scan.\n");
7683 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
7685 priv
->staging_rxon
.flags
= cpu_to_le32(flags
);
7686 iwl_commit_rxon(priv
);
7689 mutex_unlock(&priv
->mutex
);
7694 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
7696 static ssize_t
show_filter_flags(struct device
*d
,
7697 struct device_attribute
*attr
, char *buf
)
7699 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7701 return sprintf(buf
, "0x%04X\n",
7702 le32_to_cpu(priv
->active_rxon
.filter_flags
));
7705 static ssize_t
store_filter_flags(struct device
*d
,
7706 struct device_attribute
*attr
,
7707 const char *buf
, size_t count
)
7709 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7710 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
7712 mutex_lock(&priv
->mutex
);
7713 if (le32_to_cpu(priv
->staging_rxon
.filter_flags
) != filter_flags
) {
7714 /* Cancel any currently running scans... */
7715 if (iwl_scan_cancel_timeout(priv
, 100))
7716 IWL_WARNING("Could not cancel scan.\n");
7718 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
7719 "0x%04X\n", filter_flags
);
7720 priv
->staging_rxon
.filter_flags
=
7721 cpu_to_le32(filter_flags
);
7722 iwl_commit_rxon(priv
);
7725 mutex_unlock(&priv
->mutex
);
7730 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
7731 store_filter_flags
);
7733 static ssize_t
show_tune(struct device
*d
,
7734 struct device_attribute
*attr
, char *buf
)
7736 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7738 return sprintf(buf
, "0x%04X\n",
7739 (priv
->phymode
<< 8) |
7740 le16_to_cpu(priv
->active_rxon
.channel
));
7743 static void iwl_set_flags_for_phymode(struct iwl_priv
*priv
, u8 phymode
);
7745 static ssize_t
store_tune(struct device
*d
,
7746 struct device_attribute
*attr
,
7747 const char *buf
, size_t count
)
7749 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7750 char *p
= (char *)buf
;
7751 u16 tune
= simple_strtoul(p
, &p
, 0);
7752 u8 phymode
= (tune
>> 8) & 0xff;
7753 u16 channel
= tune
& 0xff;
7755 IWL_DEBUG_INFO("Tune request to:%d channel:%d\n", phymode
, channel
);
7757 mutex_lock(&priv
->mutex
);
7758 if ((le16_to_cpu(priv
->staging_rxon
.channel
) != channel
) ||
7759 (priv
->phymode
!= phymode
)) {
7760 const struct iwl_channel_info
*ch_info
;
7762 ch_info
= iwl_get_channel_info(priv
, phymode
, channel
);
7764 IWL_WARNING("Requested invalid phymode/channel "
7765 "combination: %d %d\n", phymode
, channel
);
7766 mutex_unlock(&priv
->mutex
);
7770 /* Cancel any currently running scans... */
7771 if (iwl_scan_cancel_timeout(priv
, 100))
7772 IWL_WARNING("Could not cancel scan.\n");
7774 IWL_DEBUG_INFO("Committing phymode and "
7775 "rxon.channel = %d %d\n",
7778 iwl_set_rxon_channel(priv
, phymode
, channel
);
7779 iwl_set_flags_for_phymode(priv
, phymode
);
7782 iwl_commit_rxon(priv
);
7785 mutex_unlock(&priv
->mutex
);
7790 static DEVICE_ATTR(tune
, S_IWUSR
| S_IRUGO
, show_tune
, store_tune
);
7792 #ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT
7794 static ssize_t
show_measurement(struct device
*d
,
7795 struct device_attribute
*attr
, char *buf
)
7797 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7798 struct iwl_spectrum_notification measure_report
;
7799 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
7800 u8
*data
= (u8
*) & measure_report
;
7801 unsigned long flags
;
7803 spin_lock_irqsave(&priv
->lock
, flags
);
7804 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
7805 spin_unlock_irqrestore(&priv
->lock
, flags
);
7808 memcpy(&measure_report
, &priv
->measure_report
, size
);
7809 priv
->measurement_status
= 0;
7810 spin_unlock_irqrestore(&priv
->lock
, flags
);
7812 while (size
&& (PAGE_SIZE
- len
)) {
7813 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7814 PAGE_SIZE
- len
, 1);
7816 if (PAGE_SIZE
- len
)
7820 size
-= min(size
, 16U);
7826 static ssize_t
store_measurement(struct device
*d
,
7827 struct device_attribute
*attr
,
7828 const char *buf
, size_t count
)
7830 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7831 struct ieee80211_measurement_params params
= {
7832 .channel
= le16_to_cpu(priv
->active_rxon
.channel
),
7833 .start_time
= cpu_to_le64(priv
->last_tsf
),
7834 .duration
= cpu_to_le16(1),
7836 u8 type
= IWL_MEASURE_BASIC
;
7842 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
7843 channel
= simple_strtoul(p
, NULL
, 0);
7845 params
.channel
= channel
;
7848 while (*p
&& *p
!= ' ')
7851 type
= simple_strtoul(p
+ 1, NULL
, 0);
7854 IWL_DEBUG_INFO("Invoking measurement of type %d on "
7855 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
7856 iwl_get_measurement(priv
, ¶ms
, type
);
7861 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
7862 show_measurement
, store_measurement
);
7863 #endif /* CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT */
7865 static ssize_t
show_rate(struct device
*d
,
7866 struct device_attribute
*attr
, char *buf
)
7868 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7869 unsigned long flags
;
7872 spin_lock_irqsave(&priv
->sta_lock
, flags
);
7873 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)
7874 i
= priv
->stations
[IWL_AP_ID
].current_rate
.s
.rate
;
7876 i
= priv
->stations
[IWL_STA_ID
].current_rate
.s
.rate
;
7877 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
7879 i
= iwl_rate_index_from_plcp(i
);
7881 return sprintf(buf
, "0\n");
7883 return sprintf(buf
, "%d%s\n",
7884 (iwl_rates
[i
].ieee
>> 1),
7885 (iwl_rates
[i
].ieee
& 0x1) ? ".5" : "");
7888 static DEVICE_ATTR(rate
, S_IRUSR
, show_rate
, NULL
);
7890 static ssize_t
store_retry_rate(struct device
*d
,
7891 struct device_attribute
*attr
,
7892 const char *buf
, size_t count
)
7894 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7896 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
7897 if (priv
->retry_rate
<= 0)
7898 priv
->retry_rate
= 1;
7903 static ssize_t
show_retry_rate(struct device
*d
,
7904 struct device_attribute
*attr
, char *buf
)
7906 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7907 return sprintf(buf
, "%d", priv
->retry_rate
);
7910 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
7913 static ssize_t
store_power_level(struct device
*d
,
7914 struct device_attribute
*attr
,
7915 const char *buf
, size_t count
)
7917 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7921 mode
= simple_strtoul(buf
, NULL
, 0);
7922 mutex_lock(&priv
->mutex
);
7924 if (!iwl_is_ready(priv
)) {
7929 if ((mode
< 1) || (mode
> IWL_POWER_LIMIT
) || (mode
== IWL_POWER_AC
))
7930 mode
= IWL_POWER_AC
;
7932 mode
|= IWL_POWER_ENABLED
;
7934 if (mode
!= priv
->power_mode
) {
7935 rc
= iwl_send_power_mode(priv
, IWL_POWER_LEVEL(mode
));
7937 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7940 priv
->power_mode
= mode
;
7946 mutex_unlock(&priv
->mutex
);
7950 #define MAX_WX_STRING 80
7952 /* Values are in microsecond */
7953 static const s32 timeout_duration
[] = {
7960 static const s32 period_duration
[] = {
7968 static ssize_t
show_power_level(struct device
*d
,
7969 struct device_attribute
*attr
, char *buf
)
7971 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7972 int level
= IWL_POWER_LEVEL(priv
->power_mode
);
7975 p
+= sprintf(p
, "%d ", level
);
7977 case IWL_POWER_MODE_CAM
:
7979 p
+= sprintf(p
, "(AC)");
7981 case IWL_POWER_BATTERY
:
7982 p
+= sprintf(p
, "(BATTERY)");
7986 "(Timeout %dms, Period %dms)",
7987 timeout_duration
[level
- 1] / 1000,
7988 period_duration
[level
- 1] / 1000);
7991 if (!(priv
->power_mode
& IWL_POWER_ENABLED
))
7992 p
+= sprintf(p
, " OFF\n");
7994 p
+= sprintf(p
, " \n");
7996 return (p
- buf
+ 1);
8000 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
8003 static ssize_t
show_channels(struct device
*d
,
8004 struct device_attribute
*attr
, char *buf
)
8006 struct iwl_priv
*priv
= dev_get_drvdata(d
);
8008 struct ieee80211_channel
*channels
= NULL
;
8009 const struct ieee80211_hw_mode
*hw_mode
= NULL
;
8012 if (!iwl_is_ready(priv
))
8015 hw_mode
= iwl_get_hw_mode(priv
, MODE_IEEE80211G
);
8017 hw_mode
= iwl_get_hw_mode(priv
, MODE_IEEE80211B
);
8019 channels
= hw_mode
->channels
;
8020 count
= hw_mode
->num_channels
;
8025 "Displaying %d channels in 2.4GHz band "
8026 "(802.11bg):\n", count
);
8028 for (i
= 0; i
< count
; i
++)
8029 len
+= sprintf(&buf
[len
], "%d: %ddBm: BSS%s%s, %s.\n",
8031 channels
[i
].power_level
,
8033 flag
& IEEE80211_CHAN_W_RADAR_DETECT
?
8034 " (IEEE 802.11h required)" : "",
8035 (!(channels
[i
].flag
& IEEE80211_CHAN_W_IBSS
)
8038 IEEE80211_CHAN_W_RADAR_DETECT
)) ? "" :
8041 flag
& IEEE80211_CHAN_W_ACTIVE_SCAN
?
8042 "active/passive" : "passive only");
8044 hw_mode
= iwl_get_hw_mode(priv
, MODE_IEEE80211A
);
8046 channels
= hw_mode
->channels
;
8047 count
= hw_mode
->num_channels
;
8053 len
+= sprintf(&buf
[len
], "Displaying %d channels in 5.2GHz band "
8054 "(802.11a):\n", count
);
8056 for (i
= 0; i
< count
; i
++)
8057 len
+= sprintf(&buf
[len
], "%d: %ddBm: BSS%s%s, %s.\n",
8059 channels
[i
].power_level
,
8061 flag
& IEEE80211_CHAN_W_RADAR_DETECT
?
8062 " (IEEE 802.11h required)" : "",
8063 (!(channels
[i
].flag
& IEEE80211_CHAN_W_IBSS
)
8066 IEEE80211_CHAN_W_RADAR_DETECT
)) ? "" :
8069 flag
& IEEE80211_CHAN_W_ACTIVE_SCAN
?
8070 "active/passive" : "passive only");
8075 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
8077 static ssize_t
show_statistics(struct device
*d
,
8078 struct device_attribute
*attr
, char *buf
)
8080 struct iwl_priv
*priv
= dev_get_drvdata(d
);
8081 u32 size
= sizeof(struct iwl_notif_statistics
);
8082 u32 len
= 0, ofs
= 0;
8083 u8
*data
= (u8
*) & priv
->statistics
;
8086 if (!iwl_is_alive(priv
))
8089 mutex_lock(&priv
->mutex
);
8090 rc
= iwl_send_statistics_request(priv
);
8091 mutex_unlock(&priv
->mutex
);
8095 "Error sending statistics request: 0x%08X\n", rc
);
8099 while (size
&& (PAGE_SIZE
- len
)) {
8100 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
8101 PAGE_SIZE
- len
, 1);
8103 if (PAGE_SIZE
- len
)
8107 size
-= min(size
, 16U);
8113 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
8115 static ssize_t
show_antenna(struct device
*d
,
8116 struct device_attribute
*attr
, char *buf
)
8118 struct iwl_priv
*priv
= dev_get_drvdata(d
);
8120 if (!iwl_is_alive(priv
))
8123 return sprintf(buf
, "%d\n", priv
->antenna
);
8126 static ssize_t
store_antenna(struct device
*d
,
8127 struct device_attribute
*attr
,
8128 const char *buf
, size_t count
)
8131 struct iwl_priv
*priv
= dev_get_drvdata(d
);
8136 if (sscanf(buf
, "%1i", &ant
) != 1) {
8137 IWL_DEBUG_INFO("not in hex or decimal form.\n");
8141 if ((ant
>= 0) && (ant
<= 2)) {
8142 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant
);
8143 priv
->antenna
= (enum iwl_antenna
)ant
;
8145 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant
);
8151 static DEVICE_ATTR(antenna
, S_IWUSR
| S_IRUGO
, show_antenna
, store_antenna
);
8153 static ssize_t
show_status(struct device
*d
,
8154 struct device_attribute
*attr
, char *buf
)
8156 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
8157 if (!iwl_is_alive(priv
))
8159 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
8162 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
8164 static ssize_t
dump_error_log(struct device
*d
,
8165 struct device_attribute
*attr
,
8166 const char *buf
, size_t count
)
8168 char *p
= (char *)buf
;
8171 iwl_dump_nic_error_log((struct iwl_priv
*)d
->driver_data
);
8173 return strnlen(buf
, count
);
8176 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, dump_error_log
);
8178 static ssize_t
dump_event_log(struct device
*d
,
8179 struct device_attribute
*attr
,
8180 const char *buf
, size_t count
)
8182 char *p
= (char *)buf
;
8185 iwl_dump_nic_event_log((struct iwl_priv
*)d
->driver_data
);
8187 return strnlen(buf
, count
);
8190 static DEVICE_ATTR(dump_events
, S_IWUSR
, NULL
, dump_event_log
);
8192 /*****************************************************************************
8194 * driver setup and teardown
8196 *****************************************************************************/
8198 static void iwl_setup_deferred_work(struct iwl_priv
*priv
)
8200 priv
->workqueue
= create_workqueue(DRV_NAME
);
8202 init_waitqueue_head(&priv
->wait_command_queue
);
8204 INIT_WORK(&priv
->up
, iwl_bg_up
);
8205 INIT_WORK(&priv
->restart
, iwl_bg_restart
);
8206 INIT_WORK(&priv
->rx_replenish
, iwl_bg_rx_replenish
);
8207 INIT_WORK(&priv
->scan_completed
, iwl_bg_scan_completed
);
8208 INIT_WORK(&priv
->request_scan
, iwl_bg_request_scan
);
8209 INIT_WORK(&priv
->abort_scan
, iwl_bg_abort_scan
);
8210 INIT_WORK(&priv
->rf_kill
, iwl_bg_rf_kill
);
8211 INIT_WORK(&priv
->beacon_update
, iwl_bg_beacon_update
);
8212 INIT_DELAYED_WORK(&priv
->post_associate
, iwl_bg_post_associate
);
8213 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl_bg_init_alive_start
);
8214 INIT_DELAYED_WORK(&priv
->alive_start
, iwl_bg_alive_start
);
8215 INIT_DELAYED_WORK(&priv
->scan_check
, iwl_bg_scan_check
);
8217 iwl_hw_setup_deferred_work(priv
);
8219 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
8220 iwl_irq_tasklet
, (unsigned long)priv
);
8223 static void iwl_cancel_deferred_work(struct iwl_priv
*priv
)
8225 iwl_hw_cancel_deferred_work(priv
);
8227 cancel_delayed_work(&priv
->scan_check
);
8228 cancel_delayed_work(&priv
->alive_start
);
8229 cancel_delayed_work(&priv
->post_associate
);
8230 cancel_work_sync(&priv
->beacon_update
);
8233 static struct attribute
*iwl_sysfs_entries
[] = {
8234 &dev_attr_antenna
.attr
,
8235 &dev_attr_channels
.attr
,
8236 &dev_attr_dump_errors
.attr
,
8237 &dev_attr_dump_events
.attr
,
8238 &dev_attr_flags
.attr
,
8239 &dev_attr_filter_flags
.attr
,
8240 #ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT
8241 &dev_attr_measurement
.attr
,
8243 &dev_attr_power_level
.attr
,
8244 &dev_attr_rate
.attr
,
8245 &dev_attr_retry_rate
.attr
,
8246 &dev_attr_rf_kill
.attr
,
8247 &dev_attr_rs_window
.attr
,
8248 &dev_attr_statistics
.attr
,
8249 &dev_attr_status
.attr
,
8250 &dev_attr_temperature
.attr
,
8251 &dev_attr_tune
.attr
,
8252 &dev_attr_tx_power
.attr
,
8257 static struct attribute_group iwl_attribute_group
= {
8258 .name
= NULL
, /* put in device directory */
8259 .attrs
= iwl_sysfs_entries
,
8262 static struct ieee80211_ops iwl_hw_ops
= {
8264 .start
= iwl_mac_start
,
8265 .stop
= iwl_mac_stop
,
8266 .add_interface
= iwl_mac_add_interface
,
8267 .remove_interface
= iwl_mac_remove_interface
,
8268 .config
= iwl_mac_config
,
8269 .config_interface
= iwl_mac_config_interface
,
8270 .configure_filter
= iwl_configure_filter
,
8271 .set_key
= iwl_mac_set_key
,
8272 .get_stats
= iwl_mac_get_stats
,
8273 .get_tx_stats
= iwl_mac_get_tx_stats
,
8274 .conf_tx
= iwl_mac_conf_tx
,
8275 .get_tsf
= iwl_mac_get_tsf
,
8276 .reset_tsf
= iwl_mac_reset_tsf
,
8277 .beacon_update
= iwl_mac_beacon_update
,
8278 .hw_scan
= iwl_mac_hw_scan
8281 static int iwl_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
8285 struct iwl_priv
*priv
;
8286 struct ieee80211_hw
*hw
;
8289 if (iwl_param_disable_hw_scan
) {
8290 IWL_DEBUG_INFO("Disabling hw_scan\n");
8291 iwl_hw_ops
.hw_scan
= NULL
;
8294 if ((iwl_param_queues_num
> IWL_MAX_NUM_QUEUES
) ||
8295 (iwl_param_queues_num
< IWL_MIN_NUM_QUEUES
)) {
8296 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
8297 IWL_MIN_NUM_QUEUES
, IWL_MAX_NUM_QUEUES
);
8302 /* mac80211 allocates memory for this device instance, including
8303 * space for this driver's private structure */
8304 hw
= ieee80211_alloc_hw(sizeof(struct iwl_priv
), &iwl_hw_ops
);
8306 IWL_ERROR("Can not allocate network device\n");
8310 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
8312 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
8316 priv
->pci_dev
= pdev
;
8317 priv
->antenna
= (enum iwl_antenna
)iwl_param_antenna
;
8318 #ifdef CONFIG_IWLWIFI_DEBUG
8319 iwl_debug_level
= iwl_param_debug
;
8320 atomic_set(&priv
->restrict_refcnt
, 0);
8322 priv
->retry_rate
= 1;
8324 priv
->ibss_beacon
= NULL
;
8326 /* Tell mac80211 and its clients (e.g. Wireless Extensions)
8327 * the range of signal quality values that we'll provide.
8328 * Negative values for level/noise indicate that we'll provide dBm.
8329 * For WE, at least, non-0 values here *enable* display of values
8330 * in app (iwconfig). */
8331 hw
->max_rssi
= -20; /* signal level, negative indicates dBm */
8332 hw
->max_noise
= -20; /* noise level, negative indicates dBm */
8333 hw
->max_signal
= 100; /* link quality indication (%) */
8335 /* Tell mac80211 our Tx characteristics */
8336 hw
->flags
= IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE
;
8340 spin_lock_init(&priv
->lock
);
8341 spin_lock_init(&priv
->power_data
.lock
);
8342 spin_lock_init(&priv
->sta_lock
);
8343 spin_lock_init(&priv
->hcmd_lock
);
8345 for (i
= 0; i
< IWL_IBSS_MAC_HASH_SIZE
; i
++)
8346 INIT_LIST_HEAD(&priv
->ibss_mac_hash
[i
]);
8348 INIT_LIST_HEAD(&priv
->free_frames
);
8350 mutex_init(&priv
->mutex
);
8351 if (pci_enable_device(pdev
)) {
8353 goto out_ieee80211_free_hw
;
8356 pci_set_master(pdev
);
8358 iwl_clear_stations_table(priv
);
8360 priv
->data_retry_limit
= -1;
8361 priv
->ieee_channels
= NULL
;
8362 priv
->ieee_rates
= NULL
;
8365 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
8367 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
8369 printk(KERN_WARNING DRV_NAME
": No suitable DMA available.\n");
8370 goto out_pci_disable_device
;
8373 pci_set_drvdata(pdev
, priv
);
8374 err
= pci_request_regions(pdev
, DRV_NAME
);
8376 goto out_pci_disable_device
;
8377 /* We disable the RETRY_TIMEOUT register (0x41) to keep
8378 * PCI Tx retries from interfering with C3 CPU state */
8379 pci_write_config_byte(pdev
, 0x41, 0x00);
8380 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
8381 if (!priv
->hw_base
) {
8383 goto out_pci_release_regions
;
8386 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
8387 (unsigned long long) pci_resource_len(pdev
, 0));
8388 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
8390 /* Initialize module parameter values here */
8392 if (iwl_param_disable
) {
8393 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
8394 IWL_DEBUG_INFO("Radio disabled.\n");
8397 priv
->iw_mode
= IEEE80211_IF_TYPE_STA
;
8400 (priv
->pci_dev
->device
<< 16) | priv
->pci_dev
->subsystem_device
;
8403 case 0x42221005: /* 0x4222 0x8086 0x1005 is BG SKU */
8404 case 0x42221034: /* 0x4222 0x8086 0x1034 is BG SKU */
8405 case 0x42271014: /* 0x4227 0x8086 0x1014 is BG SKU */
8406 case 0x42221044: /* 0x4222 0x8086 0x1044 is BG SKU */
8411 * Rest are assumed ABG SKU -- if this is not the
8412 * case then the card will get the wrong 'Detected'
8413 * line in the kernel log however the code that
8414 * initializes the GEO table will detect no A-band
8415 * channels and remove the is_abg mask.
8422 printk(KERN_INFO DRV_NAME
8423 ": Detected Intel PRO/Wireless 3945%sBG Network Connection\n",
8424 priv
->is_abg
? "A" : "");
8426 /* Device-specific setup */
8427 if (iwl_hw_set_hw_setting(priv
)) {
8428 IWL_ERROR("failed to set hw settings\n");
8429 mutex_unlock(&priv
->mutex
);
8433 #ifdef CONFIG_IWLWIFI_QOS
8434 if (iwl_param_qos_enable
)
8435 priv
->qos_data
.qos_enable
= 1;
8437 iwl_reset_qos(priv
);
8439 priv
->qos_data
.qos_active
= 0;
8440 priv
->qos_data
.qos_cap
.val
= 0;
8441 #endif /* CONFIG_IWLWIFI_QOS */
8443 iwl_set_rxon_channel(priv
, MODE_IEEE80211G
, 6);
8444 iwl_setup_deferred_work(priv
);
8445 iwl_setup_rx_handlers(priv
);
8447 priv
->rates_mask
= IWL_RATES_MASK
;
8448 /* If power management is turned on, default to AC mode */
8449 priv
->power_mode
= IWL_POWER_AC
;
8450 priv
->user_txpower_limit
= IWL_DEFAULT_TX_POWER
;
8452 pci_enable_msi(pdev
);
8454 err
= request_irq(pdev
->irq
, iwl_isr
, IRQF_SHARED
, DRV_NAME
, priv
);
8456 IWL_ERROR("Error allocating IRQ %d\n", pdev
->irq
);
8457 goto out_disable_msi
;
8460 mutex_lock(&priv
->mutex
);
8462 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl_attribute_group
);
8464 IWL_ERROR("failed to create sysfs device attributes\n");
8465 mutex_unlock(&priv
->mutex
);
8466 goto out_release_irq
;
8469 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
8470 * ucode filename and max sizes are card-specific. */
8471 err
= iwl_read_ucode(priv
);
8473 IWL_ERROR("Could not read microcode: %d\n", err
);
8474 mutex_unlock(&priv
->mutex
);
8478 mutex_unlock(&priv
->mutex
);
8480 IWL_DEBUG_INFO("Queing UP work.\n");
8482 queue_work(priv
->workqueue
, &priv
->up
);
8487 iwl_dealloc_ucode_pci(priv
);
8489 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl_attribute_group
);
8492 free_irq(pdev
->irq
, priv
);
8495 pci_disable_msi(pdev
);
8496 destroy_workqueue(priv
->workqueue
);
8497 priv
->workqueue
= NULL
;
8498 iwl_unset_hw_setting(priv
);
8501 pci_iounmap(pdev
, priv
->hw_base
);
8502 out_pci_release_regions
:
8503 pci_release_regions(pdev
);
8504 out_pci_disable_device
:
8505 pci_disable_device(pdev
);
8506 pci_set_drvdata(pdev
, NULL
);
8507 out_ieee80211_free_hw
:
8508 ieee80211_free_hw(priv
->hw
);
8513 static void iwl_pci_remove(struct pci_dev
*pdev
)
8515 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
8516 struct list_head
*p
, *q
;
8522 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
8524 mutex_lock(&priv
->mutex
);
8525 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
8527 mutex_unlock(&priv
->mutex
);
8529 /* Free MAC hash list for ADHOC */
8530 for (i
= 0; i
< IWL_IBSS_MAC_HASH_SIZE
; i
++) {
8531 list_for_each_safe(p
, q
, &priv
->ibss_mac_hash
[i
]) {
8533 kfree(list_entry(p
, struct iwl_ibss_seq
, list
));
8537 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl_attribute_group
);
8539 iwl_dealloc_ucode_pci(priv
);
8542 iwl_rx_queue_free(priv
, &priv
->rxq
);
8543 iwl_hw_txq_ctx_free(priv
);
8545 iwl_unset_hw_setting(priv
);
8546 iwl_clear_stations_table(priv
);
8548 if (priv
->mac80211_registered
) {
8549 ieee80211_unregister_hw(priv
->hw
);
8550 iwl_rate_control_unregister(priv
->hw
);
8553 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
8554 * priv->workqueue... so we can't take down the workqueue
8556 destroy_workqueue(priv
->workqueue
);
8557 priv
->workqueue
= NULL
;
8559 free_irq(pdev
->irq
, priv
);
8560 pci_disable_msi(pdev
);
8561 pci_iounmap(pdev
, priv
->hw_base
);
8562 pci_release_regions(pdev
);
8563 pci_disable_device(pdev
);
8564 pci_set_drvdata(pdev
, NULL
);
8566 kfree(priv
->channel_info
);
8568 kfree(priv
->ieee_channels
);
8569 kfree(priv
->ieee_rates
);
8571 if (priv
->ibss_beacon
)
8572 dev_kfree_skb(priv
->ibss_beacon
);
8574 ieee80211_free_hw(priv
->hw
);
8579 static int iwl_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
8581 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
8583 mutex_lock(&priv
->mutex
);
8585 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
8587 /* Take down the device; powers it off, etc. */
8590 if (priv
->mac80211_registered
)
8591 ieee80211_stop_queues(priv
->hw
);
8593 pci_save_state(pdev
);
8594 pci_disable_device(pdev
);
8595 pci_set_power_state(pdev
, PCI_D3hot
);
8597 mutex_unlock(&priv
->mutex
);
8602 static void iwl_resume(struct iwl_priv
*priv
)
8604 unsigned long flags
;
8606 /* The following it a temporary work around due to the
8607 * suspend / resume not fully initializing the NIC correctly.
8608 * Without all of the following, resume will not attempt to take
8609 * down the NIC (it shouldn't really need to) and will just try
8610 * and bring the NIC back up. However that fails during the
8611 * ucode verification process. This then causes iwl_down to be
8612 * called *after* iwl_hw_nic_init() has succeeded -- which
8613 * then lets the next init sequence succeed. So, we've
8614 * replicated all of that NIC init code here... */
8616 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
8618 iwl_hw_nic_init(priv
);
8620 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
8621 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
8622 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
8623 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
8624 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
8625 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
8627 /* tell the device to stop sending interrupts */
8628 iwl_disable_interrupts(priv
);
8630 spin_lock_irqsave(&priv
->lock
, flags
);
8631 iwl_clear_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
8633 if (!iwl_grab_restricted_access(priv
)) {
8634 iwl_write_restricted_reg(priv
, APMG_CLK_DIS_REG
,
8635 APMG_CLK_VAL_DMA_CLK_RQT
);
8636 iwl_release_restricted_access(priv
);
8638 spin_unlock_irqrestore(&priv
->lock
, flags
);
8642 iwl_hw_nic_reset(priv
);
8644 /* Bring the device back up */
8645 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
8646 queue_work(priv
->workqueue
, &priv
->up
);
8649 static int iwl_pci_resume(struct pci_dev
*pdev
)
8651 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
8654 printk(KERN_INFO
"Coming out of suspend...\n");
8656 mutex_lock(&priv
->mutex
);
8658 pci_set_power_state(pdev
, PCI_D0
);
8659 err
= pci_enable_device(pdev
);
8660 pci_restore_state(pdev
);
8663 * Suspend/Resume resets the PCI configuration space, so we have to
8664 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
8665 * from interfering with C3 CPU state. pci_restore_state won't help
8666 * here since it only restores the first 64 bytes pci config header.
8668 pci_write_config_byte(pdev
, 0x41, 0x00);
8671 mutex_unlock(&priv
->mutex
);
8676 #endif /* CONFIG_PM */
8678 /*****************************************************************************
8680 * driver and module entry point
8682 *****************************************************************************/
8684 static struct pci_driver iwl_driver
= {
8686 .id_table
= iwl_hw_card_ids
,
8687 .probe
= iwl_pci_probe
,
8688 .remove
= __devexit_p(iwl_pci_remove
),
8690 .suspend
= iwl_pci_suspend
,
8691 .resume
= iwl_pci_resume
,
8695 static int __init
iwl_init(void)
8699 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
8700 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
8701 ret
= pci_register_driver(&iwl_driver
);
8703 IWL_ERROR("Unable to initialize PCI module\n");
8706 #ifdef CONFIG_IWLWIFI_DEBUG
8707 ret
= driver_create_file(&iwl_driver
.driver
, &driver_attr_debug_level
);
8709 IWL_ERROR("Unable to create driver sysfs file\n");
8710 pci_unregister_driver(&iwl_driver
);
8718 static void __exit
iwl_exit(void)
8720 #ifdef CONFIG_IWLWIFI_DEBUG
8721 driver_remove_file(&iwl_driver
.driver
, &driver_attr_debug_level
);
8723 pci_unregister_driver(&iwl_driver
);
8726 module_param_named(antenna
, iwl_param_antenna
, int, 0444);
8727 MODULE_PARM_DESC(antenna
, "select antenna (1=Main, 2=Aux, default 0 [both])");
8728 module_param_named(disable
, iwl_param_disable
, int, 0444);
8729 MODULE_PARM_DESC(disable
, "manually disable the radio (default 0 [radio on])");
8730 module_param_named(hwcrypto
, iwl_param_hwcrypto
, int, 0444);
8731 MODULE_PARM_DESC(hwcrypto
,
8732 "using hardware crypto engine (default 0 [software])\n");
8733 module_param_named(debug
, iwl_param_debug
, int, 0444);
8734 MODULE_PARM_DESC(debug
, "debug output mask");
8735 module_param_named(disable_hw_scan
, iwl_param_disable_hw_scan
, int, 0444);
8736 MODULE_PARM_DESC(disable_hw_scan
, "disable hardware scanning (default 0)");
8738 module_param_named(queues_num
, iwl_param_queues_num
, int, 0444);
8739 MODULE_PARM_DESC(queues_num
, "number of hw queues.");
8742 module_param_named(qos_enable
, iwl_param_qos_enable
, int, 0444);
8743 MODULE_PARM_DESC(qos_enable
, "enable all QoS functionality");
8745 module_exit(iwl_exit
);
8746 module_init(iwl_init
);