1 /******************************************************************************
3 * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #include <linux/kernel.h>
33 #include <linux/module.h>
34 #include <linux/init.h>
35 #include <linux/slab.h>
36 #include <linux/delay.h>
37 #include <linux/sched.h>
38 #include <linux/skbuff.h>
39 #include <linux/netdevice.h>
40 #include <linux/etherdevice.h>
41 #include <linux/if_arp.h>
43 #include <net/mac80211.h>
45 #include <asm/div64.h>
47 #include "iwl-eeprom-read.h"
48 #include "iwl-eeprom-parse.h"
50 #include "iwl-trans.h"
51 #include "iwl-op-mode.h"
53 #include "iwl-modparams.h"
59 /******************************************************************************
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
76 #define DRV_VERSION IWLWIFI_VERSION VD
79 MODULE_DESCRIPTION(DRV_DESCRIPTION);
80 MODULE_VERSION(DRV_VERSION);
81 MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
82 MODULE_LICENSE("GPL");
84 void iwl_update_chain_flags(struct iwl_priv *priv)
86 struct iwl_rxon_context *ctx;
88 for_each_context(priv, ctx) {
89 iwlagn_set_rxon_chain(priv, ctx);
90 if (ctx->active.rx_chain != ctx->staging.rx_chain)
91 iwlagn_commit_rxon(priv, ctx);
95 /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
96 static void iwl_set_beacon_tim(struct iwl_priv *priv,
97 struct iwl_tx_beacon_cmd *tx_beacon_cmd,
98 u8 *beacon, u32 frame_size)
101 struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
104 * The index is relative to frame start but we start looking at the
105 * variable-length part of the beacon.
107 tim_idx = mgmt->u.beacon.variable - beacon;
109 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
110 while ((tim_idx < (frame_size - 2)) &&
111 (beacon[tim_idx] != WLAN_EID_TIM))
112 tim_idx += beacon[tim_idx+1] + 2;
114 /* If TIM field was found, set variables */
115 if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
116 tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
117 tx_beacon_cmd->tim_size = beacon[tim_idx+1];
119 IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
122 int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
124 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
125 struct iwl_host_cmd cmd = {
126 .id = REPLY_TX_BEACON,
129 struct ieee80211_tx_info *info;
135 * We have to set up the TX command, the TX Beacon command, and the
139 lockdep_assert_held(&priv->mutex);
141 if (!priv->beacon_ctx) {
142 IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
146 if (WARN_ON(!priv->beacon_skb))
149 /* Allocate beacon command */
150 if (!priv->beacon_cmd)
151 priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL);
152 tx_beacon_cmd = priv->beacon_cmd;
156 frame_size = priv->beacon_skb->len;
158 /* Set up TX command fields */
159 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
160 tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
161 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
162 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
163 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
165 /* Set up TX beacon command fields */
166 iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data,
169 /* Set up packet rate and flags */
170 info = IEEE80211_SKB_CB(priv->beacon_skb);
173 * Let's set up the rate at least somewhat correctly;
174 * it will currently not actually be used by the uCode,
175 * it uses the broadcast station's rate instead.
177 if (info->control.rates[0].idx < 0 ||
178 info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
181 rate = info->control.rates[0].idx;
183 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
184 priv->eeprom_data->valid_tx_ant);
185 rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
187 /* In mac80211, rates for 5 GHz start at 0 */
188 if (info->band == IEEE80211_BAND_5GHZ)
189 rate += IWL_FIRST_OFDM_RATE;
190 else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE)
191 rate_flags |= RATE_MCS_CCK_MSK;
193 tx_beacon_cmd->tx.rate_n_flags =
194 iwl_hw_set_rate_n_flags(rate, rate_flags);
197 cmd.len[0] = sizeof(*tx_beacon_cmd);
198 cmd.data[0] = tx_beacon_cmd;
199 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
200 cmd.len[1] = frame_size;
201 cmd.data[1] = priv->beacon_skb->data;
202 cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
204 return iwl_dvm_send_cmd(priv, &cmd);
207 static void iwl_bg_beacon_update(struct work_struct *work)
209 struct iwl_priv *priv =
210 container_of(work, struct iwl_priv, beacon_update);
211 struct sk_buff *beacon;
213 mutex_lock(&priv->mutex);
214 if (!priv->beacon_ctx) {
215 IWL_ERR(priv, "updating beacon w/o beacon context!\n");
219 if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
221 * The ucode will send beacon notifications even in
222 * IBSS mode, but we don't want to process them. But
223 * we need to defer the type check to here due to
224 * requiring locking around the beacon_ctx access.
229 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
230 beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
232 IWL_ERR(priv, "update beacon failed -- keeping old\n");
236 /* new beacon skb is allocated every time; dispose previous.*/
237 dev_kfree_skb(priv->beacon_skb);
239 priv->beacon_skb = beacon;
241 iwlagn_send_beacon_cmd(priv);
243 mutex_unlock(&priv->mutex);
246 static void iwl_bg_bt_runtime_config(struct work_struct *work)
248 struct iwl_priv *priv =
249 container_of(work, struct iwl_priv, bt_runtime_config);
251 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
254 /* dont send host command if rf-kill is on */
255 if (!iwl_is_ready_rf(priv))
257 iwlagn_send_advance_bt_config(priv);
260 static void iwl_bg_bt_full_concurrency(struct work_struct *work)
262 struct iwl_priv *priv =
263 container_of(work, struct iwl_priv, bt_full_concurrency);
264 struct iwl_rxon_context *ctx;
266 mutex_lock(&priv->mutex);
268 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
271 /* dont send host command if rf-kill is on */
272 if (!iwl_is_ready_rf(priv))
275 IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
276 priv->bt_full_concurrent ?
277 "full concurrency" : "3-wire");
280 * LQ & RXON updated cmds must be sent before BT Config cmd
281 * to avoid 3-wire collisions
283 for_each_context(priv, ctx) {
284 iwlagn_set_rxon_chain(priv, ctx);
285 iwlagn_commit_rxon(priv, ctx);
288 iwlagn_send_advance_bt_config(priv);
290 mutex_unlock(&priv->mutex);
293 int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
295 struct iwl_statistics_cmd statistics_cmd = {
296 .configuration_flags =
297 clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
300 if (flags & CMD_ASYNC)
301 return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
303 sizeof(struct iwl_statistics_cmd),
306 return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
308 sizeof(struct iwl_statistics_cmd),
313 * iwl_bg_statistics_periodic - Timer callback to queue statistics
315 * This callback is provided in order to send a statistics request.
317 * This timer function is continually reset to execute within
318 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
319 * was received. We need to ensure we receive the statistics in order
320 * to update the temperature used for calibrating the TXPOWER.
322 static void iwl_bg_statistics_periodic(unsigned long data)
324 struct iwl_priv *priv = (struct iwl_priv *)data;
326 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
329 /* dont send host command if rf-kill is on */
330 if (!iwl_is_ready_rf(priv))
333 iwl_send_statistics_request(priv, CMD_ASYNC, false);
337 static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
338 u32 start_idx, u32 num_events,
339 u32 capacity, u32 mode)
342 u32 ptr; /* SRAM byte address of log data */
343 u32 ev, time, data; /* event log data */
344 unsigned long reg_flags;
347 ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
349 ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
351 /* Make sure device is powered up for SRAM reads */
352 spin_lock_irqsave(&priv->trans->reg_lock, reg_flags);
353 if (unlikely(!iwl_grab_nic_access(priv->trans))) {
354 spin_unlock_irqrestore(&priv->trans->reg_lock, reg_flags);
358 /* Set starting address; reads will auto-increment */
359 iwl_write32(priv->trans, HBUS_TARG_MEM_RADDR, ptr);
362 * Refuse to read more than would have fit into the log from
363 * the current start_idx. This used to happen due to the race
364 * described below, but now WARN because the code below should
365 * prevent it from happening here.
367 if (WARN_ON(num_events > capacity - start_idx))
368 num_events = capacity - start_idx;
371 * "time" is actually "data" for mode 0 (no timestamp).
372 * place event id # at far right for easier visual parsing.
374 for (i = 0; i < num_events; i++) {
375 ev = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
376 time = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
378 trace_iwlwifi_dev_ucode_cont_event(
379 priv->trans->dev, 0, time, ev);
381 data = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
382 trace_iwlwifi_dev_ucode_cont_event(
383 priv->trans->dev, time, data, ev);
386 /* Allow device to power down */
387 iwl_release_nic_access(priv->trans);
388 spin_unlock_irqrestore(&priv->trans->reg_lock, reg_flags);
391 static void iwl_continuous_event_trace(struct iwl_priv *priv)
393 u32 capacity; /* event log capacity in # entries */
400 u32 base; /* SRAM byte address of event log header */
401 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
402 u32 num_wraps; /* # times uCode wrapped to top of log */
403 u32 next_entry; /* index of next entry to be written by uCode */
405 base = priv->device_pointers.log_event_table;
406 if (iwlagn_hw_valid_rtc_data_addr(base)) {
407 iwl_read_targ_mem_words(priv->trans, base, &read, sizeof(read));
408 capacity = read.capacity;
410 num_wraps = read.wrap_counter;
411 next_entry = read.write_counter;
416 * Unfortunately, the uCode doesn't use temporary variables.
417 * Therefore, it can happen that we read next_entry == capacity,
418 * which really means next_entry == 0.
420 if (unlikely(next_entry == capacity))
423 * Additionally, the uCode increases the write pointer before
424 * the wraps counter, so if the write pointer is smaller than
425 * the old write pointer (wrap occurred) but we read that no
426 * wrap occurred, we actually read between the next_entry and
427 * num_wraps update (this does happen in practice!!) -- take
428 * that into account by increasing num_wraps.
430 if (unlikely(next_entry < priv->event_log.next_entry &&
431 num_wraps == priv->event_log.num_wraps))
434 if (num_wraps == priv->event_log.num_wraps) {
435 iwl_print_cont_event_trace(
436 priv, base, priv->event_log.next_entry,
437 next_entry - priv->event_log.next_entry,
440 priv->event_log.non_wraps_count++;
442 if (num_wraps - priv->event_log.num_wraps > 1)
443 priv->event_log.wraps_more_count++;
445 priv->event_log.wraps_once_count++;
447 trace_iwlwifi_dev_ucode_wrap_event(priv->trans->dev,
448 num_wraps - priv->event_log.num_wraps,
449 next_entry, priv->event_log.next_entry);
451 if (next_entry < priv->event_log.next_entry) {
452 iwl_print_cont_event_trace(
453 priv, base, priv->event_log.next_entry,
454 capacity - priv->event_log.next_entry,
457 iwl_print_cont_event_trace(
458 priv, base, 0, next_entry, capacity, mode);
460 iwl_print_cont_event_trace(
461 priv, base, next_entry,
462 capacity - next_entry,
465 iwl_print_cont_event_trace(
466 priv, base, 0, next_entry, capacity, mode);
470 priv->event_log.num_wraps = num_wraps;
471 priv->event_log.next_entry = next_entry;
475 * iwl_bg_ucode_trace - Timer callback to log ucode event
477 * The timer is continually set to execute every
478 * UCODE_TRACE_PERIOD milliseconds after the last timer expired
479 * this function is to perform continuous uCode event logging operation
482 static void iwl_bg_ucode_trace(unsigned long data)
484 struct iwl_priv *priv = (struct iwl_priv *)data;
486 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
489 if (priv->event_log.ucode_trace) {
490 iwl_continuous_event_trace(priv);
491 /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
492 mod_timer(&priv->ucode_trace,
493 jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
497 static void iwl_bg_tx_flush(struct work_struct *work)
499 struct iwl_priv *priv =
500 container_of(work, struct iwl_priv, tx_flush);
502 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
505 /* do nothing if rf-kill is on */
506 if (!iwl_is_ready_rf(priv))
509 IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
510 iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
514 * queue/FIFO/AC mapping definitions
517 #define IWL_TX_FIFO_BK 0 /* shared */
518 #define IWL_TX_FIFO_BE 1
519 #define IWL_TX_FIFO_VI 2 /* shared */
520 #define IWL_TX_FIFO_VO 3
521 #define IWL_TX_FIFO_BK_IPAN IWL_TX_FIFO_BK
522 #define IWL_TX_FIFO_BE_IPAN 4
523 #define IWL_TX_FIFO_VI_IPAN IWL_TX_FIFO_VI
524 #define IWL_TX_FIFO_VO_IPAN 5
525 /* re-uses the VO FIFO, uCode will properly flush/schedule */
526 #define IWL_TX_FIFO_AUX 5
527 #define IWL_TX_FIFO_UNUSED -1
529 #define IWLAGN_CMD_FIFO_NUM 7
532 * This queue number is required for proper operation
533 * because the ucode will stop/start the scheduler as
536 #define IWL_IPAN_MCAST_QUEUE 8
538 static const u8 iwlagn_default_queue_to_tx_fifo[] = {
546 static const u8 iwlagn_ipan_queue_to_tx_fifo[] = {
560 static const u8 iwlagn_bss_ac_to_fifo[] = {
567 static const u8 iwlagn_bss_ac_to_queue[] = {
571 static const u8 iwlagn_pan_ac_to_fifo[] = {
578 static const u8 iwlagn_pan_ac_to_queue[] = {
582 static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
587 * The default context is always valid,
588 * the PAN context depends on uCode.
590 priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
591 if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN)
592 priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
594 for (i = 0; i < NUM_IWL_RXON_CTX; i++)
595 priv->contexts[i].ctxid = i;
597 priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
598 priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
599 priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
600 priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
601 priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
602 priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
603 priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
604 priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
605 priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
606 priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
607 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_MONITOR);
608 priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
609 BIT(NL80211_IFTYPE_STATION);
610 priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
611 priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
612 priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
613 priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
614 memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue,
615 iwlagn_bss_ac_to_queue, sizeof(iwlagn_bss_ac_to_queue));
616 memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo,
617 iwlagn_bss_ac_to_fifo, sizeof(iwlagn_bss_ac_to_fifo));
619 priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
620 priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
621 REPLY_WIPAN_RXON_TIMING;
622 priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
623 REPLY_WIPAN_RXON_ASSOC;
624 priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
625 priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
626 priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
627 priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
628 priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
629 priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
630 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
632 if (ucode_flags & IWL_UCODE_TLV_FLAGS_P2P)
633 priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
634 BIT(NL80211_IFTYPE_P2P_CLIENT) |
635 BIT(NL80211_IFTYPE_P2P_GO);
637 priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
638 priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
639 priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
640 memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue,
641 iwlagn_pan_ac_to_queue, sizeof(iwlagn_pan_ac_to_queue));
642 memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo,
643 iwlagn_pan_ac_to_fifo, sizeof(iwlagn_pan_ac_to_fifo));
644 priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
646 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
649 static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
651 struct iwl_ct_kill_config cmd;
652 struct iwl_ct_kill_throttling_config adv_cmd;
655 iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR,
656 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
658 priv->thermal_throttle.ct_kill_toggle = false;
660 if (priv->cfg->base_params->support_ct_kill_exit) {
661 adv_cmd.critical_temperature_enter =
662 cpu_to_le32(priv->hw_params.ct_kill_threshold);
663 adv_cmd.critical_temperature_exit =
664 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
666 ret = iwl_dvm_send_cmd_pdu(priv,
667 REPLY_CT_KILL_CONFIG_CMD,
668 CMD_SYNC, sizeof(adv_cmd), &adv_cmd);
670 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
672 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
673 "succeeded, critical temperature enter is %d,"
675 priv->hw_params.ct_kill_threshold,
676 priv->hw_params.ct_kill_exit_threshold);
678 cmd.critical_temperature_R =
679 cpu_to_le32(priv->hw_params.ct_kill_threshold);
681 ret = iwl_dvm_send_cmd_pdu(priv,
682 REPLY_CT_KILL_CONFIG_CMD,
683 CMD_SYNC, sizeof(cmd), &cmd);
685 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
687 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
689 "critical temperature is %d\n",
690 priv->hw_params.ct_kill_threshold);
694 static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
696 struct iwl_calib_cfg_cmd calib_cfg_cmd;
697 struct iwl_host_cmd cmd = {
698 .id = CALIBRATION_CFG_CMD,
699 .len = { sizeof(struct iwl_calib_cfg_cmd), },
700 .data = { &calib_cfg_cmd, },
703 memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
704 calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL;
705 calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
707 return iwl_dvm_send_cmd(priv, &cmd);
711 static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
713 struct iwl_tx_ant_config_cmd tx_ant_cmd = {
714 .valid = cpu_to_le32(valid_tx_ant),
717 if (IWL_UCODE_API(priv->fw->ucode_ver) > 1) {
718 IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
719 return iwl_dvm_send_cmd_pdu(priv,
720 TX_ANT_CONFIGURATION_CMD,
722 sizeof(struct iwl_tx_ant_config_cmd),
725 IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
730 static void iwl_send_bt_config(struct iwl_priv *priv)
732 struct iwl_bt_cmd bt_cmd = {
733 .lead_time = BT_LEAD_TIME_DEF,
734 .max_kill = BT_MAX_KILL_DEF,
739 if (!iwlwifi_mod_params.bt_coex_active)
740 bt_cmd.flags = BT_COEX_DISABLE;
742 bt_cmd.flags = BT_COEX_ENABLE;
744 priv->bt_enable_flag = bt_cmd.flags;
745 IWL_DEBUG_INFO(priv, "BT coex %s\n",
746 (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
748 if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
749 CMD_SYNC, sizeof(struct iwl_bt_cmd), &bt_cmd))
750 IWL_ERR(priv, "failed to send BT Coex Config\n");
754 * iwl_alive_start - called after REPLY_ALIVE notification received
755 * from protocol/runtime uCode (initialization uCode's
756 * Alive gets handled by iwl_init_alive_start()).
758 int iwl_alive_start(struct iwl_priv *priv)
761 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
763 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
765 /* After the ALIVE response, we can send host commands to the uCode */
766 set_bit(STATUS_ALIVE, &priv->status);
768 if (iwl_is_rfkill(priv))
771 if (priv->event_log.ucode_trace) {
772 /* start collecting data now */
773 mod_timer(&priv->ucode_trace, jiffies);
776 /* download priority table before any calibration request */
777 if (priv->cfg->bt_params &&
778 priv->cfg->bt_params->advanced_bt_coexist) {
779 /* Configure Bluetooth device coexistence support */
780 if (priv->cfg->bt_params->bt_sco_disable)
781 priv->bt_enable_pspoll = false;
783 priv->bt_enable_pspoll = true;
785 priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
786 priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
787 priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
788 iwlagn_send_advance_bt_config(priv);
789 priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
790 priv->cur_rssi_ctx = NULL;
792 iwl_send_prio_tbl(priv);
794 /* FIXME: w/a to force change uCode BT state machine */
795 ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
796 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
799 ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
800 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
805 * default is 2-wire BT coexexistence support
807 iwl_send_bt_config(priv);
811 * Perform runtime calibrations, including DC calibration.
813 iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX);
815 ieee80211_wake_queues(priv->hw);
817 /* Configure Tx antenna selection based on H/W config */
818 iwlagn_send_tx_ant_config(priv, priv->eeprom_data->valid_tx_ant);
820 if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
821 struct iwl_rxon_cmd *active_rxon =
822 (struct iwl_rxon_cmd *)&ctx->active;
823 /* apply any changes in staging */
824 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
825 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
827 struct iwl_rxon_context *tmp;
828 /* Initialize our rx_config data */
829 for_each_context(priv, tmp)
830 iwl_connection_init_rx_config(priv, tmp);
832 iwlagn_set_rxon_chain(priv, ctx);
836 /* WoWLAN ucode will not reply in the same way, skip it */
837 iwl_reset_run_time_calib(priv);
840 set_bit(STATUS_READY, &priv->status);
842 /* Configure the adapter for unassociated operation */
843 ret = iwlagn_commit_rxon(priv, ctx);
847 /* At this point, the NIC is initialized and operational */
848 iwl_rf_kill_ct_config(priv);
850 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
852 return iwl_power_update_mode(priv, true);
856 * iwl_clear_driver_stations - clear knowledge of all stations from driver
857 * @priv: iwl priv struct
859 * This is called during iwl_down() to make sure that in the case
860 * we're coming there from a hardware restart mac80211 will be
861 * able to reconfigure stations -- if we're getting there in the
862 * normal down flow then the stations will already be cleared.
864 static void iwl_clear_driver_stations(struct iwl_priv *priv)
866 struct iwl_rxon_context *ctx;
868 spin_lock_bh(&priv->sta_lock);
869 memset(priv->stations, 0, sizeof(priv->stations));
870 priv->num_stations = 0;
872 priv->ucode_key_table = 0;
874 for_each_context(priv, ctx) {
876 * Remove all key information that is not stored as part
877 * of station information since mac80211 may not have had
878 * a chance to remove all the keys. When device is
879 * reconfigured by mac80211 after an error all keys will
882 memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
883 ctx->key_mapping_keys = 0;
886 spin_unlock_bh(&priv->sta_lock);
889 void iwl_down(struct iwl_priv *priv)
893 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
895 lockdep_assert_held(&priv->mutex);
897 iwl_scan_cancel_timeout(priv, 200);
900 * If active, scanning won't cancel it, so say it expired.
901 * No race since we hold the mutex here and a new one
902 * can't come in at this time.
904 ieee80211_remain_on_channel_expired(priv->hw);
907 test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
909 iwl_clear_ucode_stations(priv, NULL);
910 iwl_dealloc_bcast_stations(priv);
911 iwl_clear_driver_stations(priv);
913 /* reset BT coex data */
915 priv->cur_rssi_ctx = NULL;
917 if (priv->cfg->bt_params)
918 priv->bt_traffic_load =
919 priv->cfg->bt_params->bt_init_traffic_load;
921 priv->bt_traffic_load = 0;
922 priv->bt_full_concurrent = false;
923 priv->bt_ci_compliance = 0;
925 /* Wipe out the EXIT_PENDING status bit if we are not actually
926 * exiting the module */
928 clear_bit(STATUS_EXIT_PENDING, &priv->status);
930 if (priv->mac80211_registered)
931 ieee80211_stop_queues(priv->hw);
933 priv->ucode_loaded = false;
934 iwl_trans_stop_device(priv->trans);
936 /* Set num_aux_in_flight must be done after the transport is stopped */
937 atomic_set(&priv->num_aux_in_flight, 0);
939 /* Clear out all status bits but a few that are stable across reset */
940 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
942 test_bit(STATUS_FW_ERROR, &priv->status) <<
944 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
947 dev_kfree_skb(priv->beacon_skb);
948 priv->beacon_skb = NULL;
951 /*****************************************************************************
953 * Workqueue callbacks
955 *****************************************************************************/
957 static void iwl_bg_run_time_calib_work(struct work_struct *work)
959 struct iwl_priv *priv = container_of(work, struct iwl_priv,
960 run_time_calib_work);
962 mutex_lock(&priv->mutex);
964 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
965 test_bit(STATUS_SCANNING, &priv->status)) {
966 mutex_unlock(&priv->mutex);
970 if (priv->start_calib) {
971 iwl_chain_noise_calibration(priv);
972 iwl_sensitivity_calibration(priv);
975 mutex_unlock(&priv->mutex);
978 void iwlagn_prepare_restart(struct iwl_priv *priv)
980 bool bt_full_concurrent;
987 lockdep_assert_held(&priv->mutex);
992 * __iwl_down() will clear the BT status variables,
993 * which is correct, but when we restart we really
994 * want to keep them so restore them afterwards.
996 * The restart process will later pick them up and
997 * re-configure the hw when we reconfigure the BT
1000 bt_full_concurrent = priv->bt_full_concurrent;
1001 bt_ci_compliance = priv->bt_ci_compliance;
1002 bt_load = priv->bt_traffic_load;
1003 bt_status = priv->bt_status;
1004 bt_is_sco = priv->bt_is_sco;
1008 priv->bt_full_concurrent = bt_full_concurrent;
1009 priv->bt_ci_compliance = bt_ci_compliance;
1010 priv->bt_traffic_load = bt_load;
1011 priv->bt_status = bt_status;
1012 priv->bt_is_sco = bt_is_sco;
1014 /* reset aggregation queues */
1015 for (i = IWLAGN_FIRST_AMPDU_QUEUE; i < IWL_MAX_HW_QUEUES; i++)
1016 priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
1017 /* and stop counts */
1018 for (i = 0; i < IWL_MAX_HW_QUEUES; i++)
1019 atomic_set(&priv->queue_stop_count[i], 0);
1021 memset(priv->agg_q_alloc, 0, sizeof(priv->agg_q_alloc));
1024 static void iwl_bg_restart(struct work_struct *data)
1026 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
1028 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1031 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
1032 mutex_lock(&priv->mutex);
1033 iwlagn_prepare_restart(priv);
1034 mutex_unlock(&priv->mutex);
1035 iwl_cancel_deferred_work(priv);
1036 ieee80211_restart_hw(priv->hw);
1045 void iwlagn_disable_roc(struct iwl_priv *priv)
1047 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
1049 lockdep_assert_held(&priv->mutex);
1051 if (!priv->hw_roc_setup)
1054 ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
1055 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1057 priv->hw_roc_channel = NULL;
1059 memset(ctx->staging.node_addr, 0, ETH_ALEN);
1061 iwlagn_commit_rxon(priv, ctx);
1063 ctx->is_active = false;
1064 priv->hw_roc_setup = false;
1067 static void iwlagn_disable_roc_work(struct work_struct *work)
1069 struct iwl_priv *priv = container_of(work, struct iwl_priv,
1070 hw_roc_disable_work.work);
1072 mutex_lock(&priv->mutex);
1073 iwlagn_disable_roc(priv);
1074 mutex_unlock(&priv->mutex);
1077 /*****************************************************************************
1079 * driver setup and teardown
1081 *****************************************************************************/
1083 static void iwl_setup_deferred_work(struct iwl_priv *priv)
1085 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
1087 INIT_WORK(&priv->restart, iwl_bg_restart);
1088 INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
1089 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
1090 INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
1091 INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
1092 INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
1093 INIT_DELAYED_WORK(&priv->hw_roc_disable_work,
1094 iwlagn_disable_roc_work);
1096 iwl_setup_scan_deferred_work(priv);
1098 if (priv->cfg->bt_params)
1099 iwlagn_bt_setup_deferred_work(priv);
1101 init_timer(&priv->statistics_periodic);
1102 priv->statistics_periodic.data = (unsigned long)priv;
1103 priv->statistics_periodic.function = iwl_bg_statistics_periodic;
1105 init_timer(&priv->ucode_trace);
1106 priv->ucode_trace.data = (unsigned long)priv;
1107 priv->ucode_trace.function = iwl_bg_ucode_trace;
1110 void iwl_cancel_deferred_work(struct iwl_priv *priv)
1112 if (priv->cfg->bt_params)
1113 iwlagn_bt_cancel_deferred_work(priv);
1115 cancel_work_sync(&priv->run_time_calib_work);
1116 cancel_work_sync(&priv->beacon_update);
1118 iwl_cancel_scan_deferred_work(priv);
1120 cancel_work_sync(&priv->bt_full_concurrency);
1121 cancel_work_sync(&priv->bt_runtime_config);
1122 cancel_delayed_work_sync(&priv->hw_roc_disable_work);
1124 del_timer_sync(&priv->statistics_periodic);
1125 del_timer_sync(&priv->ucode_trace);
1128 static int iwl_init_drv(struct iwl_priv *priv)
1130 spin_lock_init(&priv->sta_lock);
1132 mutex_init(&priv->mutex);
1134 INIT_LIST_HEAD(&priv->calib_results);
1136 priv->band = IEEE80211_BAND_2GHZ;
1138 priv->plcp_delta_threshold =
1139 priv->cfg->base_params->plcp_delta_threshold;
1141 priv->iw_mode = NL80211_IFTYPE_STATION;
1142 priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
1143 priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
1144 priv->agg_tids_count = 0;
1146 priv->ucode_owner = IWL_OWNERSHIP_DRIVER;
1148 priv->rx_statistics_jiffies = jiffies;
1150 /* Choose which receivers/antennas to use */
1151 iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
1153 iwl_init_scan_params(priv);
1156 if (priv->cfg->bt_params &&
1157 priv->cfg->bt_params->advanced_bt_coexist) {
1158 priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
1159 priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
1160 priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
1161 priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
1162 priv->bt_duration = BT_DURATION_LIMIT_DEF;
1163 priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
1169 static void iwl_uninit_drv(struct iwl_priv *priv)
1171 kfree(priv->scan_cmd);
1172 kfree(priv->beacon_cmd);
1173 kfree(rcu_dereference_raw(priv->noa_data));
1174 iwl_calib_free_results(priv);
1175 #ifdef CONFIG_IWLWIFI_DEBUGFS
1176 kfree(priv->wowlan_sram);
1180 static void iwl_set_hw_params(struct iwl_priv *priv)
1182 if (priv->cfg->ht_params)
1183 priv->hw_params.use_rts_for_aggregation =
1184 priv->cfg->ht_params->use_rts_for_aggregation;
1186 if (iwlwifi_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
1187 priv->hw_params.sku &= ~EEPROM_SKU_CAP_11N_ENABLE;
1189 /* Device-specific setup */
1190 priv->lib->set_hw_params(priv);
1195 /* show what optional capabilities we have */
1196 static void iwl_option_config(struct iwl_priv *priv)
1198 #ifdef CONFIG_IWLWIFI_DEBUG
1199 IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG enabled\n");
1201 IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG disabled\n");
1204 #ifdef CONFIG_IWLWIFI_DEBUGFS
1205 IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS enabled\n");
1207 IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS disabled\n");
1210 #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
1211 IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING enabled\n");
1213 IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING disabled\n");
1216 #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
1217 IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TESTMODE enabled\n");
1219 IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TESTMODE disabled\n");
1222 #ifdef CONFIG_IWLWIFI_P2P
1223 IWL_INFO(priv, "CONFIG_IWLWIFI_P2P enabled\n");
1225 IWL_INFO(priv, "CONFIG_IWLWIFI_P2P disabled\n");
1229 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
1233 priv->hw_params.sku = priv->eeprom_data->sku;
1235 if (priv->hw_params.sku & EEPROM_SKU_CAP_11N_ENABLE &&
1236 !priv->cfg->ht_params) {
1237 IWL_ERR(priv, "Invalid 11n configuration\n");
1241 if (!priv->hw_params.sku) {
1242 IWL_ERR(priv, "Invalid device sku\n");
1246 IWL_INFO(priv, "Device SKU: 0x%X\n", priv->hw_params.sku);
1248 radio_cfg = priv->eeprom_data->radio_cfg;
1250 priv->hw_params.tx_chains_num =
1251 num_of_ant(priv->eeprom_data->valid_tx_ant);
1252 if (priv->cfg->rx_with_siso_diversity)
1253 priv->hw_params.rx_chains_num = 1;
1255 priv->hw_params.rx_chains_num =
1256 num_of_ant(priv->eeprom_data->valid_rx_ant);
1258 IWL_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n",
1259 priv->eeprom_data->valid_tx_ant,
1260 priv->eeprom_data->valid_rx_ant);
1265 static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
1266 const struct iwl_cfg *cfg,
1267 const struct iwl_fw *fw)
1269 struct iwl_priv *priv;
1270 struct ieee80211_hw *hw;
1271 struct iwl_op_mode *op_mode;
1274 struct iwl_trans_config trans_cfg;
1275 static const u8 no_reclaim_cmds[] = {
1279 REPLY_COMPRESSED_BA,
1280 STATISTICS_NOTIFICATION,
1285 /************************
1286 * 1. Allocating HW data
1287 ************************/
1288 hw = iwl_alloc_all();
1290 pr_err("%s: Cannot allocate network device\n", cfg->name);
1295 op_mode->ops = &iwl_dvm_ops;
1296 priv = IWL_OP_MODE_GET_DVM(op_mode);
1297 priv->trans = trans;
1298 priv->dev = trans->dev;
1302 switch (priv->cfg->device_family) {
1303 case IWL_DEVICE_FAMILY_1000:
1304 case IWL_DEVICE_FAMILY_100:
1305 priv->lib = &iwl1000_lib;
1307 case IWL_DEVICE_FAMILY_2000:
1308 case IWL_DEVICE_FAMILY_105:
1309 priv->lib = &iwl2000_lib;
1311 case IWL_DEVICE_FAMILY_2030:
1312 case IWL_DEVICE_FAMILY_135:
1313 priv->lib = &iwl2030_lib;
1315 case IWL_DEVICE_FAMILY_5000:
1316 priv->lib = &iwl5000_lib;
1318 case IWL_DEVICE_FAMILY_5150:
1319 priv->lib = &iwl5150_lib;
1321 case IWL_DEVICE_FAMILY_6000:
1322 case IWL_DEVICE_FAMILY_6005:
1323 case IWL_DEVICE_FAMILY_6000i:
1324 case IWL_DEVICE_FAMILY_6050:
1325 case IWL_DEVICE_FAMILY_6150:
1326 priv->lib = &iwl6000_lib;
1328 case IWL_DEVICE_FAMILY_6030:
1329 priv->lib = &iwl6030_lib;
1335 if (WARN_ON(!priv->lib))
1339 * Populate the state variables that the transport layer needs
1342 trans_cfg.op_mode = op_mode;
1343 trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
1344 trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
1345 trans_cfg.rx_buf_size_8k = iwlwifi_mod_params.amsdu_size_8K;
1346 if (!iwlwifi_mod_params.wd_disable)
1347 trans_cfg.queue_watchdog_timeout =
1348 priv->cfg->base_params->wd_timeout;
1350 trans_cfg.queue_watchdog_timeout = IWL_WATCHHDOG_DISABLED;
1351 trans_cfg.command_names = iwl_dvm_cmd_strings;
1353 ucode_flags = fw->ucode_capa.flags;
1355 #ifndef CONFIG_IWLWIFI_P2P
1356 ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
1359 if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
1360 priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
1361 trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
1362 trans_cfg.queue_to_fifo = iwlagn_ipan_queue_to_tx_fifo;
1363 trans_cfg.n_queue_to_fifo =
1364 ARRAY_SIZE(iwlagn_ipan_queue_to_tx_fifo);
1366 priv->sta_key_max_num = STA_KEY_MAX_NUM;
1367 trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
1368 trans_cfg.queue_to_fifo = iwlagn_default_queue_to_tx_fifo;
1369 trans_cfg.n_queue_to_fifo =
1370 ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo);
1373 /* Configure transport layer */
1374 iwl_trans_configure(priv->trans, &trans_cfg);
1376 /* At this point both hw and priv are allocated. */
1378 SET_IEEE80211_DEV(priv->hw, priv->trans->dev);
1380 iwl_option_config(priv);
1382 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
1384 /* is antenna coupling more than 35dB ? */
1385 priv->bt_ant_couple_ok =
1386 (iwlwifi_mod_params.ant_coupling >
1387 IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
1390 /* enable/disable bt channel inhibition */
1391 priv->bt_ch_announce = iwlwifi_mod_params.bt_ch_announce;
1392 IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
1393 (priv->bt_ch_announce) ? "On" : "Off");
1395 /* these spin locks will be used in apm_ops.init and EEPROM access
1396 * we should init now
1398 spin_lock_init(&priv->statistics.lock);
1400 /***********************
1401 * 2. Read REV register
1402 ***********************/
1403 IWL_INFO(priv, "Detected %s, REV=0x%X\n",
1404 priv->cfg->name, priv->trans->hw_rev);
1406 if (iwl_trans_start_hw(priv->trans))
1409 /* Read the EEPROM */
1410 if (iwl_read_eeprom(priv->trans, &priv->eeprom_blob,
1411 &priv->eeprom_blob_size)) {
1412 IWL_ERR(priv, "Unable to init EEPROM\n");
1416 /* Reset chip to save power until we load uCode during "up". */
1417 iwl_trans_stop_hw(priv->trans, false);
1419 priv->eeprom_data = iwl_parse_eeprom_data(priv->trans->dev, priv->cfg,
1421 priv->eeprom_blob_size);
1422 if (!priv->eeprom_data)
1423 goto out_free_eeprom_blob;
1425 if (iwl_eeprom_check_version(priv->eeprom_data, priv->trans))
1426 goto out_free_eeprom;
1428 if (iwl_eeprom_init_hw_params(priv))
1429 goto out_free_eeprom;
1431 /* extract MAC Address */
1432 memcpy(priv->addresses[0].addr, priv->eeprom_data->hw_addr, ETH_ALEN);
1433 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
1434 priv->hw->wiphy->addresses = priv->addresses;
1435 priv->hw->wiphy->n_addresses = 1;
1436 num_mac = priv->eeprom_data->n_hw_addrs;
1438 memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
1440 priv->addresses[1].addr[5]++;
1441 priv->hw->wiphy->n_addresses++;
1444 /************************
1445 * 4. Setup HW constants
1446 ************************/
1447 iwl_set_hw_params(priv);
1449 if (!(priv->hw_params.sku & EEPROM_SKU_CAP_IPAN_ENABLE)) {
1450 IWL_DEBUG_INFO(priv, "Your EEPROM disabled PAN");
1451 ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
1453 * if not PAN, then don't support P2P -- might be a uCode
1454 * packaging bug or due to the eeprom check above
1456 ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
1457 priv->sta_key_max_num = STA_KEY_MAX_NUM;
1458 trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
1459 trans_cfg.queue_to_fifo = iwlagn_default_queue_to_tx_fifo;
1460 trans_cfg.n_queue_to_fifo =
1461 ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo);
1463 /* Configure transport layer again*/
1464 iwl_trans_configure(priv->trans, &trans_cfg);
1467 /*******************
1469 *******************/
1470 for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
1471 priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
1472 if (i < IWLAGN_FIRST_AMPDU_QUEUE &&
1473 i != IWL_DEFAULT_CMD_QUEUE_NUM &&
1474 i != IWL_IPAN_CMD_QUEUE_NUM)
1475 priv->queue_to_mac80211[i] = i;
1476 atomic_set(&priv->queue_stop_count[i], 0);
1479 WARN_ON(trans_cfg.queue_to_fifo[trans_cfg.cmd_queue] !=
1480 IWLAGN_CMD_FIFO_NUM);
1482 if (iwl_init_drv(priv))
1483 goto out_free_eeprom;
1485 /* At this point both hw and priv are initialized. */
1487 /********************
1489 ********************/
1490 iwl_setup_deferred_work(priv);
1491 iwl_setup_rx_handlers(priv);
1492 iwl_testmode_init(priv);
1494 iwl_power_initialize(priv);
1495 iwl_tt_initialize(priv);
1497 snprintf(priv->hw->wiphy->fw_version,
1498 sizeof(priv->hw->wiphy->fw_version),
1499 "%s", fw->fw_version);
1501 priv->new_scan_threshold_behaviour =
1502 !!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
1504 priv->phy_calib_chain_noise_reset_cmd =
1505 fw->ucode_capa.standard_phy_calibration_size;
1506 priv->phy_calib_chain_noise_gain_cmd =
1507 fw->ucode_capa.standard_phy_calibration_size + 1;
1509 /* initialize all valid contexts */
1510 iwl_init_context(priv, ucode_flags);
1512 /**************************************************
1513 * This is still part of probe() in a sense...
1515 * 7. Setup and register with mac80211 and debugfs
1516 **************************************************/
1517 if (iwlagn_mac_setup_register(priv, &fw->ucode_capa))
1518 goto out_destroy_workqueue;
1520 if (iwl_dbgfs_register(priv, DRV_NAME))
1522 "failed to create debugfs files. Ignoring error\n");
1526 out_destroy_workqueue:
1527 destroy_workqueue(priv->workqueue);
1528 priv->workqueue = NULL;
1529 iwl_uninit_drv(priv);
1530 out_free_eeprom_blob:
1531 kfree(priv->eeprom_blob);
1533 iwl_free_eeprom_data(priv->eeprom_data);
1535 ieee80211_free_hw(priv->hw);
1541 static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
1543 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
1545 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
1547 iwl_dbgfs_unregister(priv);
1549 iwl_testmode_cleanup(priv);
1550 iwlagn_mac_unregister(priv);
1554 /*This will stop the queues, move the device to low power state */
1555 priv->ucode_loaded = false;
1556 iwl_trans_stop_device(priv->trans);
1558 kfree(priv->eeprom_blob);
1559 iwl_free_eeprom_data(priv->eeprom_data);
1561 /*netif_stop_queue(dev); */
1562 flush_workqueue(priv->workqueue);
1564 /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
1565 * priv->workqueue... so we can't take down the workqueue
1567 destroy_workqueue(priv->workqueue);
1568 priv->workqueue = NULL;
1570 iwl_uninit_drv(priv);
1572 dev_kfree_skb(priv->beacon_skb);
1574 iwl_trans_stop_hw(priv->trans, true);
1575 ieee80211_free_hw(priv->hw);
1578 static const char * const desc_lookup_text[] = {
1583 "NMI_INTERRUPT_WDG",
1587 "HW_ERROR_TUNE_LOCK",
1588 "HW_ERROR_TEMPERATURE",
1589 "ILLEGAL_CHAN_FREQ",
1592 "NMI_INTERRUPT_HOST",
1593 "NMI_INTERRUPT_ACTION_PT",
1594 "NMI_INTERRUPT_UNKNOWN",
1595 "UCODE_VERSION_MISMATCH",
1596 "HW_ERROR_ABS_LOCK",
1597 "HW_ERROR_CAL_LOCK_FAIL",
1598 "NMI_INTERRUPT_INST_ACTION_PT",
1599 "NMI_INTERRUPT_DATA_ACTION_PT",
1601 "NMI_INTERRUPT_TRM",
1602 "NMI_INTERRUPT_BREAK_POINT",
1609 static struct { char *name; u8 num; } advanced_lookup[] = {
1610 { "NMI_INTERRUPT_WDG", 0x34 },
1611 { "SYSASSERT", 0x35 },
1612 { "UCODE_VERSION_MISMATCH", 0x37 },
1613 { "BAD_COMMAND", 0x38 },
1614 { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
1615 { "FATAL_ERROR", 0x3D },
1616 { "NMI_TRM_HW_ERR", 0x46 },
1617 { "NMI_INTERRUPT_TRM", 0x4C },
1618 { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
1619 { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
1620 { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
1621 { "NMI_INTERRUPT_HOST", 0x66 },
1622 { "NMI_INTERRUPT_ACTION_PT", 0x7C },
1623 { "NMI_INTERRUPT_UNKNOWN", 0x84 },
1624 { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
1625 { "ADVANCED_SYSASSERT", 0 },
1628 static const char *desc_lookup(u32 num)
1631 int max = ARRAY_SIZE(desc_lookup_text);
1634 return desc_lookup_text[num];
1636 max = ARRAY_SIZE(advanced_lookup) - 1;
1637 for (i = 0; i < max; i++) {
1638 if (advanced_lookup[i].num == num)
1641 return advanced_lookup[i].name;
1644 #define ERROR_START_OFFSET (1 * sizeof(u32))
1645 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
1647 static void iwl_dump_nic_error_log(struct iwl_priv *priv)
1649 struct iwl_trans *trans = priv->trans;
1651 struct iwl_error_event_table table;
1653 base = priv->device_pointers.error_event_table;
1654 if (priv->cur_ucode == IWL_UCODE_INIT) {
1656 base = priv->fw->init_errlog_ptr;
1659 base = priv->fw->inst_errlog_ptr;
1662 if (!iwlagn_hw_valid_rtc_data_addr(base)) {
1664 "Not valid error log pointer 0x%08X for %s uCode\n",
1666 (priv->cur_ucode == IWL_UCODE_INIT)
1671 /*TODO: Update dbgfs with ISR error stats obtained below */
1672 iwl_read_targ_mem_words(trans, base, &table, sizeof(table));
1674 if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
1675 IWL_ERR(trans, "Start IWL Error Log Dump:\n");
1676 IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
1677 priv->status, table.valid);
1680 trace_iwlwifi_dev_ucode_error(trans->dev, table.error_id, table.tsf_low,
1681 table.data1, table.data2, table.line,
1682 table.blink1, table.blink2, table.ilink1,
1683 table.ilink2, table.bcon_time, table.gp1,
1684 table.gp2, table.gp3, table.ucode_ver,
1685 table.hw_ver, table.brd_ver);
1686 IWL_ERR(priv, "0x%08X | %-28s\n", table.error_id,
1687 desc_lookup(table.error_id));
1688 IWL_ERR(priv, "0x%08X | uPc\n", table.pc);
1689 IWL_ERR(priv, "0x%08X | branchlink1\n", table.blink1);
1690 IWL_ERR(priv, "0x%08X | branchlink2\n", table.blink2);
1691 IWL_ERR(priv, "0x%08X | interruptlink1\n", table.ilink1);
1692 IWL_ERR(priv, "0x%08X | interruptlink2\n", table.ilink2);
1693 IWL_ERR(priv, "0x%08X | data1\n", table.data1);
1694 IWL_ERR(priv, "0x%08X | data2\n", table.data2);
1695 IWL_ERR(priv, "0x%08X | line\n", table.line);
1696 IWL_ERR(priv, "0x%08X | beacon time\n", table.bcon_time);
1697 IWL_ERR(priv, "0x%08X | tsf low\n", table.tsf_low);
1698 IWL_ERR(priv, "0x%08X | tsf hi\n", table.tsf_hi);
1699 IWL_ERR(priv, "0x%08X | time gp1\n", table.gp1);
1700 IWL_ERR(priv, "0x%08X | time gp2\n", table.gp2);
1701 IWL_ERR(priv, "0x%08X | time gp3\n", table.gp3);
1702 IWL_ERR(priv, "0x%08X | uCode version\n", table.ucode_ver);
1703 IWL_ERR(priv, "0x%08X | hw version\n", table.hw_ver);
1704 IWL_ERR(priv, "0x%08X | board version\n", table.brd_ver);
1705 IWL_ERR(priv, "0x%08X | hcmd\n", table.hcmd);
1706 IWL_ERR(priv, "0x%08X | isr0\n", table.isr0);
1707 IWL_ERR(priv, "0x%08X | isr1\n", table.isr1);
1708 IWL_ERR(priv, "0x%08X | isr2\n", table.isr2);
1709 IWL_ERR(priv, "0x%08X | isr3\n", table.isr3);
1710 IWL_ERR(priv, "0x%08X | isr4\n", table.isr4);
1711 IWL_ERR(priv, "0x%08X | isr_pref\n", table.isr_pref);
1712 IWL_ERR(priv, "0x%08X | wait_event\n", table.wait_event);
1713 IWL_ERR(priv, "0x%08X | l2p_control\n", table.l2p_control);
1714 IWL_ERR(priv, "0x%08X | l2p_duration\n", table.l2p_duration);
1715 IWL_ERR(priv, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
1716 IWL_ERR(priv, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
1717 IWL_ERR(priv, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
1718 IWL_ERR(priv, "0x%08X | timestamp\n", table.u_timestamp);
1719 IWL_ERR(priv, "0x%08X | flow_handler\n", table.flow_handler);
1722 #define EVENT_START_OFFSET (4 * sizeof(u32))
1725 * iwl_print_event_log - Dump error event log to syslog
1728 static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
1729 u32 num_events, u32 mode,
1730 int pos, char **buf, size_t bufsz)
1733 u32 base; /* SRAM byte address of event log header */
1734 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1735 u32 ptr; /* SRAM byte address of log data */
1736 u32 ev, time, data; /* event log data */
1737 unsigned long reg_flags;
1739 struct iwl_trans *trans = priv->trans;
1741 if (num_events == 0)
1744 base = priv->device_pointers.log_event_table;
1745 if (priv->cur_ucode == IWL_UCODE_INIT) {
1747 base = priv->fw->init_evtlog_ptr;
1750 base = priv->fw->inst_evtlog_ptr;
1754 event_size = 2 * sizeof(u32);
1756 event_size = 3 * sizeof(u32);
1758 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1760 /* Make sure device is powered up for SRAM reads */
1761 spin_lock_irqsave(&trans->reg_lock, reg_flags);
1762 if (unlikely(!iwl_grab_nic_access(trans)))
1765 /* Set starting address; reads will auto-increment */
1766 iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr);
1768 /* "time" is actually "data" for mode 0 (no timestamp).
1769 * place event id # at far right for easier visual parsing. */
1770 for (i = 0; i < num_events; i++) {
1771 ev = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
1772 time = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
1776 pos += scnprintf(*buf + pos, bufsz - pos,
1777 "EVT_LOG:0x%08x:%04u\n",
1780 trace_iwlwifi_dev_ucode_event(trans->dev, 0,
1782 IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
1786 data = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
1788 pos += scnprintf(*buf + pos, bufsz - pos,
1789 "EVT_LOGT:%010u:0x%08x:%04u\n",
1792 IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
1794 trace_iwlwifi_dev_ucode_event(trans->dev, time,
1800 /* Allow device to power down */
1801 iwl_release_nic_access(trans);
1803 spin_unlock_irqrestore(&trans->reg_lock, reg_flags);
1808 * iwl_print_last_event_logs - Dump the newest # of event log to syslog
1810 static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
1811 u32 num_wraps, u32 next_entry,
1813 int pos, char **buf, size_t bufsz)
1816 * display the newest DEFAULT_LOG_ENTRIES entries
1817 * i.e the entries just before the next ont that uCode would fill.
1820 if (next_entry < size) {
1821 pos = iwl_print_event_log(priv,
1822 capacity - (size - next_entry),
1823 size - next_entry, mode,
1825 pos = iwl_print_event_log(priv, 0,
1829 pos = iwl_print_event_log(priv, next_entry - size,
1830 size, mode, pos, buf, bufsz);
1832 if (next_entry < size) {
1833 pos = iwl_print_event_log(priv, 0, next_entry,
1834 mode, pos, buf, bufsz);
1836 pos = iwl_print_event_log(priv, next_entry - size,
1837 size, mode, pos, buf, bufsz);
1843 #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
1845 int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
1846 char **buf, bool display)
1848 u32 base; /* SRAM byte address of event log header */
1849 u32 capacity; /* event log capacity in # entries */
1850 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1851 u32 num_wraps; /* # times uCode wrapped to top of log */
1852 u32 next_entry; /* index of next entry to be written by uCode */
1853 u32 size; /* # entries that we'll print */
1857 struct iwl_trans *trans = priv->trans;
1859 base = priv->device_pointers.log_event_table;
1860 if (priv->cur_ucode == IWL_UCODE_INIT) {
1861 logsize = priv->fw->init_evtlog_size;
1863 base = priv->fw->init_evtlog_ptr;
1865 logsize = priv->fw->inst_evtlog_size;
1867 base = priv->fw->inst_evtlog_ptr;
1870 if (!iwlagn_hw_valid_rtc_data_addr(base)) {
1872 "Invalid event log pointer 0x%08X for %s uCode\n",
1874 (priv->cur_ucode == IWL_UCODE_INIT)
1879 /* event log header */
1880 capacity = iwl_read_targ_mem(trans, base);
1881 mode = iwl_read_targ_mem(trans, base + (1 * sizeof(u32)));
1882 num_wraps = iwl_read_targ_mem(trans, base + (2 * sizeof(u32)));
1883 next_entry = iwl_read_targ_mem(trans, base + (3 * sizeof(u32)));
1885 if (capacity > logsize) {
1886 IWL_ERR(priv, "Log capacity %d is bogus, limit to %d "
1887 "entries\n", capacity, logsize);
1891 if (next_entry > logsize) {
1892 IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
1893 next_entry, logsize);
1894 next_entry = logsize;
1897 size = num_wraps ? capacity : next_entry;
1899 /* bail out if nothing in log */
1901 IWL_ERR(trans, "Start IWL Event Log Dump: nothing in log\n");
1905 #ifdef CONFIG_IWLWIFI_DEBUG
1906 if (!(iwl_have_debug_level(IWL_DL_FW_ERRORS)) && !full_log)
1907 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
1908 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
1910 size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
1911 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
1913 IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
1916 #ifdef CONFIG_IWLWIFI_DEBUG
1919 bufsz = capacity * 48;
1922 *buf = kmalloc(bufsz, GFP_KERNEL);
1926 if (iwl_have_debug_level(IWL_DL_FW_ERRORS) || full_log) {
1928 * if uCode has wrapped back to top of log,
1929 * start at the oldest entry,
1930 * i.e the next one that uCode would fill.
1933 pos = iwl_print_event_log(priv, next_entry,
1934 capacity - next_entry, mode,
1936 /* (then/else) start at top of log */
1937 pos = iwl_print_event_log(priv, 0,
1938 next_entry, mode, pos, buf, bufsz);
1940 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
1941 next_entry, size, mode,
1944 pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
1945 next_entry, size, mode,
1951 static void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
1953 unsigned int reload_msec;
1954 unsigned long reload_jiffies;
1956 #ifdef CONFIG_IWLWIFI_DEBUG
1957 if (iwl_have_debug_level(IWL_DL_FW_ERRORS))
1958 iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS);
1961 /* uCode is no longer loaded. */
1962 priv->ucode_loaded = false;
1964 /* Set the FW error flag -- cleared on iwl_down */
1965 set_bit(STATUS_FW_ERROR, &priv->status);
1967 iwl_abort_notification_waits(&priv->notif_wait);
1969 /* Keep the restart process from trying to send host
1970 * commands by clearing the ready bit */
1971 clear_bit(STATUS_READY, &priv->status);
1973 wake_up(&priv->trans->wait_command_queue);
1977 * If firmware keep reloading, then it indicate something
1978 * serious wrong and firmware having problem to recover
1979 * from it. Instead of keep trying which will fill the syslog
1980 * and hang the system, let's just stop it
1982 reload_jiffies = jiffies;
1983 reload_msec = jiffies_to_msecs((long) reload_jiffies -
1984 (long) priv->reload_jiffies);
1985 priv->reload_jiffies = reload_jiffies;
1986 if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
1987 priv->reload_count++;
1988 if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
1989 IWL_ERR(priv, "BUG_ON, Stop restarting\n");
1993 priv->reload_count = 0;
1996 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
1997 if (iwlwifi_mod_params.restart_fw) {
1998 IWL_DEBUG_FW_ERRORS(priv,
1999 "Restarting adapter due to uCode error.\n");
2000 queue_work(priv->workqueue, &priv->restart);
2002 IWL_DEBUG_FW_ERRORS(priv,
2003 "Detected FW error, but not restarting\n");
2007 static void iwl_nic_error(struct iwl_op_mode *op_mode)
2009 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2011 IWL_ERR(priv, "Loaded firmware version: %s\n",
2012 priv->fw->fw_version);
2014 iwl_dump_nic_error_log(priv);
2015 iwl_dump_nic_event_log(priv, false, NULL, false);
2017 iwlagn_fw_error(priv, false);
2020 static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
2022 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2024 if (!iwl_check_for_ct_kill(priv)) {
2025 IWL_ERR(priv, "Restarting adapter queue is full\n");
2026 iwlagn_fw_error(priv, false);
2030 static void iwl_nic_config(struct iwl_op_mode *op_mode)
2032 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2035 iwl_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
2036 CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH |
2037 CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP,
2038 (CSR_HW_REV_STEP(priv->trans->hw_rev) <<
2039 CSR_HW_IF_CONFIG_REG_POS_MAC_STEP) |
2040 (CSR_HW_REV_DASH(priv->trans->hw_rev) <<
2041 CSR_HW_IF_CONFIG_REG_POS_MAC_DASH));
2043 priv->lib->nic_config(priv);
2046 static void iwl_wimax_active(struct iwl_op_mode *op_mode)
2048 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2050 clear_bit(STATUS_READY, &priv->status);
2051 IWL_ERR(priv, "RF is used by WiMAX\n");
2054 static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
2056 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2057 int mq = priv->queue_to_mac80211[queue];
2059 if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
2062 if (atomic_inc_return(&priv->queue_stop_count[mq]) > 1) {
2063 IWL_DEBUG_TX_QUEUES(priv,
2064 "queue %d (mac80211 %d) already stopped\n",
2069 set_bit(mq, &priv->transport_queue_stop);
2070 ieee80211_stop_queue(priv->hw, mq);
2073 static void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
2075 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2076 int mq = priv->queue_to_mac80211[queue];
2078 if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
2081 if (atomic_dec_return(&priv->queue_stop_count[mq]) > 0) {
2082 IWL_DEBUG_TX_QUEUES(priv,
2083 "queue %d (mac80211 %d) already awake\n",
2088 clear_bit(mq, &priv->transport_queue_stop);
2090 if (!priv->passive_no_rx)
2091 ieee80211_wake_queue(priv->hw, mq);
2094 void iwlagn_lift_passive_no_rx(struct iwl_priv *priv)
2098 if (!priv->passive_no_rx)
2101 for (mq = 0; mq < IWLAGN_FIRST_AMPDU_QUEUE; mq++) {
2102 if (!test_bit(mq, &priv->transport_queue_stop)) {
2103 IWL_DEBUG_TX_QUEUES(priv, "Wake queue %d", mq);
2104 ieee80211_wake_queue(priv->hw, mq);
2106 IWL_DEBUG_TX_QUEUES(priv, "Don't wake queue %d", mq);
2110 priv->passive_no_rx = false;
2113 static void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
2115 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2116 struct ieee80211_tx_info *info;
2118 info = IEEE80211_SKB_CB(skb);
2119 iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]);
2120 dev_kfree_skb_any(skb);
2123 static void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
2125 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
2128 set_bit(STATUS_RF_KILL_HW, &priv->status);
2130 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2132 wiphy_rfkill_set_hw_state(priv->hw->wiphy, state);
2135 const struct iwl_op_mode_ops iwl_dvm_ops = {
2136 .start = iwl_op_mode_dvm_start,
2137 .stop = iwl_op_mode_dvm_stop,
2138 .rx = iwl_rx_dispatch,
2139 .queue_full = iwl_stop_sw_queue,
2140 .queue_not_full = iwl_wake_sw_queue,
2141 .hw_rf_kill = iwl_set_hw_rfkill_state,
2142 .free_skb = iwl_free_skb,
2143 .nic_error = iwl_nic_error,
2144 .cmd_queue_full = iwl_cmd_queue_full,
2145 .nic_config = iwl_nic_config,
2146 .wimax_active = iwl_wimax_active,
2149 /*****************************************************************************
2151 * driver and module entry point
2153 *****************************************************************************/
2154 static int __init iwl_init(void)
2158 pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
2159 pr_info(DRV_COPYRIGHT "\n");
2161 ret = iwlagn_rate_control_register();
2163 pr_err("Unable to register rate control algorithm: %d\n", ret);
2167 ret = iwl_opmode_register("iwldvm", &iwl_dvm_ops);
2169 pr_err("Unable to register op_mode: %d\n", ret);
2170 iwlagn_rate_control_unregister();
2175 module_init(iwl_init);
2177 static void __exit iwl_exit(void)
2179 iwl_opmode_deregister("iwldvm");
2180 iwlagn_rate_control_unregister();
2182 module_exit(iwl_exit);