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 portionhelp 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 #include <linux/etherdevice.h>
31 #include <linux/slab.h>
32 #include <linux/sched.h>
33 #include <net/mac80211.h>
34 #include <asm/unaligned.h>
35 #include "iwl-eeprom.h"
39 #include "iwl-agn-calib.h"
41 #include "iwl-shared.h"
43 const char *get_cmd_string(u8 cmd
)
50 IWL_CMD(REPLY_RXON_ASSOC
);
51 IWL_CMD(REPLY_QOS_PARAM
);
52 IWL_CMD(REPLY_RXON_TIMING
);
53 IWL_CMD(REPLY_ADD_STA
);
54 IWL_CMD(REPLY_REMOVE_STA
);
55 IWL_CMD(REPLY_REMOVE_ALL_STA
);
56 IWL_CMD(REPLY_TXFIFO_FLUSH
);
57 IWL_CMD(REPLY_WEPKEY
);
59 IWL_CMD(REPLY_LEDS_CMD
);
60 IWL_CMD(REPLY_TX_LINK_QUALITY_CMD
);
61 IWL_CMD(COEX_PRIORITY_TABLE_CMD
);
62 IWL_CMD(COEX_MEDIUM_NOTIFICATION
);
63 IWL_CMD(COEX_EVENT_CMD
);
64 IWL_CMD(REPLY_QUIET_CMD
);
65 IWL_CMD(REPLY_CHANNEL_SWITCH
);
66 IWL_CMD(CHANNEL_SWITCH_NOTIFICATION
);
67 IWL_CMD(REPLY_SPECTRUM_MEASUREMENT_CMD
);
68 IWL_CMD(SPECTRUM_MEASURE_NOTIFICATION
);
69 IWL_CMD(POWER_TABLE_CMD
);
70 IWL_CMD(PM_SLEEP_NOTIFICATION
);
71 IWL_CMD(PM_DEBUG_STATISTIC_NOTIFIC
);
72 IWL_CMD(REPLY_SCAN_CMD
);
73 IWL_CMD(REPLY_SCAN_ABORT_CMD
);
74 IWL_CMD(SCAN_START_NOTIFICATION
);
75 IWL_CMD(SCAN_RESULTS_NOTIFICATION
);
76 IWL_CMD(SCAN_COMPLETE_NOTIFICATION
);
77 IWL_CMD(BEACON_NOTIFICATION
);
78 IWL_CMD(REPLY_TX_BEACON
);
79 IWL_CMD(WHO_IS_AWAKE_NOTIFICATION
);
80 IWL_CMD(QUIET_NOTIFICATION
);
81 IWL_CMD(REPLY_TX_PWR_TABLE_CMD
);
82 IWL_CMD(MEASURE_ABORT_NOTIFICATION
);
83 IWL_CMD(REPLY_BT_CONFIG
);
84 IWL_CMD(REPLY_STATISTICS_CMD
);
85 IWL_CMD(STATISTICS_NOTIFICATION
);
86 IWL_CMD(REPLY_CARD_STATE_CMD
);
87 IWL_CMD(CARD_STATE_NOTIFICATION
);
88 IWL_CMD(MISSED_BEACONS_NOTIFICATION
);
89 IWL_CMD(REPLY_CT_KILL_CONFIG_CMD
);
90 IWL_CMD(SENSITIVITY_CMD
);
91 IWL_CMD(REPLY_PHY_CALIBRATION_CMD
);
92 IWL_CMD(REPLY_RX_PHY_CMD
);
93 IWL_CMD(REPLY_RX_MPDU_CMD
);
95 IWL_CMD(REPLY_COMPRESSED_BA
);
96 IWL_CMD(CALIBRATION_CFG_CMD
);
97 IWL_CMD(CALIBRATION_RES_NOTIFICATION
);
98 IWL_CMD(CALIBRATION_COMPLETE_NOTIFICATION
);
99 IWL_CMD(REPLY_TX_POWER_DBM_CMD
);
100 IWL_CMD(TEMPERATURE_NOTIFICATION
);
101 IWL_CMD(TX_ANT_CONFIGURATION_CMD
);
102 IWL_CMD(REPLY_BT_COEX_PROFILE_NOTIF
);
103 IWL_CMD(REPLY_BT_COEX_PRIO_TABLE
);
104 IWL_CMD(REPLY_BT_COEX_PROT_ENV
);
105 IWL_CMD(REPLY_WIPAN_PARAMS
);
106 IWL_CMD(REPLY_WIPAN_RXON
);
107 IWL_CMD(REPLY_WIPAN_RXON_TIMING
);
108 IWL_CMD(REPLY_WIPAN_RXON_ASSOC
);
109 IWL_CMD(REPLY_WIPAN_QOS_PARAM
);
110 IWL_CMD(REPLY_WIPAN_WEPKEY
);
111 IWL_CMD(REPLY_WIPAN_P2P_CHANNEL_SWITCH
);
112 IWL_CMD(REPLY_WIPAN_NOA_NOTIFICATION
);
113 IWL_CMD(REPLY_WIPAN_DEACTIVATION_COMPLETE
);
114 IWL_CMD(REPLY_WOWLAN_PATTERNS
);
115 IWL_CMD(REPLY_WOWLAN_WAKEUP_FILTER
);
116 IWL_CMD(REPLY_WOWLAN_TSC_RSC_PARAMS
);
117 IWL_CMD(REPLY_WOWLAN_TKIP_PARAMS
);
118 IWL_CMD(REPLY_WOWLAN_KEK_KCK_MATERIAL
);
119 IWL_CMD(REPLY_WOWLAN_GET_STATUS
);
120 IWL_CMD(REPLY_D3_CONFIG
);
127 /******************************************************************************
129 * Generic RX handler implementations
131 ******************************************************************************/
133 static int iwlagn_rx_reply_error(struct iwl_priv
*priv
,
134 struct iwl_rx_cmd_buffer
*rxb
,
135 struct iwl_device_cmd
*cmd
)
137 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
138 struct iwl_error_resp
*err_resp
= (void *)pkt
->data
;
140 IWL_ERR(priv
, "Error Reply type 0x%08X cmd %s (0x%02X) "
141 "seq 0x%04X ser 0x%08X\n",
142 le32_to_cpu(err_resp
->error_type
),
143 get_cmd_string(err_resp
->cmd_id
),
145 le16_to_cpu(err_resp
->bad_cmd_seq_num
),
146 le32_to_cpu(err_resp
->error_info
));
150 static int iwlagn_rx_csa(struct iwl_priv
*priv
, struct iwl_rx_cmd_buffer
*rxb
,
151 struct iwl_device_cmd
*cmd
)
153 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
154 struct iwl_csa_notification
*csa
= (void *)pkt
->data
;
157 * See iwlagn_mac_channel_switch.
159 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
160 struct iwl_rxon_cmd
*rxon
= (void *)&ctx
->active
;
162 if (!test_bit(STATUS_CHANNEL_SWITCH_PENDING
, &priv
->status
))
165 if (!le32_to_cpu(csa
->status
) && csa
->channel
== priv
->switch_channel
) {
166 rxon
->channel
= csa
->channel
;
167 ctx
->staging
.channel
= csa
->channel
;
168 IWL_DEBUG_11H(priv
, "CSA notif: channel %d\n",
169 le16_to_cpu(csa
->channel
));
170 iwl_chswitch_done(priv
, true);
172 IWL_ERR(priv
, "CSA notif (fail) : channel %d\n",
173 le16_to_cpu(csa
->channel
));
174 iwl_chswitch_done(priv
, false);
180 static int iwlagn_rx_spectrum_measure_notif(struct iwl_priv
*priv
,
181 struct iwl_rx_cmd_buffer
*rxb
,
182 struct iwl_device_cmd
*cmd
)
184 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
185 struct iwl_spectrum_notification
*report
= (void *)pkt
->data
;
187 if (!report
->state
) {
189 "Spectrum Measure Notification: Start\n");
193 memcpy(&priv
->measure_report
, report
, sizeof(*report
));
194 priv
->measurement_status
|= MEASUREMENT_READY
;
198 static int iwlagn_rx_pm_sleep_notif(struct iwl_priv
*priv
,
199 struct iwl_rx_cmd_buffer
*rxb
,
200 struct iwl_device_cmd
*cmd
)
202 #ifdef CONFIG_IWLWIFI_DEBUG
203 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
204 struct iwl_sleep_notification
*sleep
= (void *)pkt
->data
;
205 IWL_DEBUG_RX(priv
, "sleep mode: %d, src: %d\n",
206 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
211 static int iwlagn_rx_pm_debug_statistics_notif(struct iwl_priv
*priv
,
212 struct iwl_rx_cmd_buffer
*rxb
,
213 struct iwl_device_cmd
*cmd
)
215 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
216 u32 __maybe_unused len
=
217 le32_to_cpu(pkt
->len_n_flags
) & FH_RSCSR_FRAME_SIZE_MSK
;
218 IWL_DEBUG_RADIO(priv
, "Dumping %d bytes of unhandled "
219 "notification for %s:\n", len
,
220 get_cmd_string(pkt
->hdr
.cmd
));
221 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, pkt
->data
, len
);
225 static int iwlagn_rx_beacon_notif(struct iwl_priv
*priv
,
226 struct iwl_rx_cmd_buffer
*rxb
,
227 struct iwl_device_cmd
*cmd
)
229 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
230 struct iwlagn_beacon_notif
*beacon
= (void *)pkt
->data
;
231 #ifdef CONFIG_IWLWIFI_DEBUG
232 u16 status
= le16_to_cpu(beacon
->beacon_notify_hdr
.status
.status
);
233 u8 rate
= iwl_hw_get_rate(beacon
->beacon_notify_hdr
.rate_n_flags
);
235 IWL_DEBUG_RX(priv
, "beacon status %#x, retries:%d ibssmgr:%d "
236 "tsf:0x%.8x%.8x rate:%d\n",
237 status
& TX_STATUS_MSK
,
238 beacon
->beacon_notify_hdr
.failure_frame
,
239 le32_to_cpu(beacon
->ibss_mgr_status
),
240 le32_to_cpu(beacon
->high_tsf
),
241 le32_to_cpu(beacon
->low_tsf
), rate
);
244 priv
->ibss_manager
= le32_to_cpu(beacon
->ibss_mgr_status
);
250 * iwl_good_plcp_health - checks for plcp error.
252 * When the plcp error is exceeding the thresholds, reset the radio
253 * to improve the throughput.
255 static bool iwlagn_good_plcp_health(struct iwl_priv
*priv
,
256 struct statistics_rx_phy
*cur_ofdm
,
257 struct statistics_rx_ht_phy
*cur_ofdm_ht
,
261 int threshold
= priv
->plcp_delta_threshold
;
263 if (threshold
== IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE
) {
264 IWL_DEBUG_RADIO(priv
, "plcp_err check disabled\n");
268 delta
= le32_to_cpu(cur_ofdm
->plcp_err
) -
269 le32_to_cpu(priv
->statistics
.rx_ofdm
.plcp_err
) +
270 le32_to_cpu(cur_ofdm_ht
->plcp_err
) -
271 le32_to_cpu(priv
->statistics
.rx_ofdm_ht
.plcp_err
);
273 /* Can be negative if firmware reset statistics */
277 if ((delta
* 100 / msecs
) > threshold
) {
278 IWL_DEBUG_RADIO(priv
,
279 "plcp health threshold %u delta %d msecs %u\n",
280 threshold
, delta
, msecs
);
287 static void iwlagn_recover_from_statistics(struct iwl_priv
*priv
,
288 struct statistics_rx_phy
*cur_ofdm
,
289 struct statistics_rx_ht_phy
*cur_ofdm_ht
,
290 struct statistics_tx
*tx
,
295 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
298 msecs
= jiffies_to_msecs(stamp
- priv
->rx_statistics_jiffies
);
300 /* Only gather statistics and update time stamp when not associated */
301 if (!iwl_is_any_associated(priv
))
304 /* Do not check/recover when do not have enough statistics data */
308 if (iwlagn_mod_params
.plcp_check
&&
309 !iwlagn_good_plcp_health(priv
, cur_ofdm
, cur_ofdm_ht
, msecs
))
310 iwl_force_rf_reset(priv
, false);
313 /* Calculate noise level, based on measurements during network silence just
314 * before arriving beacon. This measurement can be done only if we know
315 * exactly when to expect beacons, therefore only when we're associated. */
316 static void iwlagn_rx_calc_noise(struct iwl_priv
*priv
)
318 struct statistics_rx_non_phy
*rx_info
;
319 int num_active_rx
= 0;
320 int total_silence
= 0;
321 int bcn_silence_a
, bcn_silence_b
, bcn_silence_c
;
324 rx_info
= &priv
->statistics
.rx_non_phy
;
327 le32_to_cpu(rx_info
->beacon_silence_rssi_a
) & IN_BAND_FILTER
;
329 le32_to_cpu(rx_info
->beacon_silence_rssi_b
) & IN_BAND_FILTER
;
331 le32_to_cpu(rx_info
->beacon_silence_rssi_c
) & IN_BAND_FILTER
;
334 total_silence
+= bcn_silence_a
;
338 total_silence
+= bcn_silence_b
;
342 total_silence
+= bcn_silence_c
;
346 /* Average among active antennas */
348 last_rx_noise
= (total_silence
/ num_active_rx
) - 107;
350 last_rx_noise
= IWL_NOISE_MEAS_NOT_AVAILABLE
;
352 IWL_DEBUG_CALIB(priv
, "inband silence a %u, b %u, c %u, dBm %d\n",
353 bcn_silence_a
, bcn_silence_b
, bcn_silence_c
,
357 #ifdef CONFIG_IWLWIFI_DEBUGFS
359 * based on the assumption of all statistics counter are in DWORD
360 * FIXME: This function is for debugging, do not deal with
361 * the case of counters roll-over.
363 static void accum_stats(__le32
*prev
, __le32
*cur
, __le32
*delta
,
364 __le32
*max_delta
, __le32
*accum
, int size
)
369 i
< size
/ sizeof(__le32
);
370 i
++, prev
++, cur
++, delta
++, max_delta
++, accum
++) {
371 if (le32_to_cpu(*cur
) > le32_to_cpu(*prev
)) {
372 *delta
= cpu_to_le32(
373 le32_to_cpu(*cur
) - le32_to_cpu(*prev
));
374 le32_add_cpu(accum
, le32_to_cpu(*delta
));
375 if (le32_to_cpu(*delta
) > le32_to_cpu(*max_delta
))
382 iwlagn_accumulative_statistics(struct iwl_priv
*priv
,
383 struct statistics_general_common
*common
,
384 struct statistics_rx_non_phy
*rx_non_phy
,
385 struct statistics_rx_phy
*rx_ofdm
,
386 struct statistics_rx_ht_phy
*rx_ofdm_ht
,
387 struct statistics_rx_phy
*rx_cck
,
388 struct statistics_tx
*tx
,
389 struct statistics_bt_activity
*bt_activity
)
391 #define ACCUM(_name) \
392 accum_stats((__le32 *)&priv->statistics._name, \
394 (__le32 *)&priv->delta_stats._name, \
395 (__le32 *)&priv->max_delta_stats._name, \
396 (__le32 *)&priv->accum_stats._name, \
411 iwlagn_accumulative_statistics(struct iwl_priv
*priv
,
412 struct statistics_general_common
*common
,
413 struct statistics_rx_non_phy
*rx_non_phy
,
414 struct statistics_rx_phy
*rx_ofdm
,
415 struct statistics_rx_ht_phy
*rx_ofdm_ht
,
416 struct statistics_rx_phy
*rx_cck
,
417 struct statistics_tx
*tx
,
418 struct statistics_bt_activity
*bt_activity
)
423 static int iwlagn_rx_statistics(struct iwl_priv
*priv
,
424 struct iwl_rx_cmd_buffer
*rxb
,
425 struct iwl_device_cmd
*cmd
)
427 unsigned long stamp
= jiffies
;
428 const int reg_recalib_period
= 60;
430 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
431 u32 len
= le32_to_cpu(pkt
->len_n_flags
) & FH_RSCSR_FRAME_SIZE_MSK
;
433 struct statistics_general_common
*common
;
434 struct statistics_rx_non_phy
*rx_non_phy
;
435 struct statistics_rx_phy
*rx_ofdm
;
436 struct statistics_rx_ht_phy
*rx_ofdm_ht
;
437 struct statistics_rx_phy
*rx_cck
;
438 struct statistics_tx
*tx
;
439 struct statistics_bt_activity
*bt_activity
;
441 len
-= sizeof(struct iwl_cmd_header
); /* skip header */
443 IWL_DEBUG_RX(priv
, "Statistics notification received (%d bytes).\n",
446 spin_lock(&priv
->statistics
.lock
);
448 if (len
== sizeof(struct iwl_bt_notif_statistics
)) {
449 struct iwl_bt_notif_statistics
*stats
;
450 stats
= (void *)&pkt
->data
;
452 common
= &stats
->general
.common
;
453 rx_non_phy
= &stats
->rx
.general
.common
;
454 rx_ofdm
= &stats
->rx
.ofdm
;
455 rx_ofdm_ht
= &stats
->rx
.ofdm_ht
;
456 rx_cck
= &stats
->rx
.cck
;
458 bt_activity
= &stats
->general
.activity
;
460 #ifdef CONFIG_IWLWIFI_DEBUGFS
461 /* handle this exception directly */
462 priv
->statistics
.num_bt_kills
= stats
->rx
.general
.num_bt_kills
;
463 le32_add_cpu(&priv
->statistics
.accum_num_bt_kills
,
464 le32_to_cpu(stats
->rx
.general
.num_bt_kills
));
466 } else if (len
== sizeof(struct iwl_notif_statistics
)) {
467 struct iwl_notif_statistics
*stats
;
468 stats
= (void *)&pkt
->data
;
470 common
= &stats
->general
.common
;
471 rx_non_phy
= &stats
->rx
.general
;
472 rx_ofdm
= &stats
->rx
.ofdm
;
473 rx_ofdm_ht
= &stats
->rx
.ofdm_ht
;
474 rx_cck
= &stats
->rx
.cck
;
478 WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n",
479 len
, sizeof(struct iwl_bt_notif_statistics
),
480 sizeof(struct iwl_notif_statistics
));
481 spin_unlock(&priv
->statistics
.lock
);
485 change
= common
->temperature
!= priv
->statistics
.common
.temperature
||
486 (*flag
& STATISTICS_REPLY_FLG_HT40_MODE_MSK
) !=
487 (priv
->statistics
.flag
& STATISTICS_REPLY_FLG_HT40_MODE_MSK
);
489 iwlagn_accumulative_statistics(priv
, common
, rx_non_phy
, rx_ofdm
,
490 rx_ofdm_ht
, rx_cck
, tx
, bt_activity
);
492 iwlagn_recover_from_statistics(priv
, rx_ofdm
, rx_ofdm_ht
, tx
, stamp
);
494 priv
->statistics
.flag
= *flag
;
495 memcpy(&priv
->statistics
.common
, common
, sizeof(*common
));
496 memcpy(&priv
->statistics
.rx_non_phy
, rx_non_phy
, sizeof(*rx_non_phy
));
497 memcpy(&priv
->statistics
.rx_ofdm
, rx_ofdm
, sizeof(*rx_ofdm
));
498 memcpy(&priv
->statistics
.rx_ofdm_ht
, rx_ofdm_ht
, sizeof(*rx_ofdm_ht
));
499 memcpy(&priv
->statistics
.rx_cck
, rx_cck
, sizeof(*rx_cck
));
500 memcpy(&priv
->statistics
.tx
, tx
, sizeof(*tx
));
501 #ifdef CONFIG_IWLWIFI_DEBUGFS
503 memcpy(&priv
->statistics
.bt_activity
, bt_activity
,
504 sizeof(*bt_activity
));
507 priv
->rx_statistics_jiffies
= stamp
;
509 set_bit(STATUS_STATISTICS
, &priv
->status
);
511 /* Reschedule the statistics timer to occur in
512 * reg_recalib_period seconds to ensure we get a
513 * thermal update even if the uCode doesn't give
515 mod_timer(&priv
->statistics_periodic
, jiffies
+
516 msecs_to_jiffies(reg_recalib_period
* 1000));
518 if (unlikely(!test_bit(STATUS_SCANNING
, &priv
->status
)) &&
519 (pkt
->hdr
.cmd
== STATISTICS_NOTIFICATION
)) {
520 iwlagn_rx_calc_noise(priv
);
521 queue_work(priv
->workqueue
, &priv
->run_time_calib_work
);
523 if (priv
->lib
->temperature
&& change
)
524 priv
->lib
->temperature(priv
);
526 spin_unlock(&priv
->statistics
.lock
);
531 static int iwlagn_rx_reply_statistics(struct iwl_priv
*priv
,
532 struct iwl_rx_cmd_buffer
*rxb
,
533 struct iwl_device_cmd
*cmd
)
535 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
536 struct iwl_notif_statistics
*stats
= (void *)pkt
->data
;
538 if (le32_to_cpu(stats
->flag
) & UCODE_STATISTICS_CLEAR_MSK
) {
539 #ifdef CONFIG_IWLWIFI_DEBUGFS
540 memset(&priv
->accum_stats
, 0,
541 sizeof(priv
->accum_stats
));
542 memset(&priv
->delta_stats
, 0,
543 sizeof(priv
->delta_stats
));
544 memset(&priv
->max_delta_stats
, 0,
545 sizeof(priv
->max_delta_stats
));
547 IWL_DEBUG_RX(priv
, "Statistics have been cleared\n");
549 iwlagn_rx_statistics(priv
, rxb
, cmd
);
553 /* Handle notification from uCode that card's power state is changing
554 * due to software, hardware, or critical temperature RFKILL */
555 static int iwlagn_rx_card_state_notif(struct iwl_priv
*priv
,
556 struct iwl_rx_cmd_buffer
*rxb
,
557 struct iwl_device_cmd
*cmd
)
559 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
560 struct iwl_card_state_notif
*card_state_notif
= (void *)pkt
->data
;
561 u32 flags
= le32_to_cpu(card_state_notif
->flags
);
562 unsigned long status
= priv
->status
;
564 IWL_DEBUG_RF_KILL(priv
, "Card state received: HW:%s SW:%s CT:%s\n",
565 (flags
& HW_CARD_DISABLED
) ? "Kill" : "On",
566 (flags
& SW_CARD_DISABLED
) ? "Kill" : "On",
567 (flags
& CT_CARD_DISABLED
) ?
568 "Reached" : "Not reached");
570 if (flags
& (SW_CARD_DISABLED
| HW_CARD_DISABLED
|
573 iwl_write32(trans(priv
), CSR_UCODE_DRV_GP1_SET
,
574 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
576 iwl_write_direct32(trans(priv
), HBUS_TARG_MBX_C
,
577 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
579 if (!(flags
& RXON_CARD_DISABLED
)) {
580 iwl_write32(trans(priv
), CSR_UCODE_DRV_GP1_CLR
,
581 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED
);
582 iwl_write_direct32(trans(priv
), HBUS_TARG_MBX_C
,
583 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED
);
585 if (flags
& CT_CARD_DISABLED
)
586 iwl_tt_enter_ct_kill(priv
);
588 if (!(flags
& CT_CARD_DISABLED
))
589 iwl_tt_exit_ct_kill(priv
);
591 if (flags
& HW_CARD_DISABLED
)
592 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
594 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
597 if (!(flags
& RXON_CARD_DISABLED
))
598 iwl_scan_cancel(priv
);
600 if ((test_bit(STATUS_RF_KILL_HW
, &status
) !=
601 test_bit(STATUS_RF_KILL_HW
, &priv
->status
)))
602 wiphy_rfkill_set_hw_state(priv
->hw
->wiphy
,
603 test_bit(STATUS_RF_KILL_HW
, &priv
->status
));
605 wake_up(&trans(priv
)->wait_command_queue
);
609 static int iwlagn_rx_missed_beacon_notif(struct iwl_priv
*priv
,
610 struct iwl_rx_cmd_buffer
*rxb
,
611 struct iwl_device_cmd
*cmd
)
614 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
615 struct iwl_missed_beacon_notif
*missed_beacon
= (void *)pkt
->data
;
617 if (le32_to_cpu(missed_beacon
->consecutive_missed_beacons
) >
618 priv
->missed_beacon_threshold
) {
619 IWL_DEBUG_CALIB(priv
,
620 "missed bcn cnsq %d totl %d rcd %d expctd %d\n",
621 le32_to_cpu(missed_beacon
->consecutive_missed_beacons
),
622 le32_to_cpu(missed_beacon
->total_missed_becons
),
623 le32_to_cpu(missed_beacon
->num_recvd_beacons
),
624 le32_to_cpu(missed_beacon
->num_expected_beacons
));
625 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
626 iwl_init_sensitivity(priv
);
631 /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
632 * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
633 static int iwlagn_rx_reply_rx_phy(struct iwl_priv
*priv
,
634 struct iwl_rx_cmd_buffer
*rxb
,
635 struct iwl_device_cmd
*cmd
)
637 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
639 priv
->last_phy_res_valid
= true;
640 memcpy(&priv
->last_phy_res
, pkt
->data
,
641 sizeof(struct iwl_rx_phy_res
));
646 * returns non-zero if packet should be dropped
648 static int iwlagn_set_decrypted_flag(struct iwl_priv
*priv
,
649 struct ieee80211_hdr
*hdr
,
651 struct ieee80211_rx_status
*stats
)
653 u16 fc
= le16_to_cpu(hdr
->frame_control
);
656 * All contexts have the same setting here due to it being
657 * a module parameter, so OK to check any context.
659 if (priv
->contexts
[IWL_RXON_CTX_BSS
].active
.filter_flags
&
660 RXON_FILTER_DIS_DECRYPT_MSK
)
663 if (!(fc
& IEEE80211_FCTL_PROTECTED
))
666 IWL_DEBUG_RX(priv
, "decrypt_res:0x%x\n", decrypt_res
);
667 switch (decrypt_res
& RX_RES_STATUS_SEC_TYPE_MSK
) {
668 case RX_RES_STATUS_SEC_TYPE_TKIP
:
669 /* The uCode has got a bad phase 1 Key, pushes the packet.
670 * Decryption will be done in SW. */
671 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
672 RX_RES_STATUS_BAD_KEY_TTAK
)
675 case RX_RES_STATUS_SEC_TYPE_WEP
:
676 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
677 RX_RES_STATUS_BAD_ICV_MIC
) {
678 /* bad ICV, the packet is destroyed since the
679 * decryption is inplace, drop it */
680 IWL_DEBUG_RX(priv
, "Packet destroyed\n");
683 case RX_RES_STATUS_SEC_TYPE_CCMP
:
684 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
685 RX_RES_STATUS_DECRYPT_OK
) {
686 IWL_DEBUG_RX(priv
, "hw decrypt successfully!!!\n");
687 stats
->flag
|= RX_FLAG_DECRYPTED
;
697 static void iwlagn_pass_packet_to_mac80211(struct iwl_priv
*priv
,
698 struct ieee80211_hdr
*hdr
,
701 struct iwl_rx_cmd_buffer
*rxb
,
702 struct ieee80211_rx_status
*stats
)
705 __le16 fc
= hdr
->frame_control
;
706 struct iwl_rxon_context
*ctx
;
710 /* We only process data packets if the interface is open */
711 if (unlikely(!priv
->is_open
)) {
712 IWL_DEBUG_DROP_LIMIT(priv
,
713 "Dropping packet while interface is not open.\n");
717 /* In case of HW accelerated crypto and bad decryption, drop */
718 if (!iwlagn_mod_params
.sw_crypto
&&
719 iwlagn_set_decrypted_flag(priv
, hdr
, ampdu_status
, stats
))
722 skb
= dev_alloc_skb(128);
724 IWL_ERR(priv
, "dev_alloc_skb failed\n");
728 offset
= (void *)hdr
- rxb_addr(rxb
) + rxb_offset(rxb
);
729 p
= rxb_steal_page(rxb
);
730 skb_add_rx_frag(skb
, 0, p
, offset
, len
, len
);
732 iwl_update_stats(priv
, false, fc
, len
);
735 * Wake any queues that were stopped due to a passive channel tx
736 * failure. This can happen because the regulatory enforcement in
737 * the device waits for a beacon before allowing transmission,
738 * sometimes even after already having transmitted frames for the
739 * association because the new RXON may reset the information.
741 if (unlikely(ieee80211_is_beacon(fc
) && priv
->passive_no_rx
)) {
742 for_each_context(priv
, ctx
) {
743 if (compare_ether_addr(hdr
->addr3
,
744 ctx
->active
.bssid_addr
))
746 iwlagn_lift_passive_no_rx(priv
);
750 memcpy(IEEE80211_SKB_RXCB(skb
), stats
, sizeof(*stats
));
752 ieee80211_rx(priv
->hw
, skb
);
755 static u32
iwlagn_translate_rx_status(struct iwl_priv
*priv
, u32 decrypt_in
)
759 if ((decrypt_in
& RX_RES_STATUS_STATION_FOUND
) ==
760 RX_RES_STATUS_STATION_FOUND
)
761 decrypt_out
|= (RX_RES_STATUS_STATION_FOUND
|
762 RX_RES_STATUS_NO_STATION_INFO_MISMATCH
);
764 decrypt_out
|= (decrypt_in
& RX_RES_STATUS_SEC_TYPE_MSK
);
766 /* packet was not encrypted */
767 if ((decrypt_in
& RX_RES_STATUS_SEC_TYPE_MSK
) ==
768 RX_RES_STATUS_SEC_TYPE_NONE
)
771 /* packet was encrypted with unknown alg */
772 if ((decrypt_in
& RX_RES_STATUS_SEC_TYPE_MSK
) ==
773 RX_RES_STATUS_SEC_TYPE_ERR
)
776 /* decryption was not done in HW */
777 if ((decrypt_in
& RX_MPDU_RES_STATUS_DEC_DONE_MSK
) !=
778 RX_MPDU_RES_STATUS_DEC_DONE_MSK
)
781 switch (decrypt_in
& RX_RES_STATUS_SEC_TYPE_MSK
) {
783 case RX_RES_STATUS_SEC_TYPE_CCMP
:
784 /* alg is CCM: check MIC only */
785 if (!(decrypt_in
& RX_MPDU_RES_STATUS_MIC_OK
))
787 decrypt_out
|= RX_RES_STATUS_BAD_ICV_MIC
;
789 decrypt_out
|= RX_RES_STATUS_DECRYPT_OK
;
793 case RX_RES_STATUS_SEC_TYPE_TKIP
:
794 if (!(decrypt_in
& RX_MPDU_RES_STATUS_TTAK_OK
)) {
796 decrypt_out
|= RX_RES_STATUS_BAD_KEY_TTAK
;
799 /* fall through if TTAK OK */
801 if (!(decrypt_in
& RX_MPDU_RES_STATUS_ICV_OK
))
802 decrypt_out
|= RX_RES_STATUS_BAD_ICV_MIC
;
804 decrypt_out
|= RX_RES_STATUS_DECRYPT_OK
;
808 IWL_DEBUG_RX(priv
, "decrypt_in:0x%x decrypt_out = 0x%x\n",
809 decrypt_in
, decrypt_out
);
814 /* Calc max signal level (dBm) among 3 possible receivers */
815 static int iwlagn_calc_rssi(struct iwl_priv
*priv
,
816 struct iwl_rx_phy_res
*rx_resp
)
818 /* data from PHY/DSP regarding signal strength, etc.,
819 * contents are always there, not configurable by host
821 struct iwlagn_non_cfg_phy
*ncphy
=
822 (struct iwlagn_non_cfg_phy
*)rx_resp
->non_cfg_phy_buf
;
823 u32 val
, rssi_a
, rssi_b
, rssi_c
, max_rssi
;
826 val
= le32_to_cpu(ncphy
->non_cfg_phy
[IWLAGN_RX_RES_AGC_IDX
]);
827 agc
= (val
& IWLAGN_OFDM_AGC_MSK
) >> IWLAGN_OFDM_AGC_BIT_POS
;
829 /* Find max rssi among 3 possible receivers.
830 * These values are measured by the digital signal processor (DSP).
831 * They should stay fairly constant even as the signal strength varies,
832 * if the radio's automatic gain control (AGC) is working right.
833 * AGC value (see below) will provide the "interesting" info.
835 val
= le32_to_cpu(ncphy
->non_cfg_phy
[IWLAGN_RX_RES_RSSI_AB_IDX
]);
836 rssi_a
= (val
& IWLAGN_OFDM_RSSI_INBAND_A_BITMSK
) >>
837 IWLAGN_OFDM_RSSI_A_BIT_POS
;
838 rssi_b
= (val
& IWLAGN_OFDM_RSSI_INBAND_B_BITMSK
) >>
839 IWLAGN_OFDM_RSSI_B_BIT_POS
;
840 val
= le32_to_cpu(ncphy
->non_cfg_phy
[IWLAGN_RX_RES_RSSI_C_IDX
]);
841 rssi_c
= (val
& IWLAGN_OFDM_RSSI_INBAND_C_BITMSK
) >>
842 IWLAGN_OFDM_RSSI_C_BIT_POS
;
844 max_rssi
= max_t(u32
, rssi_a
, rssi_b
);
845 max_rssi
= max_t(u32
, max_rssi
, rssi_c
);
847 IWL_DEBUG_STATS(priv
, "Rssi In A %d B %d C %d Max %d AGC dB %d\n",
848 rssi_a
, rssi_b
, rssi_c
, max_rssi
, agc
);
850 /* dBm = max_rssi dB - agc dB - constant.
851 * Higher AGC (higher radio gain) means lower signal. */
852 return max_rssi
- agc
- IWLAGN_RSSI_OFFSET
;
855 /* Called for REPLY_RX (legacy ABG frames), or
856 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
857 static int iwlagn_rx_reply_rx(struct iwl_priv
*priv
,
858 struct iwl_rx_cmd_buffer
*rxb
,
859 struct iwl_device_cmd
*cmd
)
861 struct ieee80211_hdr
*header
;
862 struct ieee80211_rx_status rx_status
;
863 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
864 struct iwl_rx_phy_res
*phy_res
;
865 __le32 rx_pkt_status
;
866 struct iwl_rx_mpdu_res_start
*amsdu
;
872 * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently.
873 * REPLY_RX: physical layer info is in this buffer
874 * REPLY_RX_MPDU_CMD: physical layer info was sent in separate
875 * command and cached in priv->last_phy_res
877 * Here we set up local variables depending on which command is
880 if (pkt
->hdr
.cmd
== REPLY_RX
) {
881 phy_res
= (struct iwl_rx_phy_res
*)pkt
->data
;
882 header
= (struct ieee80211_hdr
*)(pkt
->data
+ sizeof(*phy_res
)
883 + phy_res
->cfg_phy_cnt
);
885 len
= le16_to_cpu(phy_res
->byte_count
);
886 rx_pkt_status
= *(__le32
*)(pkt
->data
+ sizeof(*phy_res
) +
887 phy_res
->cfg_phy_cnt
+ len
);
888 ampdu_status
= le32_to_cpu(rx_pkt_status
);
890 if (!priv
->last_phy_res_valid
) {
891 IWL_ERR(priv
, "MPDU frame without cached PHY data\n");
894 phy_res
= &priv
->last_phy_res
;
895 amsdu
= (struct iwl_rx_mpdu_res_start
*)pkt
->data
;
896 header
= (struct ieee80211_hdr
*)(pkt
->data
+ sizeof(*amsdu
));
897 len
= le16_to_cpu(amsdu
->byte_count
);
898 rx_pkt_status
= *(__le32
*)(pkt
->data
+ sizeof(*amsdu
) + len
);
899 ampdu_status
= iwlagn_translate_rx_status(priv
,
900 le32_to_cpu(rx_pkt_status
));
903 if ((unlikely(phy_res
->cfg_phy_cnt
> 20))) {
904 IWL_DEBUG_DROP(priv
, "dsp size out of range [0,20]: %d\n",
905 phy_res
->cfg_phy_cnt
);
909 if (!(rx_pkt_status
& RX_RES_STATUS_NO_CRC32_ERROR
) ||
910 !(rx_pkt_status
& RX_RES_STATUS_NO_RXE_OVERFLOW
)) {
911 IWL_DEBUG_RX(priv
, "Bad CRC or FIFO: 0x%08X.\n",
912 le32_to_cpu(rx_pkt_status
));
916 /* This will be used in several places later */
917 rate_n_flags
= le32_to_cpu(phy_res
->rate_n_flags
);
919 /* rx_status carries information about the packet to mac80211 */
920 rx_status
.mactime
= le64_to_cpu(phy_res
->timestamp
);
921 rx_status
.band
= (phy_res
->phy_flags
& RX_RES_PHY_FLAGS_BAND_24_MSK
) ?
922 IEEE80211_BAND_2GHZ
: IEEE80211_BAND_5GHZ
;
924 ieee80211_channel_to_frequency(le16_to_cpu(phy_res
->channel
),
927 iwlagn_hwrate_to_mac80211_idx(rate_n_flags
, rx_status
.band
);
930 /* TSF isn't reliable. In order to allow smooth user experience,
931 * this W/A doesn't propagate it to the mac80211 */
932 /*rx_status.flag |= RX_FLAG_MACTIME_MPDU;*/
934 priv
->ucode_beacon_time
= le32_to_cpu(phy_res
->beacon_time_stamp
);
936 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
937 rx_status
.signal
= iwlagn_calc_rssi(priv
, phy_res
);
939 iwl_dbg_log_rx_data_frame(priv
, len
, header
);
940 IWL_DEBUG_STATS_LIMIT(priv
, "Rssi %d, TSF %llu\n",
941 rx_status
.signal
, (unsigned long long)rx_status
.mactime
);
946 * It seems that the antenna field in the phy flags value
947 * is actually a bit field. This is undefined by radiotap,
948 * it wants an actual antenna number but I always get "7"
949 * for most legacy frames I receive indicating that the
950 * same frame was received on all three RX chains.
952 * I think this field should be removed in favor of a
953 * new 802.11n radiotap field "RX chains" that is defined
957 (le16_to_cpu(phy_res
->phy_flags
) & RX_RES_PHY_FLAGS_ANTENNA_MSK
)
958 >> RX_RES_PHY_FLAGS_ANTENNA_POS
;
960 /* set the preamble flag if appropriate */
961 if (phy_res
->phy_flags
& RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK
)
962 rx_status
.flag
|= RX_FLAG_SHORTPRE
;
964 /* Set up the HT phy flags */
965 if (rate_n_flags
& RATE_MCS_HT_MSK
)
966 rx_status
.flag
|= RX_FLAG_HT
;
967 if (rate_n_flags
& RATE_MCS_HT40_MSK
)
968 rx_status
.flag
|= RX_FLAG_40MHZ
;
969 if (rate_n_flags
& RATE_MCS_SGI_MSK
)
970 rx_status
.flag
|= RX_FLAG_SHORT_GI
;
972 iwlagn_pass_packet_to_mac80211(priv
, header
, len
, ampdu_status
,
977 static int iwlagn_rx_noa_notification(struct iwl_priv
*priv
,
978 struct iwl_rx_cmd_buffer
*rxb
,
979 struct iwl_device_cmd
*cmd
)
981 struct iwl_wipan_noa_data
*new_data
, *old_data
;
982 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
983 struct iwl_wipan_noa_notification
*noa_notif
= (void *)pkt
->data
;
985 /* no condition -- we're in softirq */
986 old_data
= rcu_dereference_protected(priv
->noa_data
, true);
988 if (noa_notif
->noa_active
) {
989 u32 len
= le16_to_cpu(noa_notif
->noa_attribute
.length
);
992 /* EID, len, OUI, subtype */
993 len
+= 1 + 1 + 3 + 1;
994 /* P2P id, P2P length */
998 new_data
= kmalloc(sizeof(*new_data
) + len
, GFP_ATOMIC
);
1000 new_data
->length
= len
;
1001 new_data
->data
[0] = WLAN_EID_VENDOR_SPECIFIC
;
1002 new_data
->data
[1] = len
- 2; /* not counting EID, len */
1003 new_data
->data
[2] = (WLAN_OUI_WFA
>> 16) & 0xff;
1004 new_data
->data
[3] = (WLAN_OUI_WFA
>> 8) & 0xff;
1005 new_data
->data
[4] = (WLAN_OUI_WFA
>> 0) & 0xff;
1006 new_data
->data
[5] = WLAN_OUI_TYPE_WFA_P2P
;
1007 memcpy(&new_data
->data
[6], &noa_notif
->noa_attribute
,
1013 rcu_assign_pointer(priv
->noa_data
, new_data
);
1016 kfree_rcu(old_data
, rcu_head
);
1022 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
1024 * Setup the RX handlers for each of the reply types sent from the uCode
1027 void iwl_setup_rx_handlers(struct iwl_priv
*priv
)
1029 int (**handlers
)(struct iwl_priv
*priv
, struct iwl_rx_cmd_buffer
*rxb
,
1030 struct iwl_device_cmd
*cmd
);
1032 handlers
= priv
->rx_handlers
;
1034 handlers
[REPLY_ERROR
] = iwlagn_rx_reply_error
;
1035 handlers
[CHANNEL_SWITCH_NOTIFICATION
] = iwlagn_rx_csa
;
1036 handlers
[SPECTRUM_MEASURE_NOTIFICATION
] =
1037 iwlagn_rx_spectrum_measure_notif
;
1038 handlers
[PM_SLEEP_NOTIFICATION
] = iwlagn_rx_pm_sleep_notif
;
1039 handlers
[PM_DEBUG_STATISTIC_NOTIFIC
] =
1040 iwlagn_rx_pm_debug_statistics_notif
;
1041 handlers
[BEACON_NOTIFICATION
] = iwlagn_rx_beacon_notif
;
1042 handlers
[REPLY_ADD_STA
] = iwl_add_sta_callback
;
1044 handlers
[REPLY_WIPAN_NOA_NOTIFICATION
] = iwlagn_rx_noa_notification
;
1047 * The same handler is used for both the REPLY to a discrete
1048 * statistics request from the host as well as for the periodic
1049 * statistics notifications (after received beacons) from the uCode.
1051 handlers
[REPLY_STATISTICS_CMD
] = iwlagn_rx_reply_statistics
;
1052 handlers
[STATISTICS_NOTIFICATION
] = iwlagn_rx_statistics
;
1054 iwl_setup_rx_scan_handlers(priv
);
1056 handlers
[CARD_STATE_NOTIFICATION
] = iwlagn_rx_card_state_notif
;
1057 handlers
[MISSED_BEACONS_NOTIFICATION
] =
1058 iwlagn_rx_missed_beacon_notif
;
1061 handlers
[REPLY_RX_PHY_CMD
] = iwlagn_rx_reply_rx_phy
;
1062 handlers
[REPLY_RX_MPDU_CMD
] = iwlagn_rx_reply_rx
;
1065 handlers
[REPLY_COMPRESSED_BA
] =
1066 iwlagn_rx_reply_compressed_ba
;
1068 priv
->rx_handlers
[REPLY_TX
] = iwlagn_rx_reply_tx
;
1070 /* set up notification wait support */
1071 iwl_notification_wait_init(&priv
->notif_wait
);
1073 /* Set up BT Rx handlers */
1074 if (cfg(priv
)->bt_params
)
1075 iwlagn_bt_rx_handler_setup(priv
);
1078 int iwl_rx_dispatch(struct iwl_op_mode
*op_mode
, struct iwl_rx_cmd_buffer
*rxb
,
1079 struct iwl_device_cmd
*cmd
)
1081 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1082 struct iwl_priv
*priv
= IWL_OP_MODE_GET_DVM(op_mode
);
1083 void (*pre_rx_handler
)(struct iwl_priv
*,
1084 struct iwl_rx_cmd_buffer
*);
1088 * Do the notification wait before RX handlers so
1089 * even if the RX handler consumes the RXB we have
1090 * access to it in the notification wait entry.
1092 iwl_notification_wait_notify(&priv
->notif_wait
, pkt
);
1094 /* RX data may be forwarded to userspace (using pre_rx_handler) in one
1095 * of two cases: the first, that the user owns the uCode through
1096 * testmode - in such case the pre_rx_handler is set and no further
1097 * processing takes place. The other case is when the user want to
1098 * monitor the rx w/o affecting the regular flow - the pre_rx_handler
1099 * will be set but the ownership flag != IWL_OWNERSHIP_TM and the flow
1101 * We need to use ACCESS_ONCE to prevent a case where the handler
1102 * changes between the check and the call.
1104 pre_rx_handler
= ACCESS_ONCE(priv
->pre_rx_handler
);
1106 pre_rx_handler(priv
, rxb
);
1107 if (priv
->ucode_owner
!= IWL_OWNERSHIP_TM
) {
1108 /* Based on type of command response or notification,
1109 * handle those that need handling via function in
1110 * rx_handlers table. See iwl_setup_rx_handlers() */
1111 if (priv
->rx_handlers
[pkt
->hdr
.cmd
]) {
1112 priv
->rx_handlers_stats
[pkt
->hdr
.cmd
]++;
1113 err
= priv
->rx_handlers
[pkt
->hdr
.cmd
] (priv
, rxb
, cmd
);
1115 /* No handling needed */
1117 "No handler needed for %s, 0x%02x\n",
1118 get_cmd_string(pkt
->hdr
.cmd
), pkt
->hdr
.cmd
);