1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 /* 3 * Copyright (C) 2012-2014, 2018-2023 Intel Corporation 4 * Copyright (C) 2013-2015 Intel Mobile Communications GmbH 5 * Copyright (C) 2015-2017 Intel Deutschland GmbH 6 */ 7 #include <linux/etherdevice.h> 8 #include <linux/skbuff.h> 9 #include "iwl-trans.h" 10 #include "mvm.h" 11 #include "fw-api.h" 12 #include "time-sync.h" 13 14 static inline int iwl_mvm_check_pn(struct iwl_mvm *mvm, struct sk_buff *skb, 15 int queue, struct ieee80211_sta *sta) 16 { 17 struct iwl_mvm_sta *mvmsta; 18 struct ieee80211_hdr *hdr = (void *)skb_mac_header(skb); 19 struct ieee80211_rx_status *stats = IEEE80211_SKB_RXCB(skb); 20 struct iwl_mvm_key_pn *ptk_pn; 21 int res; 22 u8 tid, keyidx; 23 u8 pn[IEEE80211_CCMP_PN_LEN]; 24 u8 *extiv; 25 26 /* do PN checking */ 27 28 /* multicast and non-data only arrives on default queue */ 29 if (!ieee80211_is_data(hdr->frame_control) || 30 is_multicast_ether_addr(hdr->addr1)) 31 return 0; 32 33 /* do not check PN for open AP */ 34 if (!(stats->flag & RX_FLAG_DECRYPTED)) 35 return 0; 36 37 /* 38 * avoid checking for default queue - we don't want to replicate 39 * all the logic that's necessary for checking the PN on fragmented 40 * frames, leave that to mac80211 41 */ 42 if (queue == 0) 43 return 0; 44 45 /* if we are here - this for sure is either CCMP or GCMP */ 46 if (IS_ERR_OR_NULL(sta)) { 47 IWL_DEBUG_DROP(mvm, 48 "expected hw-decrypted unicast frame for station\n"); 49 return -1; 50 } 51 52 mvmsta = iwl_mvm_sta_from_mac80211(sta); 53 54 extiv = (u8 *)hdr + ieee80211_hdrlen(hdr->frame_control); 55 keyidx = extiv[3] >> 6; 56 57 ptk_pn = rcu_dereference(mvmsta->ptk_pn[keyidx]); 58 if (!ptk_pn) 59 return -1; 60 61 if (ieee80211_is_data_qos(hdr->frame_control)) 62 tid = ieee80211_get_tid(hdr); 63 else 64 tid = 0; 65 66 /* we don't use HCCA/802.11 QoS TSPECs, so drop such frames */ 67 if (tid >= IWL_MAX_TID_COUNT) 68 return -1; 69 70 /* load pn */ 71 pn[0] = extiv[7]; 72 pn[1] = extiv[6]; 73 pn[2] = extiv[5]; 74 pn[3] = extiv[4]; 75 pn[4] = extiv[1]; 76 pn[5] = extiv[0]; 77 78 res = memcmp(pn, ptk_pn->q[queue].pn[tid], IEEE80211_CCMP_PN_LEN); 79 if (res < 0) 80 return -1; 81 if (!res && !(stats->flag & RX_FLAG_ALLOW_SAME_PN)) 82 return -1; 83 84 memcpy(ptk_pn->q[queue].pn[tid], pn, IEEE80211_CCMP_PN_LEN); 85 stats->flag |= RX_FLAG_PN_VALIDATED; 86 87 return 0; 88 } 89 90 /* iwl_mvm_create_skb Adds the rxb to a new skb */ 91 static int iwl_mvm_create_skb(struct iwl_mvm *mvm, struct sk_buff *skb, 92 struct ieee80211_hdr *hdr, u16 len, u8 crypt_len, 93 struct iwl_rx_cmd_buffer *rxb) 94 { 95 struct iwl_rx_packet *pkt = rxb_addr(rxb); 96 struct iwl_rx_mpdu_desc *desc = (void *)pkt->data; 97 unsigned int headlen, fraglen, pad_len = 0; 98 unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control); 99 u8 mic_crc_len = u8_get_bits(desc->mac_flags1, 100 IWL_RX_MPDU_MFLG1_MIC_CRC_LEN_MASK) << 1; 101 102 if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) { 103 len -= 2; 104 pad_len = 2; 105 } 106 107 /* 108 * For non monitor interface strip the bytes the RADA might not have 109 * removed (it might be disabled, e.g. for mgmt frames). As a monitor 110 * interface cannot exist with other interfaces, this removal is safe 111 * and sufficient, in monitor mode there's no decryption being done. 112 */ 113 if (len > mic_crc_len && !ieee80211_hw_check(mvm->hw, RX_INCLUDES_FCS)) 114 len -= mic_crc_len; 115 116 /* If frame is small enough to fit in skb->head, pull it completely. 117 * If not, only pull ieee80211_hdr (including crypto if present, and 118 * an additional 8 bytes for SNAP/ethertype, see below) so that 119 * splice() or TCP coalesce are more efficient. 120 * 121 * Since, in addition, ieee80211_data_to_8023() always pull in at 122 * least 8 bytes (possibly more for mesh) we can do the same here 123 * to save the cost of doing it later. That still doesn't pull in 124 * the actual IP header since the typical case has a SNAP header. 125 * If the latter changes (there are efforts in the standards group 126 * to do so) we should revisit this and ieee80211_data_to_8023(). 127 */ 128 headlen = (len <= skb_tailroom(skb)) ? len : 129 hdrlen + crypt_len + 8; 130 131 /* The firmware may align the packet to DWORD. 132 * The padding is inserted after the IV. 133 * After copying the header + IV skip the padding if 134 * present before copying packet data. 135 */ 136 hdrlen += crypt_len; 137 138 if (unlikely(headlen < hdrlen)) 139 return -EINVAL; 140 141 /* Since data doesn't move data while putting data on skb and that is 142 * the only way we use, data + len is the next place that hdr would be put 143 */ 144 skb_set_mac_header(skb, skb->len); 145 skb_put_data(skb, hdr, hdrlen); 146 skb_put_data(skb, (u8 *)hdr + hdrlen + pad_len, headlen - hdrlen); 147 148 /* 149 * If we did CHECKSUM_COMPLETE, the hardware only does it right for 150 * certain cases and starts the checksum after the SNAP. Check if 151 * this is the case - it's easier to just bail out to CHECKSUM_NONE 152 * in the cases the hardware didn't handle, since it's rare to see 153 * such packets, even though the hardware did calculate the checksum 154 * in this case, just starting after the MAC header instead. 155 * 156 * Starting from Bz hardware, it calculates starting directly after 157 * the MAC header, so that matches mac80211's expectation. 158 */ 159 if (skb->ip_summed == CHECKSUM_COMPLETE) { 160 struct { 161 u8 hdr[6]; 162 __be16 type; 163 } __packed *shdr = (void *)((u8 *)hdr + hdrlen + pad_len); 164 165 if (unlikely(headlen - hdrlen < sizeof(*shdr) || 166 !ether_addr_equal(shdr->hdr, rfc1042_header) || 167 (shdr->type != htons(ETH_P_IP) && 168 shdr->type != htons(ETH_P_ARP) && 169 shdr->type != htons(ETH_P_IPV6) && 170 shdr->type != htons(ETH_P_8021Q) && 171 shdr->type != htons(ETH_P_PAE) && 172 shdr->type != htons(ETH_P_TDLS)))) 173 skb->ip_summed = CHECKSUM_NONE; 174 else if (mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_BZ) 175 /* mac80211 assumes full CSUM including SNAP header */ 176 skb_postpush_rcsum(skb, shdr, sizeof(*shdr)); 177 } 178 179 fraglen = len - headlen; 180 181 if (fraglen) { 182 int offset = (u8 *)hdr + headlen + pad_len - 183 (u8 *)rxb_addr(rxb) + rxb_offset(rxb); 184 185 skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset, 186 fraglen, rxb->truesize); 187 } 188 189 return 0; 190 } 191 192 /* put a TLV on the skb and return data pointer 193 * 194 * Also pad to 4 the len and zero out all data part 195 */ 196 static void * 197 iwl_mvm_radiotap_put_tlv(struct sk_buff *skb, u16 type, u16 len) 198 { 199 struct ieee80211_radiotap_tlv *tlv; 200 201 tlv = skb_put(skb, sizeof(*tlv)); 202 tlv->type = cpu_to_le16(type); 203 tlv->len = cpu_to_le16(len); 204 return skb_put_zero(skb, ALIGN(len, 4)); 205 } 206 207 static void iwl_mvm_add_rtap_sniffer_config(struct iwl_mvm *mvm, 208 struct sk_buff *skb) 209 { 210 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 211 struct ieee80211_radiotap_vendor_content *radiotap; 212 const u16 vendor_data_len = sizeof(mvm->cur_aid); 213 214 if (!mvm->cur_aid) 215 return; 216 217 radiotap = iwl_mvm_radiotap_put_tlv(skb, 218 IEEE80211_RADIOTAP_VENDOR_NAMESPACE, 219 sizeof(*radiotap) + vendor_data_len); 220 221 /* Intel OUI */ 222 radiotap->oui[0] = 0xf6; 223 radiotap->oui[1] = 0x54; 224 radiotap->oui[2] = 0x25; 225 /* radiotap sniffer config sub-namespace */ 226 radiotap->oui_subtype = 1; 227 radiotap->vendor_type = 0; 228 229 /* fill the data now */ 230 memcpy(radiotap->data, &mvm->cur_aid, sizeof(mvm->cur_aid)); 231 232 rx_status->flag |= RX_FLAG_RADIOTAP_TLV_AT_END; 233 } 234 235 /* iwl_mvm_pass_packet_to_mac80211 - passes the packet for mac80211 */ 236 static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm *mvm, 237 struct napi_struct *napi, 238 struct sk_buff *skb, int queue, 239 struct ieee80211_sta *sta, 240 struct ieee80211_link_sta *link_sta) 241 { 242 if (unlikely(iwl_mvm_check_pn(mvm, skb, queue, sta))) { 243 kfree_skb(skb); 244 return; 245 } 246 247 if (sta && sta->valid_links && link_sta) { 248 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 249 250 rx_status->link_valid = 1; 251 rx_status->link_id = link_sta->link_id; 252 } 253 254 ieee80211_rx_napi(mvm->hw, sta, skb, napi); 255 } 256 257 static void iwl_mvm_get_signal_strength(struct iwl_mvm *mvm, 258 struct ieee80211_rx_status *rx_status, 259 u32 rate_n_flags, int energy_a, 260 int energy_b) 261 { 262 int max_energy; 263 u32 rate_flags = rate_n_flags; 264 265 energy_a = energy_a ? -energy_a : S8_MIN; 266 energy_b = energy_b ? -energy_b : S8_MIN; 267 max_energy = max(energy_a, energy_b); 268 269 IWL_DEBUG_STATS(mvm, "energy In A %d B %d, and max %d\n", 270 energy_a, energy_b, max_energy); 271 272 rx_status->signal = max_energy; 273 rx_status->chains = 274 (rate_flags & RATE_MCS_ANT_AB_MSK) >> RATE_MCS_ANT_POS; 275 rx_status->chain_signal[0] = energy_a; 276 rx_status->chain_signal[1] = energy_b; 277 } 278 279 static int iwl_mvm_rx_mgmt_prot(struct ieee80211_sta *sta, 280 struct ieee80211_hdr *hdr, 281 struct iwl_rx_mpdu_desc *desc, 282 u32 status, 283 struct ieee80211_rx_status *stats) 284 { 285 struct wireless_dev *wdev; 286 struct iwl_mvm_sta *mvmsta; 287 struct iwl_mvm_vif *mvmvif; 288 u8 keyid; 289 struct ieee80211_key_conf *key; 290 u32 len = le16_to_cpu(desc->mpdu_len); 291 const u8 *frame = (void *)hdr; 292 293 if ((status & IWL_RX_MPDU_STATUS_SEC_MASK) == IWL_RX_MPDU_STATUS_SEC_NONE) 294 return 0; 295 296 /* 297 * For non-beacon, we don't really care. But beacons may 298 * be filtered out, and we thus need the firmware's replay 299 * detection, otherwise beacons the firmware previously 300 * filtered could be replayed, or something like that, and 301 * it can filter a lot - though usually only if nothing has 302 * changed. 303 */ 304 if (!ieee80211_is_beacon(hdr->frame_control)) 305 return 0; 306 307 if (!sta) 308 return -1; 309 310 mvmsta = iwl_mvm_sta_from_mac80211(sta); 311 mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif); 312 313 /* key mismatch - will also report !MIC_OK but we shouldn't count it */ 314 if (!(status & IWL_RX_MPDU_STATUS_KEY_VALID)) 315 goto report; 316 317 /* good cases */ 318 if (likely(status & IWL_RX_MPDU_STATUS_MIC_OK && 319 !(status & IWL_RX_MPDU_STATUS_REPLAY_ERROR))) { 320 stats->flag |= RX_FLAG_DECRYPTED; 321 return 0; 322 } 323 324 /* 325 * both keys will have the same cipher and MIC length, use 326 * whichever one is available 327 */ 328 key = rcu_dereference(mvmvif->bcn_prot.keys[0]); 329 if (!key) { 330 key = rcu_dereference(mvmvif->bcn_prot.keys[1]); 331 if (!key) 332 goto report; 333 } 334 335 if (len < key->icv_len + IEEE80211_GMAC_PN_LEN + 2) 336 goto report; 337 338 /* get the real key ID */ 339 keyid = frame[len - key->icv_len - IEEE80211_GMAC_PN_LEN - 2]; 340 /* and if that's the other key, look it up */ 341 if (keyid != key->keyidx) { 342 /* 343 * shouldn't happen since firmware checked, but be safe 344 * in case the MIC length is wrong too, for example 345 */ 346 if (keyid != 6 && keyid != 7) 347 return -1; 348 key = rcu_dereference(mvmvif->bcn_prot.keys[keyid - 6]); 349 if (!key) 350 goto report; 351 } 352 353 /* Report status to mac80211 */ 354 if (!(status & IWL_RX_MPDU_STATUS_MIC_OK)) 355 ieee80211_key_mic_failure(key); 356 else if (status & IWL_RX_MPDU_STATUS_REPLAY_ERROR) 357 ieee80211_key_replay(key); 358 report: 359 wdev = ieee80211_vif_to_wdev(mvmsta->vif); 360 if (wdev->netdev) 361 cfg80211_rx_unprot_mlme_mgmt(wdev->netdev, (void *)hdr, len); 362 363 return -1; 364 } 365 366 static int iwl_mvm_rx_crypto(struct iwl_mvm *mvm, struct ieee80211_sta *sta, 367 struct ieee80211_hdr *hdr, 368 struct ieee80211_rx_status *stats, u16 phy_info, 369 struct iwl_rx_mpdu_desc *desc, 370 u32 pkt_flags, int queue, u8 *crypt_len) 371 { 372 u32 status = le32_to_cpu(desc->status); 373 374 /* 375 * Drop UNKNOWN frames in aggregation, unless in monitor mode 376 * (where we don't have the keys). 377 * We limit this to aggregation because in TKIP this is a valid 378 * scenario, since we may not have the (correct) TTAK (phase 1 379 * key) in the firmware. 380 */ 381 if (phy_info & IWL_RX_MPDU_PHY_AMPDU && 382 (status & IWL_RX_MPDU_STATUS_SEC_MASK) == 383 IWL_RX_MPDU_STATUS_SEC_UNKNOWN && !mvm->monitor_on) 384 return -1; 385 386 if (unlikely(ieee80211_is_mgmt(hdr->frame_control) && 387 !ieee80211_has_protected(hdr->frame_control))) 388 return iwl_mvm_rx_mgmt_prot(sta, hdr, desc, status, stats); 389 390 if (!ieee80211_has_protected(hdr->frame_control) || 391 (status & IWL_RX_MPDU_STATUS_SEC_MASK) == 392 IWL_RX_MPDU_STATUS_SEC_NONE) 393 return 0; 394 395 /* TODO: handle packets encrypted with unknown alg */ 396 397 switch (status & IWL_RX_MPDU_STATUS_SEC_MASK) { 398 case IWL_RX_MPDU_STATUS_SEC_CCM: 399 case IWL_RX_MPDU_STATUS_SEC_GCM: 400 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN != IEEE80211_GCMP_PN_LEN); 401 /* alg is CCM: check MIC only */ 402 if (!(status & IWL_RX_MPDU_STATUS_MIC_OK)) 403 return -1; 404 405 stats->flag |= RX_FLAG_DECRYPTED | RX_FLAG_MIC_STRIPPED; 406 *crypt_len = IEEE80211_CCMP_HDR_LEN; 407 return 0; 408 case IWL_RX_MPDU_STATUS_SEC_TKIP: 409 /* Don't drop the frame and decrypt it in SW */ 410 if (!fw_has_api(&mvm->fw->ucode_capa, 411 IWL_UCODE_TLV_API_DEPRECATE_TTAK) && 412 !(status & IWL_RX_MPDU_RES_STATUS_TTAK_OK)) 413 return 0; 414 415 if (mvm->trans->trans_cfg->gen2 && 416 !(status & RX_MPDU_RES_STATUS_MIC_OK)) 417 stats->flag |= RX_FLAG_MMIC_ERROR; 418 419 *crypt_len = IEEE80211_TKIP_IV_LEN; 420 fallthrough; 421 case IWL_RX_MPDU_STATUS_SEC_WEP: 422 if (!(status & IWL_RX_MPDU_STATUS_ICV_OK)) 423 return -1; 424 425 stats->flag |= RX_FLAG_DECRYPTED; 426 if ((status & IWL_RX_MPDU_STATUS_SEC_MASK) == 427 IWL_RX_MPDU_STATUS_SEC_WEP) 428 *crypt_len = IEEE80211_WEP_IV_LEN; 429 430 if (pkt_flags & FH_RSCSR_RADA_EN) { 431 stats->flag |= RX_FLAG_ICV_STRIPPED; 432 if (mvm->trans->trans_cfg->gen2) 433 stats->flag |= RX_FLAG_MMIC_STRIPPED; 434 } 435 436 return 0; 437 case IWL_RX_MPDU_STATUS_SEC_EXT_ENC: 438 if (!(status & IWL_RX_MPDU_STATUS_MIC_OK)) 439 return -1; 440 stats->flag |= RX_FLAG_DECRYPTED; 441 return 0; 442 case RX_MPDU_RES_STATUS_SEC_CMAC_GMAC_ENC: 443 break; 444 default: 445 /* 446 * Sometimes we can get frames that were not decrypted 447 * because the firmware didn't have the keys yet. This can 448 * happen after connection where we can get multicast frames 449 * before the GTK is installed. 450 * Silently drop those frames. 451 * Also drop un-decrypted frames in monitor mode. 452 */ 453 if (!is_multicast_ether_addr(hdr->addr1) && 454 !mvm->monitor_on && net_ratelimit()) 455 IWL_WARN(mvm, "Unhandled alg: 0x%x\n", status); 456 } 457 458 return 0; 459 } 460 461 static void iwl_mvm_rx_csum(struct iwl_mvm *mvm, 462 struct ieee80211_sta *sta, 463 struct sk_buff *skb, 464 struct iwl_rx_packet *pkt) 465 { 466 struct iwl_rx_mpdu_desc *desc = (void *)pkt->data; 467 468 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) { 469 if (pkt->len_n_flags & cpu_to_le32(FH_RSCSR_RPA_EN)) { 470 u16 hwsum = be16_to_cpu(desc->v3.raw_xsum); 471 472 skb->ip_summed = CHECKSUM_COMPLETE; 473 skb->csum = csum_unfold(~(__force __sum16)hwsum); 474 } 475 } else { 476 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 477 struct iwl_mvm_vif *mvmvif; 478 u16 flags = le16_to_cpu(desc->l3l4_flags); 479 u8 l3_prot = (u8)((flags & IWL_RX_L3L4_L3_PROTO_MASK) >> 480 IWL_RX_L3_PROTO_POS); 481 482 mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif); 483 484 if (mvmvif->features & NETIF_F_RXCSUM && 485 flags & IWL_RX_L3L4_TCP_UDP_CSUM_OK && 486 (flags & IWL_RX_L3L4_IP_HDR_CSUM_OK || 487 l3_prot == IWL_RX_L3_TYPE_IPV6 || 488 l3_prot == IWL_RX_L3_TYPE_IPV6_FRAG)) 489 skb->ip_summed = CHECKSUM_UNNECESSARY; 490 } 491 } 492 493 /* 494 * returns true if a packet is a duplicate or invalid tid and should be dropped. 495 * Updates AMSDU PN tracking info 496 */ 497 static bool iwl_mvm_is_dup(struct ieee80211_sta *sta, int queue, 498 struct ieee80211_rx_status *rx_status, 499 struct ieee80211_hdr *hdr, 500 struct iwl_rx_mpdu_desc *desc) 501 { 502 struct iwl_mvm_sta *mvm_sta; 503 struct iwl_mvm_rxq_dup_data *dup_data; 504 u8 tid, sub_frame_idx; 505 506 if (WARN_ON(IS_ERR_OR_NULL(sta))) 507 return false; 508 509 mvm_sta = iwl_mvm_sta_from_mac80211(sta); 510 511 if (WARN_ON_ONCE(!mvm_sta->dup_data)) 512 return false; 513 514 dup_data = &mvm_sta->dup_data[queue]; 515 516 /* 517 * Drop duplicate 802.11 retransmissions 518 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery") 519 */ 520 if (ieee80211_is_ctl(hdr->frame_control) || 521 ieee80211_is_qos_nullfunc(hdr->frame_control) || 522 is_multicast_ether_addr(hdr->addr1)) { 523 rx_status->flag |= RX_FLAG_DUP_VALIDATED; 524 return false; 525 } 526 527 if (ieee80211_is_data_qos(hdr->frame_control)) { 528 /* frame has qos control */ 529 tid = ieee80211_get_tid(hdr); 530 if (tid >= IWL_MAX_TID_COUNT) 531 return true; 532 } else { 533 tid = IWL_MAX_TID_COUNT; 534 } 535 536 /* If this wasn't a part of an A-MSDU the sub-frame index will be 0 */ 537 sub_frame_idx = desc->amsdu_info & 538 IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK; 539 540 if (unlikely(ieee80211_has_retry(hdr->frame_control) && 541 dup_data->last_seq[tid] == hdr->seq_ctrl && 542 dup_data->last_sub_frame[tid] >= sub_frame_idx)) 543 return true; 544 545 /* Allow same PN as the first subframe for following sub frames */ 546 if (dup_data->last_seq[tid] == hdr->seq_ctrl && 547 sub_frame_idx > dup_data->last_sub_frame[tid] && 548 desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU) 549 rx_status->flag |= RX_FLAG_ALLOW_SAME_PN; 550 551 dup_data->last_seq[tid] = hdr->seq_ctrl; 552 dup_data->last_sub_frame[tid] = sub_frame_idx; 553 554 rx_status->flag |= RX_FLAG_DUP_VALIDATED; 555 556 return false; 557 } 558 559 /* 560 * Returns true if sn2 - buffer_size < sn1 < sn2. 561 * To be used only in order to compare reorder buffer head with NSSN. 562 * We fully trust NSSN unless it is behind us due to reorder timeout. 563 * Reorder timeout can only bring us up to buffer_size SNs ahead of NSSN. 564 */ 565 static bool iwl_mvm_is_sn_less(u16 sn1, u16 sn2, u16 buffer_size) 566 { 567 return ieee80211_sn_less(sn1, sn2) && 568 !ieee80211_sn_less(sn1, sn2 - buffer_size); 569 } 570 571 static void iwl_mvm_sync_nssn(struct iwl_mvm *mvm, u8 baid, u16 nssn) 572 { 573 if (IWL_MVM_USE_NSSN_SYNC) { 574 struct iwl_mvm_nssn_sync_data notif = { 575 .baid = baid, 576 .nssn = nssn, 577 }; 578 579 iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_NSSN_SYNC, false, 580 ¬if, sizeof(notif)); 581 } 582 } 583 584 #define RX_REORDER_BUF_TIMEOUT_MQ (HZ / 10) 585 586 enum iwl_mvm_release_flags { 587 IWL_MVM_RELEASE_SEND_RSS_SYNC = BIT(0), 588 IWL_MVM_RELEASE_FROM_RSS_SYNC = BIT(1), 589 }; 590 591 static void iwl_mvm_release_frames(struct iwl_mvm *mvm, 592 struct ieee80211_sta *sta, 593 struct napi_struct *napi, 594 struct iwl_mvm_baid_data *baid_data, 595 struct iwl_mvm_reorder_buffer *reorder_buf, 596 u16 nssn, u32 flags) 597 { 598 struct iwl_mvm_reorder_buf_entry *entries = 599 &baid_data->entries[reorder_buf->queue * 600 baid_data->entries_per_queue]; 601 u16 ssn = reorder_buf->head_sn; 602 603 lockdep_assert_held(&reorder_buf->lock); 604 605 /* 606 * We keep the NSSN not too far behind, if we are sync'ing it and it 607 * is more than 2048 ahead of us, it must be behind us. Discard it. 608 * This can happen if the queue that hit the 0 / 2048 seqno was lagging 609 * behind and this queue already processed packets. The next if 610 * would have caught cases where this queue would have processed less 611 * than 64 packets, but it may have processed more than 64 packets. 612 */ 613 if ((flags & IWL_MVM_RELEASE_FROM_RSS_SYNC) && 614 ieee80211_sn_less(nssn, ssn)) 615 goto set_timer; 616 617 /* ignore nssn smaller than head sn - this can happen due to timeout */ 618 if (iwl_mvm_is_sn_less(nssn, ssn, reorder_buf->buf_size)) 619 goto set_timer; 620 621 while (iwl_mvm_is_sn_less(ssn, nssn, reorder_buf->buf_size)) { 622 int index = ssn % reorder_buf->buf_size; 623 struct sk_buff_head *skb_list = &entries[index].e.frames; 624 struct sk_buff *skb; 625 626 ssn = ieee80211_sn_inc(ssn); 627 if ((flags & IWL_MVM_RELEASE_SEND_RSS_SYNC) && 628 (ssn == 2048 || ssn == 0)) 629 iwl_mvm_sync_nssn(mvm, baid_data->baid, ssn); 630 631 /* 632 * Empty the list. Will have more than one frame for A-MSDU. 633 * Empty list is valid as well since nssn indicates frames were 634 * received. 635 */ 636 while ((skb = __skb_dequeue(skb_list))) { 637 iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb, 638 reorder_buf->queue, 639 sta, NULL /* FIXME */); 640 reorder_buf->num_stored--; 641 } 642 } 643 reorder_buf->head_sn = nssn; 644 645 set_timer: 646 if (reorder_buf->num_stored && !reorder_buf->removed) { 647 u16 index = reorder_buf->head_sn % reorder_buf->buf_size; 648 649 while (skb_queue_empty(&entries[index].e.frames)) 650 index = (index + 1) % reorder_buf->buf_size; 651 /* modify timer to match next frame's expiration time */ 652 mod_timer(&reorder_buf->reorder_timer, 653 entries[index].e.reorder_time + 1 + 654 RX_REORDER_BUF_TIMEOUT_MQ); 655 } else { 656 del_timer(&reorder_buf->reorder_timer); 657 } 658 } 659 660 void iwl_mvm_reorder_timer_expired(struct timer_list *t) 661 { 662 struct iwl_mvm_reorder_buffer *buf = from_timer(buf, t, reorder_timer); 663 struct iwl_mvm_baid_data *baid_data = 664 iwl_mvm_baid_data_from_reorder_buf(buf); 665 struct iwl_mvm_reorder_buf_entry *entries = 666 &baid_data->entries[buf->queue * baid_data->entries_per_queue]; 667 int i; 668 u16 sn = 0, index = 0; 669 bool expired = false; 670 bool cont = false; 671 672 spin_lock(&buf->lock); 673 674 if (!buf->num_stored || buf->removed) { 675 spin_unlock(&buf->lock); 676 return; 677 } 678 679 for (i = 0; i < buf->buf_size ; i++) { 680 index = (buf->head_sn + i) % buf->buf_size; 681 682 if (skb_queue_empty(&entries[index].e.frames)) { 683 /* 684 * If there is a hole and the next frame didn't expire 685 * we want to break and not advance SN 686 */ 687 cont = false; 688 continue; 689 } 690 if (!cont && 691 !time_after(jiffies, entries[index].e.reorder_time + 692 RX_REORDER_BUF_TIMEOUT_MQ)) 693 break; 694 695 expired = true; 696 /* continue until next hole after this expired frames */ 697 cont = true; 698 sn = ieee80211_sn_add(buf->head_sn, i + 1); 699 } 700 701 if (expired) { 702 struct ieee80211_sta *sta; 703 struct iwl_mvm_sta *mvmsta; 704 u8 sta_id = ffs(baid_data->sta_mask) - 1; 705 706 rcu_read_lock(); 707 sta = rcu_dereference(buf->mvm->fw_id_to_mac_id[sta_id]); 708 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) { 709 rcu_read_unlock(); 710 goto out; 711 } 712 713 mvmsta = iwl_mvm_sta_from_mac80211(sta); 714 715 /* SN is set to the last expired frame + 1 */ 716 IWL_DEBUG_HT(buf->mvm, 717 "Releasing expired frames for sta %u, sn %d\n", 718 sta_id, sn); 719 iwl_mvm_event_frame_timeout_callback(buf->mvm, mvmsta->vif, 720 sta, baid_data->tid); 721 iwl_mvm_release_frames(buf->mvm, sta, NULL, baid_data, 722 buf, sn, IWL_MVM_RELEASE_SEND_RSS_SYNC); 723 rcu_read_unlock(); 724 } else { 725 /* 726 * If no frame expired and there are stored frames, index is now 727 * pointing to the first unexpired frame - modify timer 728 * accordingly to this frame. 729 */ 730 mod_timer(&buf->reorder_timer, 731 entries[index].e.reorder_time + 732 1 + RX_REORDER_BUF_TIMEOUT_MQ); 733 } 734 735 out: 736 spin_unlock(&buf->lock); 737 } 738 739 static void iwl_mvm_del_ba(struct iwl_mvm *mvm, int queue, 740 struct iwl_mvm_delba_data *data) 741 { 742 struct iwl_mvm_baid_data *ba_data; 743 struct ieee80211_sta *sta; 744 struct iwl_mvm_reorder_buffer *reorder_buf; 745 u8 baid = data->baid; 746 u32 sta_id; 747 748 if (WARN_ONCE(baid >= IWL_MAX_BAID, "invalid BAID: %x\n", baid)) 749 return; 750 751 rcu_read_lock(); 752 753 ba_data = rcu_dereference(mvm->baid_map[baid]); 754 if (WARN_ON_ONCE(!ba_data)) 755 goto out; 756 757 /* pick any STA ID to find the pointer */ 758 sta_id = ffs(ba_data->sta_mask) - 1; 759 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); 760 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) 761 goto out; 762 763 reorder_buf = &ba_data->reorder_buf[queue]; 764 765 /* release all frames that are in the reorder buffer to the stack */ 766 spin_lock_bh(&reorder_buf->lock); 767 iwl_mvm_release_frames(mvm, sta, NULL, ba_data, reorder_buf, 768 ieee80211_sn_add(reorder_buf->head_sn, 769 reorder_buf->buf_size), 770 0); 771 spin_unlock_bh(&reorder_buf->lock); 772 del_timer_sync(&reorder_buf->reorder_timer); 773 774 out: 775 rcu_read_unlock(); 776 } 777 778 static void iwl_mvm_release_frames_from_notif(struct iwl_mvm *mvm, 779 struct napi_struct *napi, 780 u8 baid, u16 nssn, int queue, 781 u32 flags) 782 { 783 struct ieee80211_sta *sta; 784 struct iwl_mvm_reorder_buffer *reorder_buf; 785 struct iwl_mvm_baid_data *ba_data; 786 u32 sta_id; 787 788 IWL_DEBUG_HT(mvm, "Frame release notification for BAID %u, NSSN %d\n", 789 baid, nssn); 790 791 if (WARN_ON_ONCE(baid == IWL_RX_REORDER_DATA_INVALID_BAID || 792 baid >= ARRAY_SIZE(mvm->baid_map))) 793 return; 794 795 rcu_read_lock(); 796 797 ba_data = rcu_dereference(mvm->baid_map[baid]); 798 if (!ba_data) { 799 WARN(!(flags & IWL_MVM_RELEASE_FROM_RSS_SYNC), 800 "BAID %d not found in map\n", baid); 801 goto out; 802 } 803 804 /* pick any STA ID to find the pointer */ 805 sta_id = ffs(ba_data->sta_mask) - 1; 806 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); 807 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) 808 goto out; 809 810 reorder_buf = &ba_data->reorder_buf[queue]; 811 812 spin_lock_bh(&reorder_buf->lock); 813 iwl_mvm_release_frames(mvm, sta, napi, ba_data, 814 reorder_buf, nssn, flags); 815 spin_unlock_bh(&reorder_buf->lock); 816 817 out: 818 rcu_read_unlock(); 819 } 820 821 static void iwl_mvm_nssn_sync(struct iwl_mvm *mvm, 822 struct napi_struct *napi, int queue, 823 const struct iwl_mvm_nssn_sync_data *data) 824 { 825 iwl_mvm_release_frames_from_notif(mvm, napi, data->baid, 826 data->nssn, queue, 827 IWL_MVM_RELEASE_FROM_RSS_SYNC); 828 } 829 830 void iwl_mvm_rx_queue_notif(struct iwl_mvm *mvm, struct napi_struct *napi, 831 struct iwl_rx_cmd_buffer *rxb, int queue) 832 { 833 struct iwl_rx_packet *pkt = rxb_addr(rxb); 834 struct iwl_rxq_sync_notification *notif; 835 struct iwl_mvm_internal_rxq_notif *internal_notif; 836 u32 len = iwl_rx_packet_payload_len(pkt); 837 838 notif = (void *)pkt->data; 839 internal_notif = (void *)notif->payload; 840 841 if (WARN_ONCE(len < sizeof(*notif) + sizeof(*internal_notif), 842 "invalid notification size %d (%d)", 843 len, (int)(sizeof(*notif) + sizeof(*internal_notif)))) 844 return; 845 len -= sizeof(*notif) + sizeof(*internal_notif); 846 847 if (internal_notif->sync && 848 mvm->queue_sync_cookie != internal_notif->cookie) { 849 WARN_ONCE(1, "Received expired RX queue sync message\n"); 850 return; 851 } 852 853 switch (internal_notif->type) { 854 case IWL_MVM_RXQ_EMPTY: 855 WARN_ONCE(len, "invalid empty notification size %d", len); 856 break; 857 case IWL_MVM_RXQ_NOTIF_DEL_BA: 858 if (WARN_ONCE(len != sizeof(struct iwl_mvm_delba_data), 859 "invalid delba notification size %d (%d)", 860 len, (int)sizeof(struct iwl_mvm_delba_data))) 861 break; 862 iwl_mvm_del_ba(mvm, queue, (void *)internal_notif->data); 863 break; 864 case IWL_MVM_RXQ_NSSN_SYNC: 865 if (WARN_ONCE(len != sizeof(struct iwl_mvm_nssn_sync_data), 866 "invalid nssn sync notification size %d (%d)", 867 len, (int)sizeof(struct iwl_mvm_nssn_sync_data))) 868 break; 869 iwl_mvm_nssn_sync(mvm, napi, queue, 870 (void *)internal_notif->data); 871 break; 872 default: 873 WARN_ONCE(1, "Invalid identifier %d", internal_notif->type); 874 } 875 876 if (internal_notif->sync) { 877 WARN_ONCE(!test_and_clear_bit(queue, &mvm->queue_sync_state), 878 "queue sync: queue %d responded a second time!\n", 879 queue); 880 if (READ_ONCE(mvm->queue_sync_state) == 0) 881 wake_up(&mvm->rx_sync_waitq); 882 } 883 } 884 885 static void iwl_mvm_oldsn_workaround(struct iwl_mvm *mvm, 886 struct ieee80211_sta *sta, int tid, 887 struct iwl_mvm_reorder_buffer *buffer, 888 u32 reorder, u32 gp2, int queue) 889 { 890 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 891 892 if (gp2 != buffer->consec_oldsn_ampdu_gp2) { 893 /* we have a new (A-)MPDU ... */ 894 895 /* 896 * reset counter to 0 if we didn't have any oldsn in 897 * the last A-MPDU (as detected by GP2 being identical) 898 */ 899 if (!buffer->consec_oldsn_prev_drop) 900 buffer->consec_oldsn_drops = 0; 901 902 /* either way, update our tracking state */ 903 buffer->consec_oldsn_ampdu_gp2 = gp2; 904 } else if (buffer->consec_oldsn_prev_drop) { 905 /* 906 * tracking state didn't change, and we had an old SN 907 * indication before - do nothing in this case, we 908 * already noted this one down and are waiting for the 909 * next A-MPDU (by GP2) 910 */ 911 return; 912 } 913 914 /* return unless this MPDU has old SN */ 915 if (!(reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN)) 916 return; 917 918 /* update state */ 919 buffer->consec_oldsn_prev_drop = 1; 920 buffer->consec_oldsn_drops++; 921 922 /* if limit is reached, send del BA and reset state */ 923 if (buffer->consec_oldsn_drops == IWL_MVM_AMPDU_CONSEC_DROPS_DELBA) { 924 IWL_WARN(mvm, 925 "reached %d old SN frames from %pM on queue %d, stopping BA session on TID %d\n", 926 IWL_MVM_AMPDU_CONSEC_DROPS_DELBA, 927 sta->addr, queue, tid); 928 ieee80211_stop_rx_ba_session(mvmsta->vif, BIT(tid), sta->addr); 929 buffer->consec_oldsn_prev_drop = 0; 930 buffer->consec_oldsn_drops = 0; 931 } 932 } 933 934 /* 935 * Returns true if the MPDU was buffered\dropped, false if it should be passed 936 * to upper layer. 937 */ 938 static bool iwl_mvm_reorder(struct iwl_mvm *mvm, 939 struct napi_struct *napi, 940 int queue, 941 struct ieee80211_sta *sta, 942 struct sk_buff *skb, 943 struct iwl_rx_mpdu_desc *desc) 944 { 945 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 946 struct ieee80211_hdr *hdr = (void *)skb_mac_header(skb); 947 struct iwl_mvm_baid_data *baid_data; 948 struct iwl_mvm_reorder_buffer *buffer; 949 struct sk_buff *tail; 950 u32 reorder = le32_to_cpu(desc->reorder_data); 951 bool amsdu = desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU; 952 bool last_subframe = 953 desc->amsdu_info & IWL_RX_MPDU_AMSDU_LAST_SUBFRAME; 954 u8 tid = ieee80211_get_tid(hdr); 955 u8 sub_frame_idx = desc->amsdu_info & 956 IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK; 957 struct iwl_mvm_reorder_buf_entry *entries; 958 u32 sta_mask; 959 int index; 960 u16 nssn, sn; 961 u8 baid; 962 963 baid = (reorder & IWL_RX_MPDU_REORDER_BAID_MASK) >> 964 IWL_RX_MPDU_REORDER_BAID_SHIFT; 965 966 /* 967 * This also covers the case of receiving a Block Ack Request 968 * outside a BA session; we'll pass it to mac80211 and that 969 * then sends a delBA action frame. 970 * This also covers pure monitor mode, in which case we won't 971 * have any BA sessions. 972 */ 973 if (baid == IWL_RX_REORDER_DATA_INVALID_BAID) 974 return false; 975 976 /* no sta yet */ 977 if (WARN_ONCE(IS_ERR_OR_NULL(sta), 978 "Got valid BAID without a valid station assigned\n")) 979 return false; 980 981 /* not a data packet or a bar */ 982 if (!ieee80211_is_back_req(hdr->frame_control) && 983 (!ieee80211_is_data_qos(hdr->frame_control) || 984 is_multicast_ether_addr(hdr->addr1))) 985 return false; 986 987 if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) 988 return false; 989 990 baid_data = rcu_dereference(mvm->baid_map[baid]); 991 if (!baid_data) { 992 IWL_DEBUG_RX(mvm, 993 "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n", 994 baid, reorder); 995 return false; 996 } 997 998 rcu_read_lock(); 999 sta_mask = iwl_mvm_sta_fw_id_mask(mvm, sta, -1); 1000 rcu_read_unlock(); 1001 1002 if (IWL_FW_CHECK(mvm, 1003 tid != baid_data->tid || 1004 !(sta_mask & baid_data->sta_mask), 1005 "baid 0x%x is mapped to sta_mask:0x%x tid:%d, but was received for sta_mask:0x%x tid:%d\n", 1006 baid, baid_data->sta_mask, baid_data->tid, 1007 sta_mask, tid)) 1008 return false; 1009 1010 nssn = reorder & IWL_RX_MPDU_REORDER_NSSN_MASK; 1011 sn = (reorder & IWL_RX_MPDU_REORDER_SN_MASK) >> 1012 IWL_RX_MPDU_REORDER_SN_SHIFT; 1013 1014 buffer = &baid_data->reorder_buf[queue]; 1015 entries = &baid_data->entries[queue * baid_data->entries_per_queue]; 1016 1017 spin_lock_bh(&buffer->lock); 1018 1019 if (!buffer->valid) { 1020 if (reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN) { 1021 spin_unlock_bh(&buffer->lock); 1022 return false; 1023 } 1024 buffer->valid = true; 1025 } 1026 1027 if (ieee80211_is_back_req(hdr->frame_control)) { 1028 iwl_mvm_release_frames(mvm, sta, napi, baid_data, 1029 buffer, nssn, 0); 1030 goto drop; 1031 } 1032 1033 /* 1034 * If there was a significant jump in the nssn - adjust. 1035 * If the SN is smaller than the NSSN it might need to first go into 1036 * the reorder buffer, in which case we just release up to it and the 1037 * rest of the function will take care of storing it and releasing up to 1038 * the nssn. 1039 * This should not happen. This queue has been lagging and it should 1040 * have been updated by a IWL_MVM_RXQ_NSSN_SYNC notification. Be nice 1041 * and update the other queues. 1042 */ 1043 if (!iwl_mvm_is_sn_less(nssn, buffer->head_sn + buffer->buf_size, 1044 buffer->buf_size) || 1045 !ieee80211_sn_less(sn, buffer->head_sn + buffer->buf_size)) { 1046 u16 min_sn = ieee80211_sn_less(sn, nssn) ? sn : nssn; 1047 1048 iwl_mvm_release_frames(mvm, sta, napi, baid_data, buffer, 1049 min_sn, IWL_MVM_RELEASE_SEND_RSS_SYNC); 1050 } 1051 1052 iwl_mvm_oldsn_workaround(mvm, sta, tid, buffer, reorder, 1053 rx_status->device_timestamp, queue); 1054 1055 /* drop any oudated packets */ 1056 if (ieee80211_sn_less(sn, buffer->head_sn)) 1057 goto drop; 1058 1059 /* release immediately if allowed by nssn and no stored frames */ 1060 if (!buffer->num_stored && ieee80211_sn_less(sn, nssn)) { 1061 if (iwl_mvm_is_sn_less(buffer->head_sn, nssn, 1062 buffer->buf_size) && 1063 (!amsdu || last_subframe)) { 1064 /* 1065 * If we crossed the 2048 or 0 SN, notify all the 1066 * queues. This is done in order to avoid having a 1067 * head_sn that lags behind for too long. When that 1068 * happens, we can get to a situation where the head_sn 1069 * is within the interval [nssn - buf_size : nssn] 1070 * which will make us think that the nssn is a packet 1071 * that we already freed because of the reordering 1072 * buffer and we will ignore it. So maintain the 1073 * head_sn somewhat updated across all the queues: 1074 * when it crosses 0 and 2048. 1075 */ 1076 if (sn == 2048 || sn == 0) 1077 iwl_mvm_sync_nssn(mvm, baid, sn); 1078 buffer->head_sn = nssn; 1079 } 1080 /* No need to update AMSDU last SN - we are moving the head */ 1081 spin_unlock_bh(&buffer->lock); 1082 return false; 1083 } 1084 1085 /* 1086 * release immediately if there are no stored frames, and the sn is 1087 * equal to the head. 1088 * This can happen due to reorder timer, where NSSN is behind head_sn. 1089 * When we released everything, and we got the next frame in the 1090 * sequence, according to the NSSN we can't release immediately, 1091 * while technically there is no hole and we can move forward. 1092 */ 1093 if (!buffer->num_stored && sn == buffer->head_sn) { 1094 if (!amsdu || last_subframe) { 1095 if (sn == 2048 || sn == 0) 1096 iwl_mvm_sync_nssn(mvm, baid, sn); 1097 buffer->head_sn = ieee80211_sn_inc(buffer->head_sn); 1098 } 1099 /* No need to update AMSDU last SN - we are moving the head */ 1100 spin_unlock_bh(&buffer->lock); 1101 return false; 1102 } 1103 1104 index = sn % buffer->buf_size; 1105 1106 /* 1107 * Check if we already stored this frame 1108 * As AMSDU is either received or not as whole, logic is simple: 1109 * If we have frames in that position in the buffer and the last frame 1110 * originated from AMSDU had a different SN then it is a retransmission. 1111 * If it is the same SN then if the subframe index is incrementing it 1112 * is the same AMSDU - otherwise it is a retransmission. 1113 */ 1114 tail = skb_peek_tail(&entries[index].e.frames); 1115 if (tail && !amsdu) 1116 goto drop; 1117 else if (tail && (sn != buffer->last_amsdu || 1118 buffer->last_sub_index >= sub_frame_idx)) 1119 goto drop; 1120 1121 /* put in reorder buffer */ 1122 __skb_queue_tail(&entries[index].e.frames, skb); 1123 buffer->num_stored++; 1124 entries[index].e.reorder_time = jiffies; 1125 1126 if (amsdu) { 1127 buffer->last_amsdu = sn; 1128 buffer->last_sub_index = sub_frame_idx; 1129 } 1130 1131 /* 1132 * We cannot trust NSSN for AMSDU sub-frames that are not the last. 1133 * The reason is that NSSN advances on the first sub-frame, and may 1134 * cause the reorder buffer to advance before all the sub-frames arrive. 1135 * Example: reorder buffer contains SN 0 & 2, and we receive AMSDU with 1136 * SN 1. NSSN for first sub frame will be 3 with the result of driver 1137 * releasing SN 0,1, 2. When sub-frame 1 arrives - reorder buffer is 1138 * already ahead and it will be dropped. 1139 * If the last sub-frame is not on this queue - we will get frame 1140 * release notification with up to date NSSN. 1141 */ 1142 if (!amsdu || last_subframe) 1143 iwl_mvm_release_frames(mvm, sta, napi, baid_data, 1144 buffer, nssn, 1145 IWL_MVM_RELEASE_SEND_RSS_SYNC); 1146 1147 spin_unlock_bh(&buffer->lock); 1148 return true; 1149 1150 drop: 1151 kfree_skb(skb); 1152 spin_unlock_bh(&buffer->lock); 1153 return true; 1154 } 1155 1156 static void iwl_mvm_agg_rx_received(struct iwl_mvm *mvm, 1157 u32 reorder_data, u8 baid) 1158 { 1159 unsigned long now = jiffies; 1160 unsigned long timeout; 1161 struct iwl_mvm_baid_data *data; 1162 1163 rcu_read_lock(); 1164 1165 data = rcu_dereference(mvm->baid_map[baid]); 1166 if (!data) { 1167 IWL_DEBUG_RX(mvm, 1168 "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n", 1169 baid, reorder_data); 1170 goto out; 1171 } 1172 1173 if (!data->timeout) 1174 goto out; 1175 1176 timeout = data->timeout; 1177 /* 1178 * Do not update last rx all the time to avoid cache bouncing 1179 * between the rx queues. 1180 * Update it every timeout. Worst case is the session will 1181 * expire after ~ 2 * timeout, which doesn't matter that much. 1182 */ 1183 if (time_before(data->last_rx + TU_TO_JIFFIES(timeout), now)) 1184 /* Update is atomic */ 1185 data->last_rx = now; 1186 1187 out: 1188 rcu_read_unlock(); 1189 } 1190 1191 static void iwl_mvm_flip_address(u8 *addr) 1192 { 1193 int i; 1194 u8 mac_addr[ETH_ALEN]; 1195 1196 for (i = 0; i < ETH_ALEN; i++) 1197 mac_addr[i] = addr[ETH_ALEN - i - 1]; 1198 ether_addr_copy(addr, mac_addr); 1199 } 1200 1201 struct iwl_mvm_rx_phy_data { 1202 enum iwl_rx_phy_info_type info_type; 1203 __le32 d0, d1, d2, d3, eht_d4, d5; 1204 __le16 d4; 1205 bool with_data; 1206 bool first_subframe; 1207 __le32 rx_vec[4]; 1208 1209 u32 rate_n_flags; 1210 u32 gp2_on_air_rise; 1211 u16 phy_info; 1212 u8 energy_a, energy_b; 1213 u8 channel; 1214 }; 1215 1216 static void iwl_mvm_decode_he_mu_ext(struct iwl_mvm *mvm, 1217 struct iwl_mvm_rx_phy_data *phy_data, 1218 struct ieee80211_radiotap_he_mu *he_mu) 1219 { 1220 u32 phy_data2 = le32_to_cpu(phy_data->d2); 1221 u32 phy_data3 = le32_to_cpu(phy_data->d3); 1222 u16 phy_data4 = le16_to_cpu(phy_data->d4); 1223 u32 rate_n_flags = phy_data->rate_n_flags; 1224 1225 if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CRC_OK, phy_data4)) { 1226 he_mu->flags1 |= 1227 cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_RU_KNOWN | 1228 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU_KNOWN); 1229 1230 he_mu->flags1 |= 1231 le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CTR_RU, 1232 phy_data4), 1233 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU); 1234 1235 he_mu->ru_ch1[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU0, 1236 phy_data2); 1237 he_mu->ru_ch1[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU1, 1238 phy_data3); 1239 he_mu->ru_ch1[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU2, 1240 phy_data2); 1241 he_mu->ru_ch1[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU3, 1242 phy_data3); 1243 } 1244 1245 if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CRC_OK, phy_data4) && 1246 (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK_V1) != RATE_MCS_CHAN_WIDTH_20) { 1247 he_mu->flags1 |= 1248 cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_RU_KNOWN | 1249 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_CTR_26T_RU_KNOWN); 1250 1251 he_mu->flags2 |= 1252 le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CTR_RU, 1253 phy_data4), 1254 IEEE80211_RADIOTAP_HE_MU_FLAGS2_CH2_CTR_26T_RU); 1255 1256 he_mu->ru_ch2[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU0, 1257 phy_data2); 1258 he_mu->ru_ch2[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU1, 1259 phy_data3); 1260 he_mu->ru_ch2[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU2, 1261 phy_data2); 1262 he_mu->ru_ch2[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU3, 1263 phy_data3); 1264 } 1265 } 1266 1267 static void 1268 iwl_mvm_decode_he_phy_ru_alloc(struct iwl_mvm_rx_phy_data *phy_data, 1269 struct ieee80211_radiotap_he *he, 1270 struct ieee80211_radiotap_he_mu *he_mu, 1271 struct ieee80211_rx_status *rx_status) 1272 { 1273 /* 1274 * Unfortunately, we have to leave the mac80211 data 1275 * incorrect for the case that we receive an HE-MU 1276 * transmission and *don't* have the HE phy data (due 1277 * to the bits being used for TSF). This shouldn't 1278 * happen though as management frames where we need 1279 * the TSF/timers are not be transmitted in HE-MU. 1280 */ 1281 u8 ru = le32_get_bits(phy_data->d1, IWL_RX_PHY_DATA1_HE_RU_ALLOC_MASK); 1282 u32 rate_n_flags = phy_data->rate_n_flags; 1283 u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK_V1; 1284 u8 offs = 0; 1285 1286 rx_status->bw = RATE_INFO_BW_HE_RU; 1287 1288 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN); 1289 1290 switch (ru) { 1291 case 0 ... 36: 1292 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_26; 1293 offs = ru; 1294 break; 1295 case 37 ... 52: 1296 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_52; 1297 offs = ru - 37; 1298 break; 1299 case 53 ... 60: 1300 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106; 1301 offs = ru - 53; 1302 break; 1303 case 61 ... 64: 1304 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_242; 1305 offs = ru - 61; 1306 break; 1307 case 65 ... 66: 1308 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_484; 1309 offs = ru - 65; 1310 break; 1311 case 67: 1312 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_996; 1313 break; 1314 case 68: 1315 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_2x996; 1316 break; 1317 } 1318 he->data2 |= le16_encode_bits(offs, 1319 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET); 1320 he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_KNOWN | 1321 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET_KNOWN); 1322 if (phy_data->d1 & cpu_to_le32(IWL_RX_PHY_DATA1_HE_RU_ALLOC_SEC80)) 1323 he->data2 |= 1324 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_SEC); 1325 1326 #define CHECK_BW(bw) \ 1327 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_ ## bw ## MHZ != \ 1328 RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS); \ 1329 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_ ## bw ## MHZ != \ 1330 RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS) 1331 CHECK_BW(20); 1332 CHECK_BW(40); 1333 CHECK_BW(80); 1334 CHECK_BW(160); 1335 1336 if (he_mu) 1337 he_mu->flags2 |= 1338 le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK_V1, 1339 rate_n_flags), 1340 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW); 1341 else if (he_type == RATE_MCS_HE_TYPE_TRIG_V1) 1342 he->data6 |= 1343 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_KNOWN) | 1344 le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK_V1, 1345 rate_n_flags), 1346 IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW); 1347 } 1348 1349 static void iwl_mvm_decode_he_phy_data(struct iwl_mvm *mvm, 1350 struct iwl_mvm_rx_phy_data *phy_data, 1351 struct ieee80211_radiotap_he *he, 1352 struct ieee80211_radiotap_he_mu *he_mu, 1353 struct ieee80211_rx_status *rx_status, 1354 int queue) 1355 { 1356 switch (phy_data->info_type) { 1357 case IWL_RX_PHY_INFO_TYPE_NONE: 1358 case IWL_RX_PHY_INFO_TYPE_CCK: 1359 case IWL_RX_PHY_INFO_TYPE_OFDM_LGCY: 1360 case IWL_RX_PHY_INFO_TYPE_HT: 1361 case IWL_RX_PHY_INFO_TYPE_VHT_SU: 1362 case IWL_RX_PHY_INFO_TYPE_VHT_MU: 1363 case IWL_RX_PHY_INFO_TYPE_EHT_MU: 1364 case IWL_RX_PHY_INFO_TYPE_EHT_TB: 1365 case IWL_RX_PHY_INFO_TYPE_EHT_MU_EXT: 1366 case IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT: 1367 return; 1368 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT: 1369 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN | 1370 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE2_KNOWN | 1371 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE3_KNOWN | 1372 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE4_KNOWN); 1373 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2, 1374 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE1), 1375 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE1); 1376 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2, 1377 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE2), 1378 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE2); 1379 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2, 1380 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE3), 1381 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE3); 1382 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2, 1383 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE4), 1384 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE4); 1385 fallthrough; 1386 case IWL_RX_PHY_INFO_TYPE_HE_SU: 1387 case IWL_RX_PHY_INFO_TYPE_HE_MU: 1388 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT: 1389 case IWL_RX_PHY_INFO_TYPE_HE_TB: 1390 /* HE common */ 1391 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_LDPC_XSYMSEG_KNOWN | 1392 IEEE80211_RADIOTAP_HE_DATA1_DOPPLER_KNOWN | 1393 IEEE80211_RADIOTAP_HE_DATA1_BSS_COLOR_KNOWN); 1394 he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRE_FEC_PAD_KNOWN | 1395 IEEE80211_RADIOTAP_HE_DATA2_PE_DISAMBIG_KNOWN | 1396 IEEE80211_RADIOTAP_HE_DATA2_TXOP_KNOWN | 1397 IEEE80211_RADIOTAP_HE_DATA2_NUM_LTF_SYMS_KNOWN); 1398 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1399 IWL_RX_PHY_DATA0_HE_BSS_COLOR_MASK), 1400 IEEE80211_RADIOTAP_HE_DATA3_BSS_COLOR); 1401 if (phy_data->info_type != IWL_RX_PHY_INFO_TYPE_HE_TB && 1402 phy_data->info_type != IWL_RX_PHY_INFO_TYPE_HE_TB_EXT) { 1403 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_UL_DL_KNOWN); 1404 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1405 IWL_RX_PHY_DATA0_HE_UPLINK), 1406 IEEE80211_RADIOTAP_HE_DATA3_UL_DL); 1407 } 1408 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1409 IWL_RX_PHY_DATA0_HE_LDPC_EXT_SYM), 1410 IEEE80211_RADIOTAP_HE_DATA3_LDPC_XSYMSEG); 1411 he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1412 IWL_RX_PHY_DATA0_HE_PRE_FEC_PAD_MASK), 1413 IEEE80211_RADIOTAP_HE_DATA5_PRE_FEC_PAD); 1414 he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1415 IWL_RX_PHY_DATA0_HE_PE_DISAMBIG), 1416 IEEE80211_RADIOTAP_HE_DATA5_PE_DISAMBIG); 1417 he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d1, 1418 IWL_RX_PHY_DATA1_HE_LTF_NUM_MASK), 1419 IEEE80211_RADIOTAP_HE_DATA5_NUM_LTF_SYMS); 1420 he->data6 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1421 IWL_RX_PHY_DATA0_HE_TXOP_DUR_MASK), 1422 IEEE80211_RADIOTAP_HE_DATA6_TXOP); 1423 he->data6 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1424 IWL_RX_PHY_DATA0_HE_DOPPLER), 1425 IEEE80211_RADIOTAP_HE_DATA6_DOPPLER); 1426 break; 1427 } 1428 1429 switch (phy_data->info_type) { 1430 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT: 1431 case IWL_RX_PHY_INFO_TYPE_HE_MU: 1432 case IWL_RX_PHY_INFO_TYPE_HE_SU: 1433 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN); 1434 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1435 IWL_RX_PHY_DATA0_HE_SPATIAL_REUSE_MASK), 1436 IEEE80211_RADIOTAP_HE_DATA4_SU_MU_SPTL_REUSE); 1437 break; 1438 default: 1439 /* nothing here */ 1440 break; 1441 } 1442 1443 switch (phy_data->info_type) { 1444 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT: 1445 he_mu->flags1 |= 1446 le16_encode_bits(le16_get_bits(phy_data->d4, 1447 IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_DCM), 1448 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM); 1449 he_mu->flags1 |= 1450 le16_encode_bits(le16_get_bits(phy_data->d4, 1451 IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_MCS_MASK), 1452 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS); 1453 he_mu->flags2 |= 1454 le16_encode_bits(le16_get_bits(phy_data->d4, 1455 IWL_RX_PHY_DATA4_HE_MU_EXT_PREAMBLE_PUNC_TYPE_MASK), 1456 IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW); 1457 iwl_mvm_decode_he_mu_ext(mvm, phy_data, he_mu); 1458 fallthrough; 1459 case IWL_RX_PHY_INFO_TYPE_HE_MU: 1460 he_mu->flags2 |= 1461 le16_encode_bits(le32_get_bits(phy_data->d1, 1462 IWL_RX_PHY_DATA1_HE_MU_SIBG_SYM_OR_USER_NUM_MASK), 1463 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_SYMS_USERS); 1464 he_mu->flags2 |= 1465 le16_encode_bits(le32_get_bits(phy_data->d1, 1466 IWL_RX_PHY_DATA1_HE_MU_SIGB_COMPRESSION), 1467 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_COMP); 1468 fallthrough; 1469 case IWL_RX_PHY_INFO_TYPE_HE_TB: 1470 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT: 1471 iwl_mvm_decode_he_phy_ru_alloc(phy_data, he, he_mu, rx_status); 1472 break; 1473 case IWL_RX_PHY_INFO_TYPE_HE_SU: 1474 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BEAM_CHANGE_KNOWN); 1475 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1476 IWL_RX_PHY_DATA0_HE_BEAM_CHNG), 1477 IEEE80211_RADIOTAP_HE_DATA3_BEAM_CHANGE); 1478 break; 1479 default: 1480 /* nothing */ 1481 break; 1482 } 1483 } 1484 1485 #define LE32_DEC_ENC(value, dec_bits, enc_bits) \ 1486 le32_encode_bits(le32_get_bits(value, dec_bits), enc_bits) 1487 1488 #define IWL_MVM_ENC_USIG_VALUE_MASK(usig, in_value, dec_bits, enc_bits) do { \ 1489 typeof(enc_bits) _enc_bits = enc_bits; \ 1490 typeof(usig) _usig = usig; \ 1491 (_usig)->mask |= cpu_to_le32(_enc_bits); \ 1492 (_usig)->value |= LE32_DEC_ENC(in_value, dec_bits, _enc_bits); \ 1493 } while (0) 1494 1495 #define __IWL_MVM_ENC_EHT_RU(rt_data, rt_ru, fw_data, fw_ru) \ 1496 eht->data[(rt_data)] |= \ 1497 (cpu_to_le32 \ 1498 (IEEE80211_RADIOTAP_EHT_DATA ## rt_data ## _RU_ALLOC_CC_ ## rt_ru ## _KNOWN) | \ 1499 LE32_DEC_ENC(data ## fw_data, \ 1500 IWL_RX_PHY_DATA ## fw_data ## _EHT_MU_EXT_RU_ALLOC_ ## fw_ru, \ 1501 IEEE80211_RADIOTAP_EHT_DATA ## rt_data ## _RU_ALLOC_CC_ ## rt_ru)) 1502 1503 #define _IWL_MVM_ENC_EHT_RU(rt_data, rt_ru, fw_data, fw_ru) \ 1504 __IWL_MVM_ENC_EHT_RU(rt_data, rt_ru, fw_data, fw_ru) 1505 1506 #define IEEE80211_RADIOTAP_RU_DATA_1_1_1 1 1507 #define IEEE80211_RADIOTAP_RU_DATA_2_1_1 2 1508 #define IEEE80211_RADIOTAP_RU_DATA_1_1_2 2 1509 #define IEEE80211_RADIOTAP_RU_DATA_2_1_2 2 1510 #define IEEE80211_RADIOTAP_RU_DATA_1_2_1 3 1511 #define IEEE80211_RADIOTAP_RU_DATA_2_2_1 3 1512 #define IEEE80211_RADIOTAP_RU_DATA_1_2_2 3 1513 #define IEEE80211_RADIOTAP_RU_DATA_2_2_2 4 1514 1515 #define IWL_RX_RU_DATA_A1 2 1516 #define IWL_RX_RU_DATA_A2 2 1517 #define IWL_RX_RU_DATA_B1 2 1518 #define IWL_RX_RU_DATA_B2 3 1519 #define IWL_RX_RU_DATA_C1 3 1520 #define IWL_RX_RU_DATA_C2 3 1521 #define IWL_RX_RU_DATA_D1 4 1522 #define IWL_RX_RU_DATA_D2 4 1523 1524 #define IWL_MVM_ENC_EHT_RU(rt_ru, fw_ru) \ 1525 _IWL_MVM_ENC_EHT_RU(IEEE80211_RADIOTAP_RU_DATA_ ## rt_ru, \ 1526 rt_ru, \ 1527 IWL_RX_RU_DATA_ ## fw_ru, \ 1528 fw_ru) 1529 1530 static void iwl_mvm_decode_eht_ext_mu(struct iwl_mvm *mvm, 1531 struct iwl_mvm_rx_phy_data *phy_data, 1532 struct ieee80211_rx_status *rx_status, 1533 struct ieee80211_radiotap_eht *eht, 1534 struct ieee80211_radiotap_eht_usig *usig) 1535 { 1536 if (phy_data->with_data) { 1537 __le32 data1 = phy_data->d1; 1538 __le32 data2 = phy_data->d2; 1539 __le32 data3 = phy_data->d3; 1540 __le32 data4 = phy_data->eht_d4; 1541 __le32 data5 = phy_data->d5; 1542 u32 phy_bw = phy_data->rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK; 1543 1544 IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5, 1545 IWL_RX_PHY_DATA5_EHT_TYPE_AND_COMP, 1546 IEEE80211_RADIOTAP_EHT_USIG2_MU_B0_B1_PPDU_TYPE); 1547 IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5, 1548 IWL_RX_PHY_DATA5_EHT_MU_PUNC_CH_CODE, 1549 IEEE80211_RADIOTAP_EHT_USIG2_MU_B3_B7_PUNCTURED_INFO); 1550 IWL_MVM_ENC_USIG_VALUE_MASK(usig, data4, 1551 IWL_RX_PHY_DATA4_EHT_MU_EXT_SIGB_MCS, 1552 IEEE80211_RADIOTAP_EHT_USIG2_MU_B9_B10_SIG_MCS); 1553 IWL_MVM_ENC_USIG_VALUE_MASK 1554 (usig, data1, IWL_RX_PHY_DATA1_EHT_MU_NUM_SIG_SYM_USIGA2, 1555 IEEE80211_RADIOTAP_EHT_USIG2_MU_B11_B15_EHT_SIG_SYMBOLS); 1556 1557 eht->user_info[0] |= 1558 cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_STA_ID_KNOWN) | 1559 LE32_DEC_ENC(data5, IWL_RX_PHY_DATA5_EHT_MU_STA_ID_USR, 1560 IEEE80211_RADIOTAP_EHT_USER_INFO_STA_ID); 1561 1562 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_NR_NON_OFDMA_USERS_M); 1563 eht->data[7] |= LE32_DEC_ENC 1564 (data5, IWL_RX_PHY_DATA5_EHT_MU_NUM_USR_NON_OFDMA, 1565 IEEE80211_RADIOTAP_EHT_DATA7_NUM_OF_NON_OFDMA_USERS); 1566 1567 /* 1568 * Hardware labels the content channels/RU allocation values 1569 * as follows: 1570 * Content Channel 1 Content Channel 2 1571 * 20 MHz: A1 1572 * 40 MHz: A1 B1 1573 * 80 MHz: A1 C1 B1 D1 1574 * 160 MHz: A1 C1 A2 C2 B1 D1 B2 D2 1575 * 320 MHz: A1 C1 A2 C2 A3 C3 A4 C4 B1 D1 B2 D2 B3 D3 B4 D4 1576 * 1577 * However firmware can only give us A1-D2, so the higher 1578 * frequencies are missing. 1579 */ 1580 1581 switch (phy_bw) { 1582 case RATE_MCS_CHAN_WIDTH_320: 1583 /* additional values are missing in RX metadata */ 1584 case RATE_MCS_CHAN_WIDTH_160: 1585 /* content channel 1 */ 1586 IWL_MVM_ENC_EHT_RU(1_2_1, A2); 1587 IWL_MVM_ENC_EHT_RU(1_2_2, C2); 1588 /* content channel 2 */ 1589 IWL_MVM_ENC_EHT_RU(2_2_1, B2); 1590 IWL_MVM_ENC_EHT_RU(2_2_2, D2); 1591 fallthrough; 1592 case RATE_MCS_CHAN_WIDTH_80: 1593 /* content channel 1 */ 1594 IWL_MVM_ENC_EHT_RU(1_1_2, C1); 1595 /* content channel 2 */ 1596 IWL_MVM_ENC_EHT_RU(2_1_2, D1); 1597 fallthrough; 1598 case RATE_MCS_CHAN_WIDTH_40: 1599 /* content channel 2 */ 1600 IWL_MVM_ENC_EHT_RU(2_1_1, B1); 1601 fallthrough; 1602 case RATE_MCS_CHAN_WIDTH_20: 1603 IWL_MVM_ENC_EHT_RU(1_1_1, A1); 1604 break; 1605 } 1606 } else { 1607 __le32 usig_a1 = phy_data->rx_vec[0]; 1608 __le32 usig_a2 = phy_data->rx_vec[1]; 1609 1610 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a1, 1611 IWL_RX_USIG_A1_DISREGARD, 1612 IEEE80211_RADIOTAP_EHT_USIG1_MU_B20_B24_DISREGARD); 1613 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a1, 1614 IWL_RX_USIG_A1_VALIDATE, 1615 IEEE80211_RADIOTAP_EHT_USIG1_MU_B25_VALIDATE); 1616 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1617 IWL_RX_USIG_A2_EHT_PPDU_TYPE, 1618 IEEE80211_RADIOTAP_EHT_USIG2_MU_B0_B1_PPDU_TYPE); 1619 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1620 IWL_RX_USIG_A2_EHT_USIG2_VALIDATE_B2, 1621 IEEE80211_RADIOTAP_EHT_USIG2_MU_B2_VALIDATE); 1622 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1623 IWL_RX_USIG_A2_EHT_PUNC_CHANNEL, 1624 IEEE80211_RADIOTAP_EHT_USIG2_MU_B3_B7_PUNCTURED_INFO); 1625 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1626 IWL_RX_USIG_A2_EHT_USIG2_VALIDATE_B8, 1627 IEEE80211_RADIOTAP_EHT_USIG2_MU_B8_VALIDATE); 1628 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1629 IWL_RX_USIG_A2_EHT_SIG_MCS, 1630 IEEE80211_RADIOTAP_EHT_USIG2_MU_B9_B10_SIG_MCS); 1631 IWL_MVM_ENC_USIG_VALUE_MASK 1632 (usig, usig_a2, IWL_RX_USIG_A2_EHT_SIG_SYM_NUM, 1633 IEEE80211_RADIOTAP_EHT_USIG2_MU_B11_B15_EHT_SIG_SYMBOLS); 1634 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1635 IWL_RX_USIG_A2_EHT_CRC_OK, 1636 IEEE80211_RADIOTAP_EHT_USIG2_MU_B16_B19_CRC); 1637 } 1638 } 1639 1640 static void iwl_mvm_decode_eht_ext_tb(struct iwl_mvm *mvm, 1641 struct iwl_mvm_rx_phy_data *phy_data, 1642 struct ieee80211_rx_status *rx_status, 1643 struct ieee80211_radiotap_eht *eht, 1644 struct ieee80211_radiotap_eht_usig *usig) 1645 { 1646 if (phy_data->with_data) { 1647 __le32 data5 = phy_data->d5; 1648 1649 IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5, 1650 IWL_RX_PHY_DATA5_EHT_TYPE_AND_COMP, 1651 IEEE80211_RADIOTAP_EHT_USIG2_TB_B0_B1_PPDU_TYPE); 1652 IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5, 1653 IWL_RX_PHY_DATA5_EHT_TB_SPATIAL_REUSE1, 1654 IEEE80211_RADIOTAP_EHT_USIG2_TB_B3_B6_SPATIAL_REUSE_1); 1655 1656 IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5, 1657 IWL_RX_PHY_DATA5_EHT_TB_SPATIAL_REUSE2, 1658 IEEE80211_RADIOTAP_EHT_USIG2_TB_B7_B10_SPATIAL_REUSE_2); 1659 } else { 1660 __le32 usig_a1 = phy_data->rx_vec[0]; 1661 __le32 usig_a2 = phy_data->rx_vec[1]; 1662 1663 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a1, 1664 IWL_RX_USIG_A1_DISREGARD, 1665 IEEE80211_RADIOTAP_EHT_USIG1_TB_B20_B25_DISREGARD); 1666 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1667 IWL_RX_USIG_A2_EHT_PPDU_TYPE, 1668 IEEE80211_RADIOTAP_EHT_USIG2_TB_B0_B1_PPDU_TYPE); 1669 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1670 IWL_RX_USIG_A2_EHT_USIG2_VALIDATE_B2, 1671 IEEE80211_RADIOTAP_EHT_USIG2_TB_B2_VALIDATE); 1672 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1673 IWL_RX_USIG_A2_EHT_TRIG_SPATIAL_REUSE_1, 1674 IEEE80211_RADIOTAP_EHT_USIG2_TB_B3_B6_SPATIAL_REUSE_1); 1675 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1676 IWL_RX_USIG_A2_EHT_TRIG_SPATIAL_REUSE_2, 1677 IEEE80211_RADIOTAP_EHT_USIG2_TB_B7_B10_SPATIAL_REUSE_2); 1678 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1679 IWL_RX_USIG_A2_EHT_TRIG_USIG2_DISREGARD, 1680 IEEE80211_RADIOTAP_EHT_USIG2_TB_B11_B15_DISREGARD); 1681 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1682 IWL_RX_USIG_A2_EHT_CRC_OK, 1683 IEEE80211_RADIOTAP_EHT_USIG2_TB_B16_B19_CRC); 1684 } 1685 } 1686 1687 static void iwl_mvm_decode_eht_ru(struct iwl_mvm *mvm, 1688 struct ieee80211_rx_status *rx_status, 1689 struct ieee80211_radiotap_eht *eht) 1690 { 1691 u32 ru = le32_get_bits(eht->data[8], 1692 IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_B7_B1); 1693 enum nl80211_eht_ru_alloc nl_ru; 1694 1695 /* Using D1.5 Table 9-53a - Encoding of PS160 and RU Allocation subfields 1696 * in an EHT variant User Info field 1697 */ 1698 1699 switch (ru) { 1700 case 0 ... 36: 1701 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_26; 1702 break; 1703 case 37 ... 52: 1704 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_52; 1705 break; 1706 case 53 ... 60: 1707 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_106; 1708 break; 1709 case 61 ... 64: 1710 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_242; 1711 break; 1712 case 65 ... 66: 1713 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_484; 1714 break; 1715 case 67: 1716 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_996; 1717 break; 1718 case 68: 1719 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_2x996; 1720 break; 1721 case 69: 1722 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_4x996; 1723 break; 1724 case 70 ... 81: 1725 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_52P26; 1726 break; 1727 case 82 ... 89: 1728 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_106P26; 1729 break; 1730 case 90 ... 93: 1731 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_484P242; 1732 break; 1733 case 94 ... 95: 1734 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_996P484; 1735 break; 1736 case 96 ... 99: 1737 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_996P484P242; 1738 break; 1739 case 100 ... 103: 1740 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_2x996P484; 1741 break; 1742 case 104: 1743 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_3x996; 1744 break; 1745 case 105 ... 106: 1746 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_3x996P484; 1747 break; 1748 default: 1749 return; 1750 } 1751 1752 rx_status->bw = RATE_INFO_BW_EHT_RU; 1753 rx_status->eht.ru = nl_ru; 1754 } 1755 1756 static void iwl_mvm_decode_eht_phy_data(struct iwl_mvm *mvm, 1757 struct iwl_mvm_rx_phy_data *phy_data, 1758 struct ieee80211_rx_status *rx_status, 1759 struct ieee80211_radiotap_eht *eht, 1760 struct ieee80211_radiotap_eht_usig *usig) 1761 1762 { 1763 __le32 data0 = phy_data->d0; 1764 __le32 data1 = phy_data->d1; 1765 __le32 usig_a1 = phy_data->rx_vec[0]; 1766 u8 info_type = phy_data->info_type; 1767 1768 /* Not in EHT range */ 1769 if (info_type < IWL_RX_PHY_INFO_TYPE_EHT_MU || 1770 info_type > IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT) 1771 return; 1772 1773 usig->common |= cpu_to_le32 1774 (IEEE80211_RADIOTAP_EHT_USIG_COMMON_UL_DL_KNOWN | 1775 IEEE80211_RADIOTAP_EHT_USIG_COMMON_BSS_COLOR_KNOWN); 1776 if (phy_data->with_data) { 1777 usig->common |= LE32_DEC_ENC(data0, 1778 IWL_RX_PHY_DATA0_EHT_UPLINK, 1779 IEEE80211_RADIOTAP_EHT_USIG_COMMON_UL_DL); 1780 usig->common |= LE32_DEC_ENC(data0, 1781 IWL_RX_PHY_DATA0_EHT_BSS_COLOR_MASK, 1782 IEEE80211_RADIOTAP_EHT_USIG_COMMON_BSS_COLOR); 1783 } else { 1784 usig->common |= LE32_DEC_ENC(usig_a1, 1785 IWL_RX_USIG_A1_UL_FLAG, 1786 IEEE80211_RADIOTAP_EHT_USIG_COMMON_UL_DL); 1787 usig->common |= LE32_DEC_ENC(usig_a1, 1788 IWL_RX_USIG_A1_BSS_COLOR, 1789 IEEE80211_RADIOTAP_EHT_USIG_COMMON_BSS_COLOR); 1790 } 1791 1792 if (fw_has_capa(&mvm->fw->ucode_capa, 1793 IWL_UCODE_TLV_CAPA_SNIFF_VALIDATE_SUPPORT)) { 1794 usig->common |= 1795 cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_VALIDATE_BITS_CHECKED); 1796 usig->common |= 1797 LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_VALIDATE, 1798 IEEE80211_RADIOTAP_EHT_USIG_COMMON_VALIDATE_BITS_OK); 1799 } 1800 1801 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_SPATIAL_REUSE); 1802 eht->data[0] |= LE32_DEC_ENC(data0, 1803 IWL_RX_PHY_DATA0_ETH_SPATIAL_REUSE_MASK, 1804 IEEE80211_RADIOTAP_EHT_DATA0_SPATIAL_REUSE); 1805 1806 /* All RU allocating size/index is in TB format */ 1807 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_RU_ALLOC_TB_FMT); 1808 eht->data[8] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PS160, 1809 IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_PS_160); 1810 eht->data[8] |= LE32_DEC_ENC(data1, IWL_RX_PHY_DATA1_EHT_RU_ALLOC_B0, 1811 IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_B0); 1812 eht->data[8] |= LE32_DEC_ENC(data1, IWL_RX_PHY_DATA1_EHT_RU_ALLOC_B1_B7, 1813 IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_B7_B1); 1814 1815 iwl_mvm_decode_eht_ru(mvm, rx_status, eht); 1816 1817 /* We only get here in case of IWL_RX_MPDU_PHY_TSF_OVERLOAD is set 1818 * which is on only in case of monitor mode so no need to check monitor 1819 * mode 1820 */ 1821 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_PRIMARY_80); 1822 eht->data[1] |= 1823 le32_encode_bits(mvm->monitor_p80, 1824 IEEE80211_RADIOTAP_EHT_DATA1_PRIMARY_80); 1825 1826 usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_TXOP_KNOWN); 1827 if (phy_data->with_data) 1828 usig->common |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_TXOP_DUR_MASK, 1829 IEEE80211_RADIOTAP_EHT_USIG_COMMON_TXOP); 1830 else 1831 usig->common |= LE32_DEC_ENC(usig_a1, IWL_RX_USIG_A1_TXOP_DURATION, 1832 IEEE80211_RADIOTAP_EHT_USIG_COMMON_TXOP); 1833 1834 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_LDPC_EXTRA_SYM_OM); 1835 eht->data[0] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_LDPC_EXT_SYM, 1836 IEEE80211_RADIOTAP_EHT_DATA0_LDPC_EXTRA_SYM_OM); 1837 1838 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_PRE_PADD_FACOR_OM); 1839 eht->data[0] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PRE_FEC_PAD_MASK, 1840 IEEE80211_RADIOTAP_EHT_DATA0_PRE_PADD_FACOR_OM); 1841 1842 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_PE_DISAMBIGUITY_OM); 1843 eht->data[0] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PE_DISAMBIG, 1844 IEEE80211_RADIOTAP_EHT_DATA0_PE_DISAMBIGUITY_OM); 1845 1846 /* TODO: what about IWL_RX_PHY_DATA0_EHT_BW320_SLOT */ 1847 1848 if (!le32_get_bits(data0, IWL_RX_PHY_DATA0_EHT_SIGA_CRC_OK)) 1849 usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BAD_USIG_CRC); 1850 1851 usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_PHY_VER_KNOWN); 1852 usig->common |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PHY_VER, 1853 IEEE80211_RADIOTAP_EHT_USIG_COMMON_PHY_VER); 1854 1855 /* 1856 * TODO: what about TB - IWL_RX_PHY_DATA1_EHT_TB_PILOT_TYPE, 1857 * IWL_RX_PHY_DATA1_EHT_TB_LOW_SS 1858 */ 1859 1860 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_EHT_LTF); 1861 eht->data[0] |= LE32_DEC_ENC(data1, IWL_RX_PHY_DATA1_EHT_SIG_LTF_NUM, 1862 IEEE80211_RADIOTAP_EHT_DATA0_EHT_LTF); 1863 1864 if (info_type == IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT || 1865 info_type == IWL_RX_PHY_INFO_TYPE_EHT_TB) 1866 iwl_mvm_decode_eht_ext_tb(mvm, phy_data, rx_status, eht, usig); 1867 1868 if (info_type == IWL_RX_PHY_INFO_TYPE_EHT_MU_EXT || 1869 info_type == IWL_RX_PHY_INFO_TYPE_EHT_MU) 1870 iwl_mvm_decode_eht_ext_mu(mvm, phy_data, rx_status, eht, usig); 1871 } 1872 1873 static void iwl_mvm_rx_eht(struct iwl_mvm *mvm, struct sk_buff *skb, 1874 struct iwl_mvm_rx_phy_data *phy_data, 1875 int queue) 1876 { 1877 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 1878 1879 struct ieee80211_radiotap_eht *eht; 1880 struct ieee80211_radiotap_eht_usig *usig; 1881 size_t eht_len = sizeof(*eht); 1882 1883 u32 rate_n_flags = phy_data->rate_n_flags; 1884 u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK; 1885 /* EHT and HE have the same valus for LTF */ 1886 u8 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN; 1887 u16 phy_info = phy_data->phy_info; 1888 u32 bw; 1889 1890 /* u32 for 1 user_info */ 1891 if (phy_data->with_data) 1892 eht_len += sizeof(u32); 1893 1894 eht = iwl_mvm_radiotap_put_tlv(skb, IEEE80211_RADIOTAP_EHT, eht_len); 1895 1896 usig = iwl_mvm_radiotap_put_tlv(skb, IEEE80211_RADIOTAP_EHT_USIG, 1897 sizeof(*usig)); 1898 rx_status->flag |= RX_FLAG_RADIOTAP_TLV_AT_END; 1899 usig->common |= 1900 cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BW_KNOWN); 1901 1902 /* specific handling for 320MHz */ 1903 bw = FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK, rate_n_flags); 1904 if (bw == RATE_MCS_CHAN_WIDTH_320_VAL) 1905 bw += FIELD_GET(IWL_RX_PHY_DATA0_EHT_BW320_SLOT, 1906 le32_to_cpu(phy_data->d0)); 1907 1908 usig->common |= cpu_to_le32 1909 (FIELD_PREP(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BW, bw)); 1910 1911 /* report the AMPDU-EOF bit on single frames */ 1912 if (!queue && !(phy_info & IWL_RX_MPDU_PHY_AMPDU)) { 1913 rx_status->flag |= RX_FLAG_AMPDU_DETAILS; 1914 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN; 1915 if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_EHT_DELIM_EOF)) 1916 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT; 1917 } 1918 1919 /* update aggregation data for monitor sake on default queue */ 1920 if (!queue && (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) && 1921 (phy_info & IWL_RX_MPDU_PHY_AMPDU) && phy_data->first_subframe) { 1922 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN; 1923 if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_EHT_DELIM_EOF)) 1924 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT; 1925 } 1926 1927 if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) 1928 iwl_mvm_decode_eht_phy_data(mvm, phy_data, rx_status, eht, usig); 1929 1930 #define CHECK_TYPE(F) \ 1931 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_ ## F != \ 1932 (RATE_MCS_HE_TYPE_ ## F >> RATE_MCS_HE_TYPE_POS)) 1933 1934 CHECK_TYPE(SU); 1935 CHECK_TYPE(EXT_SU); 1936 CHECK_TYPE(MU); 1937 CHECK_TYPE(TRIG); 1938 1939 switch (FIELD_GET(RATE_MCS_HE_GI_LTF_MSK, rate_n_flags)) { 1940 case 0: 1941 if (he_type == RATE_MCS_HE_TYPE_TRIG) { 1942 rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_1_6; 1943 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X; 1944 } else { 1945 rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_0_8; 1946 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; 1947 } 1948 break; 1949 case 1: 1950 rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_1_6; 1951 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; 1952 break; 1953 case 2: 1954 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 1955 if (he_type == RATE_MCS_HE_TYPE_TRIG) 1956 rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_3_2; 1957 else 1958 rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_0_8; 1959 break; 1960 case 3: 1961 if (he_type != RATE_MCS_HE_TYPE_TRIG) { 1962 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 1963 rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_3_2; 1964 } 1965 break; 1966 default: 1967 /* nothing here */ 1968 break; 1969 } 1970 1971 if (ltf != IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN) { 1972 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_GI); 1973 eht->data[0] |= cpu_to_le32 1974 (FIELD_PREP(IEEE80211_RADIOTAP_EHT_DATA0_LTF, 1975 ltf) | 1976 FIELD_PREP(IEEE80211_RADIOTAP_EHT_DATA0_GI, 1977 rx_status->eht.gi)); 1978 } 1979 1980 1981 if (!phy_data->with_data) { 1982 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_NSS_S | 1983 IEEE80211_RADIOTAP_EHT_KNOWN_BEAMFORMED_S); 1984 eht->data[7] |= 1985 le32_encode_bits(le32_get_bits(phy_data->rx_vec[2], 1986 RX_NO_DATA_RX_VEC2_EHT_NSTS_MSK), 1987 IEEE80211_RADIOTAP_EHT_DATA7_NSS_S); 1988 if (rate_n_flags & RATE_MCS_BF_MSK) 1989 eht->data[7] |= 1990 cpu_to_le32(IEEE80211_RADIOTAP_EHT_DATA7_BEAMFORMED_S); 1991 } else { 1992 eht->user_info[0] |= 1993 cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_MCS_KNOWN | 1994 IEEE80211_RADIOTAP_EHT_USER_INFO_CODING_KNOWN | 1995 IEEE80211_RADIOTAP_EHT_USER_INFO_NSS_KNOWN_O | 1996 IEEE80211_RADIOTAP_EHT_USER_INFO_BEAMFORMING_KNOWN_O | 1997 IEEE80211_RADIOTAP_EHT_USER_INFO_DATA_FOR_USER); 1998 1999 if (rate_n_flags & RATE_MCS_BF_MSK) 2000 eht->user_info[0] |= 2001 cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_BEAMFORMING_O); 2002 2003 if (rate_n_flags & RATE_MCS_LDPC_MSK) 2004 eht->user_info[0] |= 2005 cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_CODING); 2006 2007 eht->user_info[0] |= cpu_to_le32 2008 (FIELD_PREP(IEEE80211_RADIOTAP_EHT_USER_INFO_MCS, 2009 FIELD_GET(RATE_VHT_MCS_RATE_CODE_MSK, 2010 rate_n_flags)) | 2011 FIELD_PREP(IEEE80211_RADIOTAP_EHT_USER_INFO_NSS_O, 2012 FIELD_GET(RATE_MCS_NSS_MSK, rate_n_flags))); 2013 } 2014 } 2015 2016 static void iwl_mvm_rx_he(struct iwl_mvm *mvm, struct sk_buff *skb, 2017 struct iwl_mvm_rx_phy_data *phy_data, 2018 int queue) 2019 { 2020 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 2021 struct ieee80211_radiotap_he *he = NULL; 2022 struct ieee80211_radiotap_he_mu *he_mu = NULL; 2023 u32 rate_n_flags = phy_data->rate_n_flags; 2024 u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK; 2025 u8 ltf; 2026 static const struct ieee80211_radiotap_he known = { 2027 .data1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_DATA_MCS_KNOWN | 2028 IEEE80211_RADIOTAP_HE_DATA1_DATA_DCM_KNOWN | 2029 IEEE80211_RADIOTAP_HE_DATA1_STBC_KNOWN | 2030 IEEE80211_RADIOTAP_HE_DATA1_CODING_KNOWN), 2031 .data2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_GI_KNOWN | 2032 IEEE80211_RADIOTAP_HE_DATA2_TXBF_KNOWN), 2033 }; 2034 static const struct ieee80211_radiotap_he_mu mu_known = { 2035 .flags1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS_KNOWN | 2036 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM_KNOWN | 2037 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_SYMS_USERS_KNOWN | 2038 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_COMP_KNOWN), 2039 .flags2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW_KNOWN | 2040 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_KNOWN), 2041 }; 2042 u16 phy_info = phy_data->phy_info; 2043 2044 he = skb_put_data(skb, &known, sizeof(known)); 2045 rx_status->flag |= RX_FLAG_RADIOTAP_HE; 2046 2047 if (phy_data->info_type == IWL_RX_PHY_INFO_TYPE_HE_MU || 2048 phy_data->info_type == IWL_RX_PHY_INFO_TYPE_HE_MU_EXT) { 2049 he_mu = skb_put_data(skb, &mu_known, sizeof(mu_known)); 2050 rx_status->flag |= RX_FLAG_RADIOTAP_HE_MU; 2051 } 2052 2053 /* report the AMPDU-EOF bit on single frames */ 2054 if (!queue && !(phy_info & IWL_RX_MPDU_PHY_AMPDU)) { 2055 rx_status->flag |= RX_FLAG_AMPDU_DETAILS; 2056 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN; 2057 if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_HE_DELIM_EOF)) 2058 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT; 2059 } 2060 2061 if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) 2062 iwl_mvm_decode_he_phy_data(mvm, phy_data, he, he_mu, rx_status, 2063 queue); 2064 2065 /* update aggregation data for monitor sake on default queue */ 2066 if (!queue && (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) && 2067 (phy_info & IWL_RX_MPDU_PHY_AMPDU) && phy_data->first_subframe) { 2068 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN; 2069 if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_EHT_DELIM_EOF)) 2070 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT; 2071 } 2072 2073 if (he_type == RATE_MCS_HE_TYPE_EXT_SU && 2074 rate_n_flags & RATE_MCS_HE_106T_MSK) { 2075 rx_status->bw = RATE_INFO_BW_HE_RU; 2076 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106; 2077 } 2078 2079 /* actually data is filled in mac80211 */ 2080 if (he_type == RATE_MCS_HE_TYPE_SU || 2081 he_type == RATE_MCS_HE_TYPE_EXT_SU) 2082 he->data1 |= 2083 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN); 2084 2085 #define CHECK_TYPE(F) \ 2086 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_ ## F != \ 2087 (RATE_MCS_HE_TYPE_ ## F >> RATE_MCS_HE_TYPE_POS)) 2088 2089 CHECK_TYPE(SU); 2090 CHECK_TYPE(EXT_SU); 2091 CHECK_TYPE(MU); 2092 CHECK_TYPE(TRIG); 2093 2094 he->data1 |= cpu_to_le16(he_type >> RATE_MCS_HE_TYPE_POS); 2095 2096 if (rate_n_flags & RATE_MCS_BF_MSK) 2097 he->data5 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA5_TXBF); 2098 2099 switch ((rate_n_flags & RATE_MCS_HE_GI_LTF_MSK) >> 2100 RATE_MCS_HE_GI_LTF_POS) { 2101 case 0: 2102 if (he_type == RATE_MCS_HE_TYPE_TRIG) 2103 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 2104 else 2105 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 2106 if (he_type == RATE_MCS_HE_TYPE_MU) 2107 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 2108 else 2109 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X; 2110 break; 2111 case 1: 2112 if (he_type == RATE_MCS_HE_TYPE_TRIG) 2113 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 2114 else 2115 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 2116 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; 2117 break; 2118 case 2: 2119 if (he_type == RATE_MCS_HE_TYPE_TRIG) { 2120 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 2121 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 2122 } else { 2123 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 2124 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; 2125 } 2126 break; 2127 case 3: 2128 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 2129 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 2130 break; 2131 case 4: 2132 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 2133 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 2134 break; 2135 default: 2136 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN; 2137 } 2138 2139 he->data5 |= le16_encode_bits(ltf, 2140 IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE); 2141 } 2142 2143 static void iwl_mvm_decode_lsig(struct sk_buff *skb, 2144 struct iwl_mvm_rx_phy_data *phy_data) 2145 { 2146 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 2147 struct ieee80211_radiotap_lsig *lsig; 2148 2149 switch (phy_data->info_type) { 2150 case IWL_RX_PHY_INFO_TYPE_HT: 2151 case IWL_RX_PHY_INFO_TYPE_VHT_SU: 2152 case IWL_RX_PHY_INFO_TYPE_VHT_MU: 2153 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT: 2154 case IWL_RX_PHY_INFO_TYPE_HE_SU: 2155 case IWL_RX_PHY_INFO_TYPE_HE_MU: 2156 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT: 2157 case IWL_RX_PHY_INFO_TYPE_HE_TB: 2158 case IWL_RX_PHY_INFO_TYPE_EHT_MU: 2159 case IWL_RX_PHY_INFO_TYPE_EHT_TB: 2160 case IWL_RX_PHY_INFO_TYPE_EHT_MU_EXT: 2161 case IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT: 2162 lsig = skb_put(skb, sizeof(*lsig)); 2163 lsig->data1 = cpu_to_le16(IEEE80211_RADIOTAP_LSIG_DATA1_LENGTH_KNOWN); 2164 lsig->data2 = le16_encode_bits(le32_get_bits(phy_data->d1, 2165 IWL_RX_PHY_DATA1_LSIG_LEN_MASK), 2166 IEEE80211_RADIOTAP_LSIG_DATA2_LENGTH); 2167 rx_status->flag |= RX_FLAG_RADIOTAP_LSIG; 2168 break; 2169 default: 2170 break; 2171 } 2172 } 2173 2174 static inline u8 iwl_mvm_nl80211_band_from_rx_msdu(u8 phy_band) 2175 { 2176 switch (phy_band) { 2177 case PHY_BAND_24: 2178 return NL80211_BAND_2GHZ; 2179 case PHY_BAND_5: 2180 return NL80211_BAND_5GHZ; 2181 case PHY_BAND_6: 2182 return NL80211_BAND_6GHZ; 2183 default: 2184 WARN_ONCE(1, "Unsupported phy band (%u)\n", phy_band); 2185 return NL80211_BAND_5GHZ; 2186 } 2187 } 2188 2189 struct iwl_rx_sta_csa { 2190 bool all_sta_unblocked; 2191 struct ieee80211_vif *vif; 2192 }; 2193 2194 static void iwl_mvm_rx_get_sta_block_tx(void *data, struct ieee80211_sta *sta) 2195 { 2196 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 2197 struct iwl_rx_sta_csa *rx_sta_csa = data; 2198 2199 if (mvmsta->vif != rx_sta_csa->vif) 2200 return; 2201 2202 if (mvmsta->disable_tx) 2203 rx_sta_csa->all_sta_unblocked = false; 2204 } 2205 2206 /* 2207 * Note: requires also rx_status->band to be prefilled, as well 2208 * as phy_data (apart from phy_data->info_type) 2209 */ 2210 static void iwl_mvm_rx_fill_status(struct iwl_mvm *mvm, 2211 struct sk_buff *skb, 2212 struct iwl_mvm_rx_phy_data *phy_data, 2213 int queue) 2214 { 2215 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 2216 u32 rate_n_flags = phy_data->rate_n_flags; 2217 u8 stbc = u32_get_bits(rate_n_flags, RATE_MCS_STBC_MSK); 2218 u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK; 2219 bool is_sgi; 2220 2221 phy_data->info_type = IWL_RX_PHY_INFO_TYPE_NONE; 2222 2223 if (phy_data->phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) 2224 phy_data->info_type = 2225 le32_get_bits(phy_data->d1, 2226 IWL_RX_PHY_DATA1_INFO_TYPE_MASK); 2227 2228 /* This may be overridden by iwl_mvm_rx_he() to HE_RU */ 2229 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { 2230 case RATE_MCS_CHAN_WIDTH_20: 2231 break; 2232 case RATE_MCS_CHAN_WIDTH_40: 2233 rx_status->bw = RATE_INFO_BW_40; 2234 break; 2235 case RATE_MCS_CHAN_WIDTH_80: 2236 rx_status->bw = RATE_INFO_BW_80; 2237 break; 2238 case RATE_MCS_CHAN_WIDTH_160: 2239 rx_status->bw = RATE_INFO_BW_160; 2240 break; 2241 case RATE_MCS_CHAN_WIDTH_320: 2242 rx_status->bw = RATE_INFO_BW_320; 2243 break; 2244 } 2245 2246 /* must be before L-SIG data */ 2247 if (format == RATE_MCS_HE_MSK) 2248 iwl_mvm_rx_he(mvm, skb, phy_data, queue); 2249 2250 iwl_mvm_decode_lsig(skb, phy_data); 2251 2252 rx_status->device_timestamp = phy_data->gp2_on_air_rise; 2253 rx_status->freq = ieee80211_channel_to_frequency(phy_data->channel, 2254 rx_status->band); 2255 iwl_mvm_get_signal_strength(mvm, rx_status, rate_n_flags, 2256 phy_data->energy_a, phy_data->energy_b); 2257 2258 /* using TLV format and must be after all fixed len fields */ 2259 if (format == RATE_MCS_EHT_MSK) 2260 iwl_mvm_rx_eht(mvm, skb, phy_data, queue); 2261 2262 if (unlikely(mvm->monitor_on)) 2263 iwl_mvm_add_rtap_sniffer_config(mvm, skb); 2264 2265 is_sgi = format == RATE_MCS_HE_MSK ? 2266 iwl_he_is_sgi(rate_n_flags) : 2267 rate_n_flags & RATE_MCS_SGI_MSK; 2268 2269 if (!(format == RATE_MCS_CCK_MSK) && is_sgi) 2270 rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI; 2271 2272 if (rate_n_flags & RATE_MCS_LDPC_MSK) 2273 rx_status->enc_flags |= RX_ENC_FLAG_LDPC; 2274 2275 switch (format) { 2276 case RATE_MCS_VHT_MSK: 2277 rx_status->encoding = RX_ENC_VHT; 2278 break; 2279 case RATE_MCS_HE_MSK: 2280 rx_status->encoding = RX_ENC_HE; 2281 rx_status->he_dcm = 2282 !!(rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK); 2283 break; 2284 case RATE_MCS_EHT_MSK: 2285 rx_status->encoding = RX_ENC_EHT; 2286 break; 2287 } 2288 2289 switch (format) { 2290 case RATE_MCS_HT_MSK: 2291 rx_status->encoding = RX_ENC_HT; 2292 rx_status->rate_idx = RATE_HT_MCS_INDEX(rate_n_flags); 2293 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT; 2294 break; 2295 case RATE_MCS_VHT_MSK: 2296 case RATE_MCS_HE_MSK: 2297 case RATE_MCS_EHT_MSK: 2298 rx_status->nss = 2299 u32_get_bits(rate_n_flags, RATE_MCS_NSS_MSK) + 1; 2300 rx_status->rate_idx = rate_n_flags & RATE_MCS_CODE_MSK; 2301 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT; 2302 break; 2303 default: { 2304 int rate = iwl_mvm_legacy_hw_idx_to_mac80211_idx(rate_n_flags, 2305 rx_status->band); 2306 2307 rx_status->rate_idx = rate; 2308 2309 if ((rate < 0 || rate > 0xFF)) { 2310 rx_status->rate_idx = 0; 2311 if (net_ratelimit()) 2312 IWL_ERR(mvm, "Invalid rate flags 0x%x, band %d,\n", 2313 rate_n_flags, rx_status->band); 2314 } 2315 2316 break; 2317 } 2318 } 2319 } 2320 2321 void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi, 2322 struct iwl_rx_cmd_buffer *rxb, int queue) 2323 { 2324 struct ieee80211_rx_status *rx_status; 2325 struct iwl_rx_packet *pkt = rxb_addr(rxb); 2326 struct iwl_rx_mpdu_desc *desc = (void *)pkt->data; 2327 struct ieee80211_hdr *hdr; 2328 u32 len; 2329 u32 pkt_len = iwl_rx_packet_payload_len(pkt); 2330 struct ieee80211_sta *sta = NULL; 2331 struct ieee80211_link_sta *link_sta = NULL; 2332 struct sk_buff *skb; 2333 u8 crypt_len = 0; 2334 size_t desc_size; 2335 struct iwl_mvm_rx_phy_data phy_data = {}; 2336 u32 format; 2337 2338 if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))) 2339 return; 2340 2341 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) 2342 desc_size = sizeof(*desc); 2343 else 2344 desc_size = IWL_RX_DESC_SIZE_V1; 2345 2346 if (unlikely(pkt_len < desc_size)) { 2347 IWL_DEBUG_DROP(mvm, "Bad REPLY_RX_MPDU_CMD size\n"); 2348 return; 2349 } 2350 2351 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) { 2352 phy_data.rate_n_flags = le32_to_cpu(desc->v3.rate_n_flags); 2353 phy_data.channel = desc->v3.channel; 2354 phy_data.gp2_on_air_rise = le32_to_cpu(desc->v3.gp2_on_air_rise); 2355 phy_data.energy_a = desc->v3.energy_a; 2356 phy_data.energy_b = desc->v3.energy_b; 2357 2358 phy_data.d0 = desc->v3.phy_data0; 2359 phy_data.d1 = desc->v3.phy_data1; 2360 phy_data.d2 = desc->v3.phy_data2; 2361 phy_data.d3 = desc->v3.phy_data3; 2362 phy_data.eht_d4 = desc->phy_eht_data4; 2363 phy_data.d5 = desc->v3.phy_data5; 2364 } else { 2365 phy_data.rate_n_flags = le32_to_cpu(desc->v1.rate_n_flags); 2366 phy_data.channel = desc->v1.channel; 2367 phy_data.gp2_on_air_rise = le32_to_cpu(desc->v1.gp2_on_air_rise); 2368 phy_data.energy_a = desc->v1.energy_a; 2369 phy_data.energy_b = desc->v1.energy_b; 2370 2371 phy_data.d0 = desc->v1.phy_data0; 2372 phy_data.d1 = desc->v1.phy_data1; 2373 phy_data.d2 = desc->v1.phy_data2; 2374 phy_data.d3 = desc->v1.phy_data3; 2375 } 2376 2377 if (iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP, 2378 REPLY_RX_MPDU_CMD, 0) < 4) { 2379 phy_data.rate_n_flags = iwl_new_rate_from_v1(phy_data.rate_n_flags); 2380 IWL_DEBUG_DROP(mvm, "Got old format rate, converting. New rate: 0x%x\n", 2381 phy_data.rate_n_flags); 2382 } 2383 2384 format = phy_data.rate_n_flags & RATE_MCS_MOD_TYPE_MSK; 2385 2386 len = le16_to_cpu(desc->mpdu_len); 2387 2388 if (unlikely(len + desc_size > pkt_len)) { 2389 IWL_DEBUG_DROP(mvm, "FW lied about packet len\n"); 2390 return; 2391 } 2392 2393 phy_data.with_data = true; 2394 phy_data.phy_info = le16_to_cpu(desc->phy_info); 2395 phy_data.d4 = desc->phy_data4; 2396 2397 hdr = (void *)(pkt->data + desc_size); 2398 /* Dont use dev_alloc_skb(), we'll have enough headroom once 2399 * ieee80211_hdr pulled. 2400 */ 2401 skb = alloc_skb(128, GFP_ATOMIC); 2402 if (!skb) { 2403 IWL_ERR(mvm, "alloc_skb failed\n"); 2404 return; 2405 } 2406 2407 if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) { 2408 /* 2409 * If the device inserted padding it means that (it thought) 2410 * the 802.11 header wasn't a multiple of 4 bytes long. In 2411 * this case, reserve two bytes at the start of the SKB to 2412 * align the payload properly in case we end up copying it. 2413 */ 2414 skb_reserve(skb, 2); 2415 } 2416 2417 rx_status = IEEE80211_SKB_RXCB(skb); 2418 2419 /* 2420 * Keep packets with CRC errors (and with overrun) for monitor mode 2421 * (otherwise the firmware discards them) but mark them as bad. 2422 */ 2423 if (!(desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_CRC_OK)) || 2424 !(desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_OVERRUN_OK))) { 2425 IWL_DEBUG_RX(mvm, "Bad CRC or FIFO: 0x%08X.\n", 2426 le32_to_cpu(desc->status)); 2427 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; 2428 } 2429 2430 /* set the preamble flag if appropriate */ 2431 if (format == RATE_MCS_CCK_MSK && 2432 phy_data.phy_info & IWL_RX_MPDU_PHY_SHORT_PREAMBLE) 2433 rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE; 2434 2435 if (likely(!(phy_data.phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD))) { 2436 u64 tsf_on_air_rise; 2437 2438 if (mvm->trans->trans_cfg->device_family >= 2439 IWL_DEVICE_FAMILY_AX210) 2440 tsf_on_air_rise = le64_to_cpu(desc->v3.tsf_on_air_rise); 2441 else 2442 tsf_on_air_rise = le64_to_cpu(desc->v1.tsf_on_air_rise); 2443 2444 rx_status->mactime = tsf_on_air_rise; 2445 /* TSF as indicated by the firmware is at INA time */ 2446 rx_status->flag |= RX_FLAG_MACTIME_PLCP_START; 2447 } 2448 2449 if (iwl_mvm_is_band_in_rx_supported(mvm)) { 2450 u8 band = BAND_IN_RX_STATUS(desc->mac_phy_idx); 2451 2452 rx_status->band = iwl_mvm_nl80211_band_from_rx_msdu(band); 2453 } else { 2454 rx_status->band = phy_data.channel > 14 ? NL80211_BAND_5GHZ : 2455 NL80211_BAND_2GHZ; 2456 } 2457 2458 /* update aggregation data for monitor sake on default queue */ 2459 if (!queue && (phy_data.phy_info & IWL_RX_MPDU_PHY_AMPDU)) { 2460 bool toggle_bit; 2461 2462 toggle_bit = phy_data.phy_info & IWL_RX_MPDU_PHY_AMPDU_TOGGLE; 2463 rx_status->flag |= RX_FLAG_AMPDU_DETAILS; 2464 /* 2465 * Toggle is switched whenever new aggregation starts. Make 2466 * sure ampdu_reference is never 0 so we can later use it to 2467 * see if the frame was really part of an A-MPDU or not. 2468 */ 2469 if (toggle_bit != mvm->ampdu_toggle) { 2470 mvm->ampdu_ref++; 2471 if (mvm->ampdu_ref == 0) 2472 mvm->ampdu_ref++; 2473 mvm->ampdu_toggle = toggle_bit; 2474 phy_data.first_subframe = true; 2475 } 2476 rx_status->ampdu_reference = mvm->ampdu_ref; 2477 } 2478 2479 rcu_read_lock(); 2480 2481 if (desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_SRC_STA_FOUND)) { 2482 u8 id = le32_get_bits(desc->status, IWL_RX_MPDU_STATUS_STA_ID); 2483 2484 if (!WARN_ON_ONCE(id >= mvm->fw->ucode_capa.num_stations)) { 2485 sta = rcu_dereference(mvm->fw_id_to_mac_id[id]); 2486 if (IS_ERR(sta)) 2487 sta = NULL; 2488 link_sta = rcu_dereference(mvm->fw_id_to_link_sta[id]); 2489 } 2490 } else if (!is_multicast_ether_addr(hdr->addr2)) { 2491 /* 2492 * This is fine since we prevent two stations with the same 2493 * address from being added. 2494 */ 2495 sta = ieee80211_find_sta_by_ifaddr(mvm->hw, hdr->addr2, NULL); 2496 } 2497 2498 if (iwl_mvm_rx_crypto(mvm, sta, hdr, rx_status, phy_data.phy_info, desc, 2499 le32_to_cpu(pkt->len_n_flags), queue, 2500 &crypt_len)) { 2501 kfree_skb(skb); 2502 goto out; 2503 } 2504 2505 iwl_mvm_rx_fill_status(mvm, skb, &phy_data, queue); 2506 2507 if (sta) { 2508 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 2509 struct ieee80211_vif *tx_blocked_vif = 2510 rcu_dereference(mvm->csa_tx_blocked_vif); 2511 u8 baid = (u8)((le32_to_cpu(desc->reorder_data) & 2512 IWL_RX_MPDU_REORDER_BAID_MASK) >> 2513 IWL_RX_MPDU_REORDER_BAID_SHIFT); 2514 struct iwl_fw_dbg_trigger_tlv *trig; 2515 struct ieee80211_vif *vif = mvmsta->vif; 2516 2517 if (!mvm->tcm.paused && len >= sizeof(*hdr) && 2518 !is_multicast_ether_addr(hdr->addr1) && 2519 ieee80211_is_data(hdr->frame_control) && 2520 time_after(jiffies, mvm->tcm.ts + MVM_TCM_PERIOD)) 2521 schedule_delayed_work(&mvm->tcm.work, 0); 2522 2523 /* 2524 * We have tx blocked stations (with CS bit). If we heard 2525 * frames from a blocked station on a new channel we can 2526 * TX to it again. 2527 */ 2528 if (unlikely(tx_blocked_vif) && tx_blocked_vif == vif) { 2529 struct iwl_mvm_vif *mvmvif = 2530 iwl_mvm_vif_from_mac80211(tx_blocked_vif); 2531 struct iwl_rx_sta_csa rx_sta_csa = { 2532 .all_sta_unblocked = true, 2533 .vif = tx_blocked_vif, 2534 }; 2535 2536 if (mvmvif->csa_target_freq == rx_status->freq) 2537 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, 2538 false); 2539 ieee80211_iterate_stations_atomic(mvm->hw, 2540 iwl_mvm_rx_get_sta_block_tx, 2541 &rx_sta_csa); 2542 2543 if (rx_sta_csa.all_sta_unblocked) { 2544 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); 2545 /* Unblock BCAST / MCAST station */ 2546 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false); 2547 cancel_delayed_work(&mvm->cs_tx_unblock_dwork); 2548 } 2549 } 2550 2551 rs_update_last_rssi(mvm, mvmsta, rx_status); 2552 2553 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, 2554 ieee80211_vif_to_wdev(vif), 2555 FW_DBG_TRIGGER_RSSI); 2556 2557 if (trig && ieee80211_is_beacon(hdr->frame_control)) { 2558 struct iwl_fw_dbg_trigger_low_rssi *rssi_trig; 2559 s32 rssi; 2560 2561 rssi_trig = (void *)trig->data; 2562 rssi = le32_to_cpu(rssi_trig->rssi); 2563 2564 if (rx_status->signal < rssi) 2565 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 2566 NULL); 2567 } 2568 2569 if (ieee80211_is_data(hdr->frame_control)) 2570 iwl_mvm_rx_csum(mvm, sta, skb, pkt); 2571 2572 if (iwl_mvm_is_dup(sta, queue, rx_status, hdr, desc)) { 2573 kfree_skb(skb); 2574 goto out; 2575 } 2576 2577 /* 2578 * Our hardware de-aggregates AMSDUs but copies the mac header 2579 * as it to the de-aggregated MPDUs. We need to turn off the 2580 * AMSDU bit in the QoS control ourselves. 2581 * In addition, HW reverses addr3 and addr4 - reverse it back. 2582 */ 2583 if ((desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU) && 2584 !WARN_ON(!ieee80211_is_data_qos(hdr->frame_control))) { 2585 u8 *qc = ieee80211_get_qos_ctl(hdr); 2586 2587 *qc &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT; 2588 2589 if (mvm->trans->trans_cfg->device_family == 2590 IWL_DEVICE_FAMILY_9000) { 2591 iwl_mvm_flip_address(hdr->addr3); 2592 2593 if (ieee80211_has_a4(hdr->frame_control)) 2594 iwl_mvm_flip_address(hdr->addr4); 2595 } 2596 } 2597 if (baid != IWL_RX_REORDER_DATA_INVALID_BAID) { 2598 u32 reorder_data = le32_to_cpu(desc->reorder_data); 2599 2600 iwl_mvm_agg_rx_received(mvm, reorder_data, baid); 2601 } 2602 } 2603 2604 /* management stuff on default queue */ 2605 if (!queue) { 2606 if (unlikely((ieee80211_is_beacon(hdr->frame_control) || 2607 ieee80211_is_probe_resp(hdr->frame_control)) && 2608 mvm->sched_scan_pass_all == 2609 SCHED_SCAN_PASS_ALL_ENABLED)) 2610 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_FOUND; 2611 2612 if (unlikely(ieee80211_is_beacon(hdr->frame_control) || 2613 ieee80211_is_probe_resp(hdr->frame_control))) 2614 rx_status->boottime_ns = ktime_get_boottime_ns(); 2615 } 2616 2617 if (iwl_mvm_create_skb(mvm, skb, hdr, len, crypt_len, rxb)) { 2618 kfree_skb(skb); 2619 goto out; 2620 } 2621 2622 if (!iwl_mvm_reorder(mvm, napi, queue, sta, skb, desc) && 2623 likely(!iwl_mvm_time_sync_frame(mvm, skb, hdr->addr2)) && 2624 likely(!iwl_mvm_mei_filter_scan(mvm, skb))) 2625 iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb, queue, sta, 2626 link_sta); 2627 out: 2628 rcu_read_unlock(); 2629 } 2630 2631 void iwl_mvm_rx_monitor_no_data(struct iwl_mvm *mvm, struct napi_struct *napi, 2632 struct iwl_rx_cmd_buffer *rxb, int queue) 2633 { 2634 struct ieee80211_rx_status *rx_status; 2635 struct iwl_rx_packet *pkt = rxb_addr(rxb); 2636 struct iwl_rx_no_data_ver_3 *desc = (void *)pkt->data; 2637 u32 rssi; 2638 u32 info_type; 2639 struct ieee80211_sta *sta = NULL; 2640 struct sk_buff *skb; 2641 struct iwl_mvm_rx_phy_data phy_data; 2642 u32 format; 2643 2644 if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))) 2645 return; 2646 2647 if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(struct iwl_rx_no_data))) 2648 return; 2649 2650 rssi = le32_to_cpu(desc->rssi); 2651 info_type = le32_to_cpu(desc->info) & RX_NO_DATA_INFO_TYPE_MSK; 2652 phy_data.d0 = desc->phy_info[0]; 2653 phy_data.d1 = desc->phy_info[1]; 2654 phy_data.phy_info = IWL_RX_MPDU_PHY_TSF_OVERLOAD; 2655 phy_data.gp2_on_air_rise = le32_to_cpu(desc->on_air_rise_time); 2656 phy_data.rate_n_flags = le32_to_cpu(desc->rate); 2657 phy_data.energy_a = u32_get_bits(rssi, RX_NO_DATA_CHAIN_A_MSK); 2658 phy_data.energy_b = u32_get_bits(rssi, RX_NO_DATA_CHAIN_B_MSK); 2659 phy_data.channel = u32_get_bits(rssi, RX_NO_DATA_CHANNEL_MSK); 2660 phy_data.with_data = false; 2661 phy_data.rx_vec[0] = desc->rx_vec[0]; 2662 phy_data.rx_vec[1] = desc->rx_vec[1]; 2663 2664 if (iwl_fw_lookup_notif_ver(mvm->fw, DATA_PATH_GROUP, 2665 RX_NO_DATA_NOTIF, 0) < 2) { 2666 IWL_DEBUG_DROP(mvm, "Got an old rate format. Old rate: 0x%x\n", 2667 phy_data.rate_n_flags); 2668 phy_data.rate_n_flags = iwl_new_rate_from_v1(phy_data.rate_n_flags); 2669 IWL_DEBUG_DROP(mvm, " Rate after conversion to the new format: 0x%x\n", 2670 phy_data.rate_n_flags); 2671 } 2672 2673 format = phy_data.rate_n_flags & RATE_MCS_MOD_TYPE_MSK; 2674 2675 if (iwl_fw_lookup_notif_ver(mvm->fw, DATA_PATH_GROUP, 2676 RX_NO_DATA_NOTIF, 0) >= 3) { 2677 if (unlikely(iwl_rx_packet_payload_len(pkt) < 2678 sizeof(struct iwl_rx_no_data_ver_3))) 2679 /* invalid len for ver 3 */ 2680 return; 2681 phy_data.rx_vec[2] = desc->rx_vec[2]; 2682 phy_data.rx_vec[3] = desc->rx_vec[3]; 2683 } else { 2684 if (format == RATE_MCS_EHT_MSK) 2685 /* no support for EHT before version 3 API */ 2686 return; 2687 } 2688 2689 /* Dont use dev_alloc_skb(), we'll have enough headroom once 2690 * ieee80211_hdr pulled. 2691 */ 2692 skb = alloc_skb(128, GFP_ATOMIC); 2693 if (!skb) { 2694 IWL_ERR(mvm, "alloc_skb failed\n"); 2695 return; 2696 } 2697 2698 rx_status = IEEE80211_SKB_RXCB(skb); 2699 2700 /* 0-length PSDU */ 2701 rx_status->flag |= RX_FLAG_NO_PSDU; 2702 2703 switch (info_type) { 2704 case RX_NO_DATA_INFO_TYPE_NDP: 2705 rx_status->zero_length_psdu_type = 2706 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_SOUNDING; 2707 break; 2708 case RX_NO_DATA_INFO_TYPE_MU_UNMATCHED: 2709 case RX_NO_DATA_INFO_TYPE_TB_UNMATCHED: 2710 rx_status->zero_length_psdu_type = 2711 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_NOT_CAPTURED; 2712 break; 2713 default: 2714 rx_status->zero_length_psdu_type = 2715 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_VENDOR; 2716 break; 2717 } 2718 2719 rx_status->band = phy_data.channel > 14 ? NL80211_BAND_5GHZ : 2720 NL80211_BAND_2GHZ; 2721 2722 iwl_mvm_rx_fill_status(mvm, skb, &phy_data, queue); 2723 2724 /* no more radio tap info should be put after this point. 2725 * 2726 * We mark it as mac header, for upper layers to know where 2727 * all radio tap header ends. 2728 */ 2729 skb_reset_mac_header(skb); 2730 2731 /* 2732 * Override the nss from the rx_vec since the rate_n_flags has 2733 * only 2 bits for the nss which gives a max of 4 ss but there 2734 * may be up to 8 spatial streams. 2735 */ 2736 switch (format) { 2737 case RATE_MCS_VHT_MSK: 2738 rx_status->nss = 2739 le32_get_bits(desc->rx_vec[0], 2740 RX_NO_DATA_RX_VEC0_VHT_NSTS_MSK) + 1; 2741 break; 2742 case RATE_MCS_HE_MSK: 2743 rx_status->nss = 2744 le32_get_bits(desc->rx_vec[0], 2745 RX_NO_DATA_RX_VEC0_HE_NSTS_MSK) + 1; 2746 break; 2747 case RATE_MCS_EHT_MSK: 2748 rx_status->nss = 2749 le32_get_bits(desc->rx_vec[2], 2750 RX_NO_DATA_RX_VEC2_EHT_NSTS_MSK) + 1; 2751 } 2752 2753 rcu_read_lock(); 2754 ieee80211_rx_napi(mvm->hw, sta, skb, napi); 2755 rcu_read_unlock(); 2756 } 2757 2758 void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi, 2759 struct iwl_rx_cmd_buffer *rxb, int queue) 2760 { 2761 struct iwl_rx_packet *pkt = rxb_addr(rxb); 2762 struct iwl_frame_release *release = (void *)pkt->data; 2763 2764 if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(*release))) 2765 return; 2766 2767 iwl_mvm_release_frames_from_notif(mvm, napi, release->baid, 2768 le16_to_cpu(release->nssn), 2769 queue, 0); 2770 } 2771 2772 void iwl_mvm_rx_bar_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi, 2773 struct iwl_rx_cmd_buffer *rxb, int queue) 2774 { 2775 struct iwl_rx_packet *pkt = rxb_addr(rxb); 2776 struct iwl_bar_frame_release *release = (void *)pkt->data; 2777 unsigned int baid = le32_get_bits(release->ba_info, 2778 IWL_BAR_FRAME_RELEASE_BAID_MASK); 2779 unsigned int nssn = le32_get_bits(release->ba_info, 2780 IWL_BAR_FRAME_RELEASE_NSSN_MASK); 2781 unsigned int sta_id = le32_get_bits(release->sta_tid, 2782 IWL_BAR_FRAME_RELEASE_STA_MASK); 2783 unsigned int tid = le32_get_bits(release->sta_tid, 2784 IWL_BAR_FRAME_RELEASE_TID_MASK); 2785 struct iwl_mvm_baid_data *baid_data; 2786 2787 if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(*release))) 2788 return; 2789 2790 if (WARN_ON_ONCE(baid == IWL_RX_REORDER_DATA_INVALID_BAID || 2791 baid >= ARRAY_SIZE(mvm->baid_map))) 2792 return; 2793 2794 rcu_read_lock(); 2795 baid_data = rcu_dereference(mvm->baid_map[baid]); 2796 if (!baid_data) { 2797 IWL_DEBUG_RX(mvm, 2798 "Got valid BAID %d but not allocated, invalid BAR release!\n", 2799 baid); 2800 goto out; 2801 } 2802 2803 if (WARN(tid != baid_data->tid || sta_id > IWL_MVM_STATION_COUNT_MAX || 2804 !(baid_data->sta_mask & BIT(sta_id)), 2805 "baid 0x%x is mapped to sta_mask:0x%x tid:%d, but BAR release received for sta:%d tid:%d\n", 2806 baid, baid_data->sta_mask, baid_data->tid, sta_id, 2807 tid)) 2808 goto out; 2809 2810 iwl_mvm_release_frames_from_notif(mvm, napi, baid, nssn, queue, 0); 2811 out: 2812 rcu_read_unlock(); 2813 } 2814