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