This source file includes following definitions.
- iwl_mvm_rx_rx_phy_cmd
- iwl_mvm_pass_packet_to_mac80211
- iwl_mvm_get_signal_strength
- iwl_mvm_set_mac80211_rx_flag
- iwl_mvm_rx_handle_tcm
- iwl_mvm_rx_csum
- iwl_mvm_rx_rx_mpdu
- iwl_mvm_stat_iterator
- iwl_mvm_rx_stats_check_trigger
- iwl_mvm_handle_rx_statistics
- iwl_mvm_rx_statistics
- iwl_mvm_window_status_notif
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 #include <asm/unaligned.h>
64 #include <linux/etherdevice.h>
65 #include <linux/skbuff.h>
66 #include "iwl-trans.h"
67 #include "mvm.h"
68 #include "fw-api.h"
69
70
71
72
73
74
75
76 void iwl_mvm_rx_rx_phy_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
77 {
78 struct iwl_rx_packet *pkt = rxb_addr(rxb);
79
80 memcpy(&mvm->last_phy_info, pkt->data, sizeof(mvm->last_phy_info));
81 mvm->ampdu_ref++;
82
83 #ifdef CONFIG_IWLWIFI_DEBUGFS
84 if (mvm->last_phy_info.phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_AGG)) {
85 spin_lock(&mvm->drv_stats_lock);
86 mvm->drv_rx_stats.ampdu_count++;
87 spin_unlock(&mvm->drv_stats_lock);
88 }
89 #endif
90 }
91
92
93
94
95
96
97 static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm *mvm,
98 struct ieee80211_sta *sta,
99 struct napi_struct *napi,
100 struct sk_buff *skb,
101 struct ieee80211_hdr *hdr, u16 len,
102 u8 crypt_len,
103 struct iwl_rx_cmd_buffer *rxb)
104 {
105 unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control);
106 unsigned int fraglen;
107
108
109
110
111
112
113
114
115
116
117
118 skb_reserve(skb, hdrlen & 3);
119
120
121
122
123
124
125
126
127
128
129
130
131
132 hdrlen = (len <= skb_tailroom(skb)) ? len : hdrlen + crypt_len + 8;
133
134 skb_put_data(skb, hdr, hdrlen);
135 fraglen = len - hdrlen;
136
137 if (fraglen) {
138 int offset = (void *)hdr + hdrlen -
139 rxb_addr(rxb) + rxb_offset(rxb);
140
141 skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset,
142 fraglen, rxb->truesize);
143 }
144
145 ieee80211_rx_napi(mvm->hw, sta, skb, napi);
146 }
147
148
149
150
151
152
153
154 static void iwl_mvm_get_signal_strength(struct iwl_mvm *mvm,
155 struct iwl_rx_phy_info *phy_info,
156 struct ieee80211_rx_status *rx_status)
157 {
158 int energy_a, energy_b, energy_c, max_energy;
159 u32 val;
160
161 val =
162 le32_to_cpu(phy_info->non_cfg_phy[IWL_RX_INFO_ENERGY_ANT_ABC_IDX]);
163 energy_a = (val & IWL_RX_INFO_ENERGY_ANT_A_MSK) >>
164 IWL_RX_INFO_ENERGY_ANT_A_POS;
165 energy_a = energy_a ? -energy_a : S8_MIN;
166 energy_b = (val & IWL_RX_INFO_ENERGY_ANT_B_MSK) >>
167 IWL_RX_INFO_ENERGY_ANT_B_POS;
168 energy_b = energy_b ? -energy_b : S8_MIN;
169 energy_c = (val & IWL_RX_INFO_ENERGY_ANT_C_MSK) >>
170 IWL_RX_INFO_ENERGY_ANT_C_POS;
171 energy_c = energy_c ? -energy_c : S8_MIN;
172 max_energy = max(energy_a, energy_b);
173 max_energy = max(max_energy, energy_c);
174
175 IWL_DEBUG_STATS(mvm, "energy In A %d B %d C %d , and max %d\n",
176 energy_a, energy_b, energy_c, max_energy);
177
178 rx_status->signal = max_energy;
179 rx_status->chains = (le16_to_cpu(phy_info->phy_flags) &
180 RX_RES_PHY_FLAGS_ANTENNA)
181 >> RX_RES_PHY_FLAGS_ANTENNA_POS;
182 rx_status->chain_signal[0] = energy_a;
183 rx_status->chain_signal[1] = energy_b;
184 rx_status->chain_signal[2] = energy_c;
185 }
186
187
188
189
190
191
192
193
194
195
196 static u32 iwl_mvm_set_mac80211_rx_flag(struct iwl_mvm *mvm,
197 struct ieee80211_hdr *hdr,
198 struct ieee80211_rx_status *stats,
199 u32 rx_pkt_status,
200 u8 *crypt_len)
201 {
202 if (!ieee80211_has_protected(hdr->frame_control) ||
203 (rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) ==
204 RX_MPDU_RES_STATUS_SEC_NO_ENC)
205 return 0;
206
207
208 if ((rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) ==
209 RX_MPDU_RES_STATUS_SEC_ENC_ERR)
210 return 0;
211
212 switch (rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) {
213 case RX_MPDU_RES_STATUS_SEC_CCM_ENC:
214
215 if (!(rx_pkt_status & RX_MPDU_RES_STATUS_MIC_OK))
216 return -1;
217
218 stats->flag |= RX_FLAG_DECRYPTED;
219 *crypt_len = IEEE80211_CCMP_HDR_LEN;
220 return 0;
221
222 case RX_MPDU_RES_STATUS_SEC_TKIP_ENC:
223
224 if (!fw_has_api(&mvm->fw->ucode_capa,
225 IWL_UCODE_TLV_API_DEPRECATE_TTAK) &&
226 !(rx_pkt_status & RX_MPDU_RES_STATUS_TTAK_OK))
227 return 0;
228 *crypt_len = IEEE80211_TKIP_IV_LEN;
229
230
231 case RX_MPDU_RES_STATUS_SEC_WEP_ENC:
232 if (!(rx_pkt_status & RX_MPDU_RES_STATUS_ICV_OK))
233 return -1;
234
235 stats->flag |= RX_FLAG_DECRYPTED;
236 if ((rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) ==
237 RX_MPDU_RES_STATUS_SEC_WEP_ENC)
238 *crypt_len = IEEE80211_WEP_IV_LEN;
239 return 0;
240
241 case RX_MPDU_RES_STATUS_SEC_EXT_ENC:
242 if (!(rx_pkt_status & RX_MPDU_RES_STATUS_MIC_OK))
243 return -1;
244 stats->flag |= RX_FLAG_DECRYPTED;
245 return 0;
246
247 default:
248
249 if (!mvm->monitor_on)
250 IWL_ERR(mvm, "Unhandled alg: 0x%x\n", rx_pkt_status);
251 }
252
253 return 0;
254 }
255
256 static void iwl_mvm_rx_handle_tcm(struct iwl_mvm *mvm,
257 struct ieee80211_sta *sta,
258 struct ieee80211_hdr *hdr, u32 len,
259 struct iwl_rx_phy_info *phy_info,
260 u32 rate_n_flags)
261 {
262 struct iwl_mvm_sta *mvmsta;
263 struct iwl_mvm_tcm_mac *mdata;
264 int mac;
265 int ac = IEEE80211_AC_BE;
266 struct iwl_mvm_vif *mvmvif;
267
268 static const u8 thresh_tpt[] = {
269 9, 18, 30, 42, 60, 78, 90, 96, 120, 135,
270 };
271 u16 thr;
272
273 if (ieee80211_is_data_qos(hdr->frame_control))
274 ac = tid_to_mac80211_ac[ieee80211_get_tid(hdr)];
275
276 mvmsta = iwl_mvm_sta_from_mac80211(sta);
277 mac = mvmsta->mac_id_n_color & FW_CTXT_ID_MSK;
278
279 if (time_after(jiffies, mvm->tcm.ts + MVM_TCM_PERIOD))
280 schedule_delayed_work(&mvm->tcm.work, 0);
281 mdata = &mvm->tcm.data[mac];
282 mdata->rx.pkts[ac]++;
283
284
285 if (mdata->rx.last_ampdu_ref != mvm->ampdu_ref) {
286 mdata->rx.last_ampdu_ref = mvm->ampdu_ref;
287 mdata->rx.airtime += le16_to_cpu(phy_info->frame_time);
288 }
289
290 if (!(rate_n_flags & (RATE_MCS_HT_MSK | RATE_MCS_VHT_MSK)))
291 return;
292
293 mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
294
295 if (mdata->opened_rx_ba_sessions ||
296 mdata->uapsd_nonagg_detect.detected ||
297 (!mvmvif->queue_params[IEEE80211_AC_VO].uapsd &&
298 !mvmvif->queue_params[IEEE80211_AC_VI].uapsd &&
299 !mvmvif->queue_params[IEEE80211_AC_BE].uapsd &&
300 !mvmvif->queue_params[IEEE80211_AC_BK].uapsd) ||
301 mvmsta->sta_id != mvmvif->ap_sta_id)
302 return;
303
304 if (rate_n_flags & RATE_MCS_HT_MSK) {
305 thr = thresh_tpt[rate_n_flags & RATE_HT_MCS_RATE_CODE_MSK];
306 thr *= 1 + ((rate_n_flags & RATE_HT_MCS_NSS_MSK) >>
307 RATE_HT_MCS_NSS_POS);
308 } else {
309 if (WARN_ON((rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK) >=
310 ARRAY_SIZE(thresh_tpt)))
311 return;
312 thr = thresh_tpt[rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK];
313 thr *= 1 + ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >>
314 RATE_VHT_MCS_NSS_POS);
315 }
316
317 thr <<= ((rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) >>
318 RATE_MCS_CHAN_WIDTH_POS);
319
320 mdata->uapsd_nonagg_detect.rx_bytes += len;
321 ewma_rate_add(&mdata->uapsd_nonagg_detect.rate, thr);
322 }
323
324 static void iwl_mvm_rx_csum(struct ieee80211_sta *sta,
325 struct sk_buff *skb,
326 u32 status)
327 {
328 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
329 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
330
331 if (mvmvif->features & NETIF_F_RXCSUM &&
332 status & RX_MPDU_RES_STATUS_CSUM_DONE &&
333 status & RX_MPDU_RES_STATUS_CSUM_OK)
334 skb->ip_summed = CHECKSUM_UNNECESSARY;
335 }
336
337
338
339
340
341
342 void iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct napi_struct *napi,
343 struct iwl_rx_cmd_buffer *rxb)
344 {
345 struct ieee80211_hdr *hdr;
346 struct ieee80211_rx_status *rx_status;
347 struct iwl_rx_packet *pkt = rxb_addr(rxb);
348 struct iwl_rx_phy_info *phy_info;
349 struct iwl_rx_mpdu_res_start *rx_res;
350 struct ieee80211_sta *sta = NULL;
351 struct sk_buff *skb;
352 u32 len;
353 u32 rate_n_flags;
354 u32 rx_pkt_status;
355 u8 crypt_len = 0;
356
357 phy_info = &mvm->last_phy_info;
358 rx_res = (struct iwl_rx_mpdu_res_start *)pkt->data;
359 hdr = (struct ieee80211_hdr *)(pkt->data + sizeof(*rx_res));
360 len = le16_to_cpu(rx_res->byte_count);
361 rx_pkt_status = get_unaligned_le32((__le32 *)
362 (pkt->data + sizeof(*rx_res) + len));
363
364
365
366
367 skb = alloc_skb(128, GFP_ATOMIC);
368 if (!skb) {
369 IWL_ERR(mvm, "alloc_skb failed\n");
370 return;
371 }
372
373 rx_status = IEEE80211_SKB_RXCB(skb);
374
375
376
377
378 if (iwl_mvm_set_mac80211_rx_flag(mvm, hdr, rx_status, rx_pkt_status,
379 &crypt_len)) {
380 IWL_DEBUG_DROP(mvm, "Bad decryption results 0x%08x\n",
381 rx_pkt_status);
382 kfree_skb(skb);
383 return;
384 }
385
386
387
388
389
390 if (!(rx_pkt_status & RX_MPDU_RES_STATUS_CRC_OK) ||
391 !(rx_pkt_status & RX_MPDU_RES_STATUS_OVERRUN_OK)) {
392 IWL_DEBUG_RX(mvm, "Bad CRC or FIFO: 0x%08X.\n", rx_pkt_status);
393 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
394 }
395
396
397 rate_n_flags = le32_to_cpu(phy_info->rate_n_flags);
398
399
400 rx_status->mactime = le64_to_cpu(phy_info->timestamp);
401 rx_status->device_timestamp = le32_to_cpu(phy_info->system_timestamp);
402 rx_status->band =
403 (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_BAND_24)) ?
404 NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
405 rx_status->freq =
406 ieee80211_channel_to_frequency(le16_to_cpu(phy_info->channel),
407 rx_status->band);
408
409
410 rx_status->flag |= RX_FLAG_MACTIME_PLCP_START;
411
412 iwl_mvm_get_signal_strength(mvm, phy_info, rx_status);
413
414 IWL_DEBUG_STATS_LIMIT(mvm, "Rssi %d, TSF %llu\n", rx_status->signal,
415 (unsigned long long)rx_status->mactime);
416
417 rcu_read_lock();
418 if (rx_pkt_status & RX_MPDU_RES_STATUS_SRC_STA_FOUND) {
419 u32 id = rx_pkt_status & RX_MPDU_RES_STATUS_STA_ID_MSK;
420
421 id >>= RX_MDPU_RES_STATUS_STA_ID_SHIFT;
422
423 if (!WARN_ON_ONCE(id >= ARRAY_SIZE(mvm->fw_id_to_mac_id))) {
424 sta = rcu_dereference(mvm->fw_id_to_mac_id[id]);
425 if (IS_ERR(sta))
426 sta = NULL;
427 }
428 } else if (!is_multicast_ether_addr(hdr->addr2)) {
429
430
431
432 sta = ieee80211_find_sta_by_ifaddr(mvm->hw, hdr->addr2, NULL);
433 }
434
435 if (sta) {
436 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
437 struct ieee80211_vif *tx_blocked_vif =
438 rcu_dereference(mvm->csa_tx_blocked_vif);
439 struct iwl_fw_dbg_trigger_tlv *trig;
440 struct ieee80211_vif *vif = mvmsta->vif;
441
442
443
444
445
446 if (unlikely(tx_blocked_vif) && vif == tx_blocked_vif) {
447 struct iwl_mvm_vif *mvmvif =
448 iwl_mvm_vif_from_mac80211(tx_blocked_vif);
449
450 if (mvmvif->csa_target_freq == rx_status->freq)
451 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta,
452 false);
453 }
454
455 rs_update_last_rssi(mvm, mvmsta, rx_status);
456
457 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt,
458 ieee80211_vif_to_wdev(vif),
459 FW_DBG_TRIGGER_RSSI);
460
461 if (trig && ieee80211_is_beacon(hdr->frame_control)) {
462 struct iwl_fw_dbg_trigger_low_rssi *rssi_trig;
463 s32 rssi;
464
465 rssi_trig = (void *)trig->data;
466 rssi = le32_to_cpu(rssi_trig->rssi);
467
468 if (rx_status->signal < rssi)
469 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
470 NULL);
471 }
472
473 if (!mvm->tcm.paused && len >= sizeof(*hdr) &&
474 !is_multicast_ether_addr(hdr->addr1) &&
475 ieee80211_is_data(hdr->frame_control))
476 iwl_mvm_rx_handle_tcm(mvm, sta, hdr, len, phy_info,
477 rate_n_flags);
478
479 if (ieee80211_is_data(hdr->frame_control))
480 iwl_mvm_rx_csum(sta, skb, rx_pkt_status);
481 }
482 rcu_read_unlock();
483
484
485 if (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_SHORT_PREAMBLE))
486 rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE;
487
488 if (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_AGG)) {
489
490
491
492
493
494 rx_status->flag |= RX_FLAG_AMPDU_DETAILS;
495 rx_status->ampdu_reference = mvm->ampdu_ref;
496 }
497
498
499 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
500 case RATE_MCS_CHAN_WIDTH_20:
501 break;
502 case RATE_MCS_CHAN_WIDTH_40:
503 rx_status->bw = RATE_INFO_BW_40;
504 break;
505 case RATE_MCS_CHAN_WIDTH_80:
506 rx_status->bw = RATE_INFO_BW_80;
507 break;
508 case RATE_MCS_CHAN_WIDTH_160:
509 rx_status->bw = RATE_INFO_BW_160;
510 break;
511 }
512 if (!(rate_n_flags & RATE_MCS_CCK_MSK) &&
513 rate_n_flags & RATE_MCS_SGI_MSK)
514 rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
515 if (rate_n_flags & RATE_HT_MCS_GF_MSK)
516 rx_status->enc_flags |= RX_ENC_FLAG_HT_GF;
517 if (rate_n_flags & RATE_MCS_LDPC_MSK)
518 rx_status->enc_flags |= RX_ENC_FLAG_LDPC;
519 if (rate_n_flags & RATE_MCS_HT_MSK) {
520 u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
521 RATE_MCS_STBC_POS;
522 rx_status->encoding = RX_ENC_HT;
523 rx_status->rate_idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK;
524 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
525 } else if (rate_n_flags & RATE_MCS_VHT_MSK) {
526 u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
527 RATE_MCS_STBC_POS;
528 rx_status->nss =
529 ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >>
530 RATE_VHT_MCS_NSS_POS) + 1;
531 rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK;
532 rx_status->encoding = RX_ENC_VHT;
533 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
534 if (rate_n_flags & RATE_MCS_BF_MSK)
535 rx_status->enc_flags |= RX_ENC_FLAG_BF;
536 } else {
537 int rate = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags,
538 rx_status->band);
539
540 if (WARN(rate < 0 || rate > 0xFF,
541 "Invalid rate flags 0x%x, band %d,\n",
542 rate_n_flags, rx_status->band)) {
543 kfree_skb(skb);
544 return;
545 }
546 rx_status->rate_idx = rate;
547 }
548
549 #ifdef CONFIG_IWLWIFI_DEBUGFS
550 iwl_mvm_update_frame_stats(mvm, rate_n_flags,
551 rx_status->flag & RX_FLAG_AMPDU_DETAILS);
552 #endif
553
554 if (unlikely((ieee80211_is_beacon(hdr->frame_control) ||
555 ieee80211_is_probe_resp(hdr->frame_control)) &&
556 mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED))
557 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_FOUND;
558
559 if (unlikely(ieee80211_is_beacon(hdr->frame_control) ||
560 ieee80211_is_probe_resp(hdr->frame_control)))
561 rx_status->boottime_ns = ktime_get_boottime_ns();
562
563 iwl_mvm_pass_packet_to_mac80211(mvm, sta, napi, skb, hdr, len,
564 crypt_len, rxb);
565 }
566
567 struct iwl_mvm_stat_data {
568 struct iwl_mvm *mvm;
569 __le32 flags;
570 __le32 mac_id;
571 u8 beacon_filter_average_energy;
572 void *general;
573 };
574
575 static void iwl_mvm_stat_iterator(void *_data, u8 *mac,
576 struct ieee80211_vif *vif)
577 {
578 struct iwl_mvm_stat_data *data = _data;
579 struct iwl_mvm *mvm = data->mvm;
580 int sig = -data->beacon_filter_average_energy;
581 int last_event;
582 int thold = vif->bss_conf.cqm_rssi_thold;
583 int hyst = vif->bss_conf.cqm_rssi_hyst;
584 u16 id = le32_to_cpu(data->mac_id);
585 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
586 u16 vif_id = mvmvif->id;
587
588
589
590
591
592 if (iwl_mvm_has_new_rx_stats_api(mvm)) {
593 struct mvm_statistics_general *general =
594 data->general;
595
596 mvmvif->beacon_stats.num_beacons =
597 le32_to_cpu(general->beacon_counter[vif_id]);
598 mvmvif->beacon_stats.avg_signal =
599 -general->beacon_average_energy[vif_id];
600 } else {
601 struct mvm_statistics_general_v8 *general =
602 data->general;
603
604 mvmvif->beacon_stats.num_beacons =
605 le32_to_cpu(general->beacon_counter[vif_id]);
606 mvmvif->beacon_stats.avg_signal =
607 -general->beacon_average_energy[vif_id];
608 }
609
610
611
612
613 if (le32_to_cpu(data->flags) & IWL_STATISTICS_REPLY_FLG_CLEAR)
614 mvmvif->beacon_stats.accu_num_beacons +=
615 mvmvif->beacon_stats.num_beacons;
616
617 if (mvmvif->id != id)
618 return;
619
620 if (vif->type != NL80211_IFTYPE_STATION)
621 return;
622
623 if (sig == 0) {
624 IWL_DEBUG_RX(mvm, "RSSI is 0 - skip signal based decision\n");
625 return;
626 }
627
628 mvmvif->bf_data.ave_beacon_signal = sig;
629
630
631 if (mvmvif->bf_data.bt_coex_min_thold !=
632 mvmvif->bf_data.bt_coex_max_thold) {
633 last_event = mvmvif->bf_data.last_bt_coex_event;
634 if (sig > mvmvif->bf_data.bt_coex_max_thold &&
635 (last_event <= mvmvif->bf_data.bt_coex_min_thold ||
636 last_event == 0)) {
637 mvmvif->bf_data.last_bt_coex_event = sig;
638 IWL_DEBUG_RX(mvm, "cqm_iterator bt coex high %d\n",
639 sig);
640 iwl_mvm_bt_rssi_event(mvm, vif, RSSI_EVENT_HIGH);
641 } else if (sig < mvmvif->bf_data.bt_coex_min_thold &&
642 (last_event >= mvmvif->bf_data.bt_coex_max_thold ||
643 last_event == 0)) {
644 mvmvif->bf_data.last_bt_coex_event = sig;
645 IWL_DEBUG_RX(mvm, "cqm_iterator bt coex low %d\n",
646 sig);
647 iwl_mvm_bt_rssi_event(mvm, vif, RSSI_EVENT_LOW);
648 }
649 }
650
651 if (!(vif->driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
652 return;
653
654
655 last_event = mvmvif->bf_data.last_cqm_event;
656 if (thold && sig < thold && (last_event == 0 ||
657 sig < last_event - hyst)) {
658 mvmvif->bf_data.last_cqm_event = sig;
659 IWL_DEBUG_RX(mvm, "cqm_iterator cqm low %d\n",
660 sig);
661 ieee80211_cqm_rssi_notify(
662 vif,
663 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
664 sig,
665 GFP_KERNEL);
666 } else if (sig > thold &&
667 (last_event == 0 || sig > last_event + hyst)) {
668 mvmvif->bf_data.last_cqm_event = sig;
669 IWL_DEBUG_RX(mvm, "cqm_iterator cqm high %d\n",
670 sig);
671 ieee80211_cqm_rssi_notify(
672 vif,
673 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
674 sig,
675 GFP_KERNEL);
676 }
677 }
678
679 static inline void
680 iwl_mvm_rx_stats_check_trigger(struct iwl_mvm *mvm, struct iwl_rx_packet *pkt)
681 {
682 struct iwl_fw_dbg_trigger_tlv *trig;
683 struct iwl_fw_dbg_trigger_stats *trig_stats;
684 u32 trig_offset, trig_thold;
685
686 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, NULL, FW_DBG_TRIGGER_STATS);
687 if (!trig)
688 return;
689
690 trig_stats = (void *)trig->data;
691
692 trig_offset = le32_to_cpu(trig_stats->stop_offset);
693 trig_thold = le32_to_cpu(trig_stats->stop_threshold);
694
695 if (WARN_ON_ONCE(trig_offset >= iwl_rx_packet_payload_len(pkt)))
696 return;
697
698 if (le32_to_cpup((__le32 *) (pkt->data + trig_offset)) < trig_thold)
699 return;
700
701 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, NULL);
702 }
703
704 void iwl_mvm_handle_rx_statistics(struct iwl_mvm *mvm,
705 struct iwl_rx_packet *pkt)
706 {
707 struct iwl_mvm_stat_data data = {
708 .mvm = mvm,
709 };
710 int expected_size;
711 int i;
712 u8 *energy;
713 __le32 *bytes;
714 __le32 *air_time;
715 __le32 flags;
716
717 if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
718 if (iwl_mvm_has_new_rx_api(mvm))
719 expected_size = sizeof(struct iwl_notif_statistics_v11);
720 else
721 expected_size = sizeof(struct iwl_notif_statistics_v10);
722 } else {
723 expected_size = sizeof(struct iwl_notif_statistics);
724 }
725
726 if (WARN_ONCE(iwl_rx_packet_payload_len(pkt) != expected_size,
727 "received invalid statistics size (%d)!\n",
728 iwl_rx_packet_payload_len(pkt)))
729 return;
730
731 if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
732 struct iwl_notif_statistics_v11 *stats = (void *)&pkt->data;
733
734 data.mac_id = stats->rx.general.mac_id;
735 data.beacon_filter_average_energy =
736 stats->general.common.beacon_filter_average_energy;
737
738 mvm->rx_stats_v3 = stats->rx;
739
740 mvm->radio_stats.rx_time =
741 le64_to_cpu(stats->general.common.rx_time);
742 mvm->radio_stats.tx_time =
743 le64_to_cpu(stats->general.common.tx_time);
744 mvm->radio_stats.on_time_rf =
745 le64_to_cpu(stats->general.common.on_time_rf);
746 mvm->radio_stats.on_time_scan =
747 le64_to_cpu(stats->general.common.on_time_scan);
748
749 data.general = &stats->general;
750
751 flags = stats->flag;
752 } else {
753 struct iwl_notif_statistics *stats = (void *)&pkt->data;
754
755 data.mac_id = stats->rx.general.mac_id;
756 data.beacon_filter_average_energy =
757 stats->general.common.beacon_filter_average_energy;
758
759 mvm->rx_stats = stats->rx;
760
761 mvm->radio_stats.rx_time =
762 le64_to_cpu(stats->general.common.rx_time);
763 mvm->radio_stats.tx_time =
764 le64_to_cpu(stats->general.common.tx_time);
765 mvm->radio_stats.on_time_rf =
766 le64_to_cpu(stats->general.common.on_time_rf);
767 mvm->radio_stats.on_time_scan =
768 le64_to_cpu(stats->general.common.on_time_scan);
769
770 data.general = &stats->general;
771
772 flags = stats->flag;
773 }
774 data.flags = flags;
775
776 iwl_mvm_rx_stats_check_trigger(mvm, pkt);
777
778 ieee80211_iterate_active_interfaces(mvm->hw,
779 IEEE80211_IFACE_ITER_NORMAL,
780 iwl_mvm_stat_iterator,
781 &data);
782
783 if (!iwl_mvm_has_new_rx_api(mvm))
784 return;
785
786 if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
787 struct iwl_notif_statistics_v11 *v11 = (void *)&pkt->data;
788
789 energy = (void *)&v11->load_stats.avg_energy;
790 bytes = (void *)&v11->load_stats.byte_count;
791 air_time = (void *)&v11->load_stats.air_time;
792 } else {
793 struct iwl_notif_statistics *stats = (void *)&pkt->data;
794
795 energy = (void *)&stats->load_stats.avg_energy;
796 bytes = (void *)&stats->load_stats.byte_count;
797 air_time = (void *)&stats->load_stats.air_time;
798 }
799
800 rcu_read_lock();
801 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
802 struct iwl_mvm_sta *sta;
803
804 if (!energy[i])
805 continue;
806
807 sta = iwl_mvm_sta_from_staid_rcu(mvm, i);
808 if (!sta)
809 continue;
810 sta->avg_energy = energy[i];
811 }
812 rcu_read_unlock();
813
814
815
816
817
818
819 if (!(le32_to_cpu(flags) & IWL_STATISTICS_REPLY_FLG_CLEAR))
820 return;
821
822 spin_lock(&mvm->tcm.lock);
823 for (i = 0; i < NUM_MAC_INDEX_DRIVER; i++) {
824 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[i];
825 u32 airtime = le32_to_cpu(air_time[i]);
826 u32 rx_bytes = le32_to_cpu(bytes[i]);
827
828 mdata->uapsd_nonagg_detect.rx_bytes += rx_bytes;
829 if (airtime) {
830
831 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
832 ewma_rate_add(&mdata->uapsd_nonagg_detect.rate,
833 rx_bytes * 8 / airtime);
834 }
835
836 mdata->rx.airtime += airtime;
837 }
838 spin_unlock(&mvm->tcm.lock);
839 }
840
841 void iwl_mvm_rx_statistics(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
842 {
843 iwl_mvm_handle_rx_statistics(mvm, rxb_addr(rxb));
844 }
845
846 void iwl_mvm_window_status_notif(struct iwl_mvm *mvm,
847 struct iwl_rx_cmd_buffer *rxb)
848 {
849 struct iwl_rx_packet *pkt = rxb_addr(rxb);
850 struct iwl_ba_window_status_notif *notif = (void *)pkt->data;
851 int i;
852 u32 pkt_len = iwl_rx_packet_payload_len(pkt);
853
854 if (WARN_ONCE(pkt_len != sizeof(*notif),
855 "Received window status notification of wrong size (%u)\n",
856 pkt_len))
857 return;
858
859 rcu_read_lock();
860 for (i = 0; i < BA_WINDOW_STREAMS_MAX; i++) {
861 struct ieee80211_sta *sta;
862 u8 sta_id, tid;
863 u64 bitmap;
864 u32 ssn;
865 u16 ratid;
866 u16 received_mpdu;
867
868 ratid = le16_to_cpu(notif->ra_tid[i]);
869
870 if (!(ratid & BA_WINDOW_STATUS_VALID_MSK))
871 continue;
872
873 received_mpdu = le16_to_cpu(notif->mpdu_rx_count[i]);
874 if (received_mpdu == 0)
875 continue;
876
877 tid = ratid & BA_WINDOW_STATUS_TID_MSK;
878
879 sta_id = (ratid & BA_WINDOW_STATUS_STA_ID_MSK)
880 >> BA_WINDOW_STATUS_STA_ID_POS;
881 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
882 if (IS_ERR_OR_NULL(sta))
883 continue;
884 bitmap = le64_to_cpu(notif->bitmap[i]);
885 ssn = le32_to_cpu(notif->start_seq_num[i]);
886
887
888 ieee80211_mark_rx_ba_filtered_frames(sta, tid, ssn, bitmap,
889 received_mpdu);
890 }
891 rcu_read_unlock();
892 }