1 // SPDX-License-Identifier: GPL-2.0-only
2 /******************************************************************************
4 * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
5 * Copyright(c) 2015 Intel Deutschland GmbH
6 * Copyright (C) 2018 - 2019 Intel Corporation
8 * Portions of this file are derived from the ipw3945 project, as well
9 * as portions of the ieee80211 subsystem header files.
11 * Contact Information:
12 * Intel Linux Wireless <linuxwifi@intel.com>
13 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
15 *****************************************************************************/
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/init.h>
22 #include <linux/slab.h>
23 #include <linux/delay.h>
24 #include <linux/sched.h>
25 #include <linux/skbuff.h>
26 #include <linux/netdevice.h>
27 #include <linux/etherdevice.h>
28 #include <linux/if_arp.h>
30 #include <net/mac80211.h>
32 #include <asm/div64.h>
34 #include "iwl-eeprom-read.h"
35 #include "iwl-eeprom-parse.h"
37 #include "iwl-trans.h"
38 #include "iwl-op-mode.h"
40 #include "iwl-modparams.h"
48 /******************************************************************************
52 ******************************************************************************/
54 #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
55 MODULE_DESCRIPTION(DRV_DESCRIPTION
);
56 MODULE_AUTHOR(DRV_COPYRIGHT
" " DRV_AUTHOR
);
57 MODULE_LICENSE("GPL");
59 /* Please keep this array *SORTED* by hex value.
60 * Access is done through binary search.
61 * A warning will be triggered on violation.
63 static const struct iwl_hcmd_names iwl_dvm_cmd_names
[] = {
64 HCMD_NAME(REPLY_ALIVE
),
65 HCMD_NAME(REPLY_ERROR
),
66 HCMD_NAME(REPLY_ECHO
),
67 HCMD_NAME(REPLY_RXON
),
68 HCMD_NAME(REPLY_RXON_ASSOC
),
69 HCMD_NAME(REPLY_QOS_PARAM
),
70 HCMD_NAME(REPLY_RXON_TIMING
),
71 HCMD_NAME(REPLY_ADD_STA
),
72 HCMD_NAME(REPLY_REMOVE_STA
),
73 HCMD_NAME(REPLY_REMOVE_ALL_STA
),
75 HCMD_NAME(REPLY_TXFIFO_FLUSH
),
76 HCMD_NAME(REPLY_WEPKEY
),
77 HCMD_NAME(REPLY_LEDS_CMD
),
78 HCMD_NAME(REPLY_TX_LINK_QUALITY_CMD
),
79 HCMD_NAME(COEX_PRIORITY_TABLE_CMD
),
80 HCMD_NAME(COEX_MEDIUM_NOTIFICATION
),
81 HCMD_NAME(COEX_EVENT_CMD
),
82 HCMD_NAME(TEMPERATURE_NOTIFICATION
),
83 HCMD_NAME(CALIBRATION_CFG_CMD
),
84 HCMD_NAME(CALIBRATION_RES_NOTIFICATION
),
85 HCMD_NAME(CALIBRATION_COMPLETE_NOTIFICATION
),
86 HCMD_NAME(REPLY_QUIET_CMD
),
87 HCMD_NAME(REPLY_CHANNEL_SWITCH
),
88 HCMD_NAME(CHANNEL_SWITCH_NOTIFICATION
),
89 HCMD_NAME(REPLY_SPECTRUM_MEASUREMENT_CMD
),
90 HCMD_NAME(SPECTRUM_MEASURE_NOTIFICATION
),
91 HCMD_NAME(POWER_TABLE_CMD
),
92 HCMD_NAME(PM_SLEEP_NOTIFICATION
),
93 HCMD_NAME(PM_DEBUG_STATISTIC_NOTIFIC
),
94 HCMD_NAME(REPLY_SCAN_CMD
),
95 HCMD_NAME(REPLY_SCAN_ABORT_CMD
),
96 HCMD_NAME(SCAN_START_NOTIFICATION
),
97 HCMD_NAME(SCAN_RESULTS_NOTIFICATION
),
98 HCMD_NAME(SCAN_COMPLETE_NOTIFICATION
),
99 HCMD_NAME(BEACON_NOTIFICATION
),
100 HCMD_NAME(REPLY_TX_BEACON
),
101 HCMD_NAME(WHO_IS_AWAKE_NOTIFICATION
),
102 HCMD_NAME(REPLY_TX_POWER_DBM_CMD
),
103 HCMD_NAME(QUIET_NOTIFICATION
),
104 HCMD_NAME(REPLY_TX_PWR_TABLE_CMD
),
105 HCMD_NAME(REPLY_TX_POWER_DBM_CMD_V1
),
106 HCMD_NAME(TX_ANT_CONFIGURATION_CMD
),
107 HCMD_NAME(MEASURE_ABORT_NOTIFICATION
),
108 HCMD_NAME(REPLY_BT_CONFIG
),
109 HCMD_NAME(REPLY_STATISTICS_CMD
),
110 HCMD_NAME(STATISTICS_NOTIFICATION
),
111 HCMD_NAME(REPLY_CARD_STATE_CMD
),
112 HCMD_NAME(CARD_STATE_NOTIFICATION
),
113 HCMD_NAME(MISSED_BEACONS_NOTIFICATION
),
114 HCMD_NAME(REPLY_CT_KILL_CONFIG_CMD
),
115 HCMD_NAME(SENSITIVITY_CMD
),
116 HCMD_NAME(REPLY_PHY_CALIBRATION_CMD
),
117 HCMD_NAME(REPLY_WIPAN_PARAMS
),
118 HCMD_NAME(REPLY_WIPAN_RXON
),
119 HCMD_NAME(REPLY_WIPAN_RXON_TIMING
),
120 HCMD_NAME(REPLY_WIPAN_RXON_ASSOC
),
121 HCMD_NAME(REPLY_WIPAN_QOS_PARAM
),
122 HCMD_NAME(REPLY_WIPAN_WEPKEY
),
123 HCMD_NAME(REPLY_WIPAN_P2P_CHANNEL_SWITCH
),
124 HCMD_NAME(REPLY_WIPAN_NOA_NOTIFICATION
),
125 HCMD_NAME(REPLY_WIPAN_DEACTIVATION_COMPLETE
),
126 HCMD_NAME(REPLY_RX_PHY_CMD
),
127 HCMD_NAME(REPLY_RX_MPDU_CMD
),
129 HCMD_NAME(REPLY_COMPRESSED_BA
),
130 HCMD_NAME(REPLY_BT_COEX_PRIO_TABLE
),
131 HCMD_NAME(REPLY_BT_COEX_PROT_ENV
),
132 HCMD_NAME(REPLY_BT_COEX_PROFILE_NOTIF
),
133 HCMD_NAME(REPLY_D3_CONFIG
),
134 HCMD_NAME(REPLY_WOWLAN_PATTERNS
),
135 HCMD_NAME(REPLY_WOWLAN_WAKEUP_FILTER
),
136 HCMD_NAME(REPLY_WOWLAN_TSC_RSC_PARAMS
),
137 HCMD_NAME(REPLY_WOWLAN_TKIP_PARAMS
),
138 HCMD_NAME(REPLY_WOWLAN_KEK_KCK_MATERIAL
),
139 HCMD_NAME(REPLY_WOWLAN_GET_STATUS
),
142 static const struct iwl_hcmd_arr iwl_dvm_groups
[] = {
143 [0x0] = HCMD_ARR(iwl_dvm_cmd_names
),
146 static const struct iwl_op_mode_ops iwl_dvm_ops
;
148 void iwl_update_chain_flags(struct iwl_priv
*priv
)
150 struct iwl_rxon_context
*ctx
;
152 for_each_context(priv
, ctx
) {
153 iwlagn_set_rxon_chain(priv
, ctx
);
154 if (ctx
->active
.rx_chain
!= ctx
->staging
.rx_chain
)
155 iwlagn_commit_rxon(priv
, ctx
);
159 /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
160 static void iwl_set_beacon_tim(struct iwl_priv
*priv
,
161 struct iwl_tx_beacon_cmd
*tx_beacon_cmd
,
162 u8
*beacon
, u32 frame_size
)
165 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*)beacon
;
168 * The index is relative to frame start but we start looking at the
169 * variable-length part of the beacon.
171 tim_idx
= mgmt
->u
.beacon
.variable
- beacon
;
173 /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
174 while ((tim_idx
< (frame_size
- 2)) &&
175 (beacon
[tim_idx
] != WLAN_EID_TIM
))
176 tim_idx
+= beacon
[tim_idx
+1] + 2;
178 /* If TIM field was found, set variables */
179 if ((tim_idx
< (frame_size
- 1)) && (beacon
[tim_idx
] == WLAN_EID_TIM
)) {
180 tx_beacon_cmd
->tim_idx
= cpu_to_le16(tim_idx
);
181 tx_beacon_cmd
->tim_size
= beacon
[tim_idx
+1];
183 IWL_WARN(priv
, "Unable to find TIM Element in beacon\n");
186 int iwlagn_send_beacon_cmd(struct iwl_priv
*priv
)
188 struct iwl_tx_beacon_cmd
*tx_beacon_cmd
;
189 struct iwl_host_cmd cmd
= {
190 .id
= REPLY_TX_BEACON
,
192 struct ieee80211_tx_info
*info
;
198 * We have to set up the TX command, the TX Beacon command, and the
202 lockdep_assert_held(&priv
->mutex
);
204 if (!priv
->beacon_ctx
) {
205 IWL_ERR(priv
, "trying to build beacon w/o beacon context!\n");
209 if (WARN_ON(!priv
->beacon_skb
))
212 /* Allocate beacon command */
213 if (!priv
->beacon_cmd
)
214 priv
->beacon_cmd
= kzalloc(sizeof(*tx_beacon_cmd
), GFP_KERNEL
);
215 tx_beacon_cmd
= priv
->beacon_cmd
;
219 frame_size
= priv
->beacon_skb
->len
;
221 /* Set up TX command fields */
222 tx_beacon_cmd
->tx
.len
= cpu_to_le16((u16
)frame_size
);
223 tx_beacon_cmd
->tx
.sta_id
= priv
->beacon_ctx
->bcast_sta_id
;
224 tx_beacon_cmd
->tx
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
225 tx_beacon_cmd
->tx
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
|
226 TX_CMD_FLG_TSF_MSK
| TX_CMD_FLG_STA_RATE_MSK
;
228 /* Set up TX beacon command fields */
229 iwl_set_beacon_tim(priv
, tx_beacon_cmd
, priv
->beacon_skb
->data
,
232 /* Set up packet rate and flags */
233 info
= IEEE80211_SKB_CB(priv
->beacon_skb
);
236 * Let's set up the rate at least somewhat correctly;
237 * it will currently not actually be used by the uCode,
238 * it uses the broadcast station's rate instead.
240 if (info
->control
.rates
[0].idx
< 0 ||
241 info
->control
.rates
[0].flags
& IEEE80211_TX_RC_MCS
)
244 rate
= info
->control
.rates
[0].idx
;
246 priv
->mgmt_tx_ant
= iwl_toggle_tx_ant(priv
, priv
->mgmt_tx_ant
,
247 priv
->nvm_data
->valid_tx_ant
);
248 rate_flags
= iwl_ant_idx_to_flags(priv
->mgmt_tx_ant
);
250 /* In mac80211, rates for 5 GHz start at 0 */
251 if (info
->band
== NL80211_BAND_5GHZ
)
252 rate
+= IWL_FIRST_OFDM_RATE
;
253 else if (rate
>= IWL_FIRST_CCK_RATE
&& rate
<= IWL_LAST_CCK_RATE
)
254 rate_flags
|= RATE_MCS_CCK_MSK
;
256 tx_beacon_cmd
->tx
.rate_n_flags
=
257 iwl_hw_set_rate_n_flags(rate
, rate_flags
);
260 cmd
.len
[0] = sizeof(*tx_beacon_cmd
);
261 cmd
.data
[0] = tx_beacon_cmd
;
262 cmd
.dataflags
[0] = IWL_HCMD_DFL_NOCOPY
;
263 cmd
.len
[1] = frame_size
;
264 cmd
.data
[1] = priv
->beacon_skb
->data
;
265 cmd
.dataflags
[1] = IWL_HCMD_DFL_NOCOPY
;
267 return iwl_dvm_send_cmd(priv
, &cmd
);
270 static void iwl_bg_beacon_update(struct work_struct
*work
)
272 struct iwl_priv
*priv
=
273 container_of(work
, struct iwl_priv
, beacon_update
);
274 struct sk_buff
*beacon
;
276 mutex_lock(&priv
->mutex
);
277 if (!priv
->beacon_ctx
) {
278 IWL_ERR(priv
, "updating beacon w/o beacon context!\n");
282 if (priv
->beacon_ctx
->vif
->type
!= NL80211_IFTYPE_AP
) {
284 * The ucode will send beacon notifications even in
285 * IBSS mode, but we don't want to process them. But
286 * we need to defer the type check to here due to
287 * requiring locking around the beacon_ctx access.
292 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
293 beacon
= ieee80211_beacon_get(priv
->hw
, priv
->beacon_ctx
->vif
);
295 IWL_ERR(priv
, "update beacon failed -- keeping old\n");
299 /* new beacon skb is allocated every time; dispose previous.*/
300 dev_kfree_skb(priv
->beacon_skb
);
302 priv
->beacon_skb
= beacon
;
304 iwlagn_send_beacon_cmd(priv
);
306 mutex_unlock(&priv
->mutex
);
309 static void iwl_bg_bt_runtime_config(struct work_struct
*work
)
311 struct iwl_priv
*priv
=
312 container_of(work
, struct iwl_priv
, bt_runtime_config
);
314 mutex_lock(&priv
->mutex
);
315 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
318 /* dont send host command if rf-kill is on */
319 if (!iwl_is_ready_rf(priv
))
322 iwlagn_send_advance_bt_config(priv
);
324 mutex_unlock(&priv
->mutex
);
327 static void iwl_bg_bt_full_concurrency(struct work_struct
*work
)
329 struct iwl_priv
*priv
=
330 container_of(work
, struct iwl_priv
, bt_full_concurrency
);
331 struct iwl_rxon_context
*ctx
;
333 mutex_lock(&priv
->mutex
);
335 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
338 /* dont send host command if rf-kill is on */
339 if (!iwl_is_ready_rf(priv
))
342 IWL_DEBUG_INFO(priv
, "BT coex in %s mode\n",
343 priv
->bt_full_concurrent
?
344 "full concurrency" : "3-wire");
347 * LQ & RXON updated cmds must be sent before BT Config cmd
348 * to avoid 3-wire collisions
350 for_each_context(priv
, ctx
) {
351 iwlagn_set_rxon_chain(priv
, ctx
);
352 iwlagn_commit_rxon(priv
, ctx
);
355 iwlagn_send_advance_bt_config(priv
);
357 mutex_unlock(&priv
->mutex
);
360 int iwl_send_statistics_request(struct iwl_priv
*priv
, u8 flags
, bool clear
)
362 struct iwl_statistics_cmd statistics_cmd
= {
363 .configuration_flags
=
364 clear
? IWL_STATS_CONF_CLEAR_STATS
: 0,
367 if (flags
& CMD_ASYNC
)
368 return iwl_dvm_send_cmd_pdu(priv
, REPLY_STATISTICS_CMD
,
370 sizeof(struct iwl_statistics_cmd
),
373 return iwl_dvm_send_cmd_pdu(priv
, REPLY_STATISTICS_CMD
, 0,
374 sizeof(struct iwl_statistics_cmd
),
379 * iwl_bg_statistics_periodic - Timer callback to queue statistics
381 * This callback is provided in order to send a statistics request.
383 * This timer function is continually reset to execute within
384 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
385 * was received. We need to ensure we receive the statistics in order
386 * to update the temperature used for calibrating the TXPOWER.
388 static void iwl_bg_statistics_periodic(struct timer_list
*t
)
390 struct iwl_priv
*priv
= from_timer(priv
, t
, statistics_periodic
);
392 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
395 /* dont send host command if rf-kill is on */
396 if (!iwl_is_ready_rf(priv
))
399 iwl_send_statistics_request(priv
, CMD_ASYNC
, false);
403 static void iwl_print_cont_event_trace(struct iwl_priv
*priv
, u32 base
,
404 u32 start_idx
, u32 num_events
,
405 u32 capacity
, u32 mode
)
408 u32 ptr
; /* SRAM byte address of log data */
409 u32 ev
, time
, data
; /* event log data */
410 unsigned long reg_flags
;
413 ptr
= base
+ (4 * sizeof(u32
)) + (start_idx
* 2 * sizeof(u32
));
415 ptr
= base
+ (4 * sizeof(u32
)) + (start_idx
* 3 * sizeof(u32
));
417 /* Make sure device is powered up for SRAM reads */
418 if (!iwl_trans_grab_nic_access(priv
->trans
, ®_flags
))
421 /* Set starting address; reads will auto-increment */
422 iwl_write32(priv
->trans
, HBUS_TARG_MEM_RADDR
, ptr
);
425 * Refuse to read more than would have fit into the log from
426 * the current start_idx. This used to happen due to the race
427 * described below, but now WARN because the code below should
428 * prevent it from happening here.
430 if (WARN_ON(num_events
> capacity
- start_idx
))
431 num_events
= capacity
- start_idx
;
434 * "time" is actually "data" for mode 0 (no timestamp).
435 * place event id # at far right for easier visual parsing.
437 for (i
= 0; i
< num_events
; i
++) {
438 ev
= iwl_read32(priv
->trans
, HBUS_TARG_MEM_RDAT
);
439 time
= iwl_read32(priv
->trans
, HBUS_TARG_MEM_RDAT
);
441 trace_iwlwifi_dev_ucode_cont_event(
442 priv
->trans
->dev
, 0, time
, ev
);
444 data
= iwl_read32(priv
->trans
, HBUS_TARG_MEM_RDAT
);
445 trace_iwlwifi_dev_ucode_cont_event(
446 priv
->trans
->dev
, time
, data
, ev
);
449 /* Allow device to power down */
450 iwl_trans_release_nic_access(priv
->trans
, ®_flags
);
453 static void iwl_continuous_event_trace(struct iwl_priv
*priv
)
455 u32 capacity
; /* event log capacity in # entries */
462 u32 base
; /* SRAM byte address of event log header */
463 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
464 u32 num_wraps
; /* # times uCode wrapped to top of log */
465 u32 next_entry
; /* index of next entry to be written by uCode */
467 base
= priv
->device_pointers
.log_event_table
;
468 if (iwlagn_hw_valid_rtc_data_addr(base
)) {
469 iwl_trans_read_mem_bytes(priv
->trans
, base
,
470 &read
, sizeof(read
));
471 capacity
= read
.capacity
;
473 num_wraps
= read
.wrap_counter
;
474 next_entry
= read
.write_counter
;
479 * Unfortunately, the uCode doesn't use temporary variables.
480 * Therefore, it can happen that we read next_entry == capacity,
481 * which really means next_entry == 0.
483 if (unlikely(next_entry
== capacity
))
486 * Additionally, the uCode increases the write pointer before
487 * the wraps counter, so if the write pointer is smaller than
488 * the old write pointer (wrap occurred) but we read that no
489 * wrap occurred, we actually read between the next_entry and
490 * num_wraps update (this does happen in practice!!) -- take
491 * that into account by increasing num_wraps.
493 if (unlikely(next_entry
< priv
->event_log
.next_entry
&&
494 num_wraps
== priv
->event_log
.num_wraps
))
497 if (num_wraps
== priv
->event_log
.num_wraps
) {
498 iwl_print_cont_event_trace(
499 priv
, base
, priv
->event_log
.next_entry
,
500 next_entry
- priv
->event_log
.next_entry
,
503 priv
->event_log
.non_wraps_count
++;
505 if (num_wraps
- priv
->event_log
.num_wraps
> 1)
506 priv
->event_log
.wraps_more_count
++;
508 priv
->event_log
.wraps_once_count
++;
510 trace_iwlwifi_dev_ucode_wrap_event(priv
->trans
->dev
,
511 num_wraps
- priv
->event_log
.num_wraps
,
512 next_entry
, priv
->event_log
.next_entry
);
514 if (next_entry
< priv
->event_log
.next_entry
) {
515 iwl_print_cont_event_trace(
516 priv
, base
, priv
->event_log
.next_entry
,
517 capacity
- priv
->event_log
.next_entry
,
520 iwl_print_cont_event_trace(
521 priv
, base
, 0, next_entry
, capacity
, mode
);
523 iwl_print_cont_event_trace(
524 priv
, base
, next_entry
,
525 capacity
- next_entry
,
528 iwl_print_cont_event_trace(
529 priv
, base
, 0, next_entry
, capacity
, mode
);
533 priv
->event_log
.num_wraps
= num_wraps
;
534 priv
->event_log
.next_entry
= next_entry
;
538 * iwl_bg_ucode_trace - Timer callback to log ucode event
540 * The timer is continually set to execute every
541 * UCODE_TRACE_PERIOD milliseconds after the last timer expired
542 * this function is to perform continuous uCode event logging operation
545 static void iwl_bg_ucode_trace(struct timer_list
*t
)
547 struct iwl_priv
*priv
= from_timer(priv
, t
, ucode_trace
);
549 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
552 if (priv
->event_log
.ucode_trace
) {
553 iwl_continuous_event_trace(priv
);
554 /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
555 mod_timer(&priv
->ucode_trace
,
556 jiffies
+ msecs_to_jiffies(UCODE_TRACE_PERIOD
));
560 static void iwl_bg_tx_flush(struct work_struct
*work
)
562 struct iwl_priv
*priv
=
563 container_of(work
, struct iwl_priv
, tx_flush
);
565 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
568 /* do nothing if rf-kill is on */
569 if (!iwl_is_ready_rf(priv
))
572 IWL_DEBUG_INFO(priv
, "device request: flush all tx frames\n");
573 iwlagn_dev_txfifo_flush(priv
);
577 * queue/FIFO/AC mapping definitions
580 static const u8 iwlagn_bss_ac_to_fifo
[] = {
587 static const u8 iwlagn_bss_ac_to_queue
[] = {
591 static const u8 iwlagn_pan_ac_to_fifo
[] = {
598 static const u8 iwlagn_pan_ac_to_queue
[] = {
602 static void iwl_init_context(struct iwl_priv
*priv
, u32 ucode_flags
)
607 * The default context is always valid,
608 * the PAN context depends on uCode.
610 priv
->valid_contexts
= BIT(IWL_RXON_CTX_BSS
);
611 if (ucode_flags
& IWL_UCODE_TLV_FLAGS_PAN
)
612 priv
->valid_contexts
|= BIT(IWL_RXON_CTX_PAN
);
614 for (i
= 0; i
< NUM_IWL_RXON_CTX
; i
++)
615 priv
->contexts
[i
].ctxid
= i
;
617 priv
->contexts
[IWL_RXON_CTX_BSS
].always_active
= true;
618 priv
->contexts
[IWL_RXON_CTX_BSS
].is_active
= true;
619 priv
->contexts
[IWL_RXON_CTX_BSS
].rxon_cmd
= REPLY_RXON
;
620 priv
->contexts
[IWL_RXON_CTX_BSS
].rxon_timing_cmd
= REPLY_RXON_TIMING
;
621 priv
->contexts
[IWL_RXON_CTX_BSS
].rxon_assoc_cmd
= REPLY_RXON_ASSOC
;
622 priv
->contexts
[IWL_RXON_CTX_BSS
].qos_cmd
= REPLY_QOS_PARAM
;
623 priv
->contexts
[IWL_RXON_CTX_BSS
].ap_sta_id
= IWL_AP_ID
;
624 priv
->contexts
[IWL_RXON_CTX_BSS
].wep_key_cmd
= REPLY_WEPKEY
;
625 priv
->contexts
[IWL_RXON_CTX_BSS
].bcast_sta_id
= IWLAGN_BROADCAST_ID
;
626 priv
->contexts
[IWL_RXON_CTX_BSS
].exclusive_interface_modes
=
627 BIT(NL80211_IFTYPE_ADHOC
) | BIT(NL80211_IFTYPE_MONITOR
);
628 priv
->contexts
[IWL_RXON_CTX_BSS
].interface_modes
=
629 BIT(NL80211_IFTYPE_STATION
);
630 priv
->contexts
[IWL_RXON_CTX_BSS
].ap_devtype
= RXON_DEV_TYPE_AP
;
631 priv
->contexts
[IWL_RXON_CTX_BSS
].ibss_devtype
= RXON_DEV_TYPE_IBSS
;
632 priv
->contexts
[IWL_RXON_CTX_BSS
].station_devtype
= RXON_DEV_TYPE_ESS
;
633 priv
->contexts
[IWL_RXON_CTX_BSS
].unused_devtype
= RXON_DEV_TYPE_ESS
;
634 memcpy(priv
->contexts
[IWL_RXON_CTX_BSS
].ac_to_queue
,
635 iwlagn_bss_ac_to_queue
, sizeof(iwlagn_bss_ac_to_queue
));
636 memcpy(priv
->contexts
[IWL_RXON_CTX_BSS
].ac_to_fifo
,
637 iwlagn_bss_ac_to_fifo
, sizeof(iwlagn_bss_ac_to_fifo
));
639 priv
->contexts
[IWL_RXON_CTX_PAN
].rxon_cmd
= REPLY_WIPAN_RXON
;
640 priv
->contexts
[IWL_RXON_CTX_PAN
].rxon_timing_cmd
=
641 REPLY_WIPAN_RXON_TIMING
;
642 priv
->contexts
[IWL_RXON_CTX_PAN
].rxon_assoc_cmd
=
643 REPLY_WIPAN_RXON_ASSOC
;
644 priv
->contexts
[IWL_RXON_CTX_PAN
].qos_cmd
= REPLY_WIPAN_QOS_PARAM
;
645 priv
->contexts
[IWL_RXON_CTX_PAN
].ap_sta_id
= IWL_AP_ID_PAN
;
646 priv
->contexts
[IWL_RXON_CTX_PAN
].wep_key_cmd
= REPLY_WIPAN_WEPKEY
;
647 priv
->contexts
[IWL_RXON_CTX_PAN
].bcast_sta_id
= IWLAGN_PAN_BCAST_ID
;
648 priv
->contexts
[IWL_RXON_CTX_PAN
].station_flags
= STA_FLG_PAN_STATION
;
649 priv
->contexts
[IWL_RXON_CTX_PAN
].interface_modes
=
650 BIT(NL80211_IFTYPE_STATION
) | BIT(NL80211_IFTYPE_AP
);
652 priv
->contexts
[IWL_RXON_CTX_PAN
].ap_devtype
= RXON_DEV_TYPE_CP
;
653 priv
->contexts
[IWL_RXON_CTX_PAN
].station_devtype
= RXON_DEV_TYPE_2STA
;
654 priv
->contexts
[IWL_RXON_CTX_PAN
].unused_devtype
= RXON_DEV_TYPE_P2P
;
655 memcpy(priv
->contexts
[IWL_RXON_CTX_PAN
].ac_to_queue
,
656 iwlagn_pan_ac_to_queue
, sizeof(iwlagn_pan_ac_to_queue
));
657 memcpy(priv
->contexts
[IWL_RXON_CTX_PAN
].ac_to_fifo
,
658 iwlagn_pan_ac_to_fifo
, sizeof(iwlagn_pan_ac_to_fifo
));
659 priv
->contexts
[IWL_RXON_CTX_PAN
].mcast_queue
= IWL_IPAN_MCAST_QUEUE
;
661 BUILD_BUG_ON(NUM_IWL_RXON_CTX
!= 2);
664 static void iwl_rf_kill_ct_config(struct iwl_priv
*priv
)
666 struct iwl_ct_kill_config cmd
;
667 struct iwl_ct_kill_throttling_config adv_cmd
;
670 iwl_write32(priv
->trans
, CSR_UCODE_DRV_GP1_CLR
,
671 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT
);
673 priv
->thermal_throttle
.ct_kill_toggle
= false;
675 if (priv
->lib
->support_ct_kill_exit
) {
676 adv_cmd
.critical_temperature_enter
=
677 cpu_to_le32(priv
->hw_params
.ct_kill_threshold
);
678 adv_cmd
.critical_temperature_exit
=
679 cpu_to_le32(priv
->hw_params
.ct_kill_exit_threshold
);
681 ret
= iwl_dvm_send_cmd_pdu(priv
,
682 REPLY_CT_KILL_CONFIG_CMD
,
683 0, sizeof(adv_cmd
), &adv_cmd
);
685 IWL_ERR(priv
, "REPLY_CT_KILL_CONFIG_CMD failed\n");
687 IWL_DEBUG_INFO(priv
, "REPLY_CT_KILL_CONFIG_CMD "
688 "succeeded, critical temperature enter is %d,"
690 priv
->hw_params
.ct_kill_threshold
,
691 priv
->hw_params
.ct_kill_exit_threshold
);
693 cmd
.critical_temperature_R
=
694 cpu_to_le32(priv
->hw_params
.ct_kill_threshold
);
696 ret
= iwl_dvm_send_cmd_pdu(priv
,
697 REPLY_CT_KILL_CONFIG_CMD
,
698 0, sizeof(cmd
), &cmd
);
700 IWL_ERR(priv
, "REPLY_CT_KILL_CONFIG_CMD failed\n");
702 IWL_DEBUG_INFO(priv
, "REPLY_CT_KILL_CONFIG_CMD "
704 "critical temperature is %d\n",
705 priv
->hw_params
.ct_kill_threshold
);
709 static int iwlagn_send_calib_cfg_rt(struct iwl_priv
*priv
, u32 cfg
)
711 struct iwl_calib_cfg_cmd calib_cfg_cmd
;
712 struct iwl_host_cmd cmd
= {
713 .id
= CALIBRATION_CFG_CMD
,
714 .len
= { sizeof(struct iwl_calib_cfg_cmd
), },
715 .data
= { &calib_cfg_cmd
, },
718 memset(&calib_cfg_cmd
, 0, sizeof(calib_cfg_cmd
));
719 calib_cfg_cmd
.ucd_calib_cfg
.once
.is_enable
= IWL_CALIB_RT_CFG_ALL
;
720 calib_cfg_cmd
.ucd_calib_cfg
.once
.start
= cpu_to_le32(cfg
);
722 return iwl_dvm_send_cmd(priv
, &cmd
);
726 static int iwlagn_send_tx_ant_config(struct iwl_priv
*priv
, u8 valid_tx_ant
)
728 struct iwl_tx_ant_config_cmd tx_ant_cmd
= {
729 .valid
= cpu_to_le32(valid_tx_ant
),
732 if (IWL_UCODE_API(priv
->fw
->ucode_ver
) > 1) {
733 IWL_DEBUG_HC(priv
, "select valid tx ant: %u\n", valid_tx_ant
);
734 return iwl_dvm_send_cmd_pdu(priv
, TX_ANT_CONFIGURATION_CMD
, 0,
735 sizeof(struct iwl_tx_ant_config_cmd
),
738 IWL_DEBUG_HC(priv
, "TX_ANT_CONFIGURATION_CMD not supported\n");
743 static void iwl_send_bt_config(struct iwl_priv
*priv
)
745 struct iwl_bt_cmd bt_cmd
= {
746 .lead_time
= BT_LEAD_TIME_DEF
,
747 .max_kill
= BT_MAX_KILL_DEF
,
752 if (!iwlwifi_mod_params
.bt_coex_active
)
753 bt_cmd
.flags
= BT_COEX_DISABLE
;
755 bt_cmd
.flags
= BT_COEX_ENABLE
;
757 priv
->bt_enable_flag
= bt_cmd
.flags
;
758 IWL_DEBUG_INFO(priv
, "BT coex %s\n",
759 (bt_cmd
.flags
== BT_COEX_DISABLE
) ? "disable" : "active");
761 if (iwl_dvm_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
762 0, sizeof(struct iwl_bt_cmd
), &bt_cmd
))
763 IWL_ERR(priv
, "failed to send BT Coex Config\n");
767 * iwl_alive_start - called after REPLY_ALIVE notification received
768 * from protocol/runtime uCode (initialization uCode's
769 * Alive gets handled by iwl_init_alive_start()).
771 int iwl_alive_start(struct iwl_priv
*priv
)
774 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
776 IWL_DEBUG_INFO(priv
, "Runtime Alive received.\n");
778 /* After the ALIVE response, we can send host commands to the uCode */
779 set_bit(STATUS_ALIVE
, &priv
->status
);
781 if (iwl_is_rfkill(priv
))
784 if (priv
->event_log
.ucode_trace
) {
785 /* start collecting data now */
786 mod_timer(&priv
->ucode_trace
, jiffies
);
789 /* download priority table before any calibration request */
790 if (priv
->lib
->bt_params
&&
791 priv
->lib
->bt_params
->advanced_bt_coexist
) {
792 /* Configure Bluetooth device coexistence support */
793 if (priv
->lib
->bt_params
->bt_sco_disable
)
794 priv
->bt_enable_pspoll
= false;
796 priv
->bt_enable_pspoll
= true;
798 priv
->bt_valid
= IWLAGN_BT_ALL_VALID_MSK
;
799 priv
->kill_ack_mask
= IWLAGN_BT_KILL_ACK_MASK_DEFAULT
;
800 priv
->kill_cts_mask
= IWLAGN_BT_KILL_CTS_MASK_DEFAULT
;
801 iwlagn_send_advance_bt_config(priv
);
802 priv
->bt_valid
= IWLAGN_BT_VALID_ENABLE_FLAGS
;
803 priv
->cur_rssi_ctx
= NULL
;
805 iwl_send_prio_tbl(priv
);
807 /* FIXME: w/a to force change uCode BT state machine */
808 ret
= iwl_send_bt_env(priv
, IWL_BT_COEX_ENV_OPEN
,
809 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2
);
812 ret
= iwl_send_bt_env(priv
, IWL_BT_COEX_ENV_CLOSE
,
813 BT_COEX_PRIO_TBL_EVT_INIT_CALIB2
);
816 } else if (priv
->lib
->bt_params
) {
818 * default is 2-wire BT coexexistence support
820 iwl_send_bt_config(priv
);
824 * Perform runtime calibrations, including DC calibration.
826 iwlagn_send_calib_cfg_rt(priv
, IWL_CALIB_CFG_DC_IDX
);
828 ieee80211_wake_queues(priv
->hw
);
830 /* Configure Tx antenna selection based on H/W config */
831 iwlagn_send_tx_ant_config(priv
, priv
->nvm_data
->valid_tx_ant
);
833 if (iwl_is_associated_ctx(ctx
) && !priv
->wowlan
) {
834 struct iwl_rxon_cmd
*active_rxon
=
835 (struct iwl_rxon_cmd
*)&ctx
->active
;
836 /* apply any changes in staging */
837 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
838 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
840 struct iwl_rxon_context
*tmp
;
841 /* Initialize our rx_config data */
842 for_each_context(priv
, tmp
)
843 iwl_connection_init_rx_config(priv
, tmp
);
845 iwlagn_set_rxon_chain(priv
, ctx
);
849 /* WoWLAN ucode will not reply in the same way, skip it */
850 iwl_reset_run_time_calib(priv
);
853 set_bit(STATUS_READY
, &priv
->status
);
855 /* Configure the adapter for unassociated operation */
856 ret
= iwlagn_commit_rxon(priv
, ctx
);
860 /* At this point, the NIC is initialized and operational */
861 iwl_rf_kill_ct_config(priv
);
863 IWL_DEBUG_INFO(priv
, "ALIVE processing complete.\n");
865 return iwl_power_update_mode(priv
, true);
869 * iwl_clear_driver_stations - clear knowledge of all stations from driver
870 * @priv: iwl priv struct
872 * This is called during iwl_down() to make sure that in the case
873 * we're coming there from a hardware restart mac80211 will be
874 * able to reconfigure stations -- if we're getting there in the
875 * normal down flow then the stations will already be cleared.
877 static void iwl_clear_driver_stations(struct iwl_priv
*priv
)
879 struct iwl_rxon_context
*ctx
;
881 spin_lock_bh(&priv
->sta_lock
);
882 memset(priv
->stations
, 0, sizeof(priv
->stations
));
883 priv
->num_stations
= 0;
885 priv
->ucode_key_table
= 0;
887 for_each_context(priv
, ctx
) {
889 * Remove all key information that is not stored as part
890 * of station information since mac80211 may not have had
891 * a chance to remove all the keys. When device is
892 * reconfigured by mac80211 after an error all keys will
895 memset(ctx
->wep_keys
, 0, sizeof(ctx
->wep_keys
));
896 ctx
->key_mapping_keys
= 0;
899 spin_unlock_bh(&priv
->sta_lock
);
902 void iwl_down(struct iwl_priv
*priv
)
906 IWL_DEBUG_INFO(priv
, DRV_NAME
" is going down\n");
908 lockdep_assert_held(&priv
->mutex
);
910 iwl_scan_cancel_timeout(priv
, 200);
913 test_and_set_bit(STATUS_EXIT_PENDING
, &priv
->status
);
915 iwl_clear_ucode_stations(priv
, NULL
);
916 iwl_dealloc_bcast_stations(priv
);
917 iwl_clear_driver_stations(priv
);
919 /* reset BT coex data */
921 priv
->cur_rssi_ctx
= NULL
;
923 if (priv
->lib
->bt_params
)
924 priv
->bt_traffic_load
=
925 priv
->lib
->bt_params
->bt_init_traffic_load
;
927 priv
->bt_traffic_load
= 0;
928 priv
->bt_full_concurrent
= false;
929 priv
->bt_ci_compliance
= 0;
931 /* Wipe out the EXIT_PENDING status bit if we are not actually
932 * exiting the module */
934 clear_bit(STATUS_EXIT_PENDING
, &priv
->status
);
936 if (priv
->mac80211_registered
)
937 ieee80211_stop_queues(priv
->hw
);
939 priv
->ucode_loaded
= false;
940 iwl_trans_stop_device(priv
->trans
);
942 /* Set num_aux_in_flight must be done after the transport is stopped */
943 atomic_set(&priv
->num_aux_in_flight
, 0);
945 /* Clear out all status bits but a few that are stable across reset */
946 priv
->status
&= test_bit(STATUS_RF_KILL_HW
, &priv
->status
) <<
948 test_bit(STATUS_FW_ERROR
, &priv
->status
) <<
950 test_bit(STATUS_EXIT_PENDING
, &priv
->status
) <<
953 dev_kfree_skb(priv
->beacon_skb
);
954 priv
->beacon_skb
= NULL
;
957 /*****************************************************************************
959 * Workqueue callbacks
961 *****************************************************************************/
963 static void iwl_bg_run_time_calib_work(struct work_struct
*work
)
965 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
,
966 run_time_calib_work
);
968 mutex_lock(&priv
->mutex
);
970 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
) ||
971 test_bit(STATUS_SCANNING
, &priv
->status
)) {
972 mutex_unlock(&priv
->mutex
);
976 if (priv
->start_calib
) {
977 iwl_chain_noise_calibration(priv
);
978 iwl_sensitivity_calibration(priv
);
981 mutex_unlock(&priv
->mutex
);
984 void iwlagn_prepare_restart(struct iwl_priv
*priv
)
986 bool bt_full_concurrent
;
993 lockdep_assert_held(&priv
->mutex
);
998 * __iwl_down() will clear the BT status variables,
999 * which is correct, but when we restart we really
1000 * want to keep them so restore them afterwards.
1002 * The restart process will later pick them up and
1003 * re-configure the hw when we reconfigure the BT
1006 bt_full_concurrent
= priv
->bt_full_concurrent
;
1007 bt_ci_compliance
= priv
->bt_ci_compliance
;
1008 bt_load
= priv
->bt_traffic_load
;
1009 bt_status
= priv
->bt_status
;
1010 bt_is_sco
= priv
->bt_is_sco
;
1014 priv
->bt_full_concurrent
= bt_full_concurrent
;
1015 priv
->bt_ci_compliance
= bt_ci_compliance
;
1016 priv
->bt_traffic_load
= bt_load
;
1017 priv
->bt_status
= bt_status
;
1018 priv
->bt_is_sco
= bt_is_sco
;
1020 /* reset aggregation queues */
1021 for (i
= IWLAGN_FIRST_AMPDU_QUEUE
; i
< IWL_MAX_HW_QUEUES
; i
++)
1022 priv
->queue_to_mac80211
[i
] = IWL_INVALID_MAC80211_QUEUE
;
1023 /* and stop counts */
1024 for (i
= 0; i
< IWL_MAX_HW_QUEUES
; i
++)
1025 atomic_set(&priv
->queue_stop_count
[i
], 0);
1027 memset(priv
->agg_q_alloc
, 0, sizeof(priv
->agg_q_alloc
));
1030 static void iwl_bg_restart(struct work_struct
*data
)
1032 struct iwl_priv
*priv
= container_of(data
, struct iwl_priv
, restart
);
1034 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1037 if (test_and_clear_bit(STATUS_FW_ERROR
, &priv
->status
)) {
1038 mutex_lock(&priv
->mutex
);
1039 iwlagn_prepare_restart(priv
);
1040 mutex_unlock(&priv
->mutex
);
1041 iwl_cancel_deferred_work(priv
);
1042 if (priv
->mac80211_registered
)
1043 ieee80211_restart_hw(priv
->hw
);
1046 "Cannot request restart before registering with mac80211\n");
1052 /*****************************************************************************
1054 * driver setup and teardown
1056 *****************************************************************************/
1058 static void iwl_setup_deferred_work(struct iwl_priv
*priv
)
1060 priv
->workqueue
= alloc_ordered_workqueue(DRV_NAME
, 0);
1062 INIT_WORK(&priv
->restart
, iwl_bg_restart
);
1063 INIT_WORK(&priv
->beacon_update
, iwl_bg_beacon_update
);
1064 INIT_WORK(&priv
->run_time_calib_work
, iwl_bg_run_time_calib_work
);
1065 INIT_WORK(&priv
->tx_flush
, iwl_bg_tx_flush
);
1066 INIT_WORK(&priv
->bt_full_concurrency
, iwl_bg_bt_full_concurrency
);
1067 INIT_WORK(&priv
->bt_runtime_config
, iwl_bg_bt_runtime_config
);
1069 iwl_setup_scan_deferred_work(priv
);
1071 if (priv
->lib
->bt_params
)
1072 iwlagn_bt_setup_deferred_work(priv
);
1074 timer_setup(&priv
->statistics_periodic
, iwl_bg_statistics_periodic
, 0);
1076 timer_setup(&priv
->ucode_trace
, iwl_bg_ucode_trace
, 0);
1079 void iwl_cancel_deferred_work(struct iwl_priv
*priv
)
1081 if (priv
->lib
->bt_params
)
1082 iwlagn_bt_cancel_deferred_work(priv
);
1084 cancel_work_sync(&priv
->run_time_calib_work
);
1085 cancel_work_sync(&priv
->beacon_update
);
1087 iwl_cancel_scan_deferred_work(priv
);
1089 cancel_work_sync(&priv
->bt_full_concurrency
);
1090 cancel_work_sync(&priv
->bt_runtime_config
);
1092 del_timer_sync(&priv
->statistics_periodic
);
1093 del_timer_sync(&priv
->ucode_trace
);
1096 static int iwl_init_drv(struct iwl_priv
*priv
)
1098 spin_lock_init(&priv
->sta_lock
);
1100 mutex_init(&priv
->mutex
);
1102 INIT_LIST_HEAD(&priv
->calib_results
);
1104 priv
->band
= NL80211_BAND_2GHZ
;
1106 priv
->plcp_delta_threshold
= priv
->lib
->plcp_delta_threshold
;
1108 priv
->iw_mode
= NL80211_IFTYPE_STATION
;
1109 priv
->current_ht_config
.smps
= IEEE80211_SMPS_STATIC
;
1110 priv
->missed_beacon_threshold
= IWL_MISSED_BEACON_THRESHOLD_DEF
;
1111 priv
->agg_tids_count
= 0;
1113 priv
->rx_statistics_jiffies
= jiffies
;
1115 /* Choose which receivers/antennas to use */
1116 iwlagn_set_rxon_chain(priv
, &priv
->contexts
[IWL_RXON_CTX_BSS
]);
1118 iwl_init_scan_params(priv
);
1121 if (priv
->lib
->bt_params
&&
1122 priv
->lib
->bt_params
->advanced_bt_coexist
) {
1123 priv
->kill_ack_mask
= IWLAGN_BT_KILL_ACK_MASK_DEFAULT
;
1124 priv
->kill_cts_mask
= IWLAGN_BT_KILL_CTS_MASK_DEFAULT
;
1125 priv
->bt_valid
= IWLAGN_BT_ALL_VALID_MSK
;
1126 priv
->bt_on_thresh
= BT_ON_THRESHOLD_DEF
;
1127 priv
->bt_duration
= BT_DURATION_LIMIT_DEF
;
1128 priv
->dynamic_frag_thresh
= BT_FRAG_THRESHOLD_DEF
;
1134 static void iwl_uninit_drv(struct iwl_priv
*priv
)
1136 kfree(priv
->scan_cmd
);
1137 kfree(priv
->beacon_cmd
);
1138 kfree(rcu_dereference_raw(priv
->noa_data
));
1139 iwl_calib_free_results(priv
);
1140 #ifdef CONFIG_IWLWIFI_DEBUGFS
1141 kfree(priv
->wowlan_sram
);
1145 static void iwl_set_hw_params(struct iwl_priv
*priv
)
1147 if (priv
->cfg
->ht_params
)
1148 priv
->hw_params
.use_rts_for_aggregation
=
1149 priv
->cfg
->ht_params
->use_rts_for_aggregation
;
1151 /* Device-specific setup */
1152 priv
->lib
->set_hw_params(priv
);
1157 /* show what optional capabilities we have */
1158 static void iwl_option_config(struct iwl_priv
*priv
)
1160 #ifdef CONFIG_IWLWIFI_DEBUG
1161 IWL_INFO(priv
, "CONFIG_IWLWIFI_DEBUG enabled\n");
1163 IWL_INFO(priv
, "CONFIG_IWLWIFI_DEBUG disabled\n");
1166 #ifdef CONFIG_IWLWIFI_DEBUGFS
1167 IWL_INFO(priv
, "CONFIG_IWLWIFI_DEBUGFS enabled\n");
1169 IWL_INFO(priv
, "CONFIG_IWLWIFI_DEBUGFS disabled\n");
1172 #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
1173 IWL_INFO(priv
, "CONFIG_IWLWIFI_DEVICE_TRACING enabled\n");
1175 IWL_INFO(priv
, "CONFIG_IWLWIFI_DEVICE_TRACING disabled\n");
1179 static int iwl_eeprom_init_hw_params(struct iwl_priv
*priv
)
1181 struct iwl_nvm_data
*data
= priv
->nvm_data
;
1183 if (data
->sku_cap_11n_enable
&&
1184 !priv
->cfg
->ht_params
) {
1185 IWL_ERR(priv
, "Invalid 11n configuration\n");
1189 if (!data
->sku_cap_11n_enable
&& !data
->sku_cap_band_24ghz_enable
&&
1190 !data
->sku_cap_band_52ghz_enable
) {
1191 IWL_ERR(priv
, "Invalid device sku\n");
1195 IWL_DEBUG_INFO(priv
,
1196 "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n",
1197 data
->sku_cap_band_24ghz_enable
? "" : "NOT", "enabled",
1198 data
->sku_cap_band_52ghz_enable
? "" : "NOT", "enabled",
1199 data
->sku_cap_11n_enable
? "" : "NOT", "enabled");
1201 priv
->hw_params
.tx_chains_num
=
1202 num_of_ant(data
->valid_tx_ant
);
1203 if (priv
->cfg
->rx_with_siso_diversity
)
1204 priv
->hw_params
.rx_chains_num
= 1;
1206 priv
->hw_params
.rx_chains_num
=
1207 num_of_ant(data
->valid_rx_ant
);
1209 IWL_DEBUG_INFO(priv
, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n",
1211 data
->valid_rx_ant
);
1216 static int iwl_nvm_check_version(struct iwl_nvm_data
*data
,
1217 struct iwl_trans
*trans
)
1219 if (data
->nvm_version
>= trans
->cfg
->nvm_ver
||
1220 data
->calib_version
>= trans
->cfg
->nvm_calib_ver
) {
1221 IWL_DEBUG_INFO(trans
, "device EEPROM VER=0x%x, CALIB=0x%x\n",
1222 data
->nvm_version
, data
->calib_version
);
1227 "Unsupported (too old) EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
1228 data
->nvm_version
, trans
->cfg
->nvm_ver
,
1229 data
->calib_version
, trans
->cfg
->nvm_calib_ver
);
1233 static struct iwl_op_mode
*iwl_op_mode_dvm_start(struct iwl_trans
*trans
,
1234 const struct iwl_cfg
*cfg
,
1235 const struct iwl_fw
*fw
,
1236 struct dentry
*dbgfs_dir
)
1238 struct iwl_priv
*priv
;
1239 struct ieee80211_hw
*hw
;
1240 struct iwl_op_mode
*op_mode
;
1243 struct iwl_trans_config trans_cfg
= {};
1244 static const u8 no_reclaim_cmds
[] = {
1247 REPLY_COMPRESSED_BA
,
1248 STATISTICS_NOTIFICATION
,
1253 /************************
1254 * 1. Allocating HW data
1255 ************************/
1256 hw
= iwl_alloc_all();
1258 pr_err("%s: Cannot allocate network device\n", trans
->name
);
1263 op_mode
->ops
= &iwl_dvm_ops
;
1264 priv
= IWL_OP_MODE_GET_DVM(op_mode
);
1265 priv
->trans
= trans
;
1266 priv
->dev
= trans
->dev
;
1270 switch (priv
->trans
->trans_cfg
->device_family
) {
1271 case IWL_DEVICE_FAMILY_1000
:
1272 case IWL_DEVICE_FAMILY_100
:
1273 priv
->lib
= &iwl_dvm_1000_cfg
;
1275 case IWL_DEVICE_FAMILY_2000
:
1276 priv
->lib
= &iwl_dvm_2000_cfg
;
1278 case IWL_DEVICE_FAMILY_105
:
1279 priv
->lib
= &iwl_dvm_105_cfg
;
1281 case IWL_DEVICE_FAMILY_2030
:
1282 case IWL_DEVICE_FAMILY_135
:
1283 priv
->lib
= &iwl_dvm_2030_cfg
;
1285 case IWL_DEVICE_FAMILY_5000
:
1286 priv
->lib
= &iwl_dvm_5000_cfg
;
1288 case IWL_DEVICE_FAMILY_5150
:
1289 priv
->lib
= &iwl_dvm_5150_cfg
;
1291 case IWL_DEVICE_FAMILY_6000
:
1292 case IWL_DEVICE_FAMILY_6000i
:
1293 priv
->lib
= &iwl_dvm_6000_cfg
;
1295 case IWL_DEVICE_FAMILY_6005
:
1296 priv
->lib
= &iwl_dvm_6005_cfg
;
1298 case IWL_DEVICE_FAMILY_6050
:
1299 case IWL_DEVICE_FAMILY_6150
:
1300 priv
->lib
= &iwl_dvm_6050_cfg
;
1302 case IWL_DEVICE_FAMILY_6030
:
1303 priv
->lib
= &iwl_dvm_6030_cfg
;
1309 if (WARN_ON(!priv
->lib
))
1313 * Populate the state variables that the transport layer needs
1316 trans_cfg
.op_mode
= op_mode
;
1317 trans_cfg
.no_reclaim_cmds
= no_reclaim_cmds
;
1318 trans_cfg
.n_no_reclaim_cmds
= ARRAY_SIZE(no_reclaim_cmds
);
1320 switch (iwlwifi_mod_params
.amsdu_size
) {
1323 trans_cfg
.rx_buf_size
= IWL_AMSDU_4K
;
1326 trans_cfg
.rx_buf_size
= IWL_AMSDU_8K
;
1330 trans_cfg
.rx_buf_size
= IWL_AMSDU_4K
;
1331 pr_err("Unsupported amsdu_size: %d\n",
1332 iwlwifi_mod_params
.amsdu_size
);
1335 trans_cfg
.cmd_q_wdg_timeout
= IWL_WATCHDOG_DISABLED
;
1337 trans_cfg
.command_groups
= iwl_dvm_groups
;
1338 trans_cfg
.command_groups_size
= ARRAY_SIZE(iwl_dvm_groups
);
1340 trans_cfg
.cmd_fifo
= IWLAGN_CMD_FIFO_NUM
;
1341 trans_cfg
.cb_data_offs
= offsetof(struct ieee80211_tx_info
,
1344 WARN_ON(sizeof(priv
->transport_queue_stop
) * BITS_PER_BYTE
<
1345 priv
->trans
->trans_cfg
->base_params
->num_of_queues
);
1347 ucode_flags
= fw
->ucode_capa
.flags
;
1349 if (ucode_flags
& IWL_UCODE_TLV_FLAGS_PAN
) {
1350 priv
->sta_key_max_num
= STA_KEY_MAX_NUM_PAN
;
1351 trans_cfg
.cmd_queue
= IWL_IPAN_CMD_QUEUE_NUM
;
1353 priv
->sta_key_max_num
= STA_KEY_MAX_NUM
;
1354 trans_cfg
.cmd_queue
= IWL_DEFAULT_CMD_QUEUE_NUM
;
1357 /* Configure transport layer */
1358 iwl_trans_configure(priv
->trans
, &trans_cfg
);
1360 trans
->rx_mpdu_cmd
= REPLY_RX_MPDU_CMD
;
1361 trans
->rx_mpdu_cmd_hdr_size
= sizeof(struct iwl_rx_mpdu_res_start
);
1362 trans
->command_groups
= trans_cfg
.command_groups
;
1363 trans
->command_groups_size
= trans_cfg
.command_groups_size
;
1365 /* At this point both hw and priv are allocated. */
1367 SET_IEEE80211_DEV(priv
->hw
, priv
->trans
->dev
);
1369 iwl_option_config(priv
);
1371 IWL_DEBUG_INFO(priv
, "*** LOAD DRIVER ***\n");
1373 /* is antenna coupling more than 35dB ? */
1374 priv
->bt_ant_couple_ok
=
1375 (iwlwifi_mod_params
.antenna_coupling
>
1376 IWL_BT_ANTENNA_COUPLING_THRESHOLD
) ?
1379 /* bt channel inhibition enabled*/
1380 priv
->bt_ch_announce
= true;
1381 IWL_DEBUG_INFO(priv
, "BT channel inhibition is %s\n",
1382 (priv
->bt_ch_announce
) ? "On" : "Off");
1384 /* these spin locks will be used in apm_ops.init and EEPROM access
1385 * we should init now
1387 spin_lock_init(&priv
->statistics
.lock
);
1389 /***********************
1390 * 2. Read REV register
1391 ***********************/
1392 IWL_INFO(priv
, "Detected %s, REV=0x%X\n",
1393 priv
->trans
->name
, priv
->trans
->hw_rev
);
1395 if (iwl_trans_start_hw(priv
->trans
))
1398 /* Read the EEPROM */
1399 if (iwl_read_eeprom(priv
->trans
, &priv
->eeprom_blob
,
1400 &priv
->eeprom_blob_size
)) {
1401 IWL_ERR(priv
, "Unable to init EEPROM\n");
1405 /* Reset chip to save power until we load uCode during "up". */
1406 iwl_trans_stop_device(priv
->trans
);
1408 priv
->nvm_data
= iwl_parse_eeprom_data(priv
->trans
, priv
->cfg
,
1410 priv
->eeprom_blob_size
);
1411 if (!priv
->nvm_data
)
1412 goto out_free_eeprom_blob
;
1414 if (iwl_nvm_check_version(priv
->nvm_data
, priv
->trans
))
1415 goto out_free_eeprom
;
1417 if (iwl_eeprom_init_hw_params(priv
))
1418 goto out_free_eeprom
;
1420 /* extract MAC Address */
1421 memcpy(priv
->addresses
[0].addr
, priv
->nvm_data
->hw_addr
, ETH_ALEN
);
1422 IWL_DEBUG_INFO(priv
, "MAC address: %pM\n", priv
->addresses
[0].addr
);
1423 priv
->hw
->wiphy
->addresses
= priv
->addresses
;
1424 priv
->hw
->wiphy
->n_addresses
= 1;
1425 num_mac
= priv
->nvm_data
->n_hw_addrs
;
1427 memcpy(priv
->addresses
[1].addr
, priv
->addresses
[0].addr
,
1429 priv
->addresses
[1].addr
[5]++;
1430 priv
->hw
->wiphy
->n_addresses
++;
1433 /************************
1434 * 4. Setup HW constants
1435 ************************/
1436 iwl_set_hw_params(priv
);
1438 if (!(priv
->nvm_data
->sku_cap_ipan_enable
)) {
1439 IWL_DEBUG_INFO(priv
, "Your EEPROM disabled PAN\n");
1440 ucode_flags
&= ~IWL_UCODE_TLV_FLAGS_PAN
;
1442 * if not PAN, then don't support P2P -- might be a uCode
1443 * packaging bug or due to the eeprom check above
1445 priv
->sta_key_max_num
= STA_KEY_MAX_NUM
;
1446 trans_cfg
.cmd_queue
= IWL_DEFAULT_CMD_QUEUE_NUM
;
1448 /* Configure transport layer again*/
1449 iwl_trans_configure(priv
->trans
, &trans_cfg
);
1452 /*******************
1454 *******************/
1455 for (i
= 0; i
< IWL_MAX_HW_QUEUES
; i
++) {
1456 priv
->queue_to_mac80211
[i
] = IWL_INVALID_MAC80211_QUEUE
;
1457 if (i
< IWLAGN_FIRST_AMPDU_QUEUE
&&
1458 i
!= IWL_DEFAULT_CMD_QUEUE_NUM
&&
1459 i
!= IWL_IPAN_CMD_QUEUE_NUM
)
1460 priv
->queue_to_mac80211
[i
] = i
;
1461 atomic_set(&priv
->queue_stop_count
[i
], 0);
1464 if (iwl_init_drv(priv
))
1465 goto out_free_eeprom
;
1467 /* At this point both hw and priv are initialized. */
1469 /********************
1471 ********************/
1472 iwl_setup_deferred_work(priv
);
1473 iwl_setup_rx_handlers(priv
);
1475 iwl_power_initialize(priv
);
1476 iwl_tt_initialize(priv
);
1478 snprintf(priv
->hw
->wiphy
->fw_version
,
1479 sizeof(priv
->hw
->wiphy
->fw_version
),
1480 "%s", fw
->fw_version
);
1482 priv
->new_scan_threshold_behaviour
=
1483 !!(ucode_flags
& IWL_UCODE_TLV_FLAGS_NEWSCAN
);
1485 priv
->phy_calib_chain_noise_reset_cmd
=
1486 fw
->ucode_capa
.standard_phy_calibration_size
;
1487 priv
->phy_calib_chain_noise_gain_cmd
=
1488 fw
->ucode_capa
.standard_phy_calibration_size
+ 1;
1490 /* initialize all valid contexts */
1491 iwl_init_context(priv
, ucode_flags
);
1493 /**************************************************
1494 * This is still part of probe() in a sense...
1496 * 7. Setup and register with mac80211 and debugfs
1497 **************************************************/
1498 if (iwlagn_mac_setup_register(priv
, &fw
->ucode_capa
))
1499 goto out_destroy_workqueue
;
1501 iwl_dbgfs_register(priv
, dbgfs_dir
);
1505 out_destroy_workqueue
:
1507 iwl_cancel_deferred_work(priv
);
1508 destroy_workqueue(priv
->workqueue
);
1509 priv
->workqueue
= NULL
;
1510 iwl_uninit_drv(priv
);
1511 out_free_eeprom_blob
:
1512 kfree(priv
->eeprom_blob
);
1514 kfree(priv
->nvm_data
);
1516 ieee80211_free_hw(priv
->hw
);
1522 static void iwl_op_mode_dvm_stop(struct iwl_op_mode
*op_mode
)
1524 struct iwl_priv
*priv
= IWL_OP_MODE_GET_DVM(op_mode
);
1526 IWL_DEBUG_INFO(priv
, "*** UNLOAD DRIVER ***\n");
1528 iwlagn_mac_unregister(priv
);
1532 kfree(priv
->eeprom_blob
);
1533 kfree(priv
->nvm_data
);
1535 /*netif_stop_queue(dev); */
1536 flush_workqueue(priv
->workqueue
);
1538 /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
1539 * priv->workqueue... so we can't take down the workqueue
1541 destroy_workqueue(priv
->workqueue
);
1542 priv
->workqueue
= NULL
;
1544 iwl_uninit_drv(priv
);
1546 dev_kfree_skb(priv
->beacon_skb
);
1548 iwl_trans_op_mode_leave(priv
->trans
);
1549 ieee80211_free_hw(priv
->hw
);
1552 static const char * const desc_lookup_text
[] = {
1557 "NMI_INTERRUPT_WDG",
1561 "HW_ERROR_TUNE_LOCK",
1562 "HW_ERROR_TEMPERATURE",
1563 "ILLEGAL_CHAN_FREQ",
1566 "NMI_INTERRUPT_HOST",
1567 "NMI_INTERRUPT_ACTION_PT",
1568 "NMI_INTERRUPT_UNKNOWN",
1569 "UCODE_VERSION_MISMATCH",
1570 "HW_ERROR_ABS_LOCK",
1571 "HW_ERROR_CAL_LOCK_FAIL",
1572 "NMI_INTERRUPT_INST_ACTION_PT",
1573 "NMI_INTERRUPT_DATA_ACTION_PT",
1575 "NMI_INTERRUPT_TRM",
1576 "NMI_INTERRUPT_BREAK_POINT",
1583 static struct { char *name
; u8 num
; } advanced_lookup
[] = {
1584 { "NMI_INTERRUPT_WDG", 0x34 },
1585 { "SYSASSERT", 0x35 },
1586 { "UCODE_VERSION_MISMATCH", 0x37 },
1587 { "BAD_COMMAND", 0x38 },
1588 { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
1589 { "FATAL_ERROR", 0x3D },
1590 { "NMI_TRM_HW_ERR", 0x46 },
1591 { "NMI_INTERRUPT_TRM", 0x4C },
1592 { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
1593 { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
1594 { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
1595 { "NMI_INTERRUPT_HOST", 0x66 },
1596 { "NMI_INTERRUPT_ACTION_PT", 0x7C },
1597 { "NMI_INTERRUPT_UNKNOWN", 0x84 },
1598 { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
1599 { "ADVANCED_SYSASSERT", 0 },
1602 static const char *desc_lookup(u32 num
)
1605 int max
= ARRAY_SIZE(desc_lookup_text
);
1608 return desc_lookup_text
[num
];
1610 max
= ARRAY_SIZE(advanced_lookup
) - 1;
1611 for (i
= 0; i
< max
; i
++) {
1612 if (advanced_lookup
[i
].num
== num
)
1615 return advanced_lookup
[i
].name
;
1618 #define ERROR_START_OFFSET (1 * sizeof(u32))
1619 #define ERROR_ELEM_SIZE (7 * sizeof(u32))
1621 static void iwl_dump_nic_error_log(struct iwl_priv
*priv
)
1623 struct iwl_trans
*trans
= priv
->trans
;
1625 struct iwl_error_event_table table
;
1627 base
= priv
->device_pointers
.error_event_table
;
1628 if (priv
->cur_ucode
== IWL_UCODE_INIT
) {
1630 base
= priv
->fw
->init_errlog_ptr
;
1633 base
= priv
->fw
->inst_errlog_ptr
;
1636 if (!iwlagn_hw_valid_rtc_data_addr(base
)) {
1638 "Not valid error log pointer 0x%08X for %s uCode\n",
1640 (priv
->cur_ucode
== IWL_UCODE_INIT
)
1645 /*TODO: Update dbgfs with ISR error stats obtained below */
1646 iwl_trans_read_mem_bytes(trans
, base
, &table
, sizeof(table
));
1648 if (ERROR_START_OFFSET
<= table
.valid
* ERROR_ELEM_SIZE
) {
1649 IWL_ERR(trans
, "Start IWL Error Log Dump:\n");
1650 IWL_ERR(trans
, "Status: 0x%08lX, count: %d\n",
1651 priv
->status
, table
.valid
);
1654 IWL_ERR(priv
, "0x%08X | %-28s\n", table
.error_id
,
1655 desc_lookup(table
.error_id
));
1656 IWL_ERR(priv
, "0x%08X | uPc\n", table
.pc
);
1657 IWL_ERR(priv
, "0x%08X | branchlink1\n", table
.blink1
);
1658 IWL_ERR(priv
, "0x%08X | branchlink2\n", table
.blink2
);
1659 IWL_ERR(priv
, "0x%08X | interruptlink1\n", table
.ilink1
);
1660 IWL_ERR(priv
, "0x%08X | interruptlink2\n", table
.ilink2
);
1661 IWL_ERR(priv
, "0x%08X | data1\n", table
.data1
);
1662 IWL_ERR(priv
, "0x%08X | data2\n", table
.data2
);
1663 IWL_ERR(priv
, "0x%08X | line\n", table
.line
);
1664 IWL_ERR(priv
, "0x%08X | beacon time\n", table
.bcon_time
);
1665 IWL_ERR(priv
, "0x%08X | tsf low\n", table
.tsf_low
);
1666 IWL_ERR(priv
, "0x%08X | tsf hi\n", table
.tsf_hi
);
1667 IWL_ERR(priv
, "0x%08X | time gp1\n", table
.gp1
);
1668 IWL_ERR(priv
, "0x%08X | time gp2\n", table
.gp2
);
1669 IWL_ERR(priv
, "0x%08X | time gp3\n", table
.gp3
);
1670 IWL_ERR(priv
, "0x%08X | uCode version\n", table
.ucode_ver
);
1671 IWL_ERR(priv
, "0x%08X | hw version\n", table
.hw_ver
);
1672 IWL_ERR(priv
, "0x%08X | board version\n", table
.brd_ver
);
1673 IWL_ERR(priv
, "0x%08X | hcmd\n", table
.hcmd
);
1674 IWL_ERR(priv
, "0x%08X | isr0\n", table
.isr0
);
1675 IWL_ERR(priv
, "0x%08X | isr1\n", table
.isr1
);
1676 IWL_ERR(priv
, "0x%08X | isr2\n", table
.isr2
);
1677 IWL_ERR(priv
, "0x%08X | isr3\n", table
.isr3
);
1678 IWL_ERR(priv
, "0x%08X | isr4\n", table
.isr4
);
1679 IWL_ERR(priv
, "0x%08X | isr_pref\n", table
.isr_pref
);
1680 IWL_ERR(priv
, "0x%08X | wait_event\n", table
.wait_event
);
1681 IWL_ERR(priv
, "0x%08X | l2p_control\n", table
.l2p_control
);
1682 IWL_ERR(priv
, "0x%08X | l2p_duration\n", table
.l2p_duration
);
1683 IWL_ERR(priv
, "0x%08X | l2p_mhvalid\n", table
.l2p_mhvalid
);
1684 IWL_ERR(priv
, "0x%08X | l2p_addr_match\n", table
.l2p_addr_match
);
1685 IWL_ERR(priv
, "0x%08X | lmpm_pmg_sel\n", table
.lmpm_pmg_sel
);
1686 IWL_ERR(priv
, "0x%08X | timestamp\n", table
.u_timestamp
);
1687 IWL_ERR(priv
, "0x%08X | flow_handler\n", table
.flow_handler
);
1690 #define EVENT_START_OFFSET (4 * sizeof(u32))
1693 * iwl_print_event_log - Dump error event log to syslog
1696 static int iwl_print_event_log(struct iwl_priv
*priv
, u32 start_idx
,
1697 u32 num_events
, u32 mode
,
1698 int pos
, char **buf
, size_t bufsz
)
1701 u32 base
; /* SRAM byte address of event log header */
1702 u32 event_size
; /* 2 u32s, or 3 u32s if timestamp recorded */
1703 u32 ptr
; /* SRAM byte address of log data */
1704 u32 ev
, time
, data
; /* event log data */
1705 unsigned long reg_flags
;
1707 struct iwl_trans
*trans
= priv
->trans
;
1709 if (num_events
== 0)
1712 base
= priv
->device_pointers
.log_event_table
;
1713 if (priv
->cur_ucode
== IWL_UCODE_INIT
) {
1715 base
= priv
->fw
->init_evtlog_ptr
;
1718 base
= priv
->fw
->inst_evtlog_ptr
;
1722 event_size
= 2 * sizeof(u32
);
1724 event_size
= 3 * sizeof(u32
);
1726 ptr
= base
+ EVENT_START_OFFSET
+ (start_idx
* event_size
);
1728 /* Make sure device is powered up for SRAM reads */
1729 if (!iwl_trans_grab_nic_access(trans
, ®_flags
))
1732 /* Set starting address; reads will auto-increment */
1733 iwl_write32(trans
, HBUS_TARG_MEM_RADDR
, ptr
);
1735 /* "time" is actually "data" for mode 0 (no timestamp).
1736 * place event id # at far right for easier visual parsing. */
1737 for (i
= 0; i
< num_events
; i
++) {
1738 ev
= iwl_read32(trans
, HBUS_TARG_MEM_RDAT
);
1739 time
= iwl_read32(trans
, HBUS_TARG_MEM_RDAT
);
1743 pos
+= scnprintf(*buf
+ pos
, bufsz
- pos
,
1744 "EVT_LOG:0x%08x:%04u\n",
1747 trace_iwlwifi_dev_ucode_event(trans
->dev
, 0,
1749 IWL_ERR(priv
, "EVT_LOG:0x%08x:%04u\n",
1753 data
= iwl_read32(trans
, HBUS_TARG_MEM_RDAT
);
1755 pos
+= scnprintf(*buf
+ pos
, bufsz
- pos
,
1756 "EVT_LOGT:%010u:0x%08x:%04u\n",
1759 IWL_ERR(priv
, "EVT_LOGT:%010u:0x%08x:%04u\n",
1761 trace_iwlwifi_dev_ucode_event(trans
->dev
, time
,
1767 /* Allow device to power down */
1768 iwl_trans_release_nic_access(trans
, ®_flags
);
1773 * iwl_print_last_event_logs - Dump the newest # of event log to syslog
1775 static int iwl_print_last_event_logs(struct iwl_priv
*priv
, u32 capacity
,
1776 u32 num_wraps
, u32 next_entry
,
1778 int pos
, char **buf
, size_t bufsz
)
1781 * display the newest DEFAULT_LOG_ENTRIES entries
1782 * i.e the entries just before the next ont that uCode would fill.
1785 if (next_entry
< size
) {
1786 pos
= iwl_print_event_log(priv
,
1787 capacity
- (size
- next_entry
),
1788 size
- next_entry
, mode
,
1790 pos
= iwl_print_event_log(priv
, 0,
1794 pos
= iwl_print_event_log(priv
, next_entry
- size
,
1795 size
, mode
, pos
, buf
, bufsz
);
1797 if (next_entry
< size
) {
1798 pos
= iwl_print_event_log(priv
, 0, next_entry
,
1799 mode
, pos
, buf
, bufsz
);
1801 pos
= iwl_print_event_log(priv
, next_entry
- size
,
1802 size
, mode
, pos
, buf
, bufsz
);
1808 #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
1810 int iwl_dump_nic_event_log(struct iwl_priv
*priv
, bool full_log
,
1813 u32 base
; /* SRAM byte address of event log header */
1814 u32 capacity
; /* event log capacity in # entries */
1815 u32 mode
; /* 0 - no timestamp, 1 - timestamp recorded */
1816 u32 num_wraps
; /* # times uCode wrapped to top of log */
1817 u32 next_entry
; /* index of next entry to be written by uCode */
1818 u32 size
; /* # entries that we'll print */
1822 struct iwl_trans
*trans
= priv
->trans
;
1824 base
= priv
->device_pointers
.log_event_table
;
1825 if (priv
->cur_ucode
== IWL_UCODE_INIT
) {
1826 logsize
= priv
->fw
->init_evtlog_size
;
1828 base
= priv
->fw
->init_evtlog_ptr
;
1830 logsize
= priv
->fw
->inst_evtlog_size
;
1832 base
= priv
->fw
->inst_evtlog_ptr
;
1835 if (!iwlagn_hw_valid_rtc_data_addr(base
)) {
1837 "Invalid event log pointer 0x%08X for %s uCode\n",
1839 (priv
->cur_ucode
== IWL_UCODE_INIT
)
1844 /* event log header */
1845 capacity
= iwl_trans_read_mem32(trans
, base
);
1846 mode
= iwl_trans_read_mem32(trans
, base
+ (1 * sizeof(u32
)));
1847 num_wraps
= iwl_trans_read_mem32(trans
, base
+ (2 * sizeof(u32
)));
1848 next_entry
= iwl_trans_read_mem32(trans
, base
+ (3 * sizeof(u32
)));
1850 if (capacity
> logsize
) {
1851 IWL_ERR(priv
, "Log capacity %d is bogus, limit to %d "
1852 "entries\n", capacity
, logsize
);
1856 if (next_entry
> logsize
) {
1857 IWL_ERR(priv
, "Log write index %d is bogus, limit to %d\n",
1858 next_entry
, logsize
);
1859 next_entry
= logsize
;
1862 size
= num_wraps
? capacity
: next_entry
;
1864 /* bail out if nothing in log */
1866 IWL_ERR(trans
, "Start IWL Event Log Dump: nothing in log\n");
1870 if (!(iwl_have_debug_level(IWL_DL_FW
)) && !full_log
)
1871 size
= (size
> DEFAULT_DUMP_EVENT_LOG_ENTRIES
)
1872 ? DEFAULT_DUMP_EVENT_LOG_ENTRIES
: size
;
1873 IWL_ERR(priv
, "Start IWL Event Log Dump: display last %u entries\n",
1876 #ifdef CONFIG_IWLWIFI_DEBUG
1879 bufsz
= capacity
* 48;
1882 *buf
= kmalloc(bufsz
, GFP_KERNEL
);
1886 if (iwl_have_debug_level(IWL_DL_FW
) || full_log
) {
1888 * if uCode has wrapped back to top of log,
1889 * start at the oldest entry,
1890 * i.e the next one that uCode would fill.
1893 pos
= iwl_print_event_log(priv
, next_entry
,
1894 capacity
- next_entry
, mode
,
1896 /* (then/else) start at top of log */
1897 pos
= iwl_print_event_log(priv
, 0,
1898 next_entry
, mode
, pos
, buf
, bufsz
);
1900 pos
= iwl_print_last_event_logs(priv
, capacity
, num_wraps
,
1901 next_entry
, size
, mode
,
1904 pos
= iwl_print_last_event_logs(priv
, capacity
, num_wraps
,
1905 next_entry
, size
, mode
,
1911 static void iwlagn_fw_error(struct iwl_priv
*priv
, bool ondemand
)
1913 unsigned int reload_msec
;
1914 unsigned long reload_jiffies
;
1916 if (iwl_have_debug_level(IWL_DL_FW
))
1917 iwl_print_rx_config_cmd(priv
, IWL_RXON_CTX_BSS
);
1919 /* uCode is no longer loaded. */
1920 priv
->ucode_loaded
= false;
1922 /* Set the FW error flag -- cleared on iwl_down */
1923 set_bit(STATUS_FW_ERROR
, &priv
->status
);
1925 iwl_abort_notification_waits(&priv
->notif_wait
);
1927 /* Keep the restart process from trying to send host
1928 * commands by clearing the ready bit */
1929 clear_bit(STATUS_READY
, &priv
->status
);
1933 * If firmware keep reloading, then it indicate something
1934 * serious wrong and firmware having problem to recover
1935 * from it. Instead of keep trying which will fill the syslog
1936 * and hang the system, let's just stop it
1938 reload_jiffies
= jiffies
;
1939 reload_msec
= jiffies_to_msecs((long) reload_jiffies
-
1940 (long) priv
->reload_jiffies
);
1941 priv
->reload_jiffies
= reload_jiffies
;
1942 if (reload_msec
<= IWL_MIN_RELOAD_DURATION
) {
1943 priv
->reload_count
++;
1944 if (priv
->reload_count
>= IWL_MAX_CONTINUE_RELOAD_CNT
) {
1945 IWL_ERR(priv
, "BUG_ON, Stop restarting\n");
1949 priv
->reload_count
= 0;
1952 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
1953 if (iwlwifi_mod_params
.fw_restart
) {
1955 "Restarting adapter due to uCode error.\n");
1956 queue_work(priv
->workqueue
, &priv
->restart
);
1959 "Detected FW error, but not restarting\n");
1963 static void iwl_nic_error(struct iwl_op_mode
*op_mode
)
1965 struct iwl_priv
*priv
= IWL_OP_MODE_GET_DVM(op_mode
);
1967 IWL_ERR(priv
, "Loaded firmware version: %s\n",
1968 priv
->fw
->fw_version
);
1970 iwl_dump_nic_error_log(priv
);
1971 iwl_dump_nic_event_log(priv
, false, NULL
);
1973 iwlagn_fw_error(priv
, false);
1976 static void iwl_cmd_queue_full(struct iwl_op_mode
*op_mode
)
1978 struct iwl_priv
*priv
= IWL_OP_MODE_GET_DVM(op_mode
);
1980 if (!iwl_check_for_ct_kill(priv
)) {
1981 IWL_ERR(priv
, "Restarting adapter queue is full\n");
1982 iwlagn_fw_error(priv
, false);
1986 #define EEPROM_RF_CONFIG_TYPE_MAX 0x3
1988 static void iwl_nic_config(struct iwl_op_mode
*op_mode
)
1990 struct iwl_priv
*priv
= IWL_OP_MODE_GET_DVM(op_mode
);
1993 iwl_trans_set_bits_mask(priv
->trans
, CSR_HW_IF_CONFIG_REG
,
1994 CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH
|
1995 CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP
,
1996 (CSR_HW_REV_STEP(priv
->trans
->hw_rev
) <<
1997 CSR_HW_IF_CONFIG_REG_POS_MAC_STEP
) |
1998 (CSR_HW_REV_DASH(priv
->trans
->hw_rev
) <<
1999 CSR_HW_IF_CONFIG_REG_POS_MAC_DASH
));
2001 /* write radio config values to register */
2002 if (priv
->nvm_data
->radio_cfg_type
<= EEPROM_RF_CONFIG_TYPE_MAX
) {
2004 priv
->nvm_data
->radio_cfg_type
<<
2005 CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE
|
2006 priv
->nvm_data
->radio_cfg_step
<<
2007 CSR_HW_IF_CONFIG_REG_POS_PHY_STEP
|
2008 priv
->nvm_data
->radio_cfg_dash
<<
2009 CSR_HW_IF_CONFIG_REG_POS_PHY_DASH
;
2011 iwl_trans_set_bits_mask(priv
->trans
, CSR_HW_IF_CONFIG_REG
,
2012 CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE
|
2013 CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP
|
2014 CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH
,
2017 IWL_INFO(priv
, "Radio type=0x%x-0x%x-0x%x\n",
2018 priv
->nvm_data
->radio_cfg_type
,
2019 priv
->nvm_data
->radio_cfg_step
,
2020 priv
->nvm_data
->radio_cfg_dash
);
2025 /* set CSR_HW_CONFIG_REG for uCode use */
2026 iwl_set_bit(priv
->trans
, CSR_HW_IF_CONFIG_REG
,
2027 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI
|
2028 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI
);
2030 /* W/A : NIC is stuck in a reset state after Early PCIe power off
2031 * (PCIe power is lost before PERST# is asserted),
2032 * causing ME FW to lose ownership and not being able to obtain it back.
2034 iwl_set_bits_mask_prph(priv
->trans
, APMG_PS_CTRL_REG
,
2035 APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS
,
2036 ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS
);
2038 if (priv
->lib
->nic_config
)
2039 priv
->lib
->nic_config(priv
);
2042 static void iwl_wimax_active(struct iwl_op_mode
*op_mode
)
2044 struct iwl_priv
*priv
= IWL_OP_MODE_GET_DVM(op_mode
);
2046 clear_bit(STATUS_READY
, &priv
->status
);
2047 IWL_ERR(priv
, "RF is used by WiMAX\n");
2050 static void iwl_stop_sw_queue(struct iwl_op_mode
*op_mode
, int queue
)
2052 struct iwl_priv
*priv
= IWL_OP_MODE_GET_DVM(op_mode
);
2053 int mq
= priv
->queue_to_mac80211
[queue
];
2055 if (WARN_ON_ONCE(mq
== IWL_INVALID_MAC80211_QUEUE
))
2058 if (atomic_inc_return(&priv
->queue_stop_count
[mq
]) > 1) {
2059 IWL_DEBUG_TX_QUEUES(priv
,
2060 "queue %d (mac80211 %d) already stopped\n",
2065 set_bit(mq
, &priv
->transport_queue_stop
);
2066 ieee80211_stop_queue(priv
->hw
, mq
);
2069 static void iwl_wake_sw_queue(struct iwl_op_mode
*op_mode
, int queue
)
2071 struct iwl_priv
*priv
= IWL_OP_MODE_GET_DVM(op_mode
);
2072 int mq
= priv
->queue_to_mac80211
[queue
];
2074 if (WARN_ON_ONCE(mq
== IWL_INVALID_MAC80211_QUEUE
))
2077 if (atomic_dec_return(&priv
->queue_stop_count
[mq
]) > 0) {
2078 IWL_DEBUG_TX_QUEUES(priv
,
2079 "queue %d (mac80211 %d) already awake\n",
2084 clear_bit(mq
, &priv
->transport_queue_stop
);
2086 if (!priv
->passive_no_rx
)
2087 ieee80211_wake_queue(priv
->hw
, mq
);
2090 void iwlagn_lift_passive_no_rx(struct iwl_priv
*priv
)
2094 if (!priv
->passive_no_rx
)
2097 for (mq
= 0; mq
< IWLAGN_FIRST_AMPDU_QUEUE
; mq
++) {
2098 if (!test_bit(mq
, &priv
->transport_queue_stop
)) {
2099 IWL_DEBUG_TX_QUEUES(priv
, "Wake queue %d\n", mq
);
2100 ieee80211_wake_queue(priv
->hw
, mq
);
2102 IWL_DEBUG_TX_QUEUES(priv
, "Don't wake queue %d\n", mq
);
2106 priv
->passive_no_rx
= false;
2109 static void iwl_free_skb(struct iwl_op_mode
*op_mode
, struct sk_buff
*skb
)
2111 struct iwl_priv
*priv
= IWL_OP_MODE_GET_DVM(op_mode
);
2112 struct ieee80211_tx_info
*info
;
2114 info
= IEEE80211_SKB_CB(skb
);
2115 iwl_trans_free_tx_cmd(priv
->trans
, info
->driver_data
[1]);
2116 ieee80211_free_txskb(priv
->hw
, skb
);
2119 static bool iwl_set_hw_rfkill_state(struct iwl_op_mode
*op_mode
, bool state
)
2121 struct iwl_priv
*priv
= IWL_OP_MODE_GET_DVM(op_mode
);
2124 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2126 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2128 wiphy_rfkill_set_hw_state(priv
->hw
->wiphy
, state
);
2133 static const struct iwl_op_mode_ops iwl_dvm_ops
= {
2134 .start
= iwl_op_mode_dvm_start
,
2135 .stop
= iwl_op_mode_dvm_stop
,
2136 .rx
= iwl_rx_dispatch
,
2137 .queue_full
= iwl_stop_sw_queue
,
2138 .queue_not_full
= iwl_wake_sw_queue
,
2139 .hw_rf_kill
= iwl_set_hw_rfkill_state
,
2140 .free_skb
= iwl_free_skb
,
2141 .nic_error
= iwl_nic_error
,
2142 .cmd_queue_full
= iwl_cmd_queue_full
,
2143 .nic_config
= iwl_nic_config
,
2144 .wimax_active
= iwl_wimax_active
,
2147 /*****************************************************************************
2149 * driver and module entry point
2151 *****************************************************************************/
2152 static int __init
iwl_init(void)
2157 ret
= iwlagn_rate_control_register();
2159 pr_err("Unable to register rate control algorithm: %d\n", ret
);
2163 ret
= iwl_opmode_register("iwldvm", &iwl_dvm_ops
);
2165 pr_err("Unable to register op_mode: %d\n", ret
);
2166 iwlagn_rate_control_unregister();
2171 module_init(iwl_init
);
2173 static void __exit
iwl_exit(void)
2175 iwl_opmode_deregister("iwldvm");
2176 iwlagn_rate_control_unregister();
2178 module_exit(iwl_exit
);