Commit | Line | Data |
---|---|---|
a55360e4 TW |
1 | /****************************************************************************** |
2 | * | |
4e318262 | 3 | * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. |
a55360e4 TW |
4 | * |
5 | * Portions of this file are derived from the ipw3945 project, as well | |
6a686c60 | 6 | * as portionhelp of the ieee80211 subsystem header files. |
a55360e4 TW |
7 | * |
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. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
15 | * more details. | |
16 | * | |
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 | |
20 | * | |
21 | * The full GNU General Public License is included in this distribution in the | |
22 | * file called LICENSE. | |
23 | * | |
24 | * Contact Information: | |
759ef89f | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
a55360e4 TW |
26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
27 | * | |
28 | *****************************************************************************/ | |
29 | ||
1781a07f | 30 | #include <linux/etherdevice.h> |
5a0e3ad6 | 31 | #include <linux/slab.h> |
118253ca | 32 | #include <linux/sched.h> |
a55360e4 | 33 | #include <net/mac80211.h> |
a05ffd39 | 34 | #include <asm/unaligned.h> |
a55360e4 TW |
35 | #include "iwl-eeprom.h" |
36 | #include "iwl-dev.h" | |
37 | #include "iwl-core.h" | |
a55360e4 | 38 | #include "iwl-io.h" |
67289941 | 39 | #include "iwl-agn-calib.h" |
466a19a0 | 40 | #include "iwl-agn.h" |
48f20d35 | 41 | #include "iwl-shared.h" |
466a19a0 | 42 | |
522376d2 EG |
43 | const char *get_cmd_string(u8 cmd) |
44 | { | |
45 | switch (cmd) { | |
46 | IWL_CMD(REPLY_ALIVE); | |
47 | IWL_CMD(REPLY_ERROR); | |
7e4005cc | 48 | IWL_CMD(REPLY_ECHO); |
522376d2 EG |
49 | IWL_CMD(REPLY_RXON); |
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); | |
58 | IWL_CMD(REPLY_TX); | |
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); | |
94 | IWL_CMD(REPLY_RX); | |
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); | |
1b3c0c32 | 120 | IWL_CMD(REPLY_D3_CONFIG); |
522376d2 EG |
121 | default: |
122 | return "UNKNOWN"; | |
123 | ||
124 | } | |
125 | } | |
a55360e4 | 126 | |
466a19a0 SG |
127 | /****************************************************************************** |
128 | * | |
129 | * Generic RX handler implementations | |
130 | * | |
131 | ******************************************************************************/ | |
132 | ||
3246c4e6 | 133 | static int iwlagn_rx_reply_error(struct iwl_priv *priv, |
48a2d66f | 134 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 135 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
136 | { |
137 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 138 | struct iwl_error_resp *err_resp = (void *)pkt->data; |
466a19a0 SG |
139 | |
140 | IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) " | |
141 | "seq 0x%04X ser 0x%08X\n", | |
f8d7c1a1 JB |
142 | le32_to_cpu(err_resp->error_type), |
143 | get_cmd_string(err_resp->cmd_id), | |
144 | err_resp->cmd_id, | |
145 | le16_to_cpu(err_resp->bad_cmd_seq_num), | |
146 | le32_to_cpu(err_resp->error_info)); | |
247c61d6 | 147 | return 0; |
466a19a0 SG |
148 | } |
149 | ||
48a2d66f | 150 | static int iwlagn_rx_csa(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 151 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
152 | { |
153 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 154 | struct iwl_csa_notification *csa = (void *)pkt->data; |
466a19a0 SG |
155 | /* |
156 | * MULTI-FIXME | |
ade4c649 | 157 | * See iwlagn_mac_channel_switch. |
466a19a0 SG |
158 | */ |
159 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | |
160 | struct iwl_rxon_cmd *rxon = (void *)&ctx->active; | |
161 | ||
63013ae3 | 162 | if (!test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->shrd->status)) |
247c61d6 | 163 | return 0; |
6f213ff1 SG |
164 | |
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", | |
466a19a0 | 169 | le16_to_cpu(csa->channel)); |
6f213ff1 SG |
170 | iwl_chswitch_done(priv, true); |
171 | } else { | |
172 | IWL_ERR(priv, "CSA notif (fail) : channel %d\n", | |
173 | le16_to_cpu(csa->channel)); | |
174 | iwl_chswitch_done(priv, false); | |
466a19a0 | 175 | } |
247c61d6 | 176 | return 0; |
466a19a0 SG |
177 | } |
178 | ||
179 | ||
3246c4e6 | 180 | static int iwlagn_rx_spectrum_measure_notif(struct iwl_priv *priv, |
48a2d66f | 181 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 182 | struct iwl_device_cmd *cmd) |
81963d68 RC |
183 | { |
184 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 185 | struct iwl_spectrum_notification *report = (void *)pkt->data; |
81963d68 RC |
186 | |
187 | if (!report->state) { | |
188 | IWL_DEBUG_11H(priv, | |
189 | "Spectrum Measure Notification: Start\n"); | |
247c61d6 | 190 | return 0; |
81963d68 RC |
191 | } |
192 | ||
193 | memcpy(&priv->measure_report, report, sizeof(*report)); | |
194 | priv->measurement_status |= MEASUREMENT_READY; | |
247c61d6 | 195 | return 0; |
81963d68 | 196 | } |
81963d68 | 197 | |
3246c4e6 | 198 | static int iwlagn_rx_pm_sleep_notif(struct iwl_priv *priv, |
48a2d66f | 199 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 200 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
201 | { |
202 | #ifdef CONFIG_IWLWIFI_DEBUG | |
203 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 204 | struct iwl_sleep_notification *sleep = (void *)pkt->data; |
466a19a0 SG |
205 | IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n", |
206 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); | |
207 | #endif | |
247c61d6 | 208 | return 0; |
466a19a0 SG |
209 | } |
210 | ||
3246c4e6 | 211 | static int iwlagn_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
48a2d66f | 212 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 213 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
214 | { |
215 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
44856c65 EG |
216 | u32 __maybe_unused len = |
217 | le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; | |
466a19a0 SG |
218 | IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled " |
219 | "notification for %s:\n", len, | |
220 | get_cmd_string(pkt->hdr.cmd)); | |
f8d7c1a1 | 221 | iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->data, len); |
247c61d6 | 222 | return 0; |
466a19a0 SG |
223 | } |
224 | ||
3246c4e6 | 225 | static int iwlagn_rx_beacon_notif(struct iwl_priv *priv, |
48a2d66f | 226 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 227 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
228 | { |
229 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 230 | struct iwlagn_beacon_notif *beacon = (void *)pkt->data; |
466a19a0 SG |
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); | |
234 | ||
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); | |
242 | #endif | |
243 | ||
244 | priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status); | |
245 | ||
247c61d6 | 246 | return 0; |
466a19a0 SG |
247 | } |
248 | ||
ad6e82a5 SG |
249 | /* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */ |
250 | #define ACK_CNT_RATIO (50) | |
251 | #define BA_TIMEOUT_CNT (5) | |
252 | #define BA_TIMEOUT_MAX (16) | |
253 | ||
254 | /** | |
255 | * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries. | |
256 | * | |
257 | * When the ACK count ratio is low and aggregated BA timeout retries exceeding | |
258 | * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal | |
259 | * operation state. | |
260 | */ | |
3246c4e6 | 261 | static bool iwlagn_good_ack_health(struct iwl_priv *priv, |
0da0e5bf | 262 | struct statistics_tx *cur) |
ad6e82a5 SG |
263 | { |
264 | int actual_delta, expected_delta, ba_timeout_delta; | |
0da0e5bf | 265 | struct statistics_tx *old; |
ad6e82a5 | 266 | |
898ed67b | 267 | if (priv->agg_tids_count) |
ad6e82a5 SG |
268 | return true; |
269 | ||
4ff70fcd JB |
270 | lockdep_assert_held(&priv->statistics.lock); |
271 | ||
0da0e5bf | 272 | old = &priv->statistics.tx; |
ad6e82a5 SG |
273 | |
274 | actual_delta = le32_to_cpu(cur->actual_ack_cnt) - | |
275 | le32_to_cpu(old->actual_ack_cnt); | |
276 | expected_delta = le32_to_cpu(cur->expected_ack_cnt) - | |
277 | le32_to_cpu(old->expected_ack_cnt); | |
278 | ||
279 | /* Values should not be negative, but we do not trust the firmware */ | |
280 | if (actual_delta <= 0 || expected_delta <= 0) | |
281 | return true; | |
282 | ||
283 | ba_timeout_delta = le32_to_cpu(cur->agg.ba_timeout) - | |
284 | le32_to_cpu(old->agg.ba_timeout); | |
285 | ||
286 | if ((actual_delta * 100 / expected_delta) < ACK_CNT_RATIO && | |
287 | ba_timeout_delta > BA_TIMEOUT_CNT) { | |
3246c4e6 WYG |
288 | IWL_DEBUG_RADIO(priv, |
289 | "deltas: actual %d expected %d ba_timeout %d\n", | |
290 | actual_delta, expected_delta, ba_timeout_delta); | |
ad6e82a5 SG |
291 | |
292 | #ifdef CONFIG_IWLWIFI_DEBUGFS | |
293 | /* | |
294 | * This is ifdef'ed on DEBUGFS because otherwise the | |
295 | * statistics aren't available. If DEBUGFS is set but | |
296 | * DEBUG is not, these will just compile out. | |
297 | */ | |
298 | IWL_DEBUG_RADIO(priv, "rx_detected_cnt delta %d\n", | |
0da0e5bf | 299 | priv->delta_stats.tx.rx_detected_cnt); |
ad6e82a5 SG |
300 | IWL_DEBUG_RADIO(priv, |
301 | "ack_or_ba_timeout_collision delta %d\n", | |
0da0e5bf | 302 | priv->delta_stats.tx.ack_or_ba_timeout_collision); |
ad6e82a5 SG |
303 | #endif |
304 | ||
305 | if (ba_timeout_delta >= BA_TIMEOUT_MAX) | |
306 | return false; | |
307 | } | |
308 | ||
309 | return true; | |
310 | } | |
311 | ||
312 | /** | |
313 | * iwl_good_plcp_health - checks for plcp error. | |
314 | * | |
315 | * When the plcp error is exceeding the thresholds, reset the radio | |
316 | * to improve the throughput. | |
317 | */ | |
3246c4e6 | 318 | static bool iwlagn_good_plcp_health(struct iwl_priv *priv, |
0da0e5bf JB |
319 | struct statistics_rx_phy *cur_ofdm, |
320 | struct statistics_rx_ht_phy *cur_ofdm_ht, | |
321 | unsigned int msecs) | |
ad6e82a5 | 322 | { |
6198c387 | 323 | int delta; |
ab5c0f1f | 324 | int threshold = priv->plcp_delta_threshold; |
ad6e82a5 | 325 | |
6198c387 | 326 | if (threshold == IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) { |
ad6e82a5 | 327 | IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n"); |
6198c387 | 328 | return true; |
ad6e82a5 SG |
329 | } |
330 | ||
0da0e5bf JB |
331 | delta = le32_to_cpu(cur_ofdm->plcp_err) - |
332 | le32_to_cpu(priv->statistics.rx_ofdm.plcp_err) + | |
333 | le32_to_cpu(cur_ofdm_ht->plcp_err) - | |
334 | le32_to_cpu(priv->statistics.rx_ofdm_ht.plcp_err); | |
6198c387 | 335 | |
0da0e5bf | 336 | /* Can be negative if firmware reset statistics */ |
6198c387 SG |
337 | if (delta <= 0) |
338 | return true; | |
339 | ||
340 | if ((delta * 100 / msecs) > threshold) { | |
341 | IWL_DEBUG_RADIO(priv, | |
342 | "plcp health threshold %u delta %d msecs %u\n", | |
343 | threshold, delta, msecs); | |
344 | return false; | |
345 | } | |
346 | ||
347 | return true; | |
ad6e82a5 SG |
348 | } |
349 | ||
3246c4e6 WYG |
350 | static void iwlagn_recover_from_statistics(struct iwl_priv *priv, |
351 | struct statistics_rx_phy *cur_ofdm, | |
352 | struct statistics_rx_ht_phy *cur_ofdm_ht, | |
353 | struct statistics_tx *tx, | |
354 | unsigned long stamp) | |
fa8f130c | 355 | { |
410f2bb3 | 356 | unsigned int msecs; |
b7977ffa | 357 | |
63013ae3 | 358 | if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status)) |
410f2bb3 SG |
359 | return; |
360 | ||
410f2bb3 SG |
361 | msecs = jiffies_to_msecs(stamp - priv->rx_statistics_jiffies); |
362 | ||
363 | /* Only gather statistics and update time stamp when not associated */ | |
364 | if (!iwl_is_any_associated(priv)) | |
0da0e5bf | 365 | return; |
410f2bb3 SG |
366 | |
367 | /* Do not check/recover when do not have enough statistics data */ | |
368 | if (msecs < 99) | |
fa8f130c | 369 | return; |
ca3d9389 | 370 | |
3246c4e6 | 371 | if (iwlagn_mod_params.ack_check && !iwlagn_good_ack_health(priv, tx)) { |
ca3d9389 SG |
372 | IWL_ERR(priv, "low ack count detected, restart firmware\n"); |
373 | if (!iwl_force_reset(priv, IWL_FW_RESET, false)) | |
374 | return; | |
3e4fb5fa | 375 | } |
ca3d9389 | 376 | |
9d143e9a | 377 | if (iwlagn_mod_params.plcp_check && |
3246c4e6 | 378 | !iwlagn_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs)) |
ca3d9389 | 379 | iwl_force_reset(priv, IWL_RF_RESET, false); |
beac5498 | 380 | } |
beac5498 | 381 | |
67289941 SG |
382 | /* Calculate noise level, based on measurements during network silence just |
383 | * before arriving beacon. This measurement can be done only if we know | |
384 | * exactly when to expect beacons, therefore only when we're associated. */ | |
3246c4e6 | 385 | static void iwlagn_rx_calc_noise(struct iwl_priv *priv) |
67289941 SG |
386 | { |
387 | struct statistics_rx_non_phy *rx_info; | |
388 | int num_active_rx = 0; | |
389 | int total_silence = 0; | |
390 | int bcn_silence_a, bcn_silence_b, bcn_silence_c; | |
391 | int last_rx_noise; | |
392 | ||
0da0e5bf JB |
393 | rx_info = &priv->statistics.rx_non_phy; |
394 | ||
67289941 SG |
395 | bcn_silence_a = |
396 | le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER; | |
397 | bcn_silence_b = | |
398 | le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER; | |
399 | bcn_silence_c = | |
400 | le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER; | |
401 | ||
402 | if (bcn_silence_a) { | |
403 | total_silence += bcn_silence_a; | |
404 | num_active_rx++; | |
405 | } | |
406 | if (bcn_silence_b) { | |
407 | total_silence += bcn_silence_b; | |
408 | num_active_rx++; | |
409 | } | |
410 | if (bcn_silence_c) { | |
411 | total_silence += bcn_silence_c; | |
412 | num_active_rx++; | |
413 | } | |
414 | ||
415 | /* Average among active antennas */ | |
416 | if (num_active_rx) | |
417 | last_rx_noise = (total_silence / num_active_rx) - 107; | |
418 | else | |
419 | last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE; | |
420 | ||
421 | IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n", | |
422 | bcn_silence_a, bcn_silence_b, bcn_silence_c, | |
423 | last_rx_noise); | |
424 | } | |
425 | ||
0da0e5bf | 426 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
67289941 SG |
427 | /* |
428 | * based on the assumption of all statistics counter are in DWORD | |
429 | * FIXME: This function is for debugging, do not deal with | |
430 | * the case of counters roll-over. | |
431 | */ | |
0da0e5bf JB |
432 | static void accum_stats(__le32 *prev, __le32 *cur, __le32 *delta, |
433 | __le32 *max_delta, __le32 *accum, int size) | |
67289941 | 434 | { |
0da0e5bf JB |
435 | int i; |
436 | ||
437 | for (i = 0; | |
438 | i < size / sizeof(__le32); | |
439 | i++, prev++, cur++, delta++, max_delta++, accum++) { | |
440 | if (le32_to_cpu(*cur) > le32_to_cpu(*prev)) { | |
441 | *delta = cpu_to_le32( | |
442 | le32_to_cpu(*cur) - le32_to_cpu(*prev)); | |
443 | le32_add_cpu(accum, le32_to_cpu(*delta)); | |
444 | if (le32_to_cpu(*delta) > le32_to_cpu(*max_delta)) | |
67289941 SG |
445 | *max_delta = *delta; |
446 | } | |
447 | } | |
0da0e5bf | 448 | } |
67289941 | 449 | |
0da0e5bf | 450 | static void |
3246c4e6 | 451 | iwlagn_accumulative_statistics(struct iwl_priv *priv, |
0da0e5bf JB |
452 | struct statistics_general_common *common, |
453 | struct statistics_rx_non_phy *rx_non_phy, | |
454 | struct statistics_rx_phy *rx_ofdm, | |
455 | struct statistics_rx_ht_phy *rx_ofdm_ht, | |
456 | struct statistics_rx_phy *rx_cck, | |
457 | struct statistics_tx *tx, | |
458 | struct statistics_bt_activity *bt_activity) | |
459 | { | |
460 | #define ACCUM(_name) \ | |
461 | accum_stats((__le32 *)&priv->statistics._name, \ | |
462 | (__le32 *)_name, \ | |
463 | (__le32 *)&priv->delta_stats._name, \ | |
464 | (__le32 *)&priv->max_delta_stats._name, \ | |
465 | (__le32 *)&priv->accum_stats._name, \ | |
466 | sizeof(*_name)); | |
467 | ||
468 | ACCUM(common); | |
469 | ACCUM(rx_non_phy); | |
470 | ACCUM(rx_ofdm); | |
471 | ACCUM(rx_ofdm_ht); | |
472 | ACCUM(rx_cck); | |
473 | ACCUM(tx); | |
474 | if (bt_activity) | |
475 | ACCUM(bt_activity); | |
476 | #undef ACCUM | |
466a19a0 | 477 | } |
0da0e5bf JB |
478 | #else |
479 | static inline void | |
3246c4e6 | 480 | iwlagn_accumulative_statistics(struct iwl_priv *priv, |
0da0e5bf JB |
481 | struct statistics_general_common *common, |
482 | struct statistics_rx_non_phy *rx_non_phy, | |
483 | struct statistics_rx_phy *rx_ofdm, | |
484 | struct statistics_rx_ht_phy *rx_ofdm_ht, | |
485 | struct statistics_rx_phy *rx_cck, | |
486 | struct statistics_tx *tx, | |
487 | struct statistics_bt_activity *bt_activity) | |
488 | { | |
489 | } | |
490 | #endif | |
67289941 | 491 | |
3246c4e6 | 492 | static int iwlagn_rx_statistics(struct iwl_priv *priv, |
48a2d66f | 493 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 494 | struct iwl_device_cmd *cmd) |
67289941 | 495 | { |
0da0e5bf | 496 | unsigned long stamp = jiffies; |
466a19a0 | 497 | const int reg_recalib_period = 60; |
67289941 SG |
498 | int change; |
499 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
0da0e5bf JB |
500 | u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; |
501 | __le32 *flag; | |
502 | struct statistics_general_common *common; | |
503 | struct statistics_rx_non_phy *rx_non_phy; | |
504 | struct statistics_rx_phy *rx_ofdm; | |
505 | struct statistics_rx_ht_phy *rx_ofdm_ht; | |
506 | struct statistics_rx_phy *rx_cck; | |
507 | struct statistics_tx *tx; | |
508 | struct statistics_bt_activity *bt_activity; | |
509 | ||
510 | len -= sizeof(struct iwl_cmd_header); /* skip header */ | |
511 | ||
512 | IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n", | |
513 | len); | |
514 | ||
4ff70fcd JB |
515 | spin_lock(&priv->statistics.lock); |
516 | ||
0da0e5bf JB |
517 | if (len == sizeof(struct iwl_bt_notif_statistics)) { |
518 | struct iwl_bt_notif_statistics *stats; | |
f8d7c1a1 | 519 | stats = (void *)&pkt->data; |
0da0e5bf JB |
520 | flag = &stats->flag; |
521 | common = &stats->general.common; | |
522 | rx_non_phy = &stats->rx.general.common; | |
523 | rx_ofdm = &stats->rx.ofdm; | |
524 | rx_ofdm_ht = &stats->rx.ofdm_ht; | |
525 | rx_cck = &stats->rx.cck; | |
526 | tx = &stats->tx; | |
527 | bt_activity = &stats->general.activity; | |
67289941 | 528 | |
0da0e5bf JB |
529 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
530 | /* handle this exception directly */ | |
531 | priv->statistics.num_bt_kills = stats->rx.general.num_bt_kills; | |
532 | le32_add_cpu(&priv->statistics.accum_num_bt_kills, | |
533 | le32_to_cpu(stats->rx.general.num_bt_kills)); | |
534 | #endif | |
535 | } else if (len == sizeof(struct iwl_notif_statistics)) { | |
536 | struct iwl_notif_statistics *stats; | |
f8d7c1a1 | 537 | stats = (void *)&pkt->data; |
0da0e5bf JB |
538 | flag = &stats->flag; |
539 | common = &stats->general.common; | |
540 | rx_non_phy = &stats->rx.general; | |
541 | rx_ofdm = &stats->rx.ofdm; | |
542 | rx_ofdm_ht = &stats->rx.ofdm_ht; | |
543 | rx_cck = &stats->rx.cck; | |
544 | tx = &stats->tx; | |
545 | bt_activity = NULL; | |
67289941 | 546 | } else { |
0da0e5bf JB |
547 | WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n", |
548 | len, sizeof(struct iwl_bt_notif_statistics), | |
549 | sizeof(struct iwl_notif_statistics)); | |
4ff70fcd | 550 | spin_unlock(&priv->statistics.lock); |
247c61d6 | 551 | return 0; |
67289941 SG |
552 | } |
553 | ||
0da0e5bf JB |
554 | change = common->temperature != priv->statistics.common.temperature || |
555 | (*flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK) != | |
556 | (priv->statistics.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK); | |
557 | ||
3246c4e6 | 558 | iwlagn_accumulative_statistics(priv, common, rx_non_phy, rx_ofdm, |
0da0e5bf JB |
559 | rx_ofdm_ht, rx_cck, tx, bt_activity); |
560 | ||
3246c4e6 | 561 | iwlagn_recover_from_statistics(priv, rx_ofdm, rx_ofdm_ht, tx, stamp); |
0da0e5bf JB |
562 | |
563 | priv->statistics.flag = *flag; | |
564 | memcpy(&priv->statistics.common, common, sizeof(*common)); | |
565 | memcpy(&priv->statistics.rx_non_phy, rx_non_phy, sizeof(*rx_non_phy)); | |
566 | memcpy(&priv->statistics.rx_ofdm, rx_ofdm, sizeof(*rx_ofdm)); | |
567 | memcpy(&priv->statistics.rx_ofdm_ht, rx_ofdm_ht, sizeof(*rx_ofdm_ht)); | |
568 | memcpy(&priv->statistics.rx_cck, rx_cck, sizeof(*rx_cck)); | |
569 | memcpy(&priv->statistics.tx, tx, sizeof(*tx)); | |
570 | #ifdef CONFIG_IWLWIFI_DEBUGFS | |
571 | if (bt_activity) | |
572 | memcpy(&priv->statistics.bt_activity, bt_activity, | |
573 | sizeof(*bt_activity)); | |
574 | #endif | |
575 | ||
576 | priv->rx_statistics_jiffies = stamp; | |
67289941 | 577 | |
63013ae3 | 578 | set_bit(STATUS_STATISTICS, &priv->shrd->status); |
67289941 SG |
579 | |
580 | /* Reschedule the statistics timer to occur in | |
466a19a0 | 581 | * reg_recalib_period seconds to ensure we get a |
67289941 SG |
582 | * thermal update even if the uCode doesn't give |
583 | * us one */ | |
584 | mod_timer(&priv->statistics_periodic, jiffies + | |
466a19a0 | 585 | msecs_to_jiffies(reg_recalib_period * 1000)); |
67289941 | 586 | |
63013ae3 | 587 | if (unlikely(!test_bit(STATUS_SCANNING, &priv->shrd->status)) && |
67289941 | 588 | (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) { |
3246c4e6 | 589 | iwlagn_rx_calc_noise(priv); |
1ee158d8 | 590 | queue_work(priv->workqueue, &priv->run_time_calib_work); |
67289941 | 591 | } |
38622419 DF |
592 | if (cfg(priv)->lib->temperature && change) |
593 | cfg(priv)->lib->temperature(priv); | |
4ff70fcd JB |
594 | |
595 | spin_unlock(&priv->statistics.lock); | |
596 | ||
247c61d6 | 597 | return 0; |
67289941 SG |
598 | } |
599 | ||
3246c4e6 | 600 | static int iwlagn_rx_reply_statistics(struct iwl_priv *priv, |
48a2d66f | 601 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 602 | struct iwl_device_cmd *cmd) |
67289941 SG |
603 | { |
604 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 605 | struct iwl_notif_statistics *stats = (void *)pkt->data; |
67289941 | 606 | |
f8d7c1a1 | 607 | if (le32_to_cpu(stats->flag) & UCODE_STATISTICS_CLEAR_MSK) { |
67289941 | 608 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
0da0e5bf JB |
609 | memset(&priv->accum_stats, 0, |
610 | sizeof(priv->accum_stats)); | |
611 | memset(&priv->delta_stats, 0, | |
612 | sizeof(priv->delta_stats)); | |
613 | memset(&priv->max_delta_stats, 0, | |
614 | sizeof(priv->max_delta_stats)); | |
67289941 SG |
615 | #endif |
616 | IWL_DEBUG_RX(priv, "Statistics have been cleared\n"); | |
617 | } | |
3246c4e6 | 618 | iwlagn_rx_statistics(priv, rxb, cmd); |
247c61d6 | 619 | return 0; |
67289941 SG |
620 | } |
621 | ||
466a19a0 SG |
622 | /* Handle notification from uCode that card's power state is changing |
623 | * due to software, hardware, or critical temperature RFKILL */ | |
3246c4e6 | 624 | static int iwlagn_rx_card_state_notif(struct iwl_priv *priv, |
48a2d66f | 625 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 626 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
627 | { |
628 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 JB |
629 | struct iwl_card_state_notif *card_state_notif = (void *)pkt->data; |
630 | u32 flags = le32_to_cpu(card_state_notif->flags); | |
63013ae3 | 631 | unsigned long status = priv->shrd->status; |
466a19a0 SG |
632 | |
633 | IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n", | |
634 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", | |
635 | (flags & SW_CARD_DISABLED) ? "Kill" : "On", | |
636 | (flags & CT_CARD_DISABLED) ? | |
637 | "Reached" : "Not reached"); | |
638 | ||
639 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | | |
640 | CT_CARD_DISABLED)) { | |
641 | ||
1042db2a | 642 | iwl_write32(trans(priv), CSR_UCODE_DRV_GP1_SET, |
466a19a0 SG |
643 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
644 | ||
1042db2a | 645 | iwl_write_direct32(trans(priv), HBUS_TARG_MBX_C, |
466a19a0 SG |
646 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
647 | ||
648 | if (!(flags & RXON_CARD_DISABLED)) { | |
1042db2a | 649 | iwl_write32(trans(priv), CSR_UCODE_DRV_GP1_CLR, |
466a19a0 | 650 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
1042db2a | 651 | iwl_write_direct32(trans(priv), HBUS_TARG_MBX_C, |
466a19a0 SG |
652 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
653 | } | |
654 | if (flags & CT_CARD_DISABLED) | |
655 | iwl_tt_enter_ct_kill(priv); | |
656 | } | |
657 | if (!(flags & CT_CARD_DISABLED)) | |
658 | iwl_tt_exit_ct_kill(priv); | |
659 | ||
660 | if (flags & HW_CARD_DISABLED) | |
63013ae3 | 661 | set_bit(STATUS_RF_KILL_HW, &priv->shrd->status); |
466a19a0 | 662 | else |
63013ae3 | 663 | clear_bit(STATUS_RF_KILL_HW, &priv->shrd->status); |
466a19a0 SG |
664 | |
665 | ||
666 | if (!(flags & RXON_CARD_DISABLED)) | |
667 | iwl_scan_cancel(priv); | |
668 | ||
669 | if ((test_bit(STATUS_RF_KILL_HW, &status) != | |
63013ae3 | 670 | test_bit(STATUS_RF_KILL_HW, &priv->shrd->status))) |
466a19a0 | 671 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, |
63013ae3 | 672 | test_bit(STATUS_RF_KILL_HW, &priv->shrd->status)); |
466a19a0 | 673 | else |
effd4d9a | 674 | wake_up(&priv->shrd->wait_command_queue); |
247c61d6 | 675 | return 0; |
466a19a0 SG |
676 | } |
677 | ||
3246c4e6 | 678 | static int iwlagn_rx_missed_beacon_notif(struct iwl_priv *priv, |
48a2d66f | 679 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 680 | struct iwl_device_cmd *cmd) |
67289941 SG |
681 | |
682 | { | |
683 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 684 | struct iwl_missed_beacon_notif *missed_beacon = (void *)pkt->data; |
67289941 | 685 | |
67289941 SG |
686 | if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) > |
687 | priv->missed_beacon_threshold) { | |
688 | IWL_DEBUG_CALIB(priv, | |
689 | "missed bcn cnsq %d totl %d rcd %d expctd %d\n", | |
690 | le32_to_cpu(missed_beacon->consecutive_missed_beacons), | |
691 | le32_to_cpu(missed_beacon->total_missed_becons), | |
692 | le32_to_cpu(missed_beacon->num_recvd_beacons), | |
693 | le32_to_cpu(missed_beacon->num_expected_beacons)); | |
63013ae3 | 694 | if (!test_bit(STATUS_SCANNING, &priv->shrd->status)) |
67289941 SG |
695 | iwl_init_sensitivity(priv); |
696 | } | |
247c61d6 | 697 | return 0; |
67289941 SG |
698 | } |
699 | ||
466a19a0 SG |
700 | /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD). |
701 | * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */ | |
3246c4e6 | 702 | static int iwlagn_rx_reply_rx_phy(struct iwl_priv *priv, |
48a2d66f | 703 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 704 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
705 | { |
706 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
707 | ||
898ed67b | 708 | priv->last_phy_res_valid = true; |
f8d7c1a1 | 709 | memcpy(&priv->last_phy_res, pkt->data, |
466a19a0 | 710 | sizeof(struct iwl_rx_phy_res)); |
247c61d6 | 711 | return 0; |
466a19a0 SG |
712 | } |
713 | ||
1781a07f EG |
714 | /* |
715 | * returns non-zero if packet should be dropped | |
716 | */ | |
3246c4e6 | 717 | static int iwlagn_set_decrypted_flag(struct iwl_priv *priv, |
466a19a0 SG |
718 | struct ieee80211_hdr *hdr, |
719 | u32 decrypt_res, | |
720 | struct ieee80211_rx_status *stats) | |
1781a07f EG |
721 | { |
722 | u16 fc = le16_to_cpu(hdr->frame_control); | |
723 | ||
246ed355 JB |
724 | /* |
725 | * All contexts have the same setting here due to it being | |
726 | * a module parameter, so OK to check any context. | |
727 | */ | |
728 | if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags & | |
729 | RXON_FILTER_DIS_DECRYPT_MSK) | |
1781a07f EG |
730 | return 0; |
731 | ||
732 | if (!(fc & IEEE80211_FCTL_PROTECTED)) | |
733 | return 0; | |
734 | ||
e1623446 | 735 | IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res); |
1781a07f EG |
736 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
737 | case RX_RES_STATUS_SEC_TYPE_TKIP: | |
738 | /* The uCode has got a bad phase 1 Key, pushes the packet. | |
739 | * Decryption will be done in SW. */ | |
740 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == | |
741 | RX_RES_STATUS_BAD_KEY_TTAK) | |
742 | break; | |
743 | ||
744 | case RX_RES_STATUS_SEC_TYPE_WEP: | |
745 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == | |
746 | RX_RES_STATUS_BAD_ICV_MIC) { | |
747 | /* bad ICV, the packet is destroyed since the | |
748 | * decryption is inplace, drop it */ | |
e1623446 | 749 | IWL_DEBUG_RX(priv, "Packet destroyed\n"); |
1781a07f EG |
750 | return -1; |
751 | } | |
752 | case RX_RES_STATUS_SEC_TYPE_CCMP: | |
753 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == | |
754 | RX_RES_STATUS_DECRYPT_OK) { | |
e1623446 | 755 | IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n"); |
1781a07f EG |
756 | stats->flag |= RX_FLAG_DECRYPTED; |
757 | } | |
758 | break; | |
759 | ||
760 | default: | |
761 | break; | |
762 | } | |
763 | return 0; | |
764 | } | |
466a19a0 | 765 | |
3246c4e6 | 766 | static void iwlagn_pass_packet_to_mac80211(struct iwl_priv *priv, |
466a19a0 SG |
767 | struct ieee80211_hdr *hdr, |
768 | u16 len, | |
769 | u32 ampdu_status, | |
48a2d66f | 770 | struct iwl_rx_cmd_buffer *rxb, |
466a19a0 SG |
771 | struct ieee80211_rx_status *stats) |
772 | { | |
773 | struct sk_buff *skb; | |
774 | __le16 fc = hdr->frame_control; | |
68b99311 | 775 | struct iwl_rxon_context *ctx; |
48a2d66f JB |
776 | struct page *p; |
777 | int offset; | |
466a19a0 SG |
778 | |
779 | /* We only process data packets if the interface is open */ | |
780 | if (unlikely(!priv->is_open)) { | |
781 | IWL_DEBUG_DROP_LIMIT(priv, | |
782 | "Dropping packet while interface is not open.\n"); | |
783 | return; | |
784 | } | |
785 | ||
786 | /* In case of HW accelerated crypto and bad decryption, drop */ | |
9d143e9a | 787 | if (!iwlagn_mod_params.sw_crypto && |
3246c4e6 | 788 | iwlagn_set_decrypted_flag(priv, hdr, ampdu_status, stats)) |
466a19a0 SG |
789 | return; |
790 | ||
791 | skb = dev_alloc_skb(128); | |
792 | if (!skb) { | |
793 | IWL_ERR(priv, "dev_alloc_skb failed\n"); | |
794 | return; | |
795 | } | |
796 | ||
48a2d66f JB |
797 | offset = (void *)hdr - rxb_addr(rxb); |
798 | p = rxb_steal_page(rxb); | |
799 | skb_add_rx_frag(skb, 0, p, offset, len); | |
466a19a0 SG |
800 | |
801 | iwl_update_stats(priv, false, fc, len); | |
68b99311 GT |
802 | |
803 | /* | |
804 | * Wake any queues that were stopped due to a passive channel tx | |
805 | * failure. This can happen because the regulatory enforcement in | |
806 | * the device waits for a beacon before allowing transmission, | |
807 | * sometimes even after already having transmitted frames for the | |
808 | * association because the new RXON may reset the information. | |
809 | */ | |
810 | if (unlikely(ieee80211_is_beacon(fc))) { | |
811 | for_each_context(priv, ctx) { | |
812 | if (!ctx->last_tx_rejected) | |
813 | continue; | |
814 | if (compare_ether_addr(hdr->addr3, | |
815 | ctx->active.bssid_addr)) | |
816 | continue; | |
817 | ctx->last_tx_rejected = false; | |
81a3de1c EG |
818 | iwl_trans_wake_any_queue(trans(priv), ctx->ctxid, |
819 | "channel got active"); | |
68b99311 GT |
820 | } |
821 | } | |
822 | ||
466a19a0 SG |
823 | memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats)); |
824 | ||
825 | ieee80211_rx(priv->hw, skb); | |
466a19a0 SG |
826 | } |
827 | ||
3246c4e6 | 828 | static u32 iwlagn_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in) |
466a19a0 SG |
829 | { |
830 | u32 decrypt_out = 0; | |
831 | ||
832 | if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) == | |
833 | RX_RES_STATUS_STATION_FOUND) | |
834 | decrypt_out |= (RX_RES_STATUS_STATION_FOUND | | |
835 | RX_RES_STATUS_NO_STATION_INFO_MISMATCH); | |
836 | ||
837 | decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK); | |
838 | ||
839 | /* packet was not encrypted */ | |
840 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == | |
841 | RX_RES_STATUS_SEC_TYPE_NONE) | |
842 | return decrypt_out; | |
843 | ||
844 | /* packet was encrypted with unknown alg */ | |
845 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == | |
846 | RX_RES_STATUS_SEC_TYPE_ERR) | |
847 | return decrypt_out; | |
848 | ||
849 | /* decryption was not done in HW */ | |
850 | if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) != | |
851 | RX_MPDU_RES_STATUS_DEC_DONE_MSK) | |
852 | return decrypt_out; | |
853 | ||
854 | switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) { | |
855 | ||
856 | case RX_RES_STATUS_SEC_TYPE_CCMP: | |
857 | /* alg is CCM: check MIC only */ | |
858 | if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK)) | |
859 | /* Bad MIC */ | |
860 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; | |
861 | else | |
862 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; | |
863 | ||
864 | break; | |
865 | ||
866 | case RX_RES_STATUS_SEC_TYPE_TKIP: | |
867 | if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) { | |
868 | /* Bad TTAK */ | |
869 | decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK; | |
870 | break; | |
871 | } | |
872 | /* fall through if TTAK OK */ | |
873 | default: | |
874 | if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK)) | |
875 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; | |
876 | else | |
877 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; | |
878 | break; | |
879 | } | |
880 | ||
881 | IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n", | |
882 | decrypt_in, decrypt_out); | |
883 | ||
884 | return decrypt_out; | |
885 | } | |
886 | ||
5c3d29fc DF |
887 | /* Calc max signal level (dBm) among 3 possible receivers */ |
888 | static int iwlagn_calc_rssi(struct iwl_priv *priv, | |
889 | struct iwl_rx_phy_res *rx_resp) | |
890 | { | |
891 | /* data from PHY/DSP regarding signal strength, etc., | |
892 | * contents are always there, not configurable by host | |
893 | */ | |
894 | struct iwlagn_non_cfg_phy *ncphy = | |
895 | (struct iwlagn_non_cfg_phy *)rx_resp->non_cfg_phy_buf; | |
896 | u32 val, rssi_a, rssi_b, rssi_c, max_rssi; | |
897 | u8 agc; | |
898 | ||
899 | val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_AGC_IDX]); | |
900 | agc = (val & IWLAGN_OFDM_AGC_MSK) >> IWLAGN_OFDM_AGC_BIT_POS; | |
901 | ||
902 | /* Find max rssi among 3 possible receivers. | |
903 | * These values are measured by the digital signal processor (DSP). | |
904 | * They should stay fairly constant even as the signal strength varies, | |
905 | * if the radio's automatic gain control (AGC) is working right. | |
906 | * AGC value (see below) will provide the "interesting" info. | |
907 | */ | |
908 | val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_AB_IDX]); | |
909 | rssi_a = (val & IWLAGN_OFDM_RSSI_INBAND_A_BITMSK) >> | |
910 | IWLAGN_OFDM_RSSI_A_BIT_POS; | |
911 | rssi_b = (val & IWLAGN_OFDM_RSSI_INBAND_B_BITMSK) >> | |
912 | IWLAGN_OFDM_RSSI_B_BIT_POS; | |
913 | val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_C_IDX]); | |
914 | rssi_c = (val & IWLAGN_OFDM_RSSI_INBAND_C_BITMSK) >> | |
915 | IWLAGN_OFDM_RSSI_C_BIT_POS; | |
916 | ||
917 | max_rssi = max_t(u32, rssi_a, rssi_b); | |
918 | max_rssi = max_t(u32, max_rssi, rssi_c); | |
919 | ||
920 | IWL_DEBUG_STATS(priv, "Rssi In A %d B %d C %d Max %d AGC dB %d\n", | |
921 | rssi_a, rssi_b, rssi_c, max_rssi, agc); | |
922 | ||
923 | /* dBm = max_rssi dB - agc dB - constant. | |
924 | * Higher AGC (higher radio gain) means lower signal. */ | |
925 | return max_rssi - agc - IWLAGN_RSSI_OFFSET; | |
926 | } | |
927 | ||
466a19a0 SG |
928 | /* Called for REPLY_RX (legacy ABG frames), or |
929 | * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */ | |
3246c4e6 | 930 | static int iwlagn_rx_reply_rx(struct iwl_priv *priv, |
48a2d66f | 931 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 932 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
933 | { |
934 | struct ieee80211_hdr *header; | |
935 | struct ieee80211_rx_status rx_status; | |
936 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
937 | struct iwl_rx_phy_res *phy_res; | |
938 | __le32 rx_pkt_status; | |
939 | struct iwl_rx_mpdu_res_start *amsdu; | |
940 | u32 len; | |
941 | u32 ampdu_status; | |
942 | u32 rate_n_flags; | |
943 | ||
944 | /** | |
945 | * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently. | |
946 | * REPLY_RX: physical layer info is in this buffer | |
947 | * REPLY_RX_MPDU_CMD: physical layer info was sent in separate | |
948 | * command and cached in priv->last_phy_res | |
949 | * | |
950 | * Here we set up local variables depending on which command is | |
951 | * received. | |
952 | */ | |
953 | if (pkt->hdr.cmd == REPLY_RX) { | |
f8d7c1a1 JB |
954 | phy_res = (struct iwl_rx_phy_res *)pkt->data; |
955 | header = (struct ieee80211_hdr *)(pkt->data + sizeof(*phy_res) | |
466a19a0 SG |
956 | + phy_res->cfg_phy_cnt); |
957 | ||
958 | len = le16_to_cpu(phy_res->byte_count); | |
f8d7c1a1 | 959 | rx_pkt_status = *(__le32 *)(pkt->data + sizeof(*phy_res) + |
466a19a0 SG |
960 | phy_res->cfg_phy_cnt + len); |
961 | ampdu_status = le32_to_cpu(rx_pkt_status); | |
962 | } else { | |
898ed67b | 963 | if (!priv->last_phy_res_valid) { |
466a19a0 | 964 | IWL_ERR(priv, "MPDU frame without cached PHY data\n"); |
247c61d6 | 965 | return 0; |
466a19a0 | 966 | } |
898ed67b | 967 | phy_res = &priv->last_phy_res; |
f8d7c1a1 JB |
968 | amsdu = (struct iwl_rx_mpdu_res_start *)pkt->data; |
969 | header = (struct ieee80211_hdr *)(pkt->data + sizeof(*amsdu)); | |
466a19a0 | 970 | len = le16_to_cpu(amsdu->byte_count); |
f8d7c1a1 | 971 | rx_pkt_status = *(__le32 *)(pkt->data + sizeof(*amsdu) + len); |
3246c4e6 | 972 | ampdu_status = iwlagn_translate_rx_status(priv, |
466a19a0 SG |
973 | le32_to_cpu(rx_pkt_status)); |
974 | } | |
975 | ||
976 | if ((unlikely(phy_res->cfg_phy_cnt > 20))) { | |
977 | IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d/n", | |
978 | phy_res->cfg_phy_cnt); | |
247c61d6 | 979 | return 0; |
466a19a0 SG |
980 | } |
981 | ||
982 | if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) || | |
983 | !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) { | |
984 | IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n", | |
985 | le32_to_cpu(rx_pkt_status)); | |
247c61d6 | 986 | return 0; |
466a19a0 SG |
987 | } |
988 | ||
989 | /* This will be used in several places later */ | |
990 | rate_n_flags = le32_to_cpu(phy_res->rate_n_flags); | |
991 | ||
992 | /* rx_status carries information about the packet to mac80211 */ | |
993 | rx_status.mactime = le64_to_cpu(phy_res->timestamp); | |
994 | rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? | |
995 | IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ; | |
996 | rx_status.freq = | |
997 | ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel), | |
998 | rx_status.band); | |
999 | rx_status.rate_idx = | |
1000 | iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band); | |
1001 | rx_status.flag = 0; | |
1002 | ||
1003 | /* TSF isn't reliable. In order to allow smooth user experience, | |
1004 | * this W/A doesn't propagate it to the mac80211 */ | |
1005 | /*rx_status.flag |= RX_FLAG_MACTIME_MPDU;*/ | |
1006 | ||
1007 | priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp); | |
1008 | ||
1009 | /* Find max signal strength (dBm) among 3 antenna/receiver chains */ | |
5c3d29fc | 1010 | rx_status.signal = iwlagn_calc_rssi(priv, phy_res); |
466a19a0 SG |
1011 | |
1012 | iwl_dbg_log_rx_data_frame(priv, len, header); | |
1013 | IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n", | |
1014 | rx_status.signal, (unsigned long long)rx_status.mactime); | |
1015 | ||
1016 | /* | |
1017 | * "antenna number" | |
1018 | * | |
1019 | * It seems that the antenna field in the phy flags value | |
1020 | * is actually a bit field. This is undefined by radiotap, | |
1021 | * it wants an actual antenna number but I always get "7" | |
1022 | * for most legacy frames I receive indicating that the | |
1023 | * same frame was received on all three RX chains. | |
1024 | * | |
1025 | * I think this field should be removed in favor of a | |
1026 | * new 802.11n radiotap field "RX chains" that is defined | |
1027 | * as a bitmask. | |
1028 | */ | |
1029 | rx_status.antenna = | |
1030 | (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK) | |
1031 | >> RX_RES_PHY_FLAGS_ANTENNA_POS; | |
1032 | ||
1033 | /* set the preamble flag if appropriate */ | |
1034 | if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) | |
1035 | rx_status.flag |= RX_FLAG_SHORTPRE; | |
1036 | ||
1037 | /* Set up the HT phy flags */ | |
1038 | if (rate_n_flags & RATE_MCS_HT_MSK) | |
1039 | rx_status.flag |= RX_FLAG_HT; | |
1040 | if (rate_n_flags & RATE_MCS_HT40_MSK) | |
1041 | rx_status.flag |= RX_FLAG_40MHZ; | |
1042 | if (rate_n_flags & RATE_MCS_SGI_MSK) | |
1043 | rx_status.flag |= RX_FLAG_SHORT_GI; | |
1044 | ||
3246c4e6 | 1045 | iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status, |
466a19a0 | 1046 | rxb, &rx_status); |
247c61d6 | 1047 | return 0; |
466a19a0 SG |
1048 | } |
1049 | ||
79d3eef8 | 1050 | static int iwlagn_rx_noa_notification(struct iwl_priv *priv, |
48a2d66f | 1051 | struct iwl_rx_cmd_buffer *rxb, |
79d3eef8 JB |
1052 | struct iwl_device_cmd *cmd) |
1053 | { | |
1054 | struct iwl_wipan_noa_data *new_data, *old_data; | |
1055 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 1056 | struct iwl_wipan_noa_notification *noa_notif = (void *)pkt->data; |
79d3eef8 JB |
1057 | |
1058 | /* no condition -- we're in softirq */ | |
1059 | old_data = rcu_dereference_protected(priv->noa_data, true); | |
1060 | ||
1061 | if (noa_notif->noa_active) { | |
1062 | u32 len = le16_to_cpu(noa_notif->noa_attribute.length); | |
1063 | u32 copylen = len; | |
1064 | ||
1065 | /* EID, len, OUI, subtype */ | |
1066 | len += 1 + 1 + 3 + 1; | |
1067 | /* P2P id, P2P length */ | |
1068 | len += 1 + 2; | |
1069 | copylen += 1 + 2; | |
1070 | ||
1071 | new_data = kmalloc(sizeof(*new_data) + len, GFP_ATOMIC); | |
1072 | if (new_data) { | |
1073 | new_data->length = len; | |
1074 | new_data->data[0] = WLAN_EID_VENDOR_SPECIFIC; | |
1075 | new_data->data[1] = len - 2; /* not counting EID, len */ | |
1076 | new_data->data[2] = (WLAN_OUI_WFA >> 16) & 0xff; | |
1077 | new_data->data[3] = (WLAN_OUI_WFA >> 8) & 0xff; | |
1078 | new_data->data[4] = (WLAN_OUI_WFA >> 0) & 0xff; | |
1079 | new_data->data[5] = WLAN_OUI_TYPE_WFA_P2P; | |
1080 | memcpy(&new_data->data[6], &noa_notif->noa_attribute, | |
1081 | copylen); | |
1082 | } | |
1083 | } else | |
1084 | new_data = NULL; | |
1085 | ||
1086 | rcu_assign_pointer(priv->noa_data, new_data); | |
1087 | ||
1088 | if (old_data) | |
1089 | kfree_rcu(old_data, rcu_head); | |
1090 | ||
1091 | return 0; | |
1092 | } | |
1093 | ||
466a19a0 SG |
1094 | /** |
1095 | * iwl_setup_rx_handlers - Initialize Rx handler callbacks | |
1096 | * | |
1097 | * Setup the RX handlers for each of the reply types sent from the uCode | |
1098 | * to the host. | |
1099 | */ | |
1100 | void iwl_setup_rx_handlers(struct iwl_priv *priv) | |
1101 | { | |
48a2d66f | 1102 | int (**handlers)(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 1103 | struct iwl_device_cmd *cmd); |
466a19a0 SG |
1104 | |
1105 | handlers = priv->rx_handlers; | |
1106 | ||
3246c4e6 WYG |
1107 | handlers[REPLY_ERROR] = iwlagn_rx_reply_error; |
1108 | handlers[CHANNEL_SWITCH_NOTIFICATION] = iwlagn_rx_csa; | |
1109 | handlers[SPECTRUM_MEASURE_NOTIFICATION] = | |
1110 | iwlagn_rx_spectrum_measure_notif; | |
1111 | handlers[PM_SLEEP_NOTIFICATION] = iwlagn_rx_pm_sleep_notif; | |
1112 | handlers[PM_DEBUG_STATISTIC_NOTIFIC] = | |
1113 | iwlagn_rx_pm_debug_statistics_notif; | |
1114 | handlers[BEACON_NOTIFICATION] = iwlagn_rx_beacon_notif; | |
247c61d6 | 1115 | handlers[REPLY_ADD_STA] = iwl_add_sta_callback; |
466a19a0 | 1116 | |
79d3eef8 JB |
1117 | handlers[REPLY_WIPAN_NOA_NOTIFICATION] = iwlagn_rx_noa_notification; |
1118 | ||
466a19a0 SG |
1119 | /* |
1120 | * The same handler is used for both the REPLY to a discrete | |
1121 | * statistics request from the host as well as for the periodic | |
1122 | * statistics notifications (after received beacons) from the uCode. | |
1123 | */ | |
3246c4e6 WYG |
1124 | handlers[REPLY_STATISTICS_CMD] = iwlagn_rx_reply_statistics; |
1125 | handlers[STATISTICS_NOTIFICATION] = iwlagn_rx_statistics; | |
466a19a0 SG |
1126 | |
1127 | iwl_setup_rx_scan_handlers(priv); | |
1128 | ||
3246c4e6 WYG |
1129 | handlers[CARD_STATE_NOTIFICATION] = iwlagn_rx_card_state_notif; |
1130 | handlers[MISSED_BEACONS_NOTIFICATION] = | |
1131 | iwlagn_rx_missed_beacon_notif; | |
466a19a0 SG |
1132 | |
1133 | /* Rx handlers */ | |
3246c4e6 WYG |
1134 | handlers[REPLY_RX_PHY_CMD] = iwlagn_rx_reply_rx_phy; |
1135 | handlers[REPLY_RX_MPDU_CMD] = iwlagn_rx_reply_rx; | |
466a19a0 SG |
1136 | |
1137 | /* block ack */ | |
3246c4e6 WYG |
1138 | handlers[REPLY_COMPRESSED_BA] = |
1139 | iwlagn_rx_reply_compressed_ba; | |
466a19a0 | 1140 | |
8d301193 EG |
1141 | /* init calibration handlers */ |
1142 | priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] = | |
1143 | iwlagn_rx_calib_result; | |
1144 | priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx; | |
1145 | ||
1146 | /* set up notification wait support */ | |
4bd14dd5 | 1147 | iwl_notification_wait_init(&priv->notif_wait); |
8d301193 EG |
1148 | |
1149 | /* Set up BT Rx handlers */ | |
38622419 DF |
1150 | if (cfg(priv)->lib->bt_rx_handler_setup) |
1151 | cfg(priv)->lib->bt_rx_handler_setup(priv); | |
8d301193 | 1152 | |
466a19a0 | 1153 | } |
1ab9f6c1 | 1154 | |
48a2d66f JB |
1155 | int iwl_rx_dispatch(struct iwl_op_mode *op_mode, struct iwl_rx_cmd_buffer *rxb, |
1156 | struct iwl_device_cmd *cmd) | |
1ab9f6c1 EG |
1157 | { |
1158 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
db70f290 | 1159 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); |
247c61d6 | 1160 | int err = 0; |
1ab9f6c1 EG |
1161 | |
1162 | /* | |
1163 | * Do the notification wait before RX handlers so | |
1164 | * even if the RX handler consumes the RXB we have | |
1165 | * access to it in the notification wait entry. | |
1166 | */ | |
4bd14dd5 | 1167 | iwl_notification_wait_notify(&priv->notif_wait, pkt); |
1ab9f6c1 | 1168 | |
64eeacb7 | 1169 | if (priv->pre_rx_handler && |
947a9407 | 1170 | priv->ucode_owner == IWL_OWNERSHIP_TM) |
1ab9f6c1 | 1171 | priv->pre_rx_handler(priv, rxb); |
64eeacb7 WYG |
1172 | else { |
1173 | /* Based on type of command response or notification, | |
1174 | * handle those that need handling via function in | |
1175 | * rx_handlers table. See iwl_setup_rx_handlers() */ | |
1176 | if (priv->rx_handlers[pkt->hdr.cmd]) { | |
1177 | priv->rx_handlers_stats[pkt->hdr.cmd]++; | |
1178 | err = priv->rx_handlers[pkt->hdr.cmd] (priv, rxb, cmd); | |
1179 | } else { | |
1180 | /* No handling needed */ | |
1181 | IWL_DEBUG_RX(priv, | |
1182 | "No handler needed for %s, 0x%02x\n", | |
1183 | get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd); | |
1184 | } | |
1ab9f6c1 | 1185 | } |
247c61d6 | 1186 | return err; |
1ab9f6c1 | 1187 | } |