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