blob: 8b3a08958cc87ef2de5ea43371496196fe292bc2 [file] [log] [blame]
Tomas Winklera55360e2008-05-05 10:22:28 +08001/******************************************************************************
2 *
Wey-Yi Guy901069c2011-04-05 09:42:00 -07003 * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
Tomas Winklera55360e2008-05-05 10:22:28 +08004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions 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:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Tomas Winklera55360e2008-05-05 10:22:28 +080026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Emmanuel Grumbach1781a072008-06-30 17:23:09 +080030#include <linux/etherdevice.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090031#include <linux/slab.h>
Stanislaw Gruszka118253c2011-03-07 09:22:24 +010032#include <linux/sched.h>
Tomas Winklera55360e2008-05-05 10:22:28 +080033#include <net/mac80211.h>
Tomas Winklera05ffd32008-07-10 14:28:42 +030034#include <asm/unaligned.h>
Tomas Winklera55360e2008-05-05 10:22:28 +080035#include "iwl-eeprom.h"
36#include "iwl-dev.h"
37#include "iwl-core.h"
38#include "iwl-sta.h"
39#include "iwl-io.h"
40#include "iwl-helpers.h"
Stanislaw Gruszka67289942011-02-28 14:33:17 +010041#include "iwl-agn-calib.h"
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +010042#include "iwl-agn.h"
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -070043#include "iwl-shared.h"
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +010044
Tomas Winklera55360e2008-05-05 10:22:28 +080045
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +010046/******************************************************************************
47 *
48 * Generic RX handler implementations
49 *
50 ******************************************************************************/
51
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +010052static void iwl_rx_reply_error(struct iwl_priv *priv,
53 struct iwl_rx_mem_buffer *rxb)
54{
55 struct iwl_rx_packet *pkt = rxb_addr(rxb);
56
57 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
58 "seq 0x%04X ser 0x%08X\n",
59 le32_to_cpu(pkt->u.err_resp.error_type),
60 get_cmd_string(pkt->u.err_resp.cmd_id),
61 pkt->u.err_resp.cmd_id,
62 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
63 le32_to_cpu(pkt->u.err_resp.error_info));
64}
65
66static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
67{
68 struct iwl_rx_packet *pkt = rxb_addr(rxb);
69 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
70 /*
71 * MULTI-FIXME
72 * See iwl_mac_channel_switch.
73 */
74 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
75 struct iwl_rxon_cmd *rxon = (void *)&ctx->active;
76
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +020077 if (!test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
78 return;
79
80 if (!le32_to_cpu(csa->status) && csa->channel == priv->switch_channel) {
81 rxon->channel = csa->channel;
82 ctx->staging.channel = csa->channel;
83 IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +010084 le16_to_cpu(csa->channel));
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +020085 iwl_chswitch_done(priv, true);
86 } else {
87 IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
88 le16_to_cpu(csa->channel));
89 iwl_chswitch_done(priv, false);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +010090 }
91}
92
93
94static void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv,
Reinette Chatre81963d62010-01-22 14:22:57 -080095 struct iwl_rx_mem_buffer *rxb)
96{
97 struct iwl_rx_packet *pkt = rxb_addr(rxb);
98 struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
99
100 if (!report->state) {
101 IWL_DEBUG_11H(priv,
102 "Spectrum Measure Notification: Start\n");
103 return;
104 }
105
106 memcpy(&priv->measure_report, report, sizeof(*report));
107 priv->measurement_status |= MEASUREMENT_READY;
108}
Reinette Chatre81963d62010-01-22 14:22:57 -0800109
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100110static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
111 struct iwl_rx_mem_buffer *rxb)
112{
113#ifdef CONFIG_IWLWIFI_DEBUG
114 struct iwl_rx_packet *pkt = rxb_addr(rxb);
115 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
116 IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
117 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
118#endif
119}
120
121static void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
122 struct iwl_rx_mem_buffer *rxb)
123{
124 struct iwl_rx_packet *pkt = rxb_addr(rxb);
125 u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
126 IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
127 "notification for %s:\n", len,
128 get_cmd_string(pkt->hdr.cmd));
129 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
130}
131
132static void iwl_rx_beacon_notif(struct iwl_priv *priv,
133 struct iwl_rx_mem_buffer *rxb)
134{
135 struct iwl_rx_packet *pkt = rxb_addr(rxb);
136 struct iwlagn_beacon_notif *beacon = (void *)pkt->u.raw;
137#ifdef CONFIG_IWLWIFI_DEBUG
138 u16 status = le16_to_cpu(beacon->beacon_notify_hdr.status.status);
139 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
140
141 IWL_DEBUG_RX(priv, "beacon status %#x, retries:%d ibssmgr:%d "
142 "tsf:0x%.8x%.8x rate:%d\n",
143 status & TX_STATUS_MSK,
144 beacon->beacon_notify_hdr.failure_frame,
145 le32_to_cpu(beacon->ibss_mgr_status),
146 le32_to_cpu(beacon->high_tsf),
147 le32_to_cpu(beacon->low_tsf), rate);
148#endif
149
150 priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
151
152 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
153 queue_work(priv->workqueue, &priv->beacon_update);
154}
155
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100156/* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */
157#define ACK_CNT_RATIO (50)
158#define BA_TIMEOUT_CNT (5)
159#define BA_TIMEOUT_MAX (16)
160
161/**
162 * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries.
163 *
164 * When the ACK count ratio is low and aggregated BA timeout retries exceeding
165 * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal
166 * operation state.
167 */
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700168static bool iwl_good_ack_health(struct iwl_priv *priv,
169 struct statistics_tx *cur)
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100170{
171 int actual_delta, expected_delta, ba_timeout_delta;
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700172 struct statistics_tx *old;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100173
Wey-Yi Guy898ed672011-07-13 08:38:57 -0700174 if (priv->agg_tids_count)
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100175 return true;
176
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700177 old = &priv->statistics.tx;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100178
179 actual_delta = le32_to_cpu(cur->actual_ack_cnt) -
180 le32_to_cpu(old->actual_ack_cnt);
181 expected_delta = le32_to_cpu(cur->expected_ack_cnt) -
182 le32_to_cpu(old->expected_ack_cnt);
183
184 /* Values should not be negative, but we do not trust the firmware */
185 if (actual_delta <= 0 || expected_delta <= 0)
186 return true;
187
188 ba_timeout_delta = le32_to_cpu(cur->agg.ba_timeout) -
189 le32_to_cpu(old->agg.ba_timeout);
190
191 if ((actual_delta * 100 / expected_delta) < ACK_CNT_RATIO &&
192 ba_timeout_delta > BA_TIMEOUT_CNT) {
193 IWL_DEBUG_RADIO(priv, "deltas: actual %d expected %d ba_timeout %d\n",
194 actual_delta, expected_delta, ba_timeout_delta);
195
196#ifdef CONFIG_IWLWIFI_DEBUGFS
197 /*
198 * This is ifdef'ed on DEBUGFS because otherwise the
199 * statistics aren't available. If DEBUGFS is set but
200 * DEBUG is not, these will just compile out.
201 */
202 IWL_DEBUG_RADIO(priv, "rx_detected_cnt delta %d\n",
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700203 priv->delta_stats.tx.rx_detected_cnt);
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100204 IWL_DEBUG_RADIO(priv,
205 "ack_or_ba_timeout_collision delta %d\n",
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700206 priv->delta_stats.tx.ack_or_ba_timeout_collision);
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100207#endif
208
209 if (ba_timeout_delta >= BA_TIMEOUT_MAX)
210 return false;
211 }
212
213 return true;
214}
215
216/**
217 * iwl_good_plcp_health - checks for plcp error.
218 *
219 * When the plcp error is exceeding the thresholds, reset the radio
220 * to improve the throughput.
221 */
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100222static bool iwl_good_plcp_health(struct iwl_priv *priv,
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700223 struct statistics_rx_phy *cur_ofdm,
224 struct statistics_rx_ht_phy *cur_ofdm_ht,
225 unsigned int msecs)
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100226{
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100227 int delta;
228 int threshold = priv->cfg->base_params->plcp_delta_threshold;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100229
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100230 if (threshold == IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) {
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100231 IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n");
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100232 return true;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100233 }
234
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700235 delta = le32_to_cpu(cur_ofdm->plcp_err) -
236 le32_to_cpu(priv->statistics.rx_ofdm.plcp_err) +
237 le32_to_cpu(cur_ofdm_ht->plcp_err) -
238 le32_to_cpu(priv->statistics.rx_ofdm_ht.plcp_err);
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100239
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700240 /* Can be negative if firmware reset statistics */
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100241 if (delta <= 0)
242 return true;
243
244 if ((delta * 100 / msecs) > threshold) {
245 IWL_DEBUG_RADIO(priv,
246 "plcp health threshold %u delta %d msecs %u\n",
247 threshold, delta, msecs);
248 return false;
249 }
250
251 return true;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100252}
253
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100254static void iwl_recover_from_statistics(struct iwl_priv *priv,
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700255 struct statistics_rx_phy *cur_ofdm,
256 struct statistics_rx_ht_phy *cur_ofdm_ht,
257 struct statistics_tx *tx,
258 unsigned long stamp)
Wey-Yi Guyfa8f130c2010-03-05 14:22:46 -0800259{
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100260 unsigned int msecs;
Stanislaw Gruszkab7977ff2011-02-28 14:33:15 +0100261
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100262 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
263 return;
264
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100265 msecs = jiffies_to_msecs(stamp - priv->rx_statistics_jiffies);
266
267 /* Only gather statistics and update time stamp when not associated */
268 if (!iwl_is_any_associated(priv))
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700269 return;
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100270
271 /* Do not check/recover when do not have enough statistics data */
272 if (msecs < 99)
Wey-Yi Guyfa8f130c2010-03-05 14:22:46 -0800273 return;
Stanislaw Gruszkaca3d9382011-02-08 09:31:55 +0100274
Don Fry9d143e92011-04-20 15:23:57 -0700275 if (iwlagn_mod_params.ack_check && !iwl_good_ack_health(priv, tx)) {
Stanislaw Gruszkaca3d9382011-02-08 09:31:55 +0100276 IWL_ERR(priv, "low ack count detected, restart firmware\n");
277 if (!iwl_force_reset(priv, IWL_FW_RESET, false))
278 return;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -0800279 }
Stanislaw Gruszkaca3d9382011-02-08 09:31:55 +0100280
Don Fry9d143e92011-04-20 15:23:57 -0700281 if (iwlagn_mod_params.plcp_check &&
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700282 !iwl_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs))
Stanislaw Gruszkaca3d9382011-02-08 09:31:55 +0100283 iwl_force_reset(priv, IWL_RF_RESET, false);
Wey-Yi Guybeac5492010-03-04 13:38:58 -0800284}
Wey-Yi Guybeac5492010-03-04 13:38:58 -0800285
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100286/* Calculate noise level, based on measurements during network silence just
287 * before arriving beacon. This measurement can be done only if we know
288 * exactly when to expect beacons, therefore only when we're associated. */
289static void iwl_rx_calc_noise(struct iwl_priv *priv)
290{
291 struct statistics_rx_non_phy *rx_info;
292 int num_active_rx = 0;
293 int total_silence = 0;
294 int bcn_silence_a, bcn_silence_b, bcn_silence_c;
295 int last_rx_noise;
296
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700297 rx_info = &priv->statistics.rx_non_phy;
298
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100299 bcn_silence_a =
300 le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
301 bcn_silence_b =
302 le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
303 bcn_silence_c =
304 le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
305
306 if (bcn_silence_a) {
307 total_silence += bcn_silence_a;
308 num_active_rx++;
309 }
310 if (bcn_silence_b) {
311 total_silence += bcn_silence_b;
312 num_active_rx++;
313 }
314 if (bcn_silence_c) {
315 total_silence += bcn_silence_c;
316 num_active_rx++;
317 }
318
319 /* Average among active antennas */
320 if (num_active_rx)
321 last_rx_noise = (total_silence / num_active_rx) - 107;
322 else
323 last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
324
325 IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n",
326 bcn_silence_a, bcn_silence_b, bcn_silence_c,
327 last_rx_noise);
328}
329
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700330#ifdef CONFIG_IWLWIFI_DEBUGFS
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100331/*
332 * based on the assumption of all statistics counter are in DWORD
333 * FIXME: This function is for debugging, do not deal with
334 * the case of counters roll-over.
335 */
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700336static void accum_stats(__le32 *prev, __le32 *cur, __le32 *delta,
337 __le32 *max_delta, __le32 *accum, int size)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100338{
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700339 int i;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100340
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700341 for (i = 0;
342 i < size / sizeof(__le32);
343 i++, prev++, cur++, delta++, max_delta++, accum++) {
344 if (le32_to_cpu(*cur) > le32_to_cpu(*prev)) {
345 *delta = cpu_to_le32(
346 le32_to_cpu(*cur) - le32_to_cpu(*prev));
347 le32_add_cpu(accum, le32_to_cpu(*delta));
348 if (le32_to_cpu(*delta) > le32_to_cpu(*max_delta))
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100349 *max_delta = *delta;
350 }
351 }
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100352}
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100353
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700354static void
355iwl_accumulative_statistics(struct iwl_priv *priv,
356 struct statistics_general_common *common,
357 struct statistics_rx_non_phy *rx_non_phy,
358 struct statistics_rx_phy *rx_ofdm,
359 struct statistics_rx_ht_phy *rx_ofdm_ht,
360 struct statistics_rx_phy *rx_cck,
361 struct statistics_tx *tx,
362 struct statistics_bt_activity *bt_activity)
363{
364#define ACCUM(_name) \
365 accum_stats((__le32 *)&priv->statistics._name, \
366 (__le32 *)_name, \
367 (__le32 *)&priv->delta_stats._name, \
368 (__le32 *)&priv->max_delta_stats._name, \
369 (__le32 *)&priv->accum_stats._name, \
370 sizeof(*_name));
371
372 ACCUM(common);
373 ACCUM(rx_non_phy);
374 ACCUM(rx_ofdm);
375 ACCUM(rx_ofdm_ht);
376 ACCUM(rx_cck);
377 ACCUM(tx);
378 if (bt_activity)
379 ACCUM(bt_activity);
380#undef ACCUM
381}
382#else
383static inline void
384iwl_accumulative_statistics(struct iwl_priv *priv,
385 struct statistics_general_common *common,
386 struct statistics_rx_non_phy *rx_non_phy,
387 struct statistics_rx_phy *rx_ofdm,
388 struct statistics_rx_ht_phy *rx_ofdm_ht,
389 struct statistics_rx_phy *rx_cck,
390 struct statistics_tx *tx,
391 struct statistics_bt_activity *bt_activity)
392{
393}
394#endif
395
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100396static void iwl_rx_statistics(struct iwl_priv *priv,
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100397 struct iwl_rx_mem_buffer *rxb)
398{
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700399 unsigned long stamp = jiffies;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100400 const int reg_recalib_period = 60;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100401 int change;
402 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700403 u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
404 __le32 *flag;
405 struct statistics_general_common *common;
406 struct statistics_rx_non_phy *rx_non_phy;
407 struct statistics_rx_phy *rx_ofdm;
408 struct statistics_rx_ht_phy *rx_ofdm_ht;
409 struct statistics_rx_phy *rx_cck;
410 struct statistics_tx *tx;
411 struct statistics_bt_activity *bt_activity;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100412
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700413 len -= sizeof(struct iwl_cmd_header); /* skip header */
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100414
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700415 IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n",
416 len);
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100417
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700418 if (len == sizeof(struct iwl_bt_notif_statistics)) {
419 struct iwl_bt_notif_statistics *stats;
420 stats = &pkt->u.stats_bt;
421 flag = &stats->flag;
422 common = &stats->general.common;
423 rx_non_phy = &stats->rx.general.common;
424 rx_ofdm = &stats->rx.ofdm;
425 rx_ofdm_ht = &stats->rx.ofdm_ht;
426 rx_cck = &stats->rx.cck;
427 tx = &stats->tx;
428 bt_activity = &stats->general.activity;
429
430#ifdef CONFIG_IWLWIFI_DEBUGFS
431 /* handle this exception directly */
432 priv->statistics.num_bt_kills = stats->rx.general.num_bt_kills;
433 le32_add_cpu(&priv->statistics.accum_num_bt_kills,
434 le32_to_cpu(stats->rx.general.num_bt_kills));
435#endif
436 } else if (len == sizeof(struct iwl_notif_statistics)) {
437 struct iwl_notif_statistics *stats;
438 stats = &pkt->u.stats;
439 flag = &stats->flag;
440 common = &stats->general.common;
441 rx_non_phy = &stats->rx.general;
442 rx_ofdm = &stats->rx.ofdm;
443 rx_ofdm_ht = &stats->rx.ofdm_ht;
444 rx_cck = &stats->rx.cck;
445 tx = &stats->tx;
446 bt_activity = NULL;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100447 } else {
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700448 WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n",
449 len, sizeof(struct iwl_bt_notif_statistics),
450 sizeof(struct iwl_notif_statistics));
451 return;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100452 }
453
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700454 change = common->temperature != priv->statistics.common.temperature ||
455 (*flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
456 (priv->statistics.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK);
457
458 iwl_accumulative_statistics(priv, common, rx_non_phy, rx_ofdm,
459 rx_ofdm_ht, rx_cck, tx, bt_activity);
460
461 iwl_recover_from_statistics(priv, rx_ofdm, rx_ofdm_ht, tx, stamp);
462
463 priv->statistics.flag = *flag;
464 memcpy(&priv->statistics.common, common, sizeof(*common));
465 memcpy(&priv->statistics.rx_non_phy, rx_non_phy, sizeof(*rx_non_phy));
466 memcpy(&priv->statistics.rx_ofdm, rx_ofdm, sizeof(*rx_ofdm));
467 memcpy(&priv->statistics.rx_ofdm_ht, rx_ofdm_ht, sizeof(*rx_ofdm_ht));
468 memcpy(&priv->statistics.rx_cck, rx_cck, sizeof(*rx_cck));
469 memcpy(&priv->statistics.tx, tx, sizeof(*tx));
470#ifdef CONFIG_IWLWIFI_DEBUGFS
471 if (bt_activity)
472 memcpy(&priv->statistics.bt_activity, bt_activity,
473 sizeof(*bt_activity));
474#endif
475
476 priv->rx_statistics_jiffies = stamp;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100477
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100478 set_bit(STATUS_STATISTICS, &priv->status);
479
480 /* Reschedule the statistics timer to occur in
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100481 * reg_recalib_period seconds to ensure we get a
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100482 * thermal update even if the uCode doesn't give
483 * us one */
484 mod_timer(&priv->statistics_periodic, jiffies +
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100485 msecs_to_jiffies(reg_recalib_period * 1000));
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100486
487 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
488 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
489 iwl_rx_calc_noise(priv);
490 queue_work(priv->workqueue, &priv->run_time_calib_work);
491 }
Wey-Yi Guy90c300c2011-07-07 08:33:01 -0700492 if (priv->cfg->lib->temperature && change)
493 priv->cfg->lib->temperature(priv);
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100494}
495
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100496static void iwl_rx_reply_statistics(struct iwl_priv *priv,
497 struct iwl_rx_mem_buffer *rxb)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100498{
499 struct iwl_rx_packet *pkt = rxb_addr(rxb);
500
501 if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) {
502#ifdef CONFIG_IWLWIFI_DEBUGFS
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700503 memset(&priv->accum_stats, 0,
504 sizeof(priv->accum_stats));
505 memset(&priv->delta_stats, 0,
506 sizeof(priv->delta_stats));
507 memset(&priv->max_delta_stats, 0,
508 sizeof(priv->max_delta_stats));
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100509#endif
510 IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
511 }
512 iwl_rx_statistics(priv, rxb);
513}
514
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100515/* Handle notification from uCode that card's power state is changing
516 * due to software, hardware, or critical temperature RFKILL */
517static void iwl_rx_card_state_notif(struct iwl_priv *priv,
518 struct iwl_rx_mem_buffer *rxb)
519{
520 struct iwl_rx_packet *pkt = rxb_addr(rxb);
521 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
522 unsigned long status = priv->status;
523
524 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n",
525 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
526 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
527 (flags & CT_CARD_DISABLED) ?
528 "Reached" : "Not reached");
529
530 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
531 CT_CARD_DISABLED)) {
532
533 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
534 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
535
536 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
537 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
538
539 if (!(flags & RXON_CARD_DISABLED)) {
540 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
541 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
542 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
543 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
544 }
545 if (flags & CT_CARD_DISABLED)
546 iwl_tt_enter_ct_kill(priv);
547 }
548 if (!(flags & CT_CARD_DISABLED))
549 iwl_tt_exit_ct_kill(priv);
550
551 if (flags & HW_CARD_DISABLED)
552 set_bit(STATUS_RF_KILL_HW, &priv->status);
553 else
554 clear_bit(STATUS_RF_KILL_HW, &priv->status);
555
556
557 if (!(flags & RXON_CARD_DISABLED))
558 iwl_scan_cancel(priv);
559
560 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
561 test_bit(STATUS_RF_KILL_HW, &priv->status)))
562 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
563 test_bit(STATUS_RF_KILL_HW, &priv->status));
564 else
565 wake_up_interruptible(&priv->wait_command_queue);
566}
567
568static void iwl_rx_missed_beacon_notif(struct iwl_priv *priv,
569 struct iwl_rx_mem_buffer *rxb)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100570
571{
572 struct iwl_rx_packet *pkt = rxb_addr(rxb);
573 struct iwl_missed_beacon_notif *missed_beacon;
574
575 missed_beacon = &pkt->u.missed_beacon;
576 if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) >
577 priv->missed_beacon_threshold) {
578 IWL_DEBUG_CALIB(priv,
579 "missed bcn cnsq %d totl %d rcd %d expctd %d\n",
580 le32_to_cpu(missed_beacon->consecutive_missed_beacons),
581 le32_to_cpu(missed_beacon->total_missed_becons),
582 le32_to_cpu(missed_beacon->num_recvd_beacons),
583 le32_to_cpu(missed_beacon->num_expected_beacons));
584 if (!test_bit(STATUS_SCANNING, &priv->status))
585 iwl_init_sensitivity(priv);
586 }
587}
588
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100589/* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
590 * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
591static void iwl_rx_reply_rx_phy(struct iwl_priv *priv,
592 struct iwl_rx_mem_buffer *rxb)
593{
594 struct iwl_rx_packet *pkt = rxb_addr(rxb);
595
Wey-Yi Guy898ed672011-07-13 08:38:57 -0700596 priv->last_phy_res_valid = true;
597 memcpy(&priv->last_phy_res, pkt->u.raw,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100598 sizeof(struct iwl_rx_phy_res));
599}
600
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800601/*
602 * returns non-zero if packet should be dropped
603 */
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100604static int iwl_set_decrypted_flag(struct iwl_priv *priv,
605 struct ieee80211_hdr *hdr,
606 u32 decrypt_res,
607 struct ieee80211_rx_status *stats)
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800608{
609 u16 fc = le16_to_cpu(hdr->frame_control);
610
Johannes Berg246ed352010-08-23 10:46:32 +0200611 /*
612 * All contexts have the same setting here due to it being
613 * a module parameter, so OK to check any context.
614 */
615 if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags &
616 RXON_FILTER_DIS_DECRYPT_MSK)
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800617 return 0;
618
619 if (!(fc & IEEE80211_FCTL_PROTECTED))
620 return 0;
621
Tomas Winklere1623442009-01-27 14:27:56 -0800622 IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res);
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800623 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
624 case RX_RES_STATUS_SEC_TYPE_TKIP:
625 /* The uCode has got a bad phase 1 Key, pushes the packet.
626 * Decryption will be done in SW. */
627 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
628 RX_RES_STATUS_BAD_KEY_TTAK)
629 break;
630
631 case RX_RES_STATUS_SEC_TYPE_WEP:
632 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
633 RX_RES_STATUS_BAD_ICV_MIC) {
634 /* bad ICV, the packet is destroyed since the
635 * decryption is inplace, drop it */
Tomas Winklere1623442009-01-27 14:27:56 -0800636 IWL_DEBUG_RX(priv, "Packet destroyed\n");
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800637 return -1;
638 }
639 case RX_RES_STATUS_SEC_TYPE_CCMP:
640 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
641 RX_RES_STATUS_DECRYPT_OK) {
Tomas Winklere1623442009-01-27 14:27:56 -0800642 IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n");
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800643 stats->flag |= RX_FLAG_DECRYPTED;
644 }
645 break;
646
647 default:
648 break;
649 }
650 return 0;
651}
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100652
653static void iwl_pass_packet_to_mac80211(struct iwl_priv *priv,
654 struct ieee80211_hdr *hdr,
655 u16 len,
656 u32 ampdu_status,
657 struct iwl_rx_mem_buffer *rxb,
658 struct ieee80211_rx_status *stats)
659{
660 struct sk_buff *skb;
661 __le16 fc = hdr->frame_control;
Garen Tamrazian68b99312011-03-30 02:29:32 -0700662 struct iwl_rxon_context *ctx;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100663
664 /* We only process data packets if the interface is open */
665 if (unlikely(!priv->is_open)) {
666 IWL_DEBUG_DROP_LIMIT(priv,
667 "Dropping packet while interface is not open.\n");
668 return;
669 }
670
671 /* In case of HW accelerated crypto and bad decryption, drop */
Don Fry9d143e92011-04-20 15:23:57 -0700672 if (!iwlagn_mod_params.sw_crypto &&
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100673 iwl_set_decrypted_flag(priv, hdr, ampdu_status, stats))
674 return;
675
676 skb = dev_alloc_skb(128);
677 if (!skb) {
678 IWL_ERR(priv, "dev_alloc_skb failed\n");
679 return;
680 }
681
682 skb_add_rx_frag(skb, 0, rxb->page, (void *)hdr - rxb_addr(rxb), len);
683
684 iwl_update_stats(priv, false, fc, len);
Garen Tamrazian68b99312011-03-30 02:29:32 -0700685
686 /*
687 * Wake any queues that were stopped due to a passive channel tx
688 * failure. This can happen because the regulatory enforcement in
689 * the device waits for a beacon before allowing transmission,
690 * sometimes even after already having transmitted frames for the
691 * association because the new RXON may reset the information.
692 */
693 if (unlikely(ieee80211_is_beacon(fc))) {
694 for_each_context(priv, ctx) {
695 if (!ctx->last_tx_rejected)
696 continue;
697 if (compare_ether_addr(hdr->addr3,
698 ctx->active.bssid_addr))
699 continue;
700 ctx->last_tx_rejected = false;
701 iwl_wake_any_queue(priv, ctx);
702 }
703 }
704
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100705 memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
706
707 ieee80211_rx(priv->hw, skb);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100708 rxb->page = NULL;
709}
710
711static u32 iwl_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
712{
713 u32 decrypt_out = 0;
714
715 if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
716 RX_RES_STATUS_STATION_FOUND)
717 decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
718 RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
719
720 decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
721
722 /* packet was not encrypted */
723 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
724 RX_RES_STATUS_SEC_TYPE_NONE)
725 return decrypt_out;
726
727 /* packet was encrypted with unknown alg */
728 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
729 RX_RES_STATUS_SEC_TYPE_ERR)
730 return decrypt_out;
731
732 /* decryption was not done in HW */
733 if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
734 RX_MPDU_RES_STATUS_DEC_DONE_MSK)
735 return decrypt_out;
736
737 switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
738
739 case RX_RES_STATUS_SEC_TYPE_CCMP:
740 /* alg is CCM: check MIC only */
741 if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
742 /* Bad MIC */
743 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
744 else
745 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
746
747 break;
748
749 case RX_RES_STATUS_SEC_TYPE_TKIP:
750 if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
751 /* Bad TTAK */
752 decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
753 break;
754 }
755 /* fall through if TTAK OK */
756 default:
757 if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
758 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
759 else
760 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
761 break;
762 }
763
764 IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n",
765 decrypt_in, decrypt_out);
766
767 return decrypt_out;
768}
769
Don Fry5c3d29f2011-07-08 08:46:29 -0700770/* Calc max signal level (dBm) among 3 possible receivers */
771static int iwlagn_calc_rssi(struct iwl_priv *priv,
772 struct iwl_rx_phy_res *rx_resp)
773{
774 /* data from PHY/DSP regarding signal strength, etc.,
775 * contents are always there, not configurable by host
776 */
777 struct iwlagn_non_cfg_phy *ncphy =
778 (struct iwlagn_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
779 u32 val, rssi_a, rssi_b, rssi_c, max_rssi;
780 u8 agc;
781
782 val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_AGC_IDX]);
783 agc = (val & IWLAGN_OFDM_AGC_MSK) >> IWLAGN_OFDM_AGC_BIT_POS;
784
785 /* Find max rssi among 3 possible receivers.
786 * These values are measured by the digital signal processor (DSP).
787 * They should stay fairly constant even as the signal strength varies,
788 * if the radio's automatic gain control (AGC) is working right.
789 * AGC value (see below) will provide the "interesting" info.
790 */
791 val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_AB_IDX]);
792 rssi_a = (val & IWLAGN_OFDM_RSSI_INBAND_A_BITMSK) >>
793 IWLAGN_OFDM_RSSI_A_BIT_POS;
794 rssi_b = (val & IWLAGN_OFDM_RSSI_INBAND_B_BITMSK) >>
795 IWLAGN_OFDM_RSSI_B_BIT_POS;
796 val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_C_IDX]);
797 rssi_c = (val & IWLAGN_OFDM_RSSI_INBAND_C_BITMSK) >>
798 IWLAGN_OFDM_RSSI_C_BIT_POS;
799
800 max_rssi = max_t(u32, rssi_a, rssi_b);
801 max_rssi = max_t(u32, max_rssi, rssi_c);
802
803 IWL_DEBUG_STATS(priv, "Rssi In A %d B %d C %d Max %d AGC dB %d\n",
804 rssi_a, rssi_b, rssi_c, max_rssi, agc);
805
806 /* dBm = max_rssi dB - agc dB - constant.
807 * Higher AGC (higher radio gain) means lower signal. */
808 return max_rssi - agc - IWLAGN_RSSI_OFFSET;
809}
810
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100811/* Called for REPLY_RX (legacy ABG frames), or
812 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
813static void iwl_rx_reply_rx(struct iwl_priv *priv,
814 struct iwl_rx_mem_buffer *rxb)
815{
816 struct ieee80211_hdr *header;
817 struct ieee80211_rx_status rx_status;
818 struct iwl_rx_packet *pkt = rxb_addr(rxb);
819 struct iwl_rx_phy_res *phy_res;
820 __le32 rx_pkt_status;
821 struct iwl_rx_mpdu_res_start *amsdu;
822 u32 len;
823 u32 ampdu_status;
824 u32 rate_n_flags;
825
826 /**
827 * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently.
828 * REPLY_RX: physical layer info is in this buffer
829 * REPLY_RX_MPDU_CMD: physical layer info was sent in separate
830 * command and cached in priv->last_phy_res
831 *
832 * Here we set up local variables depending on which command is
833 * received.
834 */
835 if (pkt->hdr.cmd == REPLY_RX) {
836 phy_res = (struct iwl_rx_phy_res *)pkt->u.raw;
837 header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res)
838 + phy_res->cfg_phy_cnt);
839
840 len = le16_to_cpu(phy_res->byte_count);
841 rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*phy_res) +
842 phy_res->cfg_phy_cnt + len);
843 ampdu_status = le32_to_cpu(rx_pkt_status);
844 } else {
Wey-Yi Guy898ed672011-07-13 08:38:57 -0700845 if (!priv->last_phy_res_valid) {
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100846 IWL_ERR(priv, "MPDU frame without cached PHY data\n");
847 return;
848 }
Wey-Yi Guy898ed672011-07-13 08:38:57 -0700849 phy_res = &priv->last_phy_res;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100850 amsdu = (struct iwl_rx_mpdu_res_start *)pkt->u.raw;
851 header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu));
852 len = le16_to_cpu(amsdu->byte_count);
853 rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*amsdu) + len);
854 ampdu_status = iwl_translate_rx_status(priv,
855 le32_to_cpu(rx_pkt_status));
856 }
857
858 if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
859 IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d/n",
860 phy_res->cfg_phy_cnt);
861 return;
862 }
863
864 if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
865 !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
866 IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n",
867 le32_to_cpu(rx_pkt_status));
868 return;
869 }
870
871 /* This will be used in several places later */
872 rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
873
874 /* rx_status carries information about the packet to mac80211 */
875 rx_status.mactime = le64_to_cpu(phy_res->timestamp);
876 rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
877 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
878 rx_status.freq =
879 ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel),
880 rx_status.band);
881 rx_status.rate_idx =
882 iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
883 rx_status.flag = 0;
884
885 /* TSF isn't reliable. In order to allow smooth user experience,
886 * this W/A doesn't propagate it to the mac80211 */
887 /*rx_status.flag |= RX_FLAG_MACTIME_MPDU;*/
888
889 priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
890
891 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
Don Fry5c3d29f2011-07-08 08:46:29 -0700892 rx_status.signal = iwlagn_calc_rssi(priv, phy_res);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100893
894 iwl_dbg_log_rx_data_frame(priv, len, header);
895 IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n",
896 rx_status.signal, (unsigned long long)rx_status.mactime);
897
898 /*
899 * "antenna number"
900 *
901 * It seems that the antenna field in the phy flags value
902 * is actually a bit field. This is undefined by radiotap,
903 * it wants an actual antenna number but I always get "7"
904 * for most legacy frames I receive indicating that the
905 * same frame was received on all three RX chains.
906 *
907 * I think this field should be removed in favor of a
908 * new 802.11n radiotap field "RX chains" that is defined
909 * as a bitmask.
910 */
911 rx_status.antenna =
912 (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK)
913 >> RX_RES_PHY_FLAGS_ANTENNA_POS;
914
915 /* set the preamble flag if appropriate */
916 if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
917 rx_status.flag |= RX_FLAG_SHORTPRE;
918
919 /* Set up the HT phy flags */
920 if (rate_n_flags & RATE_MCS_HT_MSK)
921 rx_status.flag |= RX_FLAG_HT;
922 if (rate_n_flags & RATE_MCS_HT40_MSK)
923 rx_status.flag |= RX_FLAG_40MHZ;
924 if (rate_n_flags & RATE_MCS_SGI_MSK)
925 rx_status.flag |= RX_FLAG_SHORT_GI;
926
927 iwl_pass_packet_to_mac80211(priv, header, len, ampdu_status,
928 rxb, &rx_status);
929}
930
931/**
932 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
933 *
934 * Setup the RX handlers for each of the reply types sent from the uCode
935 * to the host.
936 */
937void iwl_setup_rx_handlers(struct iwl_priv *priv)
938{
939 void (**handlers)(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb);
940
941 handlers = priv->rx_handlers;
942
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100943 handlers[REPLY_ERROR] = iwl_rx_reply_error;
944 handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
945 handlers[SPECTRUM_MEASURE_NOTIFICATION] = iwl_rx_spectrum_measure_notif;
946 handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
947 handlers[PM_DEBUG_STATISTIC_NOTIFIC] = iwl_rx_pm_debug_statistics_notif;
948 handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
949
950 /*
951 * The same handler is used for both the REPLY to a discrete
952 * statistics request from the host as well as for the periodic
953 * statistics notifications (after received beacons) from the uCode.
954 */
955 handlers[REPLY_STATISTICS_CMD] = iwl_rx_reply_statistics;
956 handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
957
958 iwl_setup_rx_scan_handlers(priv);
959
960 handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
961 handlers[MISSED_BEACONS_NOTIFICATION] = iwl_rx_missed_beacon_notif;
962
963 /* Rx handlers */
964 handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
965 handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
966
967 /* block ack */
968 handlers[REPLY_COMPRESSED_BA] = iwlagn_rx_reply_compressed_ba;
969
Emmanuel Grumbach8d301192011-07-03 15:45:34 +0300970 /* init calibration handlers */
971 priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
972 iwlagn_rx_calib_result;
973 priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx;
974
975 /* set up notification wait support */
Wey-Yi Guy898ed672011-07-13 08:38:57 -0700976 spin_lock_init(&priv->notif_wait_lock);
977 INIT_LIST_HEAD(&priv->notif_waits);
978 init_waitqueue_head(&priv->notif_waitq);
Emmanuel Grumbach8d301192011-07-03 15:45:34 +0300979
980 /* Set up BT Rx handlers */
981 if (priv->cfg->lib->bt_rx_handler_setup)
982 priv->cfg->lib->bt_rx_handler_setup(priv);
983
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100984}
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -0700985
986void iwl_rx_dispatch(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
987{
988 struct iwl_rx_packet *pkt = rxb_addr(rxb);
989
990 /*
991 * Do the notification wait before RX handlers so
992 * even if the RX handler consumes the RXB we have
993 * access to it in the notification wait entry.
994 */
Wey-Yi Guy898ed672011-07-13 08:38:57 -0700995 if (!list_empty(&priv->notif_waits)) {
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -0700996 struct iwl_notification_wait *w;
997
Wey-Yi Guy898ed672011-07-13 08:38:57 -0700998 spin_lock(&priv->notif_wait_lock);
999 list_for_each_entry(w, &priv->notif_waits, list) {
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001000 if (w->cmd != pkt->hdr.cmd)
1001 continue;
1002 IWL_DEBUG_RX(priv,
1003 "Notif: %s, 0x%02x - wake the callers up\n",
1004 get_cmd_string(pkt->hdr.cmd),
1005 pkt->hdr.cmd);
1006 w->triggered = true;
1007 if (w->fn)
1008 w->fn(priv, pkt, w->fn_data);
1009 }
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001010 spin_unlock(&priv->notif_wait_lock);
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001011
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001012 wake_up_all(&priv->notif_waitq);
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001013 }
1014
1015 if (priv->pre_rx_handler)
1016 priv->pre_rx_handler(priv, rxb);
1017
1018 /* Based on type of command response or notification,
1019 * handle those that need handling via function in
1020 * rx_handlers table. See iwl_setup_rx_handlers() */
1021 if (priv->rx_handlers[pkt->hdr.cmd]) {
1022 priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
1023 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1024 } else {
1025 /* No handling needed */
1026 IWL_DEBUG_RX(priv,
1027 "No handler needed for %s, 0x%02x\n",
1028 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1029 }
1030}