blob: 065d2c02655fa916e002997b1c0c84243f8ab351 [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"
43
44/******************************************************************************
45 *
46 * RX path functions
47 *
48 ******************************************************************************/
49
Tomas Winklera55360e2008-05-05 10:22:28 +080050/*
51 * Rx theory of operation
52 *
53 * Driver allocates a circular buffer of Receive Buffer Descriptors (RBDs),
54 * each of which point to Receive Buffers to be filled by the NIC. These get
55 * used not only for Rx frames, but for any command response or notification
56 * from the NIC. The driver and NIC manage the Rx buffers by means
57 * of indexes into the circular buffer.
58 *
59 * Rx Queue Indexes
60 * The host/firmware share two index registers for managing the Rx buffers.
61 *
62 * The READ index maps to the first position that the firmware may be writing
63 * to -- the driver can read up to (but not including) this position and get
64 * good data.
65 * The READ index is managed by the firmware once the card is enabled.
66 *
67 * The WRITE index maps to the last position the driver has read from -- the
68 * position preceding WRITE is the last slot the firmware can place a packet.
69 *
70 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
71 * WRITE = READ.
72 *
73 * During initialization, the host sets up the READ queue position to the first
74 * INDEX position, and WRITE to the last (READ - 1 wrapped)
75 *
76 * When the firmware places a packet in a buffer, it will advance the READ index
77 * and fire the RX interrupt. The driver can then query the READ index and
78 * process as many packets as possible, moving the WRITE index forward as it
79 * resets the Rx queue buffers with new memory.
80 *
81 * The management in the driver is as follows:
82 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
83 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
84 * to replenish the iwl->rxq->rx_free.
85 * + In iwl_rx_replenish (scheduled) if 'processed' != 'read' then the
86 * iwl->rxq is replenished and the READ INDEX is updated (updating the
87 * 'processed' and 'read' driver indexes as well)
88 * + A received packet is processed and handed to the kernel network stack,
89 * detached from the iwl->rxq. The driver 'processed' index is updated.
90 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
91 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
92 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
93 * were enough free buffers and RX_STALLED is set it is cleared.
94 *
95 *
96 * Driver sequence:
97 *
98 * iwl_rx_queue_alloc() Allocates rx_free
99 * iwl_rx_replenish() Replenishes rx_free list from rx_used, and calls
100 * iwl_rx_queue_restock
101 * iwl_rx_queue_restock() Moves available buffers from rx_free into Rx
102 * queue, updates firmware pointers, and updates
103 * the WRITE index. If insufficient rx_free buffers
104 * are available, schedules iwl_rx_replenish
105 *
106 * -- enable interrupts --
107 * ISR - iwl_rx() Detach iwl_rx_mem_buffers from pool up to the
108 * READ INDEX, detaching the SKB from the pool.
109 * Moves the packet buffer from queue to rx_used.
110 * Calls iwl_rx_queue_restock to refill any empty
111 * slots.
112 * ...
113 *
114 */
115
116/**
117 * iwl_rx_queue_space - Return number of free slots available in queue.
118 */
119int iwl_rx_queue_space(const struct iwl_rx_queue *q)
120{
121 int s = q->read - q->write;
122 if (s <= 0)
123 s += RX_QUEUE_SIZE;
124 /* keep some buffer to not confuse full and empty queue */
125 s -= 2;
126 if (s < 0)
127 s = 0;
128 return s;
129}
Tomas Winklera55360e2008-05-05 10:22:28 +0800130
131/**
132 * iwl_rx_queue_update_write_ptr - Update the write pointer for the RX queue
133 */
Abhijeet Kolekar7bfedc52010-02-03 13:47:56 -0800134void iwl_rx_queue_update_write_ptr(struct iwl_priv *priv, struct iwl_rx_queue *q)
Tomas Winklera55360e2008-05-05 10:22:28 +0800135{
Tomas Winklera55360e2008-05-05 10:22:28 +0800136 unsigned long flags;
Winkler, Tomas141c43a2009-01-08 10:19:53 -0800137 u32 rx_wrt_ptr_reg = priv->hw_params.rx_wrt_ptr_reg;
138 u32 reg;
Tomas Winklera55360e2008-05-05 10:22:28 +0800139
140 spin_lock_irqsave(&q->lock, flags);
141
142 if (q->need_update == 0)
143 goto exit_unlock;
144
Wey-Yi Guyf81c1f42010-11-10 09:56:50 -0800145 if (priv->cfg->base_params->shadow_reg_enable) {
146 /* shadow register enabled */
Tomas Winklera55360e2008-05-05 10:22:28 +0800147 /* Device expects a multiple of 8 */
Mohamed Abbas4752c932009-05-22 11:01:51 -0700148 q->write_actual = (q->write & ~0x7);
Winkler, Tomasfd117432010-11-10 09:56:42 -0800149 iwl_write32(priv, rx_wrt_ptr_reg, q->write_actual);
Wey-Yi Guyf81c1f42010-11-10 09:56:50 -0800150 } else {
151 /* If power-saving is in use, make sure device is awake */
152 if (test_bit(STATUS_POWER_PMI, &priv->status)) {
153 reg = iwl_read32(priv, CSR_UCODE_DRV_GP1);
Tomas Winklera55360e2008-05-05 10:22:28 +0800154
Wey-Yi Guyf81c1f42010-11-10 09:56:50 -0800155 if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
156 IWL_DEBUG_INFO(priv,
157 "Rx queue requesting wakeup,"
158 " GP1 = 0x%x\n", reg);
159 iwl_set_bit(priv, CSR_GP_CNTRL,
160 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
161 goto exit_unlock;
162 }
163
164 q->write_actual = (q->write & ~0x7);
165 iwl_write_direct32(priv, rx_wrt_ptr_reg,
166 q->write_actual);
167
168 /* Else device is assumed to be awake */
169 } else {
170 /* Device expects a multiple of 8 */
171 q->write_actual = (q->write & ~0x7);
172 iwl_write_direct32(priv, rx_wrt_ptr_reg,
173 q->write_actual);
174 }
175 }
Tomas Winklera55360e2008-05-05 10:22:28 +0800176 q->need_update = 0;
177
178 exit_unlock:
179 spin_unlock_irqrestore(&q->lock, flags);
Tomas Winklera55360e2008-05-05 10:22:28 +0800180}
Tomas Winklera55360e2008-05-05 10:22:28 +0800181
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100182/******************************************************************************
183 *
184 * Generic RX handler implementations
185 *
186 ******************************************************************************/
187
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100188static void iwl_rx_reply_error(struct iwl_priv *priv,
189 struct iwl_rx_mem_buffer *rxb)
190{
191 struct iwl_rx_packet *pkt = rxb_addr(rxb);
192
193 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
194 "seq 0x%04X ser 0x%08X\n",
195 le32_to_cpu(pkt->u.err_resp.error_type),
196 get_cmd_string(pkt->u.err_resp.cmd_id),
197 pkt->u.err_resp.cmd_id,
198 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
199 le32_to_cpu(pkt->u.err_resp.error_info));
200}
201
202static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
203{
204 struct iwl_rx_packet *pkt = rxb_addr(rxb);
205 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
206 /*
207 * MULTI-FIXME
208 * See iwl_mac_channel_switch.
209 */
210 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
211 struct iwl_rxon_cmd *rxon = (void *)&ctx->active;
212
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +0200213 if (!test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
214 return;
215
216 if (!le32_to_cpu(csa->status) && csa->channel == priv->switch_channel) {
217 rxon->channel = csa->channel;
218 ctx->staging.channel = csa->channel;
219 IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100220 le16_to_cpu(csa->channel));
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +0200221 iwl_chswitch_done(priv, true);
222 } else {
223 IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
224 le16_to_cpu(csa->channel));
225 iwl_chswitch_done(priv, false);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100226 }
227}
228
229
230static void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv,
Reinette Chatre81963d62010-01-22 14:22:57 -0800231 struct iwl_rx_mem_buffer *rxb)
232{
233 struct iwl_rx_packet *pkt = rxb_addr(rxb);
234 struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
235
236 if (!report->state) {
237 IWL_DEBUG_11H(priv,
238 "Spectrum Measure Notification: Start\n");
239 return;
240 }
241
242 memcpy(&priv->measure_report, report, sizeof(*report));
243 priv->measurement_status |= MEASUREMENT_READY;
244}
Reinette Chatre81963d62010-01-22 14:22:57 -0800245
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100246static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
247 struct iwl_rx_mem_buffer *rxb)
248{
249#ifdef CONFIG_IWLWIFI_DEBUG
250 struct iwl_rx_packet *pkt = rxb_addr(rxb);
251 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
252 IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
253 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
254#endif
255}
256
257static void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
258 struct iwl_rx_mem_buffer *rxb)
259{
260 struct iwl_rx_packet *pkt = rxb_addr(rxb);
261 u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
262 IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
263 "notification for %s:\n", len,
264 get_cmd_string(pkt->hdr.cmd));
265 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
266}
267
268static void iwl_rx_beacon_notif(struct iwl_priv *priv,
269 struct iwl_rx_mem_buffer *rxb)
270{
271 struct iwl_rx_packet *pkt = rxb_addr(rxb);
272 struct iwlagn_beacon_notif *beacon = (void *)pkt->u.raw;
273#ifdef CONFIG_IWLWIFI_DEBUG
274 u16 status = le16_to_cpu(beacon->beacon_notify_hdr.status.status);
275 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
276
277 IWL_DEBUG_RX(priv, "beacon status %#x, retries:%d ibssmgr:%d "
278 "tsf:0x%.8x%.8x rate:%d\n",
279 status & TX_STATUS_MSK,
280 beacon->beacon_notify_hdr.failure_frame,
281 le32_to_cpu(beacon->ibss_mgr_status),
282 le32_to_cpu(beacon->high_tsf),
283 le32_to_cpu(beacon->low_tsf), rate);
284#endif
285
286 priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
287
288 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
289 queue_work(priv->workqueue, &priv->beacon_update);
290}
291
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100292/* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */
293#define ACK_CNT_RATIO (50)
294#define BA_TIMEOUT_CNT (5)
295#define BA_TIMEOUT_MAX (16)
296
297/**
298 * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries.
299 *
300 * When the ACK count ratio is low and aggregated BA timeout retries exceeding
301 * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal
302 * operation state.
303 */
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700304static bool iwl_good_ack_health(struct iwl_priv *priv,
305 struct statistics_tx *cur)
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100306{
307 int actual_delta, expected_delta, ba_timeout_delta;
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700308 struct statistics_tx *old;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100309
310 if (priv->_agn.agg_tids_count)
311 return true;
312
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700313 old = &priv->statistics.tx;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100314
315 actual_delta = le32_to_cpu(cur->actual_ack_cnt) -
316 le32_to_cpu(old->actual_ack_cnt);
317 expected_delta = le32_to_cpu(cur->expected_ack_cnt) -
318 le32_to_cpu(old->expected_ack_cnt);
319
320 /* Values should not be negative, but we do not trust the firmware */
321 if (actual_delta <= 0 || expected_delta <= 0)
322 return true;
323
324 ba_timeout_delta = le32_to_cpu(cur->agg.ba_timeout) -
325 le32_to_cpu(old->agg.ba_timeout);
326
327 if ((actual_delta * 100 / expected_delta) < ACK_CNT_RATIO &&
328 ba_timeout_delta > BA_TIMEOUT_CNT) {
329 IWL_DEBUG_RADIO(priv, "deltas: actual %d expected %d ba_timeout %d\n",
330 actual_delta, expected_delta, ba_timeout_delta);
331
332#ifdef CONFIG_IWLWIFI_DEBUGFS
333 /*
334 * This is ifdef'ed on DEBUGFS because otherwise the
335 * statistics aren't available. If DEBUGFS is set but
336 * DEBUG is not, these will just compile out.
337 */
338 IWL_DEBUG_RADIO(priv, "rx_detected_cnt delta %d\n",
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700339 priv->delta_stats.tx.rx_detected_cnt);
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100340 IWL_DEBUG_RADIO(priv,
341 "ack_or_ba_timeout_collision delta %d\n",
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700342 priv->delta_stats.tx.ack_or_ba_timeout_collision);
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100343#endif
344
345 if (ba_timeout_delta >= BA_TIMEOUT_MAX)
346 return false;
347 }
348
349 return true;
350}
351
352/**
353 * iwl_good_plcp_health - checks for plcp error.
354 *
355 * When the plcp error is exceeding the thresholds, reset the radio
356 * to improve the throughput.
357 */
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100358static bool iwl_good_plcp_health(struct iwl_priv *priv,
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700359 struct statistics_rx_phy *cur_ofdm,
360 struct statistics_rx_ht_phy *cur_ofdm_ht,
361 unsigned int msecs)
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100362{
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100363 int delta;
364 int threshold = priv->cfg->base_params->plcp_delta_threshold;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100365
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100366 if (threshold == IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) {
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100367 IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n");
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100368 return true;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100369 }
370
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700371 delta = le32_to_cpu(cur_ofdm->plcp_err) -
372 le32_to_cpu(priv->statistics.rx_ofdm.plcp_err) +
373 le32_to_cpu(cur_ofdm_ht->plcp_err) -
374 le32_to_cpu(priv->statistics.rx_ofdm_ht.plcp_err);
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100375
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700376 /* Can be negative if firmware reset statistics */
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100377 if (delta <= 0)
378 return true;
379
380 if ((delta * 100 / msecs) > threshold) {
381 IWL_DEBUG_RADIO(priv,
382 "plcp health threshold %u delta %d msecs %u\n",
383 threshold, delta, msecs);
384 return false;
385 }
386
387 return true;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100388}
389
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100390static void iwl_recover_from_statistics(struct iwl_priv *priv,
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700391 struct statistics_rx_phy *cur_ofdm,
392 struct statistics_rx_ht_phy *cur_ofdm_ht,
393 struct statistics_tx *tx,
394 unsigned long stamp)
Wey-Yi Guyfa8f1302010-03-05 14:22:46 -0800395{
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100396 unsigned int msecs;
Stanislaw Gruszkab7977ff2011-02-28 14:33:15 +0100397
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100398 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
399 return;
400
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100401 msecs = jiffies_to_msecs(stamp - priv->rx_statistics_jiffies);
402
403 /* Only gather statistics and update time stamp when not associated */
404 if (!iwl_is_any_associated(priv))
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700405 return;
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100406
407 /* Do not check/recover when do not have enough statistics data */
408 if (msecs < 99)
Wey-Yi Guyfa8f1302010-03-05 14:22:46 -0800409 return;
Stanislaw Gruszkaca3d9382011-02-08 09:31:55 +0100410
Don Fry9d143e92011-04-20 15:23:57 -0700411 if (iwlagn_mod_params.ack_check && !iwl_good_ack_health(priv, tx)) {
Stanislaw Gruszkaca3d9382011-02-08 09:31:55 +0100412 IWL_ERR(priv, "low ack count detected, restart firmware\n");
413 if (!iwl_force_reset(priv, IWL_FW_RESET, false))
414 return;
Trieu 'Andrew' Nguyen3e4fb5f2010-01-22 14:22:46 -0800415 }
Stanislaw Gruszkaca3d9382011-02-08 09:31:55 +0100416
Don Fry9d143e92011-04-20 15:23:57 -0700417 if (iwlagn_mod_params.plcp_check &&
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700418 !iwl_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs))
Stanislaw Gruszkaca3d9382011-02-08 09:31:55 +0100419 iwl_force_reset(priv, IWL_RF_RESET, false);
Wey-Yi Guybeac5492010-03-04 13:38:58 -0800420}
Wey-Yi Guybeac5492010-03-04 13:38:58 -0800421
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100422/* Calculate noise level, based on measurements during network silence just
423 * before arriving beacon. This measurement can be done only if we know
424 * exactly when to expect beacons, therefore only when we're associated. */
425static void iwl_rx_calc_noise(struct iwl_priv *priv)
426{
427 struct statistics_rx_non_phy *rx_info;
428 int num_active_rx = 0;
429 int total_silence = 0;
430 int bcn_silence_a, bcn_silence_b, bcn_silence_c;
431 int last_rx_noise;
432
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700433 rx_info = &priv->statistics.rx_non_phy;
434
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100435 bcn_silence_a =
436 le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
437 bcn_silence_b =
438 le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
439 bcn_silence_c =
440 le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
441
442 if (bcn_silence_a) {
443 total_silence += bcn_silence_a;
444 num_active_rx++;
445 }
446 if (bcn_silence_b) {
447 total_silence += bcn_silence_b;
448 num_active_rx++;
449 }
450 if (bcn_silence_c) {
451 total_silence += bcn_silence_c;
452 num_active_rx++;
453 }
454
455 /* Average among active antennas */
456 if (num_active_rx)
457 last_rx_noise = (total_silence / num_active_rx) - 107;
458 else
459 last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
460
461 IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n",
462 bcn_silence_a, bcn_silence_b, bcn_silence_c,
463 last_rx_noise);
464}
465
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700466#ifdef CONFIG_IWLWIFI_DEBUGFS
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100467/*
468 * based on the assumption of all statistics counter are in DWORD
469 * FIXME: This function is for debugging, do not deal with
470 * the case of counters roll-over.
471 */
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700472static void accum_stats(__le32 *prev, __le32 *cur, __le32 *delta,
473 __le32 *max_delta, __le32 *accum, int size)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100474{
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700475 int i;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100476
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700477 for (i = 0;
478 i < size / sizeof(__le32);
479 i++, prev++, cur++, delta++, max_delta++, accum++) {
480 if (le32_to_cpu(*cur) > le32_to_cpu(*prev)) {
481 *delta = cpu_to_le32(
482 le32_to_cpu(*cur) - le32_to_cpu(*prev));
483 le32_add_cpu(accum, le32_to_cpu(*delta));
484 if (le32_to_cpu(*delta) > le32_to_cpu(*max_delta))
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100485 *max_delta = *delta;
486 }
487 }
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100488}
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100489
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700490static void
491iwl_accumulative_statistics(struct iwl_priv *priv,
492 struct statistics_general_common *common,
493 struct statistics_rx_non_phy *rx_non_phy,
494 struct statistics_rx_phy *rx_ofdm,
495 struct statistics_rx_ht_phy *rx_ofdm_ht,
496 struct statistics_rx_phy *rx_cck,
497 struct statistics_tx *tx,
498 struct statistics_bt_activity *bt_activity)
499{
500#define ACCUM(_name) \
501 accum_stats((__le32 *)&priv->statistics._name, \
502 (__le32 *)_name, \
503 (__le32 *)&priv->delta_stats._name, \
504 (__le32 *)&priv->max_delta_stats._name, \
505 (__le32 *)&priv->accum_stats._name, \
506 sizeof(*_name));
507
508 ACCUM(common);
509 ACCUM(rx_non_phy);
510 ACCUM(rx_ofdm);
511 ACCUM(rx_ofdm_ht);
512 ACCUM(rx_cck);
513 ACCUM(tx);
514 if (bt_activity)
515 ACCUM(bt_activity);
516#undef ACCUM
517}
518#else
519static inline void
520iwl_accumulative_statistics(struct iwl_priv *priv,
521 struct statistics_general_common *common,
522 struct statistics_rx_non_phy *rx_non_phy,
523 struct statistics_rx_phy *rx_ofdm,
524 struct statistics_rx_ht_phy *rx_ofdm_ht,
525 struct statistics_rx_phy *rx_cck,
526 struct statistics_tx *tx,
527 struct statistics_bt_activity *bt_activity)
528{
529}
530#endif
531
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100532static void iwl_rx_statistics(struct iwl_priv *priv,
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100533 struct iwl_rx_mem_buffer *rxb)
534{
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700535 unsigned long stamp = jiffies;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100536 const int reg_recalib_period = 60;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100537 int change;
538 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700539 u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
540 __le32 *flag;
541 struct statistics_general_common *common;
542 struct statistics_rx_non_phy *rx_non_phy;
543 struct statistics_rx_phy *rx_ofdm;
544 struct statistics_rx_ht_phy *rx_ofdm_ht;
545 struct statistics_rx_phy *rx_cck;
546 struct statistics_tx *tx;
547 struct statistics_bt_activity *bt_activity;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100548
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700549 len -= sizeof(struct iwl_cmd_header); /* skip header */
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100550
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700551 IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n",
552 len);
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100553
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700554 if (len == sizeof(struct iwl_bt_notif_statistics)) {
555 struct iwl_bt_notif_statistics *stats;
556 stats = &pkt->u.stats_bt;
557 flag = &stats->flag;
558 common = &stats->general.common;
559 rx_non_phy = &stats->rx.general.common;
560 rx_ofdm = &stats->rx.ofdm;
561 rx_ofdm_ht = &stats->rx.ofdm_ht;
562 rx_cck = &stats->rx.cck;
563 tx = &stats->tx;
564 bt_activity = &stats->general.activity;
565
566#ifdef CONFIG_IWLWIFI_DEBUGFS
567 /* handle this exception directly */
568 priv->statistics.num_bt_kills = stats->rx.general.num_bt_kills;
569 le32_add_cpu(&priv->statistics.accum_num_bt_kills,
570 le32_to_cpu(stats->rx.general.num_bt_kills));
571#endif
572 } else if (len == sizeof(struct iwl_notif_statistics)) {
573 struct iwl_notif_statistics *stats;
574 stats = &pkt->u.stats;
575 flag = &stats->flag;
576 common = &stats->general.common;
577 rx_non_phy = &stats->rx.general;
578 rx_ofdm = &stats->rx.ofdm;
579 rx_ofdm_ht = &stats->rx.ofdm_ht;
580 rx_cck = &stats->rx.cck;
581 tx = &stats->tx;
582 bt_activity = NULL;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100583 } else {
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700584 WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n",
585 len, sizeof(struct iwl_bt_notif_statistics),
586 sizeof(struct iwl_notif_statistics));
587 return;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100588 }
589
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700590 change = common->temperature != priv->statistics.common.temperature ||
591 (*flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
592 (priv->statistics.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK);
593
594 iwl_accumulative_statistics(priv, common, rx_non_phy, rx_ofdm,
595 rx_ofdm_ht, rx_cck, tx, bt_activity);
596
597 iwl_recover_from_statistics(priv, rx_ofdm, rx_ofdm_ht, tx, stamp);
598
599 priv->statistics.flag = *flag;
600 memcpy(&priv->statistics.common, common, sizeof(*common));
601 memcpy(&priv->statistics.rx_non_phy, rx_non_phy, sizeof(*rx_non_phy));
602 memcpy(&priv->statistics.rx_ofdm, rx_ofdm, sizeof(*rx_ofdm));
603 memcpy(&priv->statistics.rx_ofdm_ht, rx_ofdm_ht, sizeof(*rx_ofdm_ht));
604 memcpy(&priv->statistics.rx_cck, rx_cck, sizeof(*rx_cck));
605 memcpy(&priv->statistics.tx, tx, sizeof(*tx));
606#ifdef CONFIG_IWLWIFI_DEBUGFS
607 if (bt_activity)
608 memcpy(&priv->statistics.bt_activity, bt_activity,
609 sizeof(*bt_activity));
610#endif
611
612 priv->rx_statistics_jiffies = stamp;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100613
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100614 set_bit(STATUS_STATISTICS, &priv->status);
615
616 /* Reschedule the statistics timer to occur in
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100617 * reg_recalib_period seconds to ensure we get a
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100618 * thermal update even if the uCode doesn't give
619 * us one */
620 mod_timer(&priv->statistics_periodic, jiffies +
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100621 msecs_to_jiffies(reg_recalib_period * 1000));
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100622
623 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
624 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
625 iwl_rx_calc_noise(priv);
626 queue_work(priv->workqueue, &priv->run_time_calib_work);
627 }
628 if (priv->cfg->ops->lib->temp_ops.temperature && change)
629 priv->cfg->ops->lib->temp_ops.temperature(priv);
630}
631
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100632static void iwl_rx_reply_statistics(struct iwl_priv *priv,
633 struct iwl_rx_mem_buffer *rxb)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100634{
635 struct iwl_rx_packet *pkt = rxb_addr(rxb);
636
637 if (le32_to_cpu(pkt->u.stats.flag) & UCODE_STATISTICS_CLEAR_MSK) {
638#ifdef CONFIG_IWLWIFI_DEBUGFS
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700639 memset(&priv->accum_stats, 0,
640 sizeof(priv->accum_stats));
641 memset(&priv->delta_stats, 0,
642 sizeof(priv->delta_stats));
643 memset(&priv->max_delta_stats, 0,
644 sizeof(priv->max_delta_stats));
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100645#endif
646 IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
647 }
648 iwl_rx_statistics(priv, rxb);
649}
650
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100651/* Handle notification from uCode that card's power state is changing
652 * due to software, hardware, or critical temperature RFKILL */
653static void iwl_rx_card_state_notif(struct iwl_priv *priv,
654 struct iwl_rx_mem_buffer *rxb)
655{
656 struct iwl_rx_packet *pkt = rxb_addr(rxb);
657 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
658 unsigned long status = priv->status;
659
660 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n",
661 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
662 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
663 (flags & CT_CARD_DISABLED) ?
664 "Reached" : "Not reached");
665
666 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
667 CT_CARD_DISABLED)) {
668
669 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
670 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
671
672 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
673 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
674
675 if (!(flags & RXON_CARD_DISABLED)) {
676 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
677 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
678 iwl_write_direct32(priv, HBUS_TARG_MBX_C,
679 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
680 }
681 if (flags & CT_CARD_DISABLED)
682 iwl_tt_enter_ct_kill(priv);
683 }
684 if (!(flags & CT_CARD_DISABLED))
685 iwl_tt_exit_ct_kill(priv);
686
687 if (flags & HW_CARD_DISABLED)
688 set_bit(STATUS_RF_KILL_HW, &priv->status);
689 else
690 clear_bit(STATUS_RF_KILL_HW, &priv->status);
691
692
693 if (!(flags & RXON_CARD_DISABLED))
694 iwl_scan_cancel(priv);
695
696 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
697 test_bit(STATUS_RF_KILL_HW, &priv->status)))
698 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
699 test_bit(STATUS_RF_KILL_HW, &priv->status));
700 else
701 wake_up_interruptible(&priv->wait_command_queue);
702}
703
704static void iwl_rx_missed_beacon_notif(struct iwl_priv *priv,
705 struct iwl_rx_mem_buffer *rxb)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100706
707{
708 struct iwl_rx_packet *pkt = rxb_addr(rxb);
709 struct iwl_missed_beacon_notif *missed_beacon;
710
711 missed_beacon = &pkt->u.missed_beacon;
712 if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) >
713 priv->missed_beacon_threshold) {
714 IWL_DEBUG_CALIB(priv,
715 "missed bcn cnsq %d totl %d rcd %d expctd %d\n",
716 le32_to_cpu(missed_beacon->consecutive_missed_beacons),
717 le32_to_cpu(missed_beacon->total_missed_becons),
718 le32_to_cpu(missed_beacon->num_recvd_beacons),
719 le32_to_cpu(missed_beacon->num_expected_beacons));
720 if (!test_bit(STATUS_SCANNING, &priv->status))
721 iwl_init_sensitivity(priv);
722 }
723}
724
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100725/* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
726 * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
727static void iwl_rx_reply_rx_phy(struct iwl_priv *priv,
728 struct iwl_rx_mem_buffer *rxb)
729{
730 struct iwl_rx_packet *pkt = rxb_addr(rxb);
731
732 priv->_agn.last_phy_res_valid = true;
733 memcpy(&priv->_agn.last_phy_res, pkt->u.raw,
734 sizeof(struct iwl_rx_phy_res));
735}
736
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800737/*
738 * returns non-zero if packet should be dropped
739 */
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100740static int iwl_set_decrypted_flag(struct iwl_priv *priv,
741 struct ieee80211_hdr *hdr,
742 u32 decrypt_res,
743 struct ieee80211_rx_status *stats)
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800744{
745 u16 fc = le16_to_cpu(hdr->frame_control);
746
Johannes Berg246ed352010-08-23 10:46:32 +0200747 /*
748 * All contexts have the same setting here due to it being
749 * a module parameter, so OK to check any context.
750 */
751 if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags &
752 RXON_FILTER_DIS_DECRYPT_MSK)
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800753 return 0;
754
755 if (!(fc & IEEE80211_FCTL_PROTECTED))
756 return 0;
757
Tomas Winklere1623442009-01-27 14:27:56 -0800758 IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res);
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800759 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
760 case RX_RES_STATUS_SEC_TYPE_TKIP:
761 /* The uCode has got a bad phase 1 Key, pushes the packet.
762 * Decryption will be done in SW. */
763 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
764 RX_RES_STATUS_BAD_KEY_TTAK)
765 break;
766
767 case RX_RES_STATUS_SEC_TYPE_WEP:
768 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
769 RX_RES_STATUS_BAD_ICV_MIC) {
770 /* bad ICV, the packet is destroyed since the
771 * decryption is inplace, drop it */
Tomas Winklere1623442009-01-27 14:27:56 -0800772 IWL_DEBUG_RX(priv, "Packet destroyed\n");
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800773 return -1;
774 }
775 case RX_RES_STATUS_SEC_TYPE_CCMP:
776 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
777 RX_RES_STATUS_DECRYPT_OK) {
Tomas Winklere1623442009-01-27 14:27:56 -0800778 IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n");
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800779 stats->flag |= RX_FLAG_DECRYPTED;
780 }
781 break;
782
783 default:
784 break;
785 }
786 return 0;
787}
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100788
789static void iwl_pass_packet_to_mac80211(struct iwl_priv *priv,
790 struct ieee80211_hdr *hdr,
791 u16 len,
792 u32 ampdu_status,
793 struct iwl_rx_mem_buffer *rxb,
794 struct ieee80211_rx_status *stats)
795{
796 struct sk_buff *skb;
797 __le16 fc = hdr->frame_control;
Garen Tamrazian68b99312011-03-30 02:29:32 -0700798 struct iwl_rxon_context *ctx;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100799
800 /* We only process data packets if the interface is open */
801 if (unlikely(!priv->is_open)) {
802 IWL_DEBUG_DROP_LIMIT(priv,
803 "Dropping packet while interface is not open.\n");
804 return;
805 }
806
807 /* In case of HW accelerated crypto and bad decryption, drop */
Don Fry9d143e92011-04-20 15:23:57 -0700808 if (!iwlagn_mod_params.sw_crypto &&
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100809 iwl_set_decrypted_flag(priv, hdr, ampdu_status, stats))
810 return;
811
812 skb = dev_alloc_skb(128);
813 if (!skb) {
814 IWL_ERR(priv, "dev_alloc_skb failed\n");
815 return;
816 }
817
818 skb_add_rx_frag(skb, 0, rxb->page, (void *)hdr - rxb_addr(rxb), len);
819
820 iwl_update_stats(priv, false, fc, len);
Garen Tamrazian68b99312011-03-30 02:29:32 -0700821
822 /*
823 * Wake any queues that were stopped due to a passive channel tx
824 * failure. This can happen because the regulatory enforcement in
825 * the device waits for a beacon before allowing transmission,
826 * sometimes even after already having transmitted frames for the
827 * association because the new RXON may reset the information.
828 */
829 if (unlikely(ieee80211_is_beacon(fc))) {
830 for_each_context(priv, ctx) {
831 if (!ctx->last_tx_rejected)
832 continue;
833 if (compare_ether_addr(hdr->addr3,
834 ctx->active.bssid_addr))
835 continue;
836 ctx->last_tx_rejected = false;
837 iwl_wake_any_queue(priv, ctx);
838 }
839 }
840
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100841 memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
842
843 ieee80211_rx(priv->hw, skb);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100844 rxb->page = NULL;
845}
846
847static u32 iwl_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
848{
849 u32 decrypt_out = 0;
850
851 if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
852 RX_RES_STATUS_STATION_FOUND)
853 decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
854 RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
855
856 decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
857
858 /* packet was not encrypted */
859 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
860 RX_RES_STATUS_SEC_TYPE_NONE)
861 return decrypt_out;
862
863 /* packet was encrypted with unknown alg */
864 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
865 RX_RES_STATUS_SEC_TYPE_ERR)
866 return decrypt_out;
867
868 /* decryption was not done in HW */
869 if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
870 RX_MPDU_RES_STATUS_DEC_DONE_MSK)
871 return decrypt_out;
872
873 switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
874
875 case RX_RES_STATUS_SEC_TYPE_CCMP:
876 /* alg is CCM: check MIC only */
877 if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
878 /* Bad MIC */
879 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
880 else
881 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
882
883 break;
884
885 case RX_RES_STATUS_SEC_TYPE_TKIP:
886 if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
887 /* Bad TTAK */
888 decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
889 break;
890 }
891 /* fall through if TTAK OK */
892 default:
893 if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
894 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
895 else
896 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
897 break;
898 }
899
900 IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n",
901 decrypt_in, decrypt_out);
902
903 return decrypt_out;
904}
905
906/* Called for REPLY_RX (legacy ABG frames), or
907 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
908static void iwl_rx_reply_rx(struct iwl_priv *priv,
909 struct iwl_rx_mem_buffer *rxb)
910{
911 struct ieee80211_hdr *header;
912 struct ieee80211_rx_status rx_status;
913 struct iwl_rx_packet *pkt = rxb_addr(rxb);
914 struct iwl_rx_phy_res *phy_res;
915 __le32 rx_pkt_status;
916 struct iwl_rx_mpdu_res_start *amsdu;
917 u32 len;
918 u32 ampdu_status;
919 u32 rate_n_flags;
920
921 /**
922 * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently.
923 * REPLY_RX: physical layer info is in this buffer
924 * REPLY_RX_MPDU_CMD: physical layer info was sent in separate
925 * command and cached in priv->last_phy_res
926 *
927 * Here we set up local variables depending on which command is
928 * received.
929 */
930 if (pkt->hdr.cmd == REPLY_RX) {
931 phy_res = (struct iwl_rx_phy_res *)pkt->u.raw;
932 header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*phy_res)
933 + phy_res->cfg_phy_cnt);
934
935 len = le16_to_cpu(phy_res->byte_count);
936 rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*phy_res) +
937 phy_res->cfg_phy_cnt + len);
938 ampdu_status = le32_to_cpu(rx_pkt_status);
939 } else {
940 if (!priv->_agn.last_phy_res_valid) {
941 IWL_ERR(priv, "MPDU frame without cached PHY data\n");
942 return;
943 }
944 phy_res = &priv->_agn.last_phy_res;
945 amsdu = (struct iwl_rx_mpdu_res_start *)pkt->u.raw;
946 header = (struct ieee80211_hdr *)(pkt->u.raw + sizeof(*amsdu));
947 len = le16_to_cpu(amsdu->byte_count);
948 rx_pkt_status = *(__le32 *)(pkt->u.raw + sizeof(*amsdu) + len);
949 ampdu_status = iwl_translate_rx_status(priv,
950 le32_to_cpu(rx_pkt_status));
951 }
952
953 if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
954 IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d/n",
955 phy_res->cfg_phy_cnt);
956 return;
957 }
958
959 if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
960 !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
961 IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n",
962 le32_to_cpu(rx_pkt_status));
963 return;
964 }
965
966 /* This will be used in several places later */
967 rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
968
969 /* rx_status carries information about the packet to mac80211 */
970 rx_status.mactime = le64_to_cpu(phy_res->timestamp);
971 rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
972 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
973 rx_status.freq =
974 ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel),
975 rx_status.band);
976 rx_status.rate_idx =
977 iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
978 rx_status.flag = 0;
979
980 /* TSF isn't reliable. In order to allow smooth user experience,
981 * this W/A doesn't propagate it to the mac80211 */
982 /*rx_status.flag |= RX_FLAG_MACTIME_MPDU;*/
983
984 priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
985
986 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
987 rx_status.signal = priv->cfg->ops->utils->calc_rssi(priv, phy_res);
988
989 iwl_dbg_log_rx_data_frame(priv, len, header);
990 IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n",
991 rx_status.signal, (unsigned long long)rx_status.mactime);
992
993 /*
994 * "antenna number"
995 *
996 * It seems that the antenna field in the phy flags value
997 * is actually a bit field. This is undefined by radiotap,
998 * it wants an actual antenna number but I always get "7"
999 * for most legacy frames I receive indicating that the
1000 * same frame was received on all three RX chains.
1001 *
1002 * I think this field should be removed in favor of a
1003 * new 802.11n radiotap field "RX chains" that is defined
1004 * as a bitmask.
1005 */
1006 rx_status.antenna =
1007 (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK)
1008 >> RX_RES_PHY_FLAGS_ANTENNA_POS;
1009
1010 /* set the preamble flag if appropriate */
1011 if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
1012 rx_status.flag |= RX_FLAG_SHORTPRE;
1013
1014 /* Set up the HT phy flags */
1015 if (rate_n_flags & RATE_MCS_HT_MSK)
1016 rx_status.flag |= RX_FLAG_HT;
1017 if (rate_n_flags & RATE_MCS_HT40_MSK)
1018 rx_status.flag |= RX_FLAG_40MHZ;
1019 if (rate_n_flags & RATE_MCS_SGI_MSK)
1020 rx_status.flag |= RX_FLAG_SHORT_GI;
1021
1022 iwl_pass_packet_to_mac80211(priv, header, len, ampdu_status,
1023 rxb, &rx_status);
1024}
1025
1026/**
1027 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
1028 *
1029 * Setup the RX handlers for each of the reply types sent from the uCode
1030 * to the host.
1031 */
1032void iwl_setup_rx_handlers(struct iwl_priv *priv)
1033{
1034 void (**handlers)(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb);
1035
1036 handlers = priv->rx_handlers;
1037
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001038 handlers[REPLY_ERROR] = iwl_rx_reply_error;
1039 handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
1040 handlers[SPECTRUM_MEASURE_NOTIFICATION] = iwl_rx_spectrum_measure_notif;
1041 handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
1042 handlers[PM_DEBUG_STATISTIC_NOTIFIC] = iwl_rx_pm_debug_statistics_notif;
1043 handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
1044
1045 /*
1046 * The same handler is used for both the REPLY to a discrete
1047 * statistics request from the host as well as for the periodic
1048 * statistics notifications (after received beacons) from the uCode.
1049 */
1050 handlers[REPLY_STATISTICS_CMD] = iwl_rx_reply_statistics;
1051 handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
1052
1053 iwl_setup_rx_scan_handlers(priv);
1054
1055 handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
1056 handlers[MISSED_BEACONS_NOTIFICATION] = iwl_rx_missed_beacon_notif;
1057
1058 /* Rx handlers */
1059 handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
1060 handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
1061
1062 /* block ack */
1063 handlers[REPLY_COMPRESSED_BA] = iwlagn_rx_reply_compressed_ba;
1064
1065 /* Set up hardware specific Rx handlers */
1066 priv->cfg->ops->lib->rx_handler_setup(priv);
1067}