1 /******************************************************************************
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/version.h>
33 #include <linux/init.h>
34 #include <linux/pci.h>
35 #include <linux/dma-mapping.h>
36 #include <linux/delay.h>
37 #include <linux/skbuff.h>
38 #include <linux/netdevice.h>
39 #include <linux/wireless.h>
40 #include <linux/firmware.h>
41 #include <linux/etherdevice.h>
42 #include <linux/if_arp.h>
44 #include <net/mac80211.h>
46 #include <asm/div64.h>
48 #include "iwl-eeprom.h"
52 #include "iwl-helpers.h"
55 static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv
*priv
,
56 struct iwl4965_tx_queue
*txq
);
58 /******************************************************************************
62 ******************************************************************************/
65 * module name, copyright, version, etc.
66 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
69 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
71 #ifdef CONFIG_IWLWIFI_DEBUG
77 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
83 #define DRV_VERSION IWLWIFI_VERSION VD VS
86 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
87 MODULE_VERSION(DRV_VERSION
);
88 MODULE_AUTHOR(DRV_COPYRIGHT
);
89 MODULE_LICENSE("GPL");
91 __le16
*ieee80211_get_qos_ctrl(struct ieee80211_hdr
*hdr
)
93 u16 fc
= le16_to_cpu(hdr
->frame_control
);
94 int hdr_len
= ieee80211_get_hdrlen(fc
);
96 if ((fc
& 0x00cc) == (IEEE80211_STYPE_QOS_DATA
| IEEE80211_FTYPE_DATA
))
97 return (__le16
*) ((u8
*) hdr
+ hdr_len
- QOS_CONTROL_LEN
);
101 static const struct ieee80211_supported_band
*iwl4965_get_hw_mode(
102 struct iwl_priv
*priv
, enum ieee80211_band band
)
104 return priv
->hw
->wiphy
->bands
[band
];
107 static int iwl4965_is_empty_essid(const char *essid
, int essid_len
)
109 /* Single white space is for Linksys APs */
110 if (essid_len
== 1 && essid
[0] == ' ')
113 /* Otherwise, if the entire essid is 0, we assume it is hidden */
116 if (essid
[essid_len
] != '\0')
123 static const char *iwl4965_escape_essid(const char *essid
, u8 essid_len
)
125 static char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
126 const char *s
= essid
;
129 if (iwl4965_is_empty_essid(essid
, essid_len
)) {
130 memcpy(escaped
, "<hidden>", sizeof("<hidden>"));
134 essid_len
= min(essid_len
, (u8
) IW_ESSID_MAX_SIZE
);
135 while (essid_len
--) {
147 /*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
150 * Theory of operation
152 * A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
153 * of buffer descriptors, each of which points to one or more data buffers for
154 * the device to read from or fill. Driver and device exchange status of each
155 * queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
156 * entries in each circular buffer, to protect against confusing empty and full
159 * The device reads or writes the data in the queues via the device's several
160 * DMA/FIFO channels. Each queue is mapped to a single DMA channel.
162 * For Tx queue, there are low mark and high mark limits. If, after queuing
163 * the packet for Tx, free space become < low mark, Tx queue stopped. When
164 * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
167 * The 4965 operates with up to 17 queues: One receive queue, one transmit
168 * queue (#4) for sending commands to the device firmware, and 15 other
169 * Tx queues that may be mapped to prioritized Tx DMA/FIFO channels.
171 * See more detailed info in iwl-4965-hw.h.
172 ***************************************************/
174 int iwl4965_queue_space(const struct iwl4965_queue
*q
)
176 int s
= q
->read_ptr
- q
->write_ptr
;
178 if (q
->read_ptr
> q
->write_ptr
)
183 /* keep some reserve to not confuse empty and full situations */
191 static inline int x2_queue_used(const struct iwl4965_queue
*q
, int i
)
193 return q
->write_ptr
> q
->read_ptr
?
194 (i
>= q
->read_ptr
&& i
< q
->write_ptr
) :
195 !(i
< q
->read_ptr
&& i
>= q
->write_ptr
);
198 static inline u8
get_cmd_index(struct iwl4965_queue
*q
, u32 index
, int is_huge
)
200 /* This is for scan command, the big buffer at end of command array */
202 return q
->n_window
; /* must be power of 2 */
204 /* Otherwise, use normal size buffers */
205 return index
& (q
->n_window
- 1);
209 * iwl4965_queue_init - Initialize queue's high/low-water and read/write indexes
211 static int iwl4965_queue_init(struct iwl_priv
*priv
, struct iwl4965_queue
*q
,
212 int count
, int slots_num
, u32 id
)
215 q
->n_window
= slots_num
;
218 /* count must be power-of-two size, otherwise iwl_queue_inc_wrap
219 * and iwl_queue_dec_wrap are broken. */
220 BUG_ON(!is_power_of_2(count
));
222 /* slots_num must be power-of-two size, otherwise
223 * get_cmd_index is broken. */
224 BUG_ON(!is_power_of_2(slots_num
));
226 q
->low_mark
= q
->n_window
/ 4;
230 q
->high_mark
= q
->n_window
/ 8;
231 if (q
->high_mark
< 2)
234 q
->write_ptr
= q
->read_ptr
= 0;
240 * iwl4965_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
242 static int iwl4965_tx_queue_alloc(struct iwl_priv
*priv
,
243 struct iwl4965_tx_queue
*txq
, u32 id
)
245 struct pci_dev
*dev
= priv
->pci_dev
;
247 /* Driver private data, only for Tx (not command) queues,
248 * not shared with device. */
249 if (id
!= IWL_CMD_QUEUE_NUM
) {
250 txq
->txb
= kmalloc(sizeof(txq
->txb
[0]) *
251 TFD_QUEUE_SIZE_MAX
, GFP_KERNEL
);
253 IWL_ERROR("kmalloc for auxiliary BD "
254 "structures failed\n");
260 /* Circular buffer of transmit frame descriptors (TFDs),
261 * shared with device */
262 txq
->bd
= pci_alloc_consistent(dev
,
263 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
,
267 IWL_ERROR("pci_alloc_consistent(%zd) failed\n",
268 sizeof(txq
->bd
[0]) * TFD_QUEUE_SIZE_MAX
);
285 * iwl4965_tx_queue_init - Allocate and initialize one tx/cmd queue
287 int iwl4965_tx_queue_init(struct iwl_priv
*priv
,
288 struct iwl4965_tx_queue
*txq
, int slots_num
, u32 txq_id
)
290 struct pci_dev
*dev
= priv
->pci_dev
;
295 * Alloc buffer array for commands (Tx or other types of commands).
296 * For the command queue (#4), allocate command space + one big
297 * command for scan, since scan command is very huge; the system will
298 * not have two scans at the same time, so only one is needed.
299 * For normal Tx queues (all other queues), no super-size command
302 len
= sizeof(struct iwl_cmd
) * slots_num
;
303 if (txq_id
== IWL_CMD_QUEUE_NUM
)
304 len
+= IWL_MAX_SCAN_SIZE
;
305 txq
->cmd
= pci_alloc_consistent(dev
, len
, &txq
->dma_addr_cmd
);
309 /* Alloc driver data array and TFD circular buffer */
310 rc
= iwl4965_tx_queue_alloc(priv
, txq
, txq_id
);
312 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
316 txq
->need_update
= 0;
318 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
319 * iwl_queue_inc_wrap and iwl_queue_dec_wrap are broken. */
320 BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX
& (TFD_QUEUE_SIZE_MAX
- 1));
322 /* Initialize queue's high/low-water marks, and head/tail indexes */
323 iwl4965_queue_init(priv
, &txq
->q
, TFD_QUEUE_SIZE_MAX
, slots_num
, txq_id
);
325 /* Tell device where to find queue */
326 iwl4965_hw_tx_queue_init(priv
, txq
);
332 * iwl4965_tx_queue_free - Deallocate DMA queue.
333 * @txq: Transmit queue to deallocate.
335 * Empty queue by removing and destroying all BD's.
337 * 0-fill, but do not free "txq" descriptor structure.
339 void iwl4965_tx_queue_free(struct iwl_priv
*priv
, struct iwl4965_tx_queue
*txq
)
341 struct iwl4965_queue
*q
= &txq
->q
;
342 struct pci_dev
*dev
= priv
->pci_dev
;
348 /* first, empty all BD's */
349 for (; q
->write_ptr
!= q
->read_ptr
;
350 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
))
351 iwl4965_hw_txq_free_tfd(priv
, txq
);
353 len
= sizeof(struct iwl_cmd
) * q
->n_window
;
354 if (q
->id
== IWL_CMD_QUEUE_NUM
)
355 len
+= IWL_MAX_SCAN_SIZE
;
357 /* De-alloc array of command/tx buffers */
358 pci_free_consistent(dev
, len
, txq
->cmd
, txq
->dma_addr_cmd
);
360 /* De-alloc circular buffer of TFDs */
362 pci_free_consistent(dev
, sizeof(struct iwl4965_tfd_frame
) *
363 txq
->q
.n_bd
, txq
->bd
, txq
->q
.dma_addr
);
365 /* De-alloc array of per-TFD driver data */
371 /* 0-fill queue descriptor structure */
372 memset(txq
, 0, sizeof(*txq
));
375 const u8 iwl4965_broadcast_addr
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
377 /*************** STATION TABLE MANAGEMENT ****
378 * mac80211 should be examined to determine if sta_info is duplicating
379 * the functionality provided here
382 /**************************************************************/
384 #if 0 /* temporary disable till we add real remove station */
386 * iwl4965_remove_station - Remove driver's knowledge of station.
388 * NOTE: This does not remove station from device's station table.
390 static u8
iwl4965_remove_station(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
)
392 int index
= IWL_INVALID_STATION
;
396 spin_lock_irqsave(&priv
->sta_lock
, flags
);
400 else if (is_broadcast_ether_addr(addr
))
401 index
= priv
->hw_setting
.bcast_sta_id
;
403 for (i
= IWL_STA_ID
; i
< priv
->hw_setting
.max_stations
; i
++)
404 if (priv
->stations
[i
].used
&&
405 !compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
411 if (unlikely(index
== IWL_INVALID_STATION
))
414 if (priv
->stations
[index
].used
) {
415 priv
->stations
[index
].used
= 0;
416 priv
->num_stations
--;
419 BUG_ON(priv
->num_stations
< 0);
422 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
428 * iwl4965_add_station_flags - Add station to tables in driver and device
430 u8
iwl4965_add_station_flags(struct iwl_priv
*priv
, const u8
*addr
,
431 int is_ap
, u8 flags
, void *ht_data
)
434 int index
= IWL_INVALID_STATION
;
435 struct iwl4965_station_entry
*station
;
436 unsigned long flags_spin
;
437 DECLARE_MAC_BUF(mac
);
439 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
442 else if (is_broadcast_ether_addr(addr
))
443 index
= priv
->hw_setting
.bcast_sta_id
;
445 for (i
= IWL_STA_ID
; i
< priv
->hw_setting
.max_stations
; i
++) {
446 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
452 if (!priv
->stations
[i
].used
&&
453 index
== IWL_INVALID_STATION
)
458 /* These two conditions have the same outcome, but keep them separate
459 since they have different meanings */
460 if (unlikely(index
== IWL_INVALID_STATION
)) {
461 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
465 if (priv
->stations
[index
].used
&&
466 !compare_ether_addr(priv
->stations
[index
].sta
.sta
.addr
, addr
)) {
467 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
472 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index
, print_mac(mac
, addr
));
473 station
= &priv
->stations
[index
];
475 priv
->num_stations
++;
477 /* Set up the REPLY_ADD_STA command to send to device */
478 memset(&station
->sta
, 0, sizeof(struct iwl4965_addsta_cmd
));
479 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
480 station
->sta
.mode
= 0;
481 station
->sta
.sta
.sta_id
= index
;
482 station
->sta
.station_flags
= 0;
484 #ifdef CONFIG_IWL4965_HT
485 /* BCAST station and IBSS stations do not work in HT mode */
486 if (index
!= priv
->hw_setting
.bcast_sta_id
&&
487 priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
)
488 iwl4965_set_ht_add_station(priv
, index
,
489 (struct ieee80211_ht_info
*) ht_data
);
490 #endif /*CONFIG_IWL4965_HT*/
492 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
494 /* Add station to device's station table */
495 iwl4965_send_add_station(priv
, &station
->sta
, flags
);
502 /*************** HOST COMMAND QUEUE FUNCTIONS *****/
505 * iwl4965_enqueue_hcmd - enqueue a uCode command
506 * @priv: device private data point
507 * @cmd: a point to the ucode command structure
509 * The function returns < 0 values to indicate the operation is
510 * failed. On success, it turns the index (> 0) of command in the
513 int iwl4965_enqueue_hcmd(struct iwl_priv
*priv
, struct iwl_host_cmd
*cmd
)
515 struct iwl4965_tx_queue
*txq
= &priv
->txq
[IWL_CMD_QUEUE_NUM
];
516 struct iwl4965_queue
*q
= &txq
->q
;
517 struct iwl4965_tfd_frame
*tfd
;
519 struct iwl_cmd
*out_cmd
;
521 u16 fix_size
= (u16
)(cmd
->len
+ sizeof(out_cmd
->hdr
));
522 dma_addr_t phys_addr
;
526 /* If any of the command structures end up being larger than
527 * the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
528 * we will need to increase the size of the TFD entries */
529 BUG_ON((fix_size
> TFD_MAX_PAYLOAD_SIZE
) &&
530 !(cmd
->meta
.flags
& CMD_SIZE_HUGE
));
532 if (iwl_is_rfkill(priv
)) {
533 IWL_DEBUG_INFO("Not sending command - RF KILL");
537 if (iwl4965_queue_space(q
) < ((cmd
->meta
.flags
& CMD_ASYNC
) ? 2 : 1)) {
538 IWL_ERROR("No space for Tx\n");
542 spin_lock_irqsave(&priv
->hcmd_lock
, flags
);
544 tfd
= &txq
->bd
[q
->write_ptr
];
545 memset(tfd
, 0, sizeof(*tfd
));
547 control_flags
= (u32
*) tfd
;
549 idx
= get_cmd_index(q
, q
->write_ptr
, cmd
->meta
.flags
& CMD_SIZE_HUGE
);
550 out_cmd
= &txq
->cmd
[idx
];
552 out_cmd
->hdr
.cmd
= cmd
->id
;
553 memcpy(&out_cmd
->meta
, &cmd
->meta
, sizeof(cmd
->meta
));
554 memcpy(&out_cmd
->cmd
.payload
, cmd
->data
, cmd
->len
);
556 /* At this point, the out_cmd now has all of the incoming cmd
559 out_cmd
->hdr
.flags
= 0;
560 out_cmd
->hdr
.sequence
= cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM
) |
561 INDEX_TO_SEQ(q
->write_ptr
));
562 if (out_cmd
->meta
.flags
& CMD_SIZE_HUGE
)
563 out_cmd
->hdr
.sequence
|= cpu_to_le16(SEQ_HUGE_FRAME
);
565 phys_addr
= txq
->dma_addr_cmd
+ sizeof(txq
->cmd
[0]) * idx
+
566 offsetof(struct iwl_cmd
, hdr
);
567 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, fix_size
);
569 IWL_DEBUG_HC("Sending command %s (#%x), seq: 0x%04X, "
570 "%d bytes at %d[%d]:%d\n",
571 get_cmd_string(out_cmd
->hdr
.cmd
),
572 out_cmd
->hdr
.cmd
, le16_to_cpu(out_cmd
->hdr
.sequence
),
573 fix_size
, q
->write_ptr
, idx
, IWL_CMD_QUEUE_NUM
);
575 txq
->need_update
= 1;
577 /* Set up entry in queue's byte count circular buffer */
578 priv
->cfg
->ops
->lib
->txq_update_byte_cnt_tbl(priv
, txq
, 0);
580 /* Increment and update queue's write index */
581 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
582 ret
= iwl4965_tx_queue_update_write_ptr(priv
, txq
);
584 spin_unlock_irqrestore(&priv
->hcmd_lock
, flags
);
585 return ret
? ret
: idx
;
588 static void iwl4965_set_rxon_hwcrypto(struct iwl_priv
*priv
, int hw_decrypt
)
590 struct iwl4965_rxon_cmd
*rxon
= &priv
->staging_rxon
;
593 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
595 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
599 int iwl4965_send_statistics_request(struct iwl_priv
*priv
)
602 return iwl_send_cmd_pdu(priv
, REPLY_STATISTICS_CMD
,
603 sizeof(flags
), &flags
);
607 * iwl4965_rxon_add_station - add station into station table.
609 * there is only one AP station with id= IWL_AP_ID
610 * NOTE: mutex must be held before calling this fnction
612 static int iwl4965_rxon_add_station(struct iwl_priv
*priv
,
613 const u8
*addr
, int is_ap
)
617 /* Add station to device's station table */
618 #ifdef CONFIG_IWL4965_HT
619 struct ieee80211_conf
*conf
= &priv
->hw
->conf
;
620 struct ieee80211_ht_info
*cur_ht_config
= &conf
->ht_conf
;
623 (conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) &&
624 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
625 sta_id
= iwl4965_add_station_flags(priv
, addr
, is_ap
,
628 #endif /* CONFIG_IWL4965_HT */
629 sta_id
= iwl4965_add_station_flags(priv
, addr
, is_ap
,
632 /* Set up default rate scaling table in device's station table */
633 iwl4965_add_station(priv
, addr
, is_ap
);
639 * iwl4965_check_rxon_cmd - validate RXON structure is valid
641 * NOTE: This is really only useful during development and can eventually
642 * be #ifdef'd out once the driver is stable and folks aren't actively
645 static int iwl4965_check_rxon_cmd(struct iwl4965_rxon_cmd
*rxon
)
650 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
651 error
|= le32_to_cpu(rxon
->flags
&
652 (RXON_FLG_TGJ_NARROW_BAND_MSK
|
653 RXON_FLG_RADAR_DETECT_MSK
));
655 IWL_WARNING("check 24G fields %d | %d\n",
658 error
|= (rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
) ?
659 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK
);
661 IWL_WARNING("check 52 fields %d | %d\n",
663 error
|= le32_to_cpu(rxon
->flags
& RXON_FLG_CCK_MSK
);
665 IWL_WARNING("check 52 CCK %d | %d\n",
668 error
|= (rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1;
670 IWL_WARNING("check mac addr %d | %d\n", counter
++, error
);
672 /* make sure basic rates 6Mbps and 1Mbps are supported */
673 error
|= (((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0) &&
674 ((rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0));
676 IWL_WARNING("check basic rate %d | %d\n", counter
++, error
);
678 error
|= (le16_to_cpu(rxon
->assoc_id
) > 2007);
680 IWL_WARNING("check assoc id %d | %d\n", counter
++, error
);
682 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
683 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
));
685 IWL_WARNING("check CCK and short slot %d | %d\n",
688 error
|= ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
689 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
));
691 IWL_WARNING("check CCK & auto detect %d | %d\n",
694 error
|= ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
695 RXON_FLG_TGG_PROTECT_MSK
)) == RXON_FLG_TGG_PROTECT_MSK
);
697 IWL_WARNING("check TGG and auto detect %d | %d\n",
701 IWL_WARNING("Tuning to channel %d\n",
702 le16_to_cpu(rxon
->channel
));
705 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
712 * iwl4965_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
713 * @priv: staging_rxon is compared to active_rxon
715 * If the RXON structure is changing enough to require a new tune,
716 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
717 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
719 static int iwl4965_full_rxon_required(struct iwl_priv
*priv
)
722 /* These items are only settable from the full RXON command */
723 if (!(priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) ||
724 compare_ether_addr(priv
->staging_rxon
.bssid_addr
,
725 priv
->active_rxon
.bssid_addr
) ||
726 compare_ether_addr(priv
->staging_rxon
.node_addr
,
727 priv
->active_rxon
.node_addr
) ||
728 compare_ether_addr(priv
->staging_rxon
.wlap_bssid_addr
,
729 priv
->active_rxon
.wlap_bssid_addr
) ||
730 (priv
->staging_rxon
.dev_type
!= priv
->active_rxon
.dev_type
) ||
731 (priv
->staging_rxon
.channel
!= priv
->active_rxon
.channel
) ||
732 (priv
->staging_rxon
.air_propagation
!=
733 priv
->active_rxon
.air_propagation
) ||
734 (priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
!=
735 priv
->active_rxon
.ofdm_ht_single_stream_basic_rates
) ||
736 (priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
!=
737 priv
->active_rxon
.ofdm_ht_dual_stream_basic_rates
) ||
738 (priv
->staging_rxon
.rx_chain
!= priv
->active_rxon
.rx_chain
) ||
739 (priv
->staging_rxon
.assoc_id
!= priv
->active_rxon
.assoc_id
))
742 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
743 * be updated with the RXON_ASSOC command -- however only some
744 * flag transitions are allowed using RXON_ASSOC */
746 /* Check if we are not switching bands */
747 if ((priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) !=
748 (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
))
751 /* Check if we are switching association toggle */
752 if ((priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) !=
753 (priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
))
759 static int iwl4965_send_rxon_assoc(struct iwl_priv
*priv
)
762 struct iwl4965_rx_packet
*res
= NULL
;
763 struct iwl4965_rxon_assoc_cmd rxon_assoc
;
764 struct iwl_host_cmd cmd
= {
765 .id
= REPLY_RXON_ASSOC
,
766 .len
= sizeof(rxon_assoc
),
767 .meta
.flags
= CMD_WANT_SKB
,
770 const struct iwl4965_rxon_cmd
*rxon1
= &priv
->staging_rxon
;
771 const struct iwl4965_rxon_cmd
*rxon2
= &priv
->active_rxon
;
773 if ((rxon1
->flags
== rxon2
->flags
) &&
774 (rxon1
->filter_flags
== rxon2
->filter_flags
) &&
775 (rxon1
->cck_basic_rates
== rxon2
->cck_basic_rates
) &&
776 (rxon1
->ofdm_ht_single_stream_basic_rates
==
777 rxon2
->ofdm_ht_single_stream_basic_rates
) &&
778 (rxon1
->ofdm_ht_dual_stream_basic_rates
==
779 rxon2
->ofdm_ht_dual_stream_basic_rates
) &&
780 (rxon1
->rx_chain
== rxon2
->rx_chain
) &&
781 (rxon1
->ofdm_basic_rates
== rxon2
->ofdm_basic_rates
)) {
782 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
786 rxon_assoc
.flags
= priv
->staging_rxon
.flags
;
787 rxon_assoc
.filter_flags
= priv
->staging_rxon
.filter_flags
;
788 rxon_assoc
.ofdm_basic_rates
= priv
->staging_rxon
.ofdm_basic_rates
;
789 rxon_assoc
.cck_basic_rates
= priv
->staging_rxon
.cck_basic_rates
;
790 rxon_assoc
.reserved
= 0;
791 rxon_assoc
.ofdm_ht_single_stream_basic_rates
=
792 priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
;
793 rxon_assoc
.ofdm_ht_dual_stream_basic_rates
=
794 priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
;
795 rxon_assoc
.rx_chain_select_flags
= priv
->staging_rxon
.rx_chain
;
797 rc
= iwl_send_cmd_sync(priv
, &cmd
);
801 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
802 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
803 IWL_ERROR("Bad return from REPLY_RXON_ASSOC command\n");
807 priv
->alloc_rxb_skb
--;
808 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
814 * iwl4965_commit_rxon - commit staging_rxon to hardware
816 * The RXON command in staging_rxon is committed to the hardware and
817 * the active_rxon structure is updated with the new data. This
818 * function correctly transitions out of the RXON_ASSOC_MSK state if
819 * a HW tune is required based on the RXON structure changes.
821 static int iwl4965_commit_rxon(struct iwl_priv
*priv
)
823 /* cast away the const for active_rxon in this function */
824 struct iwl4965_rxon_cmd
*active_rxon
= (void *)&priv
->active_rxon
;
825 DECLARE_MAC_BUF(mac
);
828 if (!iwl_is_alive(priv
))
831 /* always get timestamp with Rx frame */
832 priv
->staging_rxon
.flags
|= RXON_FLG_TSF2HOST_MSK
;
834 rc
= iwl4965_check_rxon_cmd(&priv
->staging_rxon
);
836 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
840 /* If we don't need to send a full RXON, we can use
841 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
842 * and other flags for the current radio configuration. */
843 if (!iwl4965_full_rxon_required(priv
)) {
844 rc
= iwl4965_send_rxon_assoc(priv
);
846 IWL_ERROR("Error setting RXON_ASSOC "
847 "configuration (%d).\n", rc
);
851 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
856 /* station table will be cleared */
857 priv
->assoc_station_added
= 0;
859 #ifdef CONFIG_IWL4965_SENSITIVITY
860 priv
->sensitivity_data
.state
= IWL_SENS_CALIB_NEED_REINIT
;
861 if (!priv
->error_recovering
)
862 priv
->start_calib
= 0;
864 iwl4965_init_sensitivity(priv
, CMD_ASYNC
, 1);
865 #endif /* CONFIG_IWL4965_SENSITIVITY */
867 /* If we are currently associated and the new config requires
868 * an RXON_ASSOC and the new config wants the associated mask enabled,
869 * we must clear the associated from the active configuration
870 * before we apply the new config */
871 if (iwl_is_associated(priv
) &&
872 (priv
->staging_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
)) {
873 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
874 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
876 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
877 sizeof(struct iwl4965_rxon_cmd
),
880 /* If the mask clearing failed then we set
881 * active_rxon back to what it was previously */
883 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
884 IWL_ERROR("Error clearing ASSOC_MSK on current "
885 "configuration (%d).\n", rc
);
890 IWL_DEBUG_INFO("Sending RXON\n"
891 "* with%s RXON_FILTER_ASSOC_MSK\n"
894 ((priv
->staging_rxon
.filter_flags
&
895 RXON_FILTER_ASSOC_MSK
) ? "" : "out"),
896 le16_to_cpu(priv
->staging_rxon
.channel
),
897 print_mac(mac
, priv
->staging_rxon
.bssid_addr
));
899 iwl4965_set_rxon_hwcrypto(priv
, priv
->cfg
->mod_params
->hw_crypto
);
900 /* Apply the new configuration */
901 rc
= iwl_send_cmd_pdu(priv
, REPLY_RXON
,
902 sizeof(struct iwl4965_rxon_cmd
), &priv
->staging_rxon
);
904 IWL_ERROR("Error setting new configuration (%d).\n", rc
);
908 iwlcore_clear_stations_table(priv
);
910 #ifdef CONFIG_IWL4965_SENSITIVITY
911 if (!priv
->error_recovering
)
912 priv
->start_calib
= 0;
914 priv
->sensitivity_data
.state
= IWL_SENS_CALIB_NEED_REINIT
;
915 iwl4965_init_sensitivity(priv
, CMD_ASYNC
, 1);
916 #endif /* CONFIG_IWL4965_SENSITIVITY */
918 memcpy(active_rxon
, &priv
->staging_rxon
, sizeof(*active_rxon
));
920 /* If we issue a new RXON command which required a tune then we must
921 * send a new TXPOWER command or we won't be able to Tx any frames */
922 rc
= iwl4965_hw_reg_send_txpower(priv
);
924 IWL_ERROR("Error setting Tx power (%d).\n", rc
);
928 /* Add the broadcast address so we can send broadcast frames */
929 if (iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0) ==
930 IWL_INVALID_STATION
) {
931 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
935 /* If we have set the ASSOC_MSK and we are in BSS mode then
936 * add the IWL_AP_ID to the station rate table */
937 if (iwl_is_associated(priv
) &&
938 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)) {
939 if (iwl4965_rxon_add_station(priv
, priv
->active_rxon
.bssid_addr
, 1)
940 == IWL_INVALID_STATION
) {
941 IWL_ERROR("Error adding AP address for transmit.\n");
944 priv
->assoc_station_added
= 1;
945 if (priv
->default_wep_key
&&
946 iwl_send_static_wepkey_cmd(priv
, 0))
947 IWL_ERROR("Could not send WEP static key.\n");
953 static int iwl4965_send_bt_config(struct iwl_priv
*priv
)
955 struct iwl4965_bt_cmd bt_cmd
= {
963 return iwl_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
964 sizeof(struct iwl4965_bt_cmd
), &bt_cmd
);
967 static int iwl4965_send_scan_abort(struct iwl_priv
*priv
)
970 struct iwl4965_rx_packet
*res
;
971 struct iwl_host_cmd cmd
= {
972 .id
= REPLY_SCAN_ABORT_CMD
,
973 .meta
.flags
= CMD_WANT_SKB
,
976 /* If there isn't a scan actively going on in the hardware
977 * then we are in between scan bands and not actually
978 * actively scanning, so don't send the abort command */
979 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
980 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
984 rc
= iwl_send_cmd_sync(priv
, &cmd
);
986 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
990 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
991 if (res
->u
.status
!= CAN_ABORT_STATUS
) {
992 /* The scan abort will return 1 for success or
993 * 2 for "failure". A failure condition can be
994 * due to simply not being in an active scan which
995 * can occur if we send the scan abort before we
996 * the microcode has notified us that a scan is
998 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res
->u
.status
);
999 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1000 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
1003 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1008 static int iwl4965_card_state_sync_callback(struct iwl_priv
*priv
,
1009 struct iwl_cmd
*cmd
,
1010 struct sk_buff
*skb
)
1018 * Use: Sets the device's internal card state to enable, disable, or halt
1020 * When in the 'enable' state the card operates as normal.
1021 * When in the 'disable' state, the card enters into a low power mode.
1022 * When in the 'halt' state, the card is shut down and must be fully
1023 * restarted to come back on.
1025 static int iwl4965_send_card_state(struct iwl_priv
*priv
, u32 flags
, u8 meta_flag
)
1027 struct iwl_host_cmd cmd
= {
1028 .id
= REPLY_CARD_STATE_CMD
,
1031 .meta
.flags
= meta_flag
,
1034 if (meta_flag
& CMD_ASYNC
)
1035 cmd
.meta
.u
.callback
= iwl4965_card_state_sync_callback
;
1037 return iwl_send_cmd(priv
, &cmd
);
1040 static int iwl4965_add_sta_sync_callback(struct iwl_priv
*priv
,
1041 struct iwl_cmd
*cmd
, struct sk_buff
*skb
)
1043 struct iwl4965_rx_packet
*res
= NULL
;
1046 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
1050 res
= (struct iwl4965_rx_packet
*)skb
->data
;
1051 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1052 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1057 switch (res
->u
.add_sta
.status
) {
1058 case ADD_STA_SUCCESS_MSK
:
1064 /* We didn't cache the SKB; let the caller free it */
1068 int iwl4965_send_add_station(struct iwl_priv
*priv
,
1069 struct iwl4965_addsta_cmd
*sta
, u8 flags
)
1071 struct iwl4965_rx_packet
*res
= NULL
;
1073 struct iwl_host_cmd cmd
= {
1074 .id
= REPLY_ADD_STA
,
1075 .len
= sizeof(struct iwl4965_addsta_cmd
),
1076 .meta
.flags
= flags
,
1080 if (flags
& CMD_ASYNC
)
1081 cmd
.meta
.u
.callback
= iwl4965_add_sta_sync_callback
;
1083 cmd
.meta
.flags
|= CMD_WANT_SKB
;
1085 rc
= iwl_send_cmd(priv
, &cmd
);
1087 if (rc
|| (flags
& CMD_ASYNC
))
1090 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
1091 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
1092 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
1098 switch (res
->u
.add_sta
.status
) {
1099 case ADD_STA_SUCCESS_MSK
:
1100 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
1104 IWL_WARNING("REPLY_ADD_STA failed\n");
1109 priv
->alloc_rxb_skb
--;
1110 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
1115 static void iwl4965_clear_free_frames(struct iwl_priv
*priv
)
1117 struct list_head
*element
;
1119 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
1120 priv
->frames_count
);
1122 while (!list_empty(&priv
->free_frames
)) {
1123 element
= priv
->free_frames
.next
;
1125 kfree(list_entry(element
, struct iwl4965_frame
, list
));
1126 priv
->frames_count
--;
1129 if (priv
->frames_count
) {
1130 IWL_WARNING("%d frames still in use. Did we lose one?\n",
1131 priv
->frames_count
);
1132 priv
->frames_count
= 0;
1136 static struct iwl4965_frame
*iwl4965_get_free_frame(struct iwl_priv
*priv
)
1138 struct iwl4965_frame
*frame
;
1139 struct list_head
*element
;
1140 if (list_empty(&priv
->free_frames
)) {
1141 frame
= kzalloc(sizeof(*frame
), GFP_KERNEL
);
1143 IWL_ERROR("Could not allocate frame!\n");
1147 priv
->frames_count
++;
1151 element
= priv
->free_frames
.next
;
1153 return list_entry(element
, struct iwl4965_frame
, list
);
1156 static void iwl4965_free_frame(struct iwl_priv
*priv
, struct iwl4965_frame
*frame
)
1158 memset(frame
, 0, sizeof(*frame
));
1159 list_add(&frame
->list
, &priv
->free_frames
);
1162 unsigned int iwl4965_fill_beacon_frame(struct iwl_priv
*priv
,
1163 struct ieee80211_hdr
*hdr
,
1164 const u8
*dest
, int left
)
1167 if (!iwl_is_associated(priv
) || !priv
->ibss_beacon
||
1168 ((priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) &&
1169 (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
)))
1172 if (priv
->ibss_beacon
->len
> left
)
1175 memcpy(hdr
, priv
->ibss_beacon
->data
, priv
->ibss_beacon
->len
);
1177 return priv
->ibss_beacon
->len
;
1180 static u8
iwl4965_rate_get_lowest_plcp(int rate_mask
)
1184 for (i
= IWL_RATE_1M_INDEX
; i
!= IWL_RATE_INVALID
;
1185 i
= iwl4965_rates
[i
].next_ieee
) {
1186 if (rate_mask
& (1 << i
))
1187 return iwl4965_rates
[i
].plcp
;
1190 return IWL_RATE_INVALID
;
1193 static int iwl4965_send_beacon_cmd(struct iwl_priv
*priv
)
1195 struct iwl4965_frame
*frame
;
1196 unsigned int frame_size
;
1200 frame
= iwl4965_get_free_frame(priv
);
1203 IWL_ERROR("Could not obtain free frame buffer for beacon "
1208 if (!(priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)) {
1209 rate
= iwl4965_rate_get_lowest_plcp(priv
->active_rate_basic
&
1211 if (rate
== IWL_INVALID_RATE
)
1212 rate
= IWL_RATE_6M_PLCP
;
1214 rate
= iwl4965_rate_get_lowest_plcp(priv
->active_rate_basic
& 0xF);
1215 if (rate
== IWL_INVALID_RATE
)
1216 rate
= IWL_RATE_1M_PLCP
;
1219 frame_size
= iwl4965_hw_get_beacon_cmd(priv
, frame
, rate
);
1221 rc
= iwl_send_cmd_pdu(priv
, REPLY_TX_BEACON
, frame_size
,
1224 iwl4965_free_frame(priv
, frame
);
1229 /******************************************************************************
1231 * Misc. internal state and helper functions
1233 ******************************************************************************/
1235 static void iwl4965_unset_hw_setting(struct iwl_priv
*priv
)
1237 if (priv
->hw_setting
.shared_virt
)
1238 pci_free_consistent(priv
->pci_dev
,
1239 sizeof(struct iwl4965_shared
),
1240 priv
->hw_setting
.shared_virt
,
1241 priv
->hw_setting
.shared_phys
);
1245 * iwl4965_supported_rate_to_ie - fill in the supported rate in IE field
1247 * return : set the bit for each supported rate insert in ie
1249 static u16
iwl4965_supported_rate_to_ie(u8
*ie
, u16 supported_rate
,
1250 u16 basic_rate
, int *left
)
1252 u16 ret_rates
= 0, bit
;
1257 for (bit
= 1, i
= 0; i
< IWL_RATE_COUNT
; i
++, bit
<<= 1) {
1258 if (bit
& supported_rate
) {
1260 rates
[*cnt
] = iwl4965_rates
[i
].ieee
|
1261 ((bit
& basic_rate
) ? 0x80 : 0x00);
1265 (*cnt
>= IWL_SUPPORTED_RATES_IE_LEN
))
1274 * iwl4965_fill_probe_req - fill in all required fields and IE for probe request
1276 static u16
iwl4965_fill_probe_req(struct iwl_priv
*priv
,
1277 enum ieee80211_band band
,
1278 struct ieee80211_mgmt
*frame
,
1279 int left
, int is_direct
)
1283 u16 active_rates
, ret_rates
, cck_rates
, active_rate_basic
;
1284 #ifdef CONFIG_IWL4965_HT
1285 const struct ieee80211_supported_band
*sband
=
1286 iwl4965_get_hw_mode(priv
, band
);
1287 #endif /* CONFIG_IWL4965_HT */
1289 /* Make sure there is enough space for the probe request,
1290 * two mandatory IEs and the data */
1296 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
1297 memcpy(frame
->da
, iwl4965_broadcast_addr
, ETH_ALEN
);
1298 memcpy(frame
->sa
, priv
->mac_addr
, ETH_ALEN
);
1299 memcpy(frame
->bssid
, iwl4965_broadcast_addr
, ETH_ALEN
);
1300 frame
->seq_ctrl
= 0;
1302 /* fill in our indirect SSID IE */
1309 pos
= &(frame
->u
.probe_req
.variable
[0]);
1310 *pos
++ = WLAN_EID_SSID
;
1313 /* fill in our direct SSID IE... */
1316 left
-= 2 + priv
->essid_len
;
1319 /* ... fill it in... */
1320 *pos
++ = WLAN_EID_SSID
;
1321 *pos
++ = priv
->essid_len
;
1322 memcpy(pos
, priv
->essid
, priv
->essid_len
);
1323 pos
+= priv
->essid_len
;
1324 len
+= 2 + priv
->essid_len
;
1327 /* fill in supported rate */
1333 /* ... fill it in... */
1334 *pos
++ = WLAN_EID_SUPP_RATES
;
1337 /* exclude 60M rate */
1338 active_rates
= priv
->rates_mask
;
1339 active_rates
&= ~IWL_RATE_60M_MASK
;
1341 active_rate_basic
= active_rates
& IWL_BASIC_RATES_MASK
;
1343 cck_rates
= IWL_CCK_RATES_MASK
& active_rates
;
1344 ret_rates
= iwl4965_supported_rate_to_ie(pos
, cck_rates
,
1345 active_rate_basic
, &left
);
1346 active_rates
&= ~ret_rates
;
1348 ret_rates
= iwl4965_supported_rate_to_ie(pos
, active_rates
,
1349 active_rate_basic
, &left
);
1350 active_rates
&= ~ret_rates
;
1354 if (active_rates
== 0)
1357 /* fill in supported extended rate */
1362 /* ... fill it in... */
1363 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
1365 iwl4965_supported_rate_to_ie(pos
, active_rates
,
1366 active_rate_basic
, &left
);
1370 #ifdef CONFIG_IWL4965_HT
1371 if (sband
&& sband
->ht_info
.ht_supported
) {
1372 struct ieee80211_ht_cap
*ht_cap
;
1374 *pos
++ = WLAN_EID_HT_CAPABILITY
;
1375 *pos
++ = sizeof(struct ieee80211_ht_cap
);
1376 ht_cap
= (struct ieee80211_ht_cap
*)pos
;
1377 ht_cap
->cap_info
= cpu_to_le16(sband
->ht_info
.cap
);
1378 memcpy(ht_cap
->supp_mcs_set
, sband
->ht_info
.supp_mcs_set
, 16);
1379 ht_cap
->ampdu_params_info
=(sband
->ht_info
.ampdu_factor
&
1380 IEEE80211_HT_CAP_AMPDU_FACTOR
) |
1381 ((sband
->ht_info
.ampdu_density
<< 2) &
1382 IEEE80211_HT_CAP_AMPDU_DENSITY
);
1383 len
+= 2 + sizeof(struct ieee80211_ht_cap
);
1385 #endif /*CONFIG_IWL4965_HT */
1394 static int iwl4965_send_qos_params_command(struct iwl_priv
*priv
,
1395 struct iwl4965_qosparam_cmd
*qos
)
1398 return iwl_send_cmd_pdu(priv
, REPLY_QOS_PARAM
,
1399 sizeof(struct iwl4965_qosparam_cmd
), qos
);
1402 static void iwl4965_activate_qos(struct iwl_priv
*priv
, u8 force
)
1404 unsigned long flags
;
1406 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1409 if (!priv
->qos_data
.qos_enable
)
1412 spin_lock_irqsave(&priv
->lock
, flags
);
1413 priv
->qos_data
.def_qos_parm
.qos_flags
= 0;
1415 if (priv
->qos_data
.qos_cap
.q_AP
.queue_request
&&
1416 !priv
->qos_data
.qos_cap
.q_AP
.txop_request
)
1417 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1418 QOS_PARAM_FLG_TXOP_TYPE_MSK
;
1419 if (priv
->qos_data
.qos_active
)
1420 priv
->qos_data
.def_qos_parm
.qos_flags
|=
1421 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
1423 #ifdef CONFIG_IWL4965_HT
1424 if (priv
->current_ht_config
.is_ht
)
1425 priv
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
1426 #endif /* CONFIG_IWL4965_HT */
1428 spin_unlock_irqrestore(&priv
->lock
, flags
);
1430 if (force
|| iwl_is_associated(priv
)) {
1431 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
1432 priv
->qos_data
.qos_active
,
1433 priv
->qos_data
.def_qos_parm
.qos_flags
);
1435 iwl4965_send_qos_params_command(priv
,
1436 &(priv
->qos_data
.def_qos_parm
));
1441 * Power management (not Tx power!) functions
1443 #define MSEC_TO_USEC 1024
1445 #define NOSLP __constant_cpu_to_le16(0), 0, 0
1446 #define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
1447 #define SLP_TIMEOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
1448 #define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
1449 __constant_cpu_to_le32(X1), \
1450 __constant_cpu_to_le32(X2), \
1451 __constant_cpu_to_le32(X3), \
1452 __constant_cpu_to_le32(X4)}
1455 /* default power management (not Tx power) table values */
1457 static struct iwl4965_power_vec_entry range_0
[IWL_POWER_AC
] = {
1458 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1459 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
1460 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300), SLP_VEC(2, 4, 6, 7, 7)}, 0},
1461 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100), SLP_VEC(2, 6, 9, 9, 10)}, 0},
1462 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 10)}, 1},
1463 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25), SLP_VEC(4, 7, 10, 10, 10)}, 1}
1467 static struct iwl4965_power_vec_entry range_1
[IWL_POWER_AC
] = {
1468 {{NOSLP
, SLP_TIMEOUT(0), SLP_TIMEOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
1469 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(500),
1470 SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
1471 {{SLP
, SLP_TIMEOUT(200), SLP_TIMEOUT(300),
1472 SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
1473 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(100),
1474 SLP_VEC(2, 6, 9, 9, 0xFF)}, 0},
1475 {{SLP
, SLP_TIMEOUT(50), SLP_TIMEOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
1476 {{SLP
, SLP_TIMEOUT(25), SLP_TIMEOUT(25),
1477 SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
1480 int iwl4965_power_init_handle(struct iwl_priv
*priv
)
1483 struct iwl4965_power_mgr
*pow_data
;
1484 int size
= sizeof(struct iwl4965_power_vec_entry
) * IWL_POWER_AC
;
1487 IWL_DEBUG_POWER("Initialize power \n");
1489 pow_data
= &(priv
->power_data
);
1491 memset(pow_data
, 0, sizeof(*pow_data
));
1493 pow_data
->active_index
= IWL_POWER_RANGE_0
;
1494 pow_data
->dtim_val
= 0xffff;
1496 memcpy(&pow_data
->pwr_range_0
[0], &range_0
[0], size
);
1497 memcpy(&pow_data
->pwr_range_1
[0], &range_1
[0], size
);
1499 rc
= pci_read_config_word(priv
->pci_dev
, PCI_LINK_CTRL
, &pci_pm
);
1503 struct iwl4965_powertable_cmd
*cmd
;
1505 IWL_DEBUG_POWER("adjust power command flags\n");
1507 for (i
= 0; i
< IWL_POWER_AC
; i
++) {
1508 cmd
= &pow_data
->pwr_range_0
[i
].cmd
;
1511 cmd
->flags
&= ~IWL_POWER_PCI_PM_MSK
;
1513 cmd
->flags
|= IWL_POWER_PCI_PM_MSK
;
1519 static int iwl4965_update_power_cmd(struct iwl_priv
*priv
,
1520 struct iwl4965_powertable_cmd
*cmd
, u32 mode
)
1525 struct iwl4965_power_vec_entry
*range
;
1527 struct iwl4965_power_mgr
*pow_data
;
1529 if (mode
> IWL_POWER_INDEX_5
) {
1530 IWL_DEBUG_POWER("Error invalid power mode \n");
1533 pow_data
= &(priv
->power_data
);
1535 if (pow_data
->active_index
== IWL_POWER_RANGE_0
)
1536 range
= &pow_data
->pwr_range_0
[0];
1538 range
= &pow_data
->pwr_range_1
[1];
1540 memcpy(cmd
, &range
[mode
].cmd
, sizeof(struct iwl4965_powertable_cmd
));
1542 #ifdef IWL_MAC80211_DISABLE
1543 if (priv
->assoc_network
!= NULL
) {
1544 unsigned long flags
;
1546 period
= priv
->assoc_network
->tim
.tim_period
;
1548 #endif /*IWL_MAC80211_DISABLE */
1549 skip
= range
[mode
].no_dtim
;
1558 cmd
->flags
&= ~IWL_POWER_SLEEP_OVER_DTIM_MSK
;
1560 __le32 slp_itrvl
= cmd
->sleep_interval
[IWL_POWER_VEC_SIZE
- 1];
1561 max_sleep
= (le32_to_cpu(slp_itrvl
) / period
) * period
;
1562 cmd
->flags
|= IWL_POWER_SLEEP_OVER_DTIM_MSK
;
1565 for (i
= 0; i
< IWL_POWER_VEC_SIZE
; i
++) {
1566 if (le32_to_cpu(cmd
->sleep_interval
[i
]) > max_sleep
)
1567 cmd
->sleep_interval
[i
] = cpu_to_le32(max_sleep
);
1570 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd
->flags
);
1571 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd
->tx_data_timeout
));
1572 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd
->rx_data_timeout
));
1573 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
1574 le32_to_cpu(cmd
->sleep_interval
[0]),
1575 le32_to_cpu(cmd
->sleep_interval
[1]),
1576 le32_to_cpu(cmd
->sleep_interval
[2]),
1577 le32_to_cpu(cmd
->sleep_interval
[3]),
1578 le32_to_cpu(cmd
->sleep_interval
[4]));
1583 static int iwl4965_send_power_mode(struct iwl_priv
*priv
, u32 mode
)
1585 u32
uninitialized_var(final_mode
);
1587 struct iwl4965_powertable_cmd cmd
;
1589 /* If on battery, set to 3,
1590 * if plugged into AC power, set to CAM ("continuously aware mode"),
1591 * else user level */
1593 case IWL_POWER_BATTERY
:
1594 final_mode
= IWL_POWER_INDEX_3
;
1597 final_mode
= IWL_POWER_MODE_CAM
;
1604 cmd
.keep_alive_beacons
= 0;
1606 iwl4965_update_power_cmd(priv
, &cmd
, final_mode
);
1608 rc
= iwl_send_cmd_pdu(priv
, POWER_TABLE_CMD
, sizeof(cmd
), &cmd
);
1610 if (final_mode
== IWL_POWER_MODE_CAM
)
1611 clear_bit(STATUS_POWER_PMI
, &priv
->status
);
1613 set_bit(STATUS_POWER_PMI
, &priv
->status
);
1618 int iwl4965_is_network_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
1620 /* Filter incoming packets to determine if they are targeted toward
1621 * this network, discarding packets coming from ourselves */
1622 switch (priv
->iw_mode
) {
1623 case IEEE80211_IF_TYPE_IBSS
: /* Header: Dest. | Source | BSSID */
1624 /* packets from our adapter are dropped (echo) */
1625 if (!compare_ether_addr(header
->addr2
, priv
->mac_addr
))
1627 /* {broad,multi}cast packets to our IBSS go through */
1628 if (is_multicast_ether_addr(header
->addr1
))
1629 return !compare_ether_addr(header
->addr3
, priv
->bssid
);
1630 /* packets to our adapter go through */
1631 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
1632 case IEEE80211_IF_TYPE_STA
: /* Header: Dest. | AP{BSSID} | Source */
1633 /* packets from our adapter are dropped (echo) */
1634 if (!compare_ether_addr(header
->addr3
, priv
->mac_addr
))
1636 /* {broad,multi}cast packets to our BSS go through */
1637 if (is_multicast_ether_addr(header
->addr1
))
1638 return !compare_ether_addr(header
->addr2
, priv
->bssid
);
1639 /* packets to our adapter go through */
1640 return !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
1648 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1650 static const char *iwl4965_get_tx_fail_reason(u32 status
)
1652 switch (status
& TX_STATUS_MSK
) {
1653 case TX_STATUS_SUCCESS
:
1655 TX_STATUS_ENTRY(SHORT_LIMIT
);
1656 TX_STATUS_ENTRY(LONG_LIMIT
);
1657 TX_STATUS_ENTRY(FIFO_UNDERRUN
);
1658 TX_STATUS_ENTRY(MGMNT_ABORT
);
1659 TX_STATUS_ENTRY(NEXT_FRAG
);
1660 TX_STATUS_ENTRY(LIFE_EXPIRE
);
1661 TX_STATUS_ENTRY(DEST_PS
);
1662 TX_STATUS_ENTRY(ABORTED
);
1663 TX_STATUS_ENTRY(BT_RETRY
);
1664 TX_STATUS_ENTRY(STA_INVALID
);
1665 TX_STATUS_ENTRY(FRAG_DROPPED
);
1666 TX_STATUS_ENTRY(TID_DISABLE
);
1667 TX_STATUS_ENTRY(FRAME_FLUSHED
);
1668 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL
);
1669 TX_STATUS_ENTRY(TX_LOCKED
);
1670 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR
);
1677 * iwl4965_scan_cancel - Cancel any currently executing HW scan
1679 * NOTE: priv->mutex is not required before calling this function
1681 static int iwl4965_scan_cancel(struct iwl_priv
*priv
)
1683 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
1684 clear_bit(STATUS_SCANNING
, &priv
->status
);
1688 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1689 if (!test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1690 IWL_DEBUG_SCAN("Queuing scan abort.\n");
1691 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
1692 queue_work(priv
->workqueue
, &priv
->abort_scan
);
1695 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
1697 return test_bit(STATUS_SCANNING
, &priv
->status
);
1704 * iwl4965_scan_cancel_timeout - Cancel any currently executing HW scan
1705 * @ms: amount of time to wait (in milliseconds) for scan to abort
1707 * NOTE: priv->mutex must be held before calling this function
1709 static int iwl4965_scan_cancel_timeout(struct iwl_priv
*priv
, unsigned long ms
)
1711 unsigned long now
= jiffies
;
1714 ret
= iwl4965_scan_cancel(priv
);
1716 mutex_unlock(&priv
->mutex
);
1717 while (!time_after(jiffies
, now
+ msecs_to_jiffies(ms
)) &&
1718 test_bit(STATUS_SCANNING
, &priv
->status
))
1720 mutex_lock(&priv
->mutex
);
1722 return test_bit(STATUS_SCANNING
, &priv
->status
);
1728 static void iwl4965_sequence_reset(struct iwl_priv
*priv
)
1730 /* Reset ieee stats */
1732 /* We don't reset the net_device_stats (ieee->stats) on
1735 priv
->last_seq_num
= -1;
1736 priv
->last_frag_num
= -1;
1737 priv
->last_packet_time
= 0;
1739 iwl4965_scan_cancel(priv
);
1742 #define MAX_UCODE_BEACON_INTERVAL 4096
1743 #define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
1745 static __le16
iwl4965_adjust_beacon_interval(u16 beacon_val
)
1748 u16 beacon_factor
= 0;
1751 (beacon_val
+ MAX_UCODE_BEACON_INTERVAL
)
1752 / MAX_UCODE_BEACON_INTERVAL
;
1753 new_val
= beacon_val
/ beacon_factor
;
1755 return cpu_to_le16(new_val
);
1758 static void iwl4965_setup_rxon_timing(struct iwl_priv
*priv
)
1760 u64 interval_tm_unit
;
1762 unsigned long flags
;
1763 struct ieee80211_conf
*conf
= NULL
;
1766 conf
= ieee80211_get_hw_conf(priv
->hw
);
1768 spin_lock_irqsave(&priv
->lock
, flags
);
1769 priv
->rxon_timing
.timestamp
.dw
[1] = cpu_to_le32(priv
->timestamp
>> 32);
1770 priv
->rxon_timing
.timestamp
.dw
[0] =
1771 cpu_to_le32(priv
->timestamp
& 0xFFFFFFFF);
1773 priv
->rxon_timing
.listen_interval
= INTEL_CONN_LISTEN_INTERVAL
;
1775 tsf
= priv
->timestamp
;
1777 beacon_int
= priv
->beacon_int
;
1778 spin_unlock_irqrestore(&priv
->lock
, flags
);
1780 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
1781 if (beacon_int
== 0) {
1782 priv
->rxon_timing
.beacon_interval
= cpu_to_le16(100);
1783 priv
->rxon_timing
.beacon_init_val
= cpu_to_le32(102400);
1785 priv
->rxon_timing
.beacon_interval
=
1786 cpu_to_le16(beacon_int
);
1787 priv
->rxon_timing
.beacon_interval
=
1788 iwl4965_adjust_beacon_interval(
1789 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
1792 priv
->rxon_timing
.atim_window
= 0;
1794 priv
->rxon_timing
.beacon_interval
=
1795 iwl4965_adjust_beacon_interval(conf
->beacon_int
);
1796 /* TODO: we need to get atim_window from upper stack
1797 * for now we set to 0 */
1798 priv
->rxon_timing
.atim_window
= 0;
1802 (le16_to_cpu(priv
->rxon_timing
.beacon_interval
) * 1024);
1803 result
= do_div(tsf
, interval_tm_unit
);
1804 priv
->rxon_timing
.beacon_init_val
=
1805 cpu_to_le32((u32
) ((u64
) interval_tm_unit
- result
));
1808 ("beacon interval %d beacon timer %d beacon tim %d\n",
1809 le16_to_cpu(priv
->rxon_timing
.beacon_interval
),
1810 le32_to_cpu(priv
->rxon_timing
.beacon_init_val
),
1811 le16_to_cpu(priv
->rxon_timing
.atim_window
));
1814 static int iwl4965_scan_initiate(struct iwl_priv
*priv
)
1816 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
1817 IWL_ERROR("APs don't scan.\n");
1821 if (!iwl_is_ready_rf(priv
)) {
1822 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
1826 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
1827 IWL_DEBUG_SCAN("Scan already in progress.\n");
1831 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
1832 IWL_DEBUG_SCAN("Scan request while abort pending. "
1837 IWL_DEBUG_INFO("Starting scan...\n");
1838 priv
->scan_bands
= 2;
1839 set_bit(STATUS_SCANNING
, &priv
->status
);
1840 priv
->scan_start
= jiffies
;
1841 priv
->scan_pass_start
= priv
->scan_start
;
1843 queue_work(priv
->workqueue
, &priv
->request_scan
);
1849 static void iwl4965_set_flags_for_phymode(struct iwl_priv
*priv
,
1850 enum ieee80211_band band
)
1852 if (band
== IEEE80211_BAND_5GHZ
) {
1853 priv
->staging_rxon
.flags
&=
1854 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
1855 | RXON_FLG_CCK_MSK
);
1856 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1858 /* Copied from iwl4965_bg_post_associate() */
1859 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
1860 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1862 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1864 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
1865 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1867 priv
->staging_rxon
.flags
|= RXON_FLG_BAND_24G_MSK
;
1868 priv
->staging_rxon
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
1869 priv
->staging_rxon
.flags
&= ~RXON_FLG_CCK_MSK
;
1874 * initialize rxon structure with default values from eeprom
1876 static void iwl4965_connection_init_rx_config(struct iwl_priv
*priv
)
1878 const struct iwl_channel_info
*ch_info
;
1880 memset(&priv
->staging_rxon
, 0, sizeof(priv
->staging_rxon
));
1882 switch (priv
->iw_mode
) {
1883 case IEEE80211_IF_TYPE_AP
:
1884 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_AP
;
1887 case IEEE80211_IF_TYPE_STA
:
1888 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_ESS
;
1889 priv
->staging_rxon
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
1892 case IEEE80211_IF_TYPE_IBSS
:
1893 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_IBSS
;
1894 priv
->staging_rxon
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
1895 priv
->staging_rxon
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
1896 RXON_FILTER_ACCEPT_GRP_MSK
;
1899 case IEEE80211_IF_TYPE_MNTR
:
1900 priv
->staging_rxon
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
1901 priv
->staging_rxon
.filter_flags
= RXON_FILTER_PROMISC_MSK
|
1902 RXON_FILTER_CTL2HOST_MSK
| RXON_FILTER_ACCEPT_GRP_MSK
;
1905 IWL_ERROR("Unsupported interface type %d\n", priv
->iw_mode
);
1910 /* TODO: Figure out when short_preamble would be set and cache from
1912 if (!hw_to_local(priv
->hw
)->short_preamble
)
1913 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
1915 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
1918 ch_info
= iwl_get_channel_info(priv
, priv
->band
,
1919 le16_to_cpu(priv
->staging_rxon
.channel
));
1922 ch_info
= &priv
->channel_info
[0];
1925 * in some case A channels are all non IBSS
1926 * in this case force B/G channel
1928 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) &&
1929 !(is_channel_ibss(ch_info
)))
1930 ch_info
= &priv
->channel_info
[0];
1932 priv
->staging_rxon
.channel
= cpu_to_le16(ch_info
->channel
);
1933 priv
->band
= ch_info
->band
;
1935 iwl4965_set_flags_for_phymode(priv
, priv
->band
);
1937 priv
->staging_rxon
.ofdm_basic_rates
=
1938 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
1939 priv
->staging_rxon
.cck_basic_rates
=
1940 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
1942 priv
->staging_rxon
.flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK
|
1943 RXON_FLG_CHANNEL_MODE_PURE_40_MSK
);
1944 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
1945 memcpy(priv
->staging_rxon
.wlap_bssid_addr
, priv
->mac_addr
, ETH_ALEN
);
1946 priv
->staging_rxon
.ofdm_ht_single_stream_basic_rates
= 0xff;
1947 priv
->staging_rxon
.ofdm_ht_dual_stream_basic_rates
= 0xff;
1948 iwl4965_set_rxon_chain(priv
);
1951 static int iwl4965_set_mode(struct iwl_priv
*priv
, int mode
)
1953 if (mode
== IEEE80211_IF_TYPE_IBSS
) {
1954 const struct iwl_channel_info
*ch_info
;
1956 ch_info
= iwl_get_channel_info(priv
,
1958 le16_to_cpu(priv
->staging_rxon
.channel
));
1960 if (!ch_info
|| !is_channel_ibss(ch_info
)) {
1961 IWL_ERROR("channel %d not IBSS channel\n",
1962 le16_to_cpu(priv
->staging_rxon
.channel
));
1967 priv
->iw_mode
= mode
;
1969 iwl4965_connection_init_rx_config(priv
);
1970 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
1972 iwlcore_clear_stations_table(priv
);
1974 /* dont commit rxon if rf-kill is on*/
1975 if (!iwl_is_ready_rf(priv
))
1978 cancel_delayed_work(&priv
->scan_check
);
1979 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
1980 IWL_WARNING("Aborted scan still in progress after 100ms\n");
1981 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
1985 iwl4965_commit_rxon(priv
);
1990 static void iwl4965_build_tx_cmd_hwcrypto(struct iwl_priv
*priv
,
1991 struct ieee80211_tx_control
*ctl
,
1992 struct iwl_cmd
*cmd
,
1993 struct sk_buff
*skb_frag
,
1996 struct iwl4965_hw_key
*keyinfo
= &priv
->stations
[sta_id
].keyinfo
;
1997 struct iwl_wep_key
*wepkey
;
2000 BUG_ON(ctl
->key_idx
> 3);
2002 switch (keyinfo
->alg
) {
2004 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_CCM
;
2005 memcpy(cmd
->cmd
.tx
.key
, keyinfo
->key
, keyinfo
->keylen
);
2006 if (ctl
->flags
& IEEE80211_TXCTL_AMPDU
)
2007 cmd
->cmd
.tx
.tx_flags
|= TX_CMD_FLG_AGG_CCMP_MSK
;
2008 IWL_DEBUG_TX("tx_cmd with aes hwcrypto\n");
2012 cmd
->cmd
.tx
.sec_ctl
= TX_CMD_SEC_TKIP
;
2013 ieee80211_get_tkip_key(keyinfo
->conf
, skb_frag
,
2014 IEEE80211_TKIP_P2_KEY
, cmd
->cmd
.tx
.key
);
2015 IWL_DEBUG_TX("tx_cmd with tkip hwcrypto\n");
2019 wepkey
= &priv
->wep_keys
[ctl
->key_idx
];
2020 cmd
->cmd
.tx
.sec_ctl
= 0;
2021 if (priv
->default_wep_key
) {
2022 /* the WEP key was sent as static */
2023 keyidx
= ctl
->key_idx
;
2024 memcpy(&cmd
->cmd
.tx
.key
[3], wepkey
->key
,
2026 if (wepkey
->key_size
== WEP_KEY_LEN_128
)
2027 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
2029 /* the WEP key was sent as dynamic */
2030 keyidx
= keyinfo
->keyidx
;
2031 memcpy(&cmd
->cmd
.tx
.key
[3], keyinfo
->key
,
2033 if (keyinfo
->keylen
== WEP_KEY_LEN_128
)
2034 cmd
->cmd
.tx
.sec_ctl
|= TX_CMD_SEC_KEY128
;
2037 cmd
->cmd
.tx
.sec_ctl
|= (TX_CMD_SEC_WEP
|
2038 (keyidx
& TX_CMD_SEC_MSK
) << TX_CMD_SEC_SHIFT
);
2040 IWL_DEBUG_TX("Configuring packet for WEP encryption "
2041 "with key %d\n", keyidx
);
2045 printk(KERN_ERR
"Unknown encode alg %d\n", keyinfo
->alg
);
2051 * handle build REPLY_TX command notification.
2053 static void iwl4965_build_tx_cmd_basic(struct iwl_priv
*priv
,
2054 struct iwl_cmd
*cmd
,
2055 struct ieee80211_tx_control
*ctrl
,
2056 struct ieee80211_hdr
*hdr
,
2057 int is_unicast
, u8 std_id
)
2060 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2061 __le32 tx_flags
= cmd
->cmd
.tx
.tx_flags
;
2063 cmd
->cmd
.tx
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
2064 if (!(ctrl
->flags
& IEEE80211_TXCTL_NO_ACK
)) {
2065 tx_flags
|= TX_CMD_FLG_ACK_MSK
;
2066 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
)
2067 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2068 if (ieee80211_is_probe_response(fc
) &&
2069 !(le16_to_cpu(hdr
->seq_ctrl
) & 0xf))
2070 tx_flags
|= TX_CMD_FLG_TSF_MSK
;
2072 tx_flags
&= (~TX_CMD_FLG_ACK_MSK
);
2073 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2076 if (ieee80211_is_back_request(fc
))
2077 tx_flags
|= TX_CMD_FLG_ACK_MSK
| TX_CMD_FLG_IMM_BA_RSP_MASK
;
2080 cmd
->cmd
.tx
.sta_id
= std_id
;
2081 if (ieee80211_get_morefrag(hdr
))
2082 tx_flags
|= TX_CMD_FLG_MORE_FRAG_MSK
;
2084 qc
= ieee80211_get_qos_ctrl(hdr
);
2086 cmd
->cmd
.tx
.tid_tspec
= (u8
) (le16_to_cpu(*qc
) & 0xf);
2087 tx_flags
&= ~TX_CMD_FLG_SEQ_CTL_MSK
;
2089 tx_flags
|= TX_CMD_FLG_SEQ_CTL_MSK
;
2091 if (ctrl
->flags
& IEEE80211_TXCTL_USE_RTS_CTS
) {
2092 tx_flags
|= TX_CMD_FLG_RTS_MSK
;
2093 tx_flags
&= ~TX_CMD_FLG_CTS_MSK
;
2094 } else if (ctrl
->flags
& IEEE80211_TXCTL_USE_CTS_PROTECT
) {
2095 tx_flags
&= ~TX_CMD_FLG_RTS_MSK
;
2096 tx_flags
|= TX_CMD_FLG_CTS_MSK
;
2099 if ((tx_flags
& TX_CMD_FLG_RTS_MSK
) || (tx_flags
& TX_CMD_FLG_CTS_MSK
))
2100 tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
2102 tx_flags
&= ~(TX_CMD_FLG_ANT_SEL_MSK
);
2103 if ((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_MGMT
) {
2104 if ((fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_ASSOC_REQ
||
2105 (fc
& IEEE80211_FCTL_STYPE
) == IEEE80211_STYPE_REASSOC_REQ
)
2106 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(3);
2108 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= cpu_to_le16(2);
2110 cmd
->cmd
.tx
.timeout
.pm_frame_timeout
= 0;
2113 cmd
->cmd
.tx
.driver_txop
= 0;
2114 cmd
->cmd
.tx
.tx_flags
= tx_flags
;
2115 cmd
->cmd
.tx
.next_frame_len
= 0;
2117 static void iwl_update_tx_stats(struct iwl_priv
*priv
, u16 fc
, u16 len
)
2119 /* 0 - mgmt, 1 - cnt, 2 - data */
2120 int idx
= (fc
& IEEE80211_FCTL_FTYPE
) >> 2;
2121 priv
->tx_stats
[idx
].cnt
++;
2122 priv
->tx_stats
[idx
].bytes
+= len
;
2125 * iwl4965_get_sta_id - Find station's index within station table
2127 * If new IBSS station, create new entry in station table
2129 static int iwl4965_get_sta_id(struct iwl_priv
*priv
,
2130 struct ieee80211_hdr
*hdr
)
2133 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2134 DECLARE_MAC_BUF(mac
);
2136 /* If this frame is broadcast or management, use broadcast station id */
2137 if (((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
) ||
2138 is_multicast_ether_addr(hdr
->addr1
))
2139 return priv
->hw_setting
.bcast_sta_id
;
2141 switch (priv
->iw_mode
) {
2143 /* If we are a client station in a BSS network, use the special
2144 * AP station entry (that's the only station we communicate with) */
2145 case IEEE80211_IF_TYPE_STA
:
2148 /* If we are an AP, then find the station, or use BCAST */
2149 case IEEE80211_IF_TYPE_AP
:
2150 sta_id
= iwl4965_hw_find_station(priv
, hdr
->addr1
);
2151 if (sta_id
!= IWL_INVALID_STATION
)
2153 return priv
->hw_setting
.bcast_sta_id
;
2155 /* If this frame is going out to an IBSS network, find the station,
2156 * or create a new station table entry */
2157 case IEEE80211_IF_TYPE_IBSS
:
2158 sta_id
= iwl4965_hw_find_station(priv
, hdr
->addr1
);
2159 if (sta_id
!= IWL_INVALID_STATION
)
2162 /* Create new station table entry */
2163 sta_id
= iwl4965_add_station_flags(priv
, hdr
->addr1
,
2164 0, CMD_ASYNC
, NULL
);
2166 if (sta_id
!= IWL_INVALID_STATION
)
2169 IWL_DEBUG_DROP("Station %s not in station map. "
2170 "Defaulting to broadcast...\n",
2171 print_mac(mac
, hdr
->addr1
));
2172 iwl_print_hex_dump(IWL_DL_DROP
, (u8
*) hdr
, sizeof(*hdr
));
2173 return priv
->hw_setting
.bcast_sta_id
;
2176 IWL_WARNING("Unknown mode of operation: %d", priv
->iw_mode
);
2177 return priv
->hw_setting
.bcast_sta_id
;
2182 * start REPLY_TX command process
2184 static int iwl4965_tx_skb(struct iwl_priv
*priv
,
2185 struct sk_buff
*skb
, struct ieee80211_tx_control
*ctl
)
2187 struct ieee80211_hdr
*hdr
= (struct ieee80211_hdr
*)skb
->data
;
2188 struct iwl4965_tfd_frame
*tfd
;
2190 int txq_id
= ctl
->queue
;
2191 struct iwl4965_tx_queue
*txq
= NULL
;
2192 struct iwl4965_queue
*q
= NULL
;
2193 dma_addr_t phys_addr
;
2194 dma_addr_t txcmd_phys
;
2195 dma_addr_t scratch_phys
;
2196 struct iwl_cmd
*out_cmd
= NULL
;
2197 u16 len
, idx
, len_org
;
2198 u8 id
, hdr_len
, unicast
;
2203 u8 wait_write_ptr
= 0;
2204 unsigned long flags
;
2207 spin_lock_irqsave(&priv
->lock
, flags
);
2208 if (iwl_is_rfkill(priv
)) {
2209 IWL_DEBUG_DROP("Dropping - RF KILL\n");
2214 IWL_DEBUG_DROP("Dropping - !priv->vif\n");
2218 if ((ctl
->tx_rate
->hw_value
& 0xFF) == IWL_INVALID_RATE
) {
2219 IWL_ERROR("ERROR: No TX rate available.\n");
2223 unicast
= !is_multicast_ether_addr(hdr
->addr1
);
2226 fc
= le16_to_cpu(hdr
->frame_control
);
2228 #ifdef CONFIG_IWLWIFI_DEBUG
2229 if (ieee80211_is_auth(fc
))
2230 IWL_DEBUG_TX("Sending AUTH frame\n");
2231 else if (ieee80211_is_assoc_request(fc
))
2232 IWL_DEBUG_TX("Sending ASSOC frame\n");
2233 else if (ieee80211_is_reassoc_request(fc
))
2234 IWL_DEBUG_TX("Sending REASSOC frame\n");
2237 /* drop all data frame if we are not associated */
2238 if (((fc
& IEEE80211_FCTL_FTYPE
) == IEEE80211_FTYPE_DATA
) &&
2239 (!iwl_is_associated(priv
) ||
2240 ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && !priv
->assoc_id
) ||
2241 !priv
->assoc_station_added
)) {
2242 IWL_DEBUG_DROP("Dropping - !iwl_is_associated\n");
2246 spin_unlock_irqrestore(&priv
->lock
, flags
);
2248 hdr_len
= ieee80211_get_hdrlen(fc
);
2250 /* Find (or create) index into station table for destination station */
2251 sta_id
= iwl4965_get_sta_id(priv
, hdr
);
2252 if (sta_id
== IWL_INVALID_STATION
) {
2253 DECLARE_MAC_BUF(mac
);
2255 IWL_DEBUG_DROP("Dropping - INVALID STATION: %s\n",
2256 print_mac(mac
, hdr
->addr1
));
2260 IWL_DEBUG_RATE("station Id %d\n", sta_id
);
2262 qc
= ieee80211_get_qos_ctrl(hdr
);
2264 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2265 seq_number
= priv
->stations
[sta_id
].tid
[tid
].seq_number
&
2267 hdr
->seq_ctrl
= cpu_to_le16(seq_number
) |
2269 __constant_cpu_to_le16(IEEE80211_SCTL_FRAG
));
2271 #ifdef CONFIG_IWL4965_HT
2272 /* aggregation is on for this <sta,tid> */
2273 if (ctl
->flags
& IEEE80211_TXCTL_AMPDU
)
2274 txq_id
= priv
->stations
[sta_id
].tid
[tid
].agg
.txq_id
;
2275 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
++;
2276 #endif /* CONFIG_IWL4965_HT */
2279 /* Descriptor for chosen Tx queue */
2280 txq
= &priv
->txq
[txq_id
];
2283 spin_lock_irqsave(&priv
->lock
, flags
);
2285 /* Set up first empty TFD within this queue's circular TFD buffer */
2286 tfd
= &txq
->bd
[q
->write_ptr
];
2287 memset(tfd
, 0, sizeof(*tfd
));
2288 control_flags
= (u32
*) tfd
;
2289 idx
= get_cmd_index(q
, q
->write_ptr
, 0);
2291 /* Set up driver data for this TFD */
2292 memset(&(txq
->txb
[q
->write_ptr
]), 0, sizeof(struct iwl4965_tx_info
));
2293 txq
->txb
[q
->write_ptr
].skb
[0] = skb
;
2294 memcpy(&(txq
->txb
[q
->write_ptr
].status
.control
),
2295 ctl
, sizeof(struct ieee80211_tx_control
));
2297 /* Set up first empty entry in queue's array of Tx/cmd buffers */
2298 out_cmd
= &txq
->cmd
[idx
];
2299 memset(&out_cmd
->hdr
, 0, sizeof(out_cmd
->hdr
));
2300 memset(&out_cmd
->cmd
.tx
, 0, sizeof(out_cmd
->cmd
.tx
));
2303 * Set up the Tx-command (not MAC!) header.
2304 * Store the chosen Tx queue and TFD index within the sequence field;
2305 * after Tx, uCode's Tx response will return this value so driver can
2306 * locate the frame within the tx queue and do post-tx processing.
2308 out_cmd
->hdr
.cmd
= REPLY_TX
;
2309 out_cmd
->hdr
.sequence
= cpu_to_le16((u16
)(QUEUE_TO_SEQ(txq_id
) |
2310 INDEX_TO_SEQ(q
->write_ptr
)));
2312 /* Copy MAC header from skb into command buffer */
2313 memcpy(out_cmd
->cmd
.tx
.hdr
, hdr
, hdr_len
);
2316 * Use the first empty entry in this queue's command buffer array
2317 * to contain the Tx command and MAC header concatenated together
2318 * (payload data will be in another buffer).
2319 * Size of this varies, due to varying MAC header length.
2320 * If end is not dword aligned, we'll have 2 extra bytes at the end
2321 * of the MAC header (device reads on dword boundaries).
2322 * We'll tell device about this padding later.
2324 len
= priv
->hw_setting
.tx_cmd_len
+
2325 sizeof(struct iwl_cmd_header
) + hdr_len
;
2328 len
= (len
+ 3) & ~3;
2335 /* Physical address of this Tx command's header (not MAC header!),
2336 * within command buffer array. */
2337 txcmd_phys
= txq
->dma_addr_cmd
+ sizeof(struct iwl_cmd
) * idx
+
2338 offsetof(struct iwl_cmd
, hdr
);
2340 /* Add buffer containing Tx command and MAC(!) header to TFD's
2342 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, txcmd_phys
, len
);
2344 if (!(ctl
->flags
& IEEE80211_TXCTL_DO_NOT_ENCRYPT
))
2345 iwl4965_build_tx_cmd_hwcrypto(priv
, ctl
, out_cmd
, skb
, sta_id
);
2347 /* Set up TFD's 2nd entry to point directly to remainder of skb,
2348 * if any (802.11 null frames have no payload). */
2349 len
= skb
->len
- hdr_len
;
2351 phys_addr
= pci_map_single(priv
->pci_dev
, skb
->data
+ hdr_len
,
2352 len
, PCI_DMA_TODEVICE
);
2353 iwl4965_hw_txq_attach_buf_to_tfd(priv
, tfd
, phys_addr
, len
);
2356 /* Tell 4965 about any 2-byte padding after MAC header */
2358 out_cmd
->cmd
.tx
.tx_flags
|= TX_CMD_FLG_MH_PAD_MSK
;
2360 /* Total # bytes to be transmitted */
2361 len
= (u16
)skb
->len
;
2362 out_cmd
->cmd
.tx
.len
= cpu_to_le16(len
);
2364 /* TODO need this for burst mode later on */
2365 iwl4965_build_tx_cmd_basic(priv
, out_cmd
, ctl
, hdr
, unicast
, sta_id
);
2367 /* set is_hcca to 0; it probably will never be implemented */
2368 iwl4965_hw_build_tx_cmd_rate(priv
, out_cmd
, ctl
, hdr
, sta_id
, 0);
2370 iwl_update_tx_stats(priv
, fc
, len
);
2372 scratch_phys
= txcmd_phys
+ sizeof(struct iwl_cmd_header
) +
2373 offsetof(struct iwl4965_tx_cmd
, scratch
);
2374 out_cmd
->cmd
.tx
.dram_lsb_ptr
= cpu_to_le32(scratch_phys
);
2375 out_cmd
->cmd
.tx
.dram_msb_ptr
= iwl_get_dma_hi_address(scratch_phys
);
2377 if (!ieee80211_get_morefrag(hdr
)) {
2378 txq
->need_update
= 1;
2380 u8 tid
= (u8
)(le16_to_cpu(*qc
) & 0xf);
2381 priv
->stations
[sta_id
].tid
[tid
].seq_number
= seq_number
;
2385 txq
->need_update
= 0;
2388 iwl_print_hex_dump(IWL_DL_TX
, out_cmd
->cmd
.payload
,
2389 sizeof(out_cmd
->cmd
.tx
));
2391 iwl_print_hex_dump(IWL_DL_TX
, (u8
*)out_cmd
->cmd
.tx
.hdr
,
2392 ieee80211_get_hdrlen(fc
));
2394 /* Set up entry for this TFD in Tx byte-count array */
2395 priv
->cfg
->ops
->lib
->txq_update_byte_cnt_tbl(priv
, txq
, len
);
2397 /* Tell device the write index *just past* this latest filled TFD */
2398 q
->write_ptr
= iwl_queue_inc_wrap(q
->write_ptr
, q
->n_bd
);
2399 rc
= iwl4965_tx_queue_update_write_ptr(priv
, txq
);
2400 spin_unlock_irqrestore(&priv
->lock
, flags
);
2405 if ((iwl4965_queue_space(q
) < q
->high_mark
)
2406 && priv
->mac80211_registered
) {
2407 if (wait_write_ptr
) {
2408 spin_lock_irqsave(&priv
->lock
, flags
);
2409 txq
->need_update
= 1;
2410 iwl4965_tx_queue_update_write_ptr(priv
, txq
);
2411 spin_unlock_irqrestore(&priv
->lock
, flags
);
2414 ieee80211_stop_queue(priv
->hw
, ctl
->queue
);
2420 spin_unlock_irqrestore(&priv
->lock
, flags
);
2425 static void iwl4965_set_rate(struct iwl_priv
*priv
)
2427 const struct ieee80211_supported_band
*hw
= NULL
;
2428 struct ieee80211_rate
*rate
;
2431 hw
= iwl4965_get_hw_mode(priv
, priv
->band
);
2433 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
2437 priv
->active_rate
= 0;
2438 priv
->active_rate_basic
= 0;
2440 for (i
= 0; i
< hw
->n_bitrates
; i
++) {
2441 rate
= &(hw
->bitrates
[i
]);
2442 if (rate
->hw_value
< IWL_RATE_COUNT
)
2443 priv
->active_rate
|= (1 << rate
->hw_value
);
2446 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
2447 priv
->active_rate
, priv
->active_rate_basic
);
2450 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
2451 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
2454 if (priv
->active_rate_basic
& IWL_CCK_BASIC_RATES_MASK
)
2455 priv
->staging_rxon
.cck_basic_rates
=
2456 ((priv
->active_rate_basic
&
2457 IWL_CCK_RATES_MASK
) >> IWL_FIRST_CCK_RATE
) & 0xF;
2459 priv
->staging_rxon
.cck_basic_rates
=
2460 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
2462 if (priv
->active_rate_basic
& IWL_OFDM_BASIC_RATES_MASK
)
2463 priv
->staging_rxon
.ofdm_basic_rates
=
2464 ((priv
->active_rate_basic
&
2465 (IWL_OFDM_BASIC_RATES_MASK
| IWL_RATE_6M_MASK
)) >>
2466 IWL_FIRST_OFDM_RATE
) & 0xFF;
2468 priv
->staging_rxon
.ofdm_basic_rates
=
2469 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
2472 void iwl4965_radio_kill_sw(struct iwl_priv
*priv
, int disable_radio
)
2474 unsigned long flags
;
2476 if (!!disable_radio
== test_bit(STATUS_RF_KILL_SW
, &priv
->status
))
2479 IWL_DEBUG_RF_KILL("Manual SW RF KILL set to: RADIO %s\n",
2480 disable_radio
? "OFF" : "ON");
2482 if (disable_radio
) {
2483 iwl4965_scan_cancel(priv
);
2484 /* FIXME: This is a workaround for AP */
2485 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
2486 spin_lock_irqsave(&priv
->lock
, flags
);
2487 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
2488 CSR_UCODE_SW_BIT_RFKILL
);
2489 spin_unlock_irqrestore(&priv
->lock
, flags
);
2490 /* call the host command only if no hw rf-kill set */
2491 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
2492 iwl4965_send_card_state(priv
,
2493 CARD_STATE_CMD_DISABLE
,
2495 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2497 /* make sure mac80211 stop sending Tx frame */
2498 if (priv
->mac80211_registered
)
2499 ieee80211_stop_queues(priv
->hw
);
2504 spin_lock_irqsave(&priv
->lock
, flags
);
2505 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
2507 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
2508 spin_unlock_irqrestore(&priv
->lock
, flags
);
2513 spin_lock_irqsave(&priv
->lock
, flags
);
2514 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
2515 if (!iwl_grab_nic_access(priv
))
2516 iwl_release_nic_access(priv
);
2517 spin_unlock_irqrestore(&priv
->lock
, flags
);
2519 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) {
2520 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2521 "disabled by HW switch\n");
2525 queue_work(priv
->workqueue
, &priv
->restart
);
2529 void iwl4965_set_decrypted_flag(struct iwl_priv
*priv
, struct sk_buff
*skb
,
2530 u32 decrypt_res
, struct ieee80211_rx_status
*stats
)
2533 le16_to_cpu(((struct ieee80211_hdr
*)skb
->data
)->frame_control
);
2535 if (priv
->active_rxon
.filter_flags
& RXON_FILTER_DIS_DECRYPT_MSK
)
2538 if (!(fc
& IEEE80211_FCTL_PROTECTED
))
2541 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res
);
2542 switch (decrypt_res
& RX_RES_STATUS_SEC_TYPE_MSK
) {
2543 case RX_RES_STATUS_SEC_TYPE_TKIP
:
2544 /* The uCode has got a bad phase 1 Key, pushes the packet.
2545 * Decryption will be done in SW. */
2546 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2547 RX_RES_STATUS_BAD_KEY_TTAK
)
2550 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2551 RX_RES_STATUS_BAD_ICV_MIC
)
2552 stats
->flag
|= RX_FLAG_MMIC_ERROR
;
2553 case RX_RES_STATUS_SEC_TYPE_WEP
:
2554 case RX_RES_STATUS_SEC_TYPE_CCMP
:
2555 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2556 RX_RES_STATUS_DECRYPT_OK
) {
2557 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2558 stats
->flag
|= RX_FLAG_DECRYPTED
;
2568 #define IWL_PACKET_RETRY_TIME HZ
2570 int iwl4965_is_duplicate_packet(struct iwl_priv
*priv
, struct ieee80211_hdr
*header
)
2572 u16 sc
= le16_to_cpu(header
->seq_ctrl
);
2573 u16 seq
= (sc
& IEEE80211_SCTL_SEQ
) >> 4;
2574 u16 frag
= sc
& IEEE80211_SCTL_FRAG
;
2575 u16
*last_seq
, *last_frag
;
2576 unsigned long *last_time
;
2578 switch (priv
->iw_mode
) {
2579 case IEEE80211_IF_TYPE_IBSS
:{
2580 struct list_head
*p
;
2581 struct iwl4965_ibss_seq
*entry
= NULL
;
2582 u8
*mac
= header
->addr2
;
2583 int index
= mac
[5] & (IWL_IBSS_MAC_HASH_SIZE
- 1);
2585 __list_for_each(p
, &priv
->ibss_mac_hash
[index
]) {
2586 entry
= list_entry(p
, struct iwl4965_ibss_seq
, list
);
2587 if (!compare_ether_addr(entry
->mac
, mac
))
2590 if (p
== &priv
->ibss_mac_hash
[index
]) {
2591 entry
= kzalloc(sizeof(*entry
), GFP_ATOMIC
);
2593 IWL_ERROR("Cannot malloc new mac entry\n");
2596 memcpy(entry
->mac
, mac
, ETH_ALEN
);
2597 entry
->seq_num
= seq
;
2598 entry
->frag_num
= frag
;
2599 entry
->packet_time
= jiffies
;
2600 list_add(&entry
->list
, &priv
->ibss_mac_hash
[index
]);
2603 last_seq
= &entry
->seq_num
;
2604 last_frag
= &entry
->frag_num
;
2605 last_time
= &entry
->packet_time
;
2608 case IEEE80211_IF_TYPE_STA
:
2609 last_seq
= &priv
->last_seq_num
;
2610 last_frag
= &priv
->last_frag_num
;
2611 last_time
= &priv
->last_packet_time
;
2616 if ((*last_seq
== seq
) &&
2617 time_after(*last_time
+ IWL_PACKET_RETRY_TIME
, jiffies
)) {
2618 if (*last_frag
== frag
)
2620 if (*last_frag
+ 1 != frag
)
2621 /* out-of-order fragment */
2627 *last_time
= jiffies
;
2634 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
2636 #include "iwl-spectrum.h"
2638 #define BEACON_TIME_MASK_LOW 0x00FFFFFF
2639 #define BEACON_TIME_MASK_HIGH 0xFF000000
2640 #define TIME_UNIT 1024
2643 * extended beacon time format
2644 * time in usec will be changed into a 32-bit value in 8:24 format
2645 * the high 1 byte is the beacon counts
2646 * the lower 3 bytes is the time in usec within one beacon interval
2649 static u32
iwl4965_usecs_to_beacons(u32 usec
, u32 beacon_interval
)
2653 u32 interval
= beacon_interval
* 1024;
2655 if (!interval
|| !usec
)
2658 quot
= (usec
/ interval
) & (BEACON_TIME_MASK_HIGH
>> 24);
2659 rem
= (usec
% interval
) & BEACON_TIME_MASK_LOW
;
2661 return (quot
<< 24) + rem
;
2664 /* base is usually what we get from ucode with each received frame,
2665 * the same as HW timer counter counting down
2668 static __le32
iwl4965_add_beacon_time(u32 base
, u32 addon
, u32 beacon_interval
)
2670 u32 base_low
= base
& BEACON_TIME_MASK_LOW
;
2671 u32 addon_low
= addon
& BEACON_TIME_MASK_LOW
;
2672 u32 interval
= beacon_interval
* TIME_UNIT
;
2673 u32 res
= (base
& BEACON_TIME_MASK_HIGH
) +
2674 (addon
& BEACON_TIME_MASK_HIGH
);
2676 if (base_low
> addon_low
)
2677 res
+= base_low
- addon_low
;
2678 else if (base_low
< addon_low
) {
2679 res
+= interval
+ base_low
- addon_low
;
2684 return cpu_to_le32(res
);
2687 static int iwl4965_get_measurement(struct iwl_priv
*priv
,
2688 struct ieee80211_measurement_params
*params
,
2691 struct iwl4965_spectrum_cmd spectrum
;
2692 struct iwl4965_rx_packet
*res
;
2693 struct iwl_host_cmd cmd
= {
2694 .id
= REPLY_SPECTRUM_MEASUREMENT_CMD
,
2695 .data
= (void *)&spectrum
,
2696 .meta
.flags
= CMD_WANT_SKB
,
2698 u32 add_time
= le64_to_cpu(params
->start_time
);
2700 int spectrum_resp_status
;
2701 int duration
= le16_to_cpu(params
->duration
);
2703 if (iwl_is_associated(priv
))
2705 iwl4965_usecs_to_beacons(
2706 le64_to_cpu(params
->start_time
) - priv
->last_tsf
,
2707 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2709 memset(&spectrum
, 0, sizeof(spectrum
));
2711 spectrum
.channel_count
= cpu_to_le16(1);
2713 RXON_FLG_TSF2HOST_MSK
| RXON_FLG_ANT_A_MSK
| RXON_FLG_DIS_DIV_MSK
;
2714 spectrum
.filter_flags
= MEASUREMENT_FILTER_FLAG
;
2715 cmd
.len
= sizeof(spectrum
);
2716 spectrum
.len
= cpu_to_le16(cmd
.len
- sizeof(spectrum
.len
));
2718 if (iwl_is_associated(priv
))
2719 spectrum
.start_time
=
2720 iwl4965_add_beacon_time(priv
->last_beacon_time
,
2722 le16_to_cpu(priv
->rxon_timing
.beacon_interval
));
2724 spectrum
.start_time
= 0;
2726 spectrum
.channels
[0].duration
= cpu_to_le32(duration
* TIME_UNIT
);
2727 spectrum
.channels
[0].channel
= params
->channel
;
2728 spectrum
.channels
[0].type
= type
;
2729 if (priv
->active_rxon
.flags
& RXON_FLG_BAND_24G_MSK
)
2730 spectrum
.flags
|= RXON_FLG_BAND_24G_MSK
|
2731 RXON_FLG_AUTO_DETECT_MSK
| RXON_FLG_TGG_PROTECT_MSK
;
2733 rc
= iwl_send_cmd_sync(priv
, &cmd
);
2737 res
= (struct iwl4965_rx_packet
*)cmd
.meta
.u
.skb
->data
;
2738 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
2739 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
2743 spectrum_resp_status
= le16_to_cpu(res
->u
.spectrum
.status
);
2744 switch (spectrum_resp_status
) {
2745 case 0: /* Command will be handled */
2746 if (res
->u
.spectrum
.id
!= 0xff) {
2748 ("Replaced existing measurement: %d\n",
2749 res
->u
.spectrum
.id
);
2750 priv
->measurement_status
&= ~MEASUREMENT_READY
;
2752 priv
->measurement_status
|= MEASUREMENT_ACTIVE
;
2756 case 1: /* Command will not be handled */
2761 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
2767 static void iwl4965_txstatus_to_ieee(struct iwl_priv
*priv
,
2768 struct iwl4965_tx_info
*tx_sta
)
2771 tx_sta
->status
.ack_signal
= 0;
2772 tx_sta
->status
.excessive_retries
= 0;
2773 tx_sta
->status
.queue_length
= 0;
2774 tx_sta
->status
.queue_number
= 0;
2777 ieee80211_tx_status_irqsafe(priv
->hw
,
2778 tx_sta
->skb
[0], &(tx_sta
->status
));
2780 ieee80211_tx_status(priv
->hw
,
2781 tx_sta
->skb
[0], &(tx_sta
->status
));
2783 tx_sta
->skb
[0] = NULL
;
2787 * iwl4965_tx_queue_reclaim - Reclaim Tx queue entries already Tx'd
2789 * When FW advances 'R' index, all entries between old and new 'R' index
2790 * need to be reclaimed. As result, some free space forms. If there is
2791 * enough free space (> low mark), wake the stack that feeds us.
2793 int iwl4965_tx_queue_reclaim(struct iwl_priv
*priv
, int txq_id
, int index
)
2795 struct iwl4965_tx_queue
*txq
= &priv
->txq
[txq_id
];
2796 struct iwl4965_queue
*q
= &txq
->q
;
2799 if ((index
>= q
->n_bd
) || (x2_queue_used(q
, index
) == 0)) {
2800 IWL_ERROR("Read index for DMA queue txq id (%d), index %d, "
2801 "is out of range [0-%d] %d %d.\n", txq_id
,
2802 index
, q
->n_bd
, q
->write_ptr
, q
->read_ptr
);
2806 for (index
= iwl_queue_inc_wrap(index
, q
->n_bd
);
2807 q
->read_ptr
!= index
;
2808 q
->read_ptr
= iwl_queue_inc_wrap(q
->read_ptr
, q
->n_bd
)) {
2809 if (txq_id
!= IWL_CMD_QUEUE_NUM
) {
2810 iwl4965_txstatus_to_ieee(priv
,
2811 &(txq
->txb
[txq
->q
.read_ptr
]));
2812 iwl4965_hw_txq_free_tfd(priv
, txq
);
2813 } else if (nfreed
> 1) {
2814 IWL_ERROR("HCMD skipped: index (%d) %d %d\n", index
,
2815 q
->write_ptr
, q
->read_ptr
);
2816 queue_work(priv
->workqueue
, &priv
->restart
);
2821 /* if (iwl4965_queue_space(q) > q->low_mark && (txq_id >= 0) &&
2822 (txq_id != IWL_CMD_QUEUE_NUM) &&
2823 priv->mac80211_registered)
2824 ieee80211_wake_queue(priv->hw, txq_id); */
2830 static int iwl4965_is_tx_success(u32 status
)
2832 status
&= TX_STATUS_MSK
;
2833 return (status
== TX_STATUS_SUCCESS
)
2834 || (status
== TX_STATUS_DIRECT_DONE
);
2837 /******************************************************************************
2839 * Generic RX handler implementations
2841 ******************************************************************************/
2842 #ifdef CONFIG_IWL4965_HT
2844 static inline int iwl4965_get_ra_sta_id(struct iwl_priv
*priv
,
2845 struct ieee80211_hdr
*hdr
)
2847 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
)
2850 u8
*da
= ieee80211_get_DA(hdr
);
2851 return iwl4965_hw_find_station(priv
, da
);
2855 static struct ieee80211_hdr
*iwl4965_tx_queue_get_hdr(
2856 struct iwl_priv
*priv
, int txq_id
, int idx
)
2858 if (priv
->txq
[txq_id
].txb
[idx
].skb
[0])
2859 return (struct ieee80211_hdr
*)priv
->txq
[txq_id
].
2860 txb
[idx
].skb
[0]->data
;
2864 static inline u32
iwl4965_get_scd_ssn(struct iwl4965_tx_resp
*tx_resp
)
2866 __le32
*scd_ssn
= (__le32
*)((u32
*)&tx_resp
->status
+
2867 tx_resp
->frame_count
);
2868 return le32_to_cpu(*scd_ssn
) & MAX_SN
;
2873 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
2875 static int iwl4965_tx_status_reply_tx(struct iwl_priv
*priv
,
2876 struct iwl4965_ht_agg
*agg
,
2877 struct iwl4965_tx_resp_agg
*tx_resp
,
2881 struct agg_tx_status
*frame_status
= &tx_resp
->status
;
2882 struct ieee80211_tx_status
*tx_status
= NULL
;
2883 struct ieee80211_hdr
*hdr
= NULL
;
2888 if (agg
->wait_for_ba
)
2889 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
2891 agg
->frame_count
= tx_resp
->frame_count
;
2892 agg
->start_idx
= start_idx
;
2893 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
2896 /* # frames attempted by Tx command */
2897 if (agg
->frame_count
== 1) {
2898 /* Only one frame was attempted; no block-ack will arrive */
2899 status
= le16_to_cpu(frame_status
[0].status
);
2900 seq
= le16_to_cpu(frame_status
[0].sequence
);
2901 idx
= SEQ_TO_INDEX(seq
);
2902 txq_id
= SEQ_TO_QUEUE(seq
);
2904 /* FIXME: code repetition */
2905 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
2906 agg
->frame_count
, agg
->start_idx
, idx
);
2908 tx_status
= &(priv
->txq
[txq_id
].txb
[idx
].status
);
2909 tx_status
->retry_count
= tx_resp
->failure_frame
;
2910 tx_status
->queue_number
= status
& 0xff;
2911 tx_status
->queue_length
= tx_resp
->failure_rts
;
2912 tx_status
->control
.flags
&= ~IEEE80211_TXCTL_AMPDU
;
2913 tx_status
->flags
= iwl4965_is_tx_success(status
)?
2914 IEEE80211_TX_STATUS_ACK
: 0;
2915 iwl4965_hwrate_to_tx_control(priv
,
2916 le32_to_cpu(tx_resp
->rate_n_flags
),
2917 &tx_status
->control
);
2918 /* FIXME: code repetition end */
2920 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
2921 status
& 0xff, tx_resp
->failure_frame
);
2922 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
2923 iwl4965_hw_get_rate_n_flags(tx_resp
->rate_n_flags
));
2925 agg
->wait_for_ba
= 0;
2927 /* Two or more frames were attempted; expect block-ack */
2929 int start
= agg
->start_idx
;
2931 /* Construct bit-map of pending frames within Tx window */
2932 for (i
= 0; i
< agg
->frame_count
; i
++) {
2934 status
= le16_to_cpu(frame_status
[i
].status
);
2935 seq
= le16_to_cpu(frame_status
[i
].sequence
);
2936 idx
= SEQ_TO_INDEX(seq
);
2937 txq_id
= SEQ_TO_QUEUE(seq
);
2939 if (status
& (AGG_TX_STATE_FEW_BYTES_MSK
|
2940 AGG_TX_STATE_ABORT_MSK
))
2943 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
2944 agg
->frame_count
, txq_id
, idx
);
2946 hdr
= iwl4965_tx_queue_get_hdr(priv
, txq_id
, idx
);
2948 sc
= le16_to_cpu(hdr
->seq_ctrl
);
2949 if (idx
!= (SEQ_TO_SN(sc
) & 0xff)) {
2950 IWL_ERROR("BUG_ON idx doesn't match seq control"
2951 " idx=%d, seq_idx=%d, seq=%d\n",
2957 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
2958 i
, idx
, SEQ_TO_SN(sc
));
2962 sh
= (start
- idx
) + 0xff;
2963 bitmap
= bitmap
<< sh
;
2966 } else if (sh
< -64)
2967 sh
= 0xff - (start
- idx
);
2971 bitmap
= bitmap
<< sh
;
2974 bitmap
|= (1 << sh
);
2975 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
2976 start
, (u32
)(bitmap
& 0xFFFFFFFF));
2979 agg
->bitmap
= bitmap
;
2980 agg
->start_idx
= start
;
2981 agg
->rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
2982 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
2983 agg
->frame_count
, agg
->start_idx
,
2984 (unsigned long long)agg
->bitmap
);
2987 agg
->wait_for_ba
= 1;
2994 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
2996 static void iwl4965_rx_reply_tx(struct iwl_priv
*priv
,
2997 struct iwl4965_rx_mem_buffer
*rxb
)
2999 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3000 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3001 int txq_id
= SEQ_TO_QUEUE(sequence
);
3002 int index
= SEQ_TO_INDEX(sequence
);
3003 struct iwl4965_tx_queue
*txq
= &priv
->txq
[txq_id
];
3004 struct ieee80211_tx_status
*tx_status
;
3005 struct iwl4965_tx_resp
*tx_resp
= (void *)&pkt
->u
.raw
[0];
3006 u32 status
= le32_to_cpu(tx_resp
->status
);
3007 #ifdef CONFIG_IWL4965_HT
3008 int tid
= MAX_TID_COUNT
, sta_id
= IWL_INVALID_STATION
;
3009 struct ieee80211_hdr
*hdr
;
3013 if ((index
>= txq
->q
.n_bd
) || (x2_queue_used(&txq
->q
, index
) == 0)) {
3014 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3015 "is out of range [0-%d] %d %d\n", txq_id
,
3016 index
, txq
->q
.n_bd
, txq
->q
.write_ptr
,
3021 #ifdef CONFIG_IWL4965_HT
3022 hdr
= iwl4965_tx_queue_get_hdr(priv
, txq_id
, index
);
3023 qc
= ieee80211_get_qos_ctrl(hdr
);
3026 tid
= le16_to_cpu(*qc
) & 0xf;
3028 sta_id
= iwl4965_get_ra_sta_id(priv
, hdr
);
3029 if (txq
->sched_retry
&& unlikely(sta_id
== IWL_INVALID_STATION
)) {
3030 IWL_ERROR("Station not known\n");
3034 if (txq
->sched_retry
) {
3035 const u32 scd_ssn
= iwl4965_get_scd_ssn(tx_resp
);
3036 struct iwl4965_ht_agg
*agg
= NULL
;
3041 agg
= &priv
->stations
[sta_id
].tid
[tid
].agg
;
3043 iwl4965_tx_status_reply_tx(priv
, agg
,
3044 (struct iwl4965_tx_resp_agg
*)tx_resp
, index
);
3046 if ((tx_resp
->frame_count
== 1) &&
3047 !iwl4965_is_tx_success(status
)) {
3048 /* TODO: send BAR */
3051 if (txq
->q
.read_ptr
!= (scd_ssn
& 0xff)) {
3053 index
= iwl_queue_dec_wrap(scd_ssn
& 0xff, txq
->q
.n_bd
);
3054 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
3055 "%d index %d\n", scd_ssn
, index
);
3056 freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3057 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
-= freed
;
3059 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
3060 txq_id
>= 0 && priv
->mac80211_registered
&&
3061 agg
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
)
3062 ieee80211_wake_queue(priv
->hw
, txq_id
);
3064 iwl4965_check_empty_hw_queue(priv
, sta_id
, tid
, txq_id
);
3067 #endif /* CONFIG_IWL4965_HT */
3068 tx_status
= &(txq
->txb
[txq
->q
.read_ptr
].status
);
3070 tx_status
->retry_count
= tx_resp
->failure_frame
;
3071 tx_status
->queue_number
= status
;
3072 tx_status
->queue_length
= tx_resp
->bt_kill_count
;
3073 tx_status
->queue_length
|= tx_resp
->failure_rts
;
3075 iwl4965_is_tx_success(status
) ? IEEE80211_TX_STATUS_ACK
: 0;
3076 iwl4965_hwrate_to_tx_control(priv
, le32_to_cpu(tx_resp
->rate_n_flags
),
3077 &tx_status
->control
);
3079 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
3080 "retries %d\n", txq_id
, iwl4965_get_tx_fail_reason(status
),
3081 status
, le32_to_cpu(tx_resp
->rate_n_flags
),
3082 tx_resp
->failure_frame
);
3084 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index
);
3086 int freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3087 #ifdef CONFIG_IWL4965_HT
3088 if (tid
!= MAX_TID_COUNT
)
3089 priv
->stations
[sta_id
].tid
[tid
].tfds_in_queue
-= freed
;
3090 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
3092 priv
->mac80211_registered
)
3093 ieee80211_wake_queue(priv
->hw
, txq_id
);
3094 if (tid
!= MAX_TID_COUNT
)
3095 iwl4965_check_empty_hw_queue(priv
, sta_id
, tid
, txq_id
);
3098 #ifdef CONFIG_IWL4965_HT
3100 #endif /* CONFIG_IWL4965_HT */
3102 if (iwl_check_bits(status
, TX_ABORT_REQUIRED_MSK
))
3103 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3107 static void iwl4965_rx_reply_alive(struct iwl_priv
*priv
,
3108 struct iwl4965_rx_mem_buffer
*rxb
)
3110 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3111 struct iwl4965_alive_resp
*palive
;
3112 struct delayed_work
*pwork
;
3114 palive
= &pkt
->u
.alive_frame
;
3116 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
3118 palive
->is_valid
, palive
->ver_type
,
3119 palive
->ver_subtype
);
3121 if (palive
->ver_subtype
== INITIALIZE_SUBTYPE
) {
3122 IWL_DEBUG_INFO("Initialization Alive received.\n");
3123 memcpy(&priv
->card_alive_init
,
3124 &pkt
->u
.alive_frame
,
3125 sizeof(struct iwl4965_init_alive_resp
));
3126 pwork
= &priv
->init_alive_start
;
3128 IWL_DEBUG_INFO("Runtime Alive received.\n");
3129 memcpy(&priv
->card_alive
, &pkt
->u
.alive_frame
,
3130 sizeof(struct iwl4965_alive_resp
));
3131 pwork
= &priv
->alive_start
;
3134 /* We delay the ALIVE response by 5ms to
3135 * give the HW RF Kill time to activate... */
3136 if (palive
->is_valid
== UCODE_VALID_OK
)
3137 queue_delayed_work(priv
->workqueue
, pwork
,
3138 msecs_to_jiffies(5));
3140 IWL_WARNING("uCode did not respond OK.\n");
3143 static void iwl4965_rx_reply_add_sta(struct iwl_priv
*priv
,
3144 struct iwl4965_rx_mem_buffer
*rxb
)
3146 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3148 IWL_DEBUG_RX("Received REPLY_ADD_STA: 0x%02X\n", pkt
->u
.status
);
3152 static void iwl4965_rx_reply_error(struct iwl_priv
*priv
,
3153 struct iwl4965_rx_mem_buffer
*rxb
)
3155 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3157 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
3158 "seq 0x%04X ser 0x%08X\n",
3159 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
3160 get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
3161 pkt
->u
.err_resp
.cmd_id
,
3162 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
3163 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
3166 #define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
3168 static void iwl4965_rx_csa(struct iwl_priv
*priv
, struct iwl4965_rx_mem_buffer
*rxb
)
3170 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3171 struct iwl4965_rxon_cmd
*rxon
= (void *)&priv
->active_rxon
;
3172 struct iwl4965_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
3173 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
3174 le16_to_cpu(csa
->channel
), le32_to_cpu(csa
->status
));
3175 rxon
->channel
= csa
->channel
;
3176 priv
->staging_rxon
.channel
= csa
->channel
;
3179 static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv
*priv
,
3180 struct iwl4965_rx_mem_buffer
*rxb
)
3182 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
3183 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3184 struct iwl4965_spectrum_notification
*report
= &(pkt
->u
.spectrum_notif
);
3186 if (!report
->state
) {
3187 IWL_DEBUG(IWL_DL_11H
| IWL_DL_INFO
,
3188 "Spectrum Measure Notification: Start\n");
3192 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
3193 priv
->measurement_status
|= MEASUREMENT_READY
;
3197 static void iwl4965_rx_pm_sleep_notif(struct iwl_priv
*priv
,
3198 struct iwl4965_rx_mem_buffer
*rxb
)
3200 #ifdef CONFIG_IWLWIFI_DEBUG
3201 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3202 struct iwl4965_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
3203 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
3204 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
3208 static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv
*priv
,
3209 struct iwl4965_rx_mem_buffer
*rxb
)
3211 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3212 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
3213 "notification for %s:\n",
3214 le32_to_cpu(pkt
->len
), get_cmd_string(pkt
->hdr
.cmd
));
3215 iwl_print_hex_dump(IWL_DL_RADIO
, pkt
->u
.raw
, le32_to_cpu(pkt
->len
));
3218 static void iwl4965_bg_beacon_update(struct work_struct
*work
)
3220 struct iwl_priv
*priv
=
3221 container_of(work
, struct iwl_priv
, beacon_update
);
3222 struct sk_buff
*beacon
;
3224 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
3225 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->vif
, NULL
);
3228 IWL_ERROR("update beacon failed\n");
3232 mutex_lock(&priv
->mutex
);
3233 /* new beacon skb is allocated every time; dispose previous.*/
3234 if (priv
->ibss_beacon
)
3235 dev_kfree_skb(priv
->ibss_beacon
);
3237 priv
->ibss_beacon
= beacon
;
3238 mutex_unlock(&priv
->mutex
);
3240 iwl4965_send_beacon_cmd(priv
);
3243 static void iwl4965_rx_beacon_notif(struct iwl_priv
*priv
,
3244 struct iwl4965_rx_mem_buffer
*rxb
)
3246 #ifdef CONFIG_IWLWIFI_DEBUG
3247 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3248 struct iwl4965_beacon_notif
*beacon
= &(pkt
->u
.beacon_status
);
3249 u8 rate
= iwl4965_hw_get_rate(beacon
->beacon_notify_hdr
.rate_n_flags
);
3251 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
3252 "tsf %d %d rate %d\n",
3253 le32_to_cpu(beacon
->beacon_notify_hdr
.status
) & TX_STATUS_MSK
,
3254 beacon
->beacon_notify_hdr
.failure_frame
,
3255 le32_to_cpu(beacon
->ibss_mgr_status
),
3256 le32_to_cpu(beacon
->high_tsf
),
3257 le32_to_cpu(beacon
->low_tsf
), rate
);
3260 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
3261 (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)))
3262 queue_work(priv
->workqueue
, &priv
->beacon_update
);
3265 /* Service response to REPLY_SCAN_CMD (0x80) */
3266 static void iwl4965_rx_reply_scan(struct iwl_priv
*priv
,
3267 struct iwl4965_rx_mem_buffer
*rxb
)
3269 #ifdef CONFIG_IWLWIFI_DEBUG
3270 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3271 struct iwl4965_scanreq_notification
*notif
=
3272 (struct iwl4965_scanreq_notification
*)pkt
->u
.raw
;
3274 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
3278 /* Service SCAN_START_NOTIFICATION (0x82) */
3279 static void iwl4965_rx_scan_start_notif(struct iwl_priv
*priv
,
3280 struct iwl4965_rx_mem_buffer
*rxb
)
3282 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3283 struct iwl4965_scanstart_notification
*notif
=
3284 (struct iwl4965_scanstart_notification
*)pkt
->u
.raw
;
3285 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
3286 IWL_DEBUG_SCAN("Scan start: "
3288 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
3290 notif
->band
? "bg" : "a",
3292 notif
->tsf_low
, notif
->status
, notif
->beacon_timer
);
3295 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
3296 static void iwl4965_rx_scan_results_notif(struct iwl_priv
*priv
,
3297 struct iwl4965_rx_mem_buffer
*rxb
)
3299 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3300 struct iwl4965_scanresults_notification
*notif
=
3301 (struct iwl4965_scanresults_notification
*)pkt
->u
.raw
;
3303 IWL_DEBUG_SCAN("Scan ch.res: "
3305 "(TSF: 0x%08X:%08X) - %d "
3306 "elapsed=%lu usec (%dms since last)\n",
3308 notif
->band
? "bg" : "a",
3309 le32_to_cpu(notif
->tsf_high
),
3310 le32_to_cpu(notif
->tsf_low
),
3311 le32_to_cpu(notif
->statistics
[0]),
3312 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
3313 jiffies_to_msecs(elapsed_jiffies
3314 (priv
->last_scan_jiffies
, jiffies
)));
3316 priv
->last_scan_jiffies
= jiffies
;
3317 priv
->next_scan_jiffies
= 0;
3320 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
3321 static void iwl4965_rx_scan_complete_notif(struct iwl_priv
*priv
,
3322 struct iwl4965_rx_mem_buffer
*rxb
)
3324 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3325 struct iwl4965_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
3327 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
3328 scan_notif
->scanned_channels
,
3329 scan_notif
->tsf_low
,
3330 scan_notif
->tsf_high
, scan_notif
->status
);
3332 /* The HW is no longer scanning */
3333 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
3335 /* The scan completion notification came in, so kill that timer... */
3336 cancel_delayed_work(&priv
->scan_check
);
3338 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
3339 (priv
->scan_bands
== 2) ? "2.4" : "5.2",
3340 jiffies_to_msecs(elapsed_jiffies
3341 (priv
->scan_pass_start
, jiffies
)));
3343 /* Remove this scanned band from the list
3344 * of pending bands to scan */
3347 /* If a request to abort was given, or the scan did not succeed
3348 * then we reset the scan state machine and terminate,
3349 * re-queuing another scan if one has been requested */
3350 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
3351 IWL_DEBUG_INFO("Aborted scan completed.\n");
3352 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
3354 /* If there are more bands on this scan pass reschedule */
3355 if (priv
->scan_bands
> 0)
3359 priv
->last_scan_jiffies
= jiffies
;
3360 priv
->next_scan_jiffies
= 0;
3361 IWL_DEBUG_INFO("Setting scan to off\n");
3363 clear_bit(STATUS_SCANNING
, &priv
->status
);
3365 IWL_DEBUG_INFO("Scan took %dms\n",
3366 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
3368 queue_work(priv
->workqueue
, &priv
->scan_completed
);
3373 priv
->scan_pass_start
= jiffies
;
3374 queue_work(priv
->workqueue
, &priv
->request_scan
);
3377 /* Handle notification from uCode that card's power state is changing
3378 * due to software, hardware, or critical temperature RFKILL */
3379 static void iwl4965_rx_card_state_notif(struct iwl_priv
*priv
,
3380 struct iwl4965_rx_mem_buffer
*rxb
)
3382 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3383 u32 flags
= le32_to_cpu(pkt
->u
.card_state_notif
.flags
);
3384 unsigned long status
= priv
->status
;
3386 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
3387 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
3388 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On");
3390 if (flags
& (SW_CARD_DISABLED
| HW_CARD_DISABLED
|
3391 RF_CARD_DISABLED
)) {
3393 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3394 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3396 if (!iwl_grab_nic_access(priv
)) {
3398 priv
, HBUS_TARG_MBX_C
,
3399 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
3401 iwl_release_nic_access(priv
);
3404 if (!(flags
& RXON_CARD_DISABLED
)) {
3405 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
3406 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
3407 if (!iwl_grab_nic_access(priv
)) {
3409 priv
, HBUS_TARG_MBX_C
,
3410 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
3412 iwl_release_nic_access(priv
);
3416 if (flags
& RF_CARD_DISABLED
) {
3417 iwl_write32(priv
, CSR_UCODE_DRV_GP1_SET
,
3418 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT
);
3419 iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3420 if (!iwl_grab_nic_access(priv
))
3421 iwl_release_nic_access(priv
);
3425 if (flags
& HW_CARD_DISABLED
)
3426 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3428 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
3431 if (flags
& SW_CARD_DISABLED
)
3432 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3434 clear_bit(STATUS_RF_KILL_SW
, &priv
->status
);
3436 if (!(flags
& RXON_CARD_DISABLED
))
3437 iwl4965_scan_cancel(priv
);
3439 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
3440 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)) ||
3441 (test_bit(STATUS_RF_KILL_SW
, &status
) !=
3442 test_bit(STATUS_RF_KILL_SW
, &priv
->status
)))
3443 queue_work(priv
->workqueue
, &priv
->rf_kill
);
3445 wake_up_interruptible(&priv
->wait_command_queue
);
3449 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
3451 * Setup the RX handlers for each of the reply types sent from the uCode
3454 * This function chains into the hardware specific files for them to setup
3455 * any hardware specific handlers as well.
3457 static void iwl4965_setup_rx_handlers(struct iwl_priv
*priv
)
3459 priv
->rx_handlers
[REPLY_ALIVE
] = iwl4965_rx_reply_alive
;
3460 priv
->rx_handlers
[REPLY_ADD_STA
] = iwl4965_rx_reply_add_sta
;
3461 priv
->rx_handlers
[REPLY_ERROR
] = iwl4965_rx_reply_error
;
3462 priv
->rx_handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwl4965_rx_csa
;
3463 priv
->rx_handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
3464 iwl4965_rx_spectrum_measure_notif
;
3465 priv
->rx_handlers
[PM_SLEEP_NOTIFICATION
] = iwl4965_rx_pm_sleep_notif
;
3466 priv
->rx_handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
3467 iwl4965_rx_pm_debug_statistics_notif
;
3468 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl4965_rx_beacon_notif
;
3471 * The same handler is used for both the REPLY to a discrete
3472 * statistics request from the host as well as for the periodic
3473 * statistics notifications (after received beacons) from the uCode.
3475 priv
->rx_handlers
[REPLY_STATISTICS_CMD
] = iwl4965_hw_rx_statistics
;
3476 priv
->rx_handlers
[STATISTICS_NOTIFICATION
] = iwl4965_hw_rx_statistics
;
3478 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl4965_rx_reply_scan
;
3479 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl4965_rx_scan_start_notif
;
3480 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
3481 iwl4965_rx_scan_results_notif
;
3482 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
3483 iwl4965_rx_scan_complete_notif
;
3484 priv
->rx_handlers
[CARD_STATE_NOTIFICATION
] = iwl4965_rx_card_state_notif
;
3485 priv
->rx_handlers
[REPLY_TX
] = iwl4965_rx_reply_tx
;
3487 /* Set up hardware specific Rx handlers */
3488 iwl4965_hw_rx_handler_setup(priv
);
3492 * iwl4965_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
3493 * @rxb: Rx buffer to reclaim
3495 * If an Rx buffer has an async callback associated with it the callback
3496 * will be executed. The attached skb (if present) will only be freed
3497 * if the callback returns 1
3499 static void iwl4965_tx_cmd_complete(struct iwl_priv
*priv
,
3500 struct iwl4965_rx_mem_buffer
*rxb
)
3502 struct iwl4965_rx_packet
*pkt
= (struct iwl4965_rx_packet
*)rxb
->skb
->data
;
3503 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
3504 int txq_id
= SEQ_TO_QUEUE(sequence
);
3505 int index
= SEQ_TO_INDEX(sequence
);
3506 int huge
= sequence
& SEQ_HUGE_FRAME
;
3508 struct iwl_cmd
*cmd
;
3510 /* If a Tx command is being handled and it isn't in the actual
3511 * command queue then there a command routing bug has been introduced
3512 * in the queue management code. */
3513 if (txq_id
!= IWL_CMD_QUEUE_NUM
)
3514 IWL_ERROR("Error wrong command queue %d command id 0x%X\n",
3515 txq_id
, pkt
->hdr
.cmd
);
3516 BUG_ON(txq_id
!= IWL_CMD_QUEUE_NUM
);
3518 cmd_index
= get_cmd_index(&priv
->txq
[IWL_CMD_QUEUE_NUM
].q
, index
, huge
);
3519 cmd
= &priv
->txq
[IWL_CMD_QUEUE_NUM
].cmd
[cmd_index
];
3521 /* Input error checking is done when commands are added to queue. */
3522 if (cmd
->meta
.flags
& CMD_WANT_SKB
) {
3523 cmd
->meta
.source
->u
.skb
= rxb
->skb
;
3525 } else if (cmd
->meta
.u
.callback
&&
3526 !cmd
->meta
.u
.callback(priv
, cmd
, rxb
->skb
))
3529 iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
3531 if (!(cmd
->meta
.flags
& CMD_ASYNC
)) {
3532 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
3533 wake_up_interruptible(&priv
->wait_command_queue
);
3537 /************************** RX-FUNCTIONS ****************************/
3539 * Rx theory of operation
3541 * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
3542 * each of which point to Receive Buffers to be filled by 4965. These get
3543 * used not only for Rx frames, but for any command response or notification
3544 * from the 4965. The driver and 4965 manage the Rx buffers by means
3545 * of indexes into the circular buffer.
3548 * The host/firmware share two index registers for managing the Rx buffers.
3550 * The READ index maps to the first position that the firmware may be writing
3551 * to -- the driver can read up to (but not including) this position and get
3553 * The READ index is managed by the firmware once the card is enabled.
3555 * The WRITE index maps to the last position the driver has read from -- the
3556 * position preceding WRITE is the last slot the firmware can place a packet.
3558 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
3561 * During initialization, the host sets up the READ queue position to the first
3562 * INDEX position, and WRITE to the last (READ - 1 wrapped)
3564 * When the firmware places a packet in a buffer, it will advance the READ index
3565 * and fire the RX interrupt. The driver can then query the READ index and
3566 * process as many packets as possible, moving the WRITE index forward as it
3567 * resets the Rx queue buffers with new memory.
3569 * The management in the driver is as follows:
3570 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
3571 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
3572 * to replenish the iwl->rxq->rx_free.
3573 * + In iwl4965_rx_replenish (scheduled) if 'processed' != 'read' then the
3574 * iwl->rxq is replenished and the READ INDEX is updated (updating the
3575 * 'processed' and 'read' driver indexes as well)
3576 * + A received packet is processed and handed to the kernel network stack,
3577 * detached from the iwl->rxq. The driver 'processed' index is updated.
3578 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
3579 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
3580 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
3581 * were enough free buffers and RX_STALLED is set it is cleared.
3586 * iwl4965_rx_queue_alloc() Allocates rx_free
3587 * iwl4965_rx_replenish() Replenishes rx_free list from rx_used, and calls
3588 * iwl4965_rx_queue_restock
3589 * iwl4965_rx_queue_restock() Moves available buffers from rx_free into Rx
3590 * queue, updates firmware pointers, and updates
3591 * the WRITE index. If insufficient rx_free buffers
3592 * are available, schedules iwl4965_rx_replenish
3594 * -- enable interrupts --
3595 * ISR - iwl4965_rx() Detach iwl4965_rx_mem_buffers from pool up to the
3596 * READ INDEX, detaching the SKB from the pool.
3597 * Moves the packet buffer from queue to rx_used.
3598 * Calls iwl4965_rx_queue_restock to refill any empty
3605 * iwl4965_rx_queue_space - Return number of free slots available in queue.
3607 static int iwl4965_rx_queue_space(const struct iwl4965_rx_queue
*q
)
3609 int s
= q
->read
- q
->write
;
3612 /* keep some buffer to not confuse full and empty queue */
3620 * iwl4965_rx_queue_update_write_ptr - Update the write pointer for the RX queue
3622 int iwl4965_rx_queue_update_write_ptr(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*q
)
3626 unsigned long flags
;
3628 spin_lock_irqsave(&q
->lock
, flags
);
3630 if (q
->need_update
== 0)
3633 /* If power-saving is in use, make sure device is awake */
3634 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
3635 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
3637 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
3638 iwl_set_bit(priv
, CSR_GP_CNTRL
,
3639 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
3643 rc
= iwl_grab_nic_access(priv
);
3647 /* Device expects a multiple of 8 */
3648 iwl_write_direct32(priv
, FH_RSCSR_CHNL0_WPTR
,
3650 iwl_release_nic_access(priv
);
3652 /* Else device is assumed to be awake */
3654 /* Device expects a multiple of 8 */
3655 iwl_write32(priv
, FH_RSCSR_CHNL0_WPTR
, q
->write
& ~0x7);
3661 spin_unlock_irqrestore(&q
->lock
, flags
);
3666 * iwl4965_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
3668 static inline __le32
iwl4965_dma_addr2rbd_ptr(struct iwl_priv
*priv
,
3669 dma_addr_t dma_addr
)
3671 return cpu_to_le32((u32
)(dma_addr
>> 8));
3676 * iwl4965_rx_queue_restock - refill RX queue from pre-allocated pool
3678 * If there are slots in the RX queue that need to be restocked,
3679 * and we have free pre-allocated buffers, fill the ranks as much
3680 * as we can, pulling from rx_free.
3682 * This moves the 'write' index forward to catch up with 'processed', and
3683 * also updates the memory address in the firmware to reference the new
3686 static int iwl4965_rx_queue_restock(struct iwl_priv
*priv
)
3688 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3689 struct list_head
*element
;
3690 struct iwl4965_rx_mem_buffer
*rxb
;
3691 unsigned long flags
;
3694 spin_lock_irqsave(&rxq
->lock
, flags
);
3695 write
= rxq
->write
& ~0x7;
3696 while ((iwl4965_rx_queue_space(rxq
) > 0) && (rxq
->free_count
)) {
3697 /* Get next free Rx buffer, remove from free list */
3698 element
= rxq
->rx_free
.next
;
3699 rxb
= list_entry(element
, struct iwl4965_rx_mem_buffer
, list
);
3702 /* Point to Rx buffer via next RBD in circular buffer */
3703 rxq
->bd
[rxq
->write
] = iwl4965_dma_addr2rbd_ptr(priv
, rxb
->dma_addr
);
3704 rxq
->queue
[rxq
->write
] = rxb
;
3705 rxq
->write
= (rxq
->write
+ 1) & RX_QUEUE_MASK
;
3708 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3709 /* If the pre-allocated buffer pool is dropping low, schedule to
3711 if (rxq
->free_count
<= RX_LOW_WATERMARK
)
3712 queue_work(priv
->workqueue
, &priv
->rx_replenish
);
3715 /* If we've added more space for the firmware to place data, tell it.
3716 * Increment device's write pointer in multiples of 8. */
3717 if ((write
!= (rxq
->write
& ~0x7))
3718 || (abs(rxq
->write
- rxq
->read
) > 7)) {
3719 spin_lock_irqsave(&rxq
->lock
, flags
);
3720 rxq
->need_update
= 1;
3721 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3722 rc
= iwl4965_rx_queue_update_write_ptr(priv
, rxq
);
3731 * iwl4965_rx_replenish - Move all used packet from rx_used to rx_free
3733 * When moving to rx_free an SKB is allocated for the slot.
3735 * Also restock the Rx queue via iwl4965_rx_queue_restock.
3736 * This is called as a scheduled work item (except for during initialization)
3738 static void iwl4965_rx_allocate(struct iwl_priv
*priv
)
3740 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3741 struct list_head
*element
;
3742 struct iwl4965_rx_mem_buffer
*rxb
;
3743 unsigned long flags
;
3744 spin_lock_irqsave(&rxq
->lock
, flags
);
3745 while (!list_empty(&rxq
->rx_used
)) {
3746 element
= rxq
->rx_used
.next
;
3747 rxb
= list_entry(element
, struct iwl4965_rx_mem_buffer
, list
);
3749 /* Alloc a new receive buffer */
3751 alloc_skb(priv
->hw_setting
.rx_buf_size
,
3752 __GFP_NOWARN
| GFP_ATOMIC
);
3754 if (net_ratelimit())
3755 printk(KERN_CRIT DRV_NAME
3756 ": Can not allocate SKB buffers\n");
3757 /* We don't reschedule replenish work here -- we will
3758 * call the restock method and if it still needs
3759 * more buffers it will schedule replenish */
3762 priv
->alloc_rxb_skb
++;
3765 /* Get physical address of RB/SKB */
3767 pci_map_single(priv
->pci_dev
, rxb
->skb
->data
,
3768 priv
->hw_setting
.rx_buf_size
, PCI_DMA_FROMDEVICE
);
3769 list_add_tail(&rxb
->list
, &rxq
->rx_free
);
3772 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3776 * this should be called while priv->lock is locked
3778 static void __iwl4965_rx_replenish(void *data
)
3780 struct iwl_priv
*priv
= data
;
3782 iwl4965_rx_allocate(priv
);
3783 iwl4965_rx_queue_restock(priv
);
3787 void iwl4965_rx_replenish(void *data
)
3789 struct iwl_priv
*priv
= data
;
3790 unsigned long flags
;
3792 iwl4965_rx_allocate(priv
);
3794 spin_lock_irqsave(&priv
->lock
, flags
);
3795 iwl4965_rx_queue_restock(priv
);
3796 spin_unlock_irqrestore(&priv
->lock
, flags
);
3799 /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
3800 * If an SKB has been detached, the POOL needs to have its SKB set to NULL
3801 * This free routine walks the list of POOL entries and if SKB is set to
3802 * non NULL it is unmapped and freed
3804 static void iwl4965_rx_queue_free(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*rxq
)
3807 for (i
= 0; i
< RX_QUEUE_SIZE
+ RX_FREE_BUFFERS
; i
++) {
3808 if (rxq
->pool
[i
].skb
!= NULL
) {
3809 pci_unmap_single(priv
->pci_dev
,
3810 rxq
->pool
[i
].dma_addr
,
3811 priv
->hw_setting
.rx_buf_size
,
3812 PCI_DMA_FROMDEVICE
);
3813 dev_kfree_skb(rxq
->pool
[i
].skb
);
3817 pci_free_consistent(priv
->pci_dev
, 4 * RX_QUEUE_SIZE
, rxq
->bd
,
3822 int iwl4965_rx_queue_alloc(struct iwl_priv
*priv
)
3824 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3825 struct pci_dev
*dev
= priv
->pci_dev
;
3828 spin_lock_init(&rxq
->lock
);
3829 INIT_LIST_HEAD(&rxq
->rx_free
);
3830 INIT_LIST_HEAD(&rxq
->rx_used
);
3832 /* Alloc the circular buffer of Read Buffer Descriptors (RBDs) */
3833 rxq
->bd
= pci_alloc_consistent(dev
, 4 * RX_QUEUE_SIZE
, &rxq
->dma_addr
);
3837 /* Fill the rx_used queue with _all_ of the Rx buffers */
3838 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++)
3839 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3841 /* Set us so that we have processed and used all buffers, but have
3842 * not restocked the Rx queue with fresh buffers */
3843 rxq
->read
= rxq
->write
= 0;
3844 rxq
->free_count
= 0;
3845 rxq
->need_update
= 0;
3849 void iwl4965_rx_queue_reset(struct iwl_priv
*priv
, struct iwl4965_rx_queue
*rxq
)
3851 unsigned long flags
;
3853 spin_lock_irqsave(&rxq
->lock
, flags
);
3854 INIT_LIST_HEAD(&rxq
->rx_free
);
3855 INIT_LIST_HEAD(&rxq
->rx_used
);
3856 /* Fill the rx_used queue with _all_ of the Rx buffers */
3857 for (i
= 0; i
< RX_FREE_BUFFERS
+ RX_QUEUE_SIZE
; i
++) {
3858 /* In the reset function, these buffers may have been allocated
3859 * to an SKB, so we need to unmap and free potential storage */
3860 if (rxq
->pool
[i
].skb
!= NULL
) {
3861 pci_unmap_single(priv
->pci_dev
,
3862 rxq
->pool
[i
].dma_addr
,
3863 priv
->hw_setting
.rx_buf_size
,
3864 PCI_DMA_FROMDEVICE
);
3865 priv
->alloc_rxb_skb
--;
3866 dev_kfree_skb(rxq
->pool
[i
].skb
);
3867 rxq
->pool
[i
].skb
= NULL
;
3869 list_add_tail(&rxq
->pool
[i
].list
, &rxq
->rx_used
);
3872 /* Set us so that we have processed and used all buffers, but have
3873 * not restocked the Rx queue with fresh buffers */
3874 rxq
->read
= rxq
->write
= 0;
3875 rxq
->free_count
= 0;
3876 spin_unlock_irqrestore(&rxq
->lock
, flags
);
3879 /* Convert linear signal-to-noise ratio into dB */
3880 static u8 ratio2dB
[100] = {
3881 /* 0 1 2 3 4 5 6 7 8 9 */
3882 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
3883 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
3884 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
3885 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
3886 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
3887 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
3888 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
3889 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
3890 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
3891 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
3894 /* Calculates a relative dB value from a ratio of linear
3895 * (i.e. not dB) signal levels.
3896 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
3897 int iwl4965_calc_db_from_ratio(int sig_ratio
)
3899 /* 1000:1 or higher just report as 60 dB */
3900 if (sig_ratio
>= 1000)
3903 /* 100:1 or higher, divide by 10 and use table,
3904 * add 20 dB to make up for divide by 10 */
3905 if (sig_ratio
>= 100)
3906 return (20 + (int)ratio2dB
[sig_ratio
/10]);
3908 /* We shouldn't see this */
3912 /* Use table for ratios 1:1 - 99:1 */
3913 return (int)ratio2dB
[sig_ratio
];
3916 #define PERFECT_RSSI (-20) /* dBm */
3917 #define WORST_RSSI (-95) /* dBm */
3918 #define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
3920 /* Calculate an indication of rx signal quality (a percentage, not dBm!).
3921 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
3922 * about formulas used below. */
3923 int iwl4965_calc_sig_qual(int rssi_dbm
, int noise_dbm
)
3926 int degradation
= PERFECT_RSSI
- rssi_dbm
;
3928 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
3929 * as indicator; formula is (signal dbm - noise dbm).
3930 * SNR at or above 40 is a great signal (100%).
3931 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
3932 * Weakest usable signal is usually 10 - 15 dB SNR. */
3934 if (rssi_dbm
- noise_dbm
>= 40)
3936 else if (rssi_dbm
< noise_dbm
)
3938 sig_qual
= ((rssi_dbm
- noise_dbm
) * 5) / 2;
3940 /* Else use just the signal level.
3941 * This formula is a least squares fit of data points collected and
3942 * compared with a reference system that had a percentage (%) display
3943 * for signal quality. */
3945 sig_qual
= (100 * (RSSI_RANGE
* RSSI_RANGE
) - degradation
*
3946 (15 * RSSI_RANGE
+ 62 * degradation
)) /
3947 (RSSI_RANGE
* RSSI_RANGE
);
3951 else if (sig_qual
< 1)
3958 * iwl4965_rx_handle - Main entry function for receiving responses from uCode
3960 * Uses the priv->rx_handlers callback function array to invoke
3961 * the appropriate handlers, including command responses,
3962 * frame-received notifications, and other notifications.
3964 static void iwl4965_rx_handle(struct iwl_priv
*priv
)
3966 struct iwl4965_rx_mem_buffer
*rxb
;
3967 struct iwl4965_rx_packet
*pkt
;
3968 struct iwl4965_rx_queue
*rxq
= &priv
->rxq
;
3971 unsigned long flags
;
3975 /* uCode's read index (stored in shared DRAM) indicates the last Rx
3976 * buffer that the driver may process (last buffer filled by ucode). */
3977 r
= iwl4965_hw_get_rx_read(priv
);
3980 /* Rx interrupt, but nothing sent from uCode */
3982 IWL_DEBUG(IWL_DL_RX
| IWL_DL_ISR
, "r = %d, i = %d\n", r
, i
);
3984 if (iwl4965_rx_queue_space(rxq
) > (RX_QUEUE_SIZE
/ 2))
3988 rxb
= rxq
->queue
[i
];
3990 /* If an RXB doesn't have a Rx queue slot associated with it,
3991 * then a bug has been introduced in the queue refilling
3992 * routines -- catch it here */
3993 BUG_ON(rxb
== NULL
);
3995 rxq
->queue
[i
] = NULL
;
3997 pci_dma_sync_single_for_cpu(priv
->pci_dev
, rxb
->dma_addr
,
3998 priv
->hw_setting
.rx_buf_size
,
3999 PCI_DMA_FROMDEVICE
);
4000 pkt
= (struct iwl4965_rx_packet
*)rxb
->skb
->data
;
4002 /* Reclaim a command buffer only if this packet is a response
4003 * to a (driver-originated) command.
4004 * If the packet (e.g. Rx frame) originated from uCode,
4005 * there is no command buffer to reclaim.
4006 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
4007 * but apparently a few don't get set; catch them here. */
4008 reclaim
= !(pkt
->hdr
.sequence
& SEQ_RX_FRAME
) &&
4009 (pkt
->hdr
.cmd
!= REPLY_RX_PHY_CMD
) &&
4010 (pkt
->hdr
.cmd
!= REPLY_RX
) &&
4011 (pkt
->hdr
.cmd
!= REPLY_COMPRESSED_BA
) &&
4012 (pkt
->hdr
.cmd
!= STATISTICS_NOTIFICATION
) &&
4013 (pkt
->hdr
.cmd
!= REPLY_TX
);
4015 /* Based on type of command response or notification,
4016 * handle those that need handling via function in
4017 * rx_handlers table. See iwl4965_setup_rx_handlers() */
4018 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
4019 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
4020 "r = %d, i = %d, %s, 0x%02x\n", r
, i
,
4021 get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);
4022 priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
);
4024 /* No handling needed */
4025 IWL_DEBUG(IWL_DL_HOST_COMMAND
| IWL_DL_RX
| IWL_DL_ISR
,
4026 "r %d i %d No handler needed for %s, 0x%02x\n",
4027 r
, i
, get_cmd_string(pkt
->hdr
.cmd
),
4032 /* Invoke any callbacks, transfer the skb to caller, and
4033 * fire off the (possibly) blocking iwl_send_cmd()
4034 * as we reclaim the driver command queue */
4035 if (rxb
&& rxb
->skb
)
4036 iwl4965_tx_cmd_complete(priv
, rxb
);
4038 IWL_WARNING("Claim null rxb?\n");
4041 /* For now we just don't re-use anything. We can tweak this
4042 * later to try and re-use notification packets and SKBs that
4043 * fail to Rx correctly */
4044 if (rxb
->skb
!= NULL
) {
4045 priv
->alloc_rxb_skb
--;
4046 dev_kfree_skb_any(rxb
->skb
);
4050 pci_unmap_single(priv
->pci_dev
, rxb
->dma_addr
,
4051 priv
->hw_setting
.rx_buf_size
,
4052 PCI_DMA_FROMDEVICE
);
4053 spin_lock_irqsave(&rxq
->lock
, flags
);
4054 list_add_tail(&rxb
->list
, &priv
->rxq
.rx_used
);
4055 spin_unlock_irqrestore(&rxq
->lock
, flags
);
4056 i
= (i
+ 1) & RX_QUEUE_MASK
;
4057 /* If there are a lot of unused frames,
4058 * restock the Rx queue so ucode wont assert. */
4063 __iwl4965_rx_replenish(priv
);
4069 /* Backtrack one entry */
4071 iwl4965_rx_queue_restock(priv
);
4075 * iwl4965_tx_queue_update_write_ptr - Send new write index to hardware
4077 static int iwl4965_tx_queue_update_write_ptr(struct iwl_priv
*priv
,
4078 struct iwl4965_tx_queue
*txq
)
4082 int txq_id
= txq
->q
.id
;
4084 if (txq
->need_update
== 0)
4087 /* if we're trying to save power */
4088 if (test_bit(STATUS_POWER_PMI
, &priv
->status
)) {
4089 /* wake up nic if it's powered down ...
4090 * uCode will wake up, and interrupt us again, so next
4091 * time we'll skip this part. */
4092 reg
= iwl_read32(priv
, CSR_UCODE_DRV_GP1
);
4094 if (reg
& CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP
) {
4095 IWL_DEBUG_INFO("Requesting wakeup, GP1 = 0x%x\n", reg
);
4096 iwl_set_bit(priv
, CSR_GP_CNTRL
,
4097 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
4101 /* restore this queue's parameters in nic hardware. */
4102 rc
= iwl_grab_nic_access(priv
);
4105 iwl_write_direct32(priv
, HBUS_TARG_WRPTR
,
4106 txq
->q
.write_ptr
| (txq_id
<< 8));
4107 iwl_release_nic_access(priv
);
4109 /* else not in power-save mode, uCode will never sleep when we're
4110 * trying to tx (during RFKILL, we're not trying to tx). */
4112 iwl_write32(priv
, HBUS_TARG_WRPTR
,
4113 txq
->q
.write_ptr
| (txq_id
<< 8));
4115 txq
->need_update
= 0;
4120 #ifdef CONFIG_IWLWIFI_DEBUG
4121 static void iwl4965_print_rx_config_cmd(struct iwl4965_rxon_cmd
*rxon
)
4123 DECLARE_MAC_BUF(mac
);
4125 IWL_DEBUG_RADIO("RX CONFIG:\n");
4126 iwl_print_hex_dump(IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
4127 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
4128 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
4129 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
4130 le32_to_cpu(rxon
->filter_flags
));
4131 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon
->dev_type
);
4132 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
4133 rxon
->ofdm_basic_rates
);
4134 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
4135 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
4136 print_mac(mac
, rxon
->node_addr
));
4137 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
4138 print_mac(mac
, rxon
->bssid_addr
));
4139 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
4143 static void iwl4965_enable_interrupts(struct iwl_priv
*priv
)
4145 IWL_DEBUG_ISR("Enabling interrupts\n");
4146 set_bit(STATUS_INT_ENABLED
, &priv
->status
);
4147 iwl_write32(priv
, CSR_INT_MASK
, CSR_INI_SET_MASK
);
4150 /* call this function to flush any scheduled tasklet */
4151 static inline void iwl_synchronize_irq(struct iwl_priv
*priv
)
4153 /* wait to make sure we flush pedding tasklet*/
4154 synchronize_irq(priv
->pci_dev
->irq
);
4155 tasklet_kill(&priv
->irq_tasklet
);
4158 static inline void iwl4965_disable_interrupts(struct iwl_priv
*priv
)
4160 clear_bit(STATUS_INT_ENABLED
, &priv
->status
);
4162 /* disable interrupts from uCode/NIC to host */
4163 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
4165 /* acknowledge/clear/reset any interrupts still pending
4166 * from uCode or flow handler (Rx/Tx DMA) */
4167 iwl_write32(priv
, CSR_INT
, 0xffffffff);
4168 iwl_write32(priv
, CSR_FH_INT_STATUS
, 0xffffffff);
4169 IWL_DEBUG_ISR("Disabled interrupts\n");
4172 static const char *desc_lookup(int i
)
4180 return "BAD_CHECKSUM";
4182 return "NMI_INTERRUPT";
4186 return "FATAL_ERROR";
4192 #define ERROR_START_OFFSET (1 * sizeof(u32))
4193 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
4195 static void iwl4965_dump_nic_error_log(struct iwl_priv
*priv
)
4198 u32 desc
, time
, count
, base
, data1
;
4199 u32 blink1
, blink2
, ilink1
, ilink2
;
4202 base
= le32_to_cpu(priv
->card_alive
.error_event_table_ptr
);
4204 if (!priv
->cfg
->ops
->lib
->is_valid_rtc_data_addr(base
)) {
4205 IWL_ERROR("Not valid error log pointer 0x%08X\n", base
);
4209 rc
= iwl_grab_nic_access(priv
);
4211 IWL_WARNING("Can not read from adapter at this time.\n");
4215 count
= iwl_read_targ_mem(priv
, base
);
4217 if (ERROR_START_OFFSET
<= count
* ERROR_ELEM_SIZE
) {
4218 IWL_ERROR("Start IWL Error Log Dump:\n");
4219 IWL_ERROR("Status: 0x%08lX, count: %d\n", priv
->status
, count
);
4222 desc
= iwl_read_targ_mem(priv
, base
+ 1 * sizeof(u32
));
4223 blink1
= iwl_read_targ_mem(priv
, base
+ 3 * sizeof(u32
));
4224 blink2
= iwl_read_targ_mem(priv
, base
+ 4 * sizeof(u32
));
4225 ilink1
= iwl_read_targ_mem(priv
, base
+ 5 * sizeof(u32
));
4226 ilink2
= iwl_read_targ_mem(priv
, base
+ 6 * sizeof(u32
));
4227 data1
= iwl_read_targ_mem(priv
, base
+ 7 * sizeof(u32
));
4228 data2
= iwl_read_targ_mem(priv
, base
+ 8 * sizeof(u32
));
4229 line
= iwl_read_targ_mem(priv
, base
+ 9 * sizeof(u32
));
4230 time
= iwl_read_targ_mem(priv
, base
+ 11 * sizeof(u32
));
4232 IWL_ERROR("Desc Time "
4233 "data1 data2 line\n");
4234 IWL_ERROR("%-13s (#%d) %010u 0x%08X 0x%08X %u\n",
4235 desc_lookup(desc
), desc
, time
, data1
, data2
, line
);
4236 IWL_ERROR("blink1 blink2 ilink1 ilink2\n");
4237 IWL_ERROR("0x%05X 0x%05X 0x%05X 0x%05X\n", blink1
, blink2
,
4240 iwl_release_nic_access(priv
);
4243 #define EVENT_START_OFFSET (4 * sizeof(u32))
4246 * iwl4965_print_event_log - Dump error event log to syslog
4248 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
4250 static void iwl4965_print_event_log(struct iwl_priv
*priv
, u32 start_idx
,
4251 u32 num_events
, u32 mode
)
4254 u32 base
; /* SRAM byte address of event log header */
4255 u32 event_size
; /* 2 u32s, or 3 u32s if timestamp recorded */
4256 u32 ptr
; /* SRAM byte address of log data */
4257 u32 ev
, time
, data
; /* event log data */
4259 if (num_events
== 0)
4262 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4265 event_size
= 2 * sizeof(u32
);
4267 event_size
= 3 * sizeof(u32
);
4269 ptr
= base
+ EVENT_START_OFFSET
+ (start_idx
* event_size
);
4271 /* "time" is actually "data" for mode 0 (no timestamp).
4272 * place event id # at far right for easier visual parsing. */
4273 for (i
= 0; i
< num_events
; i
++) {
4274 ev
= iwl_read_targ_mem(priv
, ptr
);
4276 time
= iwl_read_targ_mem(priv
, ptr
);
4279 IWL_ERROR("0x%08x\t%04u\n", time
, ev
); /* data, ev */
4281 data
= iwl_read_targ_mem(priv
, ptr
);
4283 IWL_ERROR("%010u\t0x%08x\t%04u\n", time
, data
, ev
);
4288 static void iwl4965_dump_nic_event_log(struct iwl_priv
*priv
)
4291 u32 base
; /* SRAM byte address of event log header */
4292 u32 capacity
; /* event log capacity in # entries */
4293 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
4294 u32 num_wraps
; /* # times uCode wrapped to top of log */
4295 u32 next_entry
; /* index of next entry to be written by uCode */
4296 u32 size
; /* # entries that we'll print */
4298 base
= le32_to_cpu(priv
->card_alive
.log_event_table_ptr
);
4299 if (!priv
->cfg
->ops
->lib
->is_valid_rtc_data_addr(base
)) {
4300 IWL_ERROR("Invalid event log pointer 0x%08X\n", base
);
4304 rc
= iwl_grab_nic_access(priv
);
4306 IWL_WARNING("Can not read from adapter at this time.\n");
4310 /* event log header */
4311 capacity
= iwl_read_targ_mem(priv
, base
);
4312 mode
= iwl_read_targ_mem(priv
, base
+ (1 * sizeof(u32
)));
4313 num_wraps
= iwl_read_targ_mem(priv
, base
+ (2 * sizeof(u32
)));
4314 next_entry
= iwl_read_targ_mem(priv
, base
+ (3 * sizeof(u32
)));
4316 size
= num_wraps
? capacity
: next_entry
;
4318 /* bail out if nothing in log */
4320 IWL_ERROR("Start IWL Event Log Dump: nothing in log\n");
4321 iwl_release_nic_access(priv
);
4325 IWL_ERROR("Start IWL Event Log Dump: display count %d, wraps %d\n",
4328 /* if uCode has wrapped back to top of log, start at the oldest entry,
4329 * i.e the next one that uCode would fill. */
4331 iwl4965_print_event_log(priv
, next_entry
,
4332 capacity
- next_entry
, mode
);
4334 /* (then/else) start at top of log */
4335 iwl4965_print_event_log(priv
, 0, next_entry
, mode
);
4337 iwl_release_nic_access(priv
);
4341 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
4343 static void iwl4965_irq_handle_error(struct iwl_priv
*priv
)
4345 /* Set the FW error flag -- cleared on iwl4965_down */
4346 set_bit(STATUS_FW_ERROR
, &priv
->status
);
4348 /* Cancel currently queued command. */
4349 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
4351 #ifdef CONFIG_IWLWIFI_DEBUG
4352 if (iwl_debug_level
& IWL_DL_FW_ERRORS
) {
4353 iwl4965_dump_nic_error_log(priv
);
4354 iwl4965_dump_nic_event_log(priv
);
4355 iwl4965_print_rx_config_cmd(&priv
->staging_rxon
);
4359 wake_up_interruptible(&priv
->wait_command_queue
);
4361 /* Keep the restart process from trying to send host
4362 * commands by clearing the INIT status bit */
4363 clear_bit(STATUS_READY
, &priv
->status
);
4365 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
4366 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_FW_ERRORS
,
4367 "Restarting adapter due to uCode error.\n");
4369 if (iwl_is_associated(priv
)) {
4370 memcpy(&priv
->recovery_rxon
, &priv
->active_rxon
,
4371 sizeof(priv
->recovery_rxon
));
4372 priv
->error_recovering
= 1;
4374 queue_work(priv
->workqueue
, &priv
->restart
);
4378 static void iwl4965_error_recovery(struct iwl_priv
*priv
)
4380 unsigned long flags
;
4382 memcpy(&priv
->staging_rxon
, &priv
->recovery_rxon
,
4383 sizeof(priv
->staging_rxon
));
4384 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
4385 iwl4965_commit_rxon(priv
);
4387 iwl4965_rxon_add_station(priv
, priv
->bssid
, 1);
4389 spin_lock_irqsave(&priv
->lock
, flags
);
4390 priv
->assoc_id
= le16_to_cpu(priv
->staging_rxon
.assoc_id
);
4391 priv
->error_recovering
= 0;
4392 spin_unlock_irqrestore(&priv
->lock
, flags
);
4395 static void iwl4965_irq_tasklet(struct iwl_priv
*priv
)
4397 u32 inta
, handled
= 0;
4399 unsigned long flags
;
4400 #ifdef CONFIG_IWLWIFI_DEBUG
4404 spin_lock_irqsave(&priv
->lock
, flags
);
4406 /* Ack/clear/reset pending uCode interrupts.
4407 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
4408 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
4409 inta
= iwl_read32(priv
, CSR_INT
);
4410 iwl_write32(priv
, CSR_INT
, inta
);
4412 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
4413 * Any new interrupts that happen after this, either while we're
4414 * in this tasklet, or later, will show up in next ISR/tasklet. */
4415 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4416 iwl_write32(priv
, CSR_FH_INT_STATUS
, inta_fh
);
4418 #ifdef CONFIG_IWLWIFI_DEBUG
4419 if (iwl_debug_level
& IWL_DL_ISR
) {
4420 /* just for debug */
4421 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
4422 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4423 inta
, inta_mask
, inta_fh
);
4427 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
4428 * atomic, make sure that inta covers all the interrupts that
4429 * we've discovered, even if FH interrupt came in just after
4430 * reading CSR_INT. */
4431 if (inta_fh
& CSR49_FH_INT_RX_MASK
)
4432 inta
|= CSR_INT_BIT_FH_RX
;
4433 if (inta_fh
& CSR49_FH_INT_TX_MASK
)
4434 inta
|= CSR_INT_BIT_FH_TX
;
4436 /* Now service all interrupt bits discovered above. */
4437 if (inta
& CSR_INT_BIT_HW_ERR
) {
4438 IWL_ERROR("Microcode HW error detected. Restarting.\n");
4440 /* Tell the device to stop sending interrupts */
4441 iwl4965_disable_interrupts(priv
);
4443 iwl4965_irq_handle_error(priv
);
4445 handled
|= CSR_INT_BIT_HW_ERR
;
4447 spin_unlock_irqrestore(&priv
->lock
, flags
);
4452 #ifdef CONFIG_IWLWIFI_DEBUG
4453 if (iwl_debug_level
& (IWL_DL_ISR
)) {
4454 /* NIC fires this, but we don't use it, redundant with WAKEUP */
4455 if (inta
& CSR_INT_BIT_SCD
)
4456 IWL_DEBUG_ISR("Scheduler finished to transmit "
4457 "the frame/frames.\n");
4459 /* Alive notification via Rx interrupt will do the real work */
4460 if (inta
& CSR_INT_BIT_ALIVE
)
4461 IWL_DEBUG_ISR("Alive interrupt\n");
4464 /* Safely ignore these bits for debug checks below */
4465 inta
&= ~(CSR_INT_BIT_SCD
| CSR_INT_BIT_ALIVE
);
4467 /* HW RF KILL switch toggled */
4468 if (inta
& CSR_INT_BIT_RF_KILL
) {
4470 if (!(iwl_read32(priv
, CSR_GP_CNTRL
) &
4471 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
4474 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
| IWL_DL_ISR
,
4475 "RF_KILL bit toggled to %s.\n",
4476 hw_rf_kill
? "disable radio":"enable radio");
4478 /* Queue restart only if RF_KILL switch was set to "kill"
4479 * when we loaded driver, and is now set to "enable".
4480 * After we're Alive, RF_KILL gets handled by
4481 * iwl4965_rx_card_state_notif() */
4482 if (!hw_rf_kill
&& !test_bit(STATUS_ALIVE
, &priv
->status
)) {
4483 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
4484 queue_work(priv
->workqueue
, &priv
->restart
);
4487 handled
|= CSR_INT_BIT_RF_KILL
;
4490 /* Chip got too hot and stopped itself */
4491 if (inta
& CSR_INT_BIT_CT_KILL
) {
4492 IWL_ERROR("Microcode CT kill error detected.\n");
4493 handled
|= CSR_INT_BIT_CT_KILL
;
4496 /* Error detected by uCode */
4497 if (inta
& CSR_INT_BIT_SW_ERR
) {
4498 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
4500 iwl4965_irq_handle_error(priv
);
4501 handled
|= CSR_INT_BIT_SW_ERR
;
4504 /* uCode wakes up after power-down sleep */
4505 if (inta
& CSR_INT_BIT_WAKEUP
) {
4506 IWL_DEBUG_ISR("Wakeup interrupt\n");
4507 iwl4965_rx_queue_update_write_ptr(priv
, &priv
->rxq
);
4508 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[0]);
4509 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[1]);
4510 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[2]);
4511 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[3]);
4512 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[4]);
4513 iwl4965_tx_queue_update_write_ptr(priv
, &priv
->txq
[5]);
4515 handled
|= CSR_INT_BIT_WAKEUP
;
4518 /* All uCode command responses, including Tx command responses,
4519 * Rx "responses" (frame-received notification), and other
4520 * notifications from uCode come through here*/
4521 if (inta
& (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
)) {
4522 iwl4965_rx_handle(priv
);
4523 handled
|= (CSR_INT_BIT_FH_RX
| CSR_INT_BIT_SW_RX
);
4526 if (inta
& CSR_INT_BIT_FH_TX
) {
4527 IWL_DEBUG_ISR("Tx interrupt\n");
4528 handled
|= CSR_INT_BIT_FH_TX
;
4531 if (inta
& ~handled
)
4532 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta
& ~handled
);
4534 if (inta
& ~CSR_INI_SET_MASK
) {
4535 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
4536 inta
& ~CSR_INI_SET_MASK
);
4537 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh
);
4540 /* Re-enable all interrupts */
4541 /* only Re-enable if diabled by irq */
4542 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
4543 iwl4965_enable_interrupts(priv
);
4545 #ifdef CONFIG_IWLWIFI_DEBUG
4546 if (iwl_debug_level
& (IWL_DL_ISR
)) {
4547 inta
= iwl_read32(priv
, CSR_INT
);
4548 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
);
4549 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4550 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
4551 "flags 0x%08lx\n", inta
, inta_mask
, inta_fh
, flags
);
4554 spin_unlock_irqrestore(&priv
->lock
, flags
);
4557 static irqreturn_t
iwl4965_isr(int irq
, void *data
)
4559 struct iwl_priv
*priv
= data
;
4560 u32 inta
, inta_mask
;
4565 spin_lock(&priv
->lock
);
4567 /* Disable (but don't clear!) interrupts here to avoid
4568 * back-to-back ISRs and sporadic interrupts from our NIC.
4569 * If we have something to service, the tasklet will re-enable ints.
4570 * If we *don't* have something, we'll re-enable before leaving here. */
4571 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
); /* just for debug */
4572 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
4574 /* Discover which interrupts are active/pending */
4575 inta
= iwl_read32(priv
, CSR_INT
);
4576 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
4578 /* Ignore interrupt if there's nothing in NIC to service.
4579 * This may be due to IRQ shared with another device,
4580 * or due to sporadic interrupts thrown from our NIC. */
4581 if (!inta
&& !inta_fh
) {
4582 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
4586 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
4587 /* Hardware disappeared. It might have already raised
4589 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta
);
4593 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
4594 inta
, inta_mask
, inta_fh
);
4596 inta
&= ~CSR_INT_BIT_SCD
;
4598 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
4599 if (likely(inta
|| inta_fh
))
4600 tasklet_schedule(&priv
->irq_tasklet
);
4603 spin_unlock(&priv
->lock
);
4607 /* re-enable interrupts here since we don't have anything to service. */
4608 /* only Re-enable if diabled by irq */
4609 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
4610 iwl4965_enable_interrupts(priv
);
4611 spin_unlock(&priv
->lock
);
4615 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
4616 * sending probe req. This should be set long enough to hear probe responses
4617 * from more than one AP. */
4618 #define IWL_ACTIVE_DWELL_TIME_24 (20) /* all times in msec */
4619 #define IWL_ACTIVE_DWELL_TIME_52 (10)
4621 /* For faster active scanning, scan will move to the next channel if fewer than
4622 * PLCP_QUIET_THRESH packets are heard on this channel within
4623 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
4624 * time if it's a quiet channel (nothing responded to our probe, and there's
4625 * no other traffic).
4626 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
4627 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
4628 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(5) /* msec */
4630 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
4631 * Must be set longer than active dwell time.
4632 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
4633 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
4634 #define IWL_PASSIVE_DWELL_TIME_52 (10)
4635 #define IWL_PASSIVE_DWELL_BASE (100)
4636 #define IWL_CHANNEL_TUNE_TIME 5
4638 static inline u16
iwl4965_get_active_dwell_time(struct iwl_priv
*priv
,
4639 enum ieee80211_band band
)
4641 if (band
== IEEE80211_BAND_5GHZ
)
4642 return IWL_ACTIVE_DWELL_TIME_52
;
4644 return IWL_ACTIVE_DWELL_TIME_24
;
4647 static u16
iwl4965_get_passive_dwell_time(struct iwl_priv
*priv
,
4648 enum ieee80211_band band
)
4650 u16 active
= iwl4965_get_active_dwell_time(priv
, band
);
4651 u16 passive
= (band
!= IEEE80211_BAND_5GHZ
) ?
4652 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_24
:
4653 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_52
;
4655 if (iwl_is_associated(priv
)) {
4656 /* If we're associated, we clamp the maximum passive
4657 * dwell time to be 98% of the beacon interval (minus
4658 * 2 * channel tune time) */
4659 passive
= priv
->beacon_int
;
4660 if ((passive
> IWL_PASSIVE_DWELL_BASE
) || !passive
)
4661 passive
= IWL_PASSIVE_DWELL_BASE
;
4662 passive
= (passive
* 98) / 100 - IWL_CHANNEL_TUNE_TIME
* 2;
4665 if (passive
<= active
)
4666 passive
= active
+ 1;
4671 static int iwl4965_get_channels_for_scan(struct iwl_priv
*priv
,
4672 enum ieee80211_band band
,
4673 u8 is_active
, u8 direct_mask
,
4674 struct iwl4965_scan_channel
*scan_ch
)
4676 const struct ieee80211_channel
*channels
= NULL
;
4677 const struct ieee80211_supported_band
*sband
;
4678 const struct iwl_channel_info
*ch_info
;
4679 u16 passive_dwell
= 0;
4680 u16 active_dwell
= 0;
4683 sband
= iwl4965_get_hw_mode(priv
, band
);
4687 channels
= sband
->channels
;
4689 active_dwell
= iwl4965_get_active_dwell_time(priv
, band
);
4690 passive_dwell
= iwl4965_get_passive_dwell_time(priv
, band
);
4692 for (i
= 0, added
= 0; i
< sband
->n_channels
; i
++) {
4693 if (channels
[i
].flags
& IEEE80211_CHAN_DISABLED
)
4696 if (ieee80211_frequency_to_channel(channels
[i
].center_freq
) ==
4697 le16_to_cpu(priv
->active_rxon
.channel
)) {
4698 if (iwl_is_associated(priv
)) {
4700 ("Skipping current channel %d\n",
4701 le16_to_cpu(priv
->active_rxon
.channel
));
4704 } else if (priv
->only_active_channel
)
4707 scan_ch
->channel
= ieee80211_frequency_to_channel(channels
[i
].center_freq
);
4709 ch_info
= iwl_get_channel_info(priv
, band
,
4711 if (!is_channel_valid(ch_info
)) {
4712 IWL_DEBUG_SCAN("Channel %d is INVALID for this SKU.\n",
4717 if (!is_active
|| is_channel_passive(ch_info
) ||
4718 (channels
[i
].flags
& IEEE80211_CHAN_PASSIVE_SCAN
))
4719 scan_ch
->type
= 0; /* passive */
4721 scan_ch
->type
= 1; /* active */
4723 if (scan_ch
->type
& 1)
4724 scan_ch
->type
|= (direct_mask
<< 1);
4726 if (is_channel_narrow(ch_info
))
4727 scan_ch
->type
|= (1 << 7);
4729 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
4730 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
4732 /* Set txpower levels to defaults */
4733 scan_ch
->tpc
.dsp_atten
= 110;
4734 /* scan_pwr_info->tpc.dsp_atten; */
4736 /*scan_pwr_info->tpc.tx_gain; */
4737 if (band
== IEEE80211_BAND_5GHZ
)
4738 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (3 << 3)) | 3;
4740 scan_ch
->tpc
.tx_gain
= ((1 << 5) | (5 << 3));
4741 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
4743 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
4747 IWL_DEBUG_SCAN("Scanning %d [%s %d]\n",
4749 (scan_ch
->type
& 1) ? "ACTIVE" : "PASSIVE",
4750 (scan_ch
->type
& 1) ?
4751 active_dwell
: passive_dwell
);
4757 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
4761 static void iwl4965_init_hw_rates(struct iwl_priv
*priv
,
4762 struct ieee80211_rate
*rates
)
4766 for (i
= 0; i
< IWL_RATE_COUNT
; i
++) {
4767 rates
[i
].bitrate
= iwl4965_rates
[i
].ieee
* 5;
4768 rates
[i
].hw_value
= i
; /* Rate scaling will work on indexes */
4769 rates
[i
].hw_value_short
= i
;
4771 if ((i
> IWL_LAST_OFDM_RATE
) || (i
< IWL_FIRST_OFDM_RATE
)) {
4773 * If CCK != 1M then set short preamble rate flag.
4776 (iwl4965_rates
[i
].plcp
== IWL_RATE_1M_PLCP
) ?
4777 0 : IEEE80211_RATE_SHORT_PREAMBLE
;
4783 * iwl4965_init_geos - Initialize mac80211's geo/channel info based from eeprom
4785 int iwl4965_init_geos(struct iwl_priv
*priv
)
4787 struct iwl_channel_info
*ch
;
4788 struct ieee80211_supported_band
*sband
;
4789 struct ieee80211_channel
*channels
;
4790 struct ieee80211_channel
*geo_ch
;
4791 struct ieee80211_rate
*rates
;
4794 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_bitrates
||
4795 priv
->bands
[IEEE80211_BAND_5GHZ
].n_bitrates
) {
4796 IWL_DEBUG_INFO("Geography modes already initialized.\n");
4797 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
4801 channels
= kzalloc(sizeof(struct ieee80211_channel
) *
4802 priv
->channel_count
, GFP_KERNEL
);
4806 rates
= kzalloc((sizeof(struct ieee80211_rate
) * (IWL_RATE_COUNT
+ 1)),
4813 /* 5.2GHz channels start after the 2.4GHz channels */
4814 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
4815 sband
->channels
= &channels
[ARRAY_SIZE(iwl_eeprom_band_1
)];
4817 sband
->bitrates
= &rates
[IWL_FIRST_OFDM_RATE
];
4818 sband
->n_bitrates
= IWL_RATE_COUNT
- IWL_FIRST_OFDM_RATE
;
4820 iwl4965_init_ht_hw_capab(priv
, &sband
->ht_info
, IEEE80211_BAND_5GHZ
);
4822 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
4823 sband
->channels
= channels
;
4825 sband
->bitrates
= rates
;
4826 sband
->n_bitrates
= IWL_RATE_COUNT
;
4828 iwl4965_init_ht_hw_capab(priv
, &sband
->ht_info
, IEEE80211_BAND_2GHZ
);
4830 priv
->ieee_channels
= channels
;
4831 priv
->ieee_rates
= rates
;
4833 iwl4965_init_hw_rates(priv
, rates
);
4835 for (i
= 0; i
< priv
->channel_count
; i
++) {
4836 ch
= &priv
->channel_info
[i
];
4838 /* FIXME: might be removed if scan is OK */
4839 if (!is_channel_valid(ch
))
4842 if (is_channel_a_band(ch
))
4843 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
4845 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
4847 geo_ch
= &sband
->channels
[sband
->n_channels
++];
4849 geo_ch
->center_freq
= ieee80211_channel_to_frequency(ch
->channel
);
4850 geo_ch
->max_power
= ch
->max_power_avg
;
4851 geo_ch
->max_antenna_gain
= 0xff;
4852 geo_ch
->hw_value
= ch
->channel
;
4854 if (is_channel_valid(ch
)) {
4855 if (!(ch
->flags
& EEPROM_CHANNEL_IBSS
))
4856 geo_ch
->flags
|= IEEE80211_CHAN_NO_IBSS
;
4858 if (!(ch
->flags
& EEPROM_CHANNEL_ACTIVE
))
4859 geo_ch
->flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
4861 if (ch
->flags
& EEPROM_CHANNEL_RADAR
)
4862 geo_ch
->flags
|= IEEE80211_CHAN_RADAR
;
4864 if (ch
->max_power_avg
> priv
->max_channel_txpower_limit
)
4865 priv
->max_channel_txpower_limit
=
4868 geo_ch
->flags
|= IEEE80211_CHAN_DISABLED
;
4871 /* Save flags for reg domain usage */
4872 geo_ch
->orig_flags
= geo_ch
->flags
;
4874 IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
4875 ch
->channel
, geo_ch
->center_freq
,
4876 is_channel_a_band(ch
) ? "5.2" : "2.4",
4877 geo_ch
->flags
& IEEE80211_CHAN_DISABLED
?
4878 "restricted" : "valid",
4882 if ((priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
== 0) &&
4883 priv
->cfg
->sku
& IWL_SKU_A
) {
4884 printk(KERN_INFO DRV_NAME
4885 ": Incorrectly detected BG card as ABG. Please send "
4886 "your PCI ID 0x%04X:0x%04X to maintainer.\n",
4887 priv
->pci_dev
->device
, priv
->pci_dev
->subsystem_device
);
4888 priv
->cfg
->sku
&= ~IWL_SKU_A
;
4891 printk(KERN_INFO DRV_NAME
4892 ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
4893 priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
,
4894 priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
);
4896 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
4897 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
4898 &priv
->bands
[IEEE80211_BAND_2GHZ
];
4899 if (priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
4900 priv
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
4901 &priv
->bands
[IEEE80211_BAND_5GHZ
];
4903 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
4909 * iwl4965_free_geos - undo allocations in iwl4965_init_geos
4911 void iwl4965_free_geos(struct iwl_priv
*priv
)
4913 kfree(priv
->ieee_channels
);
4914 kfree(priv
->ieee_rates
);
4915 clear_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
4918 /******************************************************************************
4920 * uCode download functions
4922 ******************************************************************************/
4924 static void iwl4965_dealloc_ucode_pci(struct iwl_priv
*priv
)
4926 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
4927 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
4928 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
4929 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
4930 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
4931 iwl_free_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
4935 * iwl4965_verify_inst_full - verify runtime uCode image in card vs. host,
4936 * looking at all data.
4938 static int iwl4965_verify_inst_full(struct iwl_priv
*priv
, __le32
*image
,
4946 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
4948 rc
= iwl_grab_nic_access(priv
);
4952 iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
, RTC_INST_LOWER_BOUND
);
4955 for (; len
> 0; len
-= sizeof(u32
), image
++) {
4956 /* read data comes through single port, auto-incr addr */
4957 /* NOTE: Use the debugless read so we don't flood kernel log
4958 * if IWL_DL_IO is set */
4959 val
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
4960 if (val
!= le32_to_cpu(*image
)) {
4961 IWL_ERROR("uCode INST section is invalid at "
4962 "offset 0x%x, is 0x%x, s/b 0x%x\n",
4963 save_len
- len
, val
, le32_to_cpu(*image
));
4971 iwl_release_nic_access(priv
);
4975 ("ucode image in INSTRUCTION memory is good\n");
4982 * iwl4965_verify_inst_sparse - verify runtime uCode image in card vs. host,
4983 * using sample data 100 bytes apart. If these sample points are good,
4984 * it's a pretty good bet that everything between them is good, too.
4986 static int iwl4965_verify_inst_sparse(struct iwl_priv
*priv
, __le32
*image
, u32 len
)
4993 IWL_DEBUG_INFO("ucode inst image size is %u\n", len
);
4995 rc
= iwl_grab_nic_access(priv
);
4999 for (i
= 0; i
< len
; i
+= 100, image
+= 100/sizeof(u32
)) {
5000 /* read data comes through single port, auto-incr addr */
5001 /* NOTE: Use the debugless read so we don't flood kernel log
5002 * if IWL_DL_IO is set */
5003 iwl_write_direct32(priv
, HBUS_TARG_MEM_RADDR
,
5004 i
+ RTC_INST_LOWER_BOUND
);
5005 val
= _iwl_read_direct32(priv
, HBUS_TARG_MEM_RDAT
);
5006 if (val
!= le32_to_cpu(*image
)) {
5007 #if 0 /* Enable this if you want to see details */
5008 IWL_ERROR("uCode INST section is invalid at "
5009 "offset 0x%x, is 0x%x, s/b 0x%x\n",
5019 iwl_release_nic_access(priv
);
5026 * iwl4965_verify_ucode - determine which instruction image is in SRAM,
5027 * and verify its contents
5029 static int iwl4965_verify_ucode(struct iwl_priv
*priv
)
5036 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5037 len
= priv
->ucode_boot
.len
;
5038 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
5040 IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
5044 /* Try initialize */
5045 image
= (__le32
*)priv
->ucode_init
.v_addr
;
5046 len
= priv
->ucode_init
.len
;
5047 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
5049 IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
5053 /* Try runtime/protocol */
5054 image
= (__le32
*)priv
->ucode_code
.v_addr
;
5055 len
= priv
->ucode_code
.len
;
5056 rc
= iwl4965_verify_inst_sparse(priv
, image
, len
);
5058 IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
5062 IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
5064 /* Since nothing seems to match, show first several data entries in
5065 * instruction SRAM, so maybe visual inspection will give a clue.
5066 * Selection of bootstrap image (vs. other images) is arbitrary. */
5067 image
= (__le32
*)priv
->ucode_boot
.v_addr
;
5068 len
= priv
->ucode_boot
.len
;
5069 rc
= iwl4965_verify_inst_full(priv
, image
, len
);
5074 static void iwl4965_nic_start(struct iwl_priv
*priv
)
5076 /* Remove all resets to allow NIC to operate */
5077 iwl_write32(priv
, CSR_RESET
, 0);
5082 * iwl4965_read_ucode - Read uCode images from disk file.
5084 * Copy into buffers for card to fetch via bus-mastering
5086 static int iwl4965_read_ucode(struct iwl_priv
*priv
)
5088 struct iwl4965_ucode
*ucode
;
5090 const struct firmware
*ucode_raw
;
5091 const char *name
= priv
->cfg
->fw_name
;
5094 u32 ver
, inst_size
, data_size
, init_size
, init_data_size
, boot_size
;
5096 /* Ask kernel firmware_class module to get the boot firmware off disk.
5097 * request_firmware() is synchronous, file is in memory on return. */
5098 ret
= request_firmware(&ucode_raw
, name
, &priv
->pci_dev
->dev
);
5100 IWL_ERROR("%s firmware file req failed: Reason %d\n",
5105 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
5106 name
, ucode_raw
->size
);
5108 /* Make sure that we got at least our header! */
5109 if (ucode_raw
->size
< sizeof(*ucode
)) {
5110 IWL_ERROR("File size way too small!\n");
5115 /* Data from ucode file: header followed by uCode images */
5116 ucode
= (void *)ucode_raw
->data
;
5118 ver
= le32_to_cpu(ucode
->ver
);
5119 inst_size
= le32_to_cpu(ucode
->inst_size
);
5120 data_size
= le32_to_cpu(ucode
->data_size
);
5121 init_size
= le32_to_cpu(ucode
->init_size
);
5122 init_data_size
= le32_to_cpu(ucode
->init_data_size
);
5123 boot_size
= le32_to_cpu(ucode
->boot_size
);
5125 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver
);
5126 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
5128 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
5130 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
5132 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
5134 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
5137 /* Verify size of file vs. image size info in file's header */
5138 if (ucode_raw
->size
< sizeof(*ucode
) +
5139 inst_size
+ data_size
+ init_size
+
5140 init_data_size
+ boot_size
) {
5142 IWL_DEBUG_INFO("uCode file size %d too small\n",
5143 (int)ucode_raw
->size
);
5148 /* Verify that uCode images will fit in card's SRAM */
5149 if (inst_size
> IWL_MAX_INST_SIZE
) {
5150 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
5156 if (data_size
> IWL_MAX_DATA_SIZE
) {
5157 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
5162 if (init_size
> IWL_MAX_INST_SIZE
) {
5164 ("uCode init instr len %d too large to fit in\n",
5169 if (init_data_size
> IWL_MAX_DATA_SIZE
) {
5171 ("uCode init data len %d too large to fit in\n",
5176 if (boot_size
> IWL_MAX_BSM_SIZE
) {
5178 ("uCode boot instr len %d too large to fit in\n",
5184 /* Allocate ucode buffers for card's bus-master loading ... */
5186 /* Runtime instructions and 2 copies of data:
5187 * 1) unmodified from disk
5188 * 2) backup cache for save/restore during power-downs */
5189 priv
->ucode_code
.len
= inst_size
;
5190 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_code
);
5192 priv
->ucode_data
.len
= data_size
;
5193 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data
);
5195 priv
->ucode_data_backup
.len
= data_size
;
5196 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_data_backup
);
5198 /* Initialization instructions and data */
5199 if (init_size
&& init_data_size
) {
5200 priv
->ucode_init
.len
= init_size
;
5201 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init
);
5203 priv
->ucode_init_data
.len
= init_data_size
;
5204 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_init_data
);
5206 if (!priv
->ucode_init
.v_addr
|| !priv
->ucode_init_data
.v_addr
)
5210 /* Bootstrap (instructions only, no data) */
5212 priv
->ucode_boot
.len
= boot_size
;
5213 iwl_alloc_fw_desc(priv
->pci_dev
, &priv
->ucode_boot
);
5215 if (!priv
->ucode_boot
.v_addr
)
5219 /* Copy images into buffers for card's bus-master reads ... */
5221 /* Runtime instructions (first block of data in file) */
5222 src
= &ucode
->data
[0];
5223 len
= priv
->ucode_code
.len
;
5224 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len
);
5225 memcpy(priv
->ucode_code
.v_addr
, src
, len
);
5226 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
5227 priv
->ucode_code
.v_addr
, (u32
)priv
->ucode_code
.p_addr
);
5229 /* Runtime data (2nd block)
5230 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
5231 src
= &ucode
->data
[inst_size
];
5232 len
= priv
->ucode_data
.len
;
5233 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len
);
5234 memcpy(priv
->ucode_data
.v_addr
, src
, len
);
5235 memcpy(priv
->ucode_data_backup
.v_addr
, src
, len
);
5237 /* Initialization instructions (3rd block) */
5239 src
= &ucode
->data
[inst_size
+ data_size
];
5240 len
= priv
->ucode_init
.len
;
5241 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
5243 memcpy(priv
->ucode_init
.v_addr
, src
, len
);
5246 /* Initialization data (4th block) */
5247 if (init_data_size
) {
5248 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
];
5249 len
= priv
->ucode_init_data
.len
;
5250 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
5252 memcpy(priv
->ucode_init_data
.v_addr
, src
, len
);
5255 /* Bootstrap instructions (5th block) */
5256 src
= &ucode
->data
[inst_size
+ data_size
+ init_size
+ init_data_size
];
5257 len
= priv
->ucode_boot
.len
;
5258 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len
);
5259 memcpy(priv
->ucode_boot
.v_addr
, src
, len
);
5261 /* We have our copies now, allow OS release its copies */
5262 release_firmware(ucode_raw
);
5266 IWL_ERROR("failed to allocate pci memory\n");
5268 iwl4965_dealloc_ucode_pci(priv
);
5271 release_firmware(ucode_raw
);
5279 * iwl4965_set_ucode_ptrs - Set uCode address location
5281 * Tell initialization uCode where to find runtime uCode.
5283 * BSM registers initially contain pointers to initialization uCode.
5284 * We need to replace them to load runtime uCode inst and data,
5285 * and to save runtime data when powering down.
5287 static int iwl4965_set_ucode_ptrs(struct iwl_priv
*priv
)
5292 unsigned long flags
;
5294 /* bits 35:4 for 4965 */
5295 pinst
= priv
->ucode_code
.p_addr
>> 4;
5296 pdata
= priv
->ucode_data_backup
.p_addr
>> 4;
5298 spin_lock_irqsave(&priv
->lock
, flags
);
5299 rc
= iwl_grab_nic_access(priv
);
5301 spin_unlock_irqrestore(&priv
->lock
, flags
);
5305 /* Tell bootstrap uCode where to find image to load */
5306 iwl_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
5307 iwl_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
5308 iwl_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
,
5309 priv
->ucode_data
.len
);
5311 /* Inst bytecount must be last to set up, bit 31 signals uCode
5312 * that all new ptr/size info is in place */
5313 iwl_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
,
5314 priv
->ucode_code
.len
| BSM_DRAM_INST_LOAD
);
5316 iwl_release_nic_access(priv
);
5318 spin_unlock_irqrestore(&priv
->lock
, flags
);
5320 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
5326 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
5328 * Called after REPLY_ALIVE notification received from "initialize" uCode.
5330 * The 4965 "initialize" ALIVE reply contains calibration data for:
5331 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
5332 * (3945 does not contain this data).
5334 * Tell "initialize" uCode to go ahead and load the runtime uCode.
5336 static void iwl4965_init_alive_start(struct iwl_priv
*priv
)
5338 /* Check alive response for "valid" sign from uCode */
5339 if (priv
->card_alive_init
.is_valid
!= UCODE_VALID_OK
) {
5340 /* We had an error bringing up the hardware, so take it
5341 * all the way back down so we can try again */
5342 IWL_DEBUG_INFO("Initialize Alive failed.\n");
5346 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
5347 * This is a paranoid check, because we would not have gotten the
5348 * "initialize" alive if code weren't properly loaded. */
5349 if (iwl4965_verify_ucode(priv
)) {
5350 /* Runtime instruction load was bad;
5351 * take it all the way back down so we can try again */
5352 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
5356 /* Calculate temperature */
5357 priv
->temperature
= iwl4965_get_temperature(priv
);
5359 /* Send pointers to protocol/runtime uCode image ... init code will
5360 * load and launch runtime uCode, which will send us another "Alive"
5362 IWL_DEBUG_INFO("Initialization Alive received.\n");
5363 if (iwl4965_set_ucode_ptrs(priv
)) {
5364 /* Runtime instruction load won't happen;
5365 * take it all the way back down so we can try again */
5366 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
5372 queue_work(priv
->workqueue
, &priv
->restart
);
5377 * iwl4965_alive_start - called after REPLY_ALIVE notification received
5378 * from protocol/runtime uCode (initialization uCode's
5379 * Alive gets handled by iwl4965_init_alive_start()).
5381 static void iwl4965_alive_start(struct iwl_priv
*priv
)
5385 IWL_DEBUG_INFO("Runtime Alive received.\n");
5387 if (priv
->card_alive
.is_valid
!= UCODE_VALID_OK
) {
5388 /* We had an error bringing up the hardware, so take it
5389 * all the way back down so we can try again */
5390 IWL_DEBUG_INFO("Alive failed.\n");
5394 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
5395 * This is a paranoid check, because we would not have gotten the
5396 * "runtime" alive if code weren't properly loaded. */
5397 if (iwl4965_verify_ucode(priv
)) {
5398 /* Runtime instruction load was bad;
5399 * take it all the way back down so we can try again */
5400 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
5404 iwlcore_clear_stations_table(priv
);
5406 ret
= priv
->cfg
->ops
->lib
->alive_notify(priv
);
5408 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
5413 /* After the ALIVE response, we can send host commands to 4965 uCode */
5414 set_bit(STATUS_ALIVE
, &priv
->status
);
5416 /* Clear out the uCode error bit if it is set */
5417 clear_bit(STATUS_FW_ERROR
, &priv
->status
);
5419 if (iwl_is_rfkill(priv
))
5422 ieee80211_start_queues(priv
->hw
);
5424 priv
->active_rate
= priv
->rates_mask
;
5425 priv
->active_rate_basic
= priv
->rates_mask
& IWL_BASIC_RATES_MASK
;
5427 iwl4965_send_power_mode(priv
, IWL_POWER_LEVEL(priv
->power_mode
));
5429 if (iwl_is_associated(priv
)) {
5430 struct iwl4965_rxon_cmd
*active_rxon
=
5431 (struct iwl4965_rxon_cmd
*)(&priv
->active_rxon
);
5433 memcpy(&priv
->staging_rxon
, &priv
->active_rxon
,
5434 sizeof(priv
->staging_rxon
));
5435 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
5437 /* Initialize our rx_config data */
5438 iwl4965_connection_init_rx_config(priv
);
5439 memcpy(priv
->staging_rxon
.node_addr
, priv
->mac_addr
, ETH_ALEN
);
5442 /* Configure Bluetooth device coexistence support */
5443 iwl4965_send_bt_config(priv
);
5445 /* Configure the adapter for unassociated operation */
5446 iwl4965_commit_rxon(priv
);
5448 /* At this point, the NIC is initialized and operational */
5449 priv
->notif_missed_beacons
= 0;
5451 iwl4965_rf_kill_ct_config(priv
);
5453 iwl_leds_register(priv
);
5455 IWL_DEBUG_INFO("ALIVE processing complete.\n");
5456 set_bit(STATUS_READY
, &priv
->status
);
5457 wake_up_interruptible(&priv
->wait_command_queue
);
5459 if (priv
->error_recovering
)
5460 iwl4965_error_recovery(priv
);
5462 iwlcore_low_level_notify(priv
, IWLCORE_START_EVT
);
5463 ieee80211_notify_mac(priv
->hw
, IEEE80211_NOTIFY_RE_ASSOC
);
5467 queue_work(priv
->workqueue
, &priv
->restart
);
5470 static void iwl4965_cancel_deferred_work(struct iwl_priv
*priv
);
5472 static void __iwl4965_down(struct iwl_priv
*priv
)
5474 unsigned long flags
;
5475 int exit_pending
= test_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5476 struct ieee80211_conf
*conf
= NULL
;
5478 IWL_DEBUG_INFO(DRV_NAME
" is going down\n");
5480 conf
= ieee80211_get_hw_conf(priv
->hw
);
5483 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5485 iwl_leds_unregister(priv
);
5487 iwlcore_low_level_notify(priv
, IWLCORE_STOP_EVT
);
5489 iwlcore_clear_stations_table(priv
);
5491 /* Unblock any waiting calls */
5492 wake_up_interruptible_all(&priv
->wait_command_queue
);
5494 /* Wipe out the EXIT_PENDING status bit if we are not actually
5495 * exiting the module */
5497 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5499 /* stop and reset the on-board processor */
5500 iwl_write32(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_NEVO_RESET
);
5502 /* tell the device to stop sending interrupts */
5503 spin_lock_irqsave(&priv
->lock
, flags
);
5504 iwl4965_disable_interrupts(priv
);
5505 spin_unlock_irqrestore(&priv
->lock
, flags
);
5506 iwl_synchronize_irq(priv
);
5508 if (priv
->mac80211_registered
)
5509 ieee80211_stop_queues(priv
->hw
);
5511 /* If we have not previously called iwl4965_init() then
5512 * clear all bits but the RF Kill and SUSPEND bits and return */
5513 if (!iwl_is_init(priv
)) {
5514 priv
->status
= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
5516 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
5518 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
5519 STATUS_GEO_CONFIGURED
|
5520 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
5525 /* ...otherwise clear out all the status bits but the RF Kill and
5526 * SUSPEND bits and continue taking the NIC down. */
5527 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
5529 test_bit(STATUS_RF_KILL_SW
, &priv
->status
) <<
5531 test_bit(STATUS_GEO_CONFIGURED
, &priv
->status
) <<
5532 STATUS_GEO_CONFIGURED
|
5533 test_bit(STATUS_IN_SUSPEND
, &priv
->status
) <<
5535 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
5538 spin_lock_irqsave(&priv
->lock
, flags
);
5539 iwl_clear_bit(priv
, CSR_GP_CNTRL
,
5540 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ
);
5541 spin_unlock_irqrestore(&priv
->lock
, flags
);
5543 iwl4965_hw_txq_ctx_stop(priv
);
5544 iwl4965_hw_rxq_stop(priv
);
5546 spin_lock_irqsave(&priv
->lock
, flags
);
5547 if (!iwl_grab_nic_access(priv
)) {
5548 iwl_write_prph(priv
, APMG_CLK_DIS_REG
,
5549 APMG_CLK_VAL_DMA_CLK_RQT
);
5550 iwl_release_nic_access(priv
);
5552 spin_unlock_irqrestore(&priv
->lock
, flags
);
5556 iwl4965_hw_nic_stop_master(priv
);
5557 iwl_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_SW_RESET
);
5558 iwl4965_hw_nic_reset(priv
);
5561 memset(&priv
->card_alive
, 0, sizeof(struct iwl4965_alive_resp
));
5563 if (priv
->ibss_beacon
)
5564 dev_kfree_skb(priv
->ibss_beacon
);
5565 priv
->ibss_beacon
= NULL
;
5567 /* clear out any free frames */
5568 iwl4965_clear_free_frames(priv
);
5571 static void iwl4965_down(struct iwl_priv
*priv
)
5573 mutex_lock(&priv
->mutex
);
5574 __iwl4965_down(priv
);
5575 mutex_unlock(&priv
->mutex
);
5577 iwl4965_cancel_deferred_work(priv
);
5580 #define MAX_HW_RESTARTS 5
5582 static int __iwl4965_up(struct iwl_priv
*priv
)
5587 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
5588 IWL_WARNING("Exit pending; will not bring the NIC up\n");
5592 if (test_bit(STATUS_RF_KILL_SW
, &priv
->status
)) {
5593 IWL_WARNING("Radio disabled by SW RF kill (module "
5595 iwl_rfkill_set_hw_state(priv
);
5599 if (!priv
->ucode_data_backup
.v_addr
|| !priv
->ucode_data
.v_addr
) {
5600 IWL_ERROR("ucode not available for device bringup\n");
5604 /* If platform's RF_KILL switch is NOT set to KILL */
5605 if (iwl_read32(priv
, CSR_GP_CNTRL
) &
5606 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
)
5607 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5609 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
5610 if (!test_bit(STATUS_IN_SUSPEND
, &priv
->status
)) {
5611 iwl_rfkill_set_hw_state(priv
);
5612 IWL_WARNING("Radio disabled by HW RF Kill switch\n");
5617 iwl_rfkill_set_hw_state(priv
);
5618 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
5620 ret
= priv
->cfg
->ops
->lib
->hw_nic_init(priv
);
5622 IWL_ERROR("Unable to init nic\n");
5626 /* make sure rfkill handshake bits are cleared */
5627 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5628 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
,
5629 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
5631 /* clear (again), then enable host interrupts */
5632 iwl_write32(priv
, CSR_INT
, 0xFFFFFFFF);
5633 iwl4965_enable_interrupts(priv
);
5635 /* really make sure rfkill handshake bits are cleared */
5636 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5637 iwl_write32(priv
, CSR_UCODE_DRV_GP1_CLR
, CSR_UCODE_SW_BIT_RFKILL
);
5639 /* Copy original ucode data image from disk into backup cache.
5640 * This will be used to initialize the on-board processor's
5641 * data SRAM for a clean start when the runtime program first loads. */
5642 memcpy(priv
->ucode_data_backup
.v_addr
, priv
->ucode_data
.v_addr
,
5643 priv
->ucode_data
.len
);
5645 /* We return success when we resume from suspend and rf_kill is on. */
5646 if (test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
5649 for (i
= 0; i
< MAX_HW_RESTARTS
; i
++) {
5651 iwlcore_clear_stations_table(priv
);
5653 /* load bootstrap state machine,
5654 * load bootstrap program into processor's memory,
5655 * prepare to load the "initialize" uCode */
5656 ret
= priv
->cfg
->ops
->lib
->load_ucode(priv
);
5659 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret
);
5663 /* start card; "initialize" will load runtime ucode */
5664 iwl4965_nic_start(priv
);
5666 IWL_DEBUG_INFO(DRV_NAME
" is coming up\n");
5671 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
5672 __iwl4965_down(priv
);
5674 /* tried to restart and config the device for as long as our
5675 * patience could withstand */
5676 IWL_ERROR("Unable to initialize device after %d attempts.\n", i
);
5681 /*****************************************************************************
5683 * Workqueue callbacks
5685 *****************************************************************************/
5687 static void iwl4965_bg_init_alive_start(struct work_struct
*data
)
5689 struct iwl_priv
*priv
=
5690 container_of(data
, struct iwl_priv
, init_alive_start
.work
);
5692 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5695 mutex_lock(&priv
->mutex
);
5696 iwl4965_init_alive_start(priv
);
5697 mutex_unlock(&priv
->mutex
);
5700 static void iwl4965_bg_alive_start(struct work_struct
*data
)
5702 struct iwl_priv
*priv
=
5703 container_of(data
, struct iwl_priv
, alive_start
.work
);
5705 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5708 mutex_lock(&priv
->mutex
);
5709 iwl4965_alive_start(priv
);
5710 mutex_unlock(&priv
->mutex
);
5713 static void iwl4965_bg_rf_kill(struct work_struct
*work
)
5715 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, rf_kill
);
5717 wake_up_interruptible(&priv
->wait_command_queue
);
5719 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5722 mutex_lock(&priv
->mutex
);
5724 if (!iwl_is_rfkill(priv
)) {
5725 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_RF_KILL
,
5726 "HW and/or SW RF Kill no longer active, restarting "
5728 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5729 queue_work(priv
->workqueue
, &priv
->restart
);
5731 /* make sure mac80211 stop sending Tx frame */
5732 if (priv
->mac80211_registered
)
5733 ieee80211_stop_queues(priv
->hw
);
5735 if (!test_bit(STATUS_RF_KILL_HW
, &priv
->status
))
5736 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
5737 "disabled by SW switch\n");
5739 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
5740 "Kill switch must be turned off for "
5741 "wireless networking to work.\n");
5743 iwl_rfkill_set_hw_state(priv
);
5745 mutex_unlock(&priv
->mutex
);
5748 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
5750 static void iwl4965_bg_scan_check(struct work_struct
*data
)
5752 struct iwl_priv
*priv
=
5753 container_of(data
, struct iwl_priv
, scan_check
.work
);
5755 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5758 mutex_lock(&priv
->mutex
);
5759 if (test_bit(STATUS_SCANNING
, &priv
->status
) ||
5760 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
5761 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
,
5762 "Scan completion watchdog resetting adapter (%dms)\n",
5763 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG
));
5765 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5766 iwl4965_send_scan_abort(priv
);
5768 mutex_unlock(&priv
->mutex
);
5771 static void iwl4965_bg_request_scan(struct work_struct
*data
)
5773 struct iwl_priv
*priv
=
5774 container_of(data
, struct iwl_priv
, request_scan
);
5775 struct iwl_host_cmd cmd
= {
5776 .id
= REPLY_SCAN_CMD
,
5777 .len
= sizeof(struct iwl4965_scan_cmd
),
5778 .meta
.flags
= CMD_SIZE_HUGE
,
5780 struct iwl4965_scan_cmd
*scan
;
5781 struct ieee80211_conf
*conf
= NULL
;
5783 enum ieee80211_band band
;
5787 conf
= ieee80211_get_hw_conf(priv
->hw
);
5789 mutex_lock(&priv
->mutex
);
5791 if (!iwl_is_ready(priv
)) {
5792 IWL_WARNING("request scan called when driver not ready.\n");
5796 /* Make sure the scan wasn't cancelled before this queued work
5797 * was given the chance to run... */
5798 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
5801 /* This should never be called or scheduled if there is currently
5802 * a scan active in the hardware. */
5803 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
5804 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
5805 "Ignoring second request.\n");
5810 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
5811 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
5815 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
5816 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
5820 if (iwl_is_rfkill(priv
)) {
5821 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
5825 if (!test_bit(STATUS_READY
, &priv
->status
)) {
5826 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
5830 if (!priv
->scan_bands
) {
5831 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
5836 priv
->scan
= kmalloc(sizeof(struct iwl4965_scan_cmd
) +
5837 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
5844 memset(scan
, 0, sizeof(struct iwl4965_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
5846 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
5847 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
5849 if (iwl_is_associated(priv
)) {
5852 u32 suspend_time
= 100;
5853 u32 scan_suspend_time
= 100;
5854 unsigned long flags
;
5856 IWL_DEBUG_INFO("Scanning while associated...\n");
5858 spin_lock_irqsave(&priv
->lock
, flags
);
5859 interval
= priv
->beacon_int
;
5860 spin_unlock_irqrestore(&priv
->lock
, flags
);
5862 scan
->suspend_time
= 0;
5863 scan
->max_out_time
= cpu_to_le32(200 * 1024);
5865 interval
= suspend_time
;
5867 extra
= (suspend_time
/ interval
) << 22;
5868 scan_suspend_time
= (extra
|
5869 ((suspend_time
% interval
) * 1024));
5870 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
5871 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
5872 scan_suspend_time
, interval
);
5875 /* We should add the ability for user to lock to PASSIVE ONLY */
5876 if (priv
->one_direct_scan
) {
5878 ("Kicking off one direct scan for '%s'\n",
5879 iwl4965_escape_essid(priv
->direct_ssid
,
5880 priv
->direct_ssid_len
));
5881 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
5882 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
5883 memcpy(scan
->direct_scan
[0].ssid
,
5884 priv
->direct_ssid
, priv
->direct_ssid_len
);
5886 } else if (!iwl_is_associated(priv
) && priv
->essid_len
) {
5887 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
5888 scan
->direct_scan
[0].len
= priv
->essid_len
;
5889 memcpy(scan
->direct_scan
[0].ssid
, priv
->essid
, priv
->essid_len
);
5895 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
5896 scan
->tx_cmd
.sta_id
= priv
->hw_setting
.bcast_sta_id
;
5897 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
5900 switch (priv
->scan_bands
) {
5902 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
5903 scan
->tx_cmd
.rate_n_flags
=
5904 iwl4965_hw_set_rate_n_flags(IWL_RATE_1M_PLCP
,
5905 RATE_MCS_ANT_B_MSK
|RATE_MCS_CCK_MSK
);
5907 scan
->good_CRC_th
= 0;
5908 band
= IEEE80211_BAND_2GHZ
;
5912 scan
->tx_cmd
.rate_n_flags
=
5913 iwl4965_hw_set_rate_n_flags(IWL_RATE_6M_PLCP
,
5914 RATE_MCS_ANT_B_MSK
);
5915 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
5916 band
= IEEE80211_BAND_5GHZ
;
5920 IWL_WARNING("Invalid scan band count\n");
5924 /* We don't build a direct scan probe request; the uCode will do
5925 * that based on the direct_mask added to each channel entry */
5926 cmd_len
= iwl4965_fill_probe_req(priv
, band
,
5927 (struct ieee80211_mgmt
*)scan
->data
,
5928 IWL_MAX_SCAN_SIZE
- sizeof(*scan
), 0);
5930 scan
->tx_cmd
.len
= cpu_to_le16(cmd_len
);
5931 /* select Rx chains */
5933 /* Force use of chains B and C (0x6) for scan Rx.
5934 * Avoid A (0x1) because of its off-channel reception on A-band.
5935 * MIMO is not used here, but value is required to make uCode happy. */
5936 scan
->rx_chain
= RXON_RX_CHAIN_DRIVER_FORCE_MSK
|
5937 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS
) |
5938 (0x6 << RXON_RX_CHAIN_FORCE_SEL_POS
) |
5939 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS
));
5941 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
)
5942 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
5946 ("Initiating direct scan for %s.\n",
5947 iwl4965_escape_essid(priv
->essid
, priv
->essid_len
));
5948 scan
->channel_count
=
5949 iwl4965_get_channels_for_scan(
5950 priv
, band
, 1, /* active */
5952 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
5954 IWL_DEBUG_SCAN("Initiating indirect scan.\n");
5955 scan
->channel_count
=
5956 iwl4965_get_channels_for_scan(
5957 priv
, band
, 0, /* passive */
5959 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
5962 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
5963 scan
->channel_count
* sizeof(struct iwl4965_scan_channel
);
5965 scan
->len
= cpu_to_le16(cmd
.len
);
5967 set_bit(STATUS_SCAN_HW
, &priv
->status
);
5968 ret
= iwl_send_cmd_sync(priv
, &cmd
);
5972 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
5973 IWL_SCAN_CHECK_WATCHDOG
);
5975 mutex_unlock(&priv
->mutex
);
5979 /* inform mac80211 scan aborted */
5980 queue_work(priv
->workqueue
, &priv
->scan_completed
);
5981 mutex_unlock(&priv
->mutex
);
5984 static void iwl4965_bg_up(struct work_struct
*data
)
5986 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, up
);
5988 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
5991 mutex_lock(&priv
->mutex
);
5993 mutex_unlock(&priv
->mutex
);
5996 static void iwl4965_bg_restart(struct work_struct
*data
)
5998 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
6000 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6004 queue_work(priv
->workqueue
, &priv
->up
);
6007 static void iwl4965_bg_rx_replenish(struct work_struct
*data
)
6009 struct iwl_priv
*priv
=
6010 container_of(data
, struct iwl_priv
, rx_replenish
);
6012 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6015 mutex_lock(&priv
->mutex
);
6016 iwl4965_rx_replenish(priv
);
6017 mutex_unlock(&priv
->mutex
);
6020 #define IWL_DELAY_NEXT_SCAN (HZ*2)
6022 static void iwl4965_bg_post_associate(struct work_struct
*data
)
6024 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
,
6025 post_associate
.work
);
6026 struct ieee80211_conf
*conf
= NULL
;
6028 DECLARE_MAC_BUF(mac
);
6030 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
6031 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__
);
6035 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
6037 print_mac(mac
, priv
->active_rxon
.bssid_addr
));
6040 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6043 mutex_lock(&priv
->mutex
);
6045 if (!priv
->vif
|| !priv
->is_open
) {
6046 mutex_unlock(&priv
->mutex
);
6049 iwl4965_scan_cancel_timeout(priv
, 200);
6051 conf
= ieee80211_get_hw_conf(priv
->hw
);
6053 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6054 iwl4965_commit_rxon(priv
);
6056 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
6057 iwl4965_setup_rxon_timing(priv
);
6058 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
6059 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
6061 IWL_WARNING("REPLY_RXON_TIMING failed - "
6062 "Attempting to continue.\n");
6064 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
6066 #ifdef CONFIG_IWL4965_HT
6067 if (priv
->current_ht_config
.is_ht
)
6068 iwl4965_set_rxon_ht(priv
, &priv
->current_ht_config
);
6069 #endif /* CONFIG_IWL4965_HT*/
6070 iwl4965_set_rxon_chain(priv
);
6071 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6073 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
6074 priv
->assoc_id
, priv
->beacon_int
);
6076 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6077 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
6079 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6081 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6082 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6083 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
6085 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6087 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6088 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
6092 iwl4965_commit_rxon(priv
);
6094 switch (priv
->iw_mode
) {
6095 case IEEE80211_IF_TYPE_STA
:
6096 iwl4965_rate_scale_init(priv
->hw
, IWL_AP_ID
);
6099 case IEEE80211_IF_TYPE_IBSS
:
6101 /* clear out the station table */
6102 iwlcore_clear_stations_table(priv
);
6104 iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0);
6105 iwl4965_rxon_add_station(priv
, priv
->bssid
, 0);
6106 iwl4965_rate_scale_init(priv
->hw
, IWL_STA_ID
);
6107 iwl4965_send_beacon_cmd(priv
);
6112 IWL_ERROR("%s Should not be called in %d mode\n",
6113 __FUNCTION__
, priv
->iw_mode
);
6117 iwl4965_sequence_reset(priv
);
6119 #ifdef CONFIG_IWL4965_SENSITIVITY
6120 /* Enable Rx differential gain and sensitivity calibrations */
6121 iwl4965_chain_noise_reset(priv
);
6122 priv
->start_calib
= 1;
6123 #endif /* CONFIG_IWL4965_SENSITIVITY */
6125 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6126 priv
->assoc_station_added
= 1;
6128 iwl4965_activate_qos(priv
, 0);
6130 /* we have just associated, don't start scan too early */
6131 priv
->next_scan_jiffies
= jiffies
+ IWL_DELAY_NEXT_SCAN
;
6132 mutex_unlock(&priv
->mutex
);
6135 static void iwl4965_bg_abort_scan(struct work_struct
*work
)
6137 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, abort_scan
);
6139 if (!iwl_is_ready(priv
))
6142 mutex_lock(&priv
->mutex
);
6144 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
6145 iwl4965_send_scan_abort(priv
);
6147 mutex_unlock(&priv
->mutex
);
6150 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
);
6152 static void iwl4965_bg_scan_completed(struct work_struct
*work
)
6154 struct iwl_priv
*priv
=
6155 container_of(work
, struct iwl_priv
, scan_completed
);
6157 IWL_DEBUG(IWL_DL_INFO
| IWL_DL_SCAN
, "SCAN complete scan\n");
6159 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6162 if (test_bit(STATUS_CONF_PENDING
, &priv
->status
))
6163 iwl4965_mac_config(priv
->hw
, ieee80211_get_hw_conf(priv
->hw
));
6165 ieee80211_scan_completed(priv
->hw
);
6167 /* Since setting the TXPOWER may have been deferred while
6168 * performing the scan, fire one off */
6169 mutex_lock(&priv
->mutex
);
6170 iwl4965_hw_reg_send_txpower(priv
);
6171 mutex_unlock(&priv
->mutex
);
6174 /*****************************************************************************
6176 * mac80211 entry point functions
6178 *****************************************************************************/
6180 #define UCODE_READY_TIMEOUT (2 * HZ)
6182 static int iwl4965_mac_start(struct ieee80211_hw
*hw
)
6184 struct iwl_priv
*priv
= hw
->priv
;
6187 IWL_DEBUG_MAC80211("enter\n");
6189 if (pci_enable_device(priv
->pci_dev
)) {
6190 IWL_ERROR("Fail to pci_enable_device\n");
6193 pci_restore_state(priv
->pci_dev
);
6194 pci_enable_msi(priv
->pci_dev
);
6196 ret
= request_irq(priv
->pci_dev
->irq
, iwl4965_isr
, IRQF_SHARED
,
6199 IWL_ERROR("Error allocating IRQ %d\n", priv
->pci_dev
->irq
);
6200 goto out_disable_msi
;
6203 /* we should be verifying the device is ready to be opened */
6204 mutex_lock(&priv
->mutex
);
6206 memset(&priv
->staging_rxon
, 0, sizeof(struct iwl4965_rxon_cmd
));
6207 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
6208 * ucode filename and max sizes are card-specific. */
6210 if (!priv
->ucode_code
.len
) {
6211 ret
= iwl4965_read_ucode(priv
);
6213 IWL_ERROR("Could not read microcode: %d\n", ret
);
6214 mutex_unlock(&priv
->mutex
);
6215 goto out_release_irq
;
6219 ret
= __iwl4965_up(priv
);
6221 mutex_unlock(&priv
->mutex
);
6224 goto out_release_irq
;
6226 IWL_DEBUG_INFO("Start UP work done.\n");
6228 if (test_bit(STATUS_IN_SUSPEND
, &priv
->status
))
6231 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
6232 * mac80211 will not be run successfully. */
6233 ret
= wait_event_interruptible_timeout(priv
->wait_command_queue
,
6234 test_bit(STATUS_READY
, &priv
->status
),
6235 UCODE_READY_TIMEOUT
);
6237 if (!test_bit(STATUS_READY
, &priv
->status
)) {
6238 IWL_ERROR("Wait for START_ALIVE timeout after %dms.\n",
6239 jiffies_to_msecs(UCODE_READY_TIMEOUT
));
6241 goto out_release_irq
;
6246 IWL_DEBUG_MAC80211("leave\n");
6250 free_irq(priv
->pci_dev
->irq
, priv
);
6252 pci_disable_msi(priv
->pci_dev
);
6253 pci_disable_device(priv
->pci_dev
);
6255 IWL_DEBUG_MAC80211("leave - failed\n");
6259 static void iwl4965_mac_stop(struct ieee80211_hw
*hw
)
6261 struct iwl_priv
*priv
= hw
->priv
;
6263 IWL_DEBUG_MAC80211("enter\n");
6265 if (!priv
->is_open
) {
6266 IWL_DEBUG_MAC80211("leave - skip\n");
6272 if (iwl_is_ready_rf(priv
)) {
6273 /* stop mac, cancel any scan request and clear
6274 * RXON_FILTER_ASSOC_MSK BIT
6276 mutex_lock(&priv
->mutex
);
6277 iwl4965_scan_cancel_timeout(priv
, 100);
6278 cancel_delayed_work(&priv
->post_associate
);
6279 mutex_unlock(&priv
->mutex
);
6284 flush_workqueue(priv
->workqueue
);
6285 free_irq(priv
->pci_dev
->irq
, priv
);
6286 pci_disable_msi(priv
->pci_dev
);
6287 pci_save_state(priv
->pci_dev
);
6288 pci_disable_device(priv
->pci_dev
);
6290 IWL_DEBUG_MAC80211("leave\n");
6293 static int iwl4965_mac_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
6294 struct ieee80211_tx_control
*ctl
)
6296 struct iwl_priv
*priv
= hw
->priv
;
6298 IWL_DEBUG_MAC80211("enter\n");
6300 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
) {
6301 IWL_DEBUG_MAC80211("leave - monitor\n");
6305 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb
->len
,
6306 ctl
->tx_rate
->bitrate
);
6308 if (iwl4965_tx_skb(priv
, skb
, ctl
))
6309 dev_kfree_skb_any(skb
);
6311 IWL_DEBUG_MAC80211("leave\n");
6315 static int iwl4965_mac_add_interface(struct ieee80211_hw
*hw
,
6316 struct ieee80211_if_init_conf
*conf
)
6318 struct iwl_priv
*priv
= hw
->priv
;
6319 unsigned long flags
;
6320 DECLARE_MAC_BUF(mac
);
6322 IWL_DEBUG_MAC80211("enter: type %d\n", conf
->type
);
6325 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
6329 spin_lock_irqsave(&priv
->lock
, flags
);
6330 priv
->vif
= conf
->vif
;
6332 spin_unlock_irqrestore(&priv
->lock
, flags
);
6334 mutex_lock(&priv
->mutex
);
6336 if (conf
->mac_addr
) {
6337 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac
, conf
->mac_addr
));
6338 memcpy(priv
->mac_addr
, conf
->mac_addr
, ETH_ALEN
);
6341 if (iwl_is_ready(priv
))
6342 iwl4965_set_mode(priv
, conf
->type
);
6344 mutex_unlock(&priv
->mutex
);
6346 IWL_DEBUG_MAC80211("leave\n");
6351 * iwl4965_mac_config - mac80211 config callback
6353 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
6354 * be set inappropriately and the driver currently sets the hardware up to
6355 * use it whenever needed.
6357 static int iwl4965_mac_config(struct ieee80211_hw
*hw
, struct ieee80211_conf
*conf
)
6359 struct iwl_priv
*priv
= hw
->priv
;
6360 const struct iwl_channel_info
*ch_info
;
6361 unsigned long flags
;
6364 mutex_lock(&priv
->mutex
);
6365 IWL_DEBUG_MAC80211("enter to channel %d\n", conf
->channel
->hw_value
);
6367 priv
->add_radiotap
= !!(conf
->flags
& IEEE80211_CONF_RADIOTAP
);
6369 if (!iwl_is_ready(priv
)) {
6370 IWL_DEBUG_MAC80211("leave - not ready\n");
6375 if (unlikely(!priv
->cfg
->mod_params
->disable_hw_scan
&&
6376 test_bit(STATUS_SCANNING
, &priv
->status
))) {
6377 IWL_DEBUG_MAC80211("leave - scanning\n");
6378 set_bit(STATUS_CONF_PENDING
, &priv
->status
);
6379 mutex_unlock(&priv
->mutex
);
6383 spin_lock_irqsave(&priv
->lock
, flags
);
6385 ch_info
= iwl_get_channel_info(priv
, conf
->channel
->band
,
6386 ieee80211_frequency_to_channel(conf
->channel
->center_freq
));
6387 if (!is_channel_valid(ch_info
)) {
6388 IWL_DEBUG_MAC80211("leave - invalid channel\n");
6389 spin_unlock_irqrestore(&priv
->lock
, flags
);
6394 #ifdef CONFIG_IWL4965_HT
6395 /* if we are switching from ht to 2.4 clear flags
6396 * from any ht related info since 2.4 does not
6398 if ((le16_to_cpu(priv
->staging_rxon
.channel
) != conf
->channel
->hw_value
)
6399 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6400 && !(conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
)
6403 priv
->staging_rxon
.flags
= 0;
6404 #endif /* CONFIG_IWL4965_HT */
6406 iwlcore_set_rxon_channel(priv
, conf
->channel
->band
,
6407 ieee80211_frequency_to_channel(conf
->channel
->center_freq
));
6409 iwl4965_set_flags_for_phymode(priv
, conf
->channel
->band
);
6411 /* The list of supported rates and rate mask can be different
6412 * for each band; since the band may have changed, reset
6413 * the rate mask to what mac80211 lists */
6414 iwl4965_set_rate(priv
);
6416 spin_unlock_irqrestore(&priv
->lock
, flags
);
6418 #ifdef IEEE80211_CONF_CHANNEL_SWITCH
6419 if (conf
->flags
& IEEE80211_CONF_CHANNEL_SWITCH
) {
6420 iwl4965_hw_channel_switch(priv
, conf
->channel
);
6425 if (priv
->cfg
->ops
->lib
->radio_kill_sw
)
6426 priv
->cfg
->ops
->lib
->radio_kill_sw(priv
, !conf
->radio_enabled
);
6428 if (!conf
->radio_enabled
) {
6429 IWL_DEBUG_MAC80211("leave - radio disabled\n");
6433 if (iwl_is_rfkill(priv
)) {
6434 IWL_DEBUG_MAC80211("leave - RF kill\n");
6439 iwl4965_set_rate(priv
);
6441 if (memcmp(&priv
->active_rxon
,
6442 &priv
->staging_rxon
, sizeof(priv
->staging_rxon
)))
6443 iwl4965_commit_rxon(priv
);
6445 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
6447 IWL_DEBUG_MAC80211("leave\n");
6450 clear_bit(STATUS_CONF_PENDING
, &priv
->status
);
6451 mutex_unlock(&priv
->mutex
);
6455 static void iwl4965_config_ap(struct iwl_priv
*priv
)
6459 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
6462 /* The following should be done only at AP bring up */
6463 if ((priv
->active_rxon
.filter_flags
& RXON_FILTER_ASSOC_MSK
) == 0) {
6465 /* RXON - unassoc (to set timing command) */
6466 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6467 iwl4965_commit_rxon(priv
);
6470 memset(&priv
->rxon_timing
, 0, sizeof(struct iwl4965_rxon_time_cmd
));
6471 iwl4965_setup_rxon_timing(priv
);
6472 ret
= iwl_send_cmd_pdu(priv
, REPLY_RXON_TIMING
,
6473 sizeof(priv
->rxon_timing
), &priv
->rxon_timing
);
6475 IWL_WARNING("REPLY_RXON_TIMING failed - "
6476 "Attempting to continue.\n");
6478 iwl4965_set_rxon_chain(priv
);
6480 /* FIXME: what should be the assoc_id for AP? */
6481 priv
->staging_rxon
.assoc_id
= cpu_to_le16(priv
->assoc_id
);
6482 if (priv
->assoc_capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
)
6483 priv
->staging_rxon
.flags
|=
6484 RXON_FLG_SHORT_PREAMBLE_MSK
;
6486 priv
->staging_rxon
.flags
&=
6487 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6489 if (priv
->staging_rxon
.flags
& RXON_FLG_BAND_24G_MSK
) {
6490 if (priv
->assoc_capability
&
6491 WLAN_CAPABILITY_SHORT_SLOT_TIME
)
6492 priv
->staging_rxon
.flags
|=
6493 RXON_FLG_SHORT_SLOT_MSK
;
6495 priv
->staging_rxon
.flags
&=
6496 ~RXON_FLG_SHORT_SLOT_MSK
;
6498 if (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
)
6499 priv
->staging_rxon
.flags
&=
6500 ~RXON_FLG_SHORT_SLOT_MSK
;
6502 /* restore RXON assoc */
6503 priv
->staging_rxon
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
6504 iwl4965_commit_rxon(priv
);
6505 iwl4965_activate_qos(priv
, 1);
6506 iwl4965_rxon_add_station(priv
, iwl4965_broadcast_addr
, 0);
6508 iwl4965_send_beacon_cmd(priv
);
6510 /* FIXME - we need to add code here to detect a totally new
6511 * configuration, reset the AP, unassoc, rxon timing, assoc,
6512 * clear sta table, add BCAST sta... */
6515 static int iwl4965_mac_config_interface(struct ieee80211_hw
*hw
,
6516 struct ieee80211_vif
*vif
,
6517 struct ieee80211_if_conf
*conf
)
6519 struct iwl_priv
*priv
= hw
->priv
;
6520 DECLARE_MAC_BUF(mac
);
6521 unsigned long flags
;
6527 if (priv
->vif
!= vif
) {
6528 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
6529 mutex_unlock(&priv
->mutex
);
6533 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) &&
6534 (!conf
->beacon
|| !conf
->ssid_len
)) {
6536 ("Leaving in AP mode because HostAPD is not ready.\n");
6540 if (!iwl_is_alive(priv
))
6543 mutex_lock(&priv
->mutex
);
6546 IWL_DEBUG_MAC80211("bssid: %s\n",
6547 print_mac(mac
, conf
->bssid
));
6550 * very dubious code was here; the probe filtering flag is never set:
6552 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
6553 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
6556 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
6558 conf
->bssid
= priv
->mac_addr
;
6559 memcpy(priv
->bssid
, priv
->mac_addr
, ETH_ALEN
);
6560 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
6561 print_mac(mac
, conf
->bssid
));
6563 if (priv
->ibss_beacon
)
6564 dev_kfree_skb(priv
->ibss_beacon
);
6566 priv
->ibss_beacon
= conf
->beacon
;
6569 if (iwl_is_rfkill(priv
))
6572 if (conf
->bssid
&& !is_zero_ether_addr(conf
->bssid
) &&
6573 !is_multicast_ether_addr(conf
->bssid
)) {
6574 /* If there is currently a HW scan going on in the background
6575 * then we need to cancel it else the RXON below will fail. */
6576 if (iwl4965_scan_cancel_timeout(priv
, 100)) {
6577 IWL_WARNING("Aborted scan still in progress "
6579 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
6580 mutex_unlock(&priv
->mutex
);
6583 memcpy(priv
->staging_rxon
.bssid_addr
, conf
->bssid
, ETH_ALEN
);
6585 /* TODO: Audit driver for usage of these members and see
6586 * if mac80211 deprecates them (priv->bssid looks like it
6587 * shouldn't be there, but I haven't scanned the IBSS code
6588 * to verify) - jpk */
6589 memcpy(priv
->bssid
, conf
->bssid
, ETH_ALEN
);
6591 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
6592 iwl4965_config_ap(priv
);
6594 rc
= iwl4965_commit_rxon(priv
);
6595 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) && rc
)
6596 iwl4965_rxon_add_station(
6597 priv
, priv
->active_rxon
.bssid_addr
, 1);
6601 iwl4965_scan_cancel_timeout(priv
, 100);
6602 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6603 iwl4965_commit_rxon(priv
);
6607 spin_lock_irqsave(&priv
->lock
, flags
);
6608 if (!conf
->ssid_len
)
6609 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
6611 memcpy(priv
->essid
, conf
->ssid
, conf
->ssid_len
);
6613 priv
->essid_len
= conf
->ssid_len
;
6614 spin_unlock_irqrestore(&priv
->lock
, flags
);
6616 IWL_DEBUG_MAC80211("leave\n");
6617 mutex_unlock(&priv
->mutex
);
6622 static void iwl4965_configure_filter(struct ieee80211_hw
*hw
,
6623 unsigned int changed_flags
,
6624 unsigned int *total_flags
,
6625 int mc_count
, struct dev_addr_list
*mc_list
)
6629 * see also iwl4965_connection_init_rx_config
6634 static void iwl4965_mac_remove_interface(struct ieee80211_hw
*hw
,
6635 struct ieee80211_if_init_conf
*conf
)
6637 struct iwl_priv
*priv
= hw
->priv
;
6639 IWL_DEBUG_MAC80211("enter\n");
6641 mutex_lock(&priv
->mutex
);
6643 if (iwl_is_ready_rf(priv
)) {
6644 iwl4965_scan_cancel_timeout(priv
, 100);
6645 cancel_delayed_work(&priv
->post_associate
);
6646 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
6647 iwl4965_commit_rxon(priv
);
6649 if (priv
->vif
== conf
->vif
) {
6651 memset(priv
->bssid
, 0, ETH_ALEN
);
6652 memset(priv
->essid
, 0, IW_ESSID_MAX_SIZE
);
6653 priv
->essid_len
= 0;
6655 mutex_unlock(&priv
->mutex
);
6657 IWL_DEBUG_MAC80211("leave\n");
6662 #ifdef CONFIG_IWL4965_HT
6663 static void iwl4965_ht_conf(struct iwl_priv
*priv
,
6664 struct ieee80211_bss_conf
*bss_conf
)
6666 struct ieee80211_ht_info
*ht_conf
= bss_conf
->ht_conf
;
6667 struct ieee80211_ht_bss_info
*ht_bss_conf
= bss_conf
->ht_bss_conf
;
6668 struct iwl_ht_info
*iwl_conf
= &priv
->current_ht_config
;
6670 IWL_DEBUG_MAC80211("enter: \n");
6672 iwl_conf
->is_ht
= bss_conf
->assoc_ht
;
6674 if (!iwl_conf
->is_ht
)
6677 priv
->ps_mode
= (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
6679 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_20
)
6680 iwl_conf
->sgf
|= 0x1;
6681 if (ht_conf
->cap
& IEEE80211_HT_CAP_SGI_40
)
6682 iwl_conf
->sgf
|= 0x2;
6684 iwl_conf
->is_green_field
= !!(ht_conf
->cap
& IEEE80211_HT_CAP_GRN_FLD
);
6685 iwl_conf
->max_amsdu_size
=
6686 !!(ht_conf
->cap
& IEEE80211_HT_CAP_MAX_AMSDU
);
6688 iwl_conf
->supported_chan_width
=
6689 !!(ht_conf
->cap
& IEEE80211_HT_CAP_SUP_WIDTH
);
6690 iwl_conf
->extension_chan_offset
=
6691 ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_SEC_OFFSET
;
6692 /* If no above or below channel supplied disable FAT channel */
6693 if (iwl_conf
->extension_chan_offset
!= IWL_EXT_CHANNEL_OFFSET_ABOVE
&&
6694 iwl_conf
->extension_chan_offset
!= IWL_EXT_CHANNEL_OFFSET_BELOW
)
6695 iwl_conf
->supported_chan_width
= 0;
6697 iwl_conf
->tx_mimo_ps_mode
=
6698 (u8
)((ht_conf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2);
6699 memcpy(iwl_conf
->supp_mcs_set
, ht_conf
->supp_mcs_set
, 16);
6701 iwl_conf
->control_channel
= ht_bss_conf
->primary_channel
;
6702 iwl_conf
->tx_chan_width
=
6703 !!(ht_bss_conf
->bss_cap
& IEEE80211_HT_IE_CHA_WIDTH
);
6704 iwl_conf
->ht_protection
=
6705 ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_HT_PROTECTION
;
6706 iwl_conf
->non_GF_STA_present
=
6707 !!(ht_bss_conf
->bss_op_mode
& IEEE80211_HT_IE_NON_GF_STA_PRSNT
);
6709 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf
->control_channel
);
6710 IWL_DEBUG_MAC80211("leave\n");
6713 static inline void iwl4965_ht_conf(struct iwl_priv
*priv
,
6714 struct ieee80211_bss_conf
*bss_conf
)
6719 #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
6720 static void iwl4965_bss_info_changed(struct ieee80211_hw
*hw
,
6721 struct ieee80211_vif
*vif
,
6722 struct ieee80211_bss_conf
*bss_conf
,
6725 struct iwl_priv
*priv
= hw
->priv
;
6727 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes
);
6729 if (changes
& BSS_CHANGED_ERP_PREAMBLE
) {
6730 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
6731 bss_conf
->use_short_preamble
);
6732 if (bss_conf
->use_short_preamble
)
6733 priv
->staging_rxon
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
6735 priv
->staging_rxon
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
6738 if (changes
& BSS_CHANGED_ERP_CTS_PROT
) {
6739 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf
->use_cts_prot
);
6740 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
6741 priv
->staging_rxon
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
6743 priv
->staging_rxon
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
6746 if (changes
& BSS_CHANGED_HT
) {
6747 IWL_DEBUG_MAC80211("HT %d\n", bss_conf
->assoc_ht
);
6748 iwl4965_ht_conf(priv
, bss_conf
);
6749 iwl4965_set_rxon_chain(priv
);
6752 if (changes
& BSS_CHANGED_ASSOC
) {
6753 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf
->assoc
);
6754 if (bss_conf
->assoc
) {
6755 priv
->assoc_id
= bss_conf
->aid
;
6756 priv
->beacon_int
= bss_conf
->beacon_int
;
6757 priv
->timestamp
= bss_conf
->timestamp
;
6758 priv
->assoc_capability
= bss_conf
->assoc_capability
;
6759 priv
->next_scan_jiffies
= jiffies
+
6760 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC
;
6761 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
6764 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf
->assoc
);
6766 } else if (changes
&& iwl_is_associated(priv
) && priv
->assoc_id
) {
6767 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes
);
6768 iwl4965_send_rxon_assoc(priv
);
6773 static int iwl4965_mac_hw_scan(struct ieee80211_hw
*hw
, u8
*ssid
, size_t len
)
6776 unsigned long flags
;
6777 struct iwl_priv
*priv
= hw
->priv
;
6779 IWL_DEBUG_MAC80211("enter\n");
6781 mutex_lock(&priv
->mutex
);
6782 spin_lock_irqsave(&priv
->lock
, flags
);
6784 if (!iwl_is_ready_rf(priv
)) {
6786 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
6790 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) { /* APs don't scan */
6792 IWL_ERROR("ERROR: APs don't scan\n");
6796 /* we don't schedule scan within next_scan_jiffies period */
6797 if (priv
->next_scan_jiffies
&&
6798 time_after(priv
->next_scan_jiffies
, jiffies
)) {
6802 /* if we just finished scan ask for delay */
6803 if (priv
->last_scan_jiffies
&& time_after(priv
->last_scan_jiffies
+
6804 IWL_DELAY_NEXT_SCAN
, jiffies
)) {
6809 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
6810 iwl4965_escape_essid(ssid
, len
), (int)len
);
6812 priv
->one_direct_scan
= 1;
6813 priv
->direct_ssid_len
= (u8
)
6814 min((u8
) len
, (u8
) IW_ESSID_MAX_SIZE
);
6815 memcpy(priv
->direct_ssid
, ssid
, priv
->direct_ssid_len
);
6817 priv
->one_direct_scan
= 0;
6819 rc
= iwl4965_scan_initiate(priv
);
6821 IWL_DEBUG_MAC80211("leave\n");
6824 spin_unlock_irqrestore(&priv
->lock
, flags
);
6825 mutex_unlock(&priv
->mutex
);
6830 static void iwl4965_mac_update_tkip_key(struct ieee80211_hw
*hw
,
6831 struct ieee80211_key_conf
*keyconf
, const u8
*addr
,
6832 u32 iv32
, u16
*phase1key
)
6834 struct iwl_priv
*priv
= hw
->priv
;
6835 u8 sta_id
= IWL_INVALID_STATION
;
6836 unsigned long flags
;
6837 __le16 key_flags
= 0;
6839 DECLARE_MAC_BUF(mac
);
6841 IWL_DEBUG_MAC80211("enter\n");
6843 sta_id
= iwl4965_hw_find_station(priv
, addr
);
6844 if (sta_id
== IWL_INVALID_STATION
) {
6845 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
6846 print_mac(mac
, addr
));
6850 iwl4965_scan_cancel_timeout(priv
, 100);
6852 key_flags
|= (STA_KEY_FLG_TKIP
| STA_KEY_FLG_MAP_KEY_MSK
);
6853 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
6854 key_flags
&= ~STA_KEY_FLG_INVALID
;
6856 if (sta_id
== priv
->hw_setting
.bcast_sta_id
)
6857 key_flags
|= STA_KEY_MULTICAST_MSK
;
6859 spin_lock_irqsave(&priv
->sta_lock
, flags
);
6861 priv
->stations
[sta_id
].sta
.key
.key_offset
=
6862 iwl_get_free_ucode_key_index(priv
);
6863 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
6864 priv
->stations
[sta_id
].sta
.key
.tkip_rx_tsc_byte2
= (u8
) iv32
;
6866 for (i
= 0; i
< 5; i
++)
6867 priv
->stations
[sta_id
].sta
.key
.tkip_rx_ttak
[i
] =
6868 cpu_to_le16(phase1key
[i
]);
6870 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
6871 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
6873 iwl4965_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
6875 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
6877 IWL_DEBUG_MAC80211("leave\n");
6880 static int iwl4965_mac_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
6881 const u8
*local_addr
, const u8
*addr
,
6882 struct ieee80211_key_conf
*key
)
6884 struct iwl_priv
*priv
= hw
->priv
;
6885 DECLARE_MAC_BUF(mac
);
6887 u8 sta_id
= IWL_INVALID_STATION
;
6888 u8 is_default_wep_key
= 0;
6890 IWL_DEBUG_MAC80211("enter\n");
6892 if (!priv
->cfg
->mod_params
->hw_crypto
) {
6893 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
6897 if (is_zero_ether_addr(addr
))
6898 /* only support pairwise keys */
6901 sta_id
= iwl4965_hw_find_station(priv
, addr
);
6902 if (sta_id
== IWL_INVALID_STATION
) {
6903 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
6904 print_mac(mac
, addr
));
6909 mutex_lock(&priv
->mutex
);
6910 iwl4965_scan_cancel_timeout(priv
, 100);
6911 mutex_unlock(&priv
->mutex
);
6913 /* If we are getting WEP group key and we didn't receive any key mapping
6914 * so far, we are in legacy wep mode (group key only), otherwise we are
6916 * In legacy wep mode, we use another host command to the uCode */
6917 if (key
->alg
== ALG_WEP
&& sta_id
== priv
->hw_setting
.bcast_sta_id
&&
6918 priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
6920 is_default_wep_key
= !priv
->key_mapping_key
;
6922 is_default_wep_key
= priv
->default_wep_key
;
6927 if (is_default_wep_key
)
6928 ret
= iwl_set_default_wep_key(priv
, key
);
6930 ret
= iwl_set_dynamic_key(priv
, key
, sta_id
);
6932 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
6935 if (is_default_wep_key
)
6936 ret
= iwl_remove_default_wep_key(priv
, key
);
6938 ret
= iwl_remove_dynamic_key(priv
, sta_id
);
6940 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
6946 IWL_DEBUG_MAC80211("leave\n");
6951 static int iwl4965_mac_conf_tx(struct ieee80211_hw
*hw
, int queue
,
6952 const struct ieee80211_tx_queue_params
*params
)
6954 struct iwl_priv
*priv
= hw
->priv
;
6955 unsigned long flags
;
6958 IWL_DEBUG_MAC80211("enter\n");
6960 if (!iwl_is_ready_rf(priv
)) {
6961 IWL_DEBUG_MAC80211("leave - RF not ready\n");
6965 if (queue
>= AC_NUM
) {
6966 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue
);
6970 if (!priv
->qos_data
.qos_enable
) {
6971 priv
->qos_data
.qos_active
= 0;
6972 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
6975 q
= AC_NUM
- 1 - queue
;
6977 spin_lock_irqsave(&priv
->lock
, flags
);
6979 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_min
= cpu_to_le16(params
->cw_min
);
6980 priv
->qos_data
.def_qos_parm
.ac
[q
].cw_max
= cpu_to_le16(params
->cw_max
);
6981 priv
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
6982 priv
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
6983 cpu_to_le16((params
->txop
* 32));
6985 priv
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
6986 priv
->qos_data
.qos_active
= 1;
6988 spin_unlock_irqrestore(&priv
->lock
, flags
);
6990 mutex_lock(&priv
->mutex
);
6991 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
6992 iwl4965_activate_qos(priv
, 1);
6993 else if (priv
->assoc_id
&& iwl_is_associated(priv
))
6994 iwl4965_activate_qos(priv
, 0);
6996 mutex_unlock(&priv
->mutex
);
6998 IWL_DEBUG_MAC80211("leave\n");
7002 static int iwl4965_mac_get_tx_stats(struct ieee80211_hw
*hw
,
7003 struct ieee80211_tx_queue_stats
*stats
)
7005 struct iwl_priv
*priv
= hw
->priv
;
7007 struct iwl4965_tx_queue
*txq
;
7008 struct iwl4965_queue
*q
;
7009 unsigned long flags
;
7011 IWL_DEBUG_MAC80211("enter\n");
7013 if (!iwl_is_ready_rf(priv
)) {
7014 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7018 spin_lock_irqsave(&priv
->lock
, flags
);
7020 for (i
= 0; i
< AC_NUM
; i
++) {
7021 txq
= &priv
->txq
[i
];
7023 avail
= iwl4965_queue_space(q
);
7025 stats
->data
[i
].len
= q
->n_window
- avail
;
7026 stats
->data
[i
].limit
= q
->n_window
- q
->high_mark
;
7027 stats
->data
[i
].count
= q
->n_window
;
7030 spin_unlock_irqrestore(&priv
->lock
, flags
);
7032 IWL_DEBUG_MAC80211("leave\n");
7037 static int iwl4965_mac_get_stats(struct ieee80211_hw
*hw
,
7038 struct ieee80211_low_level_stats
*stats
)
7040 IWL_DEBUG_MAC80211("enter\n");
7041 IWL_DEBUG_MAC80211("leave\n");
7046 static u64
iwl4965_mac_get_tsf(struct ieee80211_hw
*hw
)
7048 IWL_DEBUG_MAC80211("enter\n");
7049 IWL_DEBUG_MAC80211("leave\n");
7054 static void iwl4965_mac_reset_tsf(struct ieee80211_hw
*hw
)
7056 struct iwl_priv
*priv
= hw
->priv
;
7057 unsigned long flags
;
7059 mutex_lock(&priv
->mutex
);
7060 IWL_DEBUG_MAC80211("enter\n");
7062 priv
->lq_mngr
.lq_ready
= 0;
7063 #ifdef CONFIG_IWL4965_HT
7064 spin_lock_irqsave(&priv
->lock
, flags
);
7065 memset(&priv
->current_ht_config
, 0, sizeof(struct iwl_ht_info
));
7066 spin_unlock_irqrestore(&priv
->lock
, flags
);
7067 #endif /* CONFIG_IWL4965_HT */
7069 iwlcore_reset_qos(priv
);
7071 cancel_delayed_work(&priv
->post_associate
);
7073 spin_lock_irqsave(&priv
->lock
, flags
);
7075 priv
->assoc_capability
= 0;
7076 priv
->assoc_station_added
= 0;
7078 /* new association get rid of ibss beacon skb */
7079 if (priv
->ibss_beacon
)
7080 dev_kfree_skb(priv
->ibss_beacon
);
7082 priv
->ibss_beacon
= NULL
;
7084 priv
->beacon_int
= priv
->hw
->conf
.beacon_int
;
7085 priv
->timestamp
= 0;
7086 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
7087 priv
->beacon_int
= 0;
7089 spin_unlock_irqrestore(&priv
->lock
, flags
);
7091 if (!iwl_is_ready_rf(priv
)) {
7092 IWL_DEBUG_MAC80211("leave - not ready\n");
7093 mutex_unlock(&priv
->mutex
);
7097 /* we are restarting association process
7098 * clear RXON_FILTER_ASSOC_MSK bit
7100 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_AP
) {
7101 iwl4965_scan_cancel_timeout(priv
, 100);
7102 priv
->staging_rxon
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
7103 iwl4965_commit_rxon(priv
);
7106 /* Per mac80211.h: This is only used in IBSS mode... */
7107 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
7109 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
7110 mutex_unlock(&priv
->mutex
);
7114 priv
->only_active_channel
= 0;
7116 iwl4965_set_rate(priv
);
7118 mutex_unlock(&priv
->mutex
);
7120 IWL_DEBUG_MAC80211("leave\n");
7123 static int iwl4965_mac_beacon_update(struct ieee80211_hw
*hw
, struct sk_buff
*skb
,
7124 struct ieee80211_tx_control
*control
)
7126 struct iwl_priv
*priv
= hw
->priv
;
7127 unsigned long flags
;
7129 mutex_lock(&priv
->mutex
);
7130 IWL_DEBUG_MAC80211("enter\n");
7132 if (!iwl_is_ready_rf(priv
)) {
7133 IWL_DEBUG_MAC80211("leave - RF not ready\n");
7134 mutex_unlock(&priv
->mutex
);
7138 if (priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
) {
7139 IWL_DEBUG_MAC80211("leave - not IBSS\n");
7140 mutex_unlock(&priv
->mutex
);
7144 spin_lock_irqsave(&priv
->lock
, flags
);
7146 if (priv
->ibss_beacon
)
7147 dev_kfree_skb(priv
->ibss_beacon
);
7149 priv
->ibss_beacon
= skb
;
7153 IWL_DEBUG_MAC80211("leave\n");
7154 spin_unlock_irqrestore(&priv
->lock
, flags
);
7156 iwlcore_reset_qos(priv
);
7158 queue_work(priv
->workqueue
, &priv
->post_associate
.work
);
7160 mutex_unlock(&priv
->mutex
);
7165 /*****************************************************************************
7169 *****************************************************************************/
7171 #ifdef CONFIG_IWLWIFI_DEBUG
7174 * The following adds a new attribute to the sysfs representation
7175 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
7176 * used for controlling the debug level.
7178 * See the level definitions in iwl for details.
7181 static ssize_t
show_debug_level(struct device_driver
*d
, char *buf
)
7183 return sprintf(buf
, "0x%08X\n", iwl_debug_level
);
7185 static ssize_t
store_debug_level(struct device_driver
*d
,
7186 const char *buf
, size_t count
)
7188 char *p
= (char *)buf
;
7191 val
= simple_strtoul(p
, &p
, 0);
7193 printk(KERN_INFO DRV_NAME
7194 ": %s is not in hex or decimal form.\n", buf
);
7196 iwl_debug_level
= val
;
7198 return strnlen(buf
, count
);
7201 static DRIVER_ATTR(debug_level
, S_IWUSR
| S_IRUGO
,
7202 show_debug_level
, store_debug_level
);
7204 #endif /* CONFIG_IWLWIFI_DEBUG */
7207 static ssize_t
show_temperature(struct device
*d
,
7208 struct device_attribute
*attr
, char *buf
)
7210 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7212 if (!iwl_is_alive(priv
))
7215 return sprintf(buf
, "%d\n", iwl4965_hw_get_temperature(priv
));
7218 static DEVICE_ATTR(temperature
, S_IRUGO
, show_temperature
, NULL
);
7220 static ssize_t
show_rs_window(struct device
*d
,
7221 struct device_attribute
*attr
,
7224 struct iwl_priv
*priv
= d
->driver_data
;
7225 return iwl4965_fill_rs_info(priv
->hw
, buf
, IWL_AP_ID
);
7227 static DEVICE_ATTR(rs_window
, S_IRUGO
, show_rs_window
, NULL
);
7229 static ssize_t
show_tx_power(struct device
*d
,
7230 struct device_attribute
*attr
, char *buf
)
7232 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7233 return sprintf(buf
, "%d\n", priv
->user_txpower_limit
);
7236 static ssize_t
store_tx_power(struct device
*d
,
7237 struct device_attribute
*attr
,
7238 const char *buf
, size_t count
)
7240 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7241 char *p
= (char *)buf
;
7244 val
= simple_strtoul(p
, &p
, 10);
7246 printk(KERN_INFO DRV_NAME
7247 ": %s is not in decimal form.\n", buf
);
7249 iwl4965_hw_reg_set_txpower(priv
, val
);
7254 static DEVICE_ATTR(tx_power
, S_IWUSR
| S_IRUGO
, show_tx_power
, store_tx_power
);
7256 static ssize_t
show_flags(struct device
*d
,
7257 struct device_attribute
*attr
, char *buf
)
7259 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7261 return sprintf(buf
, "0x%04X\n", priv
->active_rxon
.flags
);
7264 static ssize_t
store_flags(struct device
*d
,
7265 struct device_attribute
*attr
,
7266 const char *buf
, size_t count
)
7268 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7269 u32 flags
= simple_strtoul(buf
, NULL
, 0);
7271 mutex_lock(&priv
->mutex
);
7272 if (le32_to_cpu(priv
->staging_rxon
.flags
) != flags
) {
7273 /* Cancel any currently running scans... */
7274 if (iwl4965_scan_cancel_timeout(priv
, 100))
7275 IWL_WARNING("Could not cancel scan.\n");
7277 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
7279 priv
->staging_rxon
.flags
= cpu_to_le32(flags
);
7280 iwl4965_commit_rxon(priv
);
7283 mutex_unlock(&priv
->mutex
);
7288 static DEVICE_ATTR(flags
, S_IWUSR
| S_IRUGO
, show_flags
, store_flags
);
7290 static ssize_t
show_filter_flags(struct device
*d
,
7291 struct device_attribute
*attr
, char *buf
)
7293 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7295 return sprintf(buf
, "0x%04X\n",
7296 le32_to_cpu(priv
->active_rxon
.filter_flags
));
7299 static ssize_t
store_filter_flags(struct device
*d
,
7300 struct device_attribute
*attr
,
7301 const char *buf
, size_t count
)
7303 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7304 u32 filter_flags
= simple_strtoul(buf
, NULL
, 0);
7306 mutex_lock(&priv
->mutex
);
7307 if (le32_to_cpu(priv
->staging_rxon
.filter_flags
) != filter_flags
) {
7308 /* Cancel any currently running scans... */
7309 if (iwl4965_scan_cancel_timeout(priv
, 100))
7310 IWL_WARNING("Could not cancel scan.\n");
7312 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
7313 "0x%04X\n", filter_flags
);
7314 priv
->staging_rxon
.filter_flags
=
7315 cpu_to_le32(filter_flags
);
7316 iwl4965_commit_rxon(priv
);
7319 mutex_unlock(&priv
->mutex
);
7324 static DEVICE_ATTR(filter_flags
, S_IWUSR
| S_IRUGO
, show_filter_flags
,
7325 store_filter_flags
);
7327 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
7329 static ssize_t
show_measurement(struct device
*d
,
7330 struct device_attribute
*attr
, char *buf
)
7332 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7333 struct iwl4965_spectrum_notification measure_report
;
7334 u32 size
= sizeof(measure_report
), len
= 0, ofs
= 0;
7335 u8
*data
= (u8
*) & measure_report
;
7336 unsigned long flags
;
7338 spin_lock_irqsave(&priv
->lock
, flags
);
7339 if (!(priv
->measurement_status
& MEASUREMENT_READY
)) {
7340 spin_unlock_irqrestore(&priv
->lock
, flags
);
7343 memcpy(&measure_report
, &priv
->measure_report
, size
);
7344 priv
->measurement_status
= 0;
7345 spin_unlock_irqrestore(&priv
->lock
, flags
);
7347 while (size
&& (PAGE_SIZE
- len
)) {
7348 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7349 PAGE_SIZE
- len
, 1);
7351 if (PAGE_SIZE
- len
)
7355 size
-= min(size
, 16U);
7361 static ssize_t
store_measurement(struct device
*d
,
7362 struct device_attribute
*attr
,
7363 const char *buf
, size_t count
)
7365 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7366 struct ieee80211_measurement_params params
= {
7367 .channel
= le16_to_cpu(priv
->active_rxon
.channel
),
7368 .start_time
= cpu_to_le64(priv
->last_tsf
),
7369 .duration
= cpu_to_le16(1),
7371 u8 type
= IWL_MEASURE_BASIC
;
7377 strncpy(buffer
, buf
, min(sizeof(buffer
), count
));
7378 channel
= simple_strtoul(p
, NULL
, 0);
7380 params
.channel
= channel
;
7383 while (*p
&& *p
!= ' ')
7386 type
= simple_strtoul(p
+ 1, NULL
, 0);
7389 IWL_DEBUG_INFO("Invoking measurement of type %d on "
7390 "channel %d (for '%s')\n", type
, params
.channel
, buf
);
7391 iwl4965_get_measurement(priv
, ¶ms
, type
);
7396 static DEVICE_ATTR(measurement
, S_IRUSR
| S_IWUSR
,
7397 show_measurement
, store_measurement
);
7398 #endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
7400 static ssize_t
store_retry_rate(struct device
*d
,
7401 struct device_attribute
*attr
,
7402 const char *buf
, size_t count
)
7404 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7406 priv
->retry_rate
= simple_strtoul(buf
, NULL
, 0);
7407 if (priv
->retry_rate
<= 0)
7408 priv
->retry_rate
= 1;
7413 static ssize_t
show_retry_rate(struct device
*d
,
7414 struct device_attribute
*attr
, char *buf
)
7416 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7417 return sprintf(buf
, "%d", priv
->retry_rate
);
7420 static DEVICE_ATTR(retry_rate
, S_IWUSR
| S_IRUSR
, show_retry_rate
,
7423 static ssize_t
store_power_level(struct device
*d
,
7424 struct device_attribute
*attr
,
7425 const char *buf
, size_t count
)
7427 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7431 mode
= simple_strtoul(buf
, NULL
, 0);
7432 mutex_lock(&priv
->mutex
);
7434 if (!iwl_is_ready(priv
)) {
7439 if ((mode
< 1) || (mode
> IWL_POWER_LIMIT
) || (mode
== IWL_POWER_AC
))
7440 mode
= IWL_POWER_AC
;
7442 mode
|= IWL_POWER_ENABLED
;
7444 if (mode
!= priv
->power_mode
) {
7445 rc
= iwl4965_send_power_mode(priv
, IWL_POWER_LEVEL(mode
));
7447 IWL_DEBUG_MAC80211("failed setting power mode.\n");
7450 priv
->power_mode
= mode
;
7456 mutex_unlock(&priv
->mutex
);
7460 #define MAX_WX_STRING 80
7462 /* Values are in microsecond */
7463 static const s32 timeout_duration
[] = {
7470 static const s32 period_duration
[] = {
7478 static ssize_t
show_power_level(struct device
*d
,
7479 struct device_attribute
*attr
, char *buf
)
7481 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7482 int level
= IWL_POWER_LEVEL(priv
->power_mode
);
7485 p
+= sprintf(p
, "%d ", level
);
7487 case IWL_POWER_MODE_CAM
:
7489 p
+= sprintf(p
, "(AC)");
7491 case IWL_POWER_BATTERY
:
7492 p
+= sprintf(p
, "(BATTERY)");
7496 "(Timeout %dms, Period %dms)",
7497 timeout_duration
[level
- 1] / 1000,
7498 period_duration
[level
- 1] / 1000);
7501 if (!(priv
->power_mode
& IWL_POWER_ENABLED
))
7502 p
+= sprintf(p
, " OFF\n");
7504 p
+= sprintf(p
, " \n");
7506 return (p
- buf
+ 1);
7510 static DEVICE_ATTR(power_level
, S_IWUSR
| S_IRUSR
, show_power_level
,
7513 static ssize_t
show_channels(struct device
*d
,
7514 struct device_attribute
*attr
, char *buf
)
7516 /* all this shit doesn't belong into sysfs anyway */
7520 static DEVICE_ATTR(channels
, S_IRUSR
, show_channels
, NULL
);
7522 static ssize_t
show_statistics(struct device
*d
,
7523 struct device_attribute
*attr
, char *buf
)
7525 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7526 u32 size
= sizeof(struct iwl4965_notif_statistics
);
7527 u32 len
= 0, ofs
= 0;
7528 u8
*data
= (u8
*) & priv
->statistics
;
7531 if (!iwl_is_alive(priv
))
7534 mutex_lock(&priv
->mutex
);
7535 rc
= iwl4965_send_statistics_request(priv
);
7536 mutex_unlock(&priv
->mutex
);
7540 "Error sending statistics request: 0x%08X\n", rc
);
7544 while (size
&& (PAGE_SIZE
- len
)) {
7545 hex_dump_to_buffer(data
+ ofs
, size
, 16, 1, buf
+ len
,
7546 PAGE_SIZE
- len
, 1);
7548 if (PAGE_SIZE
- len
)
7552 size
-= min(size
, 16U);
7558 static DEVICE_ATTR(statistics
, S_IRUGO
, show_statistics
, NULL
);
7560 static ssize_t
show_antenna(struct device
*d
,
7561 struct device_attribute
*attr
, char *buf
)
7563 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7565 if (!iwl_is_alive(priv
))
7568 return sprintf(buf
, "%d\n", priv
->antenna
);
7571 static ssize_t
store_antenna(struct device
*d
,
7572 struct device_attribute
*attr
,
7573 const char *buf
, size_t count
)
7576 struct iwl_priv
*priv
= dev_get_drvdata(d
);
7581 if (sscanf(buf
, "%1i", &ant
) != 1) {
7582 IWL_DEBUG_INFO("not in hex or decimal form.\n");
7586 if ((ant
>= 0) && (ant
<= 2)) {
7587 IWL_DEBUG_INFO("Setting antenna select to %d.\n", ant
);
7588 priv
->antenna
= (enum iwl4965_antenna
)ant
;
7590 IWL_DEBUG_INFO("Bad antenna select value %d.\n", ant
);
7596 static DEVICE_ATTR(antenna
, S_IWUSR
| S_IRUGO
, show_antenna
, store_antenna
);
7598 static ssize_t
show_status(struct device
*d
,
7599 struct device_attribute
*attr
, char *buf
)
7601 struct iwl_priv
*priv
= (struct iwl_priv
*)d
->driver_data
;
7602 if (!iwl_is_alive(priv
))
7604 return sprintf(buf
, "0x%08x\n", (int)priv
->status
);
7607 static DEVICE_ATTR(status
, S_IRUGO
, show_status
, NULL
);
7609 static ssize_t
dump_error_log(struct device
*d
,
7610 struct device_attribute
*attr
,
7611 const char *buf
, size_t count
)
7613 char *p
= (char *)buf
;
7616 iwl4965_dump_nic_error_log((struct iwl_priv
*)d
->driver_data
);
7618 return strnlen(buf
, count
);
7621 static DEVICE_ATTR(dump_errors
, S_IWUSR
, NULL
, dump_error_log
);
7623 static ssize_t
dump_event_log(struct device
*d
,
7624 struct device_attribute
*attr
,
7625 const char *buf
, size_t count
)
7627 char *p
= (char *)buf
;
7630 iwl4965_dump_nic_event_log((struct iwl_priv
*)d
->driver_data
);
7632 return strnlen(buf
, count
);
7635 static DEVICE_ATTR(dump_events
, S_IWUSR
, NULL
, dump_event_log
);
7637 /*****************************************************************************
7639 * driver setup and teardown
7641 *****************************************************************************/
7643 static void iwl4965_setup_deferred_work(struct iwl_priv
*priv
)
7645 priv
->workqueue
= create_workqueue(DRV_NAME
);
7647 init_waitqueue_head(&priv
->wait_command_queue
);
7649 INIT_WORK(&priv
->up
, iwl4965_bg_up
);
7650 INIT_WORK(&priv
->restart
, iwl4965_bg_restart
);
7651 INIT_WORK(&priv
->rx_replenish
, iwl4965_bg_rx_replenish
);
7652 INIT_WORK(&priv
->scan_completed
, iwl4965_bg_scan_completed
);
7653 INIT_WORK(&priv
->request_scan
, iwl4965_bg_request_scan
);
7654 INIT_WORK(&priv
->abort_scan
, iwl4965_bg_abort_scan
);
7655 INIT_WORK(&priv
->rf_kill
, iwl4965_bg_rf_kill
);
7656 INIT_WORK(&priv
->beacon_update
, iwl4965_bg_beacon_update
);
7657 INIT_DELAYED_WORK(&priv
->post_associate
, iwl4965_bg_post_associate
);
7658 INIT_DELAYED_WORK(&priv
->init_alive_start
, iwl4965_bg_init_alive_start
);
7659 INIT_DELAYED_WORK(&priv
->alive_start
, iwl4965_bg_alive_start
);
7660 INIT_DELAYED_WORK(&priv
->scan_check
, iwl4965_bg_scan_check
);
7662 iwl4965_hw_setup_deferred_work(priv
);
7664 tasklet_init(&priv
->irq_tasklet
, (void (*)(unsigned long))
7665 iwl4965_irq_tasklet
, (unsigned long)priv
);
7668 static void iwl4965_cancel_deferred_work(struct iwl_priv
*priv
)
7670 iwl4965_hw_cancel_deferred_work(priv
);
7672 cancel_delayed_work_sync(&priv
->init_alive_start
);
7673 cancel_delayed_work(&priv
->scan_check
);
7674 cancel_delayed_work(&priv
->alive_start
);
7675 cancel_delayed_work(&priv
->post_associate
);
7676 cancel_work_sync(&priv
->beacon_update
);
7679 static struct attribute
*iwl4965_sysfs_entries
[] = {
7680 &dev_attr_antenna
.attr
,
7681 &dev_attr_channels
.attr
,
7682 &dev_attr_dump_errors
.attr
,
7683 &dev_attr_dump_events
.attr
,
7684 &dev_attr_flags
.attr
,
7685 &dev_attr_filter_flags
.attr
,
7686 #ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
7687 &dev_attr_measurement
.attr
,
7689 &dev_attr_power_level
.attr
,
7690 &dev_attr_retry_rate
.attr
,
7691 &dev_attr_rs_window
.attr
,
7692 &dev_attr_statistics
.attr
,
7693 &dev_attr_status
.attr
,
7694 &dev_attr_temperature
.attr
,
7695 &dev_attr_tx_power
.attr
,
7700 static struct attribute_group iwl4965_attribute_group
= {
7701 .name
= NULL
, /* put in device directory */
7702 .attrs
= iwl4965_sysfs_entries
,
7705 static struct ieee80211_ops iwl4965_hw_ops
= {
7706 .tx
= iwl4965_mac_tx
,
7707 .start
= iwl4965_mac_start
,
7708 .stop
= iwl4965_mac_stop
,
7709 .add_interface
= iwl4965_mac_add_interface
,
7710 .remove_interface
= iwl4965_mac_remove_interface
,
7711 .config
= iwl4965_mac_config
,
7712 .config_interface
= iwl4965_mac_config_interface
,
7713 .configure_filter
= iwl4965_configure_filter
,
7714 .set_key
= iwl4965_mac_set_key
,
7715 .update_tkip_key
= iwl4965_mac_update_tkip_key
,
7716 .get_stats
= iwl4965_mac_get_stats
,
7717 .get_tx_stats
= iwl4965_mac_get_tx_stats
,
7718 .conf_tx
= iwl4965_mac_conf_tx
,
7719 .get_tsf
= iwl4965_mac_get_tsf
,
7720 .reset_tsf
= iwl4965_mac_reset_tsf
,
7721 .beacon_update
= iwl4965_mac_beacon_update
,
7722 .bss_info_changed
= iwl4965_bss_info_changed
,
7723 #ifdef CONFIG_IWL4965_HT
7724 .ampdu_action
= iwl4965_mac_ampdu_action
,
7725 #endif /* CONFIG_IWL4965_HT */
7726 .hw_scan
= iwl4965_mac_hw_scan
7729 static int iwl4965_pci_probe(struct pci_dev
*pdev
, const struct pci_device_id
*ent
)
7732 struct iwl_priv
*priv
;
7733 struct ieee80211_hw
*hw
;
7734 struct iwl_cfg
*cfg
= (struct iwl_cfg
*)(ent
->driver_data
);
7735 unsigned long flags
;
7736 DECLARE_MAC_BUF(mac
);
7738 /************************
7739 * 1. Allocating HW data
7740 ************************/
7742 /* Disabling hardware scan means that mac80211 will perform scans
7743 * "the hard way", rather than using device's scan. */
7744 if (cfg
->mod_params
->disable_hw_scan
) {
7745 IWL_DEBUG_INFO("Disabling hw_scan\n");
7746 iwl4965_hw_ops
.hw_scan
= NULL
;
7749 hw
= iwl_alloc_all(cfg
, &iwl4965_hw_ops
);
7755 /* At this point both hw and priv are allocated. */
7757 SET_IEEE80211_DEV(hw
, &pdev
->dev
);
7759 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
7761 priv
->pci_dev
= pdev
;
7763 #ifdef CONFIG_IWLWIFI_DEBUG
7764 iwl_debug_level
= priv
->cfg
->mod_params
->debug
;
7765 atomic_set(&priv
->restrict_refcnt
, 0);
7768 /**************************
7769 * 2. Initializing PCI bus
7770 **************************/
7771 if (pci_enable_device(pdev
)) {
7773 goto out_ieee80211_free_hw
;
7776 pci_set_master(pdev
);
7778 err
= pci_set_dma_mask(pdev
, DMA_32BIT_MASK
);
7780 err
= pci_set_consistent_dma_mask(pdev
, DMA_32BIT_MASK
);
7782 printk(KERN_WARNING DRV_NAME
7783 ": No suitable DMA available.\n");
7784 goto out_pci_disable_device
;
7787 err
= pci_request_regions(pdev
, DRV_NAME
);
7789 goto out_pci_disable_device
;
7791 pci_set_drvdata(pdev
, priv
);
7793 /* We disable the RETRY_TIMEOUT register (0x41) to keep
7794 * PCI Tx retries from interfering with C3 CPU state */
7795 pci_write_config_byte(pdev
, 0x41, 0x00);
7797 /***********************
7798 * 3. Read REV register
7799 ***********************/
7800 priv
->hw_base
= pci_iomap(pdev
, 0, 0);
7801 if (!priv
->hw_base
) {
7803 goto out_pci_release_regions
;
7806 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
7807 (unsigned long long) pci_resource_len(pdev
, 0));
7808 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv
->hw_base
);
7810 printk(KERN_INFO DRV_NAME
7811 ": Detected Intel Wireless WiFi Link %s\n", priv
->cfg
->name
);
7817 iwl_set_bit(priv
, CSR_GIO_CHICKEN_BITS
,
7818 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER
);
7820 iwl_set_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_INIT_DONE
);
7821 err
= iwl_poll_bit(priv
, CSR_GP_CNTRL
,
7822 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
,
7823 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
, 25000);
7825 IWL_DEBUG_INFO("Failed to init the card\n");
7828 /* Read the EEPROM */
7829 err
= iwl_eeprom_init(priv
);
7831 IWL_ERROR("Unable to init EEPROM\n");
7834 /* MAC Address location in EEPROM same for 3945/4965 */
7835 iwl_eeprom_get_mac(priv
, priv
->mac_addr
);
7836 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac
, priv
->mac_addr
));
7837 SET_IEEE80211_PERM_ADDR(priv
->hw
, priv
->mac_addr
);
7839 /************************
7840 * 5. Setup HW constants
7841 ************************/
7842 /* Device-specific setup */
7843 if (iwl4965_hw_set_hw_setting(priv
)) {
7844 IWL_ERROR("failed to set hw settings\n");
7848 /*******************
7850 *******************/
7852 err
= iwl_setup(priv
);
7854 goto out_unset_hw_settings
;
7855 /* At this point both hw and priv are initialized. */
7857 /**********************************
7858 * 7. Initialize module parameters
7859 **********************************/
7861 /* Disable radio (SW RF KILL) via parameter when loading driver */
7862 if (priv
->cfg
->mod_params
->disable
) {
7863 set_bit(STATUS_RF_KILL_SW
, &priv
->status
);
7864 IWL_DEBUG_INFO("Radio disabled.\n");
7867 if (priv
->cfg
->mod_params
->enable_qos
)
7868 priv
->qos_data
.qos_enable
= 1;
7870 /********************
7872 ********************/
7873 spin_lock_irqsave(&priv
->lock
, flags
);
7874 iwl4965_disable_interrupts(priv
);
7875 spin_unlock_irqrestore(&priv
->lock
, flags
);
7877 err
= sysfs_create_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
7879 IWL_ERROR("failed to create sysfs device attributes\n");
7880 goto out_unset_hw_settings
;
7883 err
= iwl_dbgfs_register(priv
, DRV_NAME
);
7885 IWL_ERROR("failed to create debugfs files\n");
7886 goto out_remove_sysfs
;
7889 iwl4965_setup_deferred_work(priv
);
7890 iwl4965_setup_rx_handlers(priv
);
7892 /********************
7894 ********************/
7895 pci_save_state(pdev
);
7896 pci_disable_device(pdev
);
7898 /* notify iwlcore to init */
7899 iwlcore_low_level_notify(priv
, IWLCORE_INIT_EVT
);
7903 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
7904 out_unset_hw_settings
:
7905 iwl4965_unset_hw_setting(priv
);
7907 pci_iounmap(pdev
, priv
->hw_base
);
7908 out_pci_release_regions
:
7909 pci_release_regions(pdev
);
7910 pci_set_drvdata(pdev
, NULL
);
7911 out_pci_disable_device
:
7912 pci_disable_device(pdev
);
7913 out_ieee80211_free_hw
:
7914 ieee80211_free_hw(priv
->hw
);
7919 static void __devexit
iwl4965_pci_remove(struct pci_dev
*pdev
)
7921 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
7922 struct list_head
*p
, *q
;
7924 unsigned long flags
;
7929 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
7931 if (priv
->mac80211_registered
) {
7932 ieee80211_unregister_hw(priv
->hw
);
7933 priv
->mac80211_registered
= 0;
7936 set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
7940 /* make sure we flush any pending irq or
7941 * tasklet for the driver
7943 spin_lock_irqsave(&priv
->lock
, flags
);
7944 iwl4965_disable_interrupts(priv
);
7945 spin_unlock_irqrestore(&priv
->lock
, flags
);
7947 iwl_synchronize_irq(priv
);
7949 /* Free MAC hash list for ADHOC */
7950 for (i
= 0; i
< IWL_IBSS_MAC_HASH_SIZE
; i
++) {
7951 list_for_each_safe(p
, q
, &priv
->ibss_mac_hash
[i
]) {
7953 kfree(list_entry(p
, struct iwl4965_ibss_seq
, list
));
7957 iwlcore_low_level_notify(priv
, IWLCORE_REMOVE_EVT
);
7958 iwl_dbgfs_unregister(priv
);
7959 sysfs_remove_group(&pdev
->dev
.kobj
, &iwl4965_attribute_group
);
7961 iwl4965_dealloc_ucode_pci(priv
);
7964 iwl4965_rx_queue_free(priv
, &priv
->rxq
);
7965 iwl4965_hw_txq_ctx_free(priv
);
7967 iwl4965_unset_hw_setting(priv
);
7968 iwlcore_clear_stations_table(priv
);
7971 /*netif_stop_queue(dev); */
7972 flush_workqueue(priv
->workqueue
);
7974 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
7975 * priv->workqueue... so we can't take down the workqueue
7977 destroy_workqueue(priv
->workqueue
);
7978 priv
->workqueue
= NULL
;
7980 pci_iounmap(pdev
, priv
->hw_base
);
7981 pci_release_regions(pdev
);
7982 pci_disable_device(pdev
);
7983 pci_set_drvdata(pdev
, NULL
);
7985 iwl_free_channel_map(priv
);
7986 iwl4965_free_geos(priv
);
7988 if (priv
->ibss_beacon
)
7989 dev_kfree_skb(priv
->ibss_beacon
);
7991 ieee80211_free_hw(priv
->hw
);
7996 static int iwl4965_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
7998 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
8000 if (priv
->is_open
) {
8001 set_bit(STATUS_IN_SUSPEND
, &priv
->status
);
8002 iwl4965_mac_stop(priv
->hw
);
8006 pci_set_power_state(pdev
, PCI_D3hot
);
8011 static int iwl4965_pci_resume(struct pci_dev
*pdev
)
8013 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
8015 pci_set_power_state(pdev
, PCI_D0
);
8018 iwl4965_mac_start(priv
->hw
);
8020 clear_bit(STATUS_IN_SUSPEND
, &priv
->status
);
8024 #endif /* CONFIG_PM */
8026 /*****************************************************************************
8028 * driver and module entry point
8030 *****************************************************************************/
8032 static struct pci_driver iwl4965_driver
= {
8034 .id_table
= iwl4965_hw_card_ids
,
8035 .probe
= iwl4965_pci_probe
,
8036 .remove
= __devexit_p(iwl4965_pci_remove
),
8038 .suspend
= iwl4965_pci_suspend
,
8039 .resume
= iwl4965_pci_resume
,
8043 static int __init
iwl4965_init(void)
8047 printk(KERN_INFO DRV_NAME
": " DRV_DESCRIPTION
", " DRV_VERSION
"\n");
8048 printk(KERN_INFO DRV_NAME
": " DRV_COPYRIGHT
"\n");
8050 ret
= iwl4965_rate_control_register();
8052 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret
);
8056 ret
= pci_register_driver(&iwl4965_driver
);
8058 IWL_ERROR("Unable to initialize PCI module\n");
8059 goto error_register
;
8061 #ifdef CONFIG_IWLWIFI_DEBUG
8062 ret
= driver_create_file(&iwl4965_driver
.driver
, &driver_attr_debug_level
);
8064 IWL_ERROR("Unable to create driver sysfs file\n");
8071 #ifdef CONFIG_IWLWIFI_DEBUG
8073 pci_unregister_driver(&iwl4965_driver
);
8076 iwl4965_rate_control_unregister();
8080 static void __exit
iwl4965_exit(void)
8082 #ifdef CONFIG_IWLWIFI_DEBUG
8083 driver_remove_file(&iwl4965_driver
.driver
, &driver_attr_debug_level
);
8085 pci_unregister_driver(&iwl4965_driver
);
8086 iwl4965_rate_control_unregister();
8089 module_exit(iwl4965_exit
);
8090 module_init(iwl4965_init
);