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