1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /******************************************************************************
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
5*4882a593Smuzhiyun * Copyright(c) 2015 Intel Deutschland GmbH
6*4882a593Smuzhiyun * Copyright(c) 2018 Intel Corporation
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Portions of this file are derived from the ipw3945 project, as well
9*4882a593Smuzhiyun * as portionhelp of the ieee80211 subsystem header files.
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * Contact Information:
12*4882a593Smuzhiyun * Intel Linux Wireless <linuxwifi@intel.com>
13*4882a593Smuzhiyun * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun *****************************************************************************/
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #include <linux/etherdevice.h>
18*4882a593Smuzhiyun #include <linux/slab.h>
19*4882a593Smuzhiyun #include <linux/sched.h>
20*4882a593Smuzhiyun #include <net/mac80211.h>
21*4882a593Smuzhiyun #include <asm/unaligned.h>
22*4882a593Smuzhiyun
23*4882a593Smuzhiyun #include "iwl-trans.h"
24*4882a593Smuzhiyun #include "iwl-io.h"
25*4882a593Smuzhiyun #include "dev.h"
26*4882a593Smuzhiyun #include "calib.h"
27*4882a593Smuzhiyun #include "agn.h"
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun /******************************************************************************
30*4882a593Smuzhiyun *
31*4882a593Smuzhiyun * Generic RX handler implementations
32*4882a593Smuzhiyun *
33*4882a593Smuzhiyun ******************************************************************************/
34*4882a593Smuzhiyun
iwlagn_rx_reply_error(struct iwl_priv * priv,struct iwl_rx_cmd_buffer * rxb)35*4882a593Smuzhiyun static void iwlagn_rx_reply_error(struct iwl_priv *priv,
36*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb)
37*4882a593Smuzhiyun {
38*4882a593Smuzhiyun struct iwl_rx_packet *pkt = rxb_addr(rxb);
39*4882a593Smuzhiyun struct iwl_error_resp *err_resp = (void *)pkt->data;
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun IWL_ERR(priv, "Error Reply type 0x%08X cmd REPLY_ERROR (0x%02X) "
42*4882a593Smuzhiyun "seq 0x%04X ser 0x%08X\n",
43*4882a593Smuzhiyun le32_to_cpu(err_resp->error_type),
44*4882a593Smuzhiyun err_resp->cmd_id,
45*4882a593Smuzhiyun le16_to_cpu(err_resp->bad_cmd_seq_num),
46*4882a593Smuzhiyun le32_to_cpu(err_resp->error_info));
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun
iwlagn_rx_csa(struct iwl_priv * priv,struct iwl_rx_cmd_buffer * rxb)49*4882a593Smuzhiyun static void iwlagn_rx_csa(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb)
50*4882a593Smuzhiyun {
51*4882a593Smuzhiyun struct iwl_rx_packet *pkt = rxb_addr(rxb);
52*4882a593Smuzhiyun struct iwl_csa_notification *csa = (void *)pkt->data;
53*4882a593Smuzhiyun /*
54*4882a593Smuzhiyun * MULTI-FIXME
55*4882a593Smuzhiyun * See iwlagn_mac_channel_switch.
56*4882a593Smuzhiyun */
57*4882a593Smuzhiyun struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
58*4882a593Smuzhiyun struct iwl_rxon_cmd *rxon = (void *)&ctx->active;
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun if (!test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
61*4882a593Smuzhiyun return;
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun if (!le32_to_cpu(csa->status) && csa->channel == priv->switch_channel) {
64*4882a593Smuzhiyun rxon->channel = csa->channel;
65*4882a593Smuzhiyun ctx->staging.channel = csa->channel;
66*4882a593Smuzhiyun IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
67*4882a593Smuzhiyun le16_to_cpu(csa->channel));
68*4882a593Smuzhiyun iwl_chswitch_done(priv, true);
69*4882a593Smuzhiyun } else {
70*4882a593Smuzhiyun IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
71*4882a593Smuzhiyun le16_to_cpu(csa->channel));
72*4882a593Smuzhiyun iwl_chswitch_done(priv, false);
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun }
75*4882a593Smuzhiyun
76*4882a593Smuzhiyun
iwlagn_rx_spectrum_measure_notif(struct iwl_priv * priv,struct iwl_rx_cmd_buffer * rxb)77*4882a593Smuzhiyun static void iwlagn_rx_spectrum_measure_notif(struct iwl_priv *priv,
78*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb)
79*4882a593Smuzhiyun {
80*4882a593Smuzhiyun struct iwl_rx_packet *pkt = rxb_addr(rxb);
81*4882a593Smuzhiyun struct iwl_spectrum_notification *report = (void *)pkt->data;
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun if (!report->state) {
84*4882a593Smuzhiyun IWL_DEBUG_11H(priv,
85*4882a593Smuzhiyun "Spectrum Measure Notification: Start\n");
86*4882a593Smuzhiyun return;
87*4882a593Smuzhiyun }
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun memcpy(&priv->measure_report, report, sizeof(*report));
90*4882a593Smuzhiyun priv->measurement_status |= MEASUREMENT_READY;
91*4882a593Smuzhiyun }
92*4882a593Smuzhiyun
iwlagn_rx_pm_sleep_notif(struct iwl_priv * priv,struct iwl_rx_cmd_buffer * rxb)93*4882a593Smuzhiyun static void iwlagn_rx_pm_sleep_notif(struct iwl_priv *priv,
94*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb)
95*4882a593Smuzhiyun {
96*4882a593Smuzhiyun #ifdef CONFIG_IWLWIFI_DEBUG
97*4882a593Smuzhiyun struct iwl_rx_packet *pkt = rxb_addr(rxb);
98*4882a593Smuzhiyun struct iwl_sleep_notification *sleep = (void *)pkt->data;
99*4882a593Smuzhiyun IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
100*4882a593Smuzhiyun sleep->pm_sleep_mode, sleep->pm_wakeup_src);
101*4882a593Smuzhiyun #endif
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun
iwlagn_rx_pm_debug_statistics_notif(struct iwl_priv * priv,struct iwl_rx_cmd_buffer * rxb)104*4882a593Smuzhiyun static void iwlagn_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
105*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb)
106*4882a593Smuzhiyun {
107*4882a593Smuzhiyun struct iwl_rx_packet *pkt = rxb_addr(rxb);
108*4882a593Smuzhiyun u32 __maybe_unused len = iwl_rx_packet_len(pkt);
109*4882a593Smuzhiyun IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
110*4882a593Smuzhiyun "notification for PM_DEBUG_STATISTIC_NOTIFIC:\n", len);
111*4882a593Smuzhiyun iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->data, len);
112*4882a593Smuzhiyun }
113*4882a593Smuzhiyun
iwlagn_rx_beacon_notif(struct iwl_priv * priv,struct iwl_rx_cmd_buffer * rxb)114*4882a593Smuzhiyun static void iwlagn_rx_beacon_notif(struct iwl_priv *priv,
115*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb)
116*4882a593Smuzhiyun {
117*4882a593Smuzhiyun struct iwl_rx_packet *pkt = rxb_addr(rxb);
118*4882a593Smuzhiyun struct iwlagn_beacon_notif *beacon = (void *)pkt->data;
119*4882a593Smuzhiyun #ifdef CONFIG_IWLWIFI_DEBUG
120*4882a593Smuzhiyun u16 status = le16_to_cpu(beacon->beacon_notify_hdr.status.status);
121*4882a593Smuzhiyun u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun IWL_DEBUG_RX(priv, "beacon status %#x, retries:%d ibssmgr:%d "
124*4882a593Smuzhiyun "tsf:0x%.8x%.8x rate:%d\n",
125*4882a593Smuzhiyun status & TX_STATUS_MSK,
126*4882a593Smuzhiyun beacon->beacon_notify_hdr.failure_frame,
127*4882a593Smuzhiyun le32_to_cpu(beacon->ibss_mgr_status),
128*4882a593Smuzhiyun le32_to_cpu(beacon->high_tsf),
129*4882a593Smuzhiyun le32_to_cpu(beacon->low_tsf), rate);
130*4882a593Smuzhiyun #endif
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
133*4882a593Smuzhiyun }
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun /*
136*4882a593Smuzhiyun * iwl_good_plcp_health - checks for plcp error.
137*4882a593Smuzhiyun *
138*4882a593Smuzhiyun * When the plcp error is exceeding the thresholds, reset the radio
139*4882a593Smuzhiyun * to improve the throughput.
140*4882a593Smuzhiyun */
iwlagn_good_plcp_health(struct iwl_priv * priv,struct statistics_rx_phy * cur_ofdm,struct statistics_rx_ht_phy * cur_ofdm_ht,unsigned int msecs)141*4882a593Smuzhiyun static bool iwlagn_good_plcp_health(struct iwl_priv *priv,
142*4882a593Smuzhiyun struct statistics_rx_phy *cur_ofdm,
143*4882a593Smuzhiyun struct statistics_rx_ht_phy *cur_ofdm_ht,
144*4882a593Smuzhiyun unsigned int msecs)
145*4882a593Smuzhiyun {
146*4882a593Smuzhiyun int delta;
147*4882a593Smuzhiyun int threshold = priv->plcp_delta_threshold;
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun if (threshold == IWL_MAX_PLCP_ERR_THRESHOLD_DISABLE) {
150*4882a593Smuzhiyun IWL_DEBUG_RADIO(priv, "plcp_err check disabled\n");
151*4882a593Smuzhiyun return true;
152*4882a593Smuzhiyun }
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun delta = le32_to_cpu(cur_ofdm->plcp_err) -
155*4882a593Smuzhiyun le32_to_cpu(priv->statistics.rx_ofdm.plcp_err) +
156*4882a593Smuzhiyun le32_to_cpu(cur_ofdm_ht->plcp_err) -
157*4882a593Smuzhiyun le32_to_cpu(priv->statistics.rx_ofdm_ht.plcp_err);
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun /* Can be negative if firmware reset statistics */
160*4882a593Smuzhiyun if (delta <= 0)
161*4882a593Smuzhiyun return true;
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun if ((delta * 100 / msecs) > threshold) {
164*4882a593Smuzhiyun IWL_DEBUG_RADIO(priv,
165*4882a593Smuzhiyun "plcp health threshold %u delta %d msecs %u\n",
166*4882a593Smuzhiyun threshold, delta, msecs);
167*4882a593Smuzhiyun return false;
168*4882a593Smuzhiyun }
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun return true;
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun
iwl_force_rf_reset(struct iwl_priv * priv,bool external)173*4882a593Smuzhiyun int iwl_force_rf_reset(struct iwl_priv *priv, bool external)
174*4882a593Smuzhiyun {
175*4882a593Smuzhiyun struct iwl_rf_reset *rf_reset;
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun if (test_bit(STATUS_EXIT_PENDING, &priv->status))
178*4882a593Smuzhiyun return -EAGAIN;
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun if (!iwl_is_any_associated(priv)) {
181*4882a593Smuzhiyun IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
182*4882a593Smuzhiyun return -ENOLINK;
183*4882a593Smuzhiyun }
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun rf_reset = &priv->rf_reset;
186*4882a593Smuzhiyun rf_reset->reset_request_count++;
187*4882a593Smuzhiyun if (!external && rf_reset->last_reset_jiffies &&
188*4882a593Smuzhiyun time_after(rf_reset->last_reset_jiffies +
189*4882a593Smuzhiyun IWL_DELAY_NEXT_FORCE_RF_RESET, jiffies)) {
190*4882a593Smuzhiyun IWL_DEBUG_INFO(priv, "RF reset rejected\n");
191*4882a593Smuzhiyun rf_reset->reset_reject_count++;
192*4882a593Smuzhiyun return -EAGAIN;
193*4882a593Smuzhiyun }
194*4882a593Smuzhiyun rf_reset->reset_success_count++;
195*4882a593Smuzhiyun rf_reset->last_reset_jiffies = jiffies;
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun /*
198*4882a593Smuzhiyun * There is no easy and better way to force reset the radio,
199*4882a593Smuzhiyun * the only known method is switching channel which will force to
200*4882a593Smuzhiyun * reset and tune the radio.
201*4882a593Smuzhiyun * Use internal short scan (single channel) operation to should
202*4882a593Smuzhiyun * achieve this objective.
203*4882a593Smuzhiyun * Driver should reset the radio when number of consecutive missed
204*4882a593Smuzhiyun * beacon, or any other uCode error condition detected.
205*4882a593Smuzhiyun */
206*4882a593Smuzhiyun IWL_DEBUG_INFO(priv, "perform radio reset.\n");
207*4882a593Smuzhiyun iwl_internal_short_hw_scan(priv);
208*4882a593Smuzhiyun return 0;
209*4882a593Smuzhiyun }
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun
iwlagn_recover_from_statistics(struct iwl_priv * priv,struct statistics_rx_phy * cur_ofdm,struct statistics_rx_ht_phy * cur_ofdm_ht,struct statistics_tx * tx,unsigned long stamp)212*4882a593Smuzhiyun static void iwlagn_recover_from_statistics(struct iwl_priv *priv,
213*4882a593Smuzhiyun struct statistics_rx_phy *cur_ofdm,
214*4882a593Smuzhiyun struct statistics_rx_ht_phy *cur_ofdm_ht,
215*4882a593Smuzhiyun struct statistics_tx *tx,
216*4882a593Smuzhiyun unsigned long stamp)
217*4882a593Smuzhiyun {
218*4882a593Smuzhiyun unsigned int msecs;
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun if (test_bit(STATUS_EXIT_PENDING, &priv->status))
221*4882a593Smuzhiyun return;
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun msecs = jiffies_to_msecs(stamp - priv->rx_statistics_jiffies);
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun /* Only gather statistics and update time stamp when not associated */
226*4882a593Smuzhiyun if (!iwl_is_any_associated(priv))
227*4882a593Smuzhiyun return;
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun /* Do not check/recover when do not have enough statistics data */
230*4882a593Smuzhiyun if (msecs < 99)
231*4882a593Smuzhiyun return;
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun if (!iwlagn_good_plcp_health(priv, cur_ofdm, cur_ofdm_ht, msecs))
234*4882a593Smuzhiyun iwl_force_rf_reset(priv, false);
235*4882a593Smuzhiyun }
236*4882a593Smuzhiyun
237*4882a593Smuzhiyun /* Calculate noise level, based on measurements during network silence just
238*4882a593Smuzhiyun * before arriving beacon. This measurement can be done only if we know
239*4882a593Smuzhiyun * exactly when to expect beacons, therefore only when we're associated. */
iwlagn_rx_calc_noise(struct iwl_priv * priv)240*4882a593Smuzhiyun static void iwlagn_rx_calc_noise(struct iwl_priv *priv)
241*4882a593Smuzhiyun {
242*4882a593Smuzhiyun struct statistics_rx_non_phy *rx_info;
243*4882a593Smuzhiyun int num_active_rx = 0;
244*4882a593Smuzhiyun int total_silence = 0;
245*4882a593Smuzhiyun int bcn_silence_a, bcn_silence_b, bcn_silence_c;
246*4882a593Smuzhiyun int last_rx_noise;
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun rx_info = &priv->statistics.rx_non_phy;
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun bcn_silence_a =
251*4882a593Smuzhiyun le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
252*4882a593Smuzhiyun bcn_silence_b =
253*4882a593Smuzhiyun le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
254*4882a593Smuzhiyun bcn_silence_c =
255*4882a593Smuzhiyun le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun if (bcn_silence_a) {
258*4882a593Smuzhiyun total_silence += bcn_silence_a;
259*4882a593Smuzhiyun num_active_rx++;
260*4882a593Smuzhiyun }
261*4882a593Smuzhiyun if (bcn_silence_b) {
262*4882a593Smuzhiyun total_silence += bcn_silence_b;
263*4882a593Smuzhiyun num_active_rx++;
264*4882a593Smuzhiyun }
265*4882a593Smuzhiyun if (bcn_silence_c) {
266*4882a593Smuzhiyun total_silence += bcn_silence_c;
267*4882a593Smuzhiyun num_active_rx++;
268*4882a593Smuzhiyun }
269*4882a593Smuzhiyun
270*4882a593Smuzhiyun /* Average among active antennas */
271*4882a593Smuzhiyun if (num_active_rx)
272*4882a593Smuzhiyun last_rx_noise = (total_silence / num_active_rx) - 107;
273*4882a593Smuzhiyun else
274*4882a593Smuzhiyun last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun IWL_DEBUG_CALIB(priv, "inband silence a %u, b %u, c %u, dBm %d\n",
277*4882a593Smuzhiyun bcn_silence_a, bcn_silence_b, bcn_silence_c,
278*4882a593Smuzhiyun last_rx_noise);
279*4882a593Smuzhiyun }
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun #ifdef CONFIG_IWLWIFI_DEBUGFS
282*4882a593Smuzhiyun /*
283*4882a593Smuzhiyun * based on the assumption of all statistics counter are in DWORD
284*4882a593Smuzhiyun * FIXME: This function is for debugging, do not deal with
285*4882a593Smuzhiyun * the case of counters roll-over.
286*4882a593Smuzhiyun */
accum_stats(__le32 * prev,__le32 * cur,__le32 * delta,__le32 * max_delta,__le32 * accum,int size)287*4882a593Smuzhiyun static void accum_stats(__le32 *prev, __le32 *cur, __le32 *delta,
288*4882a593Smuzhiyun __le32 *max_delta, __le32 *accum, int size)
289*4882a593Smuzhiyun {
290*4882a593Smuzhiyun int i;
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun for (i = 0;
293*4882a593Smuzhiyun i < size / sizeof(__le32);
294*4882a593Smuzhiyun i++, prev++, cur++, delta++, max_delta++, accum++) {
295*4882a593Smuzhiyun if (le32_to_cpu(*cur) > le32_to_cpu(*prev)) {
296*4882a593Smuzhiyun *delta = cpu_to_le32(
297*4882a593Smuzhiyun le32_to_cpu(*cur) - le32_to_cpu(*prev));
298*4882a593Smuzhiyun le32_add_cpu(accum, le32_to_cpu(*delta));
299*4882a593Smuzhiyun if (le32_to_cpu(*delta) > le32_to_cpu(*max_delta))
300*4882a593Smuzhiyun *max_delta = *delta;
301*4882a593Smuzhiyun }
302*4882a593Smuzhiyun }
303*4882a593Smuzhiyun }
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun static void
iwlagn_accumulative_statistics(struct iwl_priv * priv,struct statistics_general_common * common,struct statistics_rx_non_phy * rx_non_phy,struct statistics_rx_phy * rx_ofdm,struct statistics_rx_ht_phy * rx_ofdm_ht,struct statistics_rx_phy * rx_cck,struct statistics_tx * tx,struct statistics_bt_activity * bt_activity)306*4882a593Smuzhiyun iwlagn_accumulative_statistics(struct iwl_priv *priv,
307*4882a593Smuzhiyun struct statistics_general_common *common,
308*4882a593Smuzhiyun struct statistics_rx_non_phy *rx_non_phy,
309*4882a593Smuzhiyun struct statistics_rx_phy *rx_ofdm,
310*4882a593Smuzhiyun struct statistics_rx_ht_phy *rx_ofdm_ht,
311*4882a593Smuzhiyun struct statistics_rx_phy *rx_cck,
312*4882a593Smuzhiyun struct statistics_tx *tx,
313*4882a593Smuzhiyun struct statistics_bt_activity *bt_activity)
314*4882a593Smuzhiyun {
315*4882a593Smuzhiyun #define ACCUM(_name) \
316*4882a593Smuzhiyun accum_stats((__le32 *)&priv->statistics._name, \
317*4882a593Smuzhiyun (__le32 *)_name, \
318*4882a593Smuzhiyun (__le32 *)&priv->delta_stats._name, \
319*4882a593Smuzhiyun (__le32 *)&priv->max_delta_stats._name, \
320*4882a593Smuzhiyun (__le32 *)&priv->accum_stats._name, \
321*4882a593Smuzhiyun sizeof(*_name));
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun ACCUM(common);
324*4882a593Smuzhiyun ACCUM(rx_non_phy);
325*4882a593Smuzhiyun ACCUM(rx_ofdm);
326*4882a593Smuzhiyun ACCUM(rx_ofdm_ht);
327*4882a593Smuzhiyun ACCUM(rx_cck);
328*4882a593Smuzhiyun ACCUM(tx);
329*4882a593Smuzhiyun if (bt_activity)
330*4882a593Smuzhiyun ACCUM(bt_activity);
331*4882a593Smuzhiyun #undef ACCUM
332*4882a593Smuzhiyun }
333*4882a593Smuzhiyun #else
334*4882a593Smuzhiyun static inline void
iwlagn_accumulative_statistics(struct iwl_priv * priv,struct statistics_general_common * common,struct statistics_rx_non_phy * rx_non_phy,struct statistics_rx_phy * rx_ofdm,struct statistics_rx_ht_phy * rx_ofdm_ht,struct statistics_rx_phy * rx_cck,struct statistics_tx * tx,struct statistics_bt_activity * bt_activity)335*4882a593Smuzhiyun iwlagn_accumulative_statistics(struct iwl_priv *priv,
336*4882a593Smuzhiyun struct statistics_general_common *common,
337*4882a593Smuzhiyun struct statistics_rx_non_phy *rx_non_phy,
338*4882a593Smuzhiyun struct statistics_rx_phy *rx_ofdm,
339*4882a593Smuzhiyun struct statistics_rx_ht_phy *rx_ofdm_ht,
340*4882a593Smuzhiyun struct statistics_rx_phy *rx_cck,
341*4882a593Smuzhiyun struct statistics_tx *tx,
342*4882a593Smuzhiyun struct statistics_bt_activity *bt_activity)
343*4882a593Smuzhiyun {
344*4882a593Smuzhiyun }
345*4882a593Smuzhiyun #endif
346*4882a593Smuzhiyun
iwlagn_rx_statistics(struct iwl_priv * priv,struct iwl_rx_cmd_buffer * rxb)347*4882a593Smuzhiyun static void iwlagn_rx_statistics(struct iwl_priv *priv,
348*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb)
349*4882a593Smuzhiyun {
350*4882a593Smuzhiyun unsigned long stamp = jiffies;
351*4882a593Smuzhiyun const int reg_recalib_period = 60;
352*4882a593Smuzhiyun int change;
353*4882a593Smuzhiyun struct iwl_rx_packet *pkt = rxb_addr(rxb);
354*4882a593Smuzhiyun u32 len = iwl_rx_packet_payload_len(pkt);
355*4882a593Smuzhiyun __le32 *flag;
356*4882a593Smuzhiyun struct statistics_general_common *common;
357*4882a593Smuzhiyun struct statistics_rx_non_phy *rx_non_phy;
358*4882a593Smuzhiyun struct statistics_rx_phy *rx_ofdm;
359*4882a593Smuzhiyun struct statistics_rx_ht_phy *rx_ofdm_ht;
360*4882a593Smuzhiyun struct statistics_rx_phy *rx_cck;
361*4882a593Smuzhiyun struct statistics_tx *tx;
362*4882a593Smuzhiyun struct statistics_bt_activity *bt_activity;
363*4882a593Smuzhiyun
364*4882a593Smuzhiyun IWL_DEBUG_RX(priv, "Statistics notification received (%d bytes).\n",
365*4882a593Smuzhiyun len);
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun spin_lock(&priv->statistics.lock);
368*4882a593Smuzhiyun
369*4882a593Smuzhiyun if (len == sizeof(struct iwl_bt_notif_statistics)) {
370*4882a593Smuzhiyun struct iwl_bt_notif_statistics *stats;
371*4882a593Smuzhiyun stats = (void *)&pkt->data;
372*4882a593Smuzhiyun flag = &stats->flag;
373*4882a593Smuzhiyun common = &stats->general.common;
374*4882a593Smuzhiyun rx_non_phy = &stats->rx.general.common;
375*4882a593Smuzhiyun rx_ofdm = &stats->rx.ofdm;
376*4882a593Smuzhiyun rx_ofdm_ht = &stats->rx.ofdm_ht;
377*4882a593Smuzhiyun rx_cck = &stats->rx.cck;
378*4882a593Smuzhiyun tx = &stats->tx;
379*4882a593Smuzhiyun bt_activity = &stats->general.activity;
380*4882a593Smuzhiyun
381*4882a593Smuzhiyun #ifdef CONFIG_IWLWIFI_DEBUGFS
382*4882a593Smuzhiyun /* handle this exception directly */
383*4882a593Smuzhiyun priv->statistics.num_bt_kills = stats->rx.general.num_bt_kills;
384*4882a593Smuzhiyun le32_add_cpu(&priv->statistics.accum_num_bt_kills,
385*4882a593Smuzhiyun le32_to_cpu(stats->rx.general.num_bt_kills));
386*4882a593Smuzhiyun #endif
387*4882a593Smuzhiyun } else if (len == sizeof(struct iwl_notif_statistics)) {
388*4882a593Smuzhiyun struct iwl_notif_statistics *stats;
389*4882a593Smuzhiyun stats = (void *)&pkt->data;
390*4882a593Smuzhiyun flag = &stats->flag;
391*4882a593Smuzhiyun common = &stats->general.common;
392*4882a593Smuzhiyun rx_non_phy = &stats->rx.general;
393*4882a593Smuzhiyun rx_ofdm = &stats->rx.ofdm;
394*4882a593Smuzhiyun rx_ofdm_ht = &stats->rx.ofdm_ht;
395*4882a593Smuzhiyun rx_cck = &stats->rx.cck;
396*4882a593Smuzhiyun tx = &stats->tx;
397*4882a593Smuzhiyun bt_activity = NULL;
398*4882a593Smuzhiyun } else {
399*4882a593Smuzhiyun WARN_ONCE(1, "len %d doesn't match BT (%zu) or normal (%zu)\n",
400*4882a593Smuzhiyun len, sizeof(struct iwl_bt_notif_statistics),
401*4882a593Smuzhiyun sizeof(struct iwl_notif_statistics));
402*4882a593Smuzhiyun spin_unlock(&priv->statistics.lock);
403*4882a593Smuzhiyun return;
404*4882a593Smuzhiyun }
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun change = common->temperature != priv->statistics.common.temperature ||
407*4882a593Smuzhiyun (*flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK) !=
408*4882a593Smuzhiyun (priv->statistics.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK);
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun iwlagn_accumulative_statistics(priv, common, rx_non_phy, rx_ofdm,
411*4882a593Smuzhiyun rx_ofdm_ht, rx_cck, tx, bt_activity);
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun iwlagn_recover_from_statistics(priv, rx_ofdm, rx_ofdm_ht, tx, stamp);
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun priv->statistics.flag = *flag;
416*4882a593Smuzhiyun memcpy(&priv->statistics.common, common, sizeof(*common));
417*4882a593Smuzhiyun memcpy(&priv->statistics.rx_non_phy, rx_non_phy, sizeof(*rx_non_phy));
418*4882a593Smuzhiyun memcpy(&priv->statistics.rx_ofdm, rx_ofdm, sizeof(*rx_ofdm));
419*4882a593Smuzhiyun memcpy(&priv->statistics.rx_ofdm_ht, rx_ofdm_ht, sizeof(*rx_ofdm_ht));
420*4882a593Smuzhiyun memcpy(&priv->statistics.rx_cck, rx_cck, sizeof(*rx_cck));
421*4882a593Smuzhiyun memcpy(&priv->statistics.tx, tx, sizeof(*tx));
422*4882a593Smuzhiyun #ifdef CONFIG_IWLWIFI_DEBUGFS
423*4882a593Smuzhiyun if (bt_activity)
424*4882a593Smuzhiyun memcpy(&priv->statistics.bt_activity, bt_activity,
425*4882a593Smuzhiyun sizeof(*bt_activity));
426*4882a593Smuzhiyun #endif
427*4882a593Smuzhiyun
428*4882a593Smuzhiyun priv->rx_statistics_jiffies = stamp;
429*4882a593Smuzhiyun
430*4882a593Smuzhiyun set_bit(STATUS_STATISTICS, &priv->status);
431*4882a593Smuzhiyun
432*4882a593Smuzhiyun /* Reschedule the statistics timer to occur in
433*4882a593Smuzhiyun * reg_recalib_period seconds to ensure we get a
434*4882a593Smuzhiyun * thermal update even if the uCode doesn't give
435*4882a593Smuzhiyun * us one */
436*4882a593Smuzhiyun mod_timer(&priv->statistics_periodic, jiffies +
437*4882a593Smuzhiyun msecs_to_jiffies(reg_recalib_period * 1000));
438*4882a593Smuzhiyun
439*4882a593Smuzhiyun if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
440*4882a593Smuzhiyun (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
441*4882a593Smuzhiyun iwlagn_rx_calc_noise(priv);
442*4882a593Smuzhiyun queue_work(priv->workqueue, &priv->run_time_calib_work);
443*4882a593Smuzhiyun }
444*4882a593Smuzhiyun if (priv->lib->temperature && change)
445*4882a593Smuzhiyun priv->lib->temperature(priv);
446*4882a593Smuzhiyun
447*4882a593Smuzhiyun spin_unlock(&priv->statistics.lock);
448*4882a593Smuzhiyun }
449*4882a593Smuzhiyun
iwlagn_rx_reply_statistics(struct iwl_priv * priv,struct iwl_rx_cmd_buffer * rxb)450*4882a593Smuzhiyun static void iwlagn_rx_reply_statistics(struct iwl_priv *priv,
451*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb)
452*4882a593Smuzhiyun {
453*4882a593Smuzhiyun struct iwl_rx_packet *pkt = rxb_addr(rxb);
454*4882a593Smuzhiyun struct iwl_notif_statistics *stats = (void *)pkt->data;
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun if (le32_to_cpu(stats->flag) & UCODE_STATISTICS_CLEAR_MSK) {
457*4882a593Smuzhiyun #ifdef CONFIG_IWLWIFI_DEBUGFS
458*4882a593Smuzhiyun memset(&priv->accum_stats, 0,
459*4882a593Smuzhiyun sizeof(priv->accum_stats));
460*4882a593Smuzhiyun memset(&priv->delta_stats, 0,
461*4882a593Smuzhiyun sizeof(priv->delta_stats));
462*4882a593Smuzhiyun memset(&priv->max_delta_stats, 0,
463*4882a593Smuzhiyun sizeof(priv->max_delta_stats));
464*4882a593Smuzhiyun #endif
465*4882a593Smuzhiyun IWL_DEBUG_RX(priv, "Statistics have been cleared\n");
466*4882a593Smuzhiyun }
467*4882a593Smuzhiyun
468*4882a593Smuzhiyun iwlagn_rx_statistics(priv, rxb);
469*4882a593Smuzhiyun }
470*4882a593Smuzhiyun
471*4882a593Smuzhiyun /* Handle notification from uCode that card's power state is changing
472*4882a593Smuzhiyun * due to software, hardware, or critical temperature RFKILL */
iwlagn_rx_card_state_notif(struct iwl_priv * priv,struct iwl_rx_cmd_buffer * rxb)473*4882a593Smuzhiyun static void iwlagn_rx_card_state_notif(struct iwl_priv *priv,
474*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb)
475*4882a593Smuzhiyun {
476*4882a593Smuzhiyun struct iwl_rx_packet *pkt = rxb_addr(rxb);
477*4882a593Smuzhiyun struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
478*4882a593Smuzhiyun u32 flags = le32_to_cpu(card_state_notif->flags);
479*4882a593Smuzhiyun unsigned long status = priv->status;
480*4882a593Smuzhiyun
481*4882a593Smuzhiyun IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n",
482*4882a593Smuzhiyun (flags & HW_CARD_DISABLED) ? "Kill" : "On",
483*4882a593Smuzhiyun (flags & SW_CARD_DISABLED) ? "Kill" : "On",
484*4882a593Smuzhiyun (flags & CT_CARD_DISABLED) ?
485*4882a593Smuzhiyun "Reached" : "Not reached");
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
488*4882a593Smuzhiyun CT_CARD_DISABLED)) {
489*4882a593Smuzhiyun
490*4882a593Smuzhiyun iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_SET,
491*4882a593Smuzhiyun CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C,
494*4882a593Smuzhiyun HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun if (!(flags & RXON_CARD_DISABLED)) {
497*4882a593Smuzhiyun iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR,
498*4882a593Smuzhiyun CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
499*4882a593Smuzhiyun iwl_write_direct32(priv->trans, HBUS_TARG_MBX_C,
500*4882a593Smuzhiyun HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
501*4882a593Smuzhiyun }
502*4882a593Smuzhiyun if (flags & CT_CARD_DISABLED)
503*4882a593Smuzhiyun iwl_tt_enter_ct_kill(priv);
504*4882a593Smuzhiyun }
505*4882a593Smuzhiyun if (!(flags & CT_CARD_DISABLED))
506*4882a593Smuzhiyun iwl_tt_exit_ct_kill(priv);
507*4882a593Smuzhiyun
508*4882a593Smuzhiyun if (flags & HW_CARD_DISABLED)
509*4882a593Smuzhiyun set_bit(STATUS_RF_KILL_HW, &priv->status);
510*4882a593Smuzhiyun else
511*4882a593Smuzhiyun clear_bit(STATUS_RF_KILL_HW, &priv->status);
512*4882a593Smuzhiyun
513*4882a593Smuzhiyun
514*4882a593Smuzhiyun if (!(flags & RXON_CARD_DISABLED))
515*4882a593Smuzhiyun iwl_scan_cancel(priv);
516*4882a593Smuzhiyun
517*4882a593Smuzhiyun if ((test_bit(STATUS_RF_KILL_HW, &status) !=
518*4882a593Smuzhiyun test_bit(STATUS_RF_KILL_HW, &priv->status)))
519*4882a593Smuzhiyun wiphy_rfkill_set_hw_state(priv->hw->wiphy,
520*4882a593Smuzhiyun test_bit(STATUS_RF_KILL_HW, &priv->status));
521*4882a593Smuzhiyun }
522*4882a593Smuzhiyun
iwlagn_rx_missed_beacon_notif(struct iwl_priv * priv,struct iwl_rx_cmd_buffer * rxb)523*4882a593Smuzhiyun static void iwlagn_rx_missed_beacon_notif(struct iwl_priv *priv,
524*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb)
525*4882a593Smuzhiyun
526*4882a593Smuzhiyun {
527*4882a593Smuzhiyun struct iwl_rx_packet *pkt = rxb_addr(rxb);
528*4882a593Smuzhiyun struct iwl_missed_beacon_notif *missed_beacon = (void *)pkt->data;
529*4882a593Smuzhiyun
530*4882a593Smuzhiyun if (le32_to_cpu(missed_beacon->consecutive_missed_beacons) >
531*4882a593Smuzhiyun priv->missed_beacon_threshold) {
532*4882a593Smuzhiyun IWL_DEBUG_CALIB(priv,
533*4882a593Smuzhiyun "missed bcn cnsq %d totl %d rcd %d expctd %d\n",
534*4882a593Smuzhiyun le32_to_cpu(missed_beacon->consecutive_missed_beacons),
535*4882a593Smuzhiyun le32_to_cpu(missed_beacon->total_missed_becons),
536*4882a593Smuzhiyun le32_to_cpu(missed_beacon->num_recvd_beacons),
537*4882a593Smuzhiyun le32_to_cpu(missed_beacon->num_expected_beacons));
538*4882a593Smuzhiyun if (!test_bit(STATUS_SCANNING, &priv->status))
539*4882a593Smuzhiyun iwl_init_sensitivity(priv);
540*4882a593Smuzhiyun }
541*4882a593Smuzhiyun }
542*4882a593Smuzhiyun
543*4882a593Smuzhiyun /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
544*4882a593Smuzhiyun * This will be used later in iwl_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
iwlagn_rx_reply_rx_phy(struct iwl_priv * priv,struct iwl_rx_cmd_buffer * rxb)545*4882a593Smuzhiyun static void iwlagn_rx_reply_rx_phy(struct iwl_priv *priv,
546*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb)
547*4882a593Smuzhiyun {
548*4882a593Smuzhiyun struct iwl_rx_packet *pkt = rxb_addr(rxb);
549*4882a593Smuzhiyun
550*4882a593Smuzhiyun priv->last_phy_res_valid = true;
551*4882a593Smuzhiyun priv->ampdu_ref++;
552*4882a593Smuzhiyun memcpy(&priv->last_phy_res, pkt->data,
553*4882a593Smuzhiyun sizeof(struct iwl_rx_phy_res));
554*4882a593Smuzhiyun }
555*4882a593Smuzhiyun
556*4882a593Smuzhiyun /*
557*4882a593Smuzhiyun * returns non-zero if packet should be dropped
558*4882a593Smuzhiyun */
iwlagn_set_decrypted_flag(struct iwl_priv * priv,struct ieee80211_hdr * hdr,u32 decrypt_res,struct ieee80211_rx_status * stats)559*4882a593Smuzhiyun static int iwlagn_set_decrypted_flag(struct iwl_priv *priv,
560*4882a593Smuzhiyun struct ieee80211_hdr *hdr,
561*4882a593Smuzhiyun u32 decrypt_res,
562*4882a593Smuzhiyun struct ieee80211_rx_status *stats)
563*4882a593Smuzhiyun {
564*4882a593Smuzhiyun u16 fc = le16_to_cpu(hdr->frame_control);
565*4882a593Smuzhiyun
566*4882a593Smuzhiyun /*
567*4882a593Smuzhiyun * All contexts have the same setting here due to it being
568*4882a593Smuzhiyun * a module parameter, so OK to check any context.
569*4882a593Smuzhiyun */
570*4882a593Smuzhiyun if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags &
571*4882a593Smuzhiyun RXON_FILTER_DIS_DECRYPT_MSK)
572*4882a593Smuzhiyun return 0;
573*4882a593Smuzhiyun
574*4882a593Smuzhiyun if (!(fc & IEEE80211_FCTL_PROTECTED))
575*4882a593Smuzhiyun return 0;
576*4882a593Smuzhiyun
577*4882a593Smuzhiyun IWL_DEBUG_RX(priv, "decrypt_res:0x%x\n", decrypt_res);
578*4882a593Smuzhiyun switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
579*4882a593Smuzhiyun case RX_RES_STATUS_SEC_TYPE_TKIP:
580*4882a593Smuzhiyun /* The uCode has got a bad phase 1 Key, pushes the packet.
581*4882a593Smuzhiyun * Decryption will be done in SW. */
582*4882a593Smuzhiyun if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
583*4882a593Smuzhiyun RX_RES_STATUS_BAD_KEY_TTAK)
584*4882a593Smuzhiyun break;
585*4882a593Smuzhiyun /* fall through */
586*4882a593Smuzhiyun case RX_RES_STATUS_SEC_TYPE_WEP:
587*4882a593Smuzhiyun if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
588*4882a593Smuzhiyun RX_RES_STATUS_BAD_ICV_MIC) {
589*4882a593Smuzhiyun /* bad ICV, the packet is destroyed since the
590*4882a593Smuzhiyun * decryption is inplace, drop it */
591*4882a593Smuzhiyun IWL_DEBUG_RX(priv, "Packet destroyed\n");
592*4882a593Smuzhiyun return -1;
593*4882a593Smuzhiyun }
594*4882a593Smuzhiyun /* fall through */
595*4882a593Smuzhiyun case RX_RES_STATUS_SEC_TYPE_CCMP:
596*4882a593Smuzhiyun if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
597*4882a593Smuzhiyun RX_RES_STATUS_DECRYPT_OK) {
598*4882a593Smuzhiyun IWL_DEBUG_RX(priv, "hw decrypt successfully!!!\n");
599*4882a593Smuzhiyun stats->flag |= RX_FLAG_DECRYPTED;
600*4882a593Smuzhiyun }
601*4882a593Smuzhiyun break;
602*4882a593Smuzhiyun
603*4882a593Smuzhiyun default:
604*4882a593Smuzhiyun break;
605*4882a593Smuzhiyun }
606*4882a593Smuzhiyun return 0;
607*4882a593Smuzhiyun }
608*4882a593Smuzhiyun
iwlagn_pass_packet_to_mac80211(struct iwl_priv * priv,struct ieee80211_hdr * hdr,u16 len,u32 ampdu_status,struct iwl_rx_cmd_buffer * rxb,struct ieee80211_rx_status * stats)609*4882a593Smuzhiyun static void iwlagn_pass_packet_to_mac80211(struct iwl_priv *priv,
610*4882a593Smuzhiyun struct ieee80211_hdr *hdr,
611*4882a593Smuzhiyun u16 len,
612*4882a593Smuzhiyun u32 ampdu_status,
613*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb,
614*4882a593Smuzhiyun struct ieee80211_rx_status *stats)
615*4882a593Smuzhiyun {
616*4882a593Smuzhiyun struct sk_buff *skb;
617*4882a593Smuzhiyun __le16 fc = hdr->frame_control;
618*4882a593Smuzhiyun struct iwl_rxon_context *ctx;
619*4882a593Smuzhiyun unsigned int hdrlen, fraglen;
620*4882a593Smuzhiyun
621*4882a593Smuzhiyun /* We only process data packets if the interface is open */
622*4882a593Smuzhiyun if (unlikely(!priv->is_open)) {
623*4882a593Smuzhiyun IWL_DEBUG_DROP_LIMIT(priv,
624*4882a593Smuzhiyun "Dropping packet while interface is not open.\n");
625*4882a593Smuzhiyun return;
626*4882a593Smuzhiyun }
627*4882a593Smuzhiyun
628*4882a593Smuzhiyun /* In case of HW accelerated crypto and bad decryption, drop */
629*4882a593Smuzhiyun if (!iwlwifi_mod_params.swcrypto &&
630*4882a593Smuzhiyun iwlagn_set_decrypted_flag(priv, hdr, ampdu_status, stats))
631*4882a593Smuzhiyun return;
632*4882a593Smuzhiyun
633*4882a593Smuzhiyun /* Dont use dev_alloc_skb(), we'll have enough headroom once
634*4882a593Smuzhiyun * ieee80211_hdr pulled.
635*4882a593Smuzhiyun */
636*4882a593Smuzhiyun skb = alloc_skb(128, GFP_ATOMIC);
637*4882a593Smuzhiyun if (!skb) {
638*4882a593Smuzhiyun IWL_ERR(priv, "alloc_skb failed\n");
639*4882a593Smuzhiyun return;
640*4882a593Smuzhiyun }
641*4882a593Smuzhiyun /* If frame is small enough to fit in skb->head, pull it completely.
642*4882a593Smuzhiyun * If not, only pull ieee80211_hdr so that splice() or TCP coalesce
643*4882a593Smuzhiyun * are more efficient.
644*4882a593Smuzhiyun */
645*4882a593Smuzhiyun hdrlen = (len <= skb_tailroom(skb)) ? len : sizeof(*hdr);
646*4882a593Smuzhiyun
647*4882a593Smuzhiyun skb_put_data(skb, hdr, hdrlen);
648*4882a593Smuzhiyun fraglen = len - hdrlen;
649*4882a593Smuzhiyun
650*4882a593Smuzhiyun if (fraglen) {
651*4882a593Smuzhiyun int offset = (void *)hdr + hdrlen -
652*4882a593Smuzhiyun rxb_addr(rxb) + rxb_offset(rxb);
653*4882a593Smuzhiyun
654*4882a593Smuzhiyun skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset,
655*4882a593Smuzhiyun fraglen, rxb->truesize);
656*4882a593Smuzhiyun }
657*4882a593Smuzhiyun
658*4882a593Smuzhiyun /*
659*4882a593Smuzhiyun * Wake any queues that were stopped due to a passive channel tx
660*4882a593Smuzhiyun * failure. This can happen because the regulatory enforcement in
661*4882a593Smuzhiyun * the device waits for a beacon before allowing transmission,
662*4882a593Smuzhiyun * sometimes even after already having transmitted frames for the
663*4882a593Smuzhiyun * association because the new RXON may reset the information.
664*4882a593Smuzhiyun */
665*4882a593Smuzhiyun if (unlikely(ieee80211_is_beacon(fc) && priv->passive_no_rx)) {
666*4882a593Smuzhiyun for_each_context(priv, ctx) {
667*4882a593Smuzhiyun if (!ether_addr_equal(hdr->addr3,
668*4882a593Smuzhiyun ctx->active.bssid_addr))
669*4882a593Smuzhiyun continue;
670*4882a593Smuzhiyun iwlagn_lift_passive_no_rx(priv);
671*4882a593Smuzhiyun }
672*4882a593Smuzhiyun }
673*4882a593Smuzhiyun
674*4882a593Smuzhiyun memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
675*4882a593Smuzhiyun
676*4882a593Smuzhiyun ieee80211_rx_napi(priv->hw, NULL, skb, priv->napi);
677*4882a593Smuzhiyun }
678*4882a593Smuzhiyun
iwlagn_translate_rx_status(struct iwl_priv * priv,u32 decrypt_in)679*4882a593Smuzhiyun static u32 iwlagn_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
680*4882a593Smuzhiyun {
681*4882a593Smuzhiyun u32 decrypt_out = 0;
682*4882a593Smuzhiyun
683*4882a593Smuzhiyun if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
684*4882a593Smuzhiyun RX_RES_STATUS_STATION_FOUND)
685*4882a593Smuzhiyun decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
686*4882a593Smuzhiyun RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
689*4882a593Smuzhiyun
690*4882a593Smuzhiyun /* packet was not encrypted */
691*4882a593Smuzhiyun if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
692*4882a593Smuzhiyun RX_RES_STATUS_SEC_TYPE_NONE)
693*4882a593Smuzhiyun return decrypt_out;
694*4882a593Smuzhiyun
695*4882a593Smuzhiyun /* packet was encrypted with unknown alg */
696*4882a593Smuzhiyun if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
697*4882a593Smuzhiyun RX_RES_STATUS_SEC_TYPE_ERR)
698*4882a593Smuzhiyun return decrypt_out;
699*4882a593Smuzhiyun
700*4882a593Smuzhiyun /* decryption was not done in HW */
701*4882a593Smuzhiyun if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
702*4882a593Smuzhiyun RX_MPDU_RES_STATUS_DEC_DONE_MSK)
703*4882a593Smuzhiyun return decrypt_out;
704*4882a593Smuzhiyun
705*4882a593Smuzhiyun switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
706*4882a593Smuzhiyun
707*4882a593Smuzhiyun case RX_RES_STATUS_SEC_TYPE_CCMP:
708*4882a593Smuzhiyun /* alg is CCM: check MIC only */
709*4882a593Smuzhiyun if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
710*4882a593Smuzhiyun /* Bad MIC */
711*4882a593Smuzhiyun decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
712*4882a593Smuzhiyun else
713*4882a593Smuzhiyun decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
714*4882a593Smuzhiyun
715*4882a593Smuzhiyun break;
716*4882a593Smuzhiyun
717*4882a593Smuzhiyun case RX_RES_STATUS_SEC_TYPE_TKIP:
718*4882a593Smuzhiyun if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
719*4882a593Smuzhiyun /* Bad TTAK */
720*4882a593Smuzhiyun decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
721*4882a593Smuzhiyun break;
722*4882a593Smuzhiyun }
723*4882a593Smuzhiyun /* fall through */
724*4882a593Smuzhiyun default:
725*4882a593Smuzhiyun if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
726*4882a593Smuzhiyun decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
727*4882a593Smuzhiyun else
728*4882a593Smuzhiyun decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
729*4882a593Smuzhiyun break;
730*4882a593Smuzhiyun }
731*4882a593Smuzhiyun
732*4882a593Smuzhiyun IWL_DEBUG_RX(priv, "decrypt_in:0x%x decrypt_out = 0x%x\n",
733*4882a593Smuzhiyun decrypt_in, decrypt_out);
734*4882a593Smuzhiyun
735*4882a593Smuzhiyun return decrypt_out;
736*4882a593Smuzhiyun }
737*4882a593Smuzhiyun
738*4882a593Smuzhiyun /* Calc max signal level (dBm) among 3 possible receivers */
iwlagn_calc_rssi(struct iwl_priv * priv,struct iwl_rx_phy_res * rx_resp)739*4882a593Smuzhiyun static int iwlagn_calc_rssi(struct iwl_priv *priv,
740*4882a593Smuzhiyun struct iwl_rx_phy_res *rx_resp)
741*4882a593Smuzhiyun {
742*4882a593Smuzhiyun /* data from PHY/DSP regarding signal strength, etc.,
743*4882a593Smuzhiyun * contents are always there, not configurable by host
744*4882a593Smuzhiyun */
745*4882a593Smuzhiyun struct iwlagn_non_cfg_phy *ncphy =
746*4882a593Smuzhiyun (struct iwlagn_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
747*4882a593Smuzhiyun u32 val, rssi_a, rssi_b, rssi_c, max_rssi;
748*4882a593Smuzhiyun u8 agc;
749*4882a593Smuzhiyun
750*4882a593Smuzhiyun val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_AGC_IDX]);
751*4882a593Smuzhiyun agc = (val & IWLAGN_OFDM_AGC_MSK) >> IWLAGN_OFDM_AGC_BIT_POS;
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun /* Find max rssi among 3 possible receivers.
754*4882a593Smuzhiyun * These values are measured by the digital signal processor (DSP).
755*4882a593Smuzhiyun * They should stay fairly constant even as the signal strength varies,
756*4882a593Smuzhiyun * if the radio's automatic gain control (AGC) is working right.
757*4882a593Smuzhiyun * AGC value (see below) will provide the "interesting" info.
758*4882a593Smuzhiyun */
759*4882a593Smuzhiyun val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_AB_IDX]);
760*4882a593Smuzhiyun rssi_a = (val & IWLAGN_OFDM_RSSI_INBAND_A_BITMSK) >>
761*4882a593Smuzhiyun IWLAGN_OFDM_RSSI_A_BIT_POS;
762*4882a593Smuzhiyun rssi_b = (val & IWLAGN_OFDM_RSSI_INBAND_B_BITMSK) >>
763*4882a593Smuzhiyun IWLAGN_OFDM_RSSI_B_BIT_POS;
764*4882a593Smuzhiyun val = le32_to_cpu(ncphy->non_cfg_phy[IWLAGN_RX_RES_RSSI_C_IDX]);
765*4882a593Smuzhiyun rssi_c = (val & IWLAGN_OFDM_RSSI_INBAND_C_BITMSK) >>
766*4882a593Smuzhiyun IWLAGN_OFDM_RSSI_C_BIT_POS;
767*4882a593Smuzhiyun
768*4882a593Smuzhiyun max_rssi = max_t(u32, rssi_a, rssi_b);
769*4882a593Smuzhiyun max_rssi = max_t(u32, max_rssi, rssi_c);
770*4882a593Smuzhiyun
771*4882a593Smuzhiyun IWL_DEBUG_STATS(priv, "Rssi In A %d B %d C %d Max %d AGC dB %d\n",
772*4882a593Smuzhiyun rssi_a, rssi_b, rssi_c, max_rssi, agc);
773*4882a593Smuzhiyun
774*4882a593Smuzhiyun /* dBm = max_rssi dB - agc dB - constant.
775*4882a593Smuzhiyun * Higher AGC (higher radio gain) means lower signal. */
776*4882a593Smuzhiyun return max_rssi - agc - IWLAGN_RSSI_OFFSET;
777*4882a593Smuzhiyun }
778*4882a593Smuzhiyun
779*4882a593Smuzhiyun /* Called for REPLY_RX_MPDU_CMD */
iwlagn_rx_reply_rx(struct iwl_priv * priv,struct iwl_rx_cmd_buffer * rxb)780*4882a593Smuzhiyun static void iwlagn_rx_reply_rx(struct iwl_priv *priv,
781*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb)
782*4882a593Smuzhiyun {
783*4882a593Smuzhiyun struct ieee80211_hdr *header;
784*4882a593Smuzhiyun struct ieee80211_rx_status rx_status = {};
785*4882a593Smuzhiyun struct iwl_rx_packet *pkt = rxb_addr(rxb);
786*4882a593Smuzhiyun struct iwl_rx_phy_res *phy_res;
787*4882a593Smuzhiyun __le32 rx_pkt_status;
788*4882a593Smuzhiyun struct iwl_rx_mpdu_res_start *amsdu;
789*4882a593Smuzhiyun u32 len;
790*4882a593Smuzhiyun u32 ampdu_status;
791*4882a593Smuzhiyun u32 rate_n_flags;
792*4882a593Smuzhiyun
793*4882a593Smuzhiyun if (!priv->last_phy_res_valid) {
794*4882a593Smuzhiyun IWL_ERR(priv, "MPDU frame without cached PHY data\n");
795*4882a593Smuzhiyun return;
796*4882a593Smuzhiyun }
797*4882a593Smuzhiyun phy_res = &priv->last_phy_res;
798*4882a593Smuzhiyun amsdu = (struct iwl_rx_mpdu_res_start *)pkt->data;
799*4882a593Smuzhiyun header = (struct ieee80211_hdr *)(pkt->data + sizeof(*amsdu));
800*4882a593Smuzhiyun len = le16_to_cpu(amsdu->byte_count);
801*4882a593Smuzhiyun rx_pkt_status = *(__le32 *)(pkt->data + sizeof(*amsdu) + len);
802*4882a593Smuzhiyun ampdu_status = iwlagn_translate_rx_status(priv,
803*4882a593Smuzhiyun le32_to_cpu(rx_pkt_status));
804*4882a593Smuzhiyun
805*4882a593Smuzhiyun if ((unlikely(phy_res->cfg_phy_cnt > 20))) {
806*4882a593Smuzhiyun IWL_DEBUG_DROP(priv, "dsp size out of range [0,20]: %d\n",
807*4882a593Smuzhiyun phy_res->cfg_phy_cnt);
808*4882a593Smuzhiyun return;
809*4882a593Smuzhiyun }
810*4882a593Smuzhiyun
811*4882a593Smuzhiyun if (!(rx_pkt_status & RX_RES_STATUS_NO_CRC32_ERROR) ||
812*4882a593Smuzhiyun !(rx_pkt_status & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
813*4882a593Smuzhiyun IWL_DEBUG_RX(priv, "Bad CRC or FIFO: 0x%08X.\n",
814*4882a593Smuzhiyun le32_to_cpu(rx_pkt_status));
815*4882a593Smuzhiyun return;
816*4882a593Smuzhiyun }
817*4882a593Smuzhiyun
818*4882a593Smuzhiyun /* This will be used in several places later */
819*4882a593Smuzhiyun rate_n_flags = le32_to_cpu(phy_res->rate_n_flags);
820*4882a593Smuzhiyun
821*4882a593Smuzhiyun /* rx_status carries information about the packet to mac80211 */
822*4882a593Smuzhiyun rx_status.mactime = le64_to_cpu(phy_res->timestamp);
823*4882a593Smuzhiyun rx_status.band = (phy_res->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
824*4882a593Smuzhiyun NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
825*4882a593Smuzhiyun rx_status.freq =
826*4882a593Smuzhiyun ieee80211_channel_to_frequency(le16_to_cpu(phy_res->channel),
827*4882a593Smuzhiyun rx_status.band);
828*4882a593Smuzhiyun rx_status.rate_idx =
829*4882a593Smuzhiyun iwlagn_hwrate_to_mac80211_idx(rate_n_flags, rx_status.band);
830*4882a593Smuzhiyun rx_status.flag = 0;
831*4882a593Smuzhiyun
832*4882a593Smuzhiyun /* TSF isn't reliable. In order to allow smooth user experience,
833*4882a593Smuzhiyun * this W/A doesn't propagate it to the mac80211 */
834*4882a593Smuzhiyun /*rx_status.flag |= RX_FLAG_MACTIME_START;*/
835*4882a593Smuzhiyun
836*4882a593Smuzhiyun priv->ucode_beacon_time = le32_to_cpu(phy_res->beacon_time_stamp);
837*4882a593Smuzhiyun
838*4882a593Smuzhiyun /* Find max signal strength (dBm) among 3 antenna/receiver chains */
839*4882a593Smuzhiyun rx_status.signal = iwlagn_calc_rssi(priv, phy_res);
840*4882a593Smuzhiyun
841*4882a593Smuzhiyun IWL_DEBUG_STATS_LIMIT(priv, "Rssi %d, TSF %llu\n",
842*4882a593Smuzhiyun rx_status.signal, (unsigned long long)rx_status.mactime);
843*4882a593Smuzhiyun
844*4882a593Smuzhiyun /*
845*4882a593Smuzhiyun * "antenna number"
846*4882a593Smuzhiyun *
847*4882a593Smuzhiyun * It seems that the antenna field in the phy flags value
848*4882a593Smuzhiyun * is actually a bit field. This is undefined by radiotap,
849*4882a593Smuzhiyun * it wants an actual antenna number but I always get "7"
850*4882a593Smuzhiyun * for most legacy frames I receive indicating that the
851*4882a593Smuzhiyun * same frame was received on all three RX chains.
852*4882a593Smuzhiyun *
853*4882a593Smuzhiyun * I think this field should be removed in favor of a
854*4882a593Smuzhiyun * new 802.11n radiotap field "RX chains" that is defined
855*4882a593Smuzhiyun * as a bitmask.
856*4882a593Smuzhiyun */
857*4882a593Smuzhiyun rx_status.antenna =
858*4882a593Smuzhiyun (le16_to_cpu(phy_res->phy_flags) & RX_RES_PHY_FLAGS_ANTENNA_MSK)
859*4882a593Smuzhiyun >> RX_RES_PHY_FLAGS_ANTENNA_POS;
860*4882a593Smuzhiyun
861*4882a593Smuzhiyun /* set the preamble flag if appropriate */
862*4882a593Smuzhiyun if (phy_res->phy_flags & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
863*4882a593Smuzhiyun rx_status.enc_flags |= RX_ENC_FLAG_SHORTPRE;
864*4882a593Smuzhiyun
865*4882a593Smuzhiyun if (phy_res->phy_flags & RX_RES_PHY_FLAGS_AGG_MSK) {
866*4882a593Smuzhiyun /*
867*4882a593Smuzhiyun * We know which subframes of an A-MPDU belong
868*4882a593Smuzhiyun * together since we get a single PHY response
869*4882a593Smuzhiyun * from the firmware for all of them
870*4882a593Smuzhiyun */
871*4882a593Smuzhiyun rx_status.flag |= RX_FLAG_AMPDU_DETAILS;
872*4882a593Smuzhiyun rx_status.ampdu_reference = priv->ampdu_ref;
873*4882a593Smuzhiyun }
874*4882a593Smuzhiyun
875*4882a593Smuzhiyun /* Set up the HT phy flags */
876*4882a593Smuzhiyun if (rate_n_flags & RATE_MCS_HT_MSK)
877*4882a593Smuzhiyun rx_status.encoding = RX_ENC_HT;
878*4882a593Smuzhiyun if (rate_n_flags & RATE_MCS_HT40_MSK)
879*4882a593Smuzhiyun rx_status.bw = RATE_INFO_BW_40;
880*4882a593Smuzhiyun else
881*4882a593Smuzhiyun rx_status.bw = RATE_INFO_BW_20;
882*4882a593Smuzhiyun if (rate_n_flags & RATE_MCS_SGI_MSK)
883*4882a593Smuzhiyun rx_status.enc_flags |= RX_ENC_FLAG_SHORT_GI;
884*4882a593Smuzhiyun if (rate_n_flags & RATE_MCS_GF_MSK)
885*4882a593Smuzhiyun rx_status.enc_flags |= RX_ENC_FLAG_HT_GF;
886*4882a593Smuzhiyun
887*4882a593Smuzhiyun iwlagn_pass_packet_to_mac80211(priv, header, len, ampdu_status,
888*4882a593Smuzhiyun rxb, &rx_status);
889*4882a593Smuzhiyun }
890*4882a593Smuzhiyun
iwlagn_rx_noa_notification(struct iwl_priv * priv,struct iwl_rx_cmd_buffer * rxb)891*4882a593Smuzhiyun static void iwlagn_rx_noa_notification(struct iwl_priv *priv,
892*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb)
893*4882a593Smuzhiyun {
894*4882a593Smuzhiyun struct iwl_wipan_noa_data *new_data, *old_data;
895*4882a593Smuzhiyun struct iwl_rx_packet *pkt = rxb_addr(rxb);
896*4882a593Smuzhiyun struct iwl_wipan_noa_notification *noa_notif = (void *)pkt->data;
897*4882a593Smuzhiyun
898*4882a593Smuzhiyun /* no condition -- we're in softirq */
899*4882a593Smuzhiyun old_data = rcu_dereference_protected(priv->noa_data, true);
900*4882a593Smuzhiyun
901*4882a593Smuzhiyun if (noa_notif->noa_active) {
902*4882a593Smuzhiyun u32 len = le16_to_cpu(noa_notif->noa_attribute.length);
903*4882a593Smuzhiyun u32 copylen = len;
904*4882a593Smuzhiyun
905*4882a593Smuzhiyun /* EID, len, OUI, subtype */
906*4882a593Smuzhiyun len += 1 + 1 + 3 + 1;
907*4882a593Smuzhiyun /* P2P id, P2P length */
908*4882a593Smuzhiyun len += 1 + 2;
909*4882a593Smuzhiyun copylen += 1 + 2;
910*4882a593Smuzhiyun
911*4882a593Smuzhiyun new_data = kmalloc(sizeof(*new_data) + len, GFP_ATOMIC);
912*4882a593Smuzhiyun if (new_data) {
913*4882a593Smuzhiyun new_data->length = len;
914*4882a593Smuzhiyun new_data->data[0] = WLAN_EID_VENDOR_SPECIFIC;
915*4882a593Smuzhiyun new_data->data[1] = len - 2; /* not counting EID, len */
916*4882a593Smuzhiyun new_data->data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
917*4882a593Smuzhiyun new_data->data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
918*4882a593Smuzhiyun new_data->data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
919*4882a593Smuzhiyun new_data->data[5] = WLAN_OUI_TYPE_WFA_P2P;
920*4882a593Smuzhiyun memcpy(&new_data->data[6], &noa_notif->noa_attribute,
921*4882a593Smuzhiyun copylen);
922*4882a593Smuzhiyun }
923*4882a593Smuzhiyun } else
924*4882a593Smuzhiyun new_data = NULL;
925*4882a593Smuzhiyun
926*4882a593Smuzhiyun rcu_assign_pointer(priv->noa_data, new_data);
927*4882a593Smuzhiyun
928*4882a593Smuzhiyun if (old_data)
929*4882a593Smuzhiyun kfree_rcu(old_data, rcu_head);
930*4882a593Smuzhiyun }
931*4882a593Smuzhiyun
932*4882a593Smuzhiyun /*
933*4882a593Smuzhiyun * iwl_setup_rx_handlers - Initialize Rx handler callbacks
934*4882a593Smuzhiyun *
935*4882a593Smuzhiyun * Setup the RX handlers for each of the reply types sent from the uCode
936*4882a593Smuzhiyun * to the host.
937*4882a593Smuzhiyun */
iwl_setup_rx_handlers(struct iwl_priv * priv)938*4882a593Smuzhiyun void iwl_setup_rx_handlers(struct iwl_priv *priv)
939*4882a593Smuzhiyun {
940*4882a593Smuzhiyun void (**handlers)(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb);
941*4882a593Smuzhiyun
942*4882a593Smuzhiyun handlers = priv->rx_handlers;
943*4882a593Smuzhiyun
944*4882a593Smuzhiyun handlers[REPLY_ERROR] = iwlagn_rx_reply_error;
945*4882a593Smuzhiyun handlers[CHANNEL_SWITCH_NOTIFICATION] = iwlagn_rx_csa;
946*4882a593Smuzhiyun handlers[SPECTRUM_MEASURE_NOTIFICATION] =
947*4882a593Smuzhiyun iwlagn_rx_spectrum_measure_notif;
948*4882a593Smuzhiyun handlers[PM_SLEEP_NOTIFICATION] = iwlagn_rx_pm_sleep_notif;
949*4882a593Smuzhiyun handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
950*4882a593Smuzhiyun iwlagn_rx_pm_debug_statistics_notif;
951*4882a593Smuzhiyun handlers[BEACON_NOTIFICATION] = iwlagn_rx_beacon_notif;
952*4882a593Smuzhiyun handlers[REPLY_ADD_STA] = iwl_add_sta_callback;
953*4882a593Smuzhiyun
954*4882a593Smuzhiyun handlers[REPLY_WIPAN_NOA_NOTIFICATION] = iwlagn_rx_noa_notification;
955*4882a593Smuzhiyun
956*4882a593Smuzhiyun /*
957*4882a593Smuzhiyun * The same handler is used for both the REPLY to a discrete
958*4882a593Smuzhiyun * statistics request from the host as well as for the periodic
959*4882a593Smuzhiyun * statistics notifications (after received beacons) from the uCode.
960*4882a593Smuzhiyun */
961*4882a593Smuzhiyun handlers[REPLY_STATISTICS_CMD] = iwlagn_rx_reply_statistics;
962*4882a593Smuzhiyun handlers[STATISTICS_NOTIFICATION] = iwlagn_rx_statistics;
963*4882a593Smuzhiyun
964*4882a593Smuzhiyun iwl_setup_rx_scan_handlers(priv);
965*4882a593Smuzhiyun
966*4882a593Smuzhiyun handlers[CARD_STATE_NOTIFICATION] = iwlagn_rx_card_state_notif;
967*4882a593Smuzhiyun handlers[MISSED_BEACONS_NOTIFICATION] =
968*4882a593Smuzhiyun iwlagn_rx_missed_beacon_notif;
969*4882a593Smuzhiyun
970*4882a593Smuzhiyun /* Rx handlers */
971*4882a593Smuzhiyun handlers[REPLY_RX_PHY_CMD] = iwlagn_rx_reply_rx_phy;
972*4882a593Smuzhiyun handlers[REPLY_RX_MPDU_CMD] = iwlagn_rx_reply_rx;
973*4882a593Smuzhiyun
974*4882a593Smuzhiyun /* block ack */
975*4882a593Smuzhiyun handlers[REPLY_COMPRESSED_BA] =
976*4882a593Smuzhiyun iwlagn_rx_reply_compressed_ba;
977*4882a593Smuzhiyun
978*4882a593Smuzhiyun priv->rx_handlers[REPLY_TX] = iwlagn_rx_reply_tx;
979*4882a593Smuzhiyun
980*4882a593Smuzhiyun /* set up notification wait support */
981*4882a593Smuzhiyun iwl_notification_wait_init(&priv->notif_wait);
982*4882a593Smuzhiyun
983*4882a593Smuzhiyun /* Set up BT Rx handlers */
984*4882a593Smuzhiyun if (priv->lib->bt_params)
985*4882a593Smuzhiyun iwlagn_bt_rx_handler_setup(priv);
986*4882a593Smuzhiyun }
987*4882a593Smuzhiyun
iwl_rx_dispatch(struct iwl_op_mode * op_mode,struct napi_struct * napi,struct iwl_rx_cmd_buffer * rxb)988*4882a593Smuzhiyun void iwl_rx_dispatch(struct iwl_op_mode *op_mode, struct napi_struct *napi,
989*4882a593Smuzhiyun struct iwl_rx_cmd_buffer *rxb)
990*4882a593Smuzhiyun {
991*4882a593Smuzhiyun struct iwl_rx_packet *pkt = rxb_addr(rxb);
992*4882a593Smuzhiyun struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
993*4882a593Smuzhiyun
994*4882a593Smuzhiyun /*
995*4882a593Smuzhiyun * Do the notification wait before RX handlers so
996*4882a593Smuzhiyun * even if the RX handler consumes the RXB we have
997*4882a593Smuzhiyun * access to it in the notification wait entry.
998*4882a593Smuzhiyun */
999*4882a593Smuzhiyun iwl_notification_wait_notify(&priv->notif_wait, pkt);
1000*4882a593Smuzhiyun
1001*4882a593Smuzhiyun /* Based on type of command response or notification,
1002*4882a593Smuzhiyun * handle those that need handling via function in
1003*4882a593Smuzhiyun * rx_handlers table. See iwl_setup_rx_handlers() */
1004*4882a593Smuzhiyun if (priv->rx_handlers[pkt->hdr.cmd]) {
1005*4882a593Smuzhiyun priv->rx_handlers_stats[pkt->hdr.cmd]++;
1006*4882a593Smuzhiyun priv->rx_handlers[pkt->hdr.cmd](priv, rxb);
1007*4882a593Smuzhiyun } else {
1008*4882a593Smuzhiyun /* No handling needed */
1009*4882a593Smuzhiyun IWL_DEBUG_RX(priv, "No handler needed for %s, 0x%02x\n",
1010*4882a593Smuzhiyun iwl_get_cmd_string(priv->trans,
1011*4882a593Smuzhiyun iwl_cmd_id(pkt->hdr.cmd,
1012*4882a593Smuzhiyun 0, 0)),
1013*4882a593Smuzhiyun pkt->hdr.cmd);
1014*4882a593Smuzhiyun }
1015*4882a593Smuzhiyun }
1016