blob: afdacb25f3446d56d1841ed551e8b1fef403f49c [file] [log] [blame]
Tomas Winklera55360e2008-05-05 10:22:28 +08001/******************************************************************************
2 *
Wey-Yi Guy4e318262011-12-27 11:21:32 -08003 * Copyright(c) 2003 - 2012 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
Emmanuel Grumbach6a686c62011-10-10 07:27:17 -07006 * as portionhelp of the ieee80211 subsystem header files.
Tomas Winklera55360e2008-05-05 10:22:28 +08007 *
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-io.h"
Johannes Berg1023fdc2012-05-15 12:16:34 +020036#include "dev.h"
37#include "calib.h"
38#include "agn.h"
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +010039
Johannes Bergd9fb6462012-03-26 08:23:39 -070040#define IWL_CMD_ENTRY(x) [x] = #x
Emmanuel Grumbach522376d2011-09-06 09:31:19 -070041
Johannes Bergd9fb6462012-03-26 08:23:39 -070042const char *iwl_dvm_cmd_strings[REPLY_MAX] = {
43 IWL_CMD_ENTRY(REPLY_ALIVE),
44 IWL_CMD_ENTRY(REPLY_ERROR),
45 IWL_CMD_ENTRY(REPLY_ECHO),
46 IWL_CMD_ENTRY(REPLY_RXON),
47 IWL_CMD_ENTRY(REPLY_RXON_ASSOC),
48 IWL_CMD_ENTRY(REPLY_QOS_PARAM),
49 IWL_CMD_ENTRY(REPLY_RXON_TIMING),
50 IWL_CMD_ENTRY(REPLY_ADD_STA),
51 IWL_CMD_ENTRY(REPLY_REMOVE_STA),
52 IWL_CMD_ENTRY(REPLY_REMOVE_ALL_STA),
53 IWL_CMD_ENTRY(REPLY_TXFIFO_FLUSH),
54 IWL_CMD_ENTRY(REPLY_WEPKEY),
55 IWL_CMD_ENTRY(REPLY_TX),
56 IWL_CMD_ENTRY(REPLY_LEDS_CMD),
57 IWL_CMD_ENTRY(REPLY_TX_LINK_QUALITY_CMD),
58 IWL_CMD_ENTRY(COEX_PRIORITY_TABLE_CMD),
59 IWL_CMD_ENTRY(COEX_MEDIUM_NOTIFICATION),
60 IWL_CMD_ENTRY(COEX_EVENT_CMD),
61 IWL_CMD_ENTRY(REPLY_QUIET_CMD),
62 IWL_CMD_ENTRY(REPLY_CHANNEL_SWITCH),
63 IWL_CMD_ENTRY(CHANNEL_SWITCH_NOTIFICATION),
64 IWL_CMD_ENTRY(REPLY_SPECTRUM_MEASUREMENT_CMD),
65 IWL_CMD_ENTRY(SPECTRUM_MEASURE_NOTIFICATION),
66 IWL_CMD_ENTRY(POWER_TABLE_CMD),
67 IWL_CMD_ENTRY(PM_SLEEP_NOTIFICATION),
68 IWL_CMD_ENTRY(PM_DEBUG_STATISTIC_NOTIFIC),
69 IWL_CMD_ENTRY(REPLY_SCAN_CMD),
70 IWL_CMD_ENTRY(REPLY_SCAN_ABORT_CMD),
71 IWL_CMD_ENTRY(SCAN_START_NOTIFICATION),
72 IWL_CMD_ENTRY(SCAN_RESULTS_NOTIFICATION),
73 IWL_CMD_ENTRY(SCAN_COMPLETE_NOTIFICATION),
74 IWL_CMD_ENTRY(BEACON_NOTIFICATION),
75 IWL_CMD_ENTRY(REPLY_TX_BEACON),
76 IWL_CMD_ENTRY(WHO_IS_AWAKE_NOTIFICATION),
77 IWL_CMD_ENTRY(QUIET_NOTIFICATION),
78 IWL_CMD_ENTRY(REPLY_TX_PWR_TABLE_CMD),
79 IWL_CMD_ENTRY(MEASURE_ABORT_NOTIFICATION),
80 IWL_CMD_ENTRY(REPLY_BT_CONFIG),
81 IWL_CMD_ENTRY(REPLY_STATISTICS_CMD),
82 IWL_CMD_ENTRY(STATISTICS_NOTIFICATION),
83 IWL_CMD_ENTRY(REPLY_CARD_STATE_CMD),
84 IWL_CMD_ENTRY(CARD_STATE_NOTIFICATION),
85 IWL_CMD_ENTRY(MISSED_BEACONS_NOTIFICATION),
86 IWL_CMD_ENTRY(REPLY_CT_KILL_CONFIG_CMD),
87 IWL_CMD_ENTRY(SENSITIVITY_CMD),
88 IWL_CMD_ENTRY(REPLY_PHY_CALIBRATION_CMD),
89 IWL_CMD_ENTRY(REPLY_RX_PHY_CMD),
90 IWL_CMD_ENTRY(REPLY_RX_MPDU_CMD),
91 IWL_CMD_ENTRY(REPLY_RX),
92 IWL_CMD_ENTRY(REPLY_COMPRESSED_BA),
93 IWL_CMD_ENTRY(CALIBRATION_CFG_CMD),
94 IWL_CMD_ENTRY(CALIBRATION_RES_NOTIFICATION),
95 IWL_CMD_ENTRY(CALIBRATION_COMPLETE_NOTIFICATION),
96 IWL_CMD_ENTRY(REPLY_TX_POWER_DBM_CMD),
97 IWL_CMD_ENTRY(TEMPERATURE_NOTIFICATION),
98 IWL_CMD_ENTRY(TX_ANT_CONFIGURATION_CMD),
99 IWL_CMD_ENTRY(REPLY_BT_COEX_PROFILE_NOTIF),
100 IWL_CMD_ENTRY(REPLY_BT_COEX_PRIO_TABLE),
101 IWL_CMD_ENTRY(REPLY_BT_COEX_PROT_ENV),
102 IWL_CMD_ENTRY(REPLY_WIPAN_PARAMS),
103 IWL_CMD_ENTRY(REPLY_WIPAN_RXON),
104 IWL_CMD_ENTRY(REPLY_WIPAN_RXON_TIMING),
105 IWL_CMD_ENTRY(REPLY_WIPAN_RXON_ASSOC),
106 IWL_CMD_ENTRY(REPLY_WIPAN_QOS_PARAM),
107 IWL_CMD_ENTRY(REPLY_WIPAN_WEPKEY),
108 IWL_CMD_ENTRY(REPLY_WIPAN_P2P_CHANNEL_SWITCH),
109 IWL_CMD_ENTRY(REPLY_WIPAN_NOA_NOTIFICATION),
110 IWL_CMD_ENTRY(REPLY_WIPAN_DEACTIVATION_COMPLETE),
111 IWL_CMD_ENTRY(REPLY_WOWLAN_PATTERNS),
112 IWL_CMD_ENTRY(REPLY_WOWLAN_WAKEUP_FILTER),
113 IWL_CMD_ENTRY(REPLY_WOWLAN_TSC_RSC_PARAMS),
114 IWL_CMD_ENTRY(REPLY_WOWLAN_TKIP_PARAMS),
115 IWL_CMD_ENTRY(REPLY_WOWLAN_KEK_KCK_MATERIAL),
116 IWL_CMD_ENTRY(REPLY_WOWLAN_GET_STATUS),
117 IWL_CMD_ENTRY(REPLY_D3_CONFIG),
118};
119#undef IWL_CMD_ENTRY
Tomas Winklera55360e2008-05-05 10:22:28 +0800120
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100121/******************************************************************************
122 *
123 * Generic RX handler implementations
124 *
125 ******************************************************************************/
126
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700127static int iwlagn_rx_reply_error(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800128 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700129 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100130{
131 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800132 struct iwl_error_resp *err_resp = (void *)pkt->data;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100133
Johannes Bergd9fb6462012-03-26 08:23:39 -0700134 IWL_ERR(priv, "Error Reply type 0x%08X cmd REPLY_ERROR (0x%02X) "
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100135 "seq 0x%04X ser 0x%08X\n",
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800136 le32_to_cpu(err_resp->error_type),
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800137 err_resp->cmd_id,
138 le16_to_cpu(err_resp->bad_cmd_seq_num),
139 le32_to_cpu(err_resp->error_info));
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700140 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100141}
142
Johannes Berg48a2d662012-03-05 11:24:39 -0800143static int iwlagn_rx_csa(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700144 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100145{
146 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800147 struct iwl_csa_notification *csa = (void *)pkt->data;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100148 /*
149 * MULTI-FIXME
Wey-Yi Guyade4c642011-10-10 07:27:11 -0700150 * See iwlagn_mac_channel_switch.
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100151 */
152 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
153 struct iwl_rxon_cmd *rxon = (void *)&ctx->active;
154
Don Fry83626402012-03-07 09:52:37 -0800155 if (!test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700156 return 0;
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +0200157
158 if (!le32_to_cpu(csa->status) && csa->channel == priv->switch_channel) {
159 rxon->channel = csa->channel;
160 ctx->staging.channel = csa->channel;
161 IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100162 le16_to_cpu(csa->channel));
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +0200163 iwl_chswitch_done(priv, true);
164 } else {
165 IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
166 le16_to_cpu(csa->channel));
167 iwl_chswitch_done(priv, false);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100168 }
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700169 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100170}
171
172
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700173static int iwlagn_rx_spectrum_measure_notif(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800174 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700175 struct iwl_device_cmd *cmd)
Reinette Chatre81963d62010-01-22 14:22:57 -0800176{
177 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800178 struct iwl_spectrum_notification *report = (void *)pkt->data;
Reinette Chatre81963d62010-01-22 14:22:57 -0800179
180 if (!report->state) {
181 IWL_DEBUG_11H(priv,
182 "Spectrum Measure Notification: Start\n");
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700183 return 0;
Reinette Chatre81963d62010-01-22 14:22:57 -0800184 }
185
186 memcpy(&priv->measure_report, report, sizeof(*report));
187 priv->measurement_status |= MEASUREMENT_READY;
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700188 return 0;
Reinette Chatre81963d62010-01-22 14:22:57 -0800189}
Reinette Chatre81963d62010-01-22 14:22:57 -0800190
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700191static int iwlagn_rx_pm_sleep_notif(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800192 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700193 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100194{
195#ifdef CONFIG_IWLWIFI_DEBUG
196 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800197 struct iwl_sleep_notification *sleep = (void *)pkt->data;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100198 IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
199 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
200#endif
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700201 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100202}
203
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700204static int iwlagn_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800205 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700206 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100207{
208 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Emmanuel Grumbach44856c62011-08-25 23:10:45 -0700209 u32 __maybe_unused len =
210 le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100211 IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
Johannes Bergd9fb6462012-03-26 08:23:39 -0700212 "notification for PM_DEBUG_STATISTIC_NOTIFIC:\n", len);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800213 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->data, len);
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700214 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100215}
216
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700217static int iwlagn_rx_beacon_notif(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800218 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700219 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100220{
221 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800222 struct iwlagn_beacon_notif *beacon = (void *)pkt->data;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100223#ifdef CONFIG_IWLWIFI_DEBUG
224 u16 status = le16_to_cpu(beacon->beacon_notify_hdr.status.status);
225 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
226
227 IWL_DEBUG_RX(priv, "beacon status %#x, retries:%d ibssmgr:%d "
228 "tsf:0x%.8x%.8x rate:%d\n",
229 status & TX_STATUS_MSK,
230 beacon->beacon_notify_hdr.failure_frame,
231 le32_to_cpu(beacon->ibss_mgr_status),
232 le32_to_cpu(beacon->high_tsf),
233 le32_to_cpu(beacon->low_tsf), rate);
234#endif
235
236 priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
237
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700238 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100239}
240
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100241/**
242 * iwl_good_plcp_health - checks for plcp error.
243 *
244 * When the plcp error is exceeding the thresholds, reset the radio
245 * to improve the throughput.
246 */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700247static bool iwlagn_good_plcp_health(struct iwl_priv *priv,
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700248 struct statistics_rx_phy *cur_ofdm,
249 struct statistics_rx_ht_phy *cur_ofdm_ht,
250 unsigned int msecs)
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100251{
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100252 int delta;
Johannes Bergab5c0f12012-03-06 13:30:53 -0800253 int threshold = priv->plcp_delta_threshold;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100254
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100255 if (threshold == IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) {
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100256 IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n");
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100257 return true;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100258 }
259
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700260 delta = le32_to_cpu(cur_ofdm->plcp_err) -
261 le32_to_cpu(priv->statistics.rx_ofdm.plcp_err) +
262 le32_to_cpu(cur_ofdm_ht->plcp_err) -
263 le32_to_cpu(priv->statistics.rx_ofdm_ht.plcp_err);
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100264
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700265 /* Can be negative if firmware reset statistics */
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100266 if (delta <= 0)
267 return true;
268
269 if ((delta * 100 / msecs) > threshold) {
270 IWL_DEBUG_RADIO(priv,
271 "plcp health threshold %u delta %d msecs %u\n",
272 threshold, delta, msecs);
273 return false;
274 }
275
276 return true;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100277}
278
Meenakshi Venkataraman66cd9e32012-03-14 15:55:13 -0700279int iwl_force_rf_reset(struct iwl_priv *priv, bool external)
280{
281 struct iwl_rf_reset *rf_reset;
282
283 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
284 return -EAGAIN;
285
286 if (!iwl_is_any_associated(priv)) {
287 IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
288 return -ENOLINK;
289 }
290
291 rf_reset = &priv->rf_reset;
292 rf_reset->reset_request_count++;
293 if (!external && rf_reset->last_reset_jiffies &&
294 time_after(rf_reset->last_reset_jiffies +
295 IWL_DELAY_NEXT_FORCE_RF_RESET, jiffies)) {
296 IWL_DEBUG_INFO(priv, "RF reset rejected\n");
297 rf_reset->reset_reject_count++;
298 return -EAGAIN;
299 }
300 rf_reset->reset_success_count++;
301 rf_reset->last_reset_jiffies = jiffies;
302
303 /*
304 * There is no easy and better way to force reset the radio,
305 * the only known method is switching channel which will force to
306 * reset and tune the radio.
307 * Use internal short scan (single channel) operation to should
308 * achieve this objective.
309 * Driver should reset the radio when number of consecutive missed
310 * beacon, or any other uCode error condition detected.
311 */
312 IWL_DEBUG_INFO(priv, "perform radio reset.\n");
313 iwl_internal_short_hw_scan(priv);
314 return 0;
315}
316
317
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700318static void iwlagn_recover_from_statistics(struct iwl_priv *priv,
319 struct statistics_rx_phy *cur_ofdm,
320 struct statistics_rx_ht_phy *cur_ofdm_ht,
321 struct statistics_tx *tx,
322 unsigned long stamp)
Wey-Yi Guyfa8f130c2010-03-05 14:22:46 -0800323{
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100324 unsigned int msecs;
Stanislaw Gruszkab7977ff2011-02-28 14:33:15 +0100325
Don Fry83626402012-03-07 09:52:37 -0800326 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100327 return;
328
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100329 msecs = jiffies_to_msecs(stamp - priv->rx_statistics_jiffies);
330
331 /* Only gather statistics and update time stamp when not associated */
332 if (!iwl_is_any_associated(priv))
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700333 return;
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100334
335 /* Do not check/recover when do not have enough statistics data */
336 if (msecs < 99)
Wey-Yi Guyfa8f130c2010-03-05 14:22:46 -0800337 return;
Stanislaw Gruszkaca3d9382011-02-08 09:31:55 +0100338
Johannes Berg65de7e82012-04-17 07:36:30 -0700339 if (iwlwifi_mod_params.plcp_check &&
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700340 !iwlagn_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs))
Johannes Berg48dffd32012-04-09 17:46:57 -0700341 iwl_force_rf_reset(priv, false);
Wey-Yi Guybeac5492010-03-04 13:38:58 -0800342}
Wey-Yi Guybeac5492010-03-04 13:38:58 -0800343
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100344/* Calculate noise level, based on measurements during network silence just
345 * before arriving beacon. This measurement can be done only if we know
346 * exactly when to expect beacons, therefore only when we're associated. */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700347static void iwlagn_rx_calc_noise(struct iwl_priv *priv)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100348{
349 struct statistics_rx_non_phy *rx_info;
350 int num_active_rx = 0;
351 int total_silence = 0;
352 int bcn_silence_a, bcn_silence_b, bcn_silence_c;
353 int last_rx_noise;
354
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700355 rx_info = &priv->statistics.rx_non_phy;
356
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100357 bcn_silence_a =
358 le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
359 bcn_silence_b =
360 le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
361 bcn_silence_c =
362 le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
363
364 if (bcn_silence_a) {
365 total_silence += bcn_silence_a;
366 num_active_rx++;
367 }
368 if (bcn_silence_b) {
369 total_silence += bcn_silence_b;
370 num_active_rx++;
371 }
372 if (bcn_silence_c) {
373 total_silence += bcn_silence_c;
374 num_active_rx++;
375 }
376
377 /* Average among active antennas */
378 if (num_active_rx)
379 last_rx_noise = (total_silence / num_active_rx) - 107;
380 else
381 last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
382
383 IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n",
384 bcn_silence_a, bcn_silence_b, bcn_silence_c,
385 last_rx_noise);
386}
387
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700388#ifdef CONFIG_IWLWIFI_DEBUGFS
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100389/*
390 * based on the assumption of all statistics counter are in DWORD
391 * FIXME: This function is for debugging, do not deal with
392 * the case of counters roll-over.
393 */
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700394static void accum_stats(__le32 *prev, __le32 *cur, __le32 *delta,
395 __le32 *max_delta, __le32 *accum, int size)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100396{
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700397 int i;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100398
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700399 for (i = 0;
400 i < size / sizeof(__le32);
401 i++, prev++, cur++, delta++, max_delta++, accum++) {
402 if (le32_to_cpu(*cur) > le32_to_cpu(*prev)) {
403 *delta = cpu_to_le32(
404 le32_to_cpu(*cur) - le32_to_cpu(*prev));
405 le32_add_cpu(accum, le32_to_cpu(*delta));
406 if (le32_to_cpu(*delta) > le32_to_cpu(*max_delta))
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100407 *max_delta = *delta;
408 }
409 }
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100410}
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100411
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700412static void
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700413iwlagn_accumulative_statistics(struct iwl_priv *priv,
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700414 struct statistics_general_common *common,
415 struct statistics_rx_non_phy *rx_non_phy,
416 struct statistics_rx_phy *rx_ofdm,
417 struct statistics_rx_ht_phy *rx_ofdm_ht,
418 struct statistics_rx_phy *rx_cck,
419 struct statistics_tx *tx,
420 struct statistics_bt_activity *bt_activity)
421{
422#define ACCUM(_name) \
423 accum_stats((__le32 *)&priv->statistics._name, \
424 (__le32 *)_name, \
425 (__le32 *)&priv->delta_stats._name, \
426 (__le32 *)&priv->max_delta_stats._name, \
427 (__le32 *)&priv->accum_stats._name, \
428 sizeof(*_name));
429
430 ACCUM(common);
431 ACCUM(rx_non_phy);
432 ACCUM(rx_ofdm);
433 ACCUM(rx_ofdm_ht);
434 ACCUM(rx_cck);
435 ACCUM(tx);
436 if (bt_activity)
437 ACCUM(bt_activity);
438#undef ACCUM
439}
440#else
441static inline void
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700442iwlagn_accumulative_statistics(struct iwl_priv *priv,
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700443 struct statistics_general_common *common,
444 struct statistics_rx_non_phy *rx_non_phy,
445 struct statistics_rx_phy *rx_ofdm,
446 struct statistics_rx_ht_phy *rx_ofdm_ht,
447 struct statistics_rx_phy *rx_cck,
448 struct statistics_tx *tx,
449 struct statistics_bt_activity *bt_activity)
450{
451}
452#endif
453
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700454static int iwlagn_rx_statistics(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800455 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700456 struct iwl_device_cmd *cmd)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100457{
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700458 unsigned long stamp = jiffies;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100459 const int reg_recalib_period = 60;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100460 int change;
461 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700462 u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
463 __le32 *flag;
464 struct statistics_general_common *common;
465 struct statistics_rx_non_phy *rx_non_phy;
466 struct statistics_rx_phy *rx_ofdm;
467 struct statistics_rx_ht_phy *rx_ofdm_ht;
468 struct statistics_rx_phy *rx_cck;
469 struct statistics_tx *tx;
470 struct statistics_bt_activity *bt_activity;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100471
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700472 len -= sizeof(struct iwl_cmd_header); /* skip header */
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100473
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700474 IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n",
475 len);
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100476
Johannes Berg4ff70fc2012-03-05 11:24:26 -0800477 spin_lock(&priv->statistics.lock);
478
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700479 if (len == sizeof(struct iwl_bt_notif_statistics)) {
480 struct iwl_bt_notif_statistics *stats;
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800481 stats = (void *)&pkt->data;
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700482 flag = &stats->flag;
483 common = &stats->general.common;
484 rx_non_phy = &stats->rx.general.common;
485 rx_ofdm = &stats->rx.ofdm;
486 rx_ofdm_ht = &stats->rx.ofdm_ht;
487 rx_cck = &stats->rx.cck;
488 tx = &stats->tx;
489 bt_activity = &stats->general.activity;
490
491#ifdef CONFIG_IWLWIFI_DEBUGFS
492 /* handle this exception directly */
493 priv->statistics.num_bt_kills = stats->rx.general.num_bt_kills;
494 le32_add_cpu(&priv->statistics.accum_num_bt_kills,
495 le32_to_cpu(stats->rx.general.num_bt_kills));
496#endif
497 } else if (len == sizeof(struct iwl_notif_statistics)) {
498 struct iwl_notif_statistics *stats;
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800499 stats = (void *)&pkt->data;
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700500 flag = &stats->flag;
501 common = &stats->general.common;
502 rx_non_phy = &stats->rx.general;
503 rx_ofdm = &stats->rx.ofdm;
504 rx_ofdm_ht = &stats->rx.ofdm_ht;
505 rx_cck = &stats->rx.cck;
506 tx = &stats->tx;
507 bt_activity = NULL;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100508 } else {
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700509 WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n",
510 len, sizeof(struct iwl_bt_notif_statistics),
511 sizeof(struct iwl_notif_statistics));
Johannes Berg4ff70fc2012-03-05 11:24:26 -0800512 spin_unlock(&priv->statistics.lock);
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700513 return 0;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100514 }
515
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700516 change = common->temperature != priv->statistics.common.temperature ||
517 (*flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
518 (priv->statistics.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK);
519
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700520 iwlagn_accumulative_statistics(priv, common, rx_non_phy, rx_ofdm,
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700521 rx_ofdm_ht, rx_cck, tx, bt_activity);
522
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700523 iwlagn_recover_from_statistics(priv, rx_ofdm, rx_ofdm_ht, tx, stamp);
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700524
525 priv->statistics.flag = *flag;
526 memcpy(&priv->statistics.common, common, sizeof(*common));
527 memcpy(&priv->statistics.rx_non_phy, rx_non_phy, sizeof(*rx_non_phy));
528 memcpy(&priv->statistics.rx_ofdm, rx_ofdm, sizeof(*rx_ofdm));
529 memcpy(&priv->statistics.rx_ofdm_ht, rx_ofdm_ht, sizeof(*rx_ofdm_ht));
530 memcpy(&priv->statistics.rx_cck, rx_cck, sizeof(*rx_cck));
531 memcpy(&priv->statistics.tx, tx, sizeof(*tx));
532#ifdef CONFIG_IWLWIFI_DEBUGFS
533 if (bt_activity)
534 memcpy(&priv->statistics.bt_activity, bt_activity,
535 sizeof(*bt_activity));
536#endif
537
538 priv->rx_statistics_jiffies = stamp;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100539
Don Fry83626402012-03-07 09:52:37 -0800540 set_bit(STATUS_STATISTICS, &priv->status);
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100541
542 /* Reschedule the statistics timer to occur in
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100543 * reg_recalib_period seconds to ensure we get a
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100544 * thermal update even if the uCode doesn't give
545 * us one */
546 mod_timer(&priv->statistics_periodic, jiffies +
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100547 msecs_to_jiffies(reg_recalib_period * 1000));
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100548
Don Fry83626402012-03-07 09:52:37 -0800549 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100550 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700551 iwlagn_rx_calc_noise(priv);
Johannes Berg1ee158d2012-02-17 10:07:44 -0800552 queue_work(priv->workqueue, &priv->run_time_calib_work);
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100553 }
Johannes Berge9676692012-04-10 14:10:28 -0700554 if (priv->lib->temperature && change)
555 priv->lib->temperature(priv);
Johannes Berg4ff70fc2012-03-05 11:24:26 -0800556
557 spin_unlock(&priv->statistics.lock);
558
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700559 return 0;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100560}
561
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700562static int iwlagn_rx_reply_statistics(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800563 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700564 struct iwl_device_cmd *cmd)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100565{
566 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800567 struct iwl_notif_statistics *stats = (void *)pkt->data;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100568
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800569 if (le32_to_cpu(stats->flag) & UCODE_STATISTICS_CLEAR_MSK) {
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100570#ifdef CONFIG_IWLWIFI_DEBUGFS
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700571 memset(&priv->accum_stats, 0,
572 sizeof(priv->accum_stats));
573 memset(&priv->delta_stats, 0,
574 sizeof(priv->delta_stats));
575 memset(&priv->max_delta_stats, 0,
576 sizeof(priv->max_delta_stats));
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100577#endif
578 IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
579 }
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700580 iwlagn_rx_statistics(priv, rxb, cmd);
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700581 return 0;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100582}
583
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100584/* Handle notification from uCode that card's power state is changing
585 * due to software, hardware, or critical temperature RFKILL */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700586static int iwlagn_rx_card_state_notif(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800587 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700588 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100589{
590 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800591 struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
592 u32 flags = le32_to_cpu(card_state_notif->flags);
Don Fry1353a7b2012-03-07 09:52:43 -0800593 unsigned long status = priv->status;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100594
595 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n",
596 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
597 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
598 (flags & CT_CARD_DISABLED) ?
599 "Reached" : "Not reached");
600
601 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
602 CT_CARD_DISABLED)) {
603
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700604 iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_SET,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100605 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
606
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700607 iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100608 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
609
610 if (!(flags & RXON_CARD_DISABLED)) {
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700611 iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100612 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700613 iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100614 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
615 }
616 if (flags & CT_CARD_DISABLED)
617 iwl_tt_enter_ct_kill(priv);
618 }
619 if (!(flags & CT_CARD_DISABLED))
620 iwl_tt_exit_ct_kill(priv);
621
622 if (flags & HW_CARD_DISABLED)
Don Fry83626402012-03-07 09:52:37 -0800623 set_bit(STATUS_RF_KILL_HW, &priv->status);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100624 else
Don Fry83626402012-03-07 09:52:37 -0800625 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100626
627
628 if (!(flags & RXON_CARD_DISABLED))
629 iwl_scan_cancel(priv);
630
631 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
Don Fry83626402012-03-07 09:52:37 -0800632 test_bit(STATUS_RF_KILL_HW, &priv->status)))
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100633 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
Don Fry83626402012-03-07 09:52:37 -0800634 test_bit(STATUS_RF_KILL_HW, &priv->status));
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100635 else
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700636 wake_up(&priv->trans->wait_command_queue);
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700637 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100638}
639
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700640static int iwlagn_rx_missed_beacon_notif(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800641 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700642 struct iwl_device_cmd *cmd)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100643
644{
645 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800646 struct iwl_missed_beacon_notif *missed_beacon = (void *)pkt->data;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100647
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100648 if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) >
649 priv->missed_beacon_threshold) {
650 IWL_DEBUG_CALIB(priv,
651 "missed bcn cnsq %d totl %d rcd %d expctd %d\n",
652 le32_to_cpu(missed_beacon->consecutive_missed_beacons),
653 le32_to_cpu(missed_beacon->total_missed_becons),
654 le32_to_cpu(missed_beacon->num_recvd_beacons),
655 le32_to_cpu(missed_beacon->num_expected_beacons));
Don Fry83626402012-03-07 09:52:37 -0800656 if (!test_bit(STATUS_SCANNING, &priv->status))
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100657 iwl_init_sensitivity(priv);
658 }
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700659 return 0;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100660}
661
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100662/* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
663 * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700664static int iwlagn_rx_reply_rx_phy(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800665 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700666 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100667{
668 struct iwl_rx_packet *pkt = rxb_addr(rxb);
669
Wey-Yi Guy898ed672011-07-13 08:38:57 -0700670 priv->last_phy_res_valid = true;
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800671 memcpy(&priv->last_phy_res, pkt->data,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100672 sizeof(struct iwl_rx_phy_res));
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700673 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100674}
675
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800676/*
677 * returns non-zero if packet should be dropped
678 */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700679static int iwlagn_set_decrypted_flag(struct iwl_priv *priv,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100680 struct ieee80211_hdr *hdr,
681 u32 decrypt_res,
682 struct ieee80211_rx_status *stats)
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800683{
684 u16 fc = le16_to_cpu(hdr->frame_control);
685
Johannes Berg246ed352010-08-23 10:46:32 +0200686 /*
687 * All contexts have the same setting here due to it being
688 * a module parameter, so OK to check any context.
689 */
690 if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags &
691 RXON_FILTER_DIS_DECRYPT_MSK)
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800692 return 0;
693
694 if (!(fc & IEEE80211_FCTL_PROTECTED))
695 return 0;
696
Tomas Winklere1623442009-01-27 14:27:56 -0800697 IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res);
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800698 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
699 case RX_RES_STATUS_SEC_TYPE_TKIP:
700 /* The uCode has got a bad phase 1 Key, pushes the packet.
701 * Decryption will be done in SW. */
702 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
703 RX_RES_STATUS_BAD_KEY_TTAK)
704 break;
705
706 case RX_RES_STATUS_SEC_TYPE_WEP:
707 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
708 RX_RES_STATUS_BAD_ICV_MIC) {
709 /* bad ICV, the packet is destroyed since the
710 * decryption is inplace, drop it */
Tomas Winklere1623442009-01-27 14:27:56 -0800711 IWL_DEBUG_RX(priv, "Packet destroyed\n");
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800712 return -1;
713 }
714 case RX_RES_STATUS_SEC_TYPE_CCMP:
715 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
716 RX_RES_STATUS_DECRYPT_OK) {
Tomas Winklere1623442009-01-27 14:27:56 -0800717 IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n");
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800718 stats->flag |= RX_FLAG_DECRYPTED;
719 }
720 break;
721
722 default:
723 break;
724 }
725 return 0;
726}
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100727
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700728static void iwlagn_pass_packet_to_mac80211(struct iwl_priv *priv,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100729 struct ieee80211_hdr *hdr,
730 u16 len,
731 u32 ampdu_status,
Johannes Berg48a2d662012-03-05 11:24:39 -0800732 struct iwl_rx_cmd_buffer *rxb,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100733 struct ieee80211_rx_status *stats)
734{
735 struct sk_buff *skb;
736 __le16 fc = hdr->frame_control;
Garen Tamrazian68b99312011-03-30 02:29:32 -0700737 struct iwl_rxon_context *ctx;
Eric Dumazeted905422012-03-24 00:29:46 -0400738 unsigned int hdrlen, fraglen;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100739
740 /* We only process data packets if the interface is open */
741 if (unlikely(!priv->is_open)) {
742 IWL_DEBUG_DROP_LIMIT(priv,
743 "Dropping packet while interface is not open.\n");
744 return;
745 }
746
747 /* In case of HW accelerated crypto and bad decryption, drop */
Johannes Berg65de7e82012-04-17 07:36:30 -0700748 if (!iwlwifi_mod_params.sw_crypto &&
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700749 iwlagn_set_decrypted_flag(priv, hdr, ampdu_status, stats))
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100750 return;
751
Eric Dumazeted905422012-03-24 00:29:46 -0400752 /* Dont use dev_alloc_skb(), we'll have enough headroom once
753 * ieee80211_hdr pulled.
754 */
755 skb = alloc_skb(128, GFP_ATOMIC);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100756 if (!skb) {
Eric Dumazeted905422012-03-24 00:29:46 -0400757 IWL_ERR(priv, "alloc_skb failed\n");
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100758 return;
759 }
Eric Dumazet56138f52012-05-18 04:48:33 +0000760 /* If frame is small enough to fit in skb->head, pull it completely.
761 * If not, only pull ieee80211_hdr so that splice() or TCP coalesce
762 * are more efficient.
763 */
764 hdrlen = (len <= skb_tailroom(skb)) ? len : sizeof(*hdr);
765
Eric Dumazeted905422012-03-24 00:29:46 -0400766 memcpy(skb_put(skb, hdrlen), hdr, hdrlen);
767 fraglen = len - hdrlen;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100768
Eric Dumazeted905422012-03-24 00:29:46 -0400769 if (fraglen) {
John W. Linville341352d2012-05-08 22:18:09 -0400770 int offset = (void *)hdr + hdrlen -
771 rxb_addr(rxb) + rxb_offset(rxb);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100772
Eric Dumazeted905422012-03-24 00:29:46 -0400773 skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset,
774 fraglen, rxb->truesize);
775 }
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100776
Garen Tamrazian68b99312011-03-30 02:29:32 -0700777 /*
778 * Wake any queues that were stopped due to a passive channel tx
779 * failure. This can happen because the regulatory enforcement in
780 * the device waits for a beacon before allowing transmission,
781 * sometimes even after already having transmitted frames for the
782 * association because the new RXON may reset the information.
783 */
Johannes Berge755f882012-03-07 09:52:16 -0800784 if (unlikely(ieee80211_is_beacon(fc) && priv->passive_no_rx)) {
Garen Tamrazian68b99312011-03-30 02:29:32 -0700785 for_each_context(priv, ctx) {
Joe Perches2e42e472012-05-09 17:17:46 +0000786 if (!ether_addr_equal(hdr->addr3,
787 ctx->active.bssid_addr))
Garen Tamrazian68b99312011-03-30 02:29:32 -0700788 continue;
Johannes Berge755f882012-03-07 09:52:16 -0800789 iwlagn_lift_passive_no_rx(priv);
Garen Tamrazian68b99312011-03-30 02:29:32 -0700790 }
791 }
792
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100793 memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
794
795 ieee80211_rx(priv->hw, skb);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100796}
797
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700798static u32 iwlagn_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100799{
800 u32 decrypt_out = 0;
801
802 if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
803 RX_RES_STATUS_STATION_FOUND)
804 decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
805 RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
806
807 decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
808
809 /* packet was not encrypted */
810 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
811 RX_RES_STATUS_SEC_TYPE_NONE)
812 return decrypt_out;
813
814 /* packet was encrypted with unknown alg */
815 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
816 RX_RES_STATUS_SEC_TYPE_ERR)
817 return decrypt_out;
818
819 /* decryption was not done in HW */
820 if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
821 RX_MPDU_RES_STATUS_DEC_DONE_MSK)
822 return decrypt_out;
823
824 switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
825
826 case RX_RES_STATUS_SEC_TYPE_CCMP:
827 /* alg is CCM: check MIC only */
828 if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
829 /* Bad MIC */
830 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
831 else
832 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
833
834 break;
835
836 case RX_RES_STATUS_SEC_TYPE_TKIP:
837 if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
838 /* Bad TTAK */
839 decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
840 break;
841 }
842 /* fall through if TTAK OK */
843 default:
844 if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
845 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
846 else
847 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
848 break;
849 }
850
851 IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n",
852 decrypt_in, decrypt_out);
853
854 return decrypt_out;
855}
856
Don Fry5c3d29f2011-07-08 08:46:29 -0700857/* Calc max signal level (dBm) among 3 possible receivers */
858static int iwlagn_calc_rssi(struct iwl_priv *priv,
859 struct iwl_rx_phy_res *rx_resp)
860{
861 /* data from PHY/DSP regarding signal strength, etc.,
862 * contents are always there, not configurable by host
863 */
864 struct iwlagn_non_cfg_phy *ncphy =
865 (struct iwlagn_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
866 u32 val, rssi_a, rssi_b, rssi_c, max_rssi;
867 u8 agc;
868
869 val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_AGC_IDX]);
870 agc = (val & IWLAGN_OFDM_AGC_MSK) >> IWLAGN_OFDM_AGC_BIT_POS;
871
872 /* Find max rssi among 3 possible receivers.
873 * These values are measured by the digital signal processor (DSP).
874 * They should stay fairly constant even as the signal strength varies,
875 * if the radio's automatic gain control (AGC) is working right.
876 * AGC value (see below) will provide the "interesting" info.
877 */
878 val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_AB_IDX]);
879 rssi_a = (val & IWLAGN_OFDM_RSSI_INBAND_A_BITMSK) >>
880 IWLAGN_OFDM_RSSI_A_BIT_POS;
881 rssi_b = (val & IWLAGN_OFDM_RSSI_INBAND_B_BITMSK) >>
882 IWLAGN_OFDM_RSSI_B_BIT_POS;
883 val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_C_IDX]);
884 rssi_c = (val & IWLAGN_OFDM_RSSI_INBAND_C_BITMSK) >>
885 IWLAGN_OFDM_RSSI_C_BIT_POS;
886
887 max_rssi = max_t(u32, rssi_a, rssi_b);
888 max_rssi = max_t(u32, max_rssi, rssi_c);
889
890 IWL_DEBUG_STATS(priv, "Rssi In A %d B %d C %d Max %d AGC dB %d\n",
891 rssi_a, rssi_b, rssi_c, max_rssi, agc);
892
893 /* dBm = max_rssi dB - agc dB - constant.
894 * Higher AGC (higher radio gain) means lower signal. */
895 return max_rssi - agc - IWLAGN_RSSI_OFFSET;
896}
897
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100898/* Called for REPLY_RX (legacy ABG frames), or
899 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700900static int iwlagn_rx_reply_rx(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800901 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700902 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100903{
904 struct ieee80211_hdr *header;
905 struct ieee80211_rx_status rx_status;
906 struct iwl_rx_packet *pkt = rxb_addr(rxb);
907 struct iwl_rx_phy_res *phy_res;
908 __le32 rx_pkt_status;
909 struct iwl_rx_mpdu_res_start *amsdu;
910 u32 len;
911 u32 ampdu_status;
912 u32 rate_n_flags;
913
914 /**
915 * REPLY_RX and REPLY_RX_MPDU_CMD are handled differently.
916 * REPLY_RX: physical layer info is in this buffer
917 * REPLY_RX_MPDU_CMD: physical layer info was sent in separate
918 * command and cached in priv->last_phy_res
919 *
920 * Here we set up local variables depending on which command is
921 * received.
922 */
923 if (pkt->hdr.cmd == REPLY_RX) {
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800924 phy_res = (struct iwl_rx_phy_res *)pkt->data;
925 header = (struct ieee80211_hdr *)(pkt->data + sizeof(*phy_res)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100926 + phy_res->cfg_phy_cnt);
927
928 len = le16_to_cpu(phy_res->byte_count);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800929 rx_pkt_status = *(__le32 *)(pkt->data + sizeof(*phy_res) +
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100930 phy_res->cfg_phy_cnt + len);
931 ampdu_status = le32_to_cpu(rx_pkt_status);
932 } else {
Wey-Yi Guy898ed672011-07-13 08:38:57 -0700933 if (!priv->last_phy_res_valid) {
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100934 IWL_ERR(priv, "MPDU frame without cached PHY data\n");
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700935 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100936 }
Wey-Yi Guy898ed672011-07-13 08:38:57 -0700937 phy_res = &priv->last_phy_res;
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800938 amsdu = (struct iwl_rx_mpdu_res_start *)pkt->data;
939 header = (struct ieee80211_hdr *)(pkt->data + sizeof(*amsdu));
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100940 len = le16_to_cpu(amsdu->byte_count);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800941 rx_pkt_status = *(__le32 *)(pkt->data + sizeof(*amsdu) + len);
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700942 ampdu_status = iwlagn_translate_rx_status(priv,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100943 le32_to_cpu(rx_pkt_status));
944 }
945
946 if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
Johannes Berg0ca24da2012-03-15 13:26:46 -0700947 IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d\n",
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100948 phy_res->cfg_phy_cnt);
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700949 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100950 }
951
952 if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
953 !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
954 IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n",
955 le32_to_cpu(rx_pkt_status));
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700956 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100957 }
958
959 /* This will be used in several places later */
960 rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
961
962 /* rx_status carries information about the packet to mac80211 */
963 rx_status.mactime = le64_to_cpu(phy_res->timestamp);
964 rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
965 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
966 rx_status.freq =
967 ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel),
968 rx_status.band);
969 rx_status.rate_idx =
970 iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
971 rx_status.flag = 0;
972
973 /* TSF isn't reliable. In order to allow smooth user experience,
974 * this W/A doesn't propagate it to the mac80211 */
975 /*rx_status.flag |= RX_FLAG_MACTIME_MPDU;*/
976
977 priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
978
979 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
Don Fry5c3d29f2011-07-08 08:46:29 -0700980 rx_status.signal = iwlagn_calc_rssi(priv, phy_res);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100981
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100982 IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n",
983 rx_status.signal, (unsigned long long)rx_status.mactime);
984
985 /*
986 * "antenna number"
987 *
988 * It seems that the antenna field in the phy flags value
989 * is actually a bit field. This is undefined by radiotap,
990 * it wants an actual antenna number but I always get "7"
991 * for most legacy frames I receive indicating that the
992 * same frame was received on all three RX chains.
993 *
994 * I think this field should be removed in favor of a
995 * new 802.11n radiotap field "RX chains" that is defined
996 * as a bitmask.
997 */
998 rx_status.antenna =
999 (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK)
1000 >> RX_RES_PHY_FLAGS_ANTENNA_POS;
1001
1002 /* set the preamble flag if appropriate */
1003 if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
1004 rx_status.flag |= RX_FLAG_SHORTPRE;
1005
1006 /* Set up the HT phy flags */
1007 if (rate_n_flags & RATE_MCS_HT_MSK)
1008 rx_status.flag |= RX_FLAG_HT;
1009 if (rate_n_flags & RATE_MCS_HT40_MSK)
1010 rx_status.flag |= RX_FLAG_40MHZ;
1011 if (rate_n_flags & RATE_MCS_SGI_MSK)
1012 rx_status.flag |= RX_FLAG_SHORT_GI;
Johannes Berg53e11162012-05-16 23:59:03 +02001013 if (rate_n_flags & RATE_MCS_GF_MSK)
1014 rx_status.flag |= RX_FLAG_HT_GF;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001015
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -07001016 iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001017 rxb, &rx_status);
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -07001018 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001019}
1020
Johannes Berg79d3eef2011-11-10 06:55:01 -08001021static int iwlagn_rx_noa_notification(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -08001022 struct iwl_rx_cmd_buffer *rxb,
Johannes Berg79d3eef2011-11-10 06:55:01 -08001023 struct iwl_device_cmd *cmd)
1024{
1025 struct iwl_wipan_noa_data *new_data, *old_data;
1026 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -08001027 struct iwl_wipan_noa_notification *noa_notif = (void *)pkt->data;
Johannes Berg79d3eef2011-11-10 06:55:01 -08001028
1029 /* no condition -- we're in softirq */
1030 old_data = rcu_dereference_protected(priv->noa_data, true);
1031
1032 if (noa_notif->noa_active) {
1033 u32 len = le16_to_cpu(noa_notif->noa_attribute.length);
1034 u32 copylen = len;
1035
1036 /* EID, len, OUI, subtype */
1037 len += 1 + 1 + 3 + 1;
1038 /* P2P id, P2P length */
1039 len += 1 + 2;
1040 copylen += 1 + 2;
1041
1042 new_data = kmalloc(sizeof(*new_data) + len, GFP_ATOMIC);
1043 if (new_data) {
1044 new_data->length = len;
1045 new_data->data[0] = WLAN_EID_VENDOR_SPECIFIC;
1046 new_data->data[1] = len - 2; /* not counting EID, len */
1047 new_data->data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
1048 new_data->data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
1049 new_data->data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
1050 new_data->data[5] = WLAN_OUI_TYPE_WFA_P2P;
1051 memcpy(&new_data->data[6], &noa_notif->noa_attribute,
1052 copylen);
1053 }
1054 } else
1055 new_data = NULL;
1056
1057 rcu_assign_pointer(priv->noa_data, new_data);
1058
1059 if (old_data)
1060 kfree_rcu(old_data, rcu_head);
1061
1062 return 0;
1063}
1064
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001065/**
1066 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
1067 *
1068 * Setup the RX handlers for each of the reply types sent from the uCode
1069 * to the host.
1070 */
1071void iwl_setup_rx_handlers(struct iwl_priv *priv)
1072{
Johannes Berg48a2d662012-03-05 11:24:39 -08001073 int (**handlers)(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -07001074 struct iwl_device_cmd *cmd);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001075
1076 handlers = priv->rx_handlers;
1077
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -07001078 handlers[REPLY_ERROR] = iwlagn_rx_reply_error;
1079 handlers[CHANNEL_SWITCH_NOTIFICATION] = iwlagn_rx_csa;
1080 handlers[SPECTRUM_MEASURE_NOTIFICATION] =
1081 iwlagn_rx_spectrum_measure_notif;
1082 handlers[PM_SLEEP_NOTIFICATION] = iwlagn_rx_pm_sleep_notif;
1083 handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
1084 iwlagn_rx_pm_debug_statistics_notif;
1085 handlers[BEACON_NOTIFICATION] = iwlagn_rx_beacon_notif;
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -07001086 handlers[REPLY_ADD_STA] = iwl_add_sta_callback;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001087
Johannes Berg79d3eef2011-11-10 06:55:01 -08001088 handlers[REPLY_WIPAN_NOA_NOTIFICATION] = iwlagn_rx_noa_notification;
1089
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001090 /*
1091 * The same handler is used for both the REPLY to a discrete
1092 * statistics request from the host as well as for the periodic
1093 * statistics notifications (after received beacons) from the uCode.
1094 */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -07001095 handlers[REPLY_STATISTICS_CMD] = iwlagn_rx_reply_statistics;
1096 handlers[STATISTICS_NOTIFICATION] = iwlagn_rx_statistics;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001097
1098 iwl_setup_rx_scan_handlers(priv);
1099
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -07001100 handlers[CARD_STATE_NOTIFICATION] = iwlagn_rx_card_state_notif;
1101 handlers[MISSED_BEACONS_NOTIFICATION] =
1102 iwlagn_rx_missed_beacon_notif;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001103
1104 /* Rx handlers */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -07001105 handlers[REPLY_RX_PHY_CMD] = iwlagn_rx_reply_rx_phy;
1106 handlers[REPLY_RX_MPDU_CMD] = iwlagn_rx_reply_rx;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001107
1108 /* block ack */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -07001109 handlers[REPLY_COMPRESSED_BA] =
1110 iwlagn_rx_reply_compressed_ba;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001111
Emmanuel Grumbach8d301192011-07-03 15:45:34 +03001112 priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx;
1113
1114 /* set up notification wait support */
Johannes Berg4bd14dd2012-03-06 13:30:58 -08001115 iwl_notification_wait_init(&priv->notif_wait);
Emmanuel Grumbach8d301192011-07-03 15:45:34 +03001116
1117 /* Set up BT Rx handlers */
Emmanuel Grumbach21522682012-03-22 17:51:44 +02001118 if (priv->cfg->bt_params)
Johannes Berg562f08e2012-03-07 09:52:18 -08001119 iwlagn_bt_rx_handler_setup(priv);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001120}
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001121
Johannes Berg48a2d662012-03-05 11:24:39 -08001122int iwl_rx_dispatch(struct iwl_op_mode *op_mode, struct iwl_rx_cmd_buffer *rxb,
1123 struct iwl_device_cmd *cmd)
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001124{
1125 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Emmanuel Grumbachdb70f292012-02-09 16:08:15 +02001126 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -07001127 int err = 0;
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001128
1129 /*
1130 * Do the notification wait before RX handlers so
1131 * even if the RX handler consumes the RXB we have
1132 * access to it in the notification wait entry.
1133 */
Johannes Berg4bd14dd2012-03-06 13:30:58 -08001134 iwl_notification_wait_notify(&priv->notif_wait, pkt);
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001135
Ilan Peer3a6490c2012-06-03 13:36:51 +03001136#ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
1137 /*
1138 * RX data may be forwarded to userspace in one
1139 * of two cases: the user owns the fw through testmode or when
1140 * the user requested to monitor the rx w/o affecting the regular flow.
1141 * In these cases the iwl_test object will handle forwarding the rx
1142 * data to user space.
1143 * Note that if the ownership flag != IWL_OWNERSHIP_TM the flow
Amit Beka0aef8dd2012-03-07 09:52:29 -08001144 * continues.
Amit Beka0aef8dd2012-03-07 09:52:29 -08001145 */
Ilan Peer3a6490c2012-06-03 13:36:51 +03001146 iwl_test_rx(&priv->tst, priv->hw, rxb);
1147#endif
1148
Amit Beka0aef8dd2012-03-07 09:52:29 -08001149 if (priv->ucode_owner != IWL_OWNERSHIP_TM) {
Wey-Yi Guy64eeacb2011-12-16 09:31:14 -08001150 /* Based on type of command response or notification,
1151 * handle those that need handling via function in
1152 * rx_handlers table. See iwl_setup_rx_handlers() */
1153 if (priv->rx_handlers[pkt->hdr.cmd]) {
1154 priv->rx_handlers_stats[pkt->hdr.cmd]++;
1155 err = priv->rx_handlers[pkt->hdr.cmd] (priv, rxb, cmd);
1156 } else {
1157 /* No handling needed */
Johannes Bergd9fb6462012-03-26 08:23:39 -07001158 IWL_DEBUG_RX(priv, "No handler needed for %s, 0x%02x\n",
1159 iwl_dvm_get_cmd_string(pkt->hdr.cmd),
1160 pkt->hdr.cmd);
Wey-Yi Guy64eeacb2011-12-16 09:31:14 -08001161 }
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001162 }
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -07001163 return err;
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001164}