aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi/iwl-agn.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl-agn.c')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c538
1 files changed, 313 insertions, 225 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index b35c8813bef4..6b7120a41ab2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -1,6 +1,6 @@
1/****************************************************************************** 1/******************************************************************************
2 * 2 *
3 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved. 3 * Copyright(c) 2003 - 2009 Intel Corporation. All rights reserved.
4 * 4 *
5 * Portions of this file are derived from the ipw3945 project, as well 5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files. 6 * as portions of the ieee80211 subsystem header files.
@@ -44,6 +44,8 @@
44 44
45#include <asm/div64.h> 45#include <asm/div64.h>
46 46
47#define DRV_NAME "iwlagn"
48
47#include "iwl-eeprom.h" 49#include "iwl-eeprom.h"
48#include "iwl-dev.h" 50#include "iwl-dev.h"
49#include "iwl-core.h" 51#include "iwl-core.h"
@@ -61,9 +63,7 @@
61 63
62/* 64/*
63 * module name, copyright, version, etc. 65 * module name, copyright, version, etc.
64 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
65 */ 66 */
66
67#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux" 67#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
68 68
69#ifdef CONFIG_IWLWIFI_DEBUG 69#ifdef CONFIG_IWLWIFI_DEBUG
@@ -179,9 +179,9 @@ static int iwl_commit_rxon(struct iwl_priv *priv)
179 * 5000, but will not damage 4965 */ 179 * 5000, but will not damage 4965 */
180 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN; 180 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
181 181
182 ret = iwl_agn_check_rxon_cmd(&priv->staging_rxon); 182 ret = iwl_agn_check_rxon_cmd(priv);
183 if (ret) { 183 if (ret) {
184 IWL_ERROR("Invalid RXON configuration. Not committing.\n"); 184 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
185 return -EINVAL; 185 return -EINVAL;
186 } 186 }
187 187
@@ -191,7 +191,7 @@ static int iwl_commit_rxon(struct iwl_priv *priv)
191 if (!iwl_full_rxon_required(priv)) { 191 if (!iwl_full_rxon_required(priv)) {
192 ret = iwl_send_rxon_assoc(priv); 192 ret = iwl_send_rxon_assoc(priv);
193 if (ret) { 193 if (ret) {
194 IWL_ERROR("Error setting RXON_ASSOC (%d)\n", ret); 194 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
195 return ret; 195 return ret;
196 } 196 }
197 197
@@ -218,7 +218,7 @@ static int iwl_commit_rxon(struct iwl_priv *priv)
218 * active_rxon back to what it was previously */ 218 * active_rxon back to what it was previously */
219 if (ret) { 219 if (ret) {
220 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK; 220 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
221 IWL_ERROR("Error clearing ASSOC_MSK (%d)\n", ret); 221 IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
222 return ret; 222 return ret;
223 } 223 }
224 } 224 }
@@ -242,7 +242,7 @@ static int iwl_commit_rxon(struct iwl_priv *priv)
242 ret = iwl_send_cmd_pdu(priv, REPLY_RXON, 242 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
243 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); 243 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
244 if (ret) { 244 if (ret) {
245 IWL_ERROR("Error setting new RXON (%d)\n", ret); 245 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
246 return ret; 246 return ret;
247 } 247 }
248 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); 248 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
@@ -256,7 +256,7 @@ static int iwl_commit_rxon(struct iwl_priv *priv)
256 /* Add the broadcast address so we can send broadcast frames */ 256 /* Add the broadcast address so we can send broadcast frames */
257 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) == 257 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
258 IWL_INVALID_STATION) { 258 IWL_INVALID_STATION) {
259 IWL_ERROR("Error adding BROADCAST address for transmit.\n"); 259 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
260 return -EIO; 260 return -EIO;
261 } 261 }
262 262
@@ -267,13 +267,15 @@ static int iwl_commit_rxon(struct iwl_priv *priv)
267 ret = iwl_rxon_add_station(priv, 267 ret = iwl_rxon_add_station(priv,
268 priv->active_rxon.bssid_addr, 1); 268 priv->active_rxon.bssid_addr, 1);
269 if (ret == IWL_INVALID_STATION) { 269 if (ret == IWL_INVALID_STATION) {
270 IWL_ERROR("Error adding AP address for TX.\n"); 270 IWL_ERR(priv,
271 "Error adding AP address for TX.\n");
271 return -EIO; 272 return -EIO;
272 } 273 }
273 priv->assoc_station_added = 1; 274 priv->assoc_station_added = 1;
274 if (priv->default_wep_key && 275 if (priv->default_wep_key &&
275 iwl_send_static_wepkey_cmd(priv, 0)) 276 iwl_send_static_wepkey_cmd(priv, 0))
276 IWL_ERROR("Could not send WEP static key.\n"); 277 IWL_ERR(priv,
278 "Could not send WEP static key.\n");
277 } 279 }
278 280
279 /* Apply the new configuration 281 /* Apply the new configuration
@@ -282,7 +284,7 @@ static int iwl_commit_rxon(struct iwl_priv *priv)
282 ret = iwl_send_cmd_pdu(priv, REPLY_RXON, 284 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
283 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); 285 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
284 if (ret) { 286 if (ret) {
285 IWL_ERROR("Error setting new RXON (%d)\n", ret); 287 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
286 return ret; 288 return ret;
287 } 289 }
288 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); 290 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
@@ -294,7 +296,7 @@ static int iwl_commit_rxon(struct iwl_priv *priv)
294 * send a new TXPOWER command or we won't be able to Tx any frames */ 296 * send a new TXPOWER command or we won't be able to Tx any frames */
295 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true); 297 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
296 if (ret) { 298 if (ret) {
297 IWL_ERROR("Error sending TX power (%d)\n", ret); 299 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
298 return ret; 300 return ret;
299 } 301 }
300 302
@@ -308,20 +310,6 @@ void iwl_update_chain_flags(struct iwl_priv *priv)
308 iwl_commit_rxon(priv); 310 iwl_commit_rxon(priv);
309} 311}
310 312
311static int iwl_send_bt_config(struct iwl_priv *priv)
312{
313 struct iwl_bt_cmd bt_cmd = {
314 .flags = 3,
315 .lead_time = 0xAA,
316 .max_kill = 1,
317 .kill_ack_mask = 0,
318 .kill_cts_mask = 0,
319 };
320
321 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
322 sizeof(struct iwl_bt_cmd), &bt_cmd);
323}
324
325static void iwl_clear_free_frames(struct iwl_priv *priv) 313static void iwl_clear_free_frames(struct iwl_priv *priv)
326{ 314{
327 struct list_head *element; 315 struct list_head *element;
@@ -337,7 +325,7 @@ static void iwl_clear_free_frames(struct iwl_priv *priv)
337 } 325 }
338 326
339 if (priv->frames_count) { 327 if (priv->frames_count) {
340 IWL_WARNING("%d frames still in use. Did we lose one?\n", 328 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
341 priv->frames_count); 329 priv->frames_count);
342 priv->frames_count = 0; 330 priv->frames_count = 0;
343 } 331 }
@@ -350,7 +338,7 @@ static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
350 if (list_empty(&priv->free_frames)) { 338 if (list_empty(&priv->free_frames)) {
351 frame = kzalloc(sizeof(*frame), GFP_KERNEL); 339 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
352 if (!frame) { 340 if (!frame) {
353 IWL_ERROR("Could not allocate frame!\n"); 341 IWL_ERR(priv, "Could not allocate frame!\n");
354 return NULL; 342 return NULL;
355 } 343 }
356 344
@@ -452,7 +440,7 @@ static int iwl_send_beacon_cmd(struct iwl_priv *priv)
452 frame = iwl_get_free_frame(priv); 440 frame = iwl_get_free_frame(priv);
453 441
454 if (!frame) { 442 if (!frame) {
455 IWL_ERROR("Could not obtain free frame buffer for beacon " 443 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
456 "command.\n"); 444 "command.\n");
457 return -ENOMEM; 445 return -ENOMEM;
458 } 446 }
@@ -469,6 +457,159 @@ static int iwl_send_beacon_cmd(struct iwl_priv *priv)
469 return rc; 457 return rc;
470} 458}
471 459
460static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
461{
462 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
463
464 dma_addr_t addr = get_unaligned_le32(&tb->lo);
465 if (sizeof(dma_addr_t) > sizeof(u32))
466 addr |=
467 ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
468
469 return addr;
470}
471
472static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
473{
474 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
475
476 return le16_to_cpu(tb->hi_n_len) >> 4;
477}
478
479static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
480 dma_addr_t addr, u16 len)
481{
482 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
483 u16 hi_n_len = len << 4;
484
485 put_unaligned_le32(addr, &tb->lo);
486 if (sizeof(dma_addr_t) > sizeof(u32))
487 hi_n_len |= ((addr >> 16) >> 16) & 0xF;
488
489 tb->hi_n_len = cpu_to_le16(hi_n_len);
490
491 tfd->num_tbs = idx + 1;
492}
493
494static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
495{
496 return tfd->num_tbs & 0x1f;
497}
498
499/**
500 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
501 * @priv - driver private data
502 * @txq - tx queue
503 *
504 * Does NOT advance any TFD circular buffer read/write indexes
505 * Does NOT free the TFD itself (which is within circular buffer)
506 */
507void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
508{
509 struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
510 struct iwl_tfd *tfd;
511 struct pci_dev *dev = priv->pci_dev;
512 int index = txq->q.read_ptr;
513 int i;
514 int num_tbs;
515
516 tfd = &tfd_tmp[index];
517
518 /* Sanity check on number of chunks */
519 num_tbs = iwl_tfd_get_num_tbs(tfd);
520
521 if (num_tbs >= IWL_NUM_OF_TBS) {
522 IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
523 /* @todo issue fatal error, it is quite serious situation */
524 return;
525 }
526
527 /* Unmap tx_cmd */
528 if (num_tbs)
529 pci_unmap_single(dev,
530 pci_unmap_addr(&txq->cmd[index]->meta, mapping),
531 pci_unmap_len(&txq->cmd[index]->meta, len),
532 PCI_DMA_TODEVICE);
533
534 /* Unmap chunks, if any. */
535 for (i = 1; i < num_tbs; i++) {
536 pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
537 iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
538
539 if (txq->txb) {
540 dev_kfree_skb(txq->txb[txq->q.read_ptr].skb[i - 1]);
541 txq->txb[txq->q.read_ptr].skb[i - 1] = NULL;
542 }
543 }
544}
545
546int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
547 struct iwl_tx_queue *txq,
548 dma_addr_t addr, u16 len,
549 u8 reset, u8 pad)
550{
551 struct iwl_queue *q;
552 struct iwl_tfd *tfd, *tfd_tmp;
553 u32 num_tbs;
554
555 q = &txq->q;
556 tfd_tmp = (struct iwl_tfd *)txq->tfds;
557 tfd = &tfd_tmp[q->write_ptr];
558
559 if (reset)
560 memset(tfd, 0, sizeof(*tfd));
561
562 num_tbs = iwl_tfd_get_num_tbs(tfd);
563
564 /* Each TFD can point to a maximum 20 Tx buffers */
565 if (num_tbs >= IWL_NUM_OF_TBS) {
566 IWL_ERR(priv, "Error can not send more than %d chunks\n",
567 IWL_NUM_OF_TBS);
568 return -EINVAL;
569 }
570
571 BUG_ON(addr & ~DMA_BIT_MASK(36));
572 if (unlikely(addr & ~IWL_TX_DMA_MASK))
573 IWL_ERR(priv, "Unaligned address = %llx\n",
574 (unsigned long long)addr);
575
576 iwl_tfd_set_tb(tfd, num_tbs, addr, len);
577
578 return 0;
579}
580
581/*
582 * Tell nic where to find circular buffer of Tx Frame Descriptors for
583 * given Tx queue, and enable the DMA channel used for that queue.
584 *
585 * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
586 * channels supported in hardware.
587 */
588int iwl_hw_tx_queue_init(struct iwl_priv *priv,
589 struct iwl_tx_queue *txq)
590{
591 int ret;
592 unsigned long flags;
593 int txq_id = txq->q.id;
594
595 spin_lock_irqsave(&priv->lock, flags);
596 ret = iwl_grab_nic_access(priv);
597 if (ret) {
598 spin_unlock_irqrestore(&priv->lock, flags);
599 return ret;
600 }
601
602 /* Circular buffer (TFD queue in DRAM) physical base address */
603 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
604 txq->q.dma_addr >> 8);
605
606 iwl_release_nic_access(priv);
607 spin_unlock_irqrestore(&priv->lock, flags);
608
609 return 0;
610}
611
612
472/****************************************************************************** 613/******************************************************************************
473 * 614 *
474 * Misc. internal state and helper functions 615 * Misc. internal state and helper functions
@@ -520,9 +661,9 @@ static void iwl_ht_conf(struct iwl_priv *priv,
520 */ 661 */
521 662
522 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE; 663 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
523 if (priv->hw->conf.ht.channel_type == NL80211_CHAN_HT40MINUS) 664 if (conf_is_ht40_minus(&priv->hw->conf))
524 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW; 665 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
525 else if(priv->hw->conf.ht.channel_type == NL80211_CHAN_HT40PLUS) 666 else if (conf_is_ht40_plus(&priv->hw->conf))
526 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE; 667 iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
527 668
528 /* If no above or below channel supplied disable FAT channel */ 669 /* If no above or below channel supplied disable FAT channel */
@@ -686,7 +827,7 @@ static void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
686 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK; 827 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
687 break; 828 break;
688 default: 829 default:
689 IWL_ERROR("Unsupported interface type %d\n", mode); 830 IWL_ERR(priv, "Unsupported interface type %d\n", mode);
690 break; 831 break;
691 } 832 }
692 833
@@ -745,7 +886,7 @@ static int iwl_set_mode(struct iwl_priv *priv, int mode)
745 886
746 cancel_delayed_work(&priv->scan_check); 887 cancel_delayed_work(&priv->scan_check);
747 if (iwl_scan_cancel_timeout(priv, 100)) { 888 if (iwl_scan_cancel_timeout(priv, 100)) {
748 IWL_WARNING("Aborted scan still in progress after 100ms\n"); 889 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
749 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); 890 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
750 return -EAGAIN; 891 return -EAGAIN;
751 } 892 }
@@ -763,7 +904,7 @@ static void iwl_set_rate(struct iwl_priv *priv)
763 904
764 hw = iwl_get_hw_mode(priv, priv->band); 905 hw = iwl_get_hw_mode(priv, priv->band);
765 if (!hw) { 906 if (!hw) {
766 IWL_ERROR("Failed to set rate: unable to get hw mode\n"); 907 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
767 return; 908 return;
768 } 909 }
769 910
@@ -841,7 +982,7 @@ static void iwl_rx_reply_alive(struct iwl_priv *priv,
841 queue_delayed_work(priv->workqueue, pwork, 982 queue_delayed_work(priv->workqueue, pwork,
842 msecs_to_jiffies(5)); 983 msecs_to_jiffies(5));
843 else 984 else
844 IWL_WARNING("uCode did not respond OK.\n"); 985 IWL_WARN(priv, "uCode did not respond OK.\n");
845} 986}
846 987
847static void iwl_rx_reply_error(struct iwl_priv *priv, 988static void iwl_rx_reply_error(struct iwl_priv *priv,
@@ -849,7 +990,7 @@ static void iwl_rx_reply_error(struct iwl_priv *priv,
849{ 990{
850 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data; 991 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
851 992
852 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) " 993 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
853 "seq 0x%04X ser 0x%08X\n", 994 "seq 0x%04X ser 0x%08X\n",
854 le32_to_cpu(pkt->u.err_resp.error_type), 995 le32_to_cpu(pkt->u.err_resp.error_type),
855 get_cmd_string(pkt->u.err_resp.cmd_id), 996 get_cmd_string(pkt->u.err_resp.cmd_id),
@@ -902,7 +1043,7 @@ static void iwl_bg_beacon_update(struct work_struct *work)
902 beacon = ieee80211_beacon_get(priv->hw, priv->vif); 1043 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
903 1044
904 if (!beacon) { 1045 if (!beacon) {
905 IWL_ERROR("update beacon failed\n"); 1046 IWL_ERR(priv, "update beacon failed\n");
906 return; 1047 return;
907 } 1048 }
908 1049
@@ -1193,7 +1334,7 @@ void iwl_rx_handle(struct iwl_priv *priv)
1193 if (rxb && rxb->skb) 1334 if (rxb && rxb->skb)
1194 iwl_tx_cmd_complete(priv, rxb); 1335 iwl_tx_cmd_complete(priv, rxb);
1195 else 1336 else
1196 IWL_WARNING("Claim null rxb?\n"); 1337 IWL_WARN(priv, "Claim null rxb?\n");
1197 } 1338 }
1198 1339
1199 /* For now we just don't re-use anything. We can tweak this 1340 /* For now we just don't re-use anything. We can tweak this
@@ -1357,7 +1498,7 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1357 1498
1358 /* Now service all interrupt bits discovered above. */ 1499 /* Now service all interrupt bits discovered above. */
1359 if (inta & CSR_INT_BIT_HW_ERR) { 1500 if (inta & CSR_INT_BIT_HW_ERR) {
1360 IWL_ERROR("Microcode HW error detected. Restarting.\n"); 1501 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
1361 1502
1362 /* Tell the device to stop sending interrupts */ 1503 /* Tell the device to stop sending interrupts */
1363 iwl_disable_interrupts(priv); 1504 iwl_disable_interrupts(priv);
@@ -1397,13 +1538,16 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1397 hw_rf_kill ? "disable radio" : "enable radio"); 1538 hw_rf_kill ? "disable radio" : "enable radio");
1398 1539
1399 /* driver only loads ucode once setting the interface up. 1540 /* driver only loads ucode once setting the interface up.
1400 * the driver as well won't allow loading if RFKILL is set 1541 * the driver allows loading the ucode even if the radio
1401 * therefore no need to restart the driver from this handler 1542 * is killed. Hence update the killswitch state here. The
1543 * rfkill handler will care about restarting if needed.
1402 */ 1544 */
1403 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) { 1545 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1404 clear_bit(STATUS_RF_KILL_HW, &priv->status); 1546 if (hw_rf_kill)
1405 if (priv->is_open && !iwl_is_rfkill(priv)) 1547 set_bit(STATUS_RF_KILL_HW, &priv->status);
1406 queue_work(priv->workqueue, &priv->up); 1548 else
1549 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1550 queue_work(priv->workqueue, &priv->rf_kill);
1407 } 1551 }
1408 1552
1409 handled |= CSR_INT_BIT_RF_KILL; 1553 handled |= CSR_INT_BIT_RF_KILL;
@@ -1411,14 +1555,14 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1411 1555
1412 /* Chip got too hot and stopped itself */ 1556 /* Chip got too hot and stopped itself */
1413 if (inta & CSR_INT_BIT_CT_KILL) { 1557 if (inta & CSR_INT_BIT_CT_KILL) {
1414 IWL_ERROR("Microcode CT kill error detected.\n"); 1558 IWL_ERR(priv, "Microcode CT kill error detected.\n");
1415 handled |= CSR_INT_BIT_CT_KILL; 1559 handled |= CSR_INT_BIT_CT_KILL;
1416 } 1560 }
1417 1561
1418 /* Error detected by uCode */ 1562 /* Error detected by uCode */
1419 if (inta & CSR_INT_BIT_SW_ERR) { 1563 if (inta & CSR_INT_BIT_SW_ERR) {
1420 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n", 1564 IWL_ERR(priv, "Microcode SW error detected. "
1421 inta); 1565 " Restarting 0x%X.\n", inta);
1422 iwl_irq_handle_error(priv); 1566 iwl_irq_handle_error(priv);
1423 handled |= CSR_INT_BIT_SW_ERR; 1567 handled |= CSR_INT_BIT_SW_ERR;
1424 } 1568 }
@@ -1454,12 +1598,12 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
1454 } 1598 }
1455 1599
1456 if (inta & ~handled) 1600 if (inta & ~handled)
1457 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled); 1601 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
1458 1602
1459 if (inta & ~CSR_INI_SET_MASK) { 1603 if (inta & ~CSR_INI_SET_MASK) {
1460 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n", 1604 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
1461 inta & ~CSR_INI_SET_MASK); 1605 inta & ~CSR_INI_SET_MASK);
1462 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh); 1606 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
1463 } 1607 }
1464 1608
1465 /* Re-enable all interrupts */ 1609 /* Re-enable all interrupts */
@@ -1511,7 +1655,7 @@ static irqreturn_t iwl_isr(int irq, void *data)
1511 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) { 1655 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
1512 /* Hardware disappeared. It might have already raised 1656 /* Hardware disappeared. It might have already raised
1513 * an interrupt */ 1657 * an interrupt */
1514 IWL_WARNING("HARDWARE GONE?? INTA == 0x%08x\n", inta); 1658 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
1515 goto unplugged; 1659 goto unplugged;
1516 } 1660 }
1517 1661
@@ -1584,7 +1728,7 @@ static int iwl_read_ucode(struct iwl_priv *priv)
1584 sprintf(buf, "%s%d%s", name_pre, index, ".ucode"); 1728 sprintf(buf, "%s%d%s", name_pre, index, ".ucode");
1585 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev); 1729 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
1586 if (ret < 0) { 1730 if (ret < 0) {
1587 IWL_ERROR("%s firmware file req failed: Reason %d\n", 1731 IWL_ERR(priv, "%s firmware file req failed: %d\n",
1588 buf, ret); 1732 buf, ret);
1589 if (ret == -ENOENT) 1733 if (ret == -ENOENT)
1590 continue; 1734 continue;
@@ -1592,8 +1736,11 @@ static int iwl_read_ucode(struct iwl_priv *priv)
1592 goto error; 1736 goto error;
1593 } else { 1737 } else {
1594 if (index < api_max) 1738 if (index < api_max)
1595 IWL_ERROR("Loaded firmware %s, which is deprecated. Please use API v%u instead.\n", 1739 IWL_ERR(priv, "Loaded firmware %s, "
1740 "which is deprecated. "
1741 "Please use API v%u instead.\n",
1596 buf, api_max); 1742 buf, api_max);
1743
1597 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n", 1744 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
1598 buf, ucode_raw->size); 1745 buf, ucode_raw->size);
1599 break; 1746 break;
@@ -1605,7 +1752,7 @@ static int iwl_read_ucode(struct iwl_priv *priv)
1605 1752
1606 /* Make sure that we got at least our header! */ 1753 /* Make sure that we got at least our header! */
1607 if (ucode_raw->size < sizeof(*ucode)) { 1754 if (ucode_raw->size < sizeof(*ucode)) {
1608 IWL_ERROR("File size way too small!\n"); 1755 IWL_ERR(priv, "File size way too small!\n");
1609 ret = -EINVAL; 1756 ret = -EINVAL;
1610 goto err_release; 1757 goto err_release;
1611 } 1758 }
@@ -1626,7 +1773,7 @@ static int iwl_read_ucode(struct iwl_priv *priv)
1626 * on the API version read from firware header from here on forward */ 1773 * on the API version read from firware header from here on forward */
1627 1774
1628 if (api_ver < api_min || api_ver > api_max) { 1775 if (api_ver < api_min || api_ver > api_max) {
1629 IWL_ERROR("Driver unable to support your firmware API. " 1776 IWL_ERR(priv, "Driver unable to support your firmware API. "
1630 "Driver supports v%u, firmware is v%u.\n", 1777 "Driver supports v%u, firmware is v%u.\n",
1631 api_max, api_ver); 1778 api_max, api_ver);
1632 priv->ucode_ver = 0; 1779 priv->ucode_ver = 0;
@@ -1634,16 +1781,16 @@ static int iwl_read_ucode(struct iwl_priv *priv)
1634 goto err_release; 1781 goto err_release;
1635 } 1782 }
1636 if (api_ver != api_max) 1783 if (api_ver != api_max)
1637 IWL_ERROR("Firmware has old API version. Expected v%u, " 1784 IWL_ERR(priv, "Firmware has old API version. Expected v%u, "
1638 "got v%u. New firmware can be obtained " 1785 "got v%u. New firmware can be obtained "
1639 "from http://www.intellinuxwireless.org.\n", 1786 "from http://www.intellinuxwireless.org.\n",
1640 api_max, api_ver); 1787 api_max, api_ver);
1641 1788
1642 printk(KERN_INFO DRV_NAME " loaded firmware version %u.%u.%u.%u\n", 1789 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
1643 IWL_UCODE_MAJOR(priv->ucode_ver), 1790 IWL_UCODE_MAJOR(priv->ucode_ver),
1644 IWL_UCODE_MINOR(priv->ucode_ver), 1791 IWL_UCODE_MINOR(priv->ucode_ver),
1645 IWL_UCODE_API(priv->ucode_ver), 1792 IWL_UCODE_API(priv->ucode_ver),
1646 IWL_UCODE_SERIAL(priv->ucode_ver)); 1793 IWL_UCODE_SERIAL(priv->ucode_ver));
1647 1794
1648 IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n", 1795 IWL_DEBUG_INFO("f/w package hdr ucode version raw = 0x%x\n",
1649 priv->ucode_ver); 1796 priv->ucode_ver);
@@ -1791,7 +1938,7 @@ static int iwl_read_ucode(struct iwl_priv *priv)
1791 return 0; 1938 return 0;
1792 1939
1793 err_pci_alloc: 1940 err_pci_alloc:
1794 IWL_ERROR("failed to allocate pci memory\n"); 1941 IWL_ERR(priv, "failed to allocate pci memory\n");
1795 ret = -ENOMEM; 1942 ret = -ENOMEM;
1796 iwl_dealloc_ucode_pci(priv); 1943 iwl_dealloc_ucode_pci(priv);
1797 1944
@@ -1837,8 +1984,8 @@ static void iwl_alive_start(struct iwl_priv *priv)
1837 iwl_clear_stations_table(priv); 1984 iwl_clear_stations_table(priv);
1838 ret = priv->cfg->ops->lib->alive_notify(priv); 1985 ret = priv->cfg->ops->lib->alive_notify(priv);
1839 if (ret) { 1986 if (ret) {
1840 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n", 1987 IWL_WARN(priv,
1841 ret); 1988 "Could not complete ALIVE transition [ntf]: %d\n", ret);
1842 goto restart; 1989 goto restart;
1843 } 1990 }
1844 1991
@@ -2024,12 +2171,12 @@ static int __iwl_up(struct iwl_priv *priv)
2024 int ret; 2171 int ret;
2025 2172
2026 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { 2173 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
2027 IWL_WARNING("Exit pending; will not bring the NIC up\n"); 2174 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
2028 return -EIO; 2175 return -EIO;
2029 } 2176 }
2030 2177
2031 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) { 2178 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
2032 IWL_ERROR("ucode not available for device bringup\n"); 2179 IWL_ERR(priv, "ucode not available for device bringup\n");
2033 return -EIO; 2180 return -EIO;
2034 } 2181 }
2035 2182
@@ -2041,7 +2188,7 @@ static int __iwl_up(struct iwl_priv *priv)
2041 2188
2042 if (iwl_is_rfkill(priv)) { 2189 if (iwl_is_rfkill(priv)) {
2043 iwl_enable_interrupts(priv); 2190 iwl_enable_interrupts(priv);
2044 IWL_WARNING("Radio disabled by %s RF Kill switch\n", 2191 IWL_WARN(priv, "Radio disabled by %s RF Kill switch\n",
2045 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW"); 2192 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
2046 return 0; 2193 return 0;
2047 } 2194 }
@@ -2050,7 +2197,7 @@ static int __iwl_up(struct iwl_priv *priv)
2050 2197
2051 ret = iwl_hw_nic_init(priv); 2198 ret = iwl_hw_nic_init(priv);
2052 if (ret) { 2199 if (ret) {
2053 IWL_ERROR("Unable to init nic\n"); 2200 IWL_ERR(priv, "Unable to init nic\n");
2054 return ret; 2201 return ret;
2055 } 2202 }
2056 2203
@@ -2083,7 +2230,8 @@ static int __iwl_up(struct iwl_priv *priv)
2083 ret = priv->cfg->ops->lib->load_ucode(priv); 2230 ret = priv->cfg->ops->lib->load_ucode(priv);
2084 2231
2085 if (ret) { 2232 if (ret) {
2086 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret); 2233 IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
2234 ret);
2087 continue; 2235 continue;
2088 } 2236 }
2089 2237
@@ -2104,7 +2252,7 @@ static int __iwl_up(struct iwl_priv *priv)
2104 2252
2105 /* tried to restart and config the device for as long as our 2253 /* tried to restart and config the device for as long as our
2106 * patience could withstand */ 2254 * patience could withstand */
2107 IWL_ERROR("Unable to initialize device after %d attempts.\n", i); 2255 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
2108 return -EIO; 2256 return -EIO;
2109} 2257}
2110 2258
@@ -2141,40 +2289,6 @@ static void iwl_bg_alive_start(struct work_struct *data)
2141 mutex_unlock(&priv->mutex); 2289 mutex_unlock(&priv->mutex);
2142} 2290}
2143 2291
2144static void iwl_bg_rf_kill(struct work_struct *work)
2145{
2146 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
2147
2148 wake_up_interruptible(&priv->wait_command_queue);
2149
2150 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2151 return;
2152
2153 mutex_lock(&priv->mutex);
2154
2155 if (!iwl_is_rfkill(priv)) {
2156 IWL_DEBUG(IWL_DL_RF_KILL,
2157 "HW and/or SW RF Kill no longer active, restarting "
2158 "device\n");
2159 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
2160 queue_work(priv->workqueue, &priv->restart);
2161 } else {
2162 /* make sure mac80211 stop sending Tx frame */
2163 if (priv->mac80211_registered)
2164 ieee80211_stop_queues(priv->hw);
2165
2166 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
2167 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2168 "disabled by SW switch\n");
2169 else
2170 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
2171 "Kill switch must be turned off for "
2172 "wireless networking to work.\n");
2173 }
2174 mutex_unlock(&priv->mutex);
2175 iwl_rfkill_set_hw_state(priv);
2176}
2177
2178static void iwl_bg_run_time_calib_work(struct work_struct *work) 2292static void iwl_bg_run_time_calib_work(struct work_struct *work)
2179{ 2293{
2180 struct iwl_priv *priv = container_of(work, struct iwl_priv, 2294 struct iwl_priv *priv = container_of(work, struct iwl_priv,
@@ -2244,7 +2358,7 @@ static void iwl_post_associate(struct iwl_priv *priv)
2244 unsigned long flags; 2358 unsigned long flags;
2245 2359
2246 if (priv->iw_mode == NL80211_IFTYPE_AP) { 2360 if (priv->iw_mode == NL80211_IFTYPE_AP) {
2247 IWL_ERROR("%s Should not be called in AP mode\n", __func__); 2361 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
2248 return; 2362 return;
2249 } 2363 }
2250 2364
@@ -2271,7 +2385,7 @@ static void iwl_post_associate(struct iwl_priv *priv)
2271 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, 2385 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
2272 sizeof(priv->rxon_timing), &priv->rxon_timing); 2386 sizeof(priv->rxon_timing), &priv->rxon_timing);
2273 if (ret) 2387 if (ret)
2274 IWL_WARNING("REPLY_RXON_TIMING failed - " 2388 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
2275 "Attempting to continue.\n"); 2389 "Attempting to continue.\n");
2276 2390
2277 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 2391 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
@@ -2317,7 +2431,7 @@ static void iwl_post_associate(struct iwl_priv *priv)
2317 break; 2431 break;
2318 2432
2319 default: 2433 default:
2320 IWL_ERROR("%s Should not be called in %d mode\n", 2434 IWL_ERR(priv, "%s Should not be called in %d mode\n",
2321 __func__, priv->iw_mode); 2435 __func__, priv->iw_mode);
2322 break; 2436 break;
2323 } 2437 }
@@ -2353,31 +2467,9 @@ static int iwl_mac_start(struct ieee80211_hw *hw)
2353{ 2467{
2354 struct iwl_priv *priv = hw->priv; 2468 struct iwl_priv *priv = hw->priv;
2355 int ret; 2469 int ret;
2356 u16 pci_cmd;
2357 2470
2358 IWL_DEBUG_MAC80211("enter\n"); 2471 IWL_DEBUG_MAC80211("enter\n");
2359 2472
2360 if (pci_enable_device(priv->pci_dev)) {
2361 IWL_ERROR("Fail to pci_enable_device\n");
2362 return -ENODEV;
2363 }
2364 pci_restore_state(priv->pci_dev);
2365 pci_enable_msi(priv->pci_dev);
2366
2367 /* enable interrupts if needed: hw bug w/a */
2368 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
2369 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
2370 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
2371 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
2372 }
2373
2374 ret = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
2375 DRV_NAME, priv);
2376 if (ret) {
2377 IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
2378 goto out_disable_msi;
2379 }
2380
2381 /* we should be verifying the device is ready to be opened */ 2473 /* we should be verifying the device is ready to be opened */
2382 mutex_lock(&priv->mutex); 2474 mutex_lock(&priv->mutex);
2383 2475
@@ -2388,9 +2480,9 @@ static int iwl_mac_start(struct ieee80211_hw *hw)
2388 if (!priv->ucode_code.len) { 2480 if (!priv->ucode_code.len) {
2389 ret = iwl_read_ucode(priv); 2481 ret = iwl_read_ucode(priv);
2390 if (ret) { 2482 if (ret) {
2391 IWL_ERROR("Could not read microcode: %d\n", ret); 2483 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
2392 mutex_unlock(&priv->mutex); 2484 mutex_unlock(&priv->mutex);
2393 goto out_release_irq; 2485 return ret;
2394 } 2486 }
2395 } 2487 }
2396 2488
@@ -2401,7 +2493,7 @@ static int iwl_mac_start(struct ieee80211_hw *hw)
2401 iwl_rfkill_set_hw_state(priv); 2493 iwl_rfkill_set_hw_state(priv);
2402 2494
2403 if (ret) 2495 if (ret)
2404 goto out_release_irq; 2496 return ret;
2405 2497
2406 if (iwl_is_rfkill(priv)) 2498 if (iwl_is_rfkill(priv))
2407 goto out; 2499 goto out;
@@ -2418,10 +2510,9 @@ static int iwl_mac_start(struct ieee80211_hw *hw)
2418 UCODE_READY_TIMEOUT); 2510 UCODE_READY_TIMEOUT);
2419 if (!ret) { 2511 if (!ret) {
2420 if (!test_bit(STATUS_READY, &priv->status)) { 2512 if (!test_bit(STATUS_READY, &priv->status)) {
2421 IWL_ERROR("START_ALIVE timeout after %dms.\n", 2513 IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
2422 jiffies_to_msecs(UCODE_READY_TIMEOUT)); 2514 jiffies_to_msecs(UCODE_READY_TIMEOUT));
2423 ret = -ETIMEDOUT; 2515 return -ETIMEDOUT;
2424 goto out_release_irq;
2425 } 2516 }
2426 } 2517 }
2427 2518
@@ -2429,15 +2520,6 @@ out:
2429 priv->is_open = 1; 2520 priv->is_open = 1;
2430 IWL_DEBUG_MAC80211("leave\n"); 2521 IWL_DEBUG_MAC80211("leave\n");
2431 return 0; 2522 return 0;
2432
2433out_release_irq:
2434 free_irq(priv->pci_dev->irq, priv);
2435out_disable_msi:
2436 pci_disable_msi(priv->pci_dev);
2437 pci_disable_device(priv->pci_dev);
2438 priv->is_open = 0;
2439 IWL_DEBUG_MAC80211("leave - failed\n");
2440 return ret;
2441} 2523}
2442 2524
2443static void iwl_mac_stop(struct ieee80211_hw *hw) 2525static void iwl_mac_stop(struct ieee80211_hw *hw)
@@ -2465,10 +2547,10 @@ static void iwl_mac_stop(struct ieee80211_hw *hw)
2465 iwl_down(priv); 2547 iwl_down(priv);
2466 2548
2467 flush_workqueue(priv->workqueue); 2549 flush_workqueue(priv->workqueue);
2468 free_irq(priv->pci_dev->irq, priv); 2550
2469 pci_disable_msi(priv->pci_dev); 2551 /* enable interrupts again in order to receive rfkill changes */
2470 pci_save_state(priv->pci_dev); 2552 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2471 pci_disable_device(priv->pci_dev); 2553 iwl_enable_interrupts(priv);
2472 2554
2473 IWL_DEBUG_MAC80211("leave\n"); 2555 IWL_DEBUG_MAC80211("leave\n");
2474} 2556}
@@ -2544,7 +2626,7 @@ static int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2544 mutex_lock(&priv->mutex); 2626 mutex_lock(&priv->mutex);
2545 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value); 2627 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
2546 2628
2547 priv->current_ht_config.is_ht = conf->ht.enabled; 2629 priv->current_ht_config.is_ht = conf_is_ht(conf);
2548 2630
2549 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) { 2631 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
2550 IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n"); 2632 IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
@@ -2577,7 +2659,7 @@ static int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2577 2659
2578 if (priv->iw_mode == NL80211_IFTYPE_ADHOC && 2660 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
2579 !is_channel_ibss(ch_info)) { 2661 !is_channel_ibss(ch_info)) {
2580 IWL_ERROR("channel %d in band %d not IBSS channel\n", 2662 IWL_ERR(priv, "channel %d in band %d not IBSS channel\n",
2581 conf->channel->hw_value, conf->channel->band); 2663 conf->channel->hw_value, conf->channel->band);
2582 ret = -EINVAL; 2664 ret = -EINVAL;
2583 goto out; 2665 goto out;
@@ -2639,6 +2721,9 @@ static int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2639 2721
2640 iwl_set_rate(priv); 2722 iwl_set_rate(priv);
2641 2723
2724 /* call to ensure that 4965 rx_chain is set properly in monitor mode */
2725 iwl_set_rxon_chain(priv);
2726
2642 if (memcmp(&priv->active_rxon, 2727 if (memcmp(&priv->active_rxon,
2643 &priv->staging_rxon, sizeof(priv->staging_rxon))) 2728 &priv->staging_rxon, sizeof(priv->staging_rxon)))
2644 iwl_commit_rxon(priv); 2729 iwl_commit_rxon(priv);
@@ -2672,7 +2757,7 @@ static void iwl_config_ap(struct iwl_priv *priv)
2672 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, 2757 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
2673 sizeof(priv->rxon_timing), &priv->rxon_timing); 2758 sizeof(priv->rxon_timing), &priv->rxon_timing);
2674 if (ret) 2759 if (ret)
2675 IWL_WARNING("REPLY_RXON_TIMING failed - " 2760 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
2676 "Attempting to continue.\n"); 2761 "Attempting to continue.\n");
2677 2762
2678 iwl_set_rxon_chain(priv); 2763 iwl_set_rxon_chain(priv);
@@ -2778,7 +2863,7 @@ static int iwl_mac_config_interface(struct ieee80211_hw *hw,
2778 /* If there is currently a HW scan going on in the background 2863 /* If there is currently a HW scan going on in the background
2779 * then we need to cancel it else the RXON below will fail. */ 2864 * then we need to cancel it else the RXON below will fail. */
2780 if (iwl_scan_cancel_timeout(priv, 100)) { 2865 if (iwl_scan_cancel_timeout(priv, 100)) {
2781 IWL_WARNING("Aborted scan still in progress " 2866 IWL_WARN(priv, "Aborted scan still in progress "
2782 "after 100ms\n"); 2867 "after 100ms\n");
2783 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n"); 2868 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2784 mutex_unlock(&priv->mutex); 2869 mutex_unlock(&priv->mutex);
@@ -3019,13 +3104,15 @@ static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
3019} 3104}
3020 3105
3021static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd, 3106static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3022 const u8 *local_addr, const u8 *addr, 3107 struct ieee80211_vif *vif,
3108 struct ieee80211_sta *sta,
3023 struct ieee80211_key_conf *key) 3109 struct ieee80211_key_conf *key)
3024{ 3110{
3025 struct iwl_priv *priv = hw->priv; 3111 struct iwl_priv *priv = hw->priv;
3026 int ret = 0; 3112 const u8 *addr;
3027 u8 sta_id = IWL_INVALID_STATION; 3113 int ret;
3028 u8 is_default_wep_key = 0; 3114 u8 sta_id;
3115 bool is_default_wep_key = false;
3029 3116
3030 IWL_DEBUG_MAC80211("enter\n"); 3117 IWL_DEBUG_MAC80211("enter\n");
3031 3118
@@ -3033,11 +3120,7 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3033 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n"); 3120 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
3034 return -EOPNOTSUPP; 3121 return -EOPNOTSUPP;
3035 } 3122 }
3036 3123 addr = sta ? sta->addr : iwl_bcast_addr;
3037 if (is_zero_ether_addr(addr))
3038 /* only support pairwise keys */
3039 return -EOPNOTSUPP;
3040
3041 sta_id = iwl_find_station(priv, addr); 3124 sta_id = iwl_find_station(priv, addr);
3042 if (sta_id == IWL_INVALID_STATION) { 3125 if (sta_id == IWL_INVALID_STATION) {
3043 IWL_DEBUG_MAC80211("leave - %pM not in station map.\n", 3126 IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
@@ -3359,8 +3442,7 @@ static ssize_t store_debug_level(struct device *d,
3359 3442
3360 ret = strict_strtoul(buf, 0, &val); 3443 ret = strict_strtoul(buf, 0, &val);
3361 if (ret) 3444 if (ret)
3362 printk(KERN_INFO DRV_NAME 3445 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
3363 ": %s is not in hex or decimal form.\n", buf);
3364 else 3446 else
3365 priv->debug_level = val; 3447 priv->debug_level = val;
3366 3448
@@ -3439,8 +3521,7 @@ static ssize_t store_tx_power(struct device *d,
3439 3521
3440 ret = strict_strtoul(buf, 10, &val); 3522 ret = strict_strtoul(buf, 10, &val);
3441 if (ret) 3523 if (ret)
3442 printk(KERN_INFO DRV_NAME 3524 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
3443 ": %s is not in decimal form.\n", buf);
3444 else 3525 else
3445 iwl_set_tx_power(priv, val, false); 3526 iwl_set_tx_power(priv, val, false);
3446 3527
@@ -3473,7 +3554,7 @@ static ssize_t store_flags(struct device *d,
3473 if (le32_to_cpu(priv->staging_rxon.flags) != flags) { 3554 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
3474 /* Cancel any currently running scans... */ 3555 /* Cancel any currently running scans... */
3475 if (iwl_scan_cancel_timeout(priv, 100)) 3556 if (iwl_scan_cancel_timeout(priv, 100))
3476 IWL_WARNING("Could not cancel scan.\n"); 3557 IWL_WARN(priv, "Could not cancel scan.\n");
3477 else { 3558 else {
3478 IWL_DEBUG_INFO("Commit rxon.flags = 0x%04X\n", flags); 3559 IWL_DEBUG_INFO("Commit rxon.flags = 0x%04X\n", flags);
3479 priv->staging_rxon.flags = cpu_to_le32(flags); 3560 priv->staging_rxon.flags = cpu_to_le32(flags);
@@ -3512,7 +3593,7 @@ static ssize_t store_filter_flags(struct device *d,
3512 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { 3593 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
3513 /* Cancel any currently running scans... */ 3594 /* Cancel any currently running scans... */
3514 if (iwl_scan_cancel_timeout(priv, 100)) 3595 if (iwl_scan_cancel_timeout(priv, 100))
3515 IWL_WARNING("Could not cancel scan.\n"); 3596 IWL_WARN(priv, "Could not cancel scan.\n");
3516 else { 3597 else {
3517 IWL_DEBUG_INFO("Committing rxon.filter_flags = " 3598 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
3518 "0x%04X\n", filter_flags); 3599 "0x%04X\n", filter_flags);
@@ -3529,31 +3610,6 @@ static ssize_t store_filter_flags(struct device *d,
3529static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags, 3610static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3530 store_filter_flags); 3611 store_filter_flags);
3531 3612
3532static ssize_t store_retry_rate(struct device *d,
3533 struct device_attribute *attr,
3534 const char *buf, size_t count)
3535{
3536 struct iwl_priv *priv = dev_get_drvdata(d);
3537 long val;
3538 int ret = strict_strtol(buf, 10, &val);
3539 if (!ret)
3540 return ret;
3541
3542 priv->retry_rate = (val > 0) ? val : 1;
3543
3544 return count;
3545}
3546
3547static ssize_t show_retry_rate(struct device *d,
3548 struct device_attribute *attr, char *buf)
3549{
3550 struct iwl_priv *priv = dev_get_drvdata(d);
3551 return sprintf(buf, "%d", priv->retry_rate);
3552}
3553
3554static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
3555 store_retry_rate);
3556
3557static ssize_t store_power_level(struct device *d, 3613static ssize_t store_power_level(struct device *d,
3558 struct device_attribute *attr, 3614 struct device_attribute *attr,
3559 const char *buf, size_t count) 3615 const char *buf, size_t count)
@@ -3656,16 +3712,6 @@ static ssize_t show_statistics(struct device *d,
3656 3712
3657static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL); 3713static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
3658 3714
3659static ssize_t show_status(struct device *d,
3660 struct device_attribute *attr, char *buf)
3661{
3662 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
3663 if (!iwl_is_alive(priv))
3664 return -EAGAIN;
3665 return sprintf(buf, "0x%08x\n", (int)priv->status);
3666}
3667
3668static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3669 3715
3670/***************************************************************************** 3716/*****************************************************************************
3671 * 3717 *
@@ -3719,9 +3765,7 @@ static struct attribute *iwl_sysfs_entries[] = {
3719 &dev_attr_flags.attr, 3765 &dev_attr_flags.attr,
3720 &dev_attr_filter_flags.attr, 3766 &dev_attr_filter_flags.attr,
3721 &dev_attr_power_level.attr, 3767 &dev_attr_power_level.attr,
3722 &dev_attr_retry_rate.attr,
3723 &dev_attr_statistics.attr, 3768 &dev_attr_statistics.attr,
3724 &dev_attr_status.attr,
3725 &dev_attr_temperature.attr, 3769 &dev_attr_temperature.attr,
3726 &dev_attr_tx_power.attr, 3770 &dev_attr_tx_power.attr,
3727#ifdef CONFIG_IWLWIFI_DEBUG 3771#ifdef CONFIG_IWLWIFI_DEBUG
@@ -3764,6 +3808,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3764 struct ieee80211_hw *hw; 3808 struct ieee80211_hw *hw;
3765 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); 3809 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
3766 unsigned long flags; 3810 unsigned long flags;
3811 u16 pci_cmd;
3767 3812
3768 /************************ 3813 /************************
3769 * 1. Allocating HW data 3814 * 1. Allocating HW data
@@ -3816,8 +3861,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3816 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); 3861 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
3817 /* both attempts failed: */ 3862 /* both attempts failed: */
3818 if (err) { 3863 if (err) {
3819 printk(KERN_WARNING "%s: No suitable DMA available.\n", 3864 IWL_WARN(priv, "No suitable DMA available.\n");
3820 DRV_NAME);
3821 goto out_pci_disable_device; 3865 goto out_pci_disable_device;
3822 } 3866 }
3823 } 3867 }
@@ -3843,8 +3887,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3843 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base); 3887 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
3844 3888
3845 iwl_hw_detect(priv); 3889 iwl_hw_detect(priv);
3846 printk(KERN_INFO DRV_NAME 3890 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s REV=0x%X\n",
3847 ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
3848 priv->cfg->name, priv->hw_rev); 3891 priv->cfg->name, priv->hw_rev);
3849 3892
3850 /* We disable the RETRY_TIMEOUT register (0x41) to keep 3893 /* We disable the RETRY_TIMEOUT register (0x41) to keep
@@ -3863,7 +3906,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3863 /* Read the EEPROM */ 3906 /* Read the EEPROM */
3864 err = iwl_eeprom_init(priv); 3907 err = iwl_eeprom_init(priv);
3865 if (err) { 3908 if (err) {
3866 IWL_ERROR("Unable to init EEPROM\n"); 3909 IWL_ERR(priv, "Unable to init EEPROM\n");
3867 goto out_iounmap; 3910 goto out_iounmap;
3868 } 3911 }
3869 err = iwl_eeprom_check_version(priv); 3912 err = iwl_eeprom_check_version(priv);
@@ -3879,7 +3922,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3879 * 5. Setup HW constants 3922 * 5. Setup HW constants
3880 ************************/ 3923 ************************/
3881 if (iwl_set_hw_params(priv)) { 3924 if (iwl_set_hw_params(priv)) {
3882 IWL_ERROR("failed to set hw parameters\n"); 3925 IWL_ERR(priv, "failed to set hw parameters\n");
3883 goto out_free_eeprom; 3926 goto out_free_eeprom;
3884 } 3927 }
3885 3928
@@ -3909,43 +3952,65 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3909 iwl_disable_interrupts(priv); 3952 iwl_disable_interrupts(priv);
3910 spin_unlock_irqrestore(&priv->lock, flags); 3953 spin_unlock_irqrestore(&priv->lock, flags);
3911 3954
3955 pci_enable_msi(priv->pci_dev);
3956
3957 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
3958 DRV_NAME, priv);
3959 if (err) {
3960 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
3961 goto out_disable_msi;
3962 }
3912 err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group); 3963 err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group);
3913 if (err) { 3964 if (err) {
3914 IWL_ERROR("failed to create sysfs device attributes\n"); 3965 IWL_ERR(priv, "failed to create sysfs device attributes\n");
3915 goto out_uninit_drv; 3966 goto out_uninit_drv;
3916 } 3967 }
3917 3968
3918
3919 iwl_setup_deferred_work(priv); 3969 iwl_setup_deferred_work(priv);
3920 iwl_setup_rx_handlers(priv); 3970 iwl_setup_rx_handlers(priv);
3921 3971
3922 /********************
3923 * 9. Conclude
3924 ********************/
3925 pci_save_state(pdev);
3926 pci_disable_device(pdev);
3927
3928 /********************************** 3972 /**********************************
3929 * 10. Setup and register mac80211 3973 * 9. Setup and register mac80211
3930 **********************************/ 3974 **********************************/
3931 3975
3976 /* enable interrupts if needed: hw bug w/a */
3977 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
3978 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
3979 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
3980 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
3981 }
3982
3983 iwl_enable_interrupts(priv);
3984
3932 err = iwl_setup_mac(priv); 3985 err = iwl_setup_mac(priv);
3933 if (err) 3986 if (err)
3934 goto out_remove_sysfs; 3987 goto out_remove_sysfs;
3935 3988
3936 err = iwl_dbgfs_register(priv, DRV_NAME); 3989 err = iwl_dbgfs_register(priv, DRV_NAME);
3937 if (err) 3990 if (err)
3938 IWL_ERROR("failed to create debugfs files\n"); 3991 IWL_ERR(priv, "failed to create debugfs files\n");
3992
3993 /* If platform's RF_KILL switch is NOT set to KILL */
3994 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3995 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3996 else
3997 set_bit(STATUS_RF_KILL_HW, &priv->status);
3939 3998
3940 err = iwl_rfkill_init(priv); 3999 err = iwl_rfkill_init(priv);
3941 if (err) 4000 if (err)
3942 IWL_ERROR("Unable to initialize RFKILL system. " 4001 IWL_ERR(priv, "Unable to initialize RFKILL system. "
3943 "Ignoring error: %d\n", err); 4002 "Ignoring error: %d\n", err);
4003 else
4004 iwl_rfkill_set_hw_state(priv);
4005
3944 iwl_power_initialize(priv); 4006 iwl_power_initialize(priv);
3945 return 0; 4007 return 0;
3946 4008
3947 out_remove_sysfs: 4009 out_remove_sysfs:
3948 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group); 4010 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
4011 out_disable_msi:
4012 pci_disable_msi(priv->pci_dev);
4013 pci_disable_device(priv->pci_dev);
3949 out_uninit_drv: 4014 out_uninit_drv:
3950 iwl_uninit_drv(priv); 4015 iwl_uninit_drv(priv);
3951 out_free_eeprom: 4016 out_free_eeprom:
@@ -4017,6 +4082,8 @@ static void __devexit iwl_pci_remove(struct pci_dev *pdev)
4017 destroy_workqueue(priv->workqueue); 4082 destroy_workqueue(priv->workqueue);
4018 priv->workqueue = NULL; 4083 priv->workqueue = NULL;
4019 4084
4085 free_irq(priv->pci_dev->irq, priv);
4086 pci_disable_msi(priv->pci_dev);
4020 pci_iounmap(pdev, priv->hw_base); 4087 pci_iounmap(pdev, priv->hw_base);
4021 pci_release_regions(pdev); 4088 pci_release_regions(pdev);
4022 pci_disable_device(pdev); 4089 pci_disable_device(pdev);
@@ -4042,6 +4109,8 @@ static int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
4042 priv->is_open = 1; 4109 priv->is_open = 1;
4043 } 4110 }
4044 4111
4112 pci_save_state(pdev);
4113 pci_disable_device(pdev);
4045 pci_set_power_state(pdev, PCI_D3hot); 4114 pci_set_power_state(pdev, PCI_D3hot);
4046 4115
4047 return 0; 4116 return 0;
@@ -4052,6 +4121,9 @@ static int iwl_pci_resume(struct pci_dev *pdev)
4052 struct iwl_priv *priv = pci_get_drvdata(pdev); 4121 struct iwl_priv *priv = pci_get_drvdata(pdev);
4053 4122
4054 pci_set_power_state(pdev, PCI_D0); 4123 pci_set_power_state(pdev, PCI_D0);
4124 pci_enable_device(pdev);
4125 pci_restore_state(pdev);
4126 iwl_enable_interrupts(priv);
4055 4127
4056 if (priv->is_open) 4128 if (priv->is_open)
4057 iwl_mac_start(priv->hw); 4129 iwl_mac_start(priv->hw);
@@ -4092,6 +4164,21 @@ static struct pci_device_id iwl_hw_card_ids[] = {
4092/* 5150 Wifi/WiMax */ 4164/* 5150 Wifi/WiMax */
4093 {IWL_PCI_DEVICE(0x423C, PCI_ANY_ID, iwl5150_agn_cfg)}, 4165 {IWL_PCI_DEVICE(0x423C, PCI_ANY_ID, iwl5150_agn_cfg)},
4094 {IWL_PCI_DEVICE(0x423D, PCI_ANY_ID, iwl5150_agn_cfg)}, 4166 {IWL_PCI_DEVICE(0x423D, PCI_ANY_ID, iwl5150_agn_cfg)},
4167/* 6000/6050 Series */
4168 {IWL_PCI_DEVICE(0x0082, 0x1102, iwl6000_2ag_cfg)},
4169 {IWL_PCI_DEVICE(0x0085, 0x1112, iwl6000_2ag_cfg)},
4170 {IWL_PCI_DEVICE(0x0082, 0x1122, iwl6000_2ag_cfg)},
4171 {IWL_PCI_DEVICE(0x422B, PCI_ANY_ID, iwl6000_3agn_cfg)},
4172 {IWL_PCI_DEVICE(0x4238, PCI_ANY_ID, iwl6000_3agn_cfg)},
4173 {IWL_PCI_DEVICE(0x0082, PCI_ANY_ID, iwl6000_2agn_cfg)},
4174 {IWL_PCI_DEVICE(0x0085, PCI_ANY_ID, iwl6000_3agn_cfg)},
4175 {IWL_PCI_DEVICE(0x0086, PCI_ANY_ID, iwl6050_3agn_cfg)},
4176 {IWL_PCI_DEVICE(0x0087, PCI_ANY_ID, iwl6050_2agn_cfg)},
4177 {IWL_PCI_DEVICE(0x0088, PCI_ANY_ID, iwl6050_3agn_cfg)},
4178 {IWL_PCI_DEVICE(0x0089, PCI_ANY_ID, iwl6050_2agn_cfg)},
4179/* 100 Series WiFi */
4180 {IWL_PCI_DEVICE(0x0083, PCI_ANY_ID, iwl100_bgn_cfg)},
4181 {IWL_PCI_DEVICE(0x0084, PCI_ANY_ID, iwl100_bgn_cfg)},
4095#endif /* CONFIG_IWL5000 */ 4182#endif /* CONFIG_IWL5000 */
4096 4183
4097 {0} 4184 {0}
@@ -4118,13 +4205,14 @@ static int __init iwl_init(void)
4118 4205
4119 ret = iwlagn_rate_control_register(); 4206 ret = iwlagn_rate_control_register();
4120 if (ret) { 4207 if (ret) {
4121 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret); 4208 printk(KERN_ERR DRV_NAME
4209 "Unable to register rate control algorithm: %d\n", ret);
4122 return ret; 4210 return ret;
4123 } 4211 }
4124 4212
4125 ret = pci_register_driver(&iwl_driver); 4213 ret = pci_register_driver(&iwl_driver);
4126 if (ret) { 4214 if (ret) {
4127 IWL_ERROR("Unable to initialize PCI module\n"); 4215 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
4128 goto error_register; 4216 goto error_register;
4129 } 4217 }
4130 4218