Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
0002 /*
0003  * Copyright (C) 2012-2014, 2018-2022 Intel Corporation
0004  * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
0005  * Copyright (C) 2016-2017 Intel Deutschland GmbH
0006  */
0007 #include <asm/unaligned.h>
0008 #include <linux/etherdevice.h>
0009 #include <linux/skbuff.h>
0010 #include "iwl-trans.h"
0011 #include "mvm.h"
0012 #include "fw-api.h"
0013 
0014 /*
0015  * iwl_mvm_rx_rx_phy_cmd - REPLY_RX_PHY_CMD handler
0016  *
0017  * Copies the phy information in mvm->last_phy_info, it will be used when the
0018  * actual data will come from the fw in the next packet.
0019  */
0020 void iwl_mvm_rx_rx_phy_cmd(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
0021 {
0022     struct iwl_rx_packet *pkt = rxb_addr(rxb);
0023     unsigned int pkt_len = iwl_rx_packet_payload_len(pkt);
0024 
0025     if (unlikely(pkt_len < sizeof(mvm->last_phy_info)))
0026         return;
0027 
0028     memcpy(&mvm->last_phy_info, pkt->data, sizeof(mvm->last_phy_info));
0029     mvm->ampdu_ref++;
0030 
0031 #ifdef CONFIG_IWLWIFI_DEBUGFS
0032     if (mvm->last_phy_info.phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_AGG)) {
0033         spin_lock(&mvm->drv_stats_lock);
0034         mvm->drv_rx_stats.ampdu_count++;
0035         spin_unlock(&mvm->drv_stats_lock);
0036     }
0037 #endif
0038 }
0039 
0040 /*
0041  * iwl_mvm_pass_packet_to_mac80211 - builds the packet for mac80211
0042  *
0043  * Adds the rxb to a new skb and give it to mac80211
0044  */
0045 static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm *mvm,
0046                         struct ieee80211_sta *sta,
0047                         struct napi_struct *napi,
0048                         struct sk_buff *skb,
0049                         struct ieee80211_hdr *hdr, u16 len,
0050                         u8 crypt_len,
0051                         struct iwl_rx_cmd_buffer *rxb)
0052 {
0053     unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control);
0054     unsigned int fraglen;
0055 
0056     /*
0057      * The 'hdrlen' (plus the 8 bytes for the SNAP and the crypt_len,
0058      * but those are all multiples of 4 long) all goes away, but we
0059      * want the *end* of it, which is going to be the start of the IP
0060      * header, to be aligned when it gets pulled in.
0061      * The beginning of the skb->data is aligned on at least a 4-byte
0062      * boundary after allocation. Everything here is aligned at least
0063      * on a 2-byte boundary so we can just take hdrlen & 3 and pad by
0064      * the result.
0065      */
0066     skb_reserve(skb, hdrlen & 3);
0067 
0068     /* If frame is small enough to fit in skb->head, pull it completely.
0069      * If not, only pull ieee80211_hdr (including crypto if present, and
0070      * an additional 8 bytes for SNAP/ethertype, see below) so that
0071      * splice() or TCP coalesce are more efficient.
0072      *
0073      * Since, in addition, ieee80211_data_to_8023() always pull in at
0074      * least 8 bytes (possibly more for mesh) we can do the same here
0075      * to save the cost of doing it later. That still doesn't pull in
0076      * the actual IP header since the typical case has a SNAP header.
0077      * If the latter changes (there are efforts in the standards group
0078      * to do so) we should revisit this and ieee80211_data_to_8023().
0079      */
0080     hdrlen = (len <= skb_tailroom(skb)) ? len : hdrlen + crypt_len + 8;
0081 
0082     skb_put_data(skb, hdr, hdrlen);
0083     fraglen = len - hdrlen;
0084 
0085     if (fraglen) {
0086         int offset = (u8 *)hdr + hdrlen -
0087                  (u8 *)rxb_addr(rxb) + rxb_offset(rxb);
0088 
0089         skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset,
0090                 fraglen, rxb->truesize);
0091     }
0092 
0093     ieee80211_rx_napi(mvm->hw, sta, skb, napi);
0094 }
0095 
0096 /*
0097  * iwl_mvm_get_signal_strength - use new rx PHY INFO API
0098  * values are reported by the fw as positive values - need to negate
0099  * to obtain their dBM.  Account for missing antennas by replacing 0
0100  * values by -256dBm: practically 0 power and a non-feasible 8 bit value.
0101  */
0102 static void iwl_mvm_get_signal_strength(struct iwl_mvm *mvm,
0103                     struct iwl_rx_phy_info *phy_info,
0104                     struct ieee80211_rx_status *rx_status)
0105 {
0106     int energy_a, energy_b, max_energy;
0107     u32 val;
0108 
0109     val =
0110         le32_to_cpu(phy_info->non_cfg_phy[IWL_RX_INFO_ENERGY_ANT_ABC_IDX]);
0111     energy_a = (val & IWL_RX_INFO_ENERGY_ANT_A_MSK) >>
0112                         IWL_RX_INFO_ENERGY_ANT_A_POS;
0113     energy_a = energy_a ? -energy_a : S8_MIN;
0114     energy_b = (val & IWL_RX_INFO_ENERGY_ANT_B_MSK) >>
0115                         IWL_RX_INFO_ENERGY_ANT_B_POS;
0116     energy_b = energy_b ? -energy_b : S8_MIN;
0117     max_energy = max(energy_a, energy_b);
0118 
0119     IWL_DEBUG_STATS(mvm, "energy In A %d B %d  , and max %d\n",
0120             energy_a, energy_b, max_energy);
0121 
0122     rx_status->signal = max_energy;
0123     rx_status->chains = (le16_to_cpu(phy_info->phy_flags) &
0124                 RX_RES_PHY_FLAGS_ANTENNA)
0125                     >> RX_RES_PHY_FLAGS_ANTENNA_POS;
0126     rx_status->chain_signal[0] = energy_a;
0127     rx_status->chain_signal[1] = energy_b;
0128 }
0129 
0130 /*
0131  * iwl_mvm_set_mac80211_rx_flag - translate fw status to mac80211 format
0132  * @mvm: the mvm object
0133  * @hdr: 80211 header
0134  * @stats: status in mac80211's format
0135  * @rx_pkt_status: status coming from fw
0136  *
0137  * returns non 0 value if the packet should be dropped
0138  */
0139 static u32 iwl_mvm_set_mac80211_rx_flag(struct iwl_mvm *mvm,
0140                     struct ieee80211_hdr *hdr,
0141                     struct ieee80211_rx_status *stats,
0142                     u32 rx_pkt_status,
0143                     u8 *crypt_len)
0144 {
0145     if (!ieee80211_has_protected(hdr->frame_control) ||
0146         (rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) ==
0147                  RX_MPDU_RES_STATUS_SEC_NO_ENC)
0148         return 0;
0149 
0150     /* packet was encrypted with unknown alg */
0151     if ((rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) ==
0152                     RX_MPDU_RES_STATUS_SEC_ENC_ERR)
0153         return 0;
0154 
0155     switch (rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) {
0156     case RX_MPDU_RES_STATUS_SEC_CCM_ENC:
0157         /* alg is CCM: check MIC only */
0158         if (!(rx_pkt_status & RX_MPDU_RES_STATUS_MIC_OK))
0159             return -1;
0160 
0161         stats->flag |= RX_FLAG_DECRYPTED;
0162         *crypt_len = IEEE80211_CCMP_HDR_LEN;
0163         return 0;
0164 
0165     case RX_MPDU_RES_STATUS_SEC_TKIP_ENC:
0166         /* Don't drop the frame and decrypt it in SW */
0167         if (!fw_has_api(&mvm->fw->ucode_capa,
0168                 IWL_UCODE_TLV_API_DEPRECATE_TTAK) &&
0169             !(rx_pkt_status & RX_MPDU_RES_STATUS_TTAK_OK))
0170             return 0;
0171         *crypt_len = IEEE80211_TKIP_IV_LEN;
0172         fallthrough;
0173 
0174     case RX_MPDU_RES_STATUS_SEC_WEP_ENC:
0175         if (!(rx_pkt_status & RX_MPDU_RES_STATUS_ICV_OK))
0176             return -1;
0177 
0178         stats->flag |= RX_FLAG_DECRYPTED;
0179         if ((rx_pkt_status & RX_MPDU_RES_STATUS_SEC_ENC_MSK) ==
0180                 RX_MPDU_RES_STATUS_SEC_WEP_ENC)
0181             *crypt_len = IEEE80211_WEP_IV_LEN;
0182         return 0;
0183 
0184     case RX_MPDU_RES_STATUS_SEC_EXT_ENC:
0185         if (!(rx_pkt_status & RX_MPDU_RES_STATUS_MIC_OK))
0186             return -1;
0187         stats->flag |= RX_FLAG_DECRYPTED;
0188         return 0;
0189 
0190     default:
0191         /* Expected in monitor (not having the keys) */
0192         if (!mvm->monitor_on)
0193             IWL_ERR(mvm, "Unhandled alg: 0x%x\n", rx_pkt_status);
0194     }
0195 
0196     return 0;
0197 }
0198 
0199 static void iwl_mvm_rx_handle_tcm(struct iwl_mvm *mvm,
0200                   struct ieee80211_sta *sta,
0201                   struct ieee80211_hdr *hdr, u32 len,
0202                   struct iwl_rx_phy_info *phy_info,
0203                   u32 rate_n_flags)
0204 {
0205     struct iwl_mvm_sta *mvmsta;
0206     struct iwl_mvm_tcm_mac *mdata;
0207     int mac;
0208     int ac = IEEE80211_AC_BE; /* treat non-QoS as BE */
0209     struct iwl_mvm_vif *mvmvif;
0210     /* expected throughput in 100Kbps, single stream, 20 MHz */
0211     static const u8 thresh_tpt[] = {
0212         9, 18, 30, 42, 60, 78, 90, 96, 120, 135,
0213     };
0214     u16 thr;
0215 
0216     if (ieee80211_is_data_qos(hdr->frame_control))
0217         ac = tid_to_mac80211_ac[ieee80211_get_tid(hdr)];
0218 
0219     mvmsta = iwl_mvm_sta_from_mac80211(sta);
0220     mac = mvmsta->mac_id_n_color & FW_CTXT_ID_MSK;
0221 
0222     if (time_after(jiffies, mvm->tcm.ts + MVM_TCM_PERIOD))
0223         schedule_delayed_work(&mvm->tcm.work, 0);
0224     mdata = &mvm->tcm.data[mac];
0225     mdata->rx.pkts[ac]++;
0226 
0227     /* count the airtime only once for each ampdu */
0228     if (mdata->rx.last_ampdu_ref != mvm->ampdu_ref) {
0229         mdata->rx.last_ampdu_ref = mvm->ampdu_ref;
0230         mdata->rx.airtime += le16_to_cpu(phy_info->frame_time);
0231     }
0232 
0233     if (!(rate_n_flags & (RATE_MCS_HT_MSK_V1 | RATE_MCS_VHT_MSK_V1)))
0234         return;
0235 
0236     mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
0237 
0238     if (mdata->opened_rx_ba_sessions ||
0239         mdata->uapsd_nonagg_detect.detected ||
0240         (!mvmvif->queue_params[IEEE80211_AC_VO].uapsd &&
0241          !mvmvif->queue_params[IEEE80211_AC_VI].uapsd &&
0242          !mvmvif->queue_params[IEEE80211_AC_BE].uapsd &&
0243          !mvmvif->queue_params[IEEE80211_AC_BK].uapsd) ||
0244         mvmsta->sta_id != mvmvif->ap_sta_id)
0245         return;
0246 
0247     if (rate_n_flags & RATE_MCS_HT_MSK_V1) {
0248         thr = thresh_tpt[rate_n_flags & RATE_HT_MCS_RATE_CODE_MSK_V1];
0249         thr *= 1 + ((rate_n_flags & RATE_HT_MCS_NSS_MSK_V1) >>
0250                     RATE_HT_MCS_NSS_POS_V1);
0251     } else {
0252         if (WARN_ON((rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK) >=
0253                 ARRAY_SIZE(thresh_tpt)))
0254             return;
0255         thr = thresh_tpt[rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK];
0256         thr *= 1 + ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >>
0257                     RATE_VHT_MCS_NSS_POS);
0258     }
0259 
0260     thr <<= ((rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK_V1) >>
0261                 RATE_MCS_CHAN_WIDTH_POS);
0262 
0263     mdata->uapsd_nonagg_detect.rx_bytes += len;
0264     ewma_rate_add(&mdata->uapsd_nonagg_detect.rate, thr);
0265 }
0266 
0267 static void iwl_mvm_rx_csum(struct ieee80211_sta *sta,
0268                 struct sk_buff *skb,
0269                 u32 status)
0270 {
0271     struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
0272     struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
0273 
0274     if (mvmvif->features & NETIF_F_RXCSUM &&
0275         status & RX_MPDU_RES_STATUS_CSUM_DONE &&
0276         status & RX_MPDU_RES_STATUS_CSUM_OK)
0277         skb->ip_summed = CHECKSUM_UNNECESSARY;
0278 }
0279 
0280 /*
0281  * iwl_mvm_rx_rx_mpdu - REPLY_RX_MPDU_CMD handler
0282  *
0283  * Handles the actual data of the Rx packet from the fw
0284  */
0285 void iwl_mvm_rx_rx_mpdu(struct iwl_mvm *mvm, struct napi_struct *napi,
0286             struct iwl_rx_cmd_buffer *rxb)
0287 {
0288     struct ieee80211_hdr *hdr;
0289     struct ieee80211_rx_status *rx_status;
0290     struct iwl_rx_packet *pkt = rxb_addr(rxb);
0291     struct iwl_rx_phy_info *phy_info;
0292     struct iwl_rx_mpdu_res_start *rx_res;
0293     struct ieee80211_sta *sta = NULL;
0294     struct sk_buff *skb;
0295     u32 len, pkt_len = iwl_rx_packet_payload_len(pkt);
0296     u32 rate_n_flags;
0297     u32 rx_pkt_status;
0298     u8 crypt_len = 0;
0299 
0300     if (unlikely(pkt_len < sizeof(*rx_res))) {
0301         IWL_DEBUG_DROP(mvm, "Bad REPLY_RX_MPDU_CMD size\n");
0302         return;
0303     }
0304 
0305     phy_info = &mvm->last_phy_info;
0306     rx_res = (struct iwl_rx_mpdu_res_start *)pkt->data;
0307     hdr = (struct ieee80211_hdr *)(pkt->data + sizeof(*rx_res));
0308     len = le16_to_cpu(rx_res->byte_count);
0309 
0310     if (unlikely(len + sizeof(*rx_res) + sizeof(__le32) > pkt_len)) {
0311         IWL_DEBUG_DROP(mvm, "FW lied about packet len\n");
0312         return;
0313     }
0314 
0315     rx_pkt_status = get_unaligned_le32((__le32 *)
0316         (pkt->data + sizeof(*rx_res) + len));
0317 
0318     /* Dont use dev_alloc_skb(), we'll have enough headroom once
0319      * ieee80211_hdr pulled.
0320      */
0321     skb = alloc_skb(128, GFP_ATOMIC);
0322     if (!skb) {
0323         IWL_ERR(mvm, "alloc_skb failed\n");
0324         return;
0325     }
0326 
0327     rx_status = IEEE80211_SKB_RXCB(skb);
0328 
0329     /*
0330      * Keep packets with CRC errors (and with overrun) for monitor mode
0331      * (otherwise the firmware discards them) but mark them as bad.
0332      */
0333     if (!(rx_pkt_status & RX_MPDU_RES_STATUS_CRC_OK) ||
0334         !(rx_pkt_status & RX_MPDU_RES_STATUS_OVERRUN_OK)) {
0335         IWL_DEBUG_RX(mvm, "Bad CRC or FIFO: 0x%08X.\n", rx_pkt_status);
0336         rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
0337     }
0338 
0339     /* This will be used in several places later */
0340     rate_n_flags = le32_to_cpu(phy_info->rate_n_flags);
0341 
0342     /* rx_status carries information about the packet to mac80211 */
0343     rx_status->mactime = le64_to_cpu(phy_info->timestamp);
0344     rx_status->device_timestamp = le32_to_cpu(phy_info->system_timestamp);
0345     rx_status->band =
0346         (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_BAND_24)) ?
0347                 NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
0348     rx_status->freq =
0349         ieee80211_channel_to_frequency(le16_to_cpu(phy_info->channel),
0350                            rx_status->band);
0351 
0352     /* TSF as indicated by the firmware  is at INA time */
0353     rx_status->flag |= RX_FLAG_MACTIME_PLCP_START;
0354 
0355     iwl_mvm_get_signal_strength(mvm, phy_info, rx_status);
0356 
0357     IWL_DEBUG_STATS_LIMIT(mvm, "Rssi %d, TSF %llu\n", rx_status->signal,
0358                   (unsigned long long)rx_status->mactime);
0359 
0360     rcu_read_lock();
0361     if (rx_pkt_status & RX_MPDU_RES_STATUS_SRC_STA_FOUND) {
0362         u32 id = rx_pkt_status & RX_MPDU_RES_STATUS_STA_ID_MSK;
0363 
0364         id >>= RX_MDPU_RES_STATUS_STA_ID_SHIFT;
0365 
0366         if (!WARN_ON_ONCE(id >= mvm->fw->ucode_capa.num_stations)) {
0367             sta = rcu_dereference(mvm->fw_id_to_mac_id[id]);
0368             if (IS_ERR(sta))
0369                 sta = NULL;
0370         }
0371     } else if (!is_multicast_ether_addr(hdr->addr2)) {
0372         /* This is fine since we prevent two stations with the same
0373          * address from being added.
0374          */
0375         sta = ieee80211_find_sta_by_ifaddr(mvm->hw, hdr->addr2, NULL);
0376     }
0377 
0378     if (sta) {
0379         struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
0380         struct ieee80211_vif *vif = mvmsta->vif;
0381         struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
0382 
0383         /*
0384          * Don't even try to decrypt a MCAST frame that was received
0385          * before the managed vif is authorized, we'd fail anyway.
0386          */
0387         if (vif->type == NL80211_IFTYPE_STATION &&
0388             !mvmvif->authorized &&
0389             is_multicast_ether_addr(hdr->addr1)) {
0390             IWL_DEBUG_DROP(mvm, "MCAST before the vif is authorized\n");
0391             kfree_skb(skb);
0392             rcu_read_unlock();
0393             return;
0394         }
0395     }
0396 
0397     /*
0398      * drop the packet if it has failed being decrypted by HW
0399      */
0400     if (iwl_mvm_set_mac80211_rx_flag(mvm, hdr, rx_status, rx_pkt_status,
0401                      &crypt_len)) {
0402         IWL_DEBUG_DROP(mvm, "Bad decryption results 0x%08x\n",
0403                    rx_pkt_status);
0404         kfree_skb(skb);
0405         rcu_read_unlock();
0406         return;
0407     }
0408 
0409     if (sta) {
0410         struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
0411         struct ieee80211_vif *tx_blocked_vif =
0412             rcu_dereference(mvm->csa_tx_blocked_vif);
0413         struct iwl_fw_dbg_trigger_tlv *trig;
0414         struct ieee80211_vif *vif = mvmsta->vif;
0415 
0416         /* We have tx blocked stations (with CS bit). If we heard
0417          * frames from a blocked station on a new channel we can
0418          * TX to it again.
0419          */
0420         if (unlikely(tx_blocked_vif) && vif == tx_blocked_vif) {
0421             struct iwl_mvm_vif *mvmvif =
0422                 iwl_mvm_vif_from_mac80211(tx_blocked_vif);
0423 
0424             if (mvmvif->csa_target_freq == rx_status->freq)
0425                 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta,
0426                                  false);
0427         }
0428 
0429         rs_update_last_rssi(mvm, mvmsta, rx_status);
0430 
0431         trig = iwl_fw_dbg_trigger_on(&mvm->fwrt,
0432                          ieee80211_vif_to_wdev(vif),
0433                          FW_DBG_TRIGGER_RSSI);
0434 
0435         if (trig && ieee80211_is_beacon(hdr->frame_control)) {
0436             struct iwl_fw_dbg_trigger_low_rssi *rssi_trig;
0437             s32 rssi;
0438 
0439             rssi_trig = (void *)trig->data;
0440             rssi = le32_to_cpu(rssi_trig->rssi);
0441 
0442             if (rx_status->signal < rssi)
0443                 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
0444                             NULL);
0445         }
0446 
0447         if (!mvm->tcm.paused && len >= sizeof(*hdr) &&
0448             !is_multicast_ether_addr(hdr->addr1) &&
0449             ieee80211_is_data(hdr->frame_control))
0450             iwl_mvm_rx_handle_tcm(mvm, sta, hdr, len, phy_info,
0451                           rate_n_flags);
0452 
0453         if (ieee80211_is_data(hdr->frame_control))
0454             iwl_mvm_rx_csum(sta, skb, rx_pkt_status);
0455     }
0456     rcu_read_unlock();
0457 
0458     /* set the preamble flag if appropriate */
0459     if (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_SHORT_PREAMBLE))
0460         rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE;
0461 
0462     if (phy_info->phy_flags & cpu_to_le16(RX_RES_PHY_FLAGS_AGG)) {
0463         /*
0464          * We know which subframes of an A-MPDU belong
0465          * together since we get a single PHY response
0466          * from the firmware for all of them
0467          */
0468         rx_status->flag |= RX_FLAG_AMPDU_DETAILS;
0469         rx_status->ampdu_reference = mvm->ampdu_ref;
0470     }
0471 
0472     /* Set up the HT phy flags */
0473     switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK_V1) {
0474     case RATE_MCS_CHAN_WIDTH_20:
0475         break;
0476     case RATE_MCS_CHAN_WIDTH_40:
0477         rx_status->bw = RATE_INFO_BW_40;
0478         break;
0479     case RATE_MCS_CHAN_WIDTH_80:
0480         rx_status->bw = RATE_INFO_BW_80;
0481         break;
0482     case RATE_MCS_CHAN_WIDTH_160:
0483         rx_status->bw = RATE_INFO_BW_160;
0484         break;
0485     }
0486     if (!(rate_n_flags & RATE_MCS_CCK_MSK_V1) &&
0487         rate_n_flags & RATE_MCS_SGI_MSK_V1)
0488         rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
0489     if (rate_n_flags & RATE_HT_MCS_GF_MSK)
0490         rx_status->enc_flags |= RX_ENC_FLAG_HT_GF;
0491     if (rate_n_flags & RATE_MCS_LDPC_MSK_V1)
0492         rx_status->enc_flags |= RX_ENC_FLAG_LDPC;
0493     if (rate_n_flags & RATE_MCS_HT_MSK_V1) {
0494         u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
0495                 RATE_MCS_STBC_POS;
0496         rx_status->encoding = RX_ENC_HT;
0497         rx_status->rate_idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK_V1;
0498         rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
0499     } else if (rate_n_flags & RATE_MCS_VHT_MSK_V1) {
0500         u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
0501                 RATE_MCS_STBC_POS;
0502         rx_status->nss =
0503             ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >>
0504                         RATE_VHT_MCS_NSS_POS) + 1;
0505         rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK;
0506         rx_status->encoding = RX_ENC_VHT;
0507         rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
0508         if (rate_n_flags & RATE_MCS_BF_MSK)
0509             rx_status->enc_flags |= RX_ENC_FLAG_BF;
0510     } else {
0511         int rate = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags,
0512                                    rx_status->band);
0513 
0514         if (WARN(rate < 0 || rate > 0xFF,
0515              "Invalid rate flags 0x%x, band %d,\n",
0516              rate_n_flags, rx_status->band)) {
0517             kfree_skb(skb);
0518             return;
0519         }
0520         rx_status->rate_idx = rate;
0521     }
0522 
0523 #ifdef CONFIG_IWLWIFI_DEBUGFS
0524     iwl_mvm_update_frame_stats(mvm, rate_n_flags,
0525                    rx_status->flag & RX_FLAG_AMPDU_DETAILS);
0526 #endif
0527 
0528     if (unlikely((ieee80211_is_beacon(hdr->frame_control) ||
0529               ieee80211_is_probe_resp(hdr->frame_control)) &&
0530              mvm->sched_scan_pass_all == SCHED_SCAN_PASS_ALL_ENABLED))
0531         mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_FOUND;
0532 
0533     if (unlikely(ieee80211_is_beacon(hdr->frame_control) ||
0534              ieee80211_is_probe_resp(hdr->frame_control)))
0535         rx_status->boottime_ns = ktime_get_boottime_ns();
0536 
0537     iwl_mvm_pass_packet_to_mac80211(mvm, sta, napi, skb, hdr, len,
0538                     crypt_len, rxb);
0539 }
0540 
0541 struct iwl_mvm_stat_data {
0542     struct iwl_mvm *mvm;
0543     __le32 flags;
0544     __le32 mac_id;
0545     u8 beacon_filter_average_energy;
0546     __le32 *beacon_counter;
0547     u8 *beacon_average_energy;
0548 };
0549 
0550 struct iwl_mvm_stat_data_all_macs {
0551     struct iwl_mvm *mvm;
0552     __le32 flags;
0553     struct iwl_statistics_ntfy_per_mac *per_mac_stats;
0554 };
0555 
0556 static void iwl_mvm_update_vif_sig(struct ieee80211_vif *vif, int sig)
0557 {
0558     struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
0559     struct iwl_mvm *mvm = mvmvif->mvm;
0560     int thold = vif->bss_conf.cqm_rssi_thold;
0561     int hyst = vif->bss_conf.cqm_rssi_hyst;
0562     int last_event;
0563 
0564     if (sig == 0) {
0565         IWL_DEBUG_RX(mvm, "RSSI is 0 - skip signal based decision\n");
0566         return;
0567     }
0568 
0569     mvmvif->bf_data.ave_beacon_signal = sig;
0570 
0571     /* BT Coex */
0572     if (mvmvif->bf_data.bt_coex_min_thold !=
0573         mvmvif->bf_data.bt_coex_max_thold) {
0574         last_event = mvmvif->bf_data.last_bt_coex_event;
0575         if (sig > mvmvif->bf_data.bt_coex_max_thold &&
0576             (last_event <= mvmvif->bf_data.bt_coex_min_thold ||
0577              last_event == 0)) {
0578             mvmvif->bf_data.last_bt_coex_event = sig;
0579             IWL_DEBUG_RX(mvm, "cqm_iterator bt coex high %d\n",
0580                      sig);
0581             iwl_mvm_bt_rssi_event(mvm, vif, RSSI_EVENT_HIGH);
0582         } else if (sig < mvmvif->bf_data.bt_coex_min_thold &&
0583                (last_event >= mvmvif->bf_data.bt_coex_max_thold ||
0584                 last_event == 0)) {
0585             mvmvif->bf_data.last_bt_coex_event = sig;
0586             IWL_DEBUG_RX(mvm, "cqm_iterator bt coex low %d\n",
0587                      sig);
0588             iwl_mvm_bt_rssi_event(mvm, vif, RSSI_EVENT_LOW);
0589         }
0590     }
0591 
0592     if (!(vif->driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI))
0593         return;
0594 
0595     /* CQM Notification */
0596     last_event = mvmvif->bf_data.last_cqm_event;
0597     if (thold && sig < thold && (last_event == 0 ||
0598                      sig < last_event - hyst)) {
0599         mvmvif->bf_data.last_cqm_event = sig;
0600         IWL_DEBUG_RX(mvm, "cqm_iterator cqm low %d\n",
0601                  sig);
0602         ieee80211_cqm_rssi_notify(
0603             vif,
0604             NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
0605             sig,
0606             GFP_KERNEL);
0607     } else if (sig > thold &&
0608            (last_event == 0 || sig > last_event + hyst)) {
0609         mvmvif->bf_data.last_cqm_event = sig;
0610         IWL_DEBUG_RX(mvm, "cqm_iterator cqm high %d\n",
0611                  sig);
0612         ieee80211_cqm_rssi_notify(
0613             vif,
0614             NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
0615             sig,
0616             GFP_KERNEL);
0617     }
0618 }
0619 
0620 static void iwl_mvm_stat_iterator(void *_data, u8 *mac,
0621                   struct ieee80211_vif *vif)
0622 {
0623     struct iwl_mvm_stat_data *data = _data;
0624     int sig = -data->beacon_filter_average_energy;
0625     u16 id = le32_to_cpu(data->mac_id);
0626     struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
0627     u16 vif_id = mvmvif->id;
0628 
0629     /* This doesn't need the MAC ID check since it's not taking the
0630      * data copied into the "data" struct, but rather the data from
0631      * the notification directly.
0632      */
0633     mvmvif->beacon_stats.num_beacons =
0634         le32_to_cpu(data->beacon_counter[vif_id]);
0635     mvmvif->beacon_stats.avg_signal =
0636         -data->beacon_average_energy[vif_id];
0637 
0638     if (mvmvif->id != id)
0639         return;
0640 
0641     if (vif->type != NL80211_IFTYPE_STATION)
0642         return;
0643 
0644     /* make sure that beacon statistics don't go backwards with TCM
0645      * request to clear statistics
0646      */
0647     if (le32_to_cpu(data->flags) & IWL_STATISTICS_REPLY_FLG_CLEAR)
0648         mvmvif->beacon_stats.accu_num_beacons +=
0649             mvmvif->beacon_stats.num_beacons;
0650 
0651     iwl_mvm_update_vif_sig(vif, sig);
0652 }
0653 
0654 static void iwl_mvm_stat_iterator_all_macs(void *_data, u8 *mac,
0655                        struct ieee80211_vif *vif)
0656 {
0657     struct iwl_mvm_stat_data_all_macs *data = _data;
0658     struct iwl_statistics_ntfy_per_mac *mac_stats;
0659     int sig;
0660     struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
0661     u16 vif_id = mvmvif->id;
0662 
0663     if (WARN_ONCE(vif_id >= MAC_INDEX_AUX, "invalid vif id: %d", vif_id))
0664         return;
0665 
0666     if (vif->type != NL80211_IFTYPE_STATION)
0667         return;
0668 
0669     mac_stats = &data->per_mac_stats[vif_id];
0670 
0671     mvmvif->beacon_stats.num_beacons =
0672         le32_to_cpu(mac_stats->beacon_counter);
0673     mvmvif->beacon_stats.avg_signal =
0674         -le32_to_cpu(mac_stats->beacon_average_energy);
0675 
0676     /* make sure that beacon statistics don't go backwards with TCM
0677      * request to clear statistics
0678      */
0679     if (le32_to_cpu(data->flags) & IWL_STATISTICS_REPLY_FLG_CLEAR)
0680         mvmvif->beacon_stats.accu_num_beacons +=
0681             mvmvif->beacon_stats.num_beacons;
0682 
0683     sig = -le32_to_cpu(mac_stats->beacon_filter_average_energy);
0684     iwl_mvm_update_vif_sig(vif, sig);
0685 }
0686 
0687 static inline void
0688 iwl_mvm_rx_stats_check_trigger(struct iwl_mvm *mvm, struct iwl_rx_packet *pkt)
0689 {
0690     struct iwl_fw_dbg_trigger_tlv *trig;
0691     struct iwl_fw_dbg_trigger_stats *trig_stats;
0692     u32 trig_offset, trig_thold;
0693 
0694     trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, NULL, FW_DBG_TRIGGER_STATS);
0695     if (!trig)
0696         return;
0697 
0698     trig_stats = (void *)trig->data;
0699 
0700     trig_offset = le32_to_cpu(trig_stats->stop_offset);
0701     trig_thold = le32_to_cpu(trig_stats->stop_threshold);
0702 
0703     if (WARN_ON_ONCE(trig_offset >= iwl_rx_packet_payload_len(pkt)))
0704         return;
0705 
0706     if (le32_to_cpup((__le32 *) (pkt->data + trig_offset)) < trig_thold)
0707         return;
0708 
0709     iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, NULL);
0710 }
0711 
0712 static void iwl_mvm_stats_energy_iter(void *_data,
0713                       struct ieee80211_sta *sta)
0714 {
0715     struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
0716     u8 *energy = _data;
0717     u32 sta_id = mvmsta->sta_id;
0718 
0719     if (WARN_ONCE(sta_id >= IWL_MVM_STATION_COUNT_MAX, "sta_id %d >= %d",
0720               sta_id, IWL_MVM_STATION_COUNT_MAX))
0721         return;
0722 
0723     if (energy[sta_id])
0724         mvmsta->avg_energy = energy[sta_id];
0725 
0726 }
0727 
0728 static void
0729 iwl_mvm_update_tcm_from_stats(struct iwl_mvm *mvm, __le32 *air_time_le,
0730                   __le32 *rx_bytes_le)
0731 {
0732     int i;
0733 
0734     spin_lock(&mvm->tcm.lock);
0735     for (i = 0; i < NUM_MAC_INDEX_DRIVER; i++) {
0736         struct iwl_mvm_tcm_mac *mdata = &mvm->tcm.data[i];
0737         u32 rx_bytes = le32_to_cpu(rx_bytes_le[i]);
0738         u32 airtime = le32_to_cpu(air_time_le[i]);
0739 
0740         mdata->rx.airtime += airtime;
0741         mdata->uapsd_nonagg_detect.rx_bytes += rx_bytes;
0742         if (airtime) {
0743             /* re-init every time to store rate from FW */
0744             ewma_rate_init(&mdata->uapsd_nonagg_detect.rate);
0745             ewma_rate_add(&mdata->uapsd_nonagg_detect.rate,
0746                       rx_bytes * 8 / airtime);
0747         }
0748     }
0749     spin_unlock(&mvm->tcm.lock);
0750 }
0751 
0752 static void
0753 iwl_mvm_stats_ver_15(struct iwl_mvm *mvm,
0754              struct iwl_statistics_operational_ntfy *stats)
0755 {
0756     struct iwl_mvm_stat_data_all_macs data = {
0757         .mvm = mvm,
0758         .flags = stats->flags,
0759         .per_mac_stats = stats->per_mac_stats,
0760     };
0761 
0762     ieee80211_iterate_active_interfaces(mvm->hw,
0763                         IEEE80211_IFACE_ITER_NORMAL,
0764                         iwl_mvm_stat_iterator_all_macs,
0765                         &data);
0766 }
0767 
0768 static void
0769 iwl_mvm_stats_ver_14(struct iwl_mvm *mvm,
0770              struct iwl_statistics_operational_ntfy_ver_14 *stats)
0771 {
0772     struct iwl_mvm_stat_data data = {
0773         .mvm = mvm,
0774     };
0775 
0776     u8 beacon_average_energy[MAC_INDEX_AUX];
0777     __le32 flags;
0778     int i;
0779 
0780     flags = stats->flags;
0781 
0782     data.mac_id = stats->mac_id;
0783     data.beacon_filter_average_energy =
0784         le32_to_cpu(stats->beacon_filter_average_energy);
0785     data.flags = flags;
0786     data.beacon_counter = stats->beacon_counter;
0787 
0788     for (i = 0; i < ARRAY_SIZE(beacon_average_energy); i++)
0789         beacon_average_energy[i] =
0790             le32_to_cpu(stats->beacon_average_energy[i]);
0791 
0792     data.beacon_average_energy = beacon_average_energy;
0793 
0794     ieee80211_iterate_active_interfaces(mvm->hw,
0795                         IEEE80211_IFACE_ITER_NORMAL,
0796                         iwl_mvm_stat_iterator,
0797                         &data);
0798 }
0799 
0800 static bool iwl_mvm_verify_stats_len(struct iwl_mvm *mvm,
0801                      struct iwl_rx_packet *pkt,
0802                      u32 expected_size)
0803 {
0804     struct iwl_statistics_ntfy_hdr *hdr;
0805 
0806     if (WARN_ONCE(iwl_rx_packet_payload_len(pkt) < expected_size,
0807               "received invalid statistics size (%d)!, expected_size: %d\n",
0808               iwl_rx_packet_payload_len(pkt), expected_size))
0809         return false;
0810 
0811     hdr = (void *)&pkt->data;
0812 
0813     if (WARN_ONCE((hdr->type & IWL_STATISTICS_TYPE_MSK) != FW_STATISTICS_OPERATIONAL ||
0814               hdr->version !=
0815               iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP, STATISTICS_NOTIFICATION, 0),
0816               "received unsupported hdr type %d, version %d\n",
0817               hdr->type, hdr->version))
0818         return false;
0819 
0820     if (WARN_ONCE(le16_to_cpu(hdr->size) != expected_size,
0821               "received invalid statistics size in header (%d)!, expected_size: %d\n",
0822               le16_to_cpu(hdr->size), expected_size))
0823         return false;
0824 
0825     return true;
0826 }
0827 
0828 static void
0829 iwl_mvm_handle_rx_statistics_tlv(struct iwl_mvm *mvm,
0830                  struct iwl_rx_packet *pkt)
0831 {
0832     u8 average_energy[IWL_MVM_STATION_COUNT_MAX];
0833     __le32 air_time[MAC_INDEX_AUX];
0834     __le32 rx_bytes[MAC_INDEX_AUX];
0835     __le32 flags = 0;
0836     int i;
0837     u32 notif_ver = iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,
0838                           STATISTICS_NOTIFICATION, 0);
0839 
0840     if (WARN_ONCE(notif_ver > 15,
0841               "invalid statistics version id: %d\n", notif_ver))
0842         return;
0843 
0844     if (notif_ver == 14) {
0845         struct iwl_statistics_operational_ntfy_ver_14 *stats =
0846             (void *)pkt->data;
0847 
0848         if (!iwl_mvm_verify_stats_len(mvm, pkt, sizeof(*stats)))
0849             return;
0850 
0851         iwl_mvm_stats_ver_14(mvm, stats);
0852 
0853         flags = stats->flags;
0854         mvm->radio_stats.rx_time = le64_to_cpu(stats->rx_time);
0855         mvm->radio_stats.tx_time = le64_to_cpu(stats->tx_time);
0856         mvm->radio_stats.on_time_rf = le64_to_cpu(stats->on_time_rf);
0857         mvm->radio_stats.on_time_scan =
0858             le64_to_cpu(stats->on_time_scan);
0859 
0860         for (i = 0; i < ARRAY_SIZE(average_energy); i++)
0861             average_energy[i] = le32_to_cpu(stats->average_energy[i]);
0862 
0863         for (i = 0; i < ARRAY_SIZE(air_time); i++) {
0864             air_time[i] = stats->air_time[i];
0865             rx_bytes[i] = stats->rx_bytes[i];
0866         }
0867     }
0868 
0869     if (notif_ver == 15) {
0870         struct iwl_statistics_operational_ntfy *stats =
0871             (void *)pkt->data;
0872 
0873         if (!iwl_mvm_verify_stats_len(mvm, pkt, sizeof(*stats)))
0874             return;
0875 
0876         iwl_mvm_stats_ver_15(mvm, stats);
0877 
0878         flags = stats->flags;
0879         mvm->radio_stats.rx_time = le64_to_cpu(stats->rx_time);
0880         mvm->radio_stats.tx_time = le64_to_cpu(stats->tx_time);
0881         mvm->radio_stats.on_time_rf = le64_to_cpu(stats->on_time_rf);
0882         mvm->radio_stats.on_time_scan =
0883             le64_to_cpu(stats->on_time_scan);
0884 
0885         for (i = 0; i < ARRAY_SIZE(average_energy); i++)
0886             average_energy[i] =
0887                 le32_to_cpu(stats->per_sta_stats[i].average_energy);
0888 
0889         for (i = 0; i < ARRAY_SIZE(air_time); i++) {
0890             air_time[i] = stats->per_mac_stats[i].air_time;
0891             rx_bytes[i] = stats->per_mac_stats[i].rx_bytes;
0892         }
0893     }
0894 
0895     iwl_mvm_rx_stats_check_trigger(mvm, pkt);
0896 
0897     ieee80211_iterate_stations_atomic(mvm->hw, iwl_mvm_stats_energy_iter,
0898                       average_energy);
0899     /*
0900      * Don't update in case the statistics are not cleared, since
0901      * we will end up counting twice the same airtime, once in TCM
0902      * request and once in statistics notification.
0903      */
0904     if (le32_to_cpu(flags) & IWL_STATISTICS_REPLY_FLG_CLEAR)
0905         iwl_mvm_update_tcm_from_stats(mvm, air_time, rx_bytes);
0906 }
0907 
0908 void iwl_mvm_handle_rx_statistics(struct iwl_mvm *mvm,
0909                   struct iwl_rx_packet *pkt)
0910 {
0911     struct iwl_mvm_stat_data data = {
0912         .mvm = mvm,
0913     };
0914     __le32 *bytes, *air_time, flags;
0915     int expected_size;
0916     u8 *energy;
0917 
0918     /* From ver 14 and up we use TLV statistics format */
0919     if (iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,
0920                     STATISTICS_NOTIFICATION, 0) >= 14)
0921         return iwl_mvm_handle_rx_statistics_tlv(mvm, pkt);
0922 
0923     if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
0924         if (iwl_mvm_has_new_rx_api(mvm))
0925             expected_size = sizeof(struct iwl_notif_statistics_v11);
0926         else
0927             expected_size = sizeof(struct iwl_notif_statistics_v10);
0928     } else {
0929         expected_size = sizeof(struct iwl_notif_statistics);
0930     }
0931 
0932     if (WARN_ONCE(iwl_rx_packet_payload_len(pkt) != expected_size,
0933               "received invalid statistics size (%d)!\n",
0934               iwl_rx_packet_payload_len(pkt)))
0935         return;
0936 
0937     if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
0938         struct iwl_notif_statistics_v11 *stats = (void *)&pkt->data;
0939 
0940         data.mac_id = stats->rx.general.mac_id;
0941         data.beacon_filter_average_energy =
0942             stats->general.common.beacon_filter_average_energy;
0943 
0944         mvm->rx_stats_v3 = stats->rx;
0945 
0946         mvm->radio_stats.rx_time =
0947             le64_to_cpu(stats->general.common.rx_time);
0948         mvm->radio_stats.tx_time =
0949             le64_to_cpu(stats->general.common.tx_time);
0950         mvm->radio_stats.on_time_rf =
0951             le64_to_cpu(stats->general.common.on_time_rf);
0952         mvm->radio_stats.on_time_scan =
0953             le64_to_cpu(stats->general.common.on_time_scan);
0954 
0955         data.beacon_counter = stats->general.beacon_counter;
0956         data.beacon_average_energy =
0957             stats->general.beacon_average_energy;
0958         flags = stats->flag;
0959     } else {
0960         struct iwl_notif_statistics *stats = (void *)&pkt->data;
0961 
0962         data.mac_id = stats->rx.general.mac_id;
0963         data.beacon_filter_average_energy =
0964             stats->general.common.beacon_filter_average_energy;
0965 
0966         mvm->rx_stats = stats->rx;
0967 
0968         mvm->radio_stats.rx_time =
0969             le64_to_cpu(stats->general.common.rx_time);
0970         mvm->radio_stats.tx_time =
0971             le64_to_cpu(stats->general.common.tx_time);
0972         mvm->radio_stats.on_time_rf =
0973             le64_to_cpu(stats->general.common.on_time_rf);
0974         mvm->radio_stats.on_time_scan =
0975             le64_to_cpu(stats->general.common.on_time_scan);
0976 
0977         data.beacon_counter = stats->general.beacon_counter;
0978         data.beacon_average_energy =
0979             stats->general.beacon_average_energy;
0980         flags = stats->flag;
0981     }
0982     data.flags = flags;
0983 
0984     iwl_mvm_rx_stats_check_trigger(mvm, pkt);
0985 
0986     ieee80211_iterate_active_interfaces(mvm->hw,
0987                         IEEE80211_IFACE_ITER_NORMAL,
0988                         iwl_mvm_stat_iterator,
0989                         &data);
0990 
0991     if (!iwl_mvm_has_new_rx_api(mvm))
0992         return;
0993 
0994     if (!iwl_mvm_has_new_rx_stats_api(mvm)) {
0995         struct iwl_notif_statistics_v11 *v11 = (void *)&pkt->data;
0996 
0997         energy = (void *)&v11->load_stats.avg_energy;
0998         bytes = (void *)&v11->load_stats.byte_count;
0999         air_time = (void *)&v11->load_stats.air_time;
1000     } else {
1001         struct iwl_notif_statistics *stats = (void *)&pkt->data;
1002 
1003         energy = (void *)&stats->load_stats.avg_energy;
1004         bytes = (void *)&stats->load_stats.byte_count;
1005         air_time = (void *)&stats->load_stats.air_time;
1006     }
1007     ieee80211_iterate_stations_atomic(mvm->hw, iwl_mvm_stats_energy_iter,
1008                       energy);
1009 
1010     /*
1011      * Don't update in case the statistics are not cleared, since
1012      * we will end up counting twice the same airtime, once in TCM
1013      * request and once in statistics notification.
1014      */
1015     if (le32_to_cpu(flags) & IWL_STATISTICS_REPLY_FLG_CLEAR)
1016         iwl_mvm_update_tcm_from_stats(mvm, air_time, bytes);
1017 
1018 }
1019 
1020 void iwl_mvm_rx_statistics(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb)
1021 {
1022     iwl_mvm_handle_rx_statistics(mvm, rxb_addr(rxb));
1023 }
1024 
1025 void iwl_mvm_window_status_notif(struct iwl_mvm *mvm,
1026                  struct iwl_rx_cmd_buffer *rxb)
1027 {
1028     struct iwl_rx_packet *pkt = rxb_addr(rxb);
1029     struct iwl_ba_window_status_notif *notif = (void *)pkt->data;
1030     int i;
1031 
1032     BUILD_BUG_ON(ARRAY_SIZE(notif->ra_tid) != BA_WINDOW_STREAMS_MAX);
1033     BUILD_BUG_ON(ARRAY_SIZE(notif->mpdu_rx_count) != BA_WINDOW_STREAMS_MAX);
1034     BUILD_BUG_ON(ARRAY_SIZE(notif->bitmap) != BA_WINDOW_STREAMS_MAX);
1035     BUILD_BUG_ON(ARRAY_SIZE(notif->start_seq_num) != BA_WINDOW_STREAMS_MAX);
1036 
1037     rcu_read_lock();
1038     for (i = 0; i < BA_WINDOW_STREAMS_MAX; i++) {
1039         struct ieee80211_sta *sta;
1040         u8 sta_id, tid;
1041         u64 bitmap;
1042         u32 ssn;
1043         u16 ratid;
1044         u16 received_mpdu;
1045 
1046         ratid = le16_to_cpu(notif->ra_tid[i]);
1047         /* check that this TID is valid */
1048         if (!(ratid & BA_WINDOW_STATUS_VALID_MSK))
1049             continue;
1050 
1051         received_mpdu = le16_to_cpu(notif->mpdu_rx_count[i]);
1052         if (received_mpdu == 0)
1053             continue;
1054 
1055         tid = ratid & BA_WINDOW_STATUS_TID_MSK;
1056         /* get the station */
1057         sta_id = (ratid & BA_WINDOW_STATUS_STA_ID_MSK)
1058              >> BA_WINDOW_STATUS_STA_ID_POS;
1059         sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1060         if (IS_ERR_OR_NULL(sta))
1061             continue;
1062         bitmap = le64_to_cpu(notif->bitmap[i]);
1063         ssn = le32_to_cpu(notif->start_seq_num[i]);
1064 
1065         /* update mac80211 with the bitmap for the reordering buffer */
1066         ieee80211_mark_rx_ba_filtered_frames(sta, tid, ssn, bitmap,
1067                              received_mpdu);
1068     }
1069     rcu_read_unlock();
1070 }