Commit | Line | Data |
---|---|---|
8ca151b5 JB |
1 | /****************************************************************************** |
2 | * | |
3 | * This file is provided under a dual BSD/GPLv2 license. When using or | |
4 | * redistributing this file, you may do so under either license. | |
5 | * | |
6 | * GPL LICENSE SUMMARY | |
7 | * | |
51368bf7 | 8 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
8ca151b5 JB |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of version 2 of the GNU General Public License as | |
12 | * published by the Free Software Foundation. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, but | |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | |
22 | * USA | |
23 | * | |
24 | * The full GNU General Public License is included in this distribution | |
410dc5aa | 25 | * in the file called COPYING. |
8ca151b5 JB |
26 | * |
27 | * Contact Information: | |
28 | * Intel Linux Wireless <ilw@linux.intel.com> | |
29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
30 | * | |
31 | * BSD LICENSE | |
32 | * | |
51368bf7 | 33 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
8ca151b5 JB |
34 | * All rights reserved. |
35 | * | |
36 | * Redistribution and use in source and binary forms, with or without | |
37 | * modification, are permitted provided that the following conditions | |
38 | * are met: | |
39 | * | |
40 | * * Redistributions of source code must retain the above copyright | |
41 | * notice, this list of conditions and the following disclaimer. | |
42 | * * Redistributions in binary form must reproduce the above copyright | |
43 | * notice, this list of conditions and the following disclaimer in | |
44 | * the documentation and/or other materials provided with the | |
45 | * distribution. | |
46 | * * Neither the name Intel Corporation nor the names of its | |
47 | * contributors may be used to endorse or promote products derived | |
48 | * from this software without specific prior written permission. | |
49 | * | |
50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
61 | *****************************************************************************/ | |
62 | #include "iwl-trans.h" | |
63 | ||
64 | #include "mvm.h" | |
65 | #include "fw-api.h" | |
66 | ||
67 | /* | |
68 | * iwl_mvm_rx_rx_phy_cmd - REPLY_RX_PHY_CMD handler | |
69 | * | |
70 | * Copies the phy information in mvm->last_phy_info, it will be used when the | |
71 | * actual data will come from the fw in the next packet. | |
72 | */ | |
73 | int iwl_mvm_rx_rx_phy_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb, | |
74 | struct iwl_device_cmd *cmd) | |
75 | { | |
76 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
77 | ||
78 | memcpy(&mvm->last_phy_info, pkt->data, sizeof(mvm->last_phy_info)); | |
79 | mvm->ampdu_ref++; | |
80 | return 0; | |
81 | } | |
82 | ||
83 | /* | |
84 | * iwl_mvm_pass_packet_to_mac80211 - builds the packet for mac80211 | |
85 | * | |
86 | * Adds the rxb to a new skb and give it to mac80211 | |
87 | */ | |
88 | static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm *mvm, | |
89 | struct ieee80211_hdr *hdr, u16 len, | |
90 | u32 ampdu_status, | |
91 | struct iwl_rx_cmd_buffer *rxb, | |
92 | struct ieee80211_rx_status *stats) | |
93 | { | |
94 | struct sk_buff *skb; | |
95 | unsigned int hdrlen, fraglen; | |
96 | ||
97 | /* Dont use dev_alloc_skb(), we'll have enough headroom once | |
98 | * ieee80211_hdr pulled. | |
99 | */ | |
100 | skb = alloc_skb(128, GFP_ATOMIC); | |
101 | if (!skb) { | |
102 | IWL_ERR(mvm, "alloc_skb failed\n"); | |
103 | return; | |
104 | } | |
105 | /* If frame is small enough to fit in skb->head, pull it completely. | |
106 | * If not, only pull ieee80211_hdr so that splice() or TCP coalesce | |
107 | * are more efficient. | |
108 | */ | |
109 | hdrlen = (len <= skb_tailroom(skb)) ? len : sizeof(*hdr); | |
110 | ||
111 | memcpy(skb_put(skb, hdrlen), hdr, hdrlen); | |
112 | fraglen = len - hdrlen; | |
113 | ||
114 | if (fraglen) { | |
115 | int offset = (void *)hdr + hdrlen - | |
116 | rxb_addr(rxb) + rxb_offset(rxb); | |
117 | ||
118 | skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset, | |
119 | fraglen, rxb->truesize); | |
120 | } | |
121 | ||
122 | memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats)); | |
123 | ||
2bfb5092 | 124 | ieee80211_rx_ni(mvm->hw, skb); |
8ca151b5 JB |
125 | } |
126 | ||
226eb8cd JB |
127 | static void iwl_mvm_calc_rssi(struct iwl_mvm *mvm, |
128 | struct iwl_rx_phy_info *phy_info, | |
129 | struct ieee80211_rx_status *rx_status) | |
8ca151b5 | 130 | { |
8101a7f0 | 131 | int rssi_a, rssi_b, rssi_a_dbm, rssi_b_dbm, max_rssi_dbm; |
5c0950c3 | 132 | u32 agc_a, agc_b; |
8ca151b5 JB |
133 | u32 val; |
134 | ||
8101a7f0 EG |
135 | val = le32_to_cpu(phy_info->non_cfg_phy[IWL_RX_INFO_AGC_IDX]); |
136 | agc_a = (val & IWL_OFDM_AGC_A_MSK) >> IWL_OFDM_AGC_A_POS; | |
137 | agc_b = (val & IWL_OFDM_AGC_B_MSK) >> IWL_OFDM_AGC_B_POS; | |
8101a7f0 | 138 | |
8ca151b5 JB |
139 | val = le32_to_cpu(phy_info->non_cfg_phy[IWL_RX_INFO_RSSI_AB_IDX]); |
140 | rssi_a = (val & IWL_OFDM_RSSI_INBAND_A_MSK) >> IWL_OFDM_RSSI_A_POS; | |
141 | rssi_b = (val & IWL_OFDM_RSSI_INBAND_B_MSK) >> IWL_OFDM_RSSI_B_POS; | |
8101a7f0 EG |
142 | |
143 | /* | |
144 | * dBm = rssi dB - agc dB - constant. | |
145 | * Higher AGC (higher radio gain) means lower signal. | |
146 | */ | |
147 | rssi_a_dbm = rssi_a - IWL_RSSI_OFFSET - agc_a; | |
148 | rssi_b_dbm = rssi_b - IWL_RSSI_OFFSET - agc_b; | |
149 | max_rssi_dbm = max_t(int, rssi_a_dbm, rssi_b_dbm); | |
8ca151b5 | 150 | |
8101a7f0 EG |
151 | IWL_DEBUG_STATS(mvm, "Rssi In A %d B %d Max %d AGCA %d AGCB %d\n", |
152 | rssi_a_dbm, rssi_b_dbm, max_rssi_dbm, agc_a, agc_b); | |
8ca151b5 | 153 | |
226eb8cd JB |
154 | rx_status->signal = max_rssi_dbm; |
155 | rx_status->chains = (le16_to_cpu(phy_info->phy_flags) & | |
156 | RX_RES_PHY_FLAGS_ANTENNA) | |
157 | >> RX_RES_PHY_FLAGS_ANTENNA_POS; | |
158 | rx_status->chain_signal[0] = rssi_a_dbm; | |
159 | rx_status->chain_signal[1] = rssi_b_dbm; | |
8ca151b5 JB |
160 | } |
161 | ||
a2d7b870 AA |
162 | /* |
163 | * iwl_mvm_get_signal_strength - use new rx PHY INFO API | |
17dbe564 AA |
164 | * values are reported by the fw as positive values - need to negate |
165 | * to obtain their dBM. Account for missing antennas by replacing 0 | |
166 | * values by -256dBm: practically 0 power and a non-feasible 8 bit value. | |
a2d7b870 | 167 | */ |
226eb8cd JB |
168 | static void iwl_mvm_get_signal_strength(struct iwl_mvm *mvm, |
169 | struct iwl_rx_phy_info *phy_info, | |
170 | struct ieee80211_rx_status *rx_status) | |
a2d7b870 AA |
171 | { |
172 | int energy_a, energy_b, energy_c, max_energy; | |
173 | u32 val; | |
174 | ||
175 | val = | |
176 | le32_to_cpu(phy_info->non_cfg_phy[IWL_RX_INFO_ENERGY_ANT_ABC_IDX]); | |
17dbe564 AA |
177 | energy_a = (val & IWL_RX_INFO_ENERGY_ANT_A_MSK) >> |
178 | IWL_RX_INFO_ENERGY_ANT_A_POS; | |
179 | energy_a = energy_a ? -energy_a : -256; | |
180 | energy_b = (val & IWL_RX_INFO_ENERGY_ANT_B_MSK) >> | |
181 | IWL_RX_INFO_ENERGY_ANT_B_POS; | |
182 | energy_b = energy_b ? -energy_b : -256; | |
183 | energy_c = (val & IWL_RX_INFO_ENERGY_ANT_C_MSK) >> | |
184 | IWL_RX_INFO_ENERGY_ANT_C_POS; | |
185 | energy_c = energy_c ? -energy_c : -256; | |
a2d7b870 AA |
186 | max_energy = max(energy_a, energy_b); |
187 | max_energy = max(max_energy, energy_c); | |
188 | ||
189 | IWL_DEBUG_STATS(mvm, "energy In A %d B %d C %d , and max %d\n", | |
190 | energy_a, energy_b, energy_c, max_energy); | |
191 | ||
226eb8cd JB |
192 | rx_status->signal = max_energy; |
193 | rx_status->chains = (le16_to_cpu(phy_info->phy_flags) & | |
194 | RX_RES_PHY_FLAGS_ANTENNA) | |
195 | >> RX_RES_PHY_FLAGS_ANTENNA_POS; | |
196 | rx_status->chain_signal[0] = energy_a; | |
197 | rx_status->chain_signal[1] = energy_b; | |
198 | rx_status->chain_signal[2] = energy_c; | |
a2d7b870 AA |
199 | } |
200 | ||
8ca151b5 JB |
201 | /* |
202 | * iwl_mvm_set_mac80211_rx_flag - translate fw status to mac80211 format | |
203 | * @mvm: the mvm object | |
204 | * @hdr: 80211 header | |
205 | * @stats: status in mac80211's format | |
206 | * @rx_pkt_status: status coming from fw | |
207 | * | |
208 | * returns non 0 value if the packet should be dropped | |
209 | */ | |
210 | static u32 iwl_mvm_set_mac80211_rx_flag(struct iwl_mvm *mvm, | |
211 | struct ieee80211_hdr *hdr, | |
212 | struct ieee80211_rx_status *stats, | |
213 | u32 rx_pkt_status) | |
214 | { | |
215 | if (!ieee80211_has_protected(hdr->frame_control) || | |
216 | (rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) == | |
217 | RX_MPDU_RES_STATUS_SEC_NO_ENC) | |
218 | return 0; | |
219 | ||
220 | /* packet was encrypted with unknown alg */ | |
221 | if ((rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) == | |
222 | RX_MPDU_RES_STATUS_SEC_ENC_ERR) | |
223 | return 0; | |
224 | ||
225 | switch (rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) { | |
226 | case RX_MPDU_RES_STATUS_SEC_CCM_ENC: | |
227 | /* alg is CCM: check MIC only */ | |
228 | if (!(rx_pkt_status & RX_MPDU_RES_STATUS_MIC_OK)) | |
229 | return -1; | |
230 | ||
231 | stats->flag |= RX_FLAG_DECRYPTED; | |
232 | IWL_DEBUG_WEP(mvm, "hw decrypted CCMP successfully\n"); | |
233 | return 0; | |
234 | ||
235 | case RX_MPDU_RES_STATUS_SEC_TKIP_ENC: | |
236 | /* Don't drop the frame and decrypt it in SW */ | |
237 | if (!(rx_pkt_status & RX_MPDU_RES_STATUS_TTAK_OK)) | |
238 | return 0; | |
239 | /* fall through if TTAK OK */ | |
240 | ||
241 | case RX_MPDU_RES_STATUS_SEC_WEP_ENC: | |
242 | if (!(rx_pkt_status & RX_MPDU_RES_STATUS_ICV_OK)) | |
243 | return -1; | |
244 | ||
245 | stats->flag |= RX_FLAG_DECRYPTED; | |
246 | return 0; | |
247 | ||
e36e5433 MS |
248 | case RX_MPDU_RES_STATUS_SEC_EXT_ENC: |
249 | if (!(rx_pkt_status & RX_MPDU_RES_STATUS_MIC_OK)) | |
250 | return -1; | |
251 | stats->flag |= RX_FLAG_DECRYPTED; | |
252 | return 0; | |
253 | ||
8ca151b5 JB |
254 | default: |
255 | IWL_ERR(mvm, "Unhandled alg: 0x%x\n", rx_pkt_status); | |
256 | } | |
257 | ||
258 | return 0; | |
259 | } | |
260 | ||
261 | /* | |
262 | * iwl_mvm_rx_rx_mpdu - REPLY_RX_MPDU_CMD handler | |
263 | * | |
264 | * Handles the actual data of the Rx packet from the fw | |
265 | */ | |
266 | int iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb, | |
267 | struct iwl_device_cmd *cmd) | |
268 | { | |
269 | struct ieee80211_hdr *hdr; | |
270 | struct ieee80211_rx_status rx_status = {}; | |
271 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
272 | struct iwl_rx_phy_info *phy_info; | |
273 | struct iwl_rx_mpdu_res_start *rx_res; | |
274 | u32 len; | |
275 | u32 ampdu_status; | |
276 | u32 rate_n_flags; | |
277 | u32 rx_pkt_status; | |
278 | ||
279 | phy_info = &mvm->last_phy_info; | |
280 | rx_res = (struct iwl_rx_mpdu_res_start *)pkt->data; | |
281 | hdr = (struct ieee80211_hdr *)(pkt->data + sizeof(*rx_res)); | |
282 | len = le16_to_cpu(rx_res->byte_count); | |
283 | rx_pkt_status = le32_to_cpup((__le32 *) | |
284 | (pkt->data + sizeof(*rx_res) + len)); | |
285 | ||
286 | memset(&rx_status, 0, sizeof(rx_status)); | |
287 | ||
288 | /* | |
289 | * drop the packet if it has failed being decrypted by HW | |
290 | */ | |
291 | if (iwl_mvm_set_mac80211_rx_flag(mvm, hdr, &rx_status, rx_pkt_status)) { | |
292 | IWL_DEBUG_DROP(mvm, "Bad decryption results 0x%08x\n", | |
293 | rx_pkt_status); | |
294 | return 0; | |
295 | } | |
296 | ||
297 | if ((unlikely(phy_info->cfg_phy_cnt > 20))) { | |
298 | IWL_DEBUG_DROP(mvm, "dsp size out of range [0,20]: %d\n", | |
299 | phy_info->cfg_phy_cnt); | |
300 | return 0; | |
301 | } | |
302 | ||
fb8b8ee1 JB |
303 | /* |
304 | * Keep packets with CRC errors (and with overrun) for monitor mode | |
305 | * (otherwise the firmware discards them) but mark them as bad. | |
306 | */ | |
8ca151b5 JB |
307 | if (!(rx_pkt_status & RX_MPDU_RES_STATUS_CRC_OK) || |
308 | !(rx_pkt_status & RX_MPDU_RES_STATUS_OVERRUN_OK)) { | |
309 | IWL_DEBUG_RX(mvm, "Bad CRC or FIFO: 0x%08X.\n", rx_pkt_status); | |
fb8b8ee1 | 310 | rx_status.flag |= RX_FLAG_FAILED_FCS_CRC; |
8ca151b5 JB |
311 | } |
312 | ||
313 | /* This will be used in several places later */ | |
314 | rate_n_flags = le32_to_cpu(phy_info->rate_n_flags); | |
315 | ||
316 | /* rx_status carries information about the packet to mac80211 */ | |
317 | rx_status.mactime = le64_to_cpu(phy_info->timestamp); | |
d2931bbd | 318 | rx_status.device_timestamp = le32_to_cpu(phy_info->system_timestamp); |
8ca151b5 JB |
319 | rx_status.band = |
320 | (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_BAND_24)) ? | |
321 | IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ; | |
322 | rx_status.freq = | |
323 | ieee80211_channel_to_frequency(le16_to_cpu(phy_info->channel), | |
324 | rx_status.band); | |
325 | /* | |
326 | * TSF as indicated by the fw is at INA time, but mac80211 expects the | |
327 | * TSF at the beginning of the MPDU. | |
328 | */ | |
329 | /*rx_status.flag |= RX_FLAG_MACTIME_MPDU;*/ | |
330 | ||
a2d7b870 | 331 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_RX_ENERGY_API) |
226eb8cd | 332 | iwl_mvm_get_signal_strength(mvm, phy_info, &rx_status); |
a2d7b870 | 333 | else |
226eb8cd | 334 | iwl_mvm_calc_rssi(mvm, phy_info, &rx_status); |
8ca151b5 JB |
335 | |
336 | IWL_DEBUG_STATS_LIMIT(mvm, "Rssi %d, TSF %llu\n", rx_status.signal, | |
337 | (unsigned long long)rx_status.mactime); | |
338 | ||
8ca151b5 JB |
339 | /* set the preamble flag if appropriate */ |
340 | if (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_SHORT_PREAMBLE)) | |
341 | rx_status.flag |= RX_FLAG_SHORTPRE; | |
342 | ||
343 | if (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_AGG)) { | |
344 | /* | |
345 | * We know which subframes of an A-MPDU belong | |
346 | * together since we get a single PHY response | |
347 | * from the firmware for all of them | |
348 | */ | |
349 | rx_status.flag |= RX_FLAG_AMPDU_DETAILS; | |
350 | rx_status.ampdu_reference = mvm->ampdu_ref; | |
351 | } | |
352 | ||
353 | /* Set up the HT phy flags */ | |
354 | switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { | |
355 | case RATE_MCS_CHAN_WIDTH_20: | |
356 | break; | |
357 | case RATE_MCS_CHAN_WIDTH_40: | |
358 | rx_status.flag |= RX_FLAG_40MHZ; | |
359 | break; | |
360 | case RATE_MCS_CHAN_WIDTH_80: | |
1b8d242a | 361 | rx_status.vht_flag |= RX_VHT_FLAG_80MHZ; |
8ca151b5 JB |
362 | break; |
363 | case RATE_MCS_CHAN_WIDTH_160: | |
1b8d242a | 364 | rx_status.vht_flag |= RX_VHT_FLAG_160MHZ; |
8ca151b5 JB |
365 | break; |
366 | } | |
367 | if (rate_n_flags & RATE_MCS_SGI_MSK) | |
368 | rx_status.flag |= RX_FLAG_SHORT_GI; | |
369 | if (rate_n_flags & RATE_HT_MCS_GF_MSK) | |
370 | rx_status.flag |= RX_FLAG_HT_GF; | |
371 | if (rate_n_flags & RATE_MCS_HT_MSK) { | |
372 | rx_status.flag |= RX_FLAG_HT; | |
373 | rx_status.rate_idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK; | |
374 | } else if (rate_n_flags & RATE_MCS_VHT_MSK) { | |
375 | rx_status.vht_nss = | |
376 | ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >> | |
377 | RATE_VHT_MCS_NSS_POS) + 1; | |
378 | rx_status.rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK; | |
379 | rx_status.flag |= RX_FLAG_VHT; | |
380 | } else { | |
381 | rx_status.rate_idx = | |
382 | iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags, | |
383 | rx_status.band); | |
384 | } | |
385 | ||
386 | iwl_mvm_pass_packet_to_mac80211(mvm, hdr, len, ampdu_status, | |
387 | rxb, &rx_status); | |
388 | return 0; | |
389 | } | |
9ee718aa | 390 | |
3848ab66 MG |
391 | static void iwl_mvm_update_rx_statistics(struct iwl_mvm *mvm, |
392 | struct iwl_notif_statistics *stats) | |
393 | { | |
394 | /* | |
395 | * NOTE FW aggregates the statistics - BUT the statistics are cleared | |
396 | * when the driver issues REPLY_STATISTICS_CMD 0x9c with CLEAR_STATS | |
397 | * bit set. | |
398 | */ | |
399 | lockdep_assert_held(&mvm->mutex); | |
400 | memcpy(&mvm->rx_stats, &stats->rx, sizeof(struct mvm_statistics_rx)); | |
401 | } | |
402 | ||
a20fd398 AO |
403 | struct iwl_mvm_stat_data { |
404 | struct iwl_notif_statistics *stats; | |
405 | struct iwl_mvm *mvm; | |
406 | }; | |
407 | ||
408 | static void iwl_mvm_stat_iterator(void *_data, u8 *mac, | |
409 | struct ieee80211_vif *vif) | |
410 | { | |
411 | struct iwl_mvm_stat_data *data = _data; | |
412 | struct iwl_notif_statistics *stats = data->stats; | |
413 | struct iwl_mvm *mvm = data->mvm; | |
414 | int sig = -stats->general.beacon_filter_average_energy; | |
415 | int last_event; | |
416 | int thold = vif->bss_conf.cqm_rssi_thold; | |
417 | int hyst = vif->bss_conf.cqm_rssi_hyst; | |
418 | u16 id = le32_to_cpu(stats->rx.general.mac_id); | |
419 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
420 | ||
421 | if (mvmvif->id != id) | |
422 | return; | |
423 | ||
424 | if (vif->type != NL80211_IFTYPE_STATION) | |
425 | return; | |
426 | ||
427 | mvmvif->bf_data.ave_beacon_signal = sig; | |
428 | ||
911222b5 AO |
429 | /* BT Coex */ |
430 | if (mvmvif->bf_data.bt_coex_min_thold != | |
431 | mvmvif->bf_data.bt_coex_max_thold) { | |
432 | last_event = mvmvif->bf_data.last_bt_coex_event; | |
433 | if (sig > mvmvif->bf_data.bt_coex_max_thold && | |
434 | (last_event <= mvmvif->bf_data.bt_coex_min_thold || | |
435 | last_event == 0)) { | |
436 | mvmvif->bf_data.last_bt_coex_event = sig; | |
437 | IWL_DEBUG_RX(mvm, "cqm_iterator bt coex high %d\n", | |
438 | sig); | |
439 | iwl_mvm_bt_rssi_event(mvm, vif, RSSI_EVENT_HIGH); | |
440 | } else if (sig < mvmvif->bf_data.bt_coex_min_thold && | |
441 | (last_event >= mvmvif->bf_data.bt_coex_max_thold || | |
442 | last_event == 0)) { | |
443 | mvmvif->bf_data.last_bt_coex_event = sig; | |
444 | IWL_DEBUG_RX(mvm, "cqm_iterator bt coex low %d\n", | |
445 | sig); | |
446 | iwl_mvm_bt_rssi_event(mvm, vif, RSSI_EVENT_LOW); | |
447 | } | |
448 | } | |
449 | ||
a20fd398 AO |
450 | if (!(vif->driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) |
451 | return; | |
452 | ||
453 | /* CQM Notification */ | |
454 | last_event = mvmvif->bf_data.last_cqm_event; | |
455 | if (thold && sig < thold && (last_event == 0 || | |
456 | sig < last_event - hyst)) { | |
457 | mvmvif->bf_data.last_cqm_event = sig; | |
458 | IWL_DEBUG_RX(mvm, "cqm_iterator cqm low %d\n", | |
459 | sig); | |
460 | ieee80211_cqm_rssi_notify( | |
461 | vif, | |
462 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, | |
463 | GFP_KERNEL); | |
464 | } else if (sig > thold && | |
465 | (last_event == 0 || sig > last_event + hyst)) { | |
466 | mvmvif->bf_data.last_cqm_event = sig; | |
467 | IWL_DEBUG_RX(mvm, "cqm_iterator cqm high %d\n", | |
468 | sig); | |
469 | ieee80211_cqm_rssi_notify( | |
470 | vif, | |
471 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, | |
472 | GFP_KERNEL); | |
473 | } | |
474 | } | |
475 | ||
9ee718aa EL |
476 | /* |
477 | * iwl_mvm_rx_statistics - STATISTICS_NOTIFICATION handler | |
478 | * | |
479 | * TODO: This handler is implemented partially. | |
9ee718aa EL |
480 | */ |
481 | int iwl_mvm_rx_statistics(struct iwl_mvm *mvm, | |
482 | struct iwl_rx_cmd_buffer *rxb, | |
483 | struct iwl_device_cmd *cmd) | |
484 | { | |
485 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
486 | struct iwl_notif_statistics *stats = (void *)&pkt->data; | |
487 | struct mvm_statistics_general_common *common = &stats->general.common; | |
a20fd398 AO |
488 | struct iwl_mvm_stat_data data = { |
489 | .stats = stats, | |
490 | .mvm = mvm, | |
491 | }; | |
9ee718aa EL |
492 | |
493 | if (mvm->temperature != le32_to_cpu(common->temperature)) { | |
494 | mvm->temperature = le32_to_cpu(common->temperature); | |
495 | iwl_mvm_tt_handler(mvm); | |
496 | } | |
3848ab66 | 497 | iwl_mvm_update_rx_statistics(mvm, stats); |
9ee718aa | 498 | |
a20fd398 AO |
499 | ieee80211_iterate_active_interfaces(mvm->hw, |
500 | IEEE80211_IFACE_ITER_NORMAL, | |
501 | iwl_mvm_stat_iterator, | |
502 | &data); | |
9ee718aa EL |
503 | return 0; |
504 | } |