Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6/linux-2.6-openrd.git] / drivers / net / wireless / iwlwifi / iwl-agn.c
blobeaafae091f5bd48bfc3eec8d323e2a210864c54a
1 /******************************************************************************
3 * Copyright(c) 2003 - 2009 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
15 * more details.
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/pci.h>
34 #include <linux/dma-mapping.h>
35 #include <linux/delay.h>
36 #include <linux/sched.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 #define DRV_NAME "iwlagn"
50 #include "iwl-eeprom.h"
51 #include "iwl-dev.h"
52 #include "iwl-core.h"
53 #include "iwl-io.h"
54 #include "iwl-helpers.h"
55 #include "iwl-sta.h"
56 #include "iwl-calib.h"
59 /******************************************************************************
61 * module boiler plate
63 ******************************************************************************/
66 * module name, copyright, version, etc.
68 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
70 #ifdef CONFIG_IWLWIFI_DEBUG
71 #define VD "d"
72 #else
73 #define VD
74 #endif
76 #ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT
77 #define VS "s"
78 #else
79 #define VS
80 #endif
82 #define DRV_VERSION IWLWIFI_VERSION VD VS
85 MODULE_DESCRIPTION(DRV_DESCRIPTION);
86 MODULE_VERSION(DRV_VERSION);
87 MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
88 MODULE_LICENSE("GPL");
89 MODULE_ALIAS("iwl4965");
91 /*************** STATION TABLE MANAGEMENT ****
92 * mac80211 should be examined to determine if sta_info is duplicating
93 * the functionality provided here
96 /**************************************************************/
98 /**
99 * iwl_commit_rxon - commit staging_rxon to hardware
101 * The RXON command in staging_rxon is committed to the hardware and
102 * the active_rxon structure is updated with the new data. This
103 * function correctly transitions out of the RXON_ASSOC_MSK state if
104 * a HW tune is required based on the RXON structure changes.
106 int iwl_commit_rxon(struct iwl_priv *priv)
108 /* cast away the const for active_rxon in this function */
109 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
110 int ret;
111 bool new_assoc =
112 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
114 if (!iwl_is_alive(priv))
115 return -EBUSY;
117 /* always get timestamp with Rx frame */
118 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
119 /* allow CTS-to-self if possible. this is relevant only for
120 * 5000, but will not damage 4965 */
121 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
123 ret = iwl_check_rxon_cmd(priv);
124 if (ret) {
125 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
126 return -EINVAL;
129 /* If we don't need to send a full RXON, we can use
130 * iwl_rxon_assoc_cmd which is used to reconfigure filter
131 * and other flags for the current radio configuration. */
132 if (!iwl_full_rxon_required(priv)) {
133 ret = iwl_send_rxon_assoc(priv);
134 if (ret) {
135 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
136 return ret;
139 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
140 return 0;
143 /* station table will be cleared */
144 priv->assoc_station_added = 0;
146 /* If we are currently associated and the new config requires
147 * an RXON_ASSOC and the new config wants the associated mask enabled,
148 * we must clear the associated from the active configuration
149 * before we apply the new config */
150 if (iwl_is_associated(priv) && new_assoc) {
151 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
152 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
154 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
155 sizeof(struct iwl_rxon_cmd),
156 &priv->active_rxon);
158 /* If the mask clearing failed then we set
159 * active_rxon back to what it was previously */
160 if (ret) {
161 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
162 IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
163 return ret;
167 IWL_DEBUG_INFO(priv, "Sending RXON\n"
168 "* with%s RXON_FILTER_ASSOC_MSK\n"
169 "* channel = %d\n"
170 "* bssid = %pM\n",
171 (new_assoc ? "" : "out"),
172 le16_to_cpu(priv->staging_rxon.channel),
173 priv->staging_rxon.bssid_addr);
175 iwl_set_rxon_hwcrypto(priv, !priv->cfg->mod_params->sw_crypto);
177 /* Apply the new configuration
178 * RXON unassoc clears the station table in uCode, send it before
179 * we add the bcast station. If assoc bit is set, we will send RXON
180 * after having added the bcast and bssid station.
182 if (!new_assoc) {
183 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
184 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
185 if (ret) {
186 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
187 return ret;
189 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
192 iwl_clear_stations_table(priv);
194 priv->start_calib = 0;
196 /* Add the broadcast address so we can send broadcast frames */
197 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
198 IWL_INVALID_STATION) {
199 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
200 return -EIO;
203 /* If we have set the ASSOC_MSK and we are in BSS mode then
204 * add the IWL_AP_ID to the station rate table */
205 if (new_assoc) {
206 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
207 ret = iwl_rxon_add_station(priv,
208 priv->active_rxon.bssid_addr, 1);
209 if (ret == IWL_INVALID_STATION) {
210 IWL_ERR(priv,
211 "Error adding AP address for TX.\n");
212 return -EIO;
214 priv->assoc_station_added = 1;
215 if (priv->default_wep_key &&
216 iwl_send_static_wepkey_cmd(priv, 0))
217 IWL_ERR(priv,
218 "Could not send WEP static key.\n");
221 /* Apply the new configuration
222 * RXON assoc doesn't clear the station table in uCode,
224 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
225 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
226 if (ret) {
227 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
228 return ret;
230 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
233 iwl_init_sensitivity(priv);
235 /* If we issue a new RXON command which required a tune then we must
236 * send a new TXPOWER command or we won't be able to Tx any frames */
237 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
238 if (ret) {
239 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
240 return ret;
243 return 0;
246 void iwl_update_chain_flags(struct iwl_priv *priv)
249 if (priv->cfg->ops->hcmd->set_rxon_chain)
250 priv->cfg->ops->hcmd->set_rxon_chain(priv);
251 iwlcore_commit_rxon(priv);
254 static void iwl_clear_free_frames(struct iwl_priv *priv)
256 struct list_head *element;
258 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
259 priv->frames_count);
261 while (!list_empty(&priv->free_frames)) {
262 element = priv->free_frames.next;
263 list_del(element);
264 kfree(list_entry(element, struct iwl_frame, list));
265 priv->frames_count--;
268 if (priv->frames_count) {
269 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
270 priv->frames_count);
271 priv->frames_count = 0;
275 static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
277 struct iwl_frame *frame;
278 struct list_head *element;
279 if (list_empty(&priv->free_frames)) {
280 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
281 if (!frame) {
282 IWL_ERR(priv, "Could not allocate frame!\n");
283 return NULL;
286 priv->frames_count++;
287 return frame;
290 element = priv->free_frames.next;
291 list_del(element);
292 return list_entry(element, struct iwl_frame, list);
295 static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
297 memset(frame, 0, sizeof(*frame));
298 list_add(&frame->list, &priv->free_frames);
301 static unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv,
302 struct ieee80211_hdr *hdr,
303 int left)
305 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
306 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
307 (priv->iw_mode != NL80211_IFTYPE_AP)))
308 return 0;
310 if (priv->ibss_beacon->len > left)
311 return 0;
313 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
315 return priv->ibss_beacon->len;
318 static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
319 struct iwl_frame *frame, u8 rate)
321 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
322 unsigned int frame_size;
324 tx_beacon_cmd = &frame->u.beacon;
325 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
327 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
328 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
330 frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
331 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
333 BUG_ON(frame_size > MAX_MPDU_SIZE);
334 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
336 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
337 tx_beacon_cmd->tx.rate_n_flags =
338 iwl_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
339 else
340 tx_beacon_cmd->tx.rate_n_flags =
341 iwl_hw_set_rate_n_flags(rate, 0);
343 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
344 TX_CMD_FLG_TSF_MSK |
345 TX_CMD_FLG_STA_RATE_MSK;
347 return sizeof(*tx_beacon_cmd) + frame_size;
349 static int iwl_send_beacon_cmd(struct iwl_priv *priv)
351 struct iwl_frame *frame;
352 unsigned int frame_size;
353 int rc;
354 u8 rate;
356 frame = iwl_get_free_frame(priv);
358 if (!frame) {
359 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
360 "command.\n");
361 return -ENOMEM;
364 rate = iwl_rate_get_lowest_plcp(priv);
366 frame_size = iwl_hw_get_beacon_cmd(priv, frame, rate);
368 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
369 &frame->u.cmd[0]);
371 iwl_free_frame(priv, frame);
373 return rc;
376 static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
378 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
380 dma_addr_t addr = get_unaligned_le32(&tb->lo);
381 if (sizeof(dma_addr_t) > sizeof(u32))
382 addr |=
383 ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
385 return addr;
388 static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
390 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
392 return le16_to_cpu(tb->hi_n_len) >> 4;
395 static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
396 dma_addr_t addr, u16 len)
398 struct iwl_tfd_tb *tb = &tfd->tbs[idx];
399 u16 hi_n_len = len << 4;
401 put_unaligned_le32(addr, &tb->lo);
402 if (sizeof(dma_addr_t) > sizeof(u32))
403 hi_n_len |= ((addr >> 16) >> 16) & 0xF;
405 tb->hi_n_len = cpu_to_le16(hi_n_len);
407 tfd->num_tbs = idx + 1;
410 static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
412 return tfd->num_tbs & 0x1f;
416 * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
417 * @priv - driver private data
418 * @txq - tx queue
420 * Does NOT advance any TFD circular buffer read/write indexes
421 * Does NOT free the TFD itself (which is within circular buffer)
423 void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
425 struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
426 struct iwl_tfd *tfd;
427 struct pci_dev *dev = priv->pci_dev;
428 int index = txq->q.read_ptr;
429 int i;
430 int num_tbs;
432 tfd = &tfd_tmp[index];
434 /* Sanity check on number of chunks */
435 num_tbs = iwl_tfd_get_num_tbs(tfd);
437 if (num_tbs >= IWL_NUM_OF_TBS) {
438 IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
439 /* @todo issue fatal error, it is quite serious situation */
440 return;
443 /* Unmap tx_cmd */
444 if (num_tbs)
445 pci_unmap_single(dev,
446 pci_unmap_addr(&txq->meta[index], mapping),
447 pci_unmap_len(&txq->meta[index], len),
448 PCI_DMA_BIDIRECTIONAL);
450 /* Unmap chunks, if any. */
451 for (i = 1; i < num_tbs; i++) {
452 pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
453 iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
455 if (txq->txb) {
456 dev_kfree_skb(txq->txb[txq->q.read_ptr].skb[i - 1]);
457 txq->txb[txq->q.read_ptr].skb[i - 1] = NULL;
462 int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
463 struct iwl_tx_queue *txq,
464 dma_addr_t addr, u16 len,
465 u8 reset, u8 pad)
467 struct iwl_queue *q;
468 struct iwl_tfd *tfd, *tfd_tmp;
469 u32 num_tbs;
471 q = &txq->q;
472 tfd_tmp = (struct iwl_tfd *)txq->tfds;
473 tfd = &tfd_tmp[q->write_ptr];
475 if (reset)
476 memset(tfd, 0, sizeof(*tfd));
478 num_tbs = iwl_tfd_get_num_tbs(tfd);
480 /* Each TFD can point to a maximum 20 Tx buffers */
481 if (num_tbs >= IWL_NUM_OF_TBS) {
482 IWL_ERR(priv, "Error can not send more than %d chunks\n",
483 IWL_NUM_OF_TBS);
484 return -EINVAL;
487 BUG_ON(addr & ~DMA_BIT_MASK(36));
488 if (unlikely(addr & ~IWL_TX_DMA_MASK))
489 IWL_ERR(priv, "Unaligned address = %llx\n",
490 (unsigned long long)addr);
492 iwl_tfd_set_tb(tfd, num_tbs, addr, len);
494 return 0;
498 * Tell nic where to find circular buffer of Tx Frame Descriptors for
499 * given Tx queue, and enable the DMA channel used for that queue.
501 * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
502 * channels supported in hardware.
504 int iwl_hw_tx_queue_init(struct iwl_priv *priv,
505 struct iwl_tx_queue *txq)
507 int txq_id = txq->q.id;
509 /* Circular buffer (TFD queue in DRAM) physical base address */
510 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
511 txq->q.dma_addr >> 8);
513 return 0;
516 /******************************************************************************
518 * Generic RX handler implementations
520 ******************************************************************************/
521 static void iwl_rx_reply_alive(struct iwl_priv *priv,
522 struct iwl_rx_mem_buffer *rxb)
524 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
525 struct iwl_alive_resp *palive;
526 struct delayed_work *pwork;
528 palive = &pkt->u.alive_frame;
530 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
531 "0x%01X 0x%01X\n",
532 palive->is_valid, palive->ver_type,
533 palive->ver_subtype);
535 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
536 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
537 memcpy(&priv->card_alive_init,
538 &pkt->u.alive_frame,
539 sizeof(struct iwl_init_alive_resp));
540 pwork = &priv->init_alive_start;
541 } else {
542 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
543 memcpy(&priv->card_alive, &pkt->u.alive_frame,
544 sizeof(struct iwl_alive_resp));
545 pwork = &priv->alive_start;
548 /* We delay the ALIVE response by 5ms to
549 * give the HW RF Kill time to activate... */
550 if (palive->is_valid == UCODE_VALID_OK)
551 queue_delayed_work(priv->workqueue, pwork,
552 msecs_to_jiffies(5));
553 else
554 IWL_WARN(priv, "uCode did not respond OK.\n");
557 static void iwl_bg_beacon_update(struct work_struct *work)
559 struct iwl_priv *priv =
560 container_of(work, struct iwl_priv, beacon_update);
561 struct sk_buff *beacon;
563 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
564 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
566 if (!beacon) {
567 IWL_ERR(priv, "update beacon failed\n");
568 return;
571 mutex_lock(&priv->mutex);
572 /* new beacon skb is allocated every time; dispose previous.*/
573 if (priv->ibss_beacon)
574 dev_kfree_skb(priv->ibss_beacon);
576 priv->ibss_beacon = beacon;
577 mutex_unlock(&priv->mutex);
579 iwl_send_beacon_cmd(priv);
583 * iwl_bg_statistics_periodic - Timer callback to queue statistics
585 * This callback is provided in order to send a statistics request.
587 * This timer function is continually reset to execute within
588 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
589 * was received. We need to ensure we receive the statistics in order
590 * to update the temperature used for calibrating the TXPOWER.
592 static void iwl_bg_statistics_periodic(unsigned long data)
594 struct iwl_priv *priv = (struct iwl_priv *)data;
596 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
597 return;
599 /* dont send host command if rf-kill is on */
600 if (!iwl_is_ready_rf(priv))
601 return;
603 iwl_send_statistics_request(priv, CMD_ASYNC);
606 static void iwl_rx_beacon_notif(struct iwl_priv *priv,
607 struct iwl_rx_mem_buffer *rxb)
609 #ifdef CONFIG_IWLWIFI_DEBUG
610 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
611 struct iwl4965_beacon_notif *beacon =
612 (struct iwl4965_beacon_notif *)pkt->u.raw;
613 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
615 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
616 "tsf %d %d rate %d\n",
617 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
618 beacon->beacon_notify_hdr.failure_frame,
619 le32_to_cpu(beacon->ibss_mgr_status),
620 le32_to_cpu(beacon->high_tsf),
621 le32_to_cpu(beacon->low_tsf), rate);
622 #endif
624 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
625 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
626 queue_work(priv->workqueue, &priv->beacon_update);
629 /* Handle notification from uCode that card's power state is changing
630 * due to software, hardware, or critical temperature RFKILL */
631 static void iwl_rx_card_state_notif(struct iwl_priv *priv,
632 struct iwl_rx_mem_buffer *rxb)
634 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
635 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
636 unsigned long status = priv->status;
638 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
639 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
640 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
642 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
643 RF_CARD_DISABLED)) {
645 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
646 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
648 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
649 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
651 if (!(flags & RXON_CARD_DISABLED)) {
652 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
653 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
654 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
655 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
657 if (flags & RF_CARD_DISABLED)
658 iwl_tt_enter_ct_kill(priv);
660 if (!(flags & RF_CARD_DISABLED))
661 iwl_tt_exit_ct_kill(priv);
663 if (flags & HW_CARD_DISABLED)
664 set_bit(STATUS_RF_KILL_HW, &priv->status);
665 else
666 clear_bit(STATUS_RF_KILL_HW, &priv->status);
669 if (!(flags & RXON_CARD_DISABLED))
670 iwl_scan_cancel(priv);
672 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
673 test_bit(STATUS_RF_KILL_HW, &priv->status)))
674 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
675 test_bit(STATUS_RF_KILL_HW, &priv->status));
676 else
677 wake_up_interruptible(&priv->wait_command_queue);
680 int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
682 if (src == IWL_PWR_SRC_VAUX) {
683 if (pci_pme_capable(priv->pci_dev, PCI_D3cold))
684 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
685 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
686 ~APMG_PS_CTRL_MSK_PWR_SRC);
687 } else {
688 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
689 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
690 ~APMG_PS_CTRL_MSK_PWR_SRC);
693 return 0;
697 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
699 * Setup the RX handlers for each of the reply types sent from the uCode
700 * to the host.
702 * This function chains into the hardware specific files for them to setup
703 * any hardware specific handlers as well.
705 static void iwl_setup_rx_handlers(struct iwl_priv *priv)
707 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
708 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
709 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
710 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
711 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
712 iwl_rx_pm_debug_statistics_notif;
713 priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
716 * The same handler is used for both the REPLY to a discrete
717 * statistics request from the host as well as for the periodic
718 * statistics notifications (after received beacons) from the uCode.
720 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
721 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
723 iwl_setup_spectrum_handlers(priv);
724 iwl_setup_rx_scan_handlers(priv);
726 /* status change handler */
727 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
729 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
730 iwl_rx_missed_beacon_notif;
731 /* Rx handlers */
732 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
733 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
734 /* block ack */
735 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
736 /* Set up hardware specific Rx handlers */
737 priv->cfg->ops->lib->rx_handler_setup(priv);
741 * iwl_rx_handle - Main entry function for receiving responses from uCode
743 * Uses the priv->rx_handlers callback function array to invoke
744 * the appropriate handlers, including command responses,
745 * frame-received notifications, and other notifications.
747 void iwl_rx_handle(struct iwl_priv *priv)
749 struct iwl_rx_mem_buffer *rxb;
750 struct iwl_rx_packet *pkt;
751 struct iwl_rx_queue *rxq = &priv->rxq;
752 u32 r, i;
753 int reclaim;
754 unsigned long flags;
755 u8 fill_rx = 0;
756 u32 count = 8;
757 int total_empty;
759 /* uCode's read index (stored in shared DRAM) indicates the last Rx
760 * buffer that the driver may process (last buffer filled by ucode). */
761 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
762 i = rxq->read;
764 /* Rx interrupt, but nothing sent from uCode */
765 if (i == r)
766 IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
768 /* calculate total frames need to be restock after handling RX */
769 total_empty = r - priv->rxq.write_actual;
770 if (total_empty < 0)
771 total_empty += RX_QUEUE_SIZE;
773 if (total_empty > (RX_QUEUE_SIZE / 2))
774 fill_rx = 1;
776 while (i != r) {
777 rxb = rxq->queue[i];
779 /* If an RXB doesn't have a Rx queue slot associated with it,
780 * then a bug has been introduced in the queue refilling
781 * routines -- catch it here */
782 BUG_ON(rxb == NULL);
784 rxq->queue[i] = NULL;
786 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
787 priv->hw_params.rx_buf_size + 256,
788 PCI_DMA_FROMDEVICE);
789 pkt = (struct iwl_rx_packet *)rxb->skb->data;
791 /* Reclaim a command buffer only if this packet is a response
792 * to a (driver-originated) command.
793 * If the packet (e.g. Rx frame) originated from uCode,
794 * there is no command buffer to reclaim.
795 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
796 * but apparently a few don't get set; catch them here. */
797 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
798 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
799 (pkt->hdr.cmd != REPLY_RX) &&
800 (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
801 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
802 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
803 (pkt->hdr.cmd != REPLY_TX);
805 /* Based on type of command response or notification,
806 * handle those that need handling via function in
807 * rx_handlers table. See iwl_setup_rx_handlers() */
808 if (priv->rx_handlers[pkt->hdr.cmd]) {
809 IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
810 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
811 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
812 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
813 } else {
814 /* No handling needed */
815 IWL_DEBUG_RX(priv,
816 "r %d i %d No handler needed for %s, 0x%02x\n",
817 r, i, get_cmd_string(pkt->hdr.cmd),
818 pkt->hdr.cmd);
821 if (reclaim) {
822 /* Invoke any callbacks, transfer the skb to caller, and
823 * fire off the (possibly) blocking iwl_send_cmd()
824 * as we reclaim the driver command queue */
825 if (rxb && rxb->skb)
826 iwl_tx_cmd_complete(priv, rxb);
827 else
828 IWL_WARN(priv, "Claim null rxb?\n");
831 /* For now we just don't re-use anything. We can tweak this
832 * later to try and re-use notification packets and SKBs that
833 * fail to Rx correctly */
834 if (rxb->skb != NULL) {
835 priv->alloc_rxb_skb--;
836 dev_kfree_skb_any(rxb->skb);
837 rxb->skb = NULL;
840 spin_lock_irqsave(&rxq->lock, flags);
841 list_add_tail(&rxb->list, &priv->rxq.rx_used);
842 spin_unlock_irqrestore(&rxq->lock, flags);
843 i = (i + 1) & RX_QUEUE_MASK;
844 /* If there are a lot of unused frames,
845 * restock the Rx queue so ucode wont assert. */
846 if (fill_rx) {
847 count++;
848 if (count >= 8) {
849 priv->rxq.read = i;
850 iwl_rx_replenish_now(priv);
851 count = 0;
856 /* Backtrack one entry */
857 priv->rxq.read = i;
858 if (fill_rx)
859 iwl_rx_replenish_now(priv);
860 else
861 iwl_rx_queue_restock(priv);
864 /* call this function to flush any scheduled tasklet */
865 static inline void iwl_synchronize_irq(struct iwl_priv *priv)
867 /* wait to make sure we flush pending tasklet*/
868 synchronize_irq(priv->pci_dev->irq);
869 tasklet_kill(&priv->irq_tasklet);
872 static void iwl_irq_tasklet_legacy(struct iwl_priv *priv)
874 u32 inta, handled = 0;
875 u32 inta_fh;
876 unsigned long flags;
877 #ifdef CONFIG_IWLWIFI_DEBUG
878 u32 inta_mask;
879 #endif
881 spin_lock_irqsave(&priv->lock, flags);
883 /* Ack/clear/reset pending uCode interrupts.
884 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
885 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
886 inta = iwl_read32(priv, CSR_INT);
887 iwl_write32(priv, CSR_INT, inta);
889 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
890 * Any new interrupts that happen after this, either while we're
891 * in this tasklet, or later, will show up in next ISR/tasklet. */
892 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
893 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
895 #ifdef CONFIG_IWLWIFI_DEBUG
896 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
897 /* just for debug */
898 inta_mask = iwl_read32(priv, CSR_INT_MASK);
899 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
900 inta, inta_mask, inta_fh);
902 #endif
904 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
905 * atomic, make sure that inta covers all the interrupts that
906 * we've discovered, even if FH interrupt came in just after
907 * reading CSR_INT. */
908 if (inta_fh & CSR49_FH_INT_RX_MASK)
909 inta |= CSR_INT_BIT_FH_RX;
910 if (inta_fh & CSR49_FH_INT_TX_MASK)
911 inta |= CSR_INT_BIT_FH_TX;
913 /* Now service all interrupt bits discovered above. */
914 if (inta & CSR_INT_BIT_HW_ERR) {
915 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
917 /* Tell the device to stop sending interrupts */
918 iwl_disable_interrupts(priv);
920 priv->isr_stats.hw++;
921 iwl_irq_handle_error(priv);
923 handled |= CSR_INT_BIT_HW_ERR;
925 spin_unlock_irqrestore(&priv->lock, flags);
927 return;
930 #ifdef CONFIG_IWLWIFI_DEBUG
931 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
932 /* NIC fires this, but we don't use it, redundant with WAKEUP */
933 if (inta & CSR_INT_BIT_SCD) {
934 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
935 "the frame/frames.\n");
936 priv->isr_stats.sch++;
939 /* Alive notification via Rx interrupt will do the real work */
940 if (inta & CSR_INT_BIT_ALIVE) {
941 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
942 priv->isr_stats.alive++;
945 #endif
946 /* Safely ignore these bits for debug checks below */
947 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
949 /* HW RF KILL switch toggled */
950 if (inta & CSR_INT_BIT_RF_KILL) {
951 int hw_rf_kill = 0;
952 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
953 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
954 hw_rf_kill = 1;
956 IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
957 hw_rf_kill ? "disable radio" : "enable radio");
959 priv->isr_stats.rfkill++;
961 /* driver only loads ucode once setting the interface up.
962 * the driver allows loading the ucode even if the radio
963 * is killed. Hence update the killswitch state here. The
964 * rfkill handler will care about restarting if needed.
966 if (!test_bit(STATUS_ALIVE, &priv->status)) {
967 if (hw_rf_kill)
968 set_bit(STATUS_RF_KILL_HW, &priv->status);
969 else
970 clear_bit(STATUS_RF_KILL_HW, &priv->status);
971 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
974 handled |= CSR_INT_BIT_RF_KILL;
977 /* Chip got too hot and stopped itself */
978 if (inta & CSR_INT_BIT_CT_KILL) {
979 IWL_ERR(priv, "Microcode CT kill error detected.\n");
980 priv->isr_stats.ctkill++;
981 handled |= CSR_INT_BIT_CT_KILL;
984 /* Error detected by uCode */
985 if (inta & CSR_INT_BIT_SW_ERR) {
986 IWL_ERR(priv, "Microcode SW error detected. "
987 " Restarting 0x%X.\n", inta);
988 priv->isr_stats.sw++;
989 priv->isr_stats.sw_err = inta;
990 iwl_irq_handle_error(priv);
991 handled |= CSR_INT_BIT_SW_ERR;
994 /* uCode wakes up after power-down sleep */
995 if (inta & CSR_INT_BIT_WAKEUP) {
996 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
997 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
998 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
999 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1000 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1001 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1002 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1003 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
1005 priv->isr_stats.wakeup++;
1007 handled |= CSR_INT_BIT_WAKEUP;
1010 /* All uCode command responses, including Tx command responses,
1011 * Rx "responses" (frame-received notification), and other
1012 * notifications from uCode come through here*/
1013 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
1014 iwl_rx_handle(priv);
1015 priv->isr_stats.rx++;
1016 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1019 if (inta & CSR_INT_BIT_FH_TX) {
1020 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
1021 priv->isr_stats.tx++;
1022 handled |= CSR_INT_BIT_FH_TX;
1023 /* FH finished to write, send event */
1024 priv->ucode_write_complete = 1;
1025 wake_up_interruptible(&priv->wait_command_queue);
1028 if (inta & ~handled) {
1029 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
1030 priv->isr_stats.unhandled++;
1033 if (inta & ~(priv->inta_mask)) {
1034 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
1035 inta & ~priv->inta_mask);
1036 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
1039 /* Re-enable all interrupts */
1040 /* only Re-enable if diabled by irq */
1041 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1042 iwl_enable_interrupts(priv);
1044 #ifdef CONFIG_IWLWIFI_DEBUG
1045 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
1046 inta = iwl_read32(priv, CSR_INT);
1047 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1048 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1049 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1050 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1052 #endif
1053 spin_unlock_irqrestore(&priv->lock, flags);
1056 /* tasklet for iwlagn interrupt */
1057 static void iwl_irq_tasklet(struct iwl_priv *priv)
1059 u32 inta = 0;
1060 u32 handled = 0;
1061 unsigned long flags;
1062 #ifdef CONFIG_IWLWIFI_DEBUG
1063 u32 inta_mask;
1064 #endif
1066 spin_lock_irqsave(&priv->lock, flags);
1068 /* Ack/clear/reset pending uCode interrupts.
1069 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1071 iwl_write32(priv, CSR_INT, priv->inta);
1073 inta = priv->inta;
1075 #ifdef CONFIG_IWLWIFI_DEBUG
1076 if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
1077 /* just for debug */
1078 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1079 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x\n ",
1080 inta, inta_mask);
1082 #endif
1083 /* saved interrupt in inta variable now we can reset priv->inta */
1084 priv->inta = 0;
1086 /* Now service all interrupt bits discovered above. */
1087 if (inta & CSR_INT_BIT_HW_ERR) {
1088 IWL_ERR(priv, "Hardware error detected. Restarting.\n");
1090 /* Tell the device to stop sending interrupts */
1091 iwl_disable_interrupts(priv);
1093 priv->isr_stats.hw++;
1094 iwl_irq_handle_error(priv);
1096 handled |= CSR_INT_BIT_HW_ERR;
1098 spin_unlock_irqrestore(&priv->lock, flags);
1100 return;
1103 #ifdef CONFIG_IWLWIFI_DEBUG
1104 if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
1105 /* NIC fires this, but we don't use it, redundant with WAKEUP */
1106 if (inta & CSR_INT_BIT_SCD) {
1107 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
1108 "the frame/frames.\n");
1109 priv->isr_stats.sch++;
1112 /* Alive notification via Rx interrupt will do the real work */
1113 if (inta & CSR_INT_BIT_ALIVE) {
1114 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
1115 priv->isr_stats.alive++;
1118 #endif
1119 /* Safely ignore these bits for debug checks below */
1120 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
1122 /* HW RF KILL switch toggled */
1123 if (inta & CSR_INT_BIT_RF_KILL) {
1124 int hw_rf_kill = 0;
1125 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
1126 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1127 hw_rf_kill = 1;
1129 IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
1130 hw_rf_kill ? "disable radio" : "enable radio");
1132 priv->isr_stats.rfkill++;
1134 /* driver only loads ucode once setting the interface up.
1135 * the driver allows loading the ucode even if the radio
1136 * is killed. Hence update the killswitch state here. The
1137 * rfkill handler will care about restarting if needed.
1139 if (!test_bit(STATUS_ALIVE, &priv->status)) {
1140 if (hw_rf_kill)
1141 set_bit(STATUS_RF_KILL_HW, &priv->status);
1142 else
1143 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1144 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
1147 handled |= CSR_INT_BIT_RF_KILL;
1150 /* Chip got too hot and stopped itself */
1151 if (inta & CSR_INT_BIT_CT_KILL) {
1152 IWL_ERR(priv, "Microcode CT kill error detected.\n");
1153 priv->isr_stats.ctkill++;
1154 handled |= CSR_INT_BIT_CT_KILL;
1157 /* Error detected by uCode */
1158 if (inta & CSR_INT_BIT_SW_ERR) {
1159 IWL_ERR(priv, "Microcode SW error detected. "
1160 " Restarting 0x%X.\n", inta);
1161 priv->isr_stats.sw++;
1162 priv->isr_stats.sw_err = inta;
1163 iwl_irq_handle_error(priv);
1164 handled |= CSR_INT_BIT_SW_ERR;
1167 /* uCode wakes up after power-down sleep */
1168 if (inta & CSR_INT_BIT_WAKEUP) {
1169 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
1170 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
1171 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1172 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1173 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1174 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1175 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1176 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
1178 priv->isr_stats.wakeup++;
1180 handled |= CSR_INT_BIT_WAKEUP;
1183 /* All uCode command responses, including Tx command responses,
1184 * Rx "responses" (frame-received notification), and other
1185 * notifications from uCode come through here*/
1186 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
1187 CSR_INT_BIT_RX_PERIODIC)) {
1188 IWL_DEBUG_ISR(priv, "Rx interrupt\n");
1189 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
1190 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1191 iwl_write32(priv, CSR_FH_INT_STATUS,
1192 CSR49_FH_INT_RX_MASK);
1194 if (inta & CSR_INT_BIT_RX_PERIODIC) {
1195 handled |= CSR_INT_BIT_RX_PERIODIC;
1196 iwl_write32(priv, CSR_INT, CSR_INT_BIT_RX_PERIODIC);
1198 /* Sending RX interrupt require many steps to be done in the
1199 * the device:
1200 * 1- write interrupt to current index in ICT table.
1201 * 2- dma RX frame.
1202 * 3- update RX shared data to indicate last write index.
1203 * 4- send interrupt.
1204 * This could lead to RX race, driver could receive RX interrupt
1205 * but the shared data changes does not reflect this.
1206 * this could lead to RX race, RX periodic will solve this race
1208 iwl_write32(priv, CSR_INT_PERIODIC_REG,
1209 CSR_INT_PERIODIC_DIS);
1210 iwl_rx_handle(priv);
1211 /* Only set RX periodic if real RX is received. */
1212 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
1213 iwl_write32(priv, CSR_INT_PERIODIC_REG,
1214 CSR_INT_PERIODIC_ENA);
1216 priv->isr_stats.rx++;
1219 if (inta & CSR_INT_BIT_FH_TX) {
1220 iwl_write32(priv, CSR_FH_INT_STATUS, CSR49_FH_INT_TX_MASK);
1221 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
1222 priv->isr_stats.tx++;
1223 handled |= CSR_INT_BIT_FH_TX;
1224 /* FH finished to write, send event */
1225 priv->ucode_write_complete = 1;
1226 wake_up_interruptible(&priv->wait_command_queue);
1229 if (inta & ~handled) {
1230 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
1231 priv->isr_stats.unhandled++;
1234 if (inta & ~(priv->inta_mask)) {
1235 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
1236 inta & ~priv->inta_mask);
1240 /* Re-enable all interrupts */
1241 /* only Re-enable if diabled by irq */
1242 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1243 iwl_enable_interrupts(priv);
1245 spin_unlock_irqrestore(&priv->lock, flags);
1250 /******************************************************************************
1252 * uCode download functions
1254 ******************************************************************************/
1256 static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
1258 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1259 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1260 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1261 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1262 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1263 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
1266 static void iwl_nic_start(struct iwl_priv *priv)
1268 /* Remove all resets to allow NIC to operate */
1269 iwl_write32(priv, CSR_RESET, 0);
1274 * iwl_read_ucode - Read uCode images from disk file.
1276 * Copy into buffers for card to fetch via bus-mastering
1278 static int iwl_read_ucode(struct iwl_priv *priv)
1280 struct iwl_ucode_header *ucode;
1281 int ret = -EINVAL, index;
1282 const struct firmware *ucode_raw;
1283 const char *name_pre = priv->cfg->fw_name_pre;
1284 const unsigned int api_max = priv->cfg->ucode_api_max;
1285 const unsigned int api_min = priv->cfg->ucode_api_min;
1286 char buf[25];
1287 u8 *src;
1288 size_t len;
1289 u32 api_ver, build;
1290 u32 inst_size, data_size, init_size, init_data_size, boot_size;
1291 u16 eeprom_ver;
1293 /* Ask kernel firmware_class module to get the boot firmware off disk.
1294 * request_firmware() is synchronous, file is in memory on return. */
1295 for (index = api_max; index >= api_min; index--) {
1296 sprintf(buf, "%s%d%s", name_pre, index, ".ucode");
1297 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
1298 if (ret < 0) {
1299 IWL_ERR(priv, "%s firmware file req failed: %d\n",
1300 buf, ret);
1301 if (ret == -ENOENT)
1302 continue;
1303 else
1304 goto error;
1305 } else {
1306 if (index < api_max)
1307 IWL_ERR(priv, "Loaded firmware %s, "
1308 "which is deprecated. "
1309 "Please use API v%u instead.\n",
1310 buf, api_max);
1312 IWL_DEBUG_INFO(priv, "Got firmware '%s' file (%zd bytes) from disk\n",
1313 buf, ucode_raw->size);
1314 break;
1318 if (ret < 0)
1319 goto error;
1321 /* Make sure that we got at least the v1 header! */
1322 if (ucode_raw->size < priv->cfg->ops->ucode->get_header_size(1)) {
1323 IWL_ERR(priv, "File size way too small!\n");
1324 ret = -EINVAL;
1325 goto err_release;
1328 /* Data from ucode file: header followed by uCode images */
1329 ucode = (struct iwl_ucode_header *)ucode_raw->data;
1331 priv->ucode_ver = le32_to_cpu(ucode->ver);
1332 api_ver = IWL_UCODE_API(priv->ucode_ver);
1333 build = priv->cfg->ops->ucode->get_build(ucode, api_ver);
1334 inst_size = priv->cfg->ops->ucode->get_inst_size(ucode, api_ver);
1335 data_size = priv->cfg->ops->ucode->get_data_size(ucode, api_ver);
1336 init_size = priv->cfg->ops->ucode->get_init_size(ucode, api_ver);
1337 init_data_size =
1338 priv->cfg->ops->ucode->get_init_data_size(ucode, api_ver);
1339 boot_size = priv->cfg->ops->ucode->get_boot_size(ucode, api_ver);
1340 src = priv->cfg->ops->ucode->get_data(ucode, api_ver);
1342 /* api_ver should match the api version forming part of the
1343 * firmware filename ... but we don't check for that and only rely
1344 * on the API version read from firmware header from here on forward */
1346 if (api_ver < api_min || api_ver > api_max) {
1347 IWL_ERR(priv, "Driver unable to support your firmware API. "
1348 "Driver supports v%u, firmware is v%u.\n",
1349 api_max, api_ver);
1350 priv->ucode_ver = 0;
1351 ret = -EINVAL;
1352 goto err_release;
1354 if (api_ver != api_max)
1355 IWL_ERR(priv, "Firmware has old API version. Expected v%u, "
1356 "got v%u. New firmware can be obtained "
1357 "from http://www.intellinuxwireless.org.\n",
1358 api_max, api_ver);
1360 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
1361 IWL_UCODE_MAJOR(priv->ucode_ver),
1362 IWL_UCODE_MINOR(priv->ucode_ver),
1363 IWL_UCODE_API(priv->ucode_ver),
1364 IWL_UCODE_SERIAL(priv->ucode_ver));
1366 if (build)
1367 IWL_DEBUG_INFO(priv, "Build %u\n", build);
1369 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
1370 IWL_DEBUG_INFO(priv, "NVM Type: %s, version: 0x%x\n",
1371 (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
1372 ? "OTP" : "EEPROM", eeprom_ver);
1374 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
1375 priv->ucode_ver);
1376 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
1377 inst_size);
1378 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
1379 data_size);
1380 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
1381 init_size);
1382 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
1383 init_data_size);
1384 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
1385 boot_size);
1387 /* Verify size of file vs. image size info in file's header */
1388 if (ucode_raw->size !=
1389 priv->cfg->ops->ucode->get_header_size(api_ver) +
1390 inst_size + data_size + init_size +
1391 init_data_size + boot_size) {
1393 IWL_DEBUG_INFO(priv,
1394 "uCode file size %d does not match expected size\n",
1395 (int)ucode_raw->size);
1396 ret = -EINVAL;
1397 goto err_release;
1400 /* Verify that uCode images will fit in card's SRAM */
1401 if (inst_size > priv->hw_params.max_inst_size) {
1402 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
1403 inst_size);
1404 ret = -EINVAL;
1405 goto err_release;
1408 if (data_size > priv->hw_params.max_data_size) {
1409 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
1410 data_size);
1411 ret = -EINVAL;
1412 goto err_release;
1414 if (init_size > priv->hw_params.max_inst_size) {
1415 IWL_INFO(priv, "uCode init instr len %d too large to fit in\n",
1416 init_size);
1417 ret = -EINVAL;
1418 goto err_release;
1420 if (init_data_size > priv->hw_params.max_data_size) {
1421 IWL_INFO(priv, "uCode init data len %d too large to fit in\n",
1422 init_data_size);
1423 ret = -EINVAL;
1424 goto err_release;
1426 if (boot_size > priv->hw_params.max_bsm_size) {
1427 IWL_INFO(priv, "uCode boot instr len %d too large to fit in\n",
1428 boot_size);
1429 ret = -EINVAL;
1430 goto err_release;
1433 /* Allocate ucode buffers for card's bus-master loading ... */
1435 /* Runtime instructions and 2 copies of data:
1436 * 1) unmodified from disk
1437 * 2) backup cache for save/restore during power-downs */
1438 priv->ucode_code.len = inst_size;
1439 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
1441 priv->ucode_data.len = data_size;
1442 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
1444 priv->ucode_data_backup.len = data_size;
1445 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1447 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
1448 !priv->ucode_data_backup.v_addr)
1449 goto err_pci_alloc;
1451 /* Initialization instructions and data */
1452 if (init_size && init_data_size) {
1453 priv->ucode_init.len = init_size;
1454 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
1456 priv->ucode_init_data.len = init_data_size;
1457 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1459 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
1460 goto err_pci_alloc;
1463 /* Bootstrap (instructions only, no data) */
1464 if (boot_size) {
1465 priv->ucode_boot.len = boot_size;
1466 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
1468 if (!priv->ucode_boot.v_addr)
1469 goto err_pci_alloc;
1472 /* Copy images into buffers for card's bus-master reads ... */
1474 /* Runtime instructions (first block of data in file) */
1475 len = inst_size;
1476 IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n", len);
1477 memcpy(priv->ucode_code.v_addr, src, len);
1478 src += len;
1480 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
1481 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1483 /* Runtime data (2nd block)
1484 * NOTE: Copy into backup buffer will be done in iwl_up() */
1485 len = data_size;
1486 IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n", len);
1487 memcpy(priv->ucode_data.v_addr, src, len);
1488 memcpy(priv->ucode_data_backup.v_addr, src, len);
1489 src += len;
1491 /* Initialization instructions (3rd block) */
1492 if (init_size) {
1493 len = init_size;
1494 IWL_DEBUG_INFO(priv, "Copying (but not loading) init instr len %Zd\n",
1495 len);
1496 memcpy(priv->ucode_init.v_addr, src, len);
1497 src += len;
1500 /* Initialization data (4th block) */
1501 if (init_data_size) {
1502 len = init_data_size;
1503 IWL_DEBUG_INFO(priv, "Copying (but not loading) init data len %Zd\n",
1504 len);
1505 memcpy(priv->ucode_init_data.v_addr, src, len);
1506 src += len;
1509 /* Bootstrap instructions (5th block) */
1510 len = boot_size;
1511 IWL_DEBUG_INFO(priv, "Copying (but not loading) boot instr len %Zd\n", len);
1512 memcpy(priv->ucode_boot.v_addr, src, len);
1514 /* We have our copies now, allow OS release its copies */
1515 release_firmware(ucode_raw);
1516 return 0;
1518 err_pci_alloc:
1519 IWL_ERR(priv, "failed to allocate pci memory\n");
1520 ret = -ENOMEM;
1521 iwl_dealloc_ucode_pci(priv);
1523 err_release:
1524 release_firmware(ucode_raw);
1526 error:
1527 return ret;
1530 #ifdef CONFIG_IWLWIFI_DEBUG
1531 static const char *desc_lookup_text[] = {
1532 "OK",
1533 "FAIL",
1534 "BAD_PARAM",
1535 "BAD_CHECKSUM",
1536 "NMI_INTERRUPT_WDG",
1537 "SYSASSERT",
1538 "FATAL_ERROR",
1539 "BAD_COMMAND",
1540 "HW_ERROR_TUNE_LOCK",
1541 "HW_ERROR_TEMPERATURE",
1542 "ILLEGAL_CHAN_FREQ",
1543 "VCC_NOT_STABLE",
1544 "FH_ERROR",
1545 "NMI_INTERRUPT_HOST",
1546 "NMI_INTERRUPT_ACTION_PT",
1547 "NMI_INTERRUPT_UNKNOWN",
1548 "UCODE_VERSION_MISMATCH",
1549 "HW_ERROR_ABS_LOCK",
1550 "HW_ERROR_CAL_LOCK_FAIL",
1551 "NMI_INTERRUPT_INST_ACTION_PT",
1552 "NMI_INTERRUPT_DATA_ACTION_PT",
1553 "NMI_TRM_HW_ER",
1554 "NMI_INTERRUPT_TRM",
1555 "NMI_INTERRUPT_BREAK_POINT"
1556 "DEBUG_0",
1557 "DEBUG_1",
1558 "DEBUG_2",
1559 "DEBUG_3",
1560 "UNKNOWN"
1563 static const char *desc_lookup(int i)
1565 int max = ARRAY_SIZE(desc_lookup_text) - 1;
1567 if (i < 0 || i > max)
1568 i = max;
1570 return desc_lookup_text[i];
1573 #define ERROR_START_OFFSET (1 * sizeof(u32))
1574 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
1576 void iwl_dump_nic_error_log(struct iwl_priv *priv)
1578 u32 data2, line;
1579 u32 desc, time, count, base, data1;
1580 u32 blink1, blink2, ilink1, ilink2;
1582 if (priv->ucode_type == UCODE_INIT)
1583 base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
1584 else
1585 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1587 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
1588 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
1589 return;
1592 count = iwl_read_targ_mem(priv, base);
1594 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
1595 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1596 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1597 priv->status, count);
1600 desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
1601 blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
1602 blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
1603 ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
1604 ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
1605 data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
1606 data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
1607 line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
1608 time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
1610 IWL_ERR(priv, "Desc Time "
1611 "data1 data2 line\n");
1612 IWL_ERR(priv, "%-28s (#%02d) %010u 0x%08X 0x%08X %u\n",
1613 desc_lookup(desc), desc, time, data1, data2, line);
1614 IWL_ERR(priv, "blink1 blink2 ilink1 ilink2\n");
1615 IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
1616 ilink1, ilink2);
1620 #define EVENT_START_OFFSET (4 * sizeof(u32))
1623 * iwl_print_event_log - Dump error event log to syslog
1626 static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1627 u32 num_events, u32 mode)
1629 u32 i;
1630 u32 base; /* SRAM byte address of event log header */
1631 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1632 u32 ptr; /* SRAM byte address of log data */
1633 u32 ev, time, data; /* event log data */
1635 if (num_events == 0)
1636 return;
1637 if (priv->ucode_type == UCODE_INIT)
1638 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
1639 else
1640 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1642 if (mode == 0)
1643 event_size = 2 * sizeof(u32);
1644 else
1645 event_size = 3 * sizeof(u32);
1647 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1649 /* "time" is actually "data" for mode 0 (no timestamp).
1650 * place event id # at far right for easier visual parsing. */
1651 for (i = 0; i < num_events; i++) {
1652 ev = iwl_read_targ_mem(priv, ptr);
1653 ptr += sizeof(u32);
1654 time = iwl_read_targ_mem(priv, ptr);
1655 ptr += sizeof(u32);
1656 if (mode == 0) {
1657 /* data, ev */
1658 IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n", time, ev);
1659 } else {
1660 data = iwl_read_targ_mem(priv, ptr);
1661 ptr += sizeof(u32);
1662 IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
1663 time, data, ev);
1668 void iwl_dump_nic_event_log(struct iwl_priv *priv)
1670 u32 base; /* SRAM byte address of event log header */
1671 u32 capacity; /* event log capacity in # entries */
1672 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1673 u32 num_wraps; /* # times uCode wrapped to top of log */
1674 u32 next_entry; /* index of next entry to be written by uCode */
1675 u32 size; /* # entries that we'll print */
1677 if (priv->ucode_type == UCODE_INIT)
1678 base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
1679 else
1680 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1682 if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
1683 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
1684 return;
1687 /* event log header */
1688 capacity = iwl_read_targ_mem(priv, base);
1689 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1690 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1691 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
1693 size = num_wraps ? capacity : next_entry;
1695 /* bail out if nothing in log */
1696 if (size == 0) {
1697 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
1698 return;
1701 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
1702 size, num_wraps);
1704 /* if uCode has wrapped back to top of log, start at the oldest entry,
1705 * i.e the next one that uCode would fill. */
1706 if (num_wraps)
1707 iwl_print_event_log(priv, next_entry,
1708 capacity - next_entry, mode);
1709 /* (then/else) start at top of log */
1710 iwl_print_event_log(priv, 0, next_entry, mode);
1713 #endif
1716 * iwl_alive_start - called after REPLY_ALIVE notification received
1717 * from protocol/runtime uCode (initialization uCode's
1718 * Alive gets handled by iwl_init_alive_start()).
1720 static void iwl_alive_start(struct iwl_priv *priv)
1722 int ret = 0;
1724 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
1726 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
1727 /* We had an error bringing up the hardware, so take it
1728 * all the way back down so we can try again */
1729 IWL_DEBUG_INFO(priv, "Alive failed.\n");
1730 goto restart;
1733 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
1734 * This is a paranoid check, because we would not have gotten the
1735 * "runtime" alive if code weren't properly loaded. */
1736 if (iwl_verify_ucode(priv)) {
1737 /* Runtime instruction load was bad;
1738 * take it all the way back down so we can try again */
1739 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
1740 goto restart;
1743 iwl_clear_stations_table(priv);
1744 ret = priv->cfg->ops->lib->alive_notify(priv);
1745 if (ret) {
1746 IWL_WARN(priv,
1747 "Could not complete ALIVE transition [ntf]: %d\n", ret);
1748 goto restart;
1751 /* After the ALIVE response, we can send host commands to the uCode */
1752 set_bit(STATUS_ALIVE, &priv->status);
1754 if (iwl_is_rfkill(priv))
1755 return;
1757 ieee80211_wake_queues(priv->hw);
1759 priv->active_rate = priv->rates_mask;
1760 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
1762 if (iwl_is_associated(priv)) {
1763 struct iwl_rxon_cmd *active_rxon =
1764 (struct iwl_rxon_cmd *)&priv->active_rxon;
1765 /* apply any changes in staging */
1766 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
1767 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1768 } else {
1769 /* Initialize our rx_config data */
1770 iwl_connection_init_rx_config(priv, priv->iw_mode);
1772 if (priv->cfg->ops->hcmd->set_rxon_chain)
1773 priv->cfg->ops->hcmd->set_rxon_chain(priv);
1775 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1778 /* Configure Bluetooth device coexistence support */
1779 iwl_send_bt_config(priv);
1781 iwl_reset_run_time_calib(priv);
1783 /* Configure the adapter for unassociated operation */
1784 iwlcore_commit_rxon(priv);
1786 /* At this point, the NIC is initialized and operational */
1787 iwl_rf_kill_ct_config(priv);
1789 iwl_leds_register(priv);
1791 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
1792 set_bit(STATUS_READY, &priv->status);
1793 wake_up_interruptible(&priv->wait_command_queue);
1795 iwl_power_update_mode(priv, true);
1797 /* reassociate for ADHOC mode */
1798 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
1799 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
1800 priv->vif);
1801 if (beacon)
1802 iwl_mac_beacon_update(priv->hw, beacon);
1806 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
1807 iwl_set_mode(priv, priv->iw_mode);
1809 return;
1811 restart:
1812 queue_work(priv->workqueue, &priv->restart);
1815 static void iwl_cancel_deferred_work(struct iwl_priv *priv);
1817 static void __iwl_down(struct iwl_priv *priv)
1819 unsigned long flags;
1820 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
1822 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
1824 if (!exit_pending)
1825 set_bit(STATUS_EXIT_PENDING, &priv->status);
1827 iwl_leds_unregister(priv);
1829 iwl_clear_stations_table(priv);
1831 /* Unblock any waiting calls */
1832 wake_up_interruptible_all(&priv->wait_command_queue);
1834 /* Wipe out the EXIT_PENDING status bit if we are not actually
1835 * exiting the module */
1836 if (!exit_pending)
1837 clear_bit(STATUS_EXIT_PENDING, &priv->status);
1839 /* stop and reset the on-board processor */
1840 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
1842 /* tell the device to stop sending interrupts */
1843 spin_lock_irqsave(&priv->lock, flags);
1844 iwl_disable_interrupts(priv);
1845 spin_unlock_irqrestore(&priv->lock, flags);
1846 iwl_synchronize_irq(priv);
1848 if (priv->mac80211_registered)
1849 ieee80211_stop_queues(priv->hw);
1851 /* If we have not previously called iwl_init() then
1852 * clear all bits but the RF Kill bit and return */
1853 if (!iwl_is_init(priv)) {
1854 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
1855 STATUS_RF_KILL_HW |
1856 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
1857 STATUS_GEO_CONFIGURED |
1858 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
1859 STATUS_EXIT_PENDING;
1860 goto exit;
1863 /* ...otherwise clear out all the status bits but the RF Kill
1864 * bit and continue taking the NIC down. */
1865 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
1866 STATUS_RF_KILL_HW |
1867 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
1868 STATUS_GEO_CONFIGURED |
1869 test_bit(STATUS_FW_ERROR, &priv->status) <<
1870 STATUS_FW_ERROR |
1871 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
1872 STATUS_EXIT_PENDING;
1874 /* device going down, Stop using ICT table */
1875 iwl_disable_ict(priv);
1876 spin_lock_irqsave(&priv->lock, flags);
1877 iwl_clear_bit(priv, CSR_GP_CNTRL,
1878 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
1879 spin_unlock_irqrestore(&priv->lock, flags);
1881 iwl_txq_ctx_stop(priv);
1882 iwl_rxq_stop(priv);
1884 iwl_write_prph(priv, APMG_CLK_DIS_REG,
1885 APMG_CLK_VAL_DMA_CLK_RQT);
1887 udelay(5);
1889 /* FIXME: apm_ops.suspend(priv) */
1890 if (exit_pending)
1891 priv->cfg->ops->lib->apm_ops.stop(priv);
1892 else
1893 priv->cfg->ops->lib->apm_ops.reset(priv);
1894 exit:
1895 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
1897 if (priv->ibss_beacon)
1898 dev_kfree_skb(priv->ibss_beacon);
1899 priv->ibss_beacon = NULL;
1901 /* clear out any free frames */
1902 iwl_clear_free_frames(priv);
1905 static void iwl_down(struct iwl_priv *priv)
1907 mutex_lock(&priv->mutex);
1908 __iwl_down(priv);
1909 mutex_unlock(&priv->mutex);
1911 iwl_cancel_deferred_work(priv);
1914 #define HW_READY_TIMEOUT (50)
1916 static int iwl_set_hw_ready(struct iwl_priv *priv)
1918 int ret = 0;
1920 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
1921 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
1923 /* See if we got it */
1924 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
1925 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
1926 CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
1927 HW_READY_TIMEOUT);
1928 if (ret != -ETIMEDOUT)
1929 priv->hw_ready = true;
1930 else
1931 priv->hw_ready = false;
1933 IWL_DEBUG_INFO(priv, "hardware %s\n",
1934 (priv->hw_ready == 1) ? "ready" : "not ready");
1935 return ret;
1938 static int iwl_prepare_card_hw(struct iwl_priv *priv)
1940 int ret = 0;
1942 IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter \n");
1944 ret = iwl_set_hw_ready(priv);
1945 if (priv->hw_ready)
1946 return ret;
1948 /* If HW is not ready, prepare the conditions to check again */
1949 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
1950 CSR_HW_IF_CONFIG_REG_PREPARE);
1952 ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
1953 ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
1954 CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
1956 /* HW should be ready by now, check again. */
1957 if (ret != -ETIMEDOUT)
1958 iwl_set_hw_ready(priv);
1960 return ret;
1963 #define MAX_HW_RESTARTS 5
1965 static int __iwl_up(struct iwl_priv *priv)
1967 int i;
1968 int ret;
1970 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
1971 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
1972 return -EIO;
1975 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
1976 IWL_ERR(priv, "ucode not available for device bringup\n");
1977 return -EIO;
1980 iwl_prepare_card_hw(priv);
1982 if (!priv->hw_ready) {
1983 IWL_WARN(priv, "Exit HW not ready\n");
1984 return -EIO;
1987 /* If platform's RF_KILL switch is NOT set to KILL */
1988 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
1989 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1990 else
1991 set_bit(STATUS_RF_KILL_HW, &priv->status);
1993 if (iwl_is_rfkill(priv)) {
1994 wiphy_rfkill_set_hw_state(priv->hw->wiphy, true);
1996 iwl_enable_interrupts(priv);
1997 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
1998 return 0;
2001 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2003 ret = iwl_hw_nic_init(priv);
2004 if (ret) {
2005 IWL_ERR(priv, "Unable to init nic\n");
2006 return ret;
2009 /* make sure rfkill handshake bits are cleared */
2010 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2011 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
2012 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2014 /* clear (again), then enable host interrupts */
2015 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2016 iwl_enable_interrupts(priv);
2018 /* really make sure rfkill handshake bits are cleared */
2019 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2020 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2022 /* Copy original ucode data image from disk into backup cache.
2023 * This will be used to initialize the on-board processor's
2024 * data SRAM for a clean start when the runtime program first loads. */
2025 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
2026 priv->ucode_data.len);
2028 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2030 iwl_clear_stations_table(priv);
2032 /* load bootstrap state machine,
2033 * load bootstrap program into processor's memory,
2034 * prepare to load the "initialize" uCode */
2035 ret = priv->cfg->ops->lib->load_ucode(priv);
2037 if (ret) {
2038 IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
2039 ret);
2040 continue;
2043 /* start card; "initialize" will load runtime ucode */
2044 iwl_nic_start(priv);
2046 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
2048 return 0;
2051 set_bit(STATUS_EXIT_PENDING, &priv->status);
2052 __iwl_down(priv);
2053 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2055 /* tried to restart and config the device for as long as our
2056 * patience could withstand */
2057 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
2058 return -EIO;
2062 /*****************************************************************************
2064 * Workqueue callbacks
2066 *****************************************************************************/
2068 static void iwl_bg_init_alive_start(struct work_struct *data)
2070 struct iwl_priv *priv =
2071 container_of(data, struct iwl_priv, init_alive_start.work);
2073 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2074 return;
2076 mutex_lock(&priv->mutex);
2077 priv->cfg->ops->lib->init_alive_start(priv);
2078 mutex_unlock(&priv->mutex);
2081 static void iwl_bg_alive_start(struct work_struct *data)
2083 struct iwl_priv *priv =
2084 container_of(data, struct iwl_priv, alive_start.work);
2086 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2087 return;
2089 /* enable dram interrupt */
2090 iwl_reset_ict(priv);
2092 mutex_lock(&priv->mutex);
2093 iwl_alive_start(priv);
2094 mutex_unlock(&priv->mutex);
2097 static void iwl_bg_run_time_calib_work(struct work_struct *work)
2099 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2100 run_time_calib_work);
2102 mutex_lock(&priv->mutex);
2104 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2105 test_bit(STATUS_SCANNING, &priv->status)) {
2106 mutex_unlock(&priv->mutex);
2107 return;
2110 if (priv->start_calib) {
2111 iwl_chain_noise_calibration(priv, &priv->statistics);
2113 iwl_sensitivity_calibration(priv, &priv->statistics);
2116 mutex_unlock(&priv->mutex);
2117 return;
2120 static void iwl_bg_up(struct work_struct *data)
2122 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
2124 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2125 return;
2127 mutex_lock(&priv->mutex);
2128 __iwl_up(priv);
2129 mutex_unlock(&priv->mutex);
2132 static void iwl_bg_restart(struct work_struct *data)
2134 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
2136 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2137 return;
2139 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
2140 mutex_lock(&priv->mutex);
2141 priv->vif = NULL;
2142 priv->is_open = 0;
2143 mutex_unlock(&priv->mutex);
2144 iwl_down(priv);
2145 ieee80211_restart_hw(priv->hw);
2146 } else {
2147 iwl_down(priv);
2148 queue_work(priv->workqueue, &priv->up);
2152 static void iwl_bg_rx_replenish(struct work_struct *data)
2154 struct iwl_priv *priv =
2155 container_of(data, struct iwl_priv, rx_replenish);
2157 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2158 return;
2160 mutex_lock(&priv->mutex);
2161 iwl_rx_replenish(priv);
2162 mutex_unlock(&priv->mutex);
2165 #define IWL_DELAY_NEXT_SCAN (HZ*2)
2167 void iwl_post_associate(struct iwl_priv *priv)
2169 struct ieee80211_conf *conf = NULL;
2170 int ret = 0;
2171 unsigned long flags;
2173 if (priv->iw_mode == NL80211_IFTYPE_AP) {
2174 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
2175 return;
2178 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
2179 priv->assoc_id, priv->active_rxon.bssid_addr);
2182 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2183 return;
2186 if (!priv->vif || !priv->is_open)
2187 return;
2189 iwl_scan_cancel_timeout(priv, 200);
2191 conf = ieee80211_get_hw_conf(priv->hw);
2193 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2194 iwlcore_commit_rxon(priv);
2196 iwl_setup_rxon_timing(priv);
2197 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
2198 sizeof(priv->rxon_timing), &priv->rxon_timing);
2199 if (ret)
2200 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
2201 "Attempting to continue.\n");
2203 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2205 iwl_set_rxon_ht(priv, &priv->current_ht_config);
2207 if (priv->cfg->ops->hcmd->set_rxon_chain)
2208 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2210 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2212 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
2213 priv->assoc_id, priv->beacon_int);
2215 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2216 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2217 else
2218 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2220 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2221 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2222 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2223 else
2224 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2226 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
2227 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2231 iwlcore_commit_rxon(priv);
2233 switch (priv->iw_mode) {
2234 case NL80211_IFTYPE_STATION:
2235 break;
2237 case NL80211_IFTYPE_ADHOC:
2239 /* assume default assoc id */
2240 priv->assoc_id = 1;
2242 iwl_rxon_add_station(priv, priv->bssid, 0);
2243 iwl_send_beacon_cmd(priv);
2245 break;
2247 default:
2248 IWL_ERR(priv, "%s Should not be called in %d mode\n",
2249 __func__, priv->iw_mode);
2250 break;
2253 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
2254 priv->assoc_station_added = 1;
2256 spin_lock_irqsave(&priv->lock, flags);
2257 iwl_activate_qos(priv, 0);
2258 spin_unlock_irqrestore(&priv->lock, flags);
2260 /* the chain noise calibration will enabled PM upon completion
2261 * If chain noise has already been run, then we need to enable
2262 * power management here */
2263 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
2264 iwl_power_update_mode(priv, false);
2266 /* Enable Rx differential gain and sensitivity calibrations */
2267 iwl_chain_noise_reset(priv);
2268 priv->start_calib = 1;
2272 /*****************************************************************************
2274 * mac80211 entry point functions
2276 *****************************************************************************/
2278 #define UCODE_READY_TIMEOUT (4 * HZ)
2280 static int iwl_mac_start(struct ieee80211_hw *hw)
2282 struct iwl_priv *priv = hw->priv;
2283 int ret;
2285 IWL_DEBUG_MAC80211(priv, "enter\n");
2287 /* we should be verifying the device is ready to be opened */
2288 mutex_lock(&priv->mutex);
2290 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2291 * ucode filename and max sizes are card-specific. */
2293 if (!priv->ucode_code.len) {
2294 ret = iwl_read_ucode(priv);
2295 if (ret) {
2296 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
2297 mutex_unlock(&priv->mutex);
2298 return ret;
2302 ret = __iwl_up(priv);
2304 mutex_unlock(&priv->mutex);
2306 if (ret)
2307 return ret;
2309 if (iwl_is_rfkill(priv))
2310 goto out;
2312 IWL_DEBUG_INFO(priv, "Start UP work done.\n");
2314 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
2315 * mac80211 will not be run successfully. */
2316 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2317 test_bit(STATUS_READY, &priv->status),
2318 UCODE_READY_TIMEOUT);
2319 if (!ret) {
2320 if (!test_bit(STATUS_READY, &priv->status)) {
2321 IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
2322 jiffies_to_msecs(UCODE_READY_TIMEOUT));
2323 return -ETIMEDOUT;
2327 out:
2328 priv->is_open = 1;
2329 IWL_DEBUG_MAC80211(priv, "leave\n");
2330 return 0;
2333 static void iwl_mac_stop(struct ieee80211_hw *hw)
2335 struct iwl_priv *priv = hw->priv;
2337 IWL_DEBUG_MAC80211(priv, "enter\n");
2339 if (!priv->is_open)
2340 return;
2342 priv->is_open = 0;
2344 if (iwl_is_ready_rf(priv) || test_bit(STATUS_SCAN_HW, &priv->status)) {
2345 /* stop mac, cancel any scan request and clear
2346 * RXON_FILTER_ASSOC_MSK BIT
2348 mutex_lock(&priv->mutex);
2349 iwl_scan_cancel_timeout(priv, 100);
2350 mutex_unlock(&priv->mutex);
2353 iwl_down(priv);
2355 flush_workqueue(priv->workqueue);
2357 /* enable interrupts again in order to receive rfkill changes */
2358 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
2359 iwl_enable_interrupts(priv);
2361 IWL_DEBUG_MAC80211(priv, "leave\n");
2364 static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
2366 struct iwl_priv *priv = hw->priv;
2368 IWL_DEBUG_MACDUMP(priv, "enter\n");
2370 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
2371 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
2373 if (iwl_tx_skb(priv, skb))
2374 dev_kfree_skb_any(skb);
2376 IWL_DEBUG_MACDUMP(priv, "leave\n");
2377 return NETDEV_TX_OK;
2380 void iwl_config_ap(struct iwl_priv *priv)
2382 int ret = 0;
2383 unsigned long flags;
2385 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2386 return;
2388 /* The following should be done only at AP bring up */
2389 if (!iwl_is_associated(priv)) {
2391 /* RXON - unassoc (to set timing command) */
2392 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2393 iwlcore_commit_rxon(priv);
2395 /* RXON Timing */
2396 iwl_setup_rxon_timing(priv);
2397 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
2398 sizeof(priv->rxon_timing), &priv->rxon_timing);
2399 if (ret)
2400 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
2401 "Attempting to continue.\n");
2403 if (priv->cfg->ops->hcmd->set_rxon_chain)
2404 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2406 /* FIXME: what should be the assoc_id for AP? */
2407 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2408 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2409 priv->staging_rxon.flags |=
2410 RXON_FLG_SHORT_PREAMBLE_MSK;
2411 else
2412 priv->staging_rxon.flags &=
2413 ~RXON_FLG_SHORT_PREAMBLE_MSK;
2415 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2416 if (priv->assoc_capability &
2417 WLAN_CAPABILITY_SHORT_SLOT_TIME)
2418 priv->staging_rxon.flags |=
2419 RXON_FLG_SHORT_SLOT_MSK;
2420 else
2421 priv->staging_rxon.flags &=
2422 ~RXON_FLG_SHORT_SLOT_MSK;
2424 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
2425 priv->staging_rxon.flags &=
2426 ~RXON_FLG_SHORT_SLOT_MSK;
2428 /* restore RXON assoc */
2429 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2430 iwlcore_commit_rxon(priv);
2431 spin_lock_irqsave(&priv->lock, flags);
2432 iwl_activate_qos(priv, 1);
2433 spin_unlock_irqrestore(&priv->lock, flags);
2434 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
2436 iwl_send_beacon_cmd(priv);
2438 /* FIXME - we need to add code here to detect a totally new
2439 * configuration, reset the AP, unassoc, rxon timing, assoc,
2440 * clear sta table, add BCAST sta... */
2443 static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
2444 struct ieee80211_key_conf *keyconf, const u8 *addr,
2445 u32 iv32, u16 *phase1key)
2448 struct iwl_priv *priv = hw->priv;
2449 IWL_DEBUG_MAC80211(priv, "enter\n");
2451 iwl_update_tkip_key(priv, keyconf, addr, iv32, phase1key);
2453 IWL_DEBUG_MAC80211(priv, "leave\n");
2456 static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2457 struct ieee80211_vif *vif,
2458 struct ieee80211_sta *sta,
2459 struct ieee80211_key_conf *key)
2461 struct iwl_priv *priv = hw->priv;
2462 const u8 *addr;
2463 int ret;
2464 u8 sta_id;
2465 bool is_default_wep_key = false;
2467 IWL_DEBUG_MAC80211(priv, "enter\n");
2469 if (priv->cfg->mod_params->sw_crypto) {
2470 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
2471 return -EOPNOTSUPP;
2473 addr = sta ? sta->addr : iwl_bcast_addr;
2474 sta_id = iwl_find_station(priv, addr);
2475 if (sta_id == IWL_INVALID_STATION) {
2476 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
2477 addr);
2478 return -EINVAL;
2482 mutex_lock(&priv->mutex);
2483 iwl_scan_cancel_timeout(priv, 100);
2484 mutex_unlock(&priv->mutex);
2486 /* If we are getting WEP group key and we didn't receive any key mapping
2487 * so far, we are in legacy wep mode (group key only), otherwise we are
2488 * in 1X mode.
2489 * In legacy wep mode, we use another host command to the uCode */
2490 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
2491 priv->iw_mode != NL80211_IFTYPE_AP) {
2492 if (cmd == SET_KEY)
2493 is_default_wep_key = !priv->key_mapping_key;
2494 else
2495 is_default_wep_key =
2496 (key->hw_key_idx == HW_KEY_DEFAULT);
2499 switch (cmd) {
2500 case SET_KEY:
2501 if (is_default_wep_key)
2502 ret = iwl_set_default_wep_key(priv, key);
2503 else
2504 ret = iwl_set_dynamic_key(priv, key, sta_id);
2506 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
2507 break;
2508 case DISABLE_KEY:
2509 if (is_default_wep_key)
2510 ret = iwl_remove_default_wep_key(priv, key);
2511 else
2512 ret = iwl_remove_dynamic_key(priv, key, sta_id);
2514 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
2515 break;
2516 default:
2517 ret = -EINVAL;
2520 IWL_DEBUG_MAC80211(priv, "leave\n");
2522 return ret;
2525 static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
2526 enum ieee80211_ampdu_mlme_action action,
2527 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
2529 struct iwl_priv *priv = hw->priv;
2530 int ret;
2532 IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
2533 sta->addr, tid);
2535 if (!(priv->cfg->sku & IWL_SKU_N))
2536 return -EACCES;
2538 switch (action) {
2539 case IEEE80211_AMPDU_RX_START:
2540 IWL_DEBUG_HT(priv, "start Rx\n");
2541 return iwl_sta_rx_agg_start(priv, sta->addr, tid, *ssn);
2542 case IEEE80211_AMPDU_RX_STOP:
2543 IWL_DEBUG_HT(priv, "stop Rx\n");
2544 ret = iwl_sta_rx_agg_stop(priv, sta->addr, tid);
2545 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2546 return 0;
2547 else
2548 return ret;
2549 case IEEE80211_AMPDU_TX_START:
2550 IWL_DEBUG_HT(priv, "start Tx\n");
2551 return iwl_tx_agg_start(priv, sta->addr, tid, ssn);
2552 case IEEE80211_AMPDU_TX_STOP:
2553 IWL_DEBUG_HT(priv, "stop Tx\n");
2554 ret = iwl_tx_agg_stop(priv, sta->addr, tid);
2555 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2556 return 0;
2557 else
2558 return ret;
2559 default:
2560 IWL_DEBUG_HT(priv, "unknown\n");
2561 return -EINVAL;
2562 break;
2564 return 0;
2567 static int iwl_mac_get_stats(struct ieee80211_hw *hw,
2568 struct ieee80211_low_level_stats *stats)
2570 struct iwl_priv *priv = hw->priv;
2572 priv = hw->priv;
2573 IWL_DEBUG_MAC80211(priv, "enter\n");
2574 IWL_DEBUG_MAC80211(priv, "leave\n");
2576 return 0;
2579 /*****************************************************************************
2581 * sysfs attributes
2583 *****************************************************************************/
2585 #ifdef CONFIG_IWLWIFI_DEBUG
2588 * The following adds a new attribute to the sysfs representation
2589 * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
2590 * used for controlling the debug level.
2592 * See the level definitions in iwl for details.
2594 * The debug_level being managed using sysfs below is a per device debug
2595 * level that is used instead of the global debug level if it (the per
2596 * device debug level) is set.
2598 static ssize_t show_debug_level(struct device *d,
2599 struct device_attribute *attr, char *buf)
2601 struct iwl_priv *priv = dev_get_drvdata(d);
2602 return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
2604 static ssize_t store_debug_level(struct device *d,
2605 struct device_attribute *attr,
2606 const char *buf, size_t count)
2608 struct iwl_priv *priv = dev_get_drvdata(d);
2609 unsigned long val;
2610 int ret;
2612 ret = strict_strtoul(buf, 0, &val);
2613 if (ret)
2614 IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
2615 else {
2616 priv->debug_level = val;
2617 if (iwl_alloc_traffic_mem(priv))
2618 IWL_ERR(priv,
2619 "Not enough memory to generate traffic log\n");
2621 return strnlen(buf, count);
2624 static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
2625 show_debug_level, store_debug_level);
2628 #endif /* CONFIG_IWLWIFI_DEBUG */
2631 static ssize_t show_temperature(struct device *d,
2632 struct device_attribute *attr, char *buf)
2634 struct iwl_priv *priv = dev_get_drvdata(d);
2636 if (!iwl_is_alive(priv))
2637 return -EAGAIN;
2639 return sprintf(buf, "%d\n", priv->temperature);
2642 static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
2644 static ssize_t show_tx_power(struct device *d,
2645 struct device_attribute *attr, char *buf)
2647 struct iwl_priv *priv = dev_get_drvdata(d);
2649 if (!iwl_is_ready_rf(priv))
2650 return sprintf(buf, "off\n");
2651 else
2652 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
2655 static ssize_t store_tx_power(struct device *d,
2656 struct device_attribute *attr,
2657 const char *buf, size_t count)
2659 struct iwl_priv *priv = dev_get_drvdata(d);
2660 unsigned long val;
2661 int ret;
2663 ret = strict_strtoul(buf, 10, &val);
2664 if (ret)
2665 IWL_INFO(priv, "%s is not in decimal form.\n", buf);
2666 else {
2667 ret = iwl_set_tx_power(priv, val, false);
2668 if (ret)
2669 IWL_ERR(priv, "failed setting tx power (0x%d).\n",
2670 ret);
2671 else
2672 ret = count;
2674 return ret;
2677 static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
2679 static ssize_t show_flags(struct device *d,
2680 struct device_attribute *attr, char *buf)
2682 struct iwl_priv *priv = dev_get_drvdata(d);
2684 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
2687 static ssize_t store_flags(struct device *d,
2688 struct device_attribute *attr,
2689 const char *buf, size_t count)
2691 struct iwl_priv *priv = dev_get_drvdata(d);
2692 unsigned long val;
2693 u32 flags;
2694 int ret = strict_strtoul(buf, 0, &val);
2695 if (ret)
2696 return ret;
2697 flags = (u32)val;
2699 mutex_lock(&priv->mutex);
2700 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
2701 /* Cancel any currently running scans... */
2702 if (iwl_scan_cancel_timeout(priv, 100))
2703 IWL_WARN(priv, "Could not cancel scan.\n");
2704 else {
2705 IWL_DEBUG_INFO(priv, "Commit rxon.flags = 0x%04X\n", flags);
2706 priv->staging_rxon.flags = cpu_to_le32(flags);
2707 iwlcore_commit_rxon(priv);
2710 mutex_unlock(&priv->mutex);
2712 return count;
2715 static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
2717 static ssize_t show_filter_flags(struct device *d,
2718 struct device_attribute *attr, char *buf)
2720 struct iwl_priv *priv = dev_get_drvdata(d);
2722 return sprintf(buf, "0x%04X\n",
2723 le32_to_cpu(priv->active_rxon.filter_flags));
2726 static ssize_t store_filter_flags(struct device *d,
2727 struct device_attribute *attr,
2728 const char *buf, size_t count)
2730 struct iwl_priv *priv = dev_get_drvdata(d);
2731 unsigned long val;
2732 u32 filter_flags;
2733 int ret = strict_strtoul(buf, 0, &val);
2734 if (ret)
2735 return ret;
2736 filter_flags = (u32)val;
2738 mutex_lock(&priv->mutex);
2739 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
2740 /* Cancel any currently running scans... */
2741 if (iwl_scan_cancel_timeout(priv, 100))
2742 IWL_WARN(priv, "Could not cancel scan.\n");
2743 else {
2744 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
2745 "0x%04X\n", filter_flags);
2746 priv->staging_rxon.filter_flags =
2747 cpu_to_le32(filter_flags);
2748 iwlcore_commit_rxon(priv);
2751 mutex_unlock(&priv->mutex);
2753 return count;
2756 static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
2757 store_filter_flags);
2760 static ssize_t show_statistics(struct device *d,
2761 struct device_attribute *attr, char *buf)
2763 struct iwl_priv *priv = dev_get_drvdata(d);
2764 u32 size = sizeof(struct iwl_notif_statistics);
2765 u32 len = 0, ofs = 0;
2766 u8 *data = (u8 *)&priv->statistics;
2767 int rc = 0;
2769 if (!iwl_is_alive(priv))
2770 return -EAGAIN;
2772 mutex_lock(&priv->mutex);
2773 rc = iwl_send_statistics_request(priv, 0);
2774 mutex_unlock(&priv->mutex);
2776 if (rc) {
2777 len = sprintf(buf,
2778 "Error sending statistics request: 0x%08X\n", rc);
2779 return len;
2782 while (size && (PAGE_SIZE - len)) {
2783 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
2784 PAGE_SIZE - len, 1);
2785 len = strlen(buf);
2786 if (PAGE_SIZE - len)
2787 buf[len++] = '\n';
2789 ofs += 16;
2790 size -= min(size, 16U);
2793 return len;
2796 static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
2799 /*****************************************************************************
2801 * driver setup and teardown
2803 *****************************************************************************/
2805 static void iwl_setup_deferred_work(struct iwl_priv *priv)
2807 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
2809 init_waitqueue_head(&priv->wait_command_queue);
2811 INIT_WORK(&priv->up, iwl_bg_up);
2812 INIT_WORK(&priv->restart, iwl_bg_restart);
2813 INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
2814 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
2815 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
2816 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
2817 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
2819 iwl_setup_scan_deferred_work(priv);
2821 if (priv->cfg->ops->lib->setup_deferred_work)
2822 priv->cfg->ops->lib->setup_deferred_work(priv);
2824 init_timer(&priv->statistics_periodic);
2825 priv->statistics_periodic.data = (unsigned long)priv;
2826 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
2828 if (!priv->cfg->use_isr_legacy)
2829 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
2830 iwl_irq_tasklet, (unsigned long)priv);
2831 else
2832 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
2833 iwl_irq_tasklet_legacy, (unsigned long)priv);
2836 static void iwl_cancel_deferred_work(struct iwl_priv *priv)
2838 if (priv->cfg->ops->lib->cancel_deferred_work)
2839 priv->cfg->ops->lib->cancel_deferred_work(priv);
2841 cancel_delayed_work_sync(&priv->init_alive_start);
2842 cancel_delayed_work(&priv->scan_check);
2843 cancel_delayed_work(&priv->alive_start);
2844 cancel_work_sync(&priv->beacon_update);
2845 del_timer_sync(&priv->statistics_periodic);
2848 static struct attribute *iwl_sysfs_entries[] = {
2849 &dev_attr_flags.attr,
2850 &dev_attr_filter_flags.attr,
2851 &dev_attr_statistics.attr,
2852 &dev_attr_temperature.attr,
2853 &dev_attr_tx_power.attr,
2854 #ifdef CONFIG_IWLWIFI_DEBUG
2855 &dev_attr_debug_level.attr,
2856 #endif
2857 NULL
2860 static struct attribute_group iwl_attribute_group = {
2861 .name = NULL, /* put in device directory */
2862 .attrs = iwl_sysfs_entries,
2865 static struct ieee80211_ops iwl_hw_ops = {
2866 .tx = iwl_mac_tx,
2867 .start = iwl_mac_start,
2868 .stop = iwl_mac_stop,
2869 .add_interface = iwl_mac_add_interface,
2870 .remove_interface = iwl_mac_remove_interface,
2871 .config = iwl_mac_config,
2872 .configure_filter = iwl_configure_filter,
2873 .set_key = iwl_mac_set_key,
2874 .update_tkip_key = iwl_mac_update_tkip_key,
2875 .get_stats = iwl_mac_get_stats,
2876 .get_tx_stats = iwl_mac_get_tx_stats,
2877 .conf_tx = iwl_mac_conf_tx,
2878 .reset_tsf = iwl_mac_reset_tsf,
2879 .bss_info_changed = iwl_bss_info_changed,
2880 .ampdu_action = iwl_mac_ampdu_action,
2881 .hw_scan = iwl_mac_hw_scan
2884 static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2886 int err = 0;
2887 struct iwl_priv *priv;
2888 struct ieee80211_hw *hw;
2889 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
2890 unsigned long flags;
2891 u16 pci_cmd;
2893 /************************
2894 * 1. Allocating HW data
2895 ************************/
2897 /* Disabling hardware scan means that mac80211 will perform scans
2898 * "the hard way", rather than using device's scan. */
2899 if (cfg->mod_params->disable_hw_scan) {
2900 if (iwl_debug_level & IWL_DL_INFO)
2901 dev_printk(KERN_DEBUG, &(pdev->dev),
2902 "Disabling hw_scan\n");
2903 iwl_hw_ops.hw_scan = NULL;
2906 hw = iwl_alloc_all(cfg, &iwl_hw_ops);
2907 if (!hw) {
2908 err = -ENOMEM;
2909 goto out;
2911 priv = hw->priv;
2912 /* At this point both hw and priv are allocated. */
2914 SET_IEEE80211_DEV(hw, &pdev->dev);
2916 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
2917 priv->cfg = cfg;
2918 priv->pci_dev = pdev;
2919 priv->inta_mask = CSR_INI_SET_MASK;
2921 #ifdef CONFIG_IWLWIFI_DEBUG
2922 atomic_set(&priv->restrict_refcnt, 0);
2923 #endif
2924 if (iwl_alloc_traffic_mem(priv))
2925 IWL_ERR(priv, "Not enough memory to generate traffic log\n");
2927 /**************************
2928 * 2. Initializing PCI bus
2929 **************************/
2930 if (pci_enable_device(pdev)) {
2931 err = -ENODEV;
2932 goto out_ieee80211_free_hw;
2935 pci_set_master(pdev);
2937 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
2938 if (!err)
2939 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
2940 if (err) {
2941 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2942 if (!err)
2943 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
2944 /* both attempts failed: */
2945 if (err) {
2946 IWL_WARN(priv, "No suitable DMA available.\n");
2947 goto out_pci_disable_device;
2951 err = pci_request_regions(pdev, DRV_NAME);
2952 if (err)
2953 goto out_pci_disable_device;
2955 pci_set_drvdata(pdev, priv);
2958 /***********************
2959 * 3. Read REV register
2960 ***********************/
2961 priv->hw_base = pci_iomap(pdev, 0, 0);
2962 if (!priv->hw_base) {
2963 err = -ENODEV;
2964 goto out_pci_release_regions;
2967 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
2968 (unsigned long long) pci_resource_len(pdev, 0));
2969 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
2971 /* this spin lock will be used in apm_ops.init and EEPROM access
2972 * we should init now
2974 spin_lock_init(&priv->reg_lock);
2975 iwl_hw_detect(priv);
2976 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s REV=0x%X\n",
2977 priv->cfg->name, priv->hw_rev);
2979 /* We disable the RETRY_TIMEOUT register (0x41) to keep
2980 * PCI Tx retries from interfering with C3 CPU state */
2981 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
2983 iwl_prepare_card_hw(priv);
2984 if (!priv->hw_ready) {
2985 IWL_WARN(priv, "Failed, HW not ready\n");
2986 goto out_iounmap;
2989 /* amp init */
2990 err = priv->cfg->ops->lib->apm_ops.init(priv);
2991 if (err < 0) {
2992 IWL_ERR(priv, "Failed to init APMG\n");
2993 goto out_iounmap;
2995 /*****************
2996 * 4. Read EEPROM
2997 *****************/
2998 /* Read the EEPROM */
2999 err = iwl_eeprom_init(priv);
3000 if (err) {
3001 IWL_ERR(priv, "Unable to init EEPROM\n");
3002 goto out_iounmap;
3004 err = iwl_eeprom_check_version(priv);
3005 if (err)
3006 goto out_free_eeprom;
3008 /* extract MAC Address */
3009 iwl_eeprom_get_mac(priv, priv->mac_addr);
3010 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
3011 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
3013 /************************
3014 * 5. Setup HW constants
3015 ************************/
3016 if (iwl_set_hw_params(priv)) {
3017 IWL_ERR(priv, "failed to set hw parameters\n");
3018 goto out_free_eeprom;
3021 /*******************
3022 * 6. Setup priv
3023 *******************/
3025 err = iwl_init_drv(priv);
3026 if (err)
3027 goto out_free_eeprom;
3028 /* At this point both hw and priv are initialized. */
3030 /********************
3031 * 7. Setup services
3032 ********************/
3033 spin_lock_irqsave(&priv->lock, flags);
3034 iwl_disable_interrupts(priv);
3035 spin_unlock_irqrestore(&priv->lock, flags);
3037 pci_enable_msi(priv->pci_dev);
3039 iwl_alloc_isr_ict(priv);
3040 err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
3041 IRQF_SHARED, DRV_NAME, priv);
3042 if (err) {
3043 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
3044 goto out_disable_msi;
3046 err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group);
3047 if (err) {
3048 IWL_ERR(priv, "failed to create sysfs device attributes\n");
3049 goto out_free_irq;
3052 iwl_setup_deferred_work(priv);
3053 iwl_setup_rx_handlers(priv);
3055 /**********************************
3056 * 8. Setup and register mac80211
3057 **********************************/
3059 /* enable interrupts if needed: hw bug w/a */
3060 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
3061 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
3062 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
3063 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
3066 iwl_enable_interrupts(priv);
3068 err = iwl_setup_mac(priv);
3069 if (err)
3070 goto out_remove_sysfs;
3072 err = iwl_dbgfs_register(priv, DRV_NAME);
3073 if (err)
3074 IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
3076 /* If platform's RF_KILL switch is NOT set to KILL */
3077 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3078 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3079 else
3080 set_bit(STATUS_RF_KILL_HW, &priv->status);
3082 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
3083 test_bit(STATUS_RF_KILL_HW, &priv->status));
3085 iwl_power_initialize(priv);
3086 iwl_tt_initialize(priv);
3087 return 0;
3089 out_remove_sysfs:
3090 destroy_workqueue(priv->workqueue);
3091 priv->workqueue = NULL;
3092 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
3093 out_free_irq:
3094 free_irq(priv->pci_dev->irq, priv);
3095 iwl_free_isr_ict(priv);
3096 out_disable_msi:
3097 pci_disable_msi(priv->pci_dev);
3098 iwl_uninit_drv(priv);
3099 out_free_eeprom:
3100 iwl_eeprom_free(priv);
3101 out_iounmap:
3102 pci_iounmap(pdev, priv->hw_base);
3103 out_pci_release_regions:
3104 pci_set_drvdata(pdev, NULL);
3105 pci_release_regions(pdev);
3106 out_pci_disable_device:
3107 pci_disable_device(pdev);
3108 out_ieee80211_free_hw:
3109 iwl_free_traffic_mem(priv);
3110 ieee80211_free_hw(priv->hw);
3111 out:
3112 return err;
3115 static void __devexit iwl_pci_remove(struct pci_dev *pdev)
3117 struct iwl_priv *priv = pci_get_drvdata(pdev);
3118 unsigned long flags;
3120 if (!priv)
3121 return;
3123 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
3125 iwl_dbgfs_unregister(priv);
3126 sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
3128 /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
3129 * to be called and iwl_down since we are removing the device
3130 * we need to set STATUS_EXIT_PENDING bit.
3132 set_bit(STATUS_EXIT_PENDING, &priv->status);
3133 if (priv->mac80211_registered) {
3134 ieee80211_unregister_hw(priv->hw);
3135 priv->mac80211_registered = 0;
3136 } else {
3137 iwl_down(priv);
3140 iwl_tt_exit(priv);
3142 /* make sure we flush any pending irq or
3143 * tasklet for the driver
3145 spin_lock_irqsave(&priv->lock, flags);
3146 iwl_disable_interrupts(priv);
3147 spin_unlock_irqrestore(&priv->lock, flags);
3149 iwl_synchronize_irq(priv);
3151 iwl_dealloc_ucode_pci(priv);
3153 if (priv->rxq.bd)
3154 iwl_rx_queue_free(priv, &priv->rxq);
3155 iwl_hw_txq_ctx_free(priv);
3157 iwl_clear_stations_table(priv);
3158 iwl_eeprom_free(priv);
3161 /*netif_stop_queue(dev); */
3162 flush_workqueue(priv->workqueue);
3164 /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
3165 * priv->workqueue... so we can't take down the workqueue
3166 * until now... */
3167 destroy_workqueue(priv->workqueue);
3168 priv->workqueue = NULL;
3169 iwl_free_traffic_mem(priv);
3171 free_irq(priv->pci_dev->irq, priv);
3172 pci_disable_msi(priv->pci_dev);
3173 pci_iounmap(pdev, priv->hw_base);
3174 pci_release_regions(pdev);
3175 pci_disable_device(pdev);
3176 pci_set_drvdata(pdev, NULL);
3178 iwl_uninit_drv(priv);
3180 iwl_free_isr_ict(priv);
3182 if (priv->ibss_beacon)
3183 dev_kfree_skb(priv->ibss_beacon);
3185 ieee80211_free_hw(priv->hw);
3189 /*****************************************************************************
3191 * driver and module entry point
3193 *****************************************************************************/
3195 /* Hardware specific file defines the PCI IDs table for that hardware module */
3196 static struct pci_device_id iwl_hw_card_ids[] = {
3197 #ifdef CONFIG_IWL4965
3198 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
3199 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
3200 #endif /* CONFIG_IWL4965 */
3201 #ifdef CONFIG_IWL5000
3202 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bg_cfg)},
3203 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bg_cfg)},
3204 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)},
3205 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)},
3206 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)},
3207 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)},
3208 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
3209 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
3210 {IWL_PCI_DEVICE(0x4236, PCI_ANY_ID, iwl5300_agn_cfg)},
3211 {IWL_PCI_DEVICE(0x4237, PCI_ANY_ID, iwl5100_agn_cfg)},
3212 /* 5350 WiFi/WiMax */
3213 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)},
3214 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)},
3215 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)},
3216 /* 5150 Wifi/WiMax */
3217 {IWL_PCI_DEVICE(0x423C, PCI_ANY_ID, iwl5150_agn_cfg)},
3218 {IWL_PCI_DEVICE(0x423D, PCI_ANY_ID, iwl5150_agn_cfg)},
3219 /* 6000/6050 Series */
3220 {IWL_PCI_DEVICE(0x008D, PCI_ANY_ID, iwl6000h_2agn_cfg)},
3221 {IWL_PCI_DEVICE(0x008E, PCI_ANY_ID, iwl6000h_2agn_cfg)},
3222 {IWL_PCI_DEVICE(0x422B, PCI_ANY_ID, iwl6000_3agn_cfg)},
3223 {IWL_PCI_DEVICE(0x422C, PCI_ANY_ID, iwl6000i_2agn_cfg)},
3224 {IWL_PCI_DEVICE(0x4238, PCI_ANY_ID, iwl6000_3agn_cfg)},
3225 {IWL_PCI_DEVICE(0x4239, PCI_ANY_ID, iwl6000i_2agn_cfg)},
3226 {IWL_PCI_DEVICE(0x0086, PCI_ANY_ID, iwl6050_3agn_cfg)},
3227 {IWL_PCI_DEVICE(0x0087, PCI_ANY_ID, iwl6050_2agn_cfg)},
3228 {IWL_PCI_DEVICE(0x0088, PCI_ANY_ID, iwl6050_3agn_cfg)},
3229 {IWL_PCI_DEVICE(0x0089, PCI_ANY_ID, iwl6050_2agn_cfg)},
3230 /* 1000 Series WiFi */
3231 {IWL_PCI_DEVICE(0x0083, PCI_ANY_ID, iwl1000_bgn_cfg)},
3232 {IWL_PCI_DEVICE(0x0084, PCI_ANY_ID, iwl1000_bgn_cfg)},
3233 #endif /* CONFIG_IWL5000 */
3237 MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
3239 static struct pci_driver iwl_driver = {
3240 .name = DRV_NAME,
3241 .id_table = iwl_hw_card_ids,
3242 .probe = iwl_pci_probe,
3243 .remove = __devexit_p(iwl_pci_remove),
3244 #ifdef CONFIG_PM
3245 .suspend = iwl_pci_suspend,
3246 .resume = iwl_pci_resume,
3247 #endif
3250 static int __init iwl_init(void)
3253 int ret;
3254 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
3255 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
3257 ret = iwlagn_rate_control_register();
3258 if (ret) {
3259 printk(KERN_ERR DRV_NAME
3260 "Unable to register rate control algorithm: %d\n", ret);
3261 return ret;
3264 ret = pci_register_driver(&iwl_driver);
3265 if (ret) {
3266 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
3267 goto error_register;
3270 return ret;
3272 error_register:
3273 iwlagn_rate_control_unregister();
3274 return ret;
3277 static void __exit iwl_exit(void)
3279 pci_unregister_driver(&iwl_driver);
3280 iwlagn_rate_control_unregister();
3283 module_exit(iwl_exit);
3284 module_init(iwl_init);
3286 #ifdef CONFIG_IWLWIFI_DEBUG
3287 module_param_named(debug50, iwl_debug_level, uint, 0444);
3288 MODULE_PARM_DESC(debug50, "50XX debug output mask (deprecated)");
3289 module_param_named(debug, iwl_debug_level, uint, 0644);
3290 MODULE_PARM_DESC(debug, "debug output mask");
3291 #endif