1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2012-2014, 2018-2024 Intel Corporation
4 * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5 * Copyright (C) 2016-2017 Intel Deutschland GmbH
7 #include <linux/unaligned.h>
8 #include <linux/etherdevice.h>
9 #include <linux/skbuff.h>
10 #include "iwl-trans.h"
15 * iwl_mvm_rx_rx_phy_cmd - REPLY_RX_PHY_CMD handler
17 * Copies the phy information in mvm->last_phy_info, it will be used when the
18 * actual data will come from the fw in the next packet.
20 void iwl_mvm_rx_rx_phy_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
22 struct iwl_rx_packet *pkt = rxb_addr(rxb);
23 unsigned int pkt_len = iwl_rx_packet_payload_len(pkt);
25 if (unlikely(pkt_len < sizeof(mvm->last_phy_info)))
28 memcpy(&mvm->last_phy_info, pkt->data, sizeof(mvm->last_phy_info));
31 #ifdef CONFIG_IWLWIFI_DEBUGFS
32 if (mvm->last_phy_info.phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_AGG)) {
33 spin_lock(&mvm->drv_stats_lock);
34 mvm->drv_rx_stats.ampdu_count++;
35 spin_unlock(&mvm->drv_stats_lock);
41 * iwl_mvm_pass_packet_to_mac80211 - builds the packet for mac80211
43 * Adds the rxb to a new skb and give it to mac80211
45 static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm *mvm,
46 struct ieee80211_sta *sta,
47 struct napi_struct *napi,
49 struct ieee80211_hdr *hdr, u16 len,
51 struct iwl_rx_cmd_buffer *rxb)
53 unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control);
57 * The 'hdrlen' (plus the 8 bytes for the SNAP and the crypt_len,
58 * but those are all multiples of 4 long) all goes away, but we
59 * want the *end* of it, which is going to be the start of the IP
60 * header, to be aligned when it gets pulled in.
61 * The beginning of the skb->data is aligned on at least a 4-byte
62 * boundary after allocation. Everything here is aligned at least
63 * on a 2-byte boundary so we can just take hdrlen & 3 and pad by
66 skb_reserve(skb, hdrlen & 3);
68 /* If frame is small enough to fit in skb->head, pull it completely.
69 * If not, only pull ieee80211_hdr (including crypto if present, and
70 * an additional 8 bytes for SNAP/ethertype, see below) so that
71 * splice() or TCP coalesce are more efficient.
73 * Since, in addition, ieee80211_data_to_8023() always pull in at
74 * least 8 bytes (possibly more for mesh) we can do the same here
75 * to save the cost of doing it later. That still doesn't pull in
76 * the actual IP header since the typical case has a SNAP header.
77 * If the latter changes (there are efforts in the standards group
78 * to do so) we should revisit this and ieee80211_data_to_8023().
80 hdrlen = (len <= skb_tailroom(skb)) ? len : hdrlen + crypt_len + 8;
82 skb_put_data(skb, hdr, hdrlen);
83 fraglen = len - hdrlen;
86 int offset = (u8 *)hdr + hdrlen -
87 (u8 *)rxb_addr(rxb) + rxb_offset(rxb);
89 skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset,
90 fraglen, rxb->truesize);
93 ieee80211_rx_napi(mvm->hw, sta, skb, napi);
97 * iwl_mvm_get_signal_strength - use new rx PHY INFO API
98 * values are reported by the fw as positive values - need to negate
99 * to obtain their dBM. Account for missing antennas by replacing 0
100 * values by -256dBm: practically 0 power and a non-feasible 8 bit value.
102 static void iwl_mvm_get_signal_strength(struct iwl_mvm *mvm,
103 struct iwl_rx_phy_info *phy_info,
104 struct ieee80211_rx_status *rx_status)
106 int energy_a, energy_b, max_energy;
110 le32_to_cpu(phy_info->non_cfg_phy[IWL_RX_INFO_ENERGY_ANT_ABC_IDX]);
111 energy_a = (val & IWL_RX_INFO_ENERGY_ANT_A_MSK) >>
112 IWL_RX_INFO_ENERGY_ANT_A_POS;
113 energy_a = energy_a ? -energy_a : S8_MIN;
114 energy_b = (val & IWL_RX_INFO_ENERGY_ANT_B_MSK) >>
115 IWL_RX_INFO_ENERGY_ANT_B_POS;
116 energy_b = energy_b ? -energy_b : S8_MIN;
117 max_energy = max(energy_a, energy_b);
119 IWL_DEBUG_STATS(mvm, "energy In A %d B %d , and max %d\n",
120 energy_a, energy_b, max_energy);
122 rx_status->signal = max_energy;
123 rx_status->chains = (le16_to_cpu(phy_info->phy_flags) &
124 RX_RES_PHY_FLAGS_ANTENNA)
125 >> RX_RES_PHY_FLAGS_ANTENNA_POS;
126 rx_status->chain_signal[0] = energy_a;
127 rx_status->chain_signal[1] = energy_b;
131 * iwl_mvm_set_mac80211_rx_flag - translate fw status to mac80211 format
132 * @mvm: the mvm object
134 * @stats: status in mac80211's format
135 * @rx_pkt_status: status coming from fw
137 * returns non 0 value if the packet should be dropped
139 static u32 iwl_mvm_set_mac80211_rx_flag(struct iwl_mvm *mvm,
140 struct ieee80211_hdr *hdr,
141 struct ieee80211_rx_status *stats,
145 if (!ieee80211_has_protected(hdr->frame_control) ||
146 (rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) ==
147 RX_MPDU_RES_STATUS_SEC_NO_ENC)
150 /* packet was encrypted with unknown alg */
151 if ((rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) ==
152 RX_MPDU_RES_STATUS_SEC_ENC_ERR)
155 switch (rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) {
156 case RX_MPDU_RES_STATUS_SEC_CCM_ENC:
157 /* alg is CCM: check MIC only */
158 if (!(rx_pkt_status & RX_MPDU_RES_STATUS_MIC_OK))
161 stats->flag |= RX_FLAG_DECRYPTED;
162 *crypt_len = IEEE80211_CCMP_HDR_LEN;
165 case RX_MPDU_RES_STATUS_SEC_TKIP_ENC:
166 /* Don't drop the frame and decrypt it in SW */
167 if (!fw_has_api(&mvm->fw->ucode_capa,
168 IWL_UCODE_TLV_API_DEPRECATE_TTAK) &&
169 !(rx_pkt_status & RX_MPDU_RES_STATUS_TTAK_OK))
171 *crypt_len = IEEE80211_TKIP_IV_LEN;
174 case RX_MPDU_RES_STATUS_SEC_WEP_ENC:
175 if (!(rx_pkt_status & RX_MPDU_RES_STATUS_ICV_OK))
178 stats->flag |= RX_FLAG_DECRYPTED;
179 if ((rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) ==
180 RX_MPDU_RES_STATUS_SEC_WEP_ENC)
181 *crypt_len = IEEE80211_WEP_IV_LEN;
184 case RX_MPDU_RES_STATUS_SEC_EXT_ENC:
185 if (!(rx_pkt_status & RX_MPDU_RES_STATUS_MIC_OK))
187 stats->flag |= RX_FLAG_DECRYPTED;
191 /* Expected in monitor (not having the keys) */
192 if (!mvm->monitor_on)
193 IWL_WARN(mvm, "Unhandled alg: 0x%x\n", rx_pkt_status);
199 static void iwl_mvm_rx_handle_tcm(struct iwl_mvm *mvm,
200 struct ieee80211_sta *sta,
201 struct ieee80211_hdr *hdr, u32 len,
202 struct iwl_rx_phy_info *phy_info,
205 struct iwl_mvm_sta *mvmsta;
206 struct iwl_mvm_tcm_mac *mdata;
208 int ac = IEEE80211_AC_BE; /* treat non-QoS as BE */
209 struct iwl_mvm_vif *mvmvif;
210 /* expected throughput in 100Kbps, single stream, 20 MHz */
211 static const u8 thresh_tpt[] = {
212 9, 18, 30, 42, 60, 78, 90, 96, 120, 135,
216 if (ieee80211_is_data_qos(hdr->frame_control)) {
217 u8 tid = ieee80211_get_tid(hdr);
219 if (tid < IWL_MAX_TID_COUNT)
220 ac = tid_to_mac80211_ac[tid];
223 mvmsta = iwl_mvm_sta_from_mac80211(sta);
224 mac = mvmsta->mac_id_n_color & FW_CTXT_ID_MSK;
226 if (time_after(jiffies, mvm->tcm.ts + MVM_TCM_PERIOD))
227 schedule_delayed_work(&mvm->tcm.work, 0);
228 mdata = &mvm->tcm.data[mac];
229 mdata->rx.pkts[ac]++;
231 /* count the airtime only once for each ampdu */
232 if (mdata->rx.last_ampdu_ref != mvm->ampdu_ref) {
233 mdata->rx.last_ampdu_ref = mvm->ampdu_ref;
234 mdata->rx.airtime += le16_to_cpu(phy_info->frame_time);
237 if (!(rate_n_flags & (RATE_MCS_HT_MSK_V1 | RATE_MCS_VHT_MSK_V1)))
240 mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
242 if (mdata->opened_rx_ba_sessions ||
243 mdata->uapsd_nonagg_detect.detected ||
244 (!mvmvif->deflink.queue_params[IEEE80211_AC_VO].uapsd &&
245 !mvmvif->deflink.queue_params[IEEE80211_AC_VI].uapsd &&
246 !mvmvif->deflink.queue_params[IEEE80211_AC_BE].uapsd &&
247 !mvmvif->deflink.queue_params[IEEE80211_AC_BK].uapsd) ||
248 mvmsta->deflink.sta_id != mvmvif->deflink.ap_sta_id)
251 if (rate_n_flags & RATE_MCS_HT_MSK_V1) {
252 thr = thresh_tpt[rate_n_flags & RATE_HT_MCS_RATE_CODE_MSK_V1];
253 thr *= 1 + ((rate_n_flags & RATE_HT_MCS_NSS_MSK_V1) >>
254 RATE_HT_MCS_NSS_POS_V1);
256 if (WARN_ON((rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK) >=
257 ARRAY_SIZE(thresh_tpt)))
259 thr = thresh_tpt[rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK];
260 thr *= 1 + FIELD_GET(RATE_MCS_NSS_MSK, rate_n_flags);
263 thr <<= ((rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK_V1) >>
264 RATE_MCS_CHAN_WIDTH_POS);
266 mdata->uapsd_nonagg_detect.rx_bytes += len;
267 ewma_rate_add(&mdata->uapsd_nonagg_detect.rate, thr);
270 static void iwl_mvm_rx_csum(struct ieee80211_sta *sta,
274 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
275 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
277 if (mvmvif->features & NETIF_F_RXCSUM &&
278 status & RX_MPDU_RES_STATUS_CSUM_DONE &&
279 status & RX_MPDU_RES_STATUS_CSUM_OK)
280 skb->ip_summed = CHECKSUM_UNNECESSARY;
284 * iwl_mvm_rx_rx_mpdu - REPLY_RX_MPDU_CMD handler
286 * Handles the actual data of the Rx packet from the fw
288 void iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct napi_struct *napi,
289 struct iwl_rx_cmd_buffer *rxb)
291 struct ieee80211_hdr *hdr;
292 struct ieee80211_rx_status *rx_status;
293 struct iwl_rx_packet *pkt = rxb_addr(rxb);
294 struct iwl_rx_phy_info *phy_info;
295 struct iwl_rx_mpdu_res_start *rx_res;
296 struct ieee80211_sta *sta = NULL;
298 u32 len, pkt_len = iwl_rx_packet_payload_len(pkt);
303 if (unlikely(pkt_len < sizeof(*rx_res))) {
304 IWL_DEBUG_DROP(mvm, "Bad REPLY_RX_MPDU_CMD size\n");
308 phy_info = &mvm->last_phy_info;
309 rx_res = (struct iwl_rx_mpdu_res_start *)pkt->data;
310 hdr = (struct ieee80211_hdr *)(pkt->data + sizeof(*rx_res));
311 len = le16_to_cpu(rx_res->byte_count);
313 if (unlikely(len + sizeof(*rx_res) + sizeof(__le32) > pkt_len)) {
314 IWL_DEBUG_DROP(mvm, "FW lied about packet len\n");
318 rx_pkt_status = get_unaligned_le32((__le32 *)
319 (pkt->data + sizeof(*rx_res) + len));
321 /* Dont use dev_alloc_skb(), we'll have enough headroom once
322 * ieee80211_hdr pulled.
324 skb = alloc_skb(128, GFP_ATOMIC);
326 IWL_ERR(mvm, "alloc_skb failed\n");
330 rx_status = IEEE80211_SKB_RXCB(skb);
333 * Keep packets with CRC errors (and with overrun) for monitor mode
334 * (otherwise the firmware discards them) but mark them as bad.
336 if (!(rx_pkt_status & RX_MPDU_RES_STATUS_CRC_OK) ||
337 !(rx_pkt_status & RX_MPDU_RES_STATUS_OVERRUN_OK)) {
338 IWL_DEBUG_RX(mvm, "Bad CRC or FIFO: 0x%08X.\n", rx_pkt_status);
339 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
342 /* This will be used in several places later */
343 rate_n_flags = le32_to_cpu(phy_info->rate_n_flags);
345 /* rx_status carries information about the packet to mac80211 */
346 rx_status->mactime = le64_to_cpu(phy_info->timestamp);
347 rx_status->device_timestamp = le32_to_cpu(phy_info->system_timestamp);
349 (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_BAND_24)) ?
350 NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
352 ieee80211_channel_to_frequency(le16_to_cpu(phy_info->channel),
355 /* TSF as indicated by the firmware is at INA time */
356 rx_status->flag |= RX_FLAG_MACTIME_PLCP_START;
358 iwl_mvm_get_signal_strength(mvm, phy_info, rx_status);
360 IWL_DEBUG_STATS_LIMIT(mvm, "Rssi %d, TSF %llu\n", rx_status->signal,
361 (unsigned long long)rx_status->mactime);
364 if (rx_pkt_status & RX_MPDU_RES_STATUS_SRC_STA_FOUND) {
365 u32 id = rx_pkt_status & RX_MPDU_RES_STATUS_STA_ID_MSK;
367 id >>= RX_MDPU_RES_STATUS_STA_ID_SHIFT;
369 if (!WARN_ON_ONCE(id >= mvm->fw->ucode_capa.num_stations)) {
370 sta = rcu_dereference(mvm->fw_id_to_mac_id[id]);
374 } else if (!is_multicast_ether_addr(hdr->addr2)) {
375 /* This is fine since we prevent two stations with the same
376 * address from being added.
378 sta = ieee80211_find_sta_by_ifaddr(mvm->hw, hdr->addr2, NULL);
382 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
383 struct ieee80211_vif *vif = mvmsta->vif;
384 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
387 * Don't even try to decrypt a MCAST frame that was received
388 * before the managed vif is authorized, we'd fail anyway.
390 if (is_multicast_ether_addr(hdr->addr1) &&
391 vif->type == NL80211_IFTYPE_STATION &&
392 !mvmvif->authorized &&
393 ieee80211_has_protected(hdr->frame_control)) {
394 IWL_DEBUG_DROP(mvm, "MCAST before the vif is authorized\n");
402 * drop the packet if it has failed being decrypted by HW
404 if (iwl_mvm_set_mac80211_rx_flag(mvm, hdr, rx_status, rx_pkt_status,
406 IWL_DEBUG_DROP(mvm, "Bad decryption results 0x%08x\n",
414 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
415 struct ieee80211_vif *tx_blocked_vif =
416 rcu_dereference(mvm->csa_tx_blocked_vif);
417 struct iwl_fw_dbg_trigger_tlv *trig;
418 struct ieee80211_vif *vif = mvmsta->vif;
420 /* We have tx blocked stations (with CS bit). If we heard
421 * frames from a blocked station on a new channel we can
424 if (unlikely(tx_blocked_vif) && vif == tx_blocked_vif) {
425 struct iwl_mvm_vif *mvmvif =
426 iwl_mvm_vif_from_mac80211(tx_blocked_vif);
428 if (mvmvif->csa_target_freq == rx_status->freq)
429 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta,
433 rs_update_last_rssi(mvm, mvmsta, rx_status);
435 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt,
436 ieee80211_vif_to_wdev(vif),
437 FW_DBG_TRIGGER_RSSI);
439 if (trig && ieee80211_is_beacon(hdr->frame_control)) {
440 struct iwl_fw_dbg_trigger_low_rssi *rssi_trig;
443 rssi_trig = (void *)trig->data;
444 rssi = le32_to_cpu(rssi_trig->rssi);
446 if (rx_status->signal < rssi)
447 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
451 if (!mvm->tcm.paused && len >= sizeof(*hdr) &&
452 !is_multicast_ether_addr(hdr->addr1) &&
453 ieee80211_is_data(hdr->frame_control))
454 iwl_mvm_rx_handle_tcm(mvm, sta, hdr, len, phy_info,
457 if (ieee80211_is_data(hdr->frame_control))
458 iwl_mvm_rx_csum(sta, skb, rx_pkt_status);
462 /* set the preamble flag if appropriate */
463 if (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_SHORT_PREAMBLE))
464 rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE;
466 if (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_AGG)) {
468 * We know which subframes of an A-MPDU belong
469 * together since we get a single PHY response
470 * from the firmware for all of them
472 rx_status->flag |= RX_FLAG_AMPDU_DETAILS;
473 rx_status->ampdu_reference = mvm->ampdu_ref;
476 /* Set up the HT phy flags */
477 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK_V1) {
478 case RATE_MCS_CHAN_WIDTH_20:
480 case RATE_MCS_CHAN_WIDTH_40:
481 rx_status->bw = RATE_INFO_BW_40;
483 case RATE_MCS_CHAN_WIDTH_80:
484 rx_status->bw = RATE_INFO_BW_80;
486 case RATE_MCS_CHAN_WIDTH_160:
487 rx_status->bw = RATE_INFO_BW_160;
490 if (!(rate_n_flags & RATE_MCS_CCK_MSK_V1) &&
491 rate_n_flags & RATE_MCS_SGI_MSK_V1)
492 rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
493 if (rate_n_flags & RATE_HT_MCS_GF_MSK)
494 rx_status->enc_flags |= RX_ENC_FLAG_HT_GF;
495 if (rate_n_flags & RATE_MCS_LDPC_MSK_V1)
496 rx_status->enc_flags |= RX_ENC_FLAG_LDPC;
497 if (rate_n_flags & RATE_MCS_HT_MSK_V1) {
498 u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
500 rx_status->encoding = RX_ENC_HT;
501 rx_status->rate_idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK_V1;
502 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
503 } else if (rate_n_flags & RATE_MCS_VHT_MSK_V1) {
504 u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
507 FIELD_GET(RATE_MCS_NSS_MSK, rate_n_flags) + 1;
508 rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK;
509 rx_status->encoding = RX_ENC_VHT;
510 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
511 if (rate_n_flags & RATE_MCS_BF_MSK)
512 rx_status->enc_flags |= RX_ENC_FLAG_BF;
514 int rate = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags,
517 if (WARN(rate < 0 || rate > 0xFF,
518 "Invalid rate flags 0x%x, band %d,\n",
519 rate_n_flags, rx_status->band)) {
523 rx_status->rate_idx = rate;
526 #ifdef CONFIG_IWLWIFI_DEBUGFS
527 iwl_mvm_update_frame_stats(mvm, rate_n_flags,
528 rx_status->flag & RX_FLAG_AMPDU_DETAILS);
531 if (unlikely((ieee80211_is_beacon(hdr->frame_control) ||
532 ieee80211_is_probe_resp(hdr->frame_control)) &&
533 mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED))
534 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_FOUND;
536 if (unlikely(ieee80211_is_beacon(hdr->frame_control) ||
537 ieee80211_is_probe_resp(hdr->frame_control)))
538 rx_status->boottime_ns = ktime_get_boottime_ns();
540 iwl_mvm_pass_packet_to_mac80211(mvm, sta, napi, skb, hdr, len,
544 struct iwl_mvm_stat_data {
548 u8 beacon_filter_average_energy;
549 __le32 *beacon_counter;
550 u8 *beacon_average_energy;
553 struct iwl_mvm_stat_data_all_macs {
556 struct iwl_stats_ntfy_per_mac *per_mac;
559 static void iwl_mvm_update_link_sig(struct ieee80211_vif *vif, int sig,
560 struct iwl_mvm_vif_link_info *link_info,
561 struct ieee80211_bss_conf *bss_conf)
563 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
564 struct iwl_mvm *mvm = mvmvif->mvm;
565 int thold = bss_conf->cqm_rssi_thold;
566 int hyst = bss_conf->cqm_rssi_hyst;
571 IWL_DEBUG_RX(mvm, "RSSI is 0 - skip signal based decision\n");
575 link_info->bf_data.ave_beacon_signal = sig;
578 if (link_info->bf_data.bt_coex_min_thold !=
579 link_info->bf_data.bt_coex_max_thold) {
580 last_event = link_info->bf_data.last_bt_coex_event;
581 if (sig > link_info->bf_data.bt_coex_max_thold &&
582 (last_event <= link_info->bf_data.bt_coex_min_thold ||
584 link_info->bf_data.last_bt_coex_event = sig;
585 IWL_DEBUG_RX(mvm, "cqm_iterator bt coex high %d\n",
587 iwl_mvm_bt_rssi_event(mvm, vif, RSSI_EVENT_HIGH);
588 } else if (sig < link_info->bf_data.bt_coex_min_thold &&
589 (last_event >= link_info->bf_data.bt_coex_max_thold ||
591 link_info->bf_data.last_bt_coex_event = sig;
592 IWL_DEBUG_RX(mvm, "cqm_iterator bt coex low %d\n",
594 iwl_mvm_bt_rssi_event(mvm, vif, RSSI_EVENT_LOW);
598 if (!(vif->driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
601 /* CQM Notification */
602 last_event = link_info->bf_data.last_cqm_event;
603 if (thold && sig < thold && (last_event == 0 ||
604 sig < last_event - hyst)) {
605 link_info->bf_data.last_cqm_event = sig;
606 IWL_DEBUG_RX(mvm, "cqm_iterator cqm low %d\n",
608 ieee80211_cqm_rssi_notify(
610 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
613 } else if (sig > thold &&
614 (last_event == 0 || sig > last_event + hyst)) {
615 link_info->bf_data.last_cqm_event = sig;
616 IWL_DEBUG_RX(mvm, "cqm_iterator cqm high %d\n",
618 ieee80211_cqm_rssi_notify(
620 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
625 /* ESR recalculation */
626 if (!vif->cfg.assoc || !ieee80211_vif_is_mld(vif))
629 /* We're not in EMLSR and our signal is bad, try to switch link maybe */
630 if (sig < IWL_MVM_LOW_RSSI_MLO_SCAN_THRESH && !mvmvif->esr_active) {
631 iwl_mvm_int_mlo_scan(mvm, vif);
635 /* We are in EMLSR, check if we need to exit */
637 iwl_mvm_get_esr_rssi_thresh(mvm,
638 &bss_conf->chanreq.oper,
641 if (sig < exit_esr_thresh)
642 iwl_mvm_exit_esr(mvm, vif, IWL_MVM_ESR_EXIT_LOW_RSSI,
643 iwl_mvm_get_other_link(vif,
647 static void iwl_mvm_stat_iterator(void *_data, u8 *mac,
648 struct ieee80211_vif *vif)
650 struct iwl_mvm_stat_data *data = _data;
651 int sig = -data->beacon_filter_average_energy;
652 u16 id = le32_to_cpu(data->mac_id);
653 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
654 u16 vif_id = mvmvif->id;
656 /* This doesn't need the MAC ID check since it's not taking the
657 * data copied into the "data" struct, but rather the data from
658 * the notification directly.
660 mvmvif->deflink.beacon_stats.num_beacons =
661 le32_to_cpu(data->beacon_counter[vif_id]);
662 mvmvif->deflink.beacon_stats.avg_signal =
663 -data->beacon_average_energy[vif_id];
665 if (mvmvif->id != id)
668 if (vif->type != NL80211_IFTYPE_STATION)
671 /* make sure that beacon statistics don't go backwards with TCM
672 * request to clear statistics
674 if (le32_to_cpu(data->flags) & IWL_STATISTICS_REPLY_FLG_CLEAR)
675 mvmvif->deflink.beacon_stats.accu_num_beacons +=
676 mvmvif->deflink.beacon_stats.num_beacons;
678 /* This is used in pre-MLO API so use deflink */
679 iwl_mvm_update_link_sig(vif, sig, &mvmvif->deflink, &vif->bss_conf);
682 static void iwl_mvm_stat_iterator_all_macs(void *_data, u8 *mac,
683 struct ieee80211_vif *vif)
685 struct iwl_mvm_stat_data_all_macs *data = _data;
686 struct iwl_stats_ntfy_per_mac *mac_stats;
688 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
689 u16 vif_id = mvmvif->id;
691 if (WARN_ONCE(vif_id >= MAC_INDEX_AUX, "invalid vif id: %d", vif_id))
694 if (vif->type != NL80211_IFTYPE_STATION)
697 mac_stats = &data->per_mac[vif_id];
699 mvmvif->deflink.beacon_stats.num_beacons =
700 le32_to_cpu(mac_stats->beacon_counter);
701 mvmvif->deflink.beacon_stats.avg_signal =
702 -le32_to_cpu(mac_stats->beacon_average_energy);
704 /* make sure that beacon statistics don't go backwards with TCM
705 * request to clear statistics
707 if (le32_to_cpu(data->flags) & IWL_STATISTICS_REPLY_FLG_CLEAR)
708 mvmvif->deflink.beacon_stats.accu_num_beacons +=
709 mvmvif->deflink.beacon_stats.num_beacons;
711 sig = -le32_to_cpu(mac_stats->beacon_filter_average_energy);
713 /* This is used in pre-MLO API so use deflink */
714 iwl_mvm_update_link_sig(vif, sig, &mvmvif->deflink, &vif->bss_conf);
718 iwl_mvm_rx_stats_check_trigger(struct iwl_mvm *mvm, struct iwl_rx_packet *pkt)
720 struct iwl_fw_dbg_trigger_tlv *trig;
721 struct iwl_fw_dbg_trigger_stats *trig_stats;
722 u32 trig_offset, trig_thold;
724 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, NULL, FW_DBG_TRIGGER_STATS);
728 trig_stats = (void *)trig->data;
730 trig_offset = le32_to_cpu(trig_stats->stop_offset);
731 trig_thold = le32_to_cpu(trig_stats->stop_threshold);
733 if (WARN_ON_ONCE(trig_offset >= iwl_rx_packet_payload_len(pkt)))
736 if (le32_to_cpup((__le32 *) (pkt->data + trig_offset)) < trig_thold)
739 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, NULL);
742 static void iwl_mvm_stats_energy_iter(void *_data,
743 struct ieee80211_sta *sta)
745 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
747 u32 sta_id = mvmsta->deflink.sta_id;
749 if (WARN_ONCE(sta_id >= IWL_STATION_COUNT_MAX, "sta_id %d >= %d",
750 sta_id, IWL_STATION_COUNT_MAX))
754 mvmsta->deflink.avg_energy = energy[sta_id];
759 iwl_mvm_update_tcm_from_stats(struct iwl_mvm *mvm, __le32 *air_time_le,
764 spin_lock(&mvm->tcm.lock);
765 for (i = 0; i < NUM_MAC_INDEX_DRIVER; i++) {
766 struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[i];
767 u32 rx_bytes = le32_to_cpu(rx_bytes_le[i]);
768 u32 airtime = le32_to_cpu(air_time_le[i]);
770 mdata->rx.airtime += airtime;
771 mdata->uapsd_nonagg_detect.rx_bytes += rx_bytes;
773 /* re-init every time to store rate from FW */
774 ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
775 ewma_rate_add(&mdata->uapsd_nonagg_detect.rate,
776 rx_bytes * 8 / airtime);
779 spin_unlock(&mvm->tcm.lock);
782 static void iwl_mvm_handle_per_phy_stats(struct iwl_mvm *mvm,
783 struct iwl_stats_ntfy_per_phy *per_phy)
787 for (i = 0; i < NUM_PHY_CTX; i++) {
788 if (!mvm->phy_ctxts[i].ref)
790 mvm->phy_ctxts[i].channel_load_by_us =
791 le32_to_cpu(per_phy[i].channel_load_by_us);
792 mvm->phy_ctxts[i].channel_load_not_by_us =
793 le32_to_cpu(per_phy[i].channel_load_not_by_us);
798 iwl_mvm_stats_ver_15(struct iwl_mvm *mvm,
799 struct iwl_statistics_operational_ntfy *stats)
801 struct iwl_mvm_stat_data_all_macs data = {
803 .flags = stats->flags,
804 .per_mac = stats->per_mac,
807 ieee80211_iterate_active_interfaces(mvm->hw,
808 IEEE80211_IFACE_ITER_NORMAL,
809 iwl_mvm_stat_iterator_all_macs,
811 iwl_mvm_handle_per_phy_stats(mvm, stats->per_phy);
815 iwl_mvm_stats_ver_14(struct iwl_mvm *mvm,
816 struct iwl_statistics_operational_ntfy_ver_14 *stats)
818 struct iwl_mvm_stat_data data = {
822 u8 beacon_average_energy[MAC_INDEX_AUX];
826 flags = stats->flags;
828 data.mac_id = stats->mac_id;
829 data.beacon_filter_average_energy =
830 le32_to_cpu(stats->beacon_filter_average_energy);
832 data.beacon_counter = stats->beacon_counter;
834 for (i = 0; i < ARRAY_SIZE(beacon_average_energy); i++)
835 beacon_average_energy[i] =
836 le32_to_cpu(stats->beacon_average_energy[i]);
838 data.beacon_average_energy = beacon_average_energy;
840 ieee80211_iterate_active_interfaces(mvm->hw,
841 IEEE80211_IFACE_ITER_NORMAL,
842 iwl_mvm_stat_iterator,
846 static bool iwl_mvm_verify_stats_len(struct iwl_mvm *mvm,
847 struct iwl_rx_packet *pkt,
850 struct iwl_statistics_ntfy_hdr *hdr;
852 if (WARN_ONCE(iwl_rx_packet_payload_len(pkt) < expected_size,
853 "received invalid statistics size (%d)!, expected_size: %d\n",
854 iwl_rx_packet_payload_len(pkt), expected_size))
857 hdr = (void *)&pkt->data;
859 if (WARN_ONCE((hdr->type & IWL_STATISTICS_TYPE_MSK) != FW_STATISTICS_OPERATIONAL ||
861 iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP, STATISTICS_NOTIFICATION, 0),
862 "received unsupported hdr type %d, version %d\n",
863 hdr->type, hdr->version))
866 if (WARN_ONCE(le16_to_cpu(hdr->size) != expected_size,
867 "received invalid statistics size in header (%d)!, expected_size: %d\n",
868 le16_to_cpu(hdr->size), expected_size))
875 iwl_mvm_stat_iterator_all_links(struct iwl_mvm *mvm,
876 struct iwl_stats_ntfy_per_link *per_link)
878 u32 air_time[MAC_INDEX_AUX] = {};
879 u32 rx_bytes[MAC_INDEX_AUX] = {};
882 for (fw_link_id = 0; fw_link_id < ARRAY_SIZE(mvm->link_id_to_link_conf);
884 struct iwl_stats_ntfy_per_link *link_stats;
885 struct ieee80211_bss_conf *bss_conf;
886 struct iwl_mvm_vif *mvmvif;
887 struct iwl_mvm_vif_link_info *link_info;
891 bss_conf = iwl_mvm_rcu_fw_link_id_to_link_conf(mvm, fw_link_id,
896 if (bss_conf->vif->type != NL80211_IFTYPE_STATION)
899 link_id = bss_conf->link_id;
900 if (link_id >= ARRAY_SIZE(mvmvif->link))
903 mvmvif = iwl_mvm_vif_from_mac80211(bss_conf->vif);
904 link_info = mvmvif->link[link_id];
908 link_stats = &per_link[fw_link_id];
910 link_info->beacon_stats.num_beacons =
911 le32_to_cpu(link_stats->beacon_counter);
913 /* we basically just use the u8 to store 8 bits and then treat
914 * it as a s8 whenever we take it out to a different type.
916 link_info->beacon_stats.avg_signal =
917 -le32_to_cpu(link_stats->beacon_average_energy);
919 if (link_info->phy_ctxt &&
920 link_info->phy_ctxt->channel->band == NL80211_BAND_2GHZ)
921 iwl_mvm_bt_coex_update_link_esr(mvm, bss_conf->vif,
924 /* make sure that beacon statistics don't go backwards with TCM
925 * request to clear statistics
927 if (mvm->statistics_clear)
928 mvmvif->link[link_id]->beacon_stats.accu_num_beacons +=
929 mvmvif->link[link_id]->beacon_stats.num_beacons;
931 sig = -le32_to_cpu(link_stats->beacon_filter_average_energy);
932 iwl_mvm_update_link_sig(bss_conf->vif, sig, link_info,
935 if (WARN_ONCE(mvmvif->id >= MAC_INDEX_AUX,
936 "invalid mvmvif id: %d", mvmvif->id))
939 air_time[mvmvif->id] +=
940 le32_to_cpu(per_link[fw_link_id].air_time);
941 rx_bytes[mvmvif->id] +=
942 le32_to_cpu(per_link[fw_link_id].rx_bytes);
945 /* Don't update in case the statistics are not cleared, since
946 * we will end up counting twice the same airtime, once in TCM
947 * request and once in statistics notification.
949 if (mvm->statistics_clear) {
950 __le32 air_time_le[MAC_INDEX_AUX];
951 __le32 rx_bytes_le[MAC_INDEX_AUX];
954 for (vif_id = 0; vif_id < ARRAY_SIZE(air_time_le); vif_id++) {
955 air_time_le[vif_id] = cpu_to_le32(air_time[vif_id]);
956 rx_bytes_le[vif_id] = cpu_to_le32(rx_bytes[vif_id]);
959 iwl_mvm_update_tcm_from_stats(mvm, air_time_le, rx_bytes_le);
963 #define SEC_LINK_MIN_PERC 10
964 #define SEC_LINK_MIN_TX 3000
965 #define SEC_LINK_MIN_RX 400
967 /* Accept a ~20% short window to avoid issues due to jitter */
968 #define IWL_MVM_TPT_MIN_COUNT_WINDOW (IWL_MVM_TPT_COUNT_WINDOW_SEC * HZ * 4 / 5)
970 static void iwl_mvm_update_esr_mode_tpt(struct iwl_mvm *mvm)
972 struct ieee80211_vif *bss_vif = iwl_mvm_get_bss_vif(mvm);
973 struct iwl_mvm_vif *mvmvif;
974 struct iwl_mvm_sta *mvmsta;
975 unsigned long total_tx = 0, total_rx = 0;
976 unsigned long sec_link_tx = 0, sec_link_rx = 0;
977 u8 sec_link_tx_perc, sec_link_rx_perc;
981 lockdep_assert_held(&mvm->mutex);
983 if (IS_ERR_OR_NULL(bss_vif))
986 mvmvif = iwl_mvm_vif_from_mac80211(bss_vif);
988 if (!mvmvif->esr_active || !mvmvif->ap_sta)
991 mvmsta = iwl_mvm_sta_from_mac80211(mvmvif->ap_sta);
992 /* We only count for the AP sta in a MLO connection */
993 if (!mvmsta->mpdu_counters)
996 /* Get the FW ID of the secondary link */
997 sec_link = iwl_mvm_get_other_link(bss_vif,
998 iwl_mvm_get_primary_link(bss_vif));
999 if (WARN_ON(!mvmvif->link[sec_link]))
1001 sec_link = mvmvif->link[sec_link]->fw_link_id;
1003 /* Sum up RX and TX MPDUs from the different queues/links */
1004 for (int q = 0; q < mvm->trans->num_rx_queues; q++) {
1005 spin_lock_bh(&mvmsta->mpdu_counters[q].lock);
1007 /* The link IDs that doesn't exist will contain 0 */
1008 for (int link = 0; link < IWL_FW_MAX_LINK_ID; link++) {
1009 total_tx += mvmsta->mpdu_counters[q].per_link[link].tx;
1010 total_rx += mvmsta->mpdu_counters[q].per_link[link].rx;
1013 sec_link_tx += mvmsta->mpdu_counters[q].per_link[sec_link].tx;
1014 sec_link_rx += mvmsta->mpdu_counters[q].per_link[sec_link].rx;
1017 * In EMLSR we have statistics every 5 seconds, so we can reset
1018 * the counters upon every statistics notification.
1019 * The FW sends the notification regularly, but it will be
1020 * misaligned at the start. Skipping the measurement if it is
1021 * short will synchronize us.
1023 if (jiffies - mvmsta->mpdu_counters[q].window_start <
1024 IWL_MVM_TPT_MIN_COUNT_WINDOW)
1026 mvmsta->mpdu_counters[q].window_start = jiffies;
1027 memset(mvmsta->mpdu_counters[q].per_link, 0,
1028 sizeof(mvmsta->mpdu_counters[q].per_link));
1030 spin_unlock_bh(&mvmsta->mpdu_counters[q].lock);
1034 IWL_DEBUG_INFO(mvm, "MPDU statistics window was short\n");
1038 IWL_DEBUG_INFO(mvm, "total Tx MPDUs: %ld. total Rx MPDUs: %ld\n",
1039 total_tx, total_rx);
1041 /* If we don't have enough MPDUs - exit EMLSR */
1042 if (total_tx < IWL_MVM_ENTER_ESR_TPT_THRESH &&
1043 total_rx < IWL_MVM_ENTER_ESR_TPT_THRESH) {
1044 iwl_mvm_block_esr(mvm, bss_vif, IWL_MVM_ESR_BLOCKED_TPT,
1045 iwl_mvm_get_primary_link(bss_vif));
1049 IWL_DEBUG_INFO(mvm, "Secondary Link %d: Tx MPDUs: %ld. Rx MPDUs: %ld\n",
1050 sec_link, sec_link_tx, sec_link_rx);
1052 /* Calculate the percentage of the secondary link TX/RX */
1053 sec_link_tx_perc = total_tx ? sec_link_tx * 100 / total_tx : 0;
1054 sec_link_rx_perc = total_rx ? sec_link_rx * 100 / total_rx : 0;
1057 * The TX/RX percentage is checked only if it exceeds the required
1058 * minimum. In addition, RX is checked only if the TX check failed.
1060 if ((total_tx > SEC_LINK_MIN_TX &&
1061 sec_link_tx_perc < SEC_LINK_MIN_PERC) ||
1062 (total_rx > SEC_LINK_MIN_RX &&
1063 sec_link_rx_perc < SEC_LINK_MIN_PERC))
1064 iwl_mvm_exit_esr(mvm, bss_vif, IWL_MVM_ESR_EXIT_LINK_USAGE,
1065 iwl_mvm_get_primary_link(bss_vif));
1068 void iwl_mvm_handle_rx_system_oper_stats(struct iwl_mvm *mvm,
1069 struct iwl_rx_cmd_buffer *rxb)
1071 u8 average_energy[IWL_STATION_COUNT_MAX];
1072 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1073 struct iwl_system_statistics_notif_oper *stats;
1075 u32 notif_ver = iwl_fw_lookup_notif_ver(mvm->fw, STATISTICS_GROUP,
1076 STATISTICS_OPER_NOTIF, 0);
1078 if (notif_ver != 3) {
1079 IWL_FW_CHECK_FAILED(mvm,
1080 "Oper stats notif ver %d is not supported\n",
1085 stats = (void *)&pkt->data;
1086 iwl_mvm_stat_iterator_all_links(mvm, stats->per_link);
1088 for (i = 0; i < ARRAY_SIZE(average_energy); i++)
1090 le32_to_cpu(stats->per_sta[i].average_energy);
1092 ieee80211_iterate_stations_atomic(mvm->hw, iwl_mvm_stats_energy_iter,
1094 iwl_mvm_handle_per_phy_stats(mvm, stats->per_phy);
1096 iwl_mvm_update_esr_mode_tpt(mvm);
1099 void iwl_mvm_handle_rx_system_oper_part1_stats(struct iwl_mvm *mvm,
1100 struct iwl_rx_cmd_buffer *rxb)
1102 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1103 struct iwl_system_statistics_part1_notif_oper *part1_stats;
1105 u32 notif_ver = iwl_fw_lookup_notif_ver(mvm->fw, STATISTICS_GROUP,
1106 STATISTICS_OPER_PART1_NOTIF, 0);
1108 if (notif_ver != 4) {
1109 IWL_FW_CHECK_FAILED(mvm,
1110 "Part1 stats notif ver %d is not supported\n",
1115 part1_stats = (void *)&pkt->data;
1116 mvm->radio_stats.rx_time = 0;
1117 mvm->radio_stats.tx_time = 0;
1118 for (i = 0; i < ARRAY_SIZE(part1_stats->per_link); i++) {
1119 mvm->radio_stats.rx_time +=
1120 le64_to_cpu(part1_stats->per_link[i].rx_time);
1121 mvm->radio_stats.tx_time +=
1122 le64_to_cpu(part1_stats->per_link[i].tx_time);
1127 iwl_mvm_handle_rx_statistics_tlv(struct iwl_mvm *mvm,
1128 struct iwl_rx_packet *pkt)
1130 u8 average_energy[IWL_STATION_COUNT_MAX];
1131 __le32 air_time[MAC_INDEX_AUX];
1132 __le32 rx_bytes[MAC_INDEX_AUX];
1135 u32 notif_ver = iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,
1136 STATISTICS_NOTIFICATION, 0);
1138 if (WARN_ONCE(notif_ver > 15,
1139 "invalid statistics version id: %d\n", notif_ver))
1142 if (notif_ver == 14) {
1143 struct iwl_statistics_operational_ntfy_ver_14 *stats =
1146 if (!iwl_mvm_verify_stats_len(mvm, pkt, sizeof(*stats)))
1149 iwl_mvm_stats_ver_14(mvm, stats);
1151 flags = stats->flags;
1152 mvm->radio_stats.rx_time = le64_to_cpu(stats->rx_time);
1153 mvm->radio_stats.tx_time = le64_to_cpu(stats->tx_time);
1154 mvm->radio_stats.on_time_rf = le64_to_cpu(stats->on_time_rf);
1155 mvm->radio_stats.on_time_scan =
1156 le64_to_cpu(stats->on_time_scan);
1158 for (i = 0; i < ARRAY_SIZE(average_energy); i++)
1159 average_energy[i] = le32_to_cpu(stats->average_energy[i]);
1161 for (i = 0; i < ARRAY_SIZE(air_time); i++) {
1162 air_time[i] = stats->air_time[i];
1163 rx_bytes[i] = stats->rx_bytes[i];
1167 if (notif_ver == 15) {
1168 struct iwl_statistics_operational_ntfy *stats =
1171 if (!iwl_mvm_verify_stats_len(mvm, pkt, sizeof(*stats)))
1174 iwl_mvm_stats_ver_15(mvm, stats);
1176 flags = stats->flags;
1177 mvm->radio_stats.rx_time = le64_to_cpu(stats->rx_time);
1178 mvm->radio_stats.tx_time = le64_to_cpu(stats->tx_time);
1179 mvm->radio_stats.on_time_rf = le64_to_cpu(stats->on_time_rf);
1180 mvm->radio_stats.on_time_scan =
1181 le64_to_cpu(stats->on_time_scan);
1183 for (i = 0; i < ARRAY_SIZE(average_energy); i++)
1185 le32_to_cpu(stats->per_sta[i].average_energy);
1187 for (i = 0; i < ARRAY_SIZE(air_time); i++) {
1188 air_time[i] = stats->per_mac[i].air_time;
1189 rx_bytes[i] = stats->per_mac[i].rx_bytes;
1193 iwl_mvm_rx_stats_check_trigger(mvm, pkt);
1195 ieee80211_iterate_stations_atomic(mvm->hw, iwl_mvm_stats_energy_iter,
1198 * Don't update in case the statistics are not cleared, since
1199 * we will end up counting twice the same airtime, once in TCM
1200 * request and once in statistics notification.
1202 if (le32_to_cpu(flags) & IWL_STATISTICS_REPLY_FLG_CLEAR)
1203 iwl_mvm_update_tcm_from_stats(mvm, air_time, rx_bytes);
1206 void iwl_mvm_handle_rx_statistics(struct iwl_mvm *mvm,
1207 struct iwl_rx_packet *pkt)
1209 struct iwl_mvm_stat_data data = {
1212 __le32 *bytes, *air_time, flags;
1215 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw,
1216 WIDE_ID(SYSTEM_GROUP,
1217 SYSTEM_STATISTICS_CMD),
1218 IWL_FW_CMD_VER_UNKNOWN);
1220 if (cmd_ver != IWL_FW_CMD_VER_UNKNOWN)
1223 /* From ver 14 and up we use TLV statistics format */
1224 if (iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,
1225 STATISTICS_NOTIFICATION, 0) >= 14)
1226 return iwl_mvm_handle_rx_statistics_tlv(mvm, pkt);
1228 if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
1229 if (iwl_mvm_has_new_rx_api(mvm))
1230 expected_size = sizeof(struct iwl_notif_statistics_v11);
1232 expected_size = sizeof(struct iwl_notif_statistics_v10);
1234 expected_size = sizeof(struct iwl_notif_statistics);
1237 if (WARN_ONCE(iwl_rx_packet_payload_len(pkt) != expected_size,
1238 "received invalid statistics size (%d)!\n",
1239 iwl_rx_packet_payload_len(pkt)))
1242 if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
1243 struct iwl_notif_statistics_v11 *stats = (void *)&pkt->data;
1245 data.mac_id = stats->rx.general.mac_id;
1246 data.beacon_filter_average_energy =
1247 stats->general.common.beacon_filter_average_energy;
1249 mvm->rx_stats_v3 = stats->rx;
1251 mvm->radio_stats.rx_time =
1252 le64_to_cpu(stats->general.common.rx_time);
1253 mvm->radio_stats.tx_time =
1254 le64_to_cpu(stats->general.common.tx_time);
1255 mvm->radio_stats.on_time_rf =
1256 le64_to_cpu(stats->general.common.on_time_rf);
1257 mvm->radio_stats.on_time_scan =
1258 le64_to_cpu(stats->general.common.on_time_scan);
1260 data.beacon_counter = stats->general.beacon_counter;
1261 data.beacon_average_energy =
1262 stats->general.beacon_average_energy;
1263 flags = stats->flag;
1265 struct iwl_notif_statistics *stats = (void *)&pkt->data;
1267 data.mac_id = stats->rx.general.mac_id;
1268 data.beacon_filter_average_energy =
1269 stats->general.common.beacon_filter_average_energy;
1271 mvm->rx_stats = stats->rx;
1273 mvm->radio_stats.rx_time =
1274 le64_to_cpu(stats->general.common.rx_time);
1275 mvm->radio_stats.tx_time =
1276 le64_to_cpu(stats->general.common.tx_time);
1277 mvm->radio_stats.on_time_rf =
1278 le64_to_cpu(stats->general.common.on_time_rf);
1279 mvm->radio_stats.on_time_scan =
1280 le64_to_cpu(stats->general.common.on_time_scan);
1282 data.beacon_counter = stats->general.beacon_counter;
1283 data.beacon_average_energy =
1284 stats->general.beacon_average_energy;
1285 flags = stats->flag;
1289 iwl_mvm_rx_stats_check_trigger(mvm, pkt);
1291 ieee80211_iterate_active_interfaces(mvm->hw,
1292 IEEE80211_IFACE_ITER_NORMAL,
1293 iwl_mvm_stat_iterator,
1296 if (!iwl_mvm_has_new_rx_api(mvm))
1299 if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
1300 struct iwl_notif_statistics_v11 *v11 = (void *)&pkt->data;
1302 energy = (void *)&v11->load_stats.avg_energy;
1303 bytes = (void *)&v11->load_stats.byte_count;
1304 air_time = (void *)&v11->load_stats.air_time;
1306 struct iwl_notif_statistics *stats = (void *)&pkt->data;
1308 energy = (void *)&stats->load_stats.avg_energy;
1309 bytes = (void *)&stats->load_stats.byte_count;
1310 air_time = (void *)&stats->load_stats.air_time;
1312 ieee80211_iterate_stations_atomic(mvm->hw, iwl_mvm_stats_energy_iter,
1316 * Don't update in case the statistics are not cleared, since
1317 * we will end up counting twice the same airtime, once in TCM
1318 * request and once in statistics notification.
1320 if (le32_to_cpu(flags) & IWL_STATISTICS_REPLY_FLG_CLEAR)
1321 iwl_mvm_update_tcm_from_stats(mvm, air_time, bytes);
1325 void iwl_mvm_rx_statistics(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
1327 iwl_mvm_handle_rx_statistics(mvm, rxb_addr(rxb));
1330 void iwl_mvm_window_status_notif(struct iwl_mvm *mvm,
1331 struct iwl_rx_cmd_buffer *rxb)
1333 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1334 struct iwl_ba_window_status_notif *notif = (void *)pkt->data;
1337 BUILD_BUG_ON(ARRAY_SIZE(notif->ra_tid) != BA_WINDOW_STREAMS_MAX);
1338 BUILD_BUG_ON(ARRAY_SIZE(notif->mpdu_rx_count) != BA_WINDOW_STREAMS_MAX);
1339 BUILD_BUG_ON(ARRAY_SIZE(notif->bitmap) != BA_WINDOW_STREAMS_MAX);
1340 BUILD_BUG_ON(ARRAY_SIZE(notif->start_seq_num) != BA_WINDOW_STREAMS_MAX);
1343 for (i = 0; i < BA_WINDOW_STREAMS_MAX; i++) {
1344 struct ieee80211_sta *sta;
1351 ratid = le16_to_cpu(notif->ra_tid[i]);
1352 /* check that this TID is valid */
1353 if (!(ratid & BA_WINDOW_STATUS_VALID_MSK))
1356 received_mpdu = le16_to_cpu(notif->mpdu_rx_count[i]);
1357 if (received_mpdu == 0)
1360 tid = ratid & BA_WINDOW_STATUS_TID_MSK;
1361 /* get the station */
1362 sta_id = (ratid & BA_WINDOW_STATUS_STA_ID_MSK)
1363 >> BA_WINDOW_STATUS_STA_ID_POS;
1364 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1365 if (IS_ERR_OR_NULL(sta))
1367 bitmap = le64_to_cpu(notif->bitmap[i]);
1368 ssn = le32_to_cpu(notif->start_seq_num[i]);
1370 /* update mac80211 with the bitmap for the reordering buffer */
1371 ieee80211_mark_rx_ba_filtered_frames(sta, tid, ssn, bitmap,