Commit | Line | Data |
---|---|---|
a55360e4 TW |
1 | /****************************************************************************** |
2 | * | |
128e63ef | 3 | * Copyright(c) 2003 - 2013 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 | 35 | #include "iwl-io.h" |
1023fdc4 JB |
36 | #include "dev.h" |
37 | #include "calib.h" | |
38 | #include "agn.h" | |
466a19a0 | 39 | |
d9fb6465 JB |
40 | #define IWL_CMD_ENTRY(x) [x] = #x |
41 | ||
42 | const char *iwl_dvm_cmd_strings[REPLY_MAX] = { | |
43 | IWL_CMD_ENTRY(REPLY_ALIVE), | |
44 | IWL_CMD_ENTRY(REPLY_ERROR), | |
45 | IWL_CMD_ENTRY(REPLY_ECHO), | |
46 | IWL_CMD_ENTRY(REPLY_RXON), | |
47 | IWL_CMD_ENTRY(REPLY_RXON_ASSOC), | |
48 | IWL_CMD_ENTRY(REPLY_QOS_PARAM), | |
49 | IWL_CMD_ENTRY(REPLY_RXON_TIMING), | |
50 | IWL_CMD_ENTRY(REPLY_ADD_STA), | |
51 | IWL_CMD_ENTRY(REPLY_REMOVE_STA), | |
52 | IWL_CMD_ENTRY(REPLY_REMOVE_ALL_STA), | |
53 | IWL_CMD_ENTRY(REPLY_TXFIFO_FLUSH), | |
54 | IWL_CMD_ENTRY(REPLY_WEPKEY), | |
55 | IWL_CMD_ENTRY(REPLY_TX), | |
56 | IWL_CMD_ENTRY(REPLY_LEDS_CMD), | |
57 | IWL_CMD_ENTRY(REPLY_TX_LINK_QUALITY_CMD), | |
58 | IWL_CMD_ENTRY(COEX_PRIORITY_TABLE_CMD), | |
59 | IWL_CMD_ENTRY(COEX_MEDIUM_NOTIFICATION), | |
60 | IWL_CMD_ENTRY(COEX_EVENT_CMD), | |
61 | IWL_CMD_ENTRY(REPLY_QUIET_CMD), | |
62 | IWL_CMD_ENTRY(REPLY_CHANNEL_SWITCH), | |
63 | IWL_CMD_ENTRY(CHANNEL_SWITCH_NOTIFICATION), | |
64 | IWL_CMD_ENTRY(REPLY_SPECTRUM_MEASUREMENT_CMD), | |
65 | IWL_CMD_ENTRY(SPECTRUM_MEASURE_NOTIFICATION), | |
66 | IWL_CMD_ENTRY(POWER_TABLE_CMD), | |
67 | IWL_CMD_ENTRY(PM_SLEEP_NOTIFICATION), | |
68 | IWL_CMD_ENTRY(PM_DEBUG_STATISTIC_NOTIFIC), | |
69 | IWL_CMD_ENTRY(REPLY_SCAN_CMD), | |
70 | IWL_CMD_ENTRY(REPLY_SCAN_ABORT_CMD), | |
71 | IWL_CMD_ENTRY(SCAN_START_NOTIFICATION), | |
72 | IWL_CMD_ENTRY(SCAN_RESULTS_NOTIFICATION), | |
73 | IWL_CMD_ENTRY(SCAN_COMPLETE_NOTIFICATION), | |
74 | IWL_CMD_ENTRY(BEACON_NOTIFICATION), | |
75 | IWL_CMD_ENTRY(REPLY_TX_BEACON), | |
76 | IWL_CMD_ENTRY(WHO_IS_AWAKE_NOTIFICATION), | |
77 | IWL_CMD_ENTRY(QUIET_NOTIFICATION), | |
78 | IWL_CMD_ENTRY(REPLY_TX_PWR_TABLE_CMD), | |
79 | IWL_CMD_ENTRY(MEASURE_ABORT_NOTIFICATION), | |
80 | IWL_CMD_ENTRY(REPLY_BT_CONFIG), | |
81 | IWL_CMD_ENTRY(REPLY_STATISTICS_CMD), | |
82 | IWL_CMD_ENTRY(STATISTICS_NOTIFICATION), | |
83 | IWL_CMD_ENTRY(REPLY_CARD_STATE_CMD), | |
84 | IWL_CMD_ENTRY(CARD_STATE_NOTIFICATION), | |
85 | IWL_CMD_ENTRY(MISSED_BEACONS_NOTIFICATION), | |
86 | IWL_CMD_ENTRY(REPLY_CT_KILL_CONFIG_CMD), | |
87 | IWL_CMD_ENTRY(SENSITIVITY_CMD), | |
88 | IWL_CMD_ENTRY(REPLY_PHY_CALIBRATION_CMD), | |
89 | IWL_CMD_ENTRY(REPLY_RX_PHY_CMD), | |
90 | IWL_CMD_ENTRY(REPLY_RX_MPDU_CMD), | |
d9fb6465 JB |
91 | IWL_CMD_ENTRY(REPLY_COMPRESSED_BA), |
92 | IWL_CMD_ENTRY(CALIBRATION_CFG_CMD), | |
93 | IWL_CMD_ENTRY(CALIBRATION_RES_NOTIFICATION), | |
94 | IWL_CMD_ENTRY(CALIBRATION_COMPLETE_NOTIFICATION), | |
95 | IWL_CMD_ENTRY(REPLY_TX_POWER_DBM_CMD), | |
96 | IWL_CMD_ENTRY(TEMPERATURE_NOTIFICATION), | |
97 | IWL_CMD_ENTRY(TX_ANT_CONFIGURATION_CMD), | |
98 | IWL_CMD_ENTRY(REPLY_BT_COEX_PROFILE_NOTIF), | |
99 | IWL_CMD_ENTRY(REPLY_BT_COEX_PRIO_TABLE), | |
100 | IWL_CMD_ENTRY(REPLY_BT_COEX_PROT_ENV), | |
101 | IWL_CMD_ENTRY(REPLY_WIPAN_PARAMS), | |
102 | IWL_CMD_ENTRY(REPLY_WIPAN_RXON), | |
103 | IWL_CMD_ENTRY(REPLY_WIPAN_RXON_TIMING), | |
104 | IWL_CMD_ENTRY(REPLY_WIPAN_RXON_ASSOC), | |
105 | IWL_CMD_ENTRY(REPLY_WIPAN_QOS_PARAM), | |
106 | IWL_CMD_ENTRY(REPLY_WIPAN_WEPKEY), | |
107 | IWL_CMD_ENTRY(REPLY_WIPAN_P2P_CHANNEL_SWITCH), | |
108 | IWL_CMD_ENTRY(REPLY_WIPAN_NOA_NOTIFICATION), | |
109 | IWL_CMD_ENTRY(REPLY_WIPAN_DEACTIVATION_COMPLETE), | |
110 | IWL_CMD_ENTRY(REPLY_WOWLAN_PATTERNS), | |
111 | IWL_CMD_ENTRY(REPLY_WOWLAN_WAKEUP_FILTER), | |
112 | IWL_CMD_ENTRY(REPLY_WOWLAN_TSC_RSC_PARAMS), | |
113 | IWL_CMD_ENTRY(REPLY_WOWLAN_TKIP_PARAMS), | |
114 | IWL_CMD_ENTRY(REPLY_WOWLAN_KEK_KCK_MATERIAL), | |
115 | IWL_CMD_ENTRY(REPLY_WOWLAN_GET_STATUS), | |
116 | IWL_CMD_ENTRY(REPLY_D3_CONFIG), | |
117 | }; | |
118 | #undef IWL_CMD_ENTRY | |
a55360e4 | 119 | |
466a19a0 SG |
120 | /****************************************************************************** |
121 | * | |
122 | * Generic RX handler implementations | |
123 | * | |
124 | ******************************************************************************/ | |
125 | ||
3246c4e6 | 126 | static int iwlagn_rx_reply_error(struct iwl_priv *priv, |
48a2d66f | 127 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 128 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
129 | { |
130 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 131 | struct iwl_error_resp *err_resp = (void *)pkt->data; |
466a19a0 | 132 | |
d9fb6465 | 133 | IWL_ERR(priv, "Error Reply type 0x%08X cmd REPLY_ERROR (0x%02X) " |
466a19a0 | 134 | "seq 0x%04X ser 0x%08X\n", |
f8d7c1a1 | 135 | le32_to_cpu(err_resp->error_type), |
f8d7c1a1 JB |
136 | err_resp->cmd_id, |
137 | le16_to_cpu(err_resp->bad_cmd_seq_num), | |
138 | le32_to_cpu(err_resp->error_info)); | |
247c61d6 | 139 | return 0; |
466a19a0 SG |
140 | } |
141 | ||
48a2d66f | 142 | static int iwlagn_rx_csa(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 143 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
144 | { |
145 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 146 | struct iwl_csa_notification *csa = (void *)pkt->data; |
466a19a0 SG |
147 | /* |
148 | * MULTI-FIXME | |
ade4c649 | 149 | * See iwlagn_mac_channel_switch. |
466a19a0 SG |
150 | */ |
151 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | |
152 | struct iwl_rxon_cmd *rxon = (void *)&ctx->active; | |
153 | ||
83626404 | 154 | if (!test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status)) |
247c61d6 | 155 | return 0; |
6f213ff1 SG |
156 | |
157 | if (!le32_to_cpu(csa->status) && csa->channel == priv->switch_channel) { | |
158 | rxon->channel = csa->channel; | |
159 | ctx->staging.channel = csa->channel; | |
160 | IWL_DEBUG_11H(priv, "CSA notif: channel %d\n", | |
466a19a0 | 161 | le16_to_cpu(csa->channel)); |
6f213ff1 SG |
162 | iwl_chswitch_done(priv, true); |
163 | } else { | |
164 | IWL_ERR(priv, "CSA notif (fail) : channel %d\n", | |
165 | le16_to_cpu(csa->channel)); | |
166 | iwl_chswitch_done(priv, false); | |
466a19a0 | 167 | } |
247c61d6 | 168 | return 0; |
466a19a0 SG |
169 | } |
170 | ||
171 | ||
3246c4e6 | 172 | static int iwlagn_rx_spectrum_measure_notif(struct iwl_priv *priv, |
48a2d66f | 173 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 174 | struct iwl_device_cmd *cmd) |
81963d68 RC |
175 | { |
176 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 177 | struct iwl_spectrum_notification *report = (void *)pkt->data; |
81963d68 RC |
178 | |
179 | if (!report->state) { | |
180 | IWL_DEBUG_11H(priv, | |
181 | "Spectrum Measure Notification: Start\n"); | |
247c61d6 | 182 | return 0; |
81963d68 RC |
183 | } |
184 | ||
185 | memcpy(&priv->measure_report, report, sizeof(*report)); | |
186 | priv->measurement_status |= MEASUREMENT_READY; | |
247c61d6 | 187 | return 0; |
81963d68 | 188 | } |
81963d68 | 189 | |
3246c4e6 | 190 | static int iwlagn_rx_pm_sleep_notif(struct iwl_priv *priv, |
48a2d66f | 191 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 192 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
193 | { |
194 | #ifdef CONFIG_IWLWIFI_DEBUG | |
195 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 196 | struct iwl_sleep_notification *sleep = (void *)pkt->data; |
466a19a0 SG |
197 | IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n", |
198 | sleep->pm_sleep_mode, sleep->pm_wakeup_src); | |
199 | #endif | |
247c61d6 | 200 | return 0; |
466a19a0 SG |
201 | } |
202 | ||
3246c4e6 | 203 | static int iwlagn_rx_pm_debug_statistics_notif(struct iwl_priv *priv, |
48a2d66f | 204 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 205 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
206 | { |
207 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
44856c65 EG |
208 | u32 __maybe_unused len = |
209 | le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; | |
466a19a0 | 210 | IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled " |
d9fb6465 | 211 | "notification for PM_DEBUG_STATISTIC_NOTIFIC:\n", len); |
f8d7c1a1 | 212 | iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->data, len); |
247c61d6 | 213 | return 0; |
466a19a0 SG |
214 | } |
215 | ||
3246c4e6 | 216 | static int iwlagn_rx_beacon_notif(struct iwl_priv *priv, |
48a2d66f | 217 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 218 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
219 | { |
220 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 221 | struct iwlagn_beacon_notif *beacon = (void *)pkt->data; |
466a19a0 SG |
222 | #ifdef CONFIG_IWLWIFI_DEBUG |
223 | u16 status = le16_to_cpu(beacon->beacon_notify_hdr.status.status); | |
224 | u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags); | |
225 | ||
226 | IWL_DEBUG_RX(priv, "beacon status %#x, retries:%d ibssmgr:%d " | |
227 | "tsf:0x%.8x%.8x rate:%d\n", | |
228 | status & TX_STATUS_MSK, | |
229 | beacon->beacon_notify_hdr.failure_frame, | |
230 | le32_to_cpu(beacon->ibss_mgr_status), | |
231 | le32_to_cpu(beacon->high_tsf), | |
232 | le32_to_cpu(beacon->low_tsf), rate); | |
233 | #endif | |
234 | ||
235 | priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status); | |
236 | ||
247c61d6 | 237 | return 0; |
466a19a0 SG |
238 | } |
239 | ||
ad6e82a5 SG |
240 | /** |
241 | * iwl_good_plcp_health - checks for plcp error. | |
242 | * | |
243 | * When the plcp error is exceeding the thresholds, reset the radio | |
244 | * to improve the throughput. | |
245 | */ | |
3246c4e6 | 246 | static bool iwlagn_good_plcp_health(struct iwl_priv *priv, |
0da0e5bf JB |
247 | struct statistics_rx_phy *cur_ofdm, |
248 | struct statistics_rx_ht_phy *cur_ofdm_ht, | |
249 | unsigned int msecs) | |
ad6e82a5 | 250 | { |
6198c387 | 251 | int delta; |
ab5c0f1f | 252 | int threshold = priv->plcp_delta_threshold; |
ad6e82a5 | 253 | |
6198c387 | 254 | if (threshold == IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) { |
ad6e82a5 | 255 | IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n"); |
6198c387 | 256 | return true; |
ad6e82a5 SG |
257 | } |
258 | ||
0da0e5bf JB |
259 | delta = le32_to_cpu(cur_ofdm->plcp_err) - |
260 | le32_to_cpu(priv->statistics.rx_ofdm.plcp_err) + | |
261 | le32_to_cpu(cur_ofdm_ht->plcp_err) - | |
262 | le32_to_cpu(priv->statistics.rx_ofdm_ht.plcp_err); | |
6198c387 | 263 | |
0da0e5bf | 264 | /* Can be negative if firmware reset statistics */ |
6198c387 SG |
265 | if (delta <= 0) |
266 | return true; | |
267 | ||
268 | if ((delta * 100 / msecs) > threshold) { | |
269 | IWL_DEBUG_RADIO(priv, | |
270 | "plcp health threshold %u delta %d msecs %u\n", | |
271 | threshold, delta, msecs); | |
272 | return false; | |
273 | } | |
274 | ||
275 | return true; | |
ad6e82a5 SG |
276 | } |
277 | ||
66cd9e39 MV |
278 | int iwl_force_rf_reset(struct iwl_priv *priv, bool external) |
279 | { | |
280 | struct iwl_rf_reset *rf_reset; | |
281 | ||
282 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) | |
283 | return -EAGAIN; | |
284 | ||
285 | if (!iwl_is_any_associated(priv)) { | |
286 | IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n"); | |
287 | return -ENOLINK; | |
288 | } | |
289 | ||
290 | rf_reset = &priv->rf_reset; | |
291 | rf_reset->reset_request_count++; | |
292 | if (!external && rf_reset->last_reset_jiffies && | |
293 | time_after(rf_reset->last_reset_jiffies + | |
294 | IWL_DELAY_NEXT_FORCE_RF_RESET, jiffies)) { | |
295 | IWL_DEBUG_INFO(priv, "RF reset rejected\n"); | |
296 | rf_reset->reset_reject_count++; | |
297 | return -EAGAIN; | |
298 | } | |
299 | rf_reset->reset_success_count++; | |
300 | rf_reset->last_reset_jiffies = jiffies; | |
301 | ||
302 | /* | |
303 | * There is no easy and better way to force reset the radio, | |
304 | * the only known method is switching channel which will force to | |
305 | * reset and tune the radio. | |
306 | * Use internal short scan (single channel) operation to should | |
307 | * achieve this objective. | |
308 | * Driver should reset the radio when number of consecutive missed | |
309 | * beacon, or any other uCode error condition detected. | |
310 | */ | |
311 | IWL_DEBUG_INFO(priv, "perform radio reset.\n"); | |
312 | iwl_internal_short_hw_scan(priv); | |
313 | return 0; | |
314 | } | |
315 | ||
316 | ||
3246c4e6 WYG |
317 | static void iwlagn_recover_from_statistics(struct iwl_priv *priv, |
318 | struct statistics_rx_phy *cur_ofdm, | |
319 | struct statistics_rx_ht_phy *cur_ofdm_ht, | |
320 | struct statistics_tx *tx, | |
321 | unsigned long stamp) | |
fa8f130c | 322 | { |
410f2bb3 | 323 | unsigned int msecs; |
b7977ffa | 324 | |
83626404 | 325 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
410f2bb3 SG |
326 | return; |
327 | ||
410f2bb3 SG |
328 | msecs = jiffies_to_msecs(stamp - priv->rx_statistics_jiffies); |
329 | ||
330 | /* Only gather statistics and update time stamp when not associated */ | |
331 | if (!iwl_is_any_associated(priv)) | |
0da0e5bf | 332 | return; |
410f2bb3 SG |
333 | |
334 | /* Do not check/recover when do not have enough statistics data */ | |
335 | if (msecs < 99) | |
fa8f130c | 336 | return; |
ca3d9389 | 337 | |
8b5bf335 | 338 | if (!iwlagn_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs)) |
48dffd39 | 339 | iwl_force_rf_reset(priv, false); |
beac5498 | 340 | } |
beac5498 | 341 | |
67289941 SG |
342 | /* Calculate noise level, based on measurements during network silence just |
343 | * before arriving beacon. This measurement can be done only if we know | |
344 | * exactly when to expect beacons, therefore only when we're associated. */ | |
3246c4e6 | 345 | static void iwlagn_rx_calc_noise(struct iwl_priv *priv) |
67289941 SG |
346 | { |
347 | struct statistics_rx_non_phy *rx_info; | |
348 | int num_active_rx = 0; | |
349 | int total_silence = 0; | |
350 | int bcn_silence_a, bcn_silence_b, bcn_silence_c; | |
351 | int last_rx_noise; | |
352 | ||
0da0e5bf JB |
353 | rx_info = &priv->statistics.rx_non_phy; |
354 | ||
67289941 SG |
355 | bcn_silence_a = |
356 | le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER; | |
357 | bcn_silence_b = | |
358 | le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER; | |
359 | bcn_silence_c = | |
360 | le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER; | |
361 | ||
362 | if (bcn_silence_a) { | |
363 | total_silence += bcn_silence_a; | |
364 | num_active_rx++; | |
365 | } | |
366 | if (bcn_silence_b) { | |
367 | total_silence += bcn_silence_b; | |
368 | num_active_rx++; | |
369 | } | |
370 | if (bcn_silence_c) { | |
371 | total_silence += bcn_silence_c; | |
372 | num_active_rx++; | |
373 | } | |
374 | ||
375 | /* Average among active antennas */ | |
376 | if (num_active_rx) | |
377 | last_rx_noise = (total_silence / num_active_rx) - 107; | |
378 | else | |
379 | last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE; | |
380 | ||
381 | IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n", | |
382 | bcn_silence_a, bcn_silence_b, bcn_silence_c, | |
383 | last_rx_noise); | |
384 | } | |
385 | ||
0da0e5bf | 386 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
67289941 SG |
387 | /* |
388 | * based on the assumption of all statistics counter are in DWORD | |
389 | * FIXME: This function is for debugging, do not deal with | |
390 | * the case of counters roll-over. | |
391 | */ | |
0da0e5bf JB |
392 | static void accum_stats(__le32 *prev, __le32 *cur, __le32 *delta, |
393 | __le32 *max_delta, __le32 *accum, int size) | |
67289941 | 394 | { |
0da0e5bf JB |
395 | int i; |
396 | ||
397 | for (i = 0; | |
398 | i < size / sizeof(__le32); | |
399 | i++, prev++, cur++, delta++, max_delta++, accum++) { | |
400 | if (le32_to_cpu(*cur) > le32_to_cpu(*prev)) { | |
401 | *delta = cpu_to_le32( | |
402 | le32_to_cpu(*cur) - le32_to_cpu(*prev)); | |
403 | le32_add_cpu(accum, le32_to_cpu(*delta)); | |
404 | if (le32_to_cpu(*delta) > le32_to_cpu(*max_delta)) | |
67289941 SG |
405 | *max_delta = *delta; |
406 | } | |
407 | } | |
0da0e5bf | 408 | } |
67289941 | 409 | |
0da0e5bf | 410 | static void |
3246c4e6 | 411 | iwlagn_accumulative_statistics(struct iwl_priv *priv, |
0da0e5bf JB |
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) | |
419 | { | |
420 | #define ACCUM(_name) \ | |
421 | accum_stats((__le32 *)&priv->statistics._name, \ | |
422 | (__le32 *)_name, \ | |
423 | (__le32 *)&priv->delta_stats._name, \ | |
424 | (__le32 *)&priv->max_delta_stats._name, \ | |
425 | (__le32 *)&priv->accum_stats._name, \ | |
426 | sizeof(*_name)); | |
427 | ||
428 | ACCUM(common); | |
429 | ACCUM(rx_non_phy); | |
430 | ACCUM(rx_ofdm); | |
431 | ACCUM(rx_ofdm_ht); | |
432 | ACCUM(rx_cck); | |
433 | ACCUM(tx); | |
434 | if (bt_activity) | |
435 | ACCUM(bt_activity); | |
436 | #undef ACCUM | |
466a19a0 | 437 | } |
0da0e5bf JB |
438 | #else |
439 | static inline void | |
3246c4e6 | 440 | iwlagn_accumulative_statistics(struct iwl_priv *priv, |
0da0e5bf JB |
441 | struct statistics_general_common *common, |
442 | struct statistics_rx_non_phy *rx_non_phy, | |
443 | struct statistics_rx_phy *rx_ofdm, | |
444 | struct statistics_rx_ht_phy *rx_ofdm_ht, | |
445 | struct statistics_rx_phy *rx_cck, | |
446 | struct statistics_tx *tx, | |
447 | struct statistics_bt_activity *bt_activity) | |
448 | { | |
449 | } | |
450 | #endif | |
67289941 | 451 | |
3246c4e6 | 452 | static int iwlagn_rx_statistics(struct iwl_priv *priv, |
48a2d66f | 453 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 454 | struct iwl_device_cmd *cmd) |
67289941 | 455 | { |
0da0e5bf | 456 | unsigned long stamp = jiffies; |
466a19a0 | 457 | const int reg_recalib_period = 60; |
67289941 SG |
458 | int change; |
459 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
0da0e5bf JB |
460 | u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; |
461 | __le32 *flag; | |
462 | struct statistics_general_common *common; | |
463 | struct statistics_rx_non_phy *rx_non_phy; | |
464 | struct statistics_rx_phy *rx_ofdm; | |
465 | struct statistics_rx_ht_phy *rx_ofdm_ht; | |
466 | struct statistics_rx_phy *rx_cck; | |
467 | struct statistics_tx *tx; | |
468 | struct statistics_bt_activity *bt_activity; | |
469 | ||
470 | len -= sizeof(struct iwl_cmd_header); /* skip header */ | |
471 | ||
472 | IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n", | |
473 | len); | |
474 | ||
4ff70fcd JB |
475 | spin_lock(&priv->statistics.lock); |
476 | ||
0da0e5bf JB |
477 | if (len == sizeof(struct iwl_bt_notif_statistics)) { |
478 | struct iwl_bt_notif_statistics *stats; | |
f8d7c1a1 | 479 | stats = (void *)&pkt->data; |
0da0e5bf JB |
480 | flag = &stats->flag; |
481 | common = &stats->general.common; | |
482 | rx_non_phy = &stats->rx.general.common; | |
483 | rx_ofdm = &stats->rx.ofdm; | |
484 | rx_ofdm_ht = &stats->rx.ofdm_ht; | |
485 | rx_cck = &stats->rx.cck; | |
486 | tx = &stats->tx; | |
487 | bt_activity = &stats->general.activity; | |
67289941 | 488 | |
0da0e5bf JB |
489 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
490 | /* handle this exception directly */ | |
491 | priv->statistics.num_bt_kills = stats->rx.general.num_bt_kills; | |
492 | le32_add_cpu(&priv->statistics.accum_num_bt_kills, | |
493 | le32_to_cpu(stats->rx.general.num_bt_kills)); | |
494 | #endif | |
495 | } else if (len == sizeof(struct iwl_notif_statistics)) { | |
496 | struct iwl_notif_statistics *stats; | |
f8d7c1a1 | 497 | stats = (void *)&pkt->data; |
0da0e5bf JB |
498 | flag = &stats->flag; |
499 | common = &stats->general.common; | |
500 | rx_non_phy = &stats->rx.general; | |
501 | rx_ofdm = &stats->rx.ofdm; | |
502 | rx_ofdm_ht = &stats->rx.ofdm_ht; | |
503 | rx_cck = &stats->rx.cck; | |
504 | tx = &stats->tx; | |
505 | bt_activity = NULL; | |
67289941 | 506 | } else { |
0da0e5bf JB |
507 | WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n", |
508 | len, sizeof(struct iwl_bt_notif_statistics), | |
509 | sizeof(struct iwl_notif_statistics)); | |
4ff70fcd | 510 | spin_unlock(&priv->statistics.lock); |
247c61d6 | 511 | return 0; |
67289941 SG |
512 | } |
513 | ||
0da0e5bf JB |
514 | change = common->temperature != priv->statistics.common.temperature || |
515 | (*flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK) != | |
516 | (priv->statistics.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK); | |
517 | ||
3246c4e6 | 518 | iwlagn_accumulative_statistics(priv, common, rx_non_phy, rx_ofdm, |
0da0e5bf JB |
519 | rx_ofdm_ht, rx_cck, tx, bt_activity); |
520 | ||
3246c4e6 | 521 | iwlagn_recover_from_statistics(priv, rx_ofdm, rx_ofdm_ht, tx, stamp); |
0da0e5bf JB |
522 | |
523 | priv->statistics.flag = *flag; | |
524 | memcpy(&priv->statistics.common, common, sizeof(*common)); | |
525 | memcpy(&priv->statistics.rx_non_phy, rx_non_phy, sizeof(*rx_non_phy)); | |
526 | memcpy(&priv->statistics.rx_ofdm, rx_ofdm, sizeof(*rx_ofdm)); | |
527 | memcpy(&priv->statistics.rx_ofdm_ht, rx_ofdm_ht, sizeof(*rx_ofdm_ht)); | |
528 | memcpy(&priv->statistics.rx_cck, rx_cck, sizeof(*rx_cck)); | |
529 | memcpy(&priv->statistics.tx, tx, sizeof(*tx)); | |
530 | #ifdef CONFIG_IWLWIFI_DEBUGFS | |
531 | if (bt_activity) | |
532 | memcpy(&priv->statistics.bt_activity, bt_activity, | |
533 | sizeof(*bt_activity)); | |
534 | #endif | |
535 | ||
536 | priv->rx_statistics_jiffies = stamp; | |
67289941 | 537 | |
83626404 | 538 | set_bit(STATUS_STATISTICS, &priv->status); |
67289941 SG |
539 | |
540 | /* Reschedule the statistics timer to occur in | |
466a19a0 | 541 | * reg_recalib_period seconds to ensure we get a |
67289941 SG |
542 | * thermal update even if the uCode doesn't give |
543 | * us one */ | |
544 | mod_timer(&priv->statistics_periodic, jiffies + | |
466a19a0 | 545 | msecs_to_jiffies(reg_recalib_period * 1000)); |
67289941 | 546 | |
83626404 | 547 | if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) && |
67289941 | 548 | (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) { |
3246c4e6 | 549 | iwlagn_rx_calc_noise(priv); |
1ee158d8 | 550 | queue_work(priv->workqueue, &priv->run_time_calib_work); |
67289941 | 551 | } |
e9676695 JB |
552 | if (priv->lib->temperature && change) |
553 | priv->lib->temperature(priv); | |
4ff70fcd JB |
554 | |
555 | spin_unlock(&priv->statistics.lock); | |
556 | ||
247c61d6 | 557 | return 0; |
67289941 SG |
558 | } |
559 | ||
3246c4e6 | 560 | static int iwlagn_rx_reply_statistics(struct iwl_priv *priv, |
48a2d66f | 561 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 562 | struct iwl_device_cmd *cmd) |
67289941 SG |
563 | { |
564 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 565 | struct iwl_notif_statistics *stats = (void *)pkt->data; |
67289941 | 566 | |
f8d7c1a1 | 567 | if (le32_to_cpu(stats->flag) & UCODE_STATISTICS_CLEAR_MSK) { |
67289941 | 568 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
0da0e5bf JB |
569 | memset(&priv->accum_stats, 0, |
570 | sizeof(priv->accum_stats)); | |
571 | memset(&priv->delta_stats, 0, | |
572 | sizeof(priv->delta_stats)); | |
573 | memset(&priv->max_delta_stats, 0, | |
574 | sizeof(priv->max_delta_stats)); | |
67289941 SG |
575 | #endif |
576 | IWL_DEBUG_RX(priv, "Statistics have been cleared\n"); | |
577 | } | |
3246c4e6 | 578 | iwlagn_rx_statistics(priv, rxb, cmd); |
247c61d6 | 579 | return 0; |
67289941 SG |
580 | } |
581 | ||
466a19a0 SG |
582 | /* Handle notification from uCode that card's power state is changing |
583 | * due to software, hardware, or critical temperature RFKILL */ | |
3246c4e6 | 584 | static int iwlagn_rx_card_state_notif(struct iwl_priv *priv, |
48a2d66f | 585 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 586 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
587 | { |
588 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 JB |
589 | struct iwl_card_state_notif *card_state_notif = (void *)pkt->data; |
590 | u32 flags = le32_to_cpu(card_state_notif->flags); | |
1353a7ba | 591 | unsigned long status = priv->status; |
466a19a0 SG |
592 | |
593 | IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n", | |
594 | (flags & HW_CARD_DISABLED) ? "Kill" : "On", | |
595 | (flags & SW_CARD_DISABLED) ? "Kill" : "On", | |
596 | (flags & CT_CARD_DISABLED) ? | |
597 | "Reached" : "Not reached"); | |
598 | ||
599 | if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED | | |
600 | CT_CARD_DISABLED)) { | |
601 | ||
68e8dfda | 602 | iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_SET, |
466a19a0 SG |
603 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
604 | ||
68e8dfda | 605 | iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C, |
466a19a0 SG |
606 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
607 | ||
608 | if (!(flags & RXON_CARD_DISABLED)) { | |
68e8dfda | 609 | iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR, |
466a19a0 | 610 | CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED); |
68e8dfda | 611 | iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C, |
466a19a0 SG |
612 | HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED); |
613 | } | |
614 | if (flags & CT_CARD_DISABLED) | |
615 | iwl_tt_enter_ct_kill(priv); | |
616 | } | |
617 | if (!(flags & CT_CARD_DISABLED)) | |
618 | iwl_tt_exit_ct_kill(priv); | |
619 | ||
620 | if (flags & HW_CARD_DISABLED) | |
83626404 | 621 | set_bit(STATUS_RF_KILL_HW, &priv->status); |
466a19a0 | 622 | else |
83626404 | 623 | clear_bit(STATUS_RF_KILL_HW, &priv->status); |
466a19a0 SG |
624 | |
625 | ||
626 | if (!(flags & RXON_CARD_DISABLED)) | |
627 | iwl_scan_cancel(priv); | |
628 | ||
629 | if ((test_bit(STATUS_RF_KILL_HW, &status) != | |
83626404 | 630 | test_bit(STATUS_RF_KILL_HW, &priv->status))) |
466a19a0 | 631 | wiphy_rfkill_set_hw_state(priv->hw->wiphy, |
83626404 | 632 | test_bit(STATUS_RF_KILL_HW, &priv->status)); |
247c61d6 | 633 | return 0; |
466a19a0 SG |
634 | } |
635 | ||
3246c4e6 | 636 | static int iwlagn_rx_missed_beacon_notif(struct iwl_priv *priv, |
48a2d66f | 637 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 638 | struct iwl_device_cmd *cmd) |
67289941 SG |
639 | |
640 | { | |
641 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 642 | struct iwl_missed_beacon_notif *missed_beacon = (void *)pkt->data; |
67289941 | 643 | |
67289941 SG |
644 | if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) > |
645 | priv->missed_beacon_threshold) { | |
646 | IWL_DEBUG_CALIB(priv, | |
647 | "missed bcn cnsq %d totl %d rcd %d expctd %d\n", | |
648 | le32_to_cpu(missed_beacon->consecutive_missed_beacons), | |
649 | le32_to_cpu(missed_beacon->total_missed_becons), | |
650 | le32_to_cpu(missed_beacon->num_recvd_beacons), | |
651 | le32_to_cpu(missed_beacon->num_expected_beacons)); | |
83626404 | 652 | if (!test_bit(STATUS_SCANNING, &priv->status)) |
67289941 SG |
653 | iwl_init_sensitivity(priv); |
654 | } | |
247c61d6 | 655 | return 0; |
67289941 SG |
656 | } |
657 | ||
466a19a0 SG |
658 | /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD). |
659 | * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */ | |
3246c4e6 | 660 | static int iwlagn_rx_reply_rx_phy(struct iwl_priv *priv, |
48a2d66f | 661 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 662 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
663 | { |
664 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
665 | ||
898ed67b | 666 | priv->last_phy_res_valid = true; |
12bf6f45 | 667 | priv->ampdu_ref++; |
f8d7c1a1 | 668 | memcpy(&priv->last_phy_res, pkt->data, |
466a19a0 | 669 | sizeof(struct iwl_rx_phy_res)); |
247c61d6 | 670 | return 0; |
466a19a0 SG |
671 | } |
672 | ||
1781a07f EG |
673 | /* |
674 | * returns non-zero if packet should be dropped | |
675 | */ | |
3246c4e6 | 676 | static int iwlagn_set_decrypted_flag(struct iwl_priv *priv, |
466a19a0 SG |
677 | struct ieee80211_hdr *hdr, |
678 | u32 decrypt_res, | |
679 | struct ieee80211_rx_status *stats) | |
1781a07f EG |
680 | { |
681 | u16 fc = le16_to_cpu(hdr->frame_control); | |
682 | ||
246ed355 JB |
683 | /* |
684 | * All contexts have the same setting here due to it being | |
685 | * a module parameter, so OK to check any context. | |
686 | */ | |
687 | if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags & | |
688 | RXON_FILTER_DIS_DECRYPT_MSK) | |
1781a07f EG |
689 | return 0; |
690 | ||
691 | if (!(fc & IEEE80211_FCTL_PROTECTED)) | |
692 | return 0; | |
693 | ||
e1623446 | 694 | IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res); |
1781a07f EG |
695 | switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) { |
696 | case RX_RES_STATUS_SEC_TYPE_TKIP: | |
697 | /* The uCode has got a bad phase 1 Key, pushes the packet. | |
698 | * Decryption will be done in SW. */ | |
699 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == | |
700 | RX_RES_STATUS_BAD_KEY_TTAK) | |
701 | break; | |
702 | ||
703 | case RX_RES_STATUS_SEC_TYPE_WEP: | |
704 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == | |
705 | RX_RES_STATUS_BAD_ICV_MIC) { | |
706 | /* bad ICV, the packet is destroyed since the | |
707 | * decryption is inplace, drop it */ | |
e1623446 | 708 | IWL_DEBUG_RX(priv, "Packet destroyed\n"); |
1781a07f EG |
709 | return -1; |
710 | } | |
711 | case RX_RES_STATUS_SEC_TYPE_CCMP: | |
712 | if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) == | |
713 | RX_RES_STATUS_DECRYPT_OK) { | |
e1623446 | 714 | IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n"); |
1781a07f EG |
715 | stats->flag |= RX_FLAG_DECRYPTED; |
716 | } | |
717 | break; | |
718 | ||
719 | default: | |
720 | break; | |
721 | } | |
722 | return 0; | |
723 | } | |
466a19a0 | 724 | |
3246c4e6 | 725 | static void iwlagn_pass_packet_to_mac80211(struct iwl_priv *priv, |
466a19a0 SG |
726 | struct ieee80211_hdr *hdr, |
727 | u16 len, | |
728 | u32 ampdu_status, | |
48a2d66f | 729 | struct iwl_rx_cmd_buffer *rxb, |
466a19a0 SG |
730 | struct ieee80211_rx_status *stats) |
731 | { | |
732 | struct sk_buff *skb; | |
733 | __le16 fc = hdr->frame_control; | |
68b99311 | 734 | struct iwl_rxon_context *ctx; |
ed90542b | 735 | unsigned int hdrlen, fraglen; |
466a19a0 SG |
736 | |
737 | /* We only process data packets if the interface is open */ | |
738 | if (unlikely(!priv->is_open)) { | |
739 | IWL_DEBUG_DROP_LIMIT(priv, | |
740 | "Dropping packet while interface is not open.\n"); | |
741 | return; | |
742 | } | |
743 | ||
744 | /* In case of HW accelerated crypto and bad decryption, drop */ | |
65de7e84 | 745 | if (!iwlwifi_mod_params.sw_crypto && |
3246c4e6 | 746 | iwlagn_set_decrypted_flag(priv, hdr, ampdu_status, stats)) |
466a19a0 SG |
747 | return; |
748 | ||
ed90542b ED |
749 | /* Dont use dev_alloc_skb(), we'll have enough headroom once |
750 | * ieee80211_hdr pulled. | |
751 | */ | |
752 | skb = alloc_skb(128, GFP_ATOMIC); | |
466a19a0 | 753 | if (!skb) { |
ed90542b | 754 | IWL_ERR(priv, "alloc_skb failed\n"); |
466a19a0 SG |
755 | return; |
756 | } | |
56138f50 ED |
757 | /* If frame is small enough to fit in skb->head, pull it completely. |
758 | * If not, only pull ieee80211_hdr so that splice() or TCP coalesce | |
759 | * are more efficient. | |
760 | */ | |
761 | hdrlen = (len <= skb_tailroom(skb)) ? len : sizeof(*hdr); | |
762 | ||
ed90542b ED |
763 | memcpy(skb_put(skb, hdrlen), hdr, hdrlen); |
764 | fraglen = len - hdrlen; | |
466a19a0 | 765 | |
ed90542b | 766 | if (fraglen) { |
341352d1 JL |
767 | int offset = (void *)hdr + hdrlen - |
768 | rxb_addr(rxb) + rxb_offset(rxb); | |
466a19a0 | 769 | |
ed90542b ED |
770 | skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset, |
771 | fraglen, rxb->truesize); | |
772 | } | |
466a19a0 | 773 | |
68b99311 GT |
774 | /* |
775 | * Wake any queues that were stopped due to a passive channel tx | |
776 | * failure. This can happen because the regulatory enforcement in | |
777 | * the device waits for a beacon before allowing transmission, | |
778 | * sometimes even after already having transmitted frames for the | |
779 | * association because the new RXON may reset the information. | |
780 | */ | |
e755f882 | 781 | if (unlikely(ieee80211_is_beacon(fc) && priv->passive_no_rx)) { |
68b99311 | 782 | for_each_context(priv, ctx) { |
2e42e474 JP |
783 | if (!ether_addr_equal(hdr->addr3, |
784 | ctx->active.bssid_addr)) | |
68b99311 | 785 | continue; |
e755f882 | 786 | iwlagn_lift_passive_no_rx(priv); |
68b99311 GT |
787 | } |
788 | } | |
789 | ||
466a19a0 SG |
790 | memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats)); |
791 | ||
2bfb5092 | 792 | ieee80211_rx_ni(priv->hw, skb); |
466a19a0 SG |
793 | } |
794 | ||
3246c4e6 | 795 | static u32 iwlagn_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in) |
466a19a0 SG |
796 | { |
797 | u32 decrypt_out = 0; | |
798 | ||
799 | if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) == | |
800 | RX_RES_STATUS_STATION_FOUND) | |
801 | decrypt_out |= (RX_RES_STATUS_STATION_FOUND | | |
802 | RX_RES_STATUS_NO_STATION_INFO_MISMATCH); | |
803 | ||
804 | decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK); | |
805 | ||
806 | /* packet was not encrypted */ | |
807 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == | |
808 | RX_RES_STATUS_SEC_TYPE_NONE) | |
809 | return decrypt_out; | |
810 | ||
811 | /* packet was encrypted with unknown alg */ | |
812 | if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) == | |
813 | RX_RES_STATUS_SEC_TYPE_ERR) | |
814 | return decrypt_out; | |
815 | ||
816 | /* decryption was not done in HW */ | |
817 | if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) != | |
818 | RX_MPDU_RES_STATUS_DEC_DONE_MSK) | |
819 | return decrypt_out; | |
820 | ||
821 | switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) { | |
822 | ||
823 | case RX_RES_STATUS_SEC_TYPE_CCMP: | |
824 | /* alg is CCM: check MIC only */ | |
825 | if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK)) | |
826 | /* Bad MIC */ | |
827 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; | |
828 | else | |
829 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; | |
830 | ||
831 | break; | |
832 | ||
833 | case RX_RES_STATUS_SEC_TYPE_TKIP: | |
834 | if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) { | |
835 | /* Bad TTAK */ | |
836 | decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK; | |
837 | break; | |
838 | } | |
839 | /* fall through if TTAK OK */ | |
840 | default: | |
841 | if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK)) | |
842 | decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC; | |
843 | else | |
844 | decrypt_out |= RX_RES_STATUS_DECRYPT_OK; | |
845 | break; | |
846 | } | |
847 | ||
848 | IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n", | |
849 | decrypt_in, decrypt_out); | |
850 | ||
851 | return decrypt_out; | |
852 | } | |
853 | ||
5c3d29fc DF |
854 | /* Calc max signal level (dBm) among 3 possible receivers */ |
855 | static int iwlagn_calc_rssi(struct iwl_priv *priv, | |
856 | struct iwl_rx_phy_res *rx_resp) | |
857 | { | |
858 | /* data from PHY/DSP regarding signal strength, etc., | |
859 | * contents are always there, not configurable by host | |
860 | */ | |
861 | struct iwlagn_non_cfg_phy *ncphy = | |
862 | (struct iwlagn_non_cfg_phy *)rx_resp->non_cfg_phy_buf; | |
863 | u32 val, rssi_a, rssi_b, rssi_c, max_rssi; | |
864 | u8 agc; | |
865 | ||
866 | val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_AGC_IDX]); | |
867 | agc = (val & IWLAGN_OFDM_AGC_MSK) >> IWLAGN_OFDM_AGC_BIT_POS; | |
868 | ||
869 | /* Find max rssi among 3 possible receivers. | |
870 | * These values are measured by the digital signal processor (DSP). | |
871 | * They should stay fairly constant even as the signal strength varies, | |
872 | * if the radio's automatic gain control (AGC) is working right. | |
873 | * AGC value (see below) will provide the "interesting" info. | |
874 | */ | |
875 | val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_AB_IDX]); | |
876 | rssi_a = (val & IWLAGN_OFDM_RSSI_INBAND_A_BITMSK) >> | |
877 | IWLAGN_OFDM_RSSI_A_BIT_POS; | |
878 | rssi_b = (val & IWLAGN_OFDM_RSSI_INBAND_B_BITMSK) >> | |
879 | IWLAGN_OFDM_RSSI_B_BIT_POS; | |
880 | val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_C_IDX]); | |
881 | rssi_c = (val & IWLAGN_OFDM_RSSI_INBAND_C_BITMSK) >> | |
882 | IWLAGN_OFDM_RSSI_C_BIT_POS; | |
883 | ||
884 | max_rssi = max_t(u32, rssi_a, rssi_b); | |
885 | max_rssi = max_t(u32, max_rssi, rssi_c); | |
886 | ||
887 | IWL_DEBUG_STATS(priv, "Rssi In A %d B %d C %d Max %d AGC dB %d\n", | |
888 | rssi_a, rssi_b, rssi_c, max_rssi, agc); | |
889 | ||
890 | /* dBm = max_rssi dB - agc dB - constant. | |
891 | * Higher AGC (higher radio gain) means lower signal. */ | |
892 | return max_rssi - agc - IWLAGN_RSSI_OFFSET; | |
893 | } | |
894 | ||
6d044b90 | 895 | /* Called for REPLY_RX_MPDU_CMD */ |
3246c4e6 | 896 | static int iwlagn_rx_reply_rx(struct iwl_priv *priv, |
48a2d66f | 897 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 898 | struct iwl_device_cmd *cmd) |
466a19a0 SG |
899 | { |
900 | struct ieee80211_hdr *header; | |
1d815ef4 | 901 | struct ieee80211_rx_status rx_status = {}; |
466a19a0 SG |
902 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
903 | struct iwl_rx_phy_res *phy_res; | |
904 | __le32 rx_pkt_status; | |
905 | struct iwl_rx_mpdu_res_start *amsdu; | |
906 | u32 len; | |
907 | u32 ampdu_status; | |
908 | u32 rate_n_flags; | |
909 | ||
6d044b90 EG |
910 | if (!priv->last_phy_res_valid) { |
911 | IWL_ERR(priv, "MPDU frame without cached PHY data\n"); | |
912 | return 0; | |
466a19a0 | 913 | } |
6d044b90 EG |
914 | phy_res = &priv->last_phy_res; |
915 | amsdu = (struct iwl_rx_mpdu_res_start *)pkt->data; | |
916 | header = (struct ieee80211_hdr *)(pkt->data + sizeof(*amsdu)); | |
917 | len = le16_to_cpu(amsdu->byte_count); | |
918 | rx_pkt_status = *(__le32 *)(pkt->data + sizeof(*amsdu) + len); | |
919 | ampdu_status = iwlagn_translate_rx_status(priv, | |
920 | le32_to_cpu(rx_pkt_status)); | |
466a19a0 SG |
921 | |
922 | if ((unlikely(phy_res->cfg_phy_cnt > 20))) { | |
0ca24daf | 923 | IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d\n", |
466a19a0 | 924 | phy_res->cfg_phy_cnt); |
247c61d6 | 925 | return 0; |
466a19a0 SG |
926 | } |
927 | ||
928 | if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) || | |
929 | !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) { | |
930 | IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n", | |
931 | le32_to_cpu(rx_pkt_status)); | |
247c61d6 | 932 | return 0; |
466a19a0 SG |
933 | } |
934 | ||
935 | /* This will be used in several places later */ | |
936 | rate_n_flags = le32_to_cpu(phy_res->rate_n_flags); | |
937 | ||
938 | /* rx_status carries information about the packet to mac80211 */ | |
939 | rx_status.mactime = le64_to_cpu(phy_res->timestamp); | |
940 | rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ? | |
941 | IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ; | |
942 | rx_status.freq = | |
943 | ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel), | |
944 | rx_status.band); | |
945 | rx_status.rate_idx = | |
946 | iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band); | |
947 | rx_status.flag = 0; | |
948 | ||
949 | /* TSF isn't reliable. In order to allow smooth user experience, | |
950 | * this W/A doesn't propagate it to the mac80211 */ | |
f4bda337 | 951 | /*rx_status.flag |= RX_FLAG_MACTIME_START;*/ |
466a19a0 SG |
952 | |
953 | priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp); | |
954 | ||
955 | /* Find max signal strength (dBm) among 3 antenna/receiver chains */ | |
5c3d29fc | 956 | rx_status.signal = iwlagn_calc_rssi(priv, phy_res); |
466a19a0 | 957 | |
466a19a0 SG |
958 | IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n", |
959 | rx_status.signal, (unsigned long long)rx_status.mactime); | |
960 | ||
961 | /* | |
962 | * "antenna number" | |
963 | * | |
964 | * It seems that the antenna field in the phy flags value | |
965 | * is actually a bit field. This is undefined by radiotap, | |
966 | * it wants an actual antenna number but I always get "7" | |
967 | * for most legacy frames I receive indicating that the | |
968 | * same frame was received on all three RX chains. | |
969 | * | |
970 | * I think this field should be removed in favor of a | |
971 | * new 802.11n radiotap field "RX chains" that is defined | |
972 | * as a bitmask. | |
973 | */ | |
974 | rx_status.antenna = | |
975 | (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK) | |
976 | >> RX_RES_PHY_FLAGS_ANTENNA_POS; | |
977 | ||
978 | /* set the preamble flag if appropriate */ | |
979 | if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK) | |
980 | rx_status.flag |= RX_FLAG_SHORTPRE; | |
981 | ||
12bf6f45 JB |
982 | if (phy_res->phy_flags & RX_RES_PHY_FLAGS_AGG_MSK) { |
983 | /* | |
984 | * We know which subframes of an A-MPDU belong | |
985 | * together since we get a single PHY response | |
986 | * from the firmware for all of them | |
987 | */ | |
988 | rx_status.flag |= RX_FLAG_AMPDU_DETAILS; | |
989 | rx_status.ampdu_reference = priv->ampdu_ref; | |
990 | } | |
991 | ||
466a19a0 SG |
992 | /* Set up the HT phy flags */ |
993 | if (rate_n_flags & RATE_MCS_HT_MSK) | |
994 | rx_status.flag |= RX_FLAG_HT; | |
995 | if (rate_n_flags & RATE_MCS_HT40_MSK) | |
996 | rx_status.flag |= RX_FLAG_40MHZ; | |
997 | if (rate_n_flags & RATE_MCS_SGI_MSK) | |
998 | rx_status.flag |= RX_FLAG_SHORT_GI; | |
53e1116e JB |
999 | if (rate_n_flags & RATE_MCS_GF_MSK) |
1000 | rx_status.flag |= RX_FLAG_HT_GF; | |
466a19a0 | 1001 | |
3246c4e6 | 1002 | iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status, |
466a19a0 | 1003 | rxb, &rx_status); |
247c61d6 | 1004 | return 0; |
466a19a0 SG |
1005 | } |
1006 | ||
79d3eef8 | 1007 | static int iwlagn_rx_noa_notification(struct iwl_priv *priv, |
48a2d66f | 1008 | struct iwl_rx_cmd_buffer *rxb, |
79d3eef8 JB |
1009 | struct iwl_device_cmd *cmd) |
1010 | { | |
1011 | struct iwl_wipan_noa_data *new_data, *old_data; | |
1012 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
f8d7c1a1 | 1013 | struct iwl_wipan_noa_notification *noa_notif = (void *)pkt->data; |
79d3eef8 JB |
1014 | |
1015 | /* no condition -- we're in softirq */ | |
1016 | old_data = rcu_dereference_protected(priv->noa_data, true); | |
1017 | ||
1018 | if (noa_notif->noa_active) { | |
1019 | u32 len = le16_to_cpu(noa_notif->noa_attribute.length); | |
1020 | u32 copylen = len; | |
1021 | ||
1022 | /* EID, len, OUI, subtype */ | |
1023 | len += 1 + 1 + 3 + 1; | |
1024 | /* P2P id, P2P length */ | |
1025 | len += 1 + 2; | |
1026 | copylen += 1 + 2; | |
1027 | ||
1028 | new_data = kmalloc(sizeof(*new_data) + len, GFP_ATOMIC); | |
1029 | if (new_data) { | |
1030 | new_data->length = len; | |
1031 | new_data->data[0] = WLAN_EID_VENDOR_SPECIFIC; | |
1032 | new_data->data[1] = len - 2; /* not counting EID, len */ | |
1033 | new_data->data[2] = (WLAN_OUI_WFA >> 16) & 0xff; | |
1034 | new_data->data[3] = (WLAN_OUI_WFA >> 8) & 0xff; | |
1035 | new_data->data[4] = (WLAN_OUI_WFA >> 0) & 0xff; | |
1036 | new_data->data[5] = WLAN_OUI_TYPE_WFA_P2P; | |
1037 | memcpy(&new_data->data[6], &noa_notif->noa_attribute, | |
1038 | copylen); | |
1039 | } | |
1040 | } else | |
1041 | new_data = NULL; | |
1042 | ||
1043 | rcu_assign_pointer(priv->noa_data, new_data); | |
1044 | ||
1045 | if (old_data) | |
1046 | kfree_rcu(old_data, rcu_head); | |
1047 | ||
1048 | return 0; | |
1049 | } | |
1050 | ||
466a19a0 SG |
1051 | /** |
1052 | * iwl_setup_rx_handlers - Initialize Rx handler callbacks | |
1053 | * | |
1054 | * Setup the RX handlers for each of the reply types sent from the uCode | |
1055 | * to the host. | |
1056 | */ | |
1057 | void iwl_setup_rx_handlers(struct iwl_priv *priv) | |
1058 | { | |
48a2d66f | 1059 | int (**handlers)(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 1060 | struct iwl_device_cmd *cmd); |
466a19a0 SG |
1061 | |
1062 | handlers = priv->rx_handlers; | |
1063 | ||
3246c4e6 WYG |
1064 | handlers[REPLY_ERROR] = iwlagn_rx_reply_error; |
1065 | handlers[CHANNEL_SWITCH_NOTIFICATION] = iwlagn_rx_csa; | |
1066 | handlers[SPECTRUM_MEASURE_NOTIFICATION] = | |
1067 | iwlagn_rx_spectrum_measure_notif; | |
1068 | handlers[PM_SLEEP_NOTIFICATION] = iwlagn_rx_pm_sleep_notif; | |
1069 | handlers[PM_DEBUG_STATISTIC_NOTIFIC] = | |
1070 | iwlagn_rx_pm_debug_statistics_notif; | |
1071 | handlers[BEACON_NOTIFICATION] = iwlagn_rx_beacon_notif; | |
247c61d6 | 1072 | handlers[REPLY_ADD_STA] = iwl_add_sta_callback; |
466a19a0 | 1073 | |
79d3eef8 JB |
1074 | handlers[REPLY_WIPAN_NOA_NOTIFICATION] = iwlagn_rx_noa_notification; |
1075 | ||
466a19a0 SG |
1076 | /* |
1077 | * The same handler is used for both the REPLY to a discrete | |
1078 | * statistics request from the host as well as for the periodic | |
1079 | * statistics notifications (after received beacons) from the uCode. | |
1080 | */ | |
3246c4e6 WYG |
1081 | handlers[REPLY_STATISTICS_CMD] = iwlagn_rx_reply_statistics; |
1082 | handlers[STATISTICS_NOTIFICATION] = iwlagn_rx_statistics; | |
466a19a0 SG |
1083 | |
1084 | iwl_setup_rx_scan_handlers(priv); | |
1085 | ||
3246c4e6 WYG |
1086 | handlers[CARD_STATE_NOTIFICATION] = iwlagn_rx_card_state_notif; |
1087 | handlers[MISSED_BEACONS_NOTIFICATION] = | |
1088 | iwlagn_rx_missed_beacon_notif; | |
466a19a0 SG |
1089 | |
1090 | /* Rx handlers */ | |
3246c4e6 WYG |
1091 | handlers[REPLY_RX_PHY_CMD] = iwlagn_rx_reply_rx_phy; |
1092 | handlers[REPLY_RX_MPDU_CMD] = iwlagn_rx_reply_rx; | |
466a19a0 SG |
1093 | |
1094 | /* block ack */ | |
3246c4e6 WYG |
1095 | handlers[REPLY_COMPRESSED_BA] = |
1096 | iwlagn_rx_reply_compressed_ba; | |
466a19a0 | 1097 | |
8d301193 EG |
1098 | priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx; |
1099 | ||
1100 | /* set up notification wait support */ | |
4bd14dd5 | 1101 | iwl_notification_wait_init(&priv->notif_wait); |
8d301193 EG |
1102 | |
1103 | /* Set up BT Rx handlers */ | |
0d8877a1 | 1104 | if (priv->lib->bt_params) |
562f08eb | 1105 | iwlagn_bt_rx_handler_setup(priv); |
466a19a0 | 1106 | } |
1ab9f6c1 | 1107 | |
48a2d66f JB |
1108 | int iwl_rx_dispatch(struct iwl_op_mode *op_mode, struct iwl_rx_cmd_buffer *rxb, |
1109 | struct iwl_device_cmd *cmd) | |
1ab9f6c1 EG |
1110 | { |
1111 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
db70f290 | 1112 | struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode); |
247c61d6 | 1113 | int err = 0; |
1ab9f6c1 EG |
1114 | |
1115 | /* | |
1116 | * Do the notification wait before RX handlers so | |
1117 | * even if the RX handler consumes the RXB we have | |
1118 | * access to it in the notification wait entry. | |
1119 | */ | |
4bd14dd5 | 1120 | iwl_notification_wait_notify(&priv->notif_wait, pkt); |
1ab9f6c1 | 1121 | |
49464ae5 JB |
1122 | /* Based on type of command response or notification, |
1123 | * handle those that need handling via function in | |
1124 | * rx_handlers table. See iwl_setup_rx_handlers() */ | |
1125 | if (priv->rx_handlers[pkt->hdr.cmd]) { | |
1126 | priv->rx_handlers_stats[pkt->hdr.cmd]++; | |
1127 | err = priv->rx_handlers[pkt->hdr.cmd] (priv, rxb, cmd); | |
1128 | } else { | |
1129 | /* No handling needed */ | |
1130 | IWL_DEBUG_RX(priv, "No handler needed for %s, 0x%02x\n", | |
1131 | iwl_dvm_get_cmd_string(pkt->hdr.cmd), | |
1132 | pkt->hdr.cmd); | |
1ab9f6c1 | 1133 | } |
247c61d6 | 1134 | return err; |
1ab9f6c1 | 1135 | } |