blob: fee5cffa166998c30437ac37b7490e0b85972dc1 [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),
Johannes Bergd9fb6462012-03-26 08:23:39 -070091 IWL_CMD_ENTRY(REPLY_COMPRESSED_BA),
92 IWL_CMD_ENTRY(CALIBRATION_CFG_CMD),
93 IWL_CMD_ENTRY(CALIBRATION_RES_NOTIFICATION),
94 IWL_CMD_ENTRY(CALIBRATION_COMPLETE_NOTIFICATION),
95 IWL_CMD_ENTRY(REPLY_TX_POWER_DBM_CMD),
96 IWL_CMD_ENTRY(TEMPERATURE_NOTIFICATION),
97 IWL_CMD_ENTRY(TX_ANT_CONFIGURATION_CMD),
98 IWL_CMD_ENTRY(REPLY_BT_COEX_PROFILE_NOTIF),
99 IWL_CMD_ENTRY(REPLY_BT_COEX_PRIO_TABLE),
100 IWL_CMD_ENTRY(REPLY_BT_COEX_PROT_ENV),
101 IWL_CMD_ENTRY(REPLY_WIPAN_PARAMS),
102 IWL_CMD_ENTRY(REPLY_WIPAN_RXON),
103 IWL_CMD_ENTRY(REPLY_WIPAN_RXON_TIMING),
104 IWL_CMD_ENTRY(REPLY_WIPAN_RXON_ASSOC),
105 IWL_CMD_ENTRY(REPLY_WIPAN_QOS_PARAM),
106 IWL_CMD_ENTRY(REPLY_WIPAN_WEPKEY),
107 IWL_CMD_ENTRY(REPLY_WIPAN_P2P_CHANNEL_SWITCH),
108 IWL_CMD_ENTRY(REPLY_WIPAN_NOA_NOTIFICATION),
109 IWL_CMD_ENTRY(REPLY_WIPAN_DEACTIVATION_COMPLETE),
110 IWL_CMD_ENTRY(REPLY_WOWLAN_PATTERNS),
111 IWL_CMD_ENTRY(REPLY_WOWLAN_WAKEUP_FILTER),
112 IWL_CMD_ENTRY(REPLY_WOWLAN_TSC_RSC_PARAMS),
113 IWL_CMD_ENTRY(REPLY_WOWLAN_TKIP_PARAMS),
114 IWL_CMD_ENTRY(REPLY_WOWLAN_KEK_KCK_MATERIAL),
115 IWL_CMD_ENTRY(REPLY_WOWLAN_GET_STATUS),
116 IWL_CMD_ENTRY(REPLY_D3_CONFIG),
117};
118#undef IWL_CMD_ENTRY
Tomas Winklera55360e2008-05-05 10:22:28 +0800119
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100120/******************************************************************************
121 *
122 * Generic RX handler implementations
123 *
124 ******************************************************************************/
125
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700126static int iwlagn_rx_reply_error(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800127 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700128 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100129{
130 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800131 struct iwl_error_resp *err_resp = (void *)pkt->data;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100132
Johannes Bergd9fb6462012-03-26 08:23:39 -0700133 IWL_ERR(priv, "Error Reply type 0x%08X cmd REPLY_ERROR (0x%02X) "
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100134 "seq 0x%04X ser 0x%08X\n",
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800135 le32_to_cpu(err_resp->error_type),
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800136 err_resp->cmd_id,
137 le16_to_cpu(err_resp->bad_cmd_seq_num),
138 le32_to_cpu(err_resp->error_info));
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700139 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100140}
141
Johannes Berg48a2d662012-03-05 11:24:39 -0800142static int iwlagn_rx_csa(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700143 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100144{
145 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800146 struct iwl_csa_notification *csa = (void *)pkt->data;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100147 /*
148 * MULTI-FIXME
Wey-Yi Guyade4c642011-10-10 07:27:11 -0700149 * See iwlagn_mac_channel_switch.
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100150 */
151 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
152 struct iwl_rxon_cmd *rxon = (void *)&ctx->active;
153
Don Fry83626402012-03-07 09:52:37 -0800154 if (!test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700155 return 0;
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +0200156
157 if (!le32_to_cpu(csa->status) && csa->channel == priv->switch_channel) {
158 rxon->channel = csa->channel;
159 ctx->staging.channel = csa->channel;
160 IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100161 le16_to_cpu(csa->channel));
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +0200162 iwl_chswitch_done(priv, true);
163 } else {
164 IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
165 le16_to_cpu(csa->channel));
166 iwl_chswitch_done(priv, false);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100167 }
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700168 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100169}
170
171
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700172static int iwlagn_rx_spectrum_measure_notif(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800173 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700174 struct iwl_device_cmd *cmd)
Reinette Chatre81963d62010-01-22 14:22:57 -0800175{
176 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800177 struct iwl_spectrum_notification *report = (void *)pkt->data;
Reinette Chatre81963d62010-01-22 14:22:57 -0800178
179 if (!report->state) {
180 IWL_DEBUG_11H(priv,
181 "Spectrum Measure Notification: Start\n");
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700182 return 0;
Reinette Chatre81963d62010-01-22 14:22:57 -0800183 }
184
185 memcpy(&priv->measure_report, report, sizeof(*report));
186 priv->measurement_status |= MEASUREMENT_READY;
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700187 return 0;
Reinette Chatre81963d62010-01-22 14:22:57 -0800188}
Reinette Chatre81963d62010-01-22 14:22:57 -0800189
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700190static int iwlagn_rx_pm_sleep_notif(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800191 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700192 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100193{
194#ifdef CONFIG_IWLWIFI_DEBUG
195 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800196 struct iwl_sleep_notification *sleep = (void *)pkt->data;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100197 IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
198 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
199#endif
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700200 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100201}
202
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700203static int iwlagn_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800204 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700205 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100206{
207 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Emmanuel Grumbach44856c62011-08-25 23:10:45 -0700208 u32 __maybe_unused len =
209 le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100210 IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
Johannes Bergd9fb6462012-03-26 08:23:39 -0700211 "notification for PM_DEBUG_STATISTIC_NOTIFIC:\n", len);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800212 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->data, len);
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700213 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100214}
215
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700216static int iwlagn_rx_beacon_notif(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800217 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700218 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100219{
220 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800221 struct iwlagn_beacon_notif *beacon = (void *)pkt->data;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100222#ifdef CONFIG_IWLWIFI_DEBUG
223 u16 status = le16_to_cpu(beacon->beacon_notify_hdr.status.status);
224 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
225
226 IWL_DEBUG_RX(priv, "beacon status %#x, retries:%d ibssmgr:%d "
227 "tsf:0x%.8x%.8x rate:%d\n",
228 status & TX_STATUS_MSK,
229 beacon->beacon_notify_hdr.failure_frame,
230 le32_to_cpu(beacon->ibss_mgr_status),
231 le32_to_cpu(beacon->high_tsf),
232 le32_to_cpu(beacon->low_tsf), rate);
233#endif
234
235 priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
236
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700237 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100238}
239
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100240/**
241 * iwl_good_plcp_health - checks for plcp error.
242 *
243 * When the plcp error is exceeding the thresholds, reset the radio
244 * to improve the throughput.
245 */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700246static bool iwlagn_good_plcp_health(struct iwl_priv *priv,
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700247 struct statistics_rx_phy *cur_ofdm,
248 struct statistics_rx_ht_phy *cur_ofdm_ht,
249 unsigned int msecs)
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100250{
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100251 int delta;
Johannes Bergab5c0f12012-03-06 13:30:53 -0800252 int threshold = priv->plcp_delta_threshold;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100253
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100254 if (threshold == IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) {
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100255 IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n");
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100256 return true;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100257 }
258
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700259 delta = le32_to_cpu(cur_ofdm->plcp_err) -
260 le32_to_cpu(priv->statistics.rx_ofdm.plcp_err) +
261 le32_to_cpu(cur_ofdm_ht->plcp_err) -
262 le32_to_cpu(priv->statistics.rx_ofdm_ht.plcp_err);
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100263
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700264 /* Can be negative if firmware reset statistics */
Stanislaw Gruszka6198c382011-03-04 17:51:50 +0100265 if (delta <= 0)
266 return true;
267
268 if ((delta * 100 / msecs) > threshold) {
269 IWL_DEBUG_RADIO(priv,
270 "plcp health threshold %u delta %d msecs %u\n",
271 threshold, delta, msecs);
272 return false;
273 }
274
275 return true;
Stanislaw Gruszkaad6e82a2011-02-28 14:33:16 +0100276}
277
Meenakshi Venkataraman66cd9e32012-03-14 15:55:13 -0700278int iwl_force_rf_reset(struct iwl_priv *priv, bool external)
279{
280 struct iwl_rf_reset *rf_reset;
281
282 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
283 return -EAGAIN;
284
285 if (!iwl_is_any_associated(priv)) {
286 IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
287 return -ENOLINK;
288 }
289
290 rf_reset = &priv->rf_reset;
291 rf_reset->reset_request_count++;
292 if (!external && rf_reset->last_reset_jiffies &&
293 time_after(rf_reset->last_reset_jiffies +
294 IWL_DELAY_NEXT_FORCE_RF_RESET, jiffies)) {
295 IWL_DEBUG_INFO(priv, "RF reset rejected\n");
296 rf_reset->reset_reject_count++;
297 return -EAGAIN;
298 }
299 rf_reset->reset_success_count++;
300 rf_reset->last_reset_jiffies = jiffies;
301
302 /*
303 * There is no easy and better way to force reset the radio,
304 * the only known method is switching channel which will force to
305 * reset and tune the radio.
306 * Use internal short scan (single channel) operation to should
307 * achieve this objective.
308 * Driver should reset the radio when number of consecutive missed
309 * beacon, or any other uCode error condition detected.
310 */
311 IWL_DEBUG_INFO(priv, "perform radio reset.\n");
312 iwl_internal_short_hw_scan(priv);
313 return 0;
314}
315
316
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700317static void iwlagn_recover_from_statistics(struct iwl_priv *priv,
318 struct statistics_rx_phy *cur_ofdm,
319 struct statistics_rx_ht_phy *cur_ofdm_ht,
320 struct statistics_tx *tx,
321 unsigned long stamp)
Wey-Yi Guyfa8f130c2010-03-05 14:22:46 -0800322{
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100323 unsigned int msecs;
Stanislaw Gruszkab7977ff2011-02-28 14:33:15 +0100324
Don Fry83626402012-03-07 09:52:37 -0800325 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100326 return;
327
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100328 msecs = jiffies_to_msecs(stamp - priv->rx_statistics_jiffies);
329
330 /* Only gather statistics and update time stamp when not associated */
331 if (!iwl_is_any_associated(priv))
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700332 return;
Stanislaw Gruszka410f2bb2011-03-04 17:51:51 +0100333
334 /* Do not check/recover when do not have enough statistics data */
335 if (msecs < 99)
Wey-Yi Guyfa8f130c2010-03-05 14:22:46 -0800336 return;
Stanislaw Gruszkaca3d9382011-02-08 09:31:55 +0100337
Johannes Berg65de7e82012-04-17 07:36:30 -0700338 if (iwlwifi_mod_params.plcp_check &&
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700339 !iwlagn_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs))
Johannes Berg48dffd32012-04-09 17:46:57 -0700340 iwl_force_rf_reset(priv, false);
Wey-Yi Guybeac5492010-03-04 13:38:58 -0800341}
Wey-Yi Guybeac5492010-03-04 13:38:58 -0800342
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100343/* Calculate noise level, based on measurements during network silence just
344 * before arriving beacon. This measurement can be done only if we know
345 * exactly when to expect beacons, therefore only when we're associated. */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700346static void iwlagn_rx_calc_noise(struct iwl_priv *priv)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100347{
348 struct statistics_rx_non_phy *rx_info;
349 int num_active_rx = 0;
350 int total_silence = 0;
351 int bcn_silence_a, bcn_silence_b, bcn_silence_c;
352 int last_rx_noise;
353
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700354 rx_info = &priv->statistics.rx_non_phy;
355
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100356 bcn_silence_a =
357 le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
358 bcn_silence_b =
359 le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
360 bcn_silence_c =
361 le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
362
363 if (bcn_silence_a) {
364 total_silence += bcn_silence_a;
365 num_active_rx++;
366 }
367 if (bcn_silence_b) {
368 total_silence += bcn_silence_b;
369 num_active_rx++;
370 }
371 if (bcn_silence_c) {
372 total_silence += bcn_silence_c;
373 num_active_rx++;
374 }
375
376 /* Average among active antennas */
377 if (num_active_rx)
378 last_rx_noise = (total_silence / num_active_rx) - 107;
379 else
380 last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
381
382 IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n",
383 bcn_silence_a, bcn_silence_b, bcn_silence_c,
384 last_rx_noise);
385}
386
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700387#ifdef CONFIG_IWLWIFI_DEBUGFS
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100388/*
389 * based on the assumption of all statistics counter are in DWORD
390 * FIXME: This function is for debugging, do not deal with
391 * the case of counters roll-over.
392 */
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700393static void accum_stats(__le32 *prev, __le32 *cur, __le32 *delta,
394 __le32 *max_delta, __le32 *accum, int size)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100395{
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700396 int i;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100397
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700398 for (i = 0;
399 i < size / sizeof(__le32);
400 i++, prev++, cur++, delta++, max_delta++, accum++) {
401 if (le32_to_cpu(*cur) > le32_to_cpu(*prev)) {
402 *delta = cpu_to_le32(
403 le32_to_cpu(*cur) - le32_to_cpu(*prev));
404 le32_add_cpu(accum, le32_to_cpu(*delta));
405 if (le32_to_cpu(*delta) > le32_to_cpu(*max_delta))
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100406 *max_delta = *delta;
407 }
408 }
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100409}
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100410
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700411static void
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700412iwlagn_accumulative_statistics(struct iwl_priv *priv,
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700413 struct statistics_general_common *common,
414 struct statistics_rx_non_phy *rx_non_phy,
415 struct statistics_rx_phy *rx_ofdm,
416 struct statistics_rx_ht_phy *rx_ofdm_ht,
417 struct statistics_rx_phy *rx_cck,
418 struct statistics_tx *tx,
419 struct statistics_bt_activity *bt_activity)
420{
421#define ACCUM(_name) \
422 accum_stats((__le32 *)&priv->statistics._name, \
423 (__le32 *)_name, \
424 (__le32 *)&priv->delta_stats._name, \
425 (__le32 *)&priv->max_delta_stats._name, \
426 (__le32 *)&priv->accum_stats._name, \
427 sizeof(*_name));
428
429 ACCUM(common);
430 ACCUM(rx_non_phy);
431 ACCUM(rx_ofdm);
432 ACCUM(rx_ofdm_ht);
433 ACCUM(rx_cck);
434 ACCUM(tx);
435 if (bt_activity)
436 ACCUM(bt_activity);
437#undef ACCUM
438}
439#else
440static inline void
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700441iwlagn_accumulative_statistics(struct iwl_priv *priv,
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700442 struct statistics_general_common *common,
443 struct statistics_rx_non_phy *rx_non_phy,
444 struct statistics_rx_phy *rx_ofdm,
445 struct statistics_rx_ht_phy *rx_ofdm_ht,
446 struct statistics_rx_phy *rx_cck,
447 struct statistics_tx *tx,
448 struct statistics_bt_activity *bt_activity)
449{
450}
451#endif
452
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700453static int iwlagn_rx_statistics(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800454 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700455 struct iwl_device_cmd *cmd)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100456{
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700457 unsigned long stamp = jiffies;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100458 const int reg_recalib_period = 60;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100459 int change;
460 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700461 u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
462 __le32 *flag;
463 struct statistics_general_common *common;
464 struct statistics_rx_non_phy *rx_non_phy;
465 struct statistics_rx_phy *rx_ofdm;
466 struct statistics_rx_ht_phy *rx_ofdm_ht;
467 struct statistics_rx_phy *rx_cck;
468 struct statistics_tx *tx;
469 struct statistics_bt_activity *bt_activity;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100470
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700471 len -= sizeof(struct iwl_cmd_header); /* skip header */
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100472
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700473 IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n",
474 len);
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100475
Johannes Berg4ff70fc2012-03-05 11:24:26 -0800476 spin_lock(&priv->statistics.lock);
477
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700478 if (len == sizeof(struct iwl_bt_notif_statistics)) {
479 struct iwl_bt_notif_statistics *stats;
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800480 stats = (void *)&pkt->data;
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700481 flag = &stats->flag;
482 common = &stats->general.common;
483 rx_non_phy = &stats->rx.general.common;
484 rx_ofdm = &stats->rx.ofdm;
485 rx_ofdm_ht = &stats->rx.ofdm_ht;
486 rx_cck = &stats->rx.cck;
487 tx = &stats->tx;
488 bt_activity = &stats->general.activity;
489
490#ifdef CONFIG_IWLWIFI_DEBUGFS
491 /* handle this exception directly */
492 priv->statistics.num_bt_kills = stats->rx.general.num_bt_kills;
493 le32_add_cpu(&priv->statistics.accum_num_bt_kills,
494 le32_to_cpu(stats->rx.general.num_bt_kills));
495#endif
496 } else if (len == sizeof(struct iwl_notif_statistics)) {
497 struct iwl_notif_statistics *stats;
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800498 stats = (void *)&pkt->data;
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700499 flag = &stats->flag;
500 common = &stats->general.common;
501 rx_non_phy = &stats->rx.general;
502 rx_ofdm = &stats->rx.ofdm;
503 rx_ofdm_ht = &stats->rx.ofdm_ht;
504 rx_cck = &stats->rx.cck;
505 tx = &stats->tx;
506 bt_activity = NULL;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100507 } else {
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700508 WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n",
509 len, sizeof(struct iwl_bt_notif_statistics),
510 sizeof(struct iwl_notif_statistics));
Johannes Berg4ff70fc2012-03-05 11:24:26 -0800511 spin_unlock(&priv->statistics.lock);
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700512 return 0;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100513 }
514
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700515 change = common->temperature != priv->statistics.common.temperature ||
516 (*flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
517 (priv->statistics.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK);
518
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700519 iwlagn_accumulative_statistics(priv, common, rx_non_phy, rx_ofdm,
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700520 rx_ofdm_ht, rx_cck, tx, bt_activity);
521
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700522 iwlagn_recover_from_statistics(priv, rx_ofdm, rx_ofdm_ht, tx, stamp);
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700523
524 priv->statistics.flag = *flag;
525 memcpy(&priv->statistics.common, common, sizeof(*common));
526 memcpy(&priv->statistics.rx_non_phy, rx_non_phy, sizeof(*rx_non_phy));
527 memcpy(&priv->statistics.rx_ofdm, rx_ofdm, sizeof(*rx_ofdm));
528 memcpy(&priv->statistics.rx_ofdm_ht, rx_ofdm_ht, sizeof(*rx_ofdm_ht));
529 memcpy(&priv->statistics.rx_cck, rx_cck, sizeof(*rx_cck));
530 memcpy(&priv->statistics.tx, tx, sizeof(*tx));
531#ifdef CONFIG_IWLWIFI_DEBUGFS
532 if (bt_activity)
533 memcpy(&priv->statistics.bt_activity, bt_activity,
534 sizeof(*bt_activity));
535#endif
536
537 priv->rx_statistics_jiffies = stamp;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100538
Don Fry83626402012-03-07 09:52:37 -0800539 set_bit(STATUS_STATISTICS, &priv->status);
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100540
541 /* Reschedule the statistics timer to occur in
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100542 * reg_recalib_period seconds to ensure we get a
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100543 * thermal update even if the uCode doesn't give
544 * us one */
545 mod_timer(&priv->statistics_periodic, jiffies +
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100546 msecs_to_jiffies(reg_recalib_period * 1000));
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100547
Don Fry83626402012-03-07 09:52:37 -0800548 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100549 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700550 iwlagn_rx_calc_noise(priv);
Johannes Berg1ee158d2012-02-17 10:07:44 -0800551 queue_work(priv->workqueue, &priv->run_time_calib_work);
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100552 }
Johannes Berge9676692012-04-10 14:10:28 -0700553 if (priv->lib->temperature && change)
554 priv->lib->temperature(priv);
Johannes Berg4ff70fc2012-03-05 11:24:26 -0800555
556 spin_unlock(&priv->statistics.lock);
557
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700558 return 0;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100559}
560
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700561static int iwlagn_rx_reply_statistics(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800562 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700563 struct iwl_device_cmd *cmd)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100564{
565 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800566 struct iwl_notif_statistics *stats = (void *)pkt->data;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100567
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800568 if (le32_to_cpu(stats->flag) & UCODE_STATISTICS_CLEAR_MSK) {
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100569#ifdef CONFIG_IWLWIFI_DEBUGFS
Johannes Berg0da0e5b2011-04-08 08:14:56 -0700570 memset(&priv->accum_stats, 0,
571 sizeof(priv->accum_stats));
572 memset(&priv->delta_stats, 0,
573 sizeof(priv->delta_stats));
574 memset(&priv->max_delta_stats, 0,
575 sizeof(priv->max_delta_stats));
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100576#endif
577 IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
578 }
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700579 iwlagn_rx_statistics(priv, rxb, cmd);
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700580 return 0;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100581}
582
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100583/* Handle notification from uCode that card's power state is changing
584 * due to software, hardware, or critical temperature RFKILL */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700585static int iwlagn_rx_card_state_notif(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800586 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700587 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100588{
589 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800590 struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
591 u32 flags = le32_to_cpu(card_state_notif->flags);
Don Fry1353a7b2012-03-07 09:52:43 -0800592 unsigned long status = priv->status;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100593
594 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n",
595 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
596 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
597 (flags & CT_CARD_DISABLED) ?
598 "Reached" : "Not reached");
599
600 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
601 CT_CARD_DISABLED)) {
602
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700603 iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_SET,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100604 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
605
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700606 iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100607 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
608
609 if (!(flags & RXON_CARD_DISABLED)) {
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700610 iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100611 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700612 iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100613 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
614 }
615 if (flags & CT_CARD_DISABLED)
616 iwl_tt_enter_ct_kill(priv);
617 }
618 if (!(flags & CT_CARD_DISABLED))
619 iwl_tt_exit_ct_kill(priv);
620
621 if (flags & HW_CARD_DISABLED)
Don Fry83626402012-03-07 09:52:37 -0800622 set_bit(STATUS_RF_KILL_HW, &priv->status);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100623 else
Don Fry83626402012-03-07 09:52:37 -0800624 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100625
626
627 if (!(flags & RXON_CARD_DISABLED))
628 iwl_scan_cancel(priv);
629
630 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
Don Fry83626402012-03-07 09:52:37 -0800631 test_bit(STATUS_RF_KILL_HW, &priv->status)))
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100632 wiphy_rfkill_set_hw_state(priv->hw->wiphy,
Don Fry83626402012-03-07 09:52:37 -0800633 test_bit(STATUS_RF_KILL_HW, &priv->status));
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100634 else
Emmanuel Grumbach68e8dfd2012-04-18 07:28:17 -0700635 wake_up(&priv->trans->wait_command_queue);
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700636 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100637}
638
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700639static int iwlagn_rx_missed_beacon_notif(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800640 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700641 struct iwl_device_cmd *cmd)
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100642
643{
644 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800645 struct iwl_missed_beacon_notif *missed_beacon = (void *)pkt->data;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100646
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100647 if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) >
648 priv->missed_beacon_threshold) {
649 IWL_DEBUG_CALIB(priv,
650 "missed bcn cnsq %d totl %d rcd %d expctd %d\n",
651 le32_to_cpu(missed_beacon->consecutive_missed_beacons),
652 le32_to_cpu(missed_beacon->total_missed_becons),
653 le32_to_cpu(missed_beacon->num_recvd_beacons),
654 le32_to_cpu(missed_beacon->num_expected_beacons));
Don Fry83626402012-03-07 09:52:37 -0800655 if (!test_bit(STATUS_SCANNING, &priv->status))
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100656 iwl_init_sensitivity(priv);
657 }
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700658 return 0;
Stanislaw Gruszka67289942011-02-28 14:33:17 +0100659}
660
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100661/* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
662 * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700663static int iwlagn_rx_reply_rx_phy(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800664 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700665 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100666{
667 struct iwl_rx_packet *pkt = rxb_addr(rxb);
668
Wey-Yi Guy898ed672011-07-13 08:38:57 -0700669 priv->last_phy_res_valid = true;
Johannes Bergf8d7c1a2012-03-06 13:31:02 -0800670 memcpy(&priv->last_phy_res, pkt->data,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100671 sizeof(struct iwl_rx_phy_res));
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700672 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100673}
674
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800675/*
676 * returns non-zero if packet should be dropped
677 */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700678static int iwlagn_set_decrypted_flag(struct iwl_priv *priv,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100679 struct ieee80211_hdr *hdr,
680 u32 decrypt_res,
681 struct ieee80211_rx_status *stats)
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800682{
683 u16 fc = le16_to_cpu(hdr->frame_control);
684
Johannes Berg246ed352010-08-23 10:46:32 +0200685 /*
686 * All contexts have the same setting here due to it being
687 * a module parameter, so OK to check any context.
688 */
689 if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags &
690 RXON_FILTER_DIS_DECRYPT_MSK)
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800691 return 0;
692
693 if (!(fc & IEEE80211_FCTL_PROTECTED))
694 return 0;
695
Tomas Winklere1623442009-01-27 14:27:56 -0800696 IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res);
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800697 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
698 case RX_RES_STATUS_SEC_TYPE_TKIP:
699 /* The uCode has got a bad phase 1 Key, pushes the packet.
700 * Decryption will be done in SW. */
701 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
702 RX_RES_STATUS_BAD_KEY_TTAK)
703 break;
704
705 case RX_RES_STATUS_SEC_TYPE_WEP:
706 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
707 RX_RES_STATUS_BAD_ICV_MIC) {
708 /* bad ICV, the packet is destroyed since the
709 * decryption is inplace, drop it */
Tomas Winklere1623442009-01-27 14:27:56 -0800710 IWL_DEBUG_RX(priv, "Packet destroyed\n");
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800711 return -1;
712 }
713 case RX_RES_STATUS_SEC_TYPE_CCMP:
714 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
715 RX_RES_STATUS_DECRYPT_OK) {
Tomas Winklere1623442009-01-27 14:27:56 -0800716 IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n");
Emmanuel Grumbach1781a072008-06-30 17:23:09 +0800717 stats->flag |= RX_FLAG_DECRYPTED;
718 }
719 break;
720
721 default:
722 break;
723 }
724 return 0;
725}
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100726
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700727static void iwlagn_pass_packet_to_mac80211(struct iwl_priv *priv,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100728 struct ieee80211_hdr *hdr,
729 u16 len,
730 u32 ampdu_status,
Johannes Berg48a2d662012-03-05 11:24:39 -0800731 struct iwl_rx_cmd_buffer *rxb,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100732 struct ieee80211_rx_status *stats)
733{
734 struct sk_buff *skb;
735 __le16 fc = hdr->frame_control;
Garen Tamrazian68b99312011-03-30 02:29:32 -0700736 struct iwl_rxon_context *ctx;
Eric Dumazeted905422012-03-24 00:29:46 -0400737 unsigned int hdrlen, fraglen;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100738
739 /* We only process data packets if the interface is open */
740 if (unlikely(!priv->is_open)) {
741 IWL_DEBUG_DROP_LIMIT(priv,
742 "Dropping packet while interface is not open.\n");
743 return;
744 }
745
746 /* In case of HW accelerated crypto and bad decryption, drop */
Johannes Berg65de7e82012-04-17 07:36:30 -0700747 if (!iwlwifi_mod_params.sw_crypto &&
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700748 iwlagn_set_decrypted_flag(priv, hdr, ampdu_status, stats))
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100749 return;
750
Eric Dumazeted905422012-03-24 00:29:46 -0400751 /* Dont use dev_alloc_skb(), we'll have enough headroom once
752 * ieee80211_hdr pulled.
753 */
754 skb = alloc_skb(128, GFP_ATOMIC);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100755 if (!skb) {
Eric Dumazeted905422012-03-24 00:29:46 -0400756 IWL_ERR(priv, "alloc_skb failed\n");
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100757 return;
758 }
Eric Dumazet56138f52012-05-18 04:48:33 +0000759 /* If frame is small enough to fit in skb->head, pull it completely.
760 * If not, only pull ieee80211_hdr so that splice() or TCP coalesce
761 * are more efficient.
762 */
763 hdrlen = (len <= skb_tailroom(skb)) ? len : sizeof(*hdr);
764
Eric Dumazeted905422012-03-24 00:29:46 -0400765 memcpy(skb_put(skb, hdrlen), hdr, hdrlen);
766 fraglen = len - hdrlen;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100767
Eric Dumazeted905422012-03-24 00:29:46 -0400768 if (fraglen) {
John W. Linville341352d2012-05-08 22:18:09 -0400769 int offset = (void *)hdr + hdrlen -
770 rxb_addr(rxb) + rxb_offset(rxb);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100771
Eric Dumazeted905422012-03-24 00:29:46 -0400772 skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset,
773 fraglen, rxb->truesize);
774 }
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100775
Garen Tamrazian68b99312011-03-30 02:29:32 -0700776 /*
777 * Wake any queues that were stopped due to a passive channel tx
778 * failure. This can happen because the regulatory enforcement in
779 * the device waits for a beacon before allowing transmission,
780 * sometimes even after already having transmitted frames for the
781 * association because the new RXON may reset the information.
782 */
Johannes Berge755f882012-03-07 09:52:16 -0800783 if (unlikely(ieee80211_is_beacon(fc) && priv->passive_no_rx)) {
Garen Tamrazian68b99312011-03-30 02:29:32 -0700784 for_each_context(priv, ctx) {
Joe Perches2e42e472012-05-09 17:17:46 +0000785 if (!ether_addr_equal(hdr->addr3,
786 ctx->active.bssid_addr))
Garen Tamrazian68b99312011-03-30 02:29:32 -0700787 continue;
Johannes Berge755f882012-03-07 09:52:16 -0800788 iwlagn_lift_passive_no_rx(priv);
Garen Tamrazian68b99312011-03-30 02:29:32 -0700789 }
790 }
791
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100792 memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
793
794 ieee80211_rx(priv->hw, skb);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100795}
796
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700797static u32 iwlagn_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100798{
799 u32 decrypt_out = 0;
800
801 if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
802 RX_RES_STATUS_STATION_FOUND)
803 decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
804 RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
805
806 decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
807
808 /* packet was not encrypted */
809 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
810 RX_RES_STATUS_SEC_TYPE_NONE)
811 return decrypt_out;
812
813 /* packet was encrypted with unknown alg */
814 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
815 RX_RES_STATUS_SEC_TYPE_ERR)
816 return decrypt_out;
817
818 /* decryption was not done in HW */
819 if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
820 RX_MPDU_RES_STATUS_DEC_DONE_MSK)
821 return decrypt_out;
822
823 switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
824
825 case RX_RES_STATUS_SEC_TYPE_CCMP:
826 /* alg is CCM: check MIC only */
827 if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
828 /* Bad MIC */
829 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
830 else
831 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
832
833 break;
834
835 case RX_RES_STATUS_SEC_TYPE_TKIP:
836 if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
837 /* Bad TTAK */
838 decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
839 break;
840 }
841 /* fall through if TTAK OK */
842 default:
843 if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
844 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
845 else
846 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
847 break;
848 }
849
850 IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n",
851 decrypt_in, decrypt_out);
852
853 return decrypt_out;
854}
855
Don Fry5c3d29f2011-07-08 08:46:29 -0700856/* Calc max signal level (dBm) among 3 possible receivers */
857static int iwlagn_calc_rssi(struct iwl_priv *priv,
858 struct iwl_rx_phy_res *rx_resp)
859{
860 /* data from PHY/DSP regarding signal strength, etc.,
861 * contents are always there, not configurable by host
862 */
863 struct iwlagn_non_cfg_phy *ncphy =
864 (struct iwlagn_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
865 u32 val, rssi_a, rssi_b, rssi_c, max_rssi;
866 u8 agc;
867
868 val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_AGC_IDX]);
869 agc = (val & IWLAGN_OFDM_AGC_MSK) >> IWLAGN_OFDM_AGC_BIT_POS;
870
871 /* Find max rssi among 3 possible receivers.
872 * These values are measured by the digital signal processor (DSP).
873 * They should stay fairly constant even as the signal strength varies,
874 * if the radio's automatic gain control (AGC) is working right.
875 * AGC value (see below) will provide the "interesting" info.
876 */
877 val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_AB_IDX]);
878 rssi_a = (val & IWLAGN_OFDM_RSSI_INBAND_A_BITMSK) >>
879 IWLAGN_OFDM_RSSI_A_BIT_POS;
880 rssi_b = (val & IWLAGN_OFDM_RSSI_INBAND_B_BITMSK) >>
881 IWLAGN_OFDM_RSSI_B_BIT_POS;
882 val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_C_IDX]);
883 rssi_c = (val & IWLAGN_OFDM_RSSI_INBAND_C_BITMSK) >>
884 IWLAGN_OFDM_RSSI_C_BIT_POS;
885
886 max_rssi = max_t(u32, rssi_a, rssi_b);
887 max_rssi = max_t(u32, max_rssi, rssi_c);
888
889 IWL_DEBUG_STATS(priv, "Rssi In A %d B %d C %d Max %d AGC dB %d\n",
890 rssi_a, rssi_b, rssi_c, max_rssi, agc);
891
892 /* dBm = max_rssi dB - agc dB - constant.
893 * Higher AGC (higher radio gain) means lower signal. */
894 return max_rssi - agc - IWLAGN_RSSI_OFFSET;
895}
896
Emmanuel Grumbach6d044b92012-07-05 17:31:56 +0300897/* Called for REPLY_RX_MPDU_CMD */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700898static int iwlagn_rx_reply_rx(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -0800899 struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700900 struct iwl_device_cmd *cmd)
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100901{
902 struct ieee80211_hdr *header;
903 struct ieee80211_rx_status rx_status;
904 struct iwl_rx_packet *pkt = rxb_addr(rxb);
905 struct iwl_rx_phy_res *phy_res;
906 __le32 rx_pkt_status;
907 struct iwl_rx_mpdu_res_start *amsdu;
908 u32 len;
909 u32 ampdu_status;
910 u32 rate_n_flags;
911
Emmanuel Grumbach6d044b92012-07-05 17:31:56 +0300912 if (!priv->last_phy_res_valid) {
913 IWL_ERR(priv, "MPDU frame without cached PHY data\n");
914 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100915 }
Emmanuel Grumbach6d044b92012-07-05 17:31:56 +0300916 phy_res = &priv->last_phy_res;
917 amsdu = (struct iwl_rx_mpdu_res_start *)pkt->data;
918 header = (struct ieee80211_hdr *)(pkt->data + sizeof(*amsdu));
919 len = le16_to_cpu(amsdu->byte_count);
920 rx_pkt_status = *(__le32 *)(pkt->data + sizeof(*amsdu) + len);
921 ampdu_status = iwlagn_translate_rx_status(priv,
922 le32_to_cpu(rx_pkt_status));
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100923
924 if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
Johannes Berg0ca24da2012-03-15 13:26:46 -0700925 IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d\n",
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100926 phy_res->cfg_phy_cnt);
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700927 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100928 }
929
930 if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
931 !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
932 IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n",
933 le32_to_cpu(rx_pkt_status));
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700934 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100935 }
936
937 /* This will be used in several places later */
938 rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
939
940 /* rx_status carries information about the packet to mac80211 */
941 rx_status.mactime = le64_to_cpu(phy_res->timestamp);
942 rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
943 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
944 rx_status.freq =
945 ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel),
946 rx_status.band);
947 rx_status.rate_idx =
948 iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
949 rx_status.flag = 0;
950
951 /* TSF isn't reliable. In order to allow smooth user experience,
952 * this W/A doesn't propagate it to the mac80211 */
953 /*rx_status.flag |= RX_FLAG_MACTIME_MPDU;*/
954
955 priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
956
957 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
Don Fry5c3d29f2011-07-08 08:46:29 -0700958 rx_status.signal = iwlagn_calc_rssi(priv, phy_res);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100959
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100960 IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n",
961 rx_status.signal, (unsigned long long)rx_status.mactime);
962
963 /*
964 * "antenna number"
965 *
966 * It seems that the antenna field in the phy flags value
967 * is actually a bit field. This is undefined by radiotap,
968 * it wants an actual antenna number but I always get "7"
969 * for most legacy frames I receive indicating that the
970 * same frame was received on all three RX chains.
971 *
972 * I think this field should be removed in favor of a
973 * new 802.11n radiotap field "RX chains" that is defined
974 * as a bitmask.
975 */
976 rx_status.antenna =
977 (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK)
978 >> RX_RES_PHY_FLAGS_ANTENNA_POS;
979
980 /* set the preamble flag if appropriate */
981 if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
982 rx_status.flag |= RX_FLAG_SHORTPRE;
983
984 /* Set up the HT phy flags */
985 if (rate_n_flags & RATE_MCS_HT_MSK)
986 rx_status.flag |= RX_FLAG_HT;
987 if (rate_n_flags & RATE_MCS_HT40_MSK)
988 rx_status.flag |= RX_FLAG_40MHZ;
989 if (rate_n_flags & RATE_MCS_SGI_MSK)
990 rx_status.flag |= RX_FLAG_SHORT_GI;
Johannes Berg53e11162012-05-16 23:59:03 +0200991 if (rate_n_flags & RATE_MCS_GF_MSK)
992 rx_status.flag |= RX_FLAG_HT_GF;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100993
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -0700994 iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status,
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100995 rxb, &rx_status);
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -0700996 return 0;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +0100997}
998
Johannes Berg79d3eef2011-11-10 06:55:01 -0800999static int iwlagn_rx_noa_notification(struct iwl_priv *priv,
Johannes Berg48a2d662012-03-05 11:24:39 -08001000 struct iwl_rx_cmd_buffer *rxb,
Johannes Berg79d3eef2011-11-10 06:55:01 -08001001 struct iwl_device_cmd *cmd)
1002{
1003 struct iwl_wipan_noa_data *new_data, *old_data;
1004 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Johannes Bergf8d7c1a2012-03-06 13:31:02 -08001005 struct iwl_wipan_noa_notification *noa_notif = (void *)pkt->data;
Johannes Berg79d3eef2011-11-10 06:55:01 -08001006
1007 /* no condition -- we're in softirq */
1008 old_data = rcu_dereference_protected(priv->noa_data, true);
1009
1010 if (noa_notif->noa_active) {
1011 u32 len = le16_to_cpu(noa_notif->noa_attribute.length);
1012 u32 copylen = len;
1013
1014 /* EID, len, OUI, subtype */
1015 len += 1 + 1 + 3 + 1;
1016 /* P2P id, P2P length */
1017 len += 1 + 2;
1018 copylen += 1 + 2;
1019
1020 new_data = kmalloc(sizeof(*new_data) + len, GFP_ATOMIC);
1021 if (new_data) {
1022 new_data->length = len;
1023 new_data->data[0] = WLAN_EID_VENDOR_SPECIFIC;
1024 new_data->data[1] = len - 2; /* not counting EID, len */
1025 new_data->data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
1026 new_data->data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
1027 new_data->data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
1028 new_data->data[5] = WLAN_OUI_TYPE_WFA_P2P;
1029 memcpy(&new_data->data[6], &noa_notif->noa_attribute,
1030 copylen);
1031 }
1032 } else
1033 new_data = NULL;
1034
1035 rcu_assign_pointer(priv->noa_data, new_data);
1036
1037 if (old_data)
1038 kfree_rcu(old_data, rcu_head);
1039
1040 return 0;
1041}
1042
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001043/**
1044 * iwl_setup_rx_handlers - Initialize Rx handler callbacks
1045 *
1046 * Setup the RX handlers for each of the reply types sent from the uCode
1047 * to the host.
1048 */
1049void iwl_setup_rx_handlers(struct iwl_priv *priv)
1050{
Johannes Berg48a2d662012-03-05 11:24:39 -08001051 int (**handlers)(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb,
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -07001052 struct iwl_device_cmd *cmd);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001053
1054 handlers = priv->rx_handlers;
1055
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -07001056 handlers[REPLY_ERROR] = iwlagn_rx_reply_error;
1057 handlers[CHANNEL_SWITCH_NOTIFICATION] = iwlagn_rx_csa;
1058 handlers[SPECTRUM_MEASURE_NOTIFICATION] =
1059 iwlagn_rx_spectrum_measure_notif;
1060 handlers[PM_SLEEP_NOTIFICATION] = iwlagn_rx_pm_sleep_notif;
1061 handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
1062 iwlagn_rx_pm_debug_statistics_notif;
1063 handlers[BEACON_NOTIFICATION] = iwlagn_rx_beacon_notif;
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -07001064 handlers[REPLY_ADD_STA] = iwl_add_sta_callback;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001065
Johannes Berg79d3eef2011-11-10 06:55:01 -08001066 handlers[REPLY_WIPAN_NOA_NOTIFICATION] = iwlagn_rx_noa_notification;
1067
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001068 /*
1069 * The same handler is used for both the REPLY to a discrete
1070 * statistics request from the host as well as for the periodic
1071 * statistics notifications (after received beacons) from the uCode.
1072 */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -07001073 handlers[REPLY_STATISTICS_CMD] = iwlagn_rx_reply_statistics;
1074 handlers[STATISTICS_NOTIFICATION] = iwlagn_rx_statistics;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001075
1076 iwl_setup_rx_scan_handlers(priv);
1077
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -07001078 handlers[CARD_STATE_NOTIFICATION] = iwlagn_rx_card_state_notif;
1079 handlers[MISSED_BEACONS_NOTIFICATION] =
1080 iwlagn_rx_missed_beacon_notif;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001081
1082 /* Rx handlers */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -07001083 handlers[REPLY_RX_PHY_CMD] = iwlagn_rx_reply_rx_phy;
1084 handlers[REPLY_RX_MPDU_CMD] = iwlagn_rx_reply_rx;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001085
1086 /* block ack */
Wey-Yi Guy3246c4e2011-10-10 07:27:13 -07001087 handlers[REPLY_COMPRESSED_BA] =
1088 iwlagn_rx_reply_compressed_ba;
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001089
Emmanuel Grumbach8d301192011-07-03 15:45:34 +03001090 priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx;
1091
1092 /* set up notification wait support */
Johannes Berg4bd14dd2012-03-06 13:30:58 -08001093 iwl_notification_wait_init(&priv->notif_wait);
Emmanuel Grumbach8d301192011-07-03 15:45:34 +03001094
1095 /* Set up BT Rx handlers */
Emmanuel Grumbach21522682012-03-22 17:51:44 +02001096 if (priv->cfg->bt_params)
Johannes Berg562f08e2012-03-07 09:52:18 -08001097 iwlagn_bt_rx_handler_setup(priv);
Stanislaw Gruszka466a19a2011-03-04 17:51:49 +01001098}
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001099
Johannes Berg48a2d662012-03-05 11:24:39 -08001100int iwl_rx_dispatch(struct iwl_op_mode *op_mode, struct iwl_rx_cmd_buffer *rxb,
1101 struct iwl_device_cmd *cmd)
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001102{
1103 struct iwl_rx_packet *pkt = rxb_addr(rxb);
Emmanuel Grumbachdb70f292012-02-09 16:08:15 +02001104 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -07001105 int err = 0;
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001106
1107 /*
1108 * Do the notification wait before RX handlers so
1109 * even if the RX handler consumes the RXB we have
1110 * access to it in the notification wait entry.
1111 */
Johannes Berg4bd14dd2012-03-06 13:30:58 -08001112 iwl_notification_wait_notify(&priv->notif_wait, pkt);
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001113
Ilan Peer3a6490c2012-06-03 13:36:51 +03001114#ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
1115 /*
1116 * RX data may be forwarded to userspace in one
1117 * of two cases: the user owns the fw through testmode or when
1118 * the user requested to monitor the rx w/o affecting the regular flow.
1119 * In these cases the iwl_test object will handle forwarding the rx
1120 * data to user space.
1121 * Note that if the ownership flag != IWL_OWNERSHIP_TM the flow
Amit Beka0aef8dd2012-03-07 09:52:29 -08001122 * continues.
Amit Beka0aef8dd2012-03-07 09:52:29 -08001123 */
Ilan Peerc76fe6d2012-06-04 19:39:30 +03001124 iwl_test_rx(&priv->tst, rxb);
Ilan Peer3a6490c2012-06-03 13:36:51 +03001125#endif
1126
Amit Beka0aef8dd2012-03-07 09:52:29 -08001127 if (priv->ucode_owner != IWL_OWNERSHIP_TM) {
Wey-Yi Guy64eeacb2011-12-16 09:31:14 -08001128 /* Based on type of command response or notification,
1129 * handle those that need handling via function in
1130 * rx_handlers table. See iwl_setup_rx_handlers() */
1131 if (priv->rx_handlers[pkt->hdr.cmd]) {
1132 priv->rx_handlers_stats[pkt->hdr.cmd]++;
1133 err = priv->rx_handlers[pkt->hdr.cmd] (priv, rxb, cmd);
1134 } else {
1135 /* No handling needed */
Johannes Bergd9fb6462012-03-26 08:23:39 -07001136 IWL_DEBUG_RX(priv, "No handler needed for %s, 0x%02x\n",
1137 iwl_dvm_get_cmd_string(pkt->hdr.cmd),
1138 pkt->hdr.cmd);
Wey-Yi Guy64eeacb2011-12-16 09:31:14 -08001139 }
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001140 }
Emmanuel Grumbach247c61d2011-09-20 15:37:23 -07001141 return err;
Emmanuel Grumbach1ab9f6c2011-07-07 07:59:02 -07001142}