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 sta_mask = iwl_mvm_sta_fw_id_mask(mvm, sta, -1); 777 778 if (IWL_FW_CHECK(mvm, 779 tid != baid_data->tid || 780 !(sta_mask & baid_data->sta_mask), 781 "baid 0x%x is mapped to sta_mask:0x%x tid:%d, but was received for sta_mask:0x%x tid:%d\n", 782 baid, baid_data->sta_mask, baid_data->tid, 783 sta_mask, tid)) 784 return false; 785 786 nssn = reorder & IWL_RX_MPDU_REORDER_NSSN_MASK; 787 sn = (reorder & IWL_RX_MPDU_REORDER_SN_MASK) >> 788 IWL_RX_MPDU_REORDER_SN_SHIFT; 789 790 buffer = &baid_data->reorder_buf[queue]; 791 entries = &baid_data->entries[queue * baid_data->entries_per_queue]; 792 793 spin_lock_bh(&buffer->lock); 794 795 if (!buffer->valid) { 796 if (reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN) { 797 spin_unlock_bh(&buffer->lock); 798 return false; 799 } 800 buffer->valid = true; 801 } 802 803 /* drop any duplicated packets */ 804 if (desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_DUPLICATE)) 805 goto drop; 806 807 /* drop any oudated packets */ 808 if (reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN) 809 goto drop; 810 811 /* release immediately if allowed by nssn and no stored frames */ 812 if (!buffer->num_stored && ieee80211_sn_less(sn, nssn)) { 813 if (!amsdu || last_subframe) 814 buffer->head_sn = nssn; 815 816 spin_unlock_bh(&buffer->lock); 817 return false; 818 } 819 820 /* 821 * release immediately if there are no stored frames, and the sn is 822 * equal to the head. 823 * This can happen due to reorder timer, where NSSN is behind head_sn. 824 * When we released everything, and we got the next frame in the 825 * sequence, according to the NSSN we can't release immediately, 826 * while technically there is no hole and we can move forward. 827 */ 828 if (!buffer->num_stored && sn == buffer->head_sn) { 829 if (!amsdu || last_subframe) 830 buffer->head_sn = ieee80211_sn_inc(buffer->head_sn); 831 832 spin_unlock_bh(&buffer->lock); 833 return false; 834 } 835 836 /* put in reorder buffer */ 837 index = sn % baid_data->buf_size; 838 __skb_queue_tail(&entries[index].frames, skb); 839 buffer->num_stored++; 840 841 /* 842 * We cannot trust NSSN for AMSDU sub-frames that are not the last. 843 * The reason is that NSSN advances on the first sub-frame, and may 844 * cause the reorder buffer to advance before all the sub-frames arrive. 845 * Example: reorder buffer contains SN 0 & 2, and we receive AMSDU with 846 * SN 1. NSSN for first sub frame will be 3 with the result of driver 847 * releasing SN 0,1, 2. When sub-frame 1 arrives - reorder buffer is 848 * already ahead and it will be dropped. 849 * If the last sub-frame is not on this queue - we will get frame 850 * release notification with up to date NSSN. 851 */ 852 if (!amsdu || last_subframe) 853 iwl_mvm_release_frames(mvm, sta, napi, baid_data, 854 buffer, nssn); 855 856 spin_unlock_bh(&buffer->lock); 857 return true; 858 859 drop: 860 kfree_skb(skb); 861 spin_unlock_bh(&buffer->lock); 862 return true; 863 } 864 865 static void iwl_mvm_agg_rx_received(struct iwl_mvm *mvm, 866 u32 reorder_data, u8 baid) 867 { 868 unsigned long now = jiffies; 869 unsigned long timeout; 870 struct iwl_mvm_baid_data *data; 871 872 rcu_read_lock(); 873 874 data = rcu_dereference(mvm->baid_map[baid]); 875 if (!data) { 876 IWL_DEBUG_RX(mvm, 877 "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n", 878 baid, reorder_data); 879 goto out; 880 } 881 882 if (!data->timeout) 883 goto out; 884 885 timeout = data->timeout; 886 /* 887 * Do not update last rx all the time to avoid cache bouncing 888 * between the rx queues. 889 * Update it every timeout. Worst case is the session will 890 * expire after ~ 2 * timeout, which doesn't matter that much. 891 */ 892 if (time_before(data->last_rx + TU_TO_JIFFIES(timeout), now)) 893 /* Update is atomic */ 894 data->last_rx = now; 895 896 out: 897 rcu_read_unlock(); 898 } 899 900 static void iwl_mvm_flip_address(u8 *addr) 901 { 902 int i; 903 u8 mac_addr[ETH_ALEN]; 904 905 for (i = 0; i < ETH_ALEN; i++) 906 mac_addr[i] = addr[ETH_ALEN - i - 1]; 907 ether_addr_copy(addr, mac_addr); 908 } 909 910 struct iwl_mvm_rx_phy_data { 911 enum iwl_rx_phy_info_type info_type; 912 __le32 d0, d1, d2, d3, eht_d4, d5; 913 __le16 d4; 914 bool with_data; 915 bool first_subframe; 916 __le32 rx_vec[4]; 917 918 u32 rate_n_flags; 919 u32 gp2_on_air_rise; 920 u16 phy_info; 921 u8 energy_a, energy_b; 922 u8 channel; 923 }; 924 925 static void iwl_mvm_decode_he_mu_ext(struct iwl_mvm *mvm, 926 struct iwl_mvm_rx_phy_data *phy_data, 927 struct ieee80211_radiotap_he_mu *he_mu) 928 { 929 u32 phy_data2 = le32_to_cpu(phy_data->d2); 930 u32 phy_data3 = le32_to_cpu(phy_data->d3); 931 u16 phy_data4 = le16_to_cpu(phy_data->d4); 932 u32 rate_n_flags = phy_data->rate_n_flags; 933 934 if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CRC_OK, phy_data4)) { 935 he_mu->flags1 |= 936 cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_RU_KNOWN | 937 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU_KNOWN); 938 939 he_mu->flags1 |= 940 le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CTR_RU, 941 phy_data4), 942 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU); 943 944 he_mu->ru_ch1[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU0, 945 phy_data2); 946 he_mu->ru_ch1[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU1, 947 phy_data3); 948 he_mu->ru_ch1[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU2, 949 phy_data2); 950 he_mu->ru_ch1[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU3, 951 phy_data3); 952 } 953 954 if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CRC_OK, phy_data4) && 955 (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK_V1) != RATE_MCS_CHAN_WIDTH_20) { 956 he_mu->flags1 |= 957 cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_RU_KNOWN | 958 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_CTR_26T_RU_KNOWN); 959 960 he_mu->flags2 |= 961 le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CTR_RU, 962 phy_data4), 963 IEEE80211_RADIOTAP_HE_MU_FLAGS2_CH2_CTR_26T_RU); 964 965 he_mu->ru_ch2[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU0, 966 phy_data2); 967 he_mu->ru_ch2[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU1, 968 phy_data3); 969 he_mu->ru_ch2[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU2, 970 phy_data2); 971 he_mu->ru_ch2[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU3, 972 phy_data3); 973 } 974 } 975 976 static void 977 iwl_mvm_decode_he_phy_ru_alloc(struct iwl_mvm_rx_phy_data *phy_data, 978 struct ieee80211_radiotap_he *he, 979 struct ieee80211_radiotap_he_mu *he_mu, 980 struct ieee80211_rx_status *rx_status) 981 { 982 /* 983 * Unfortunately, we have to leave the mac80211 data 984 * incorrect for the case that we receive an HE-MU 985 * transmission and *don't* have the HE phy data (due 986 * to the bits being used for TSF). This shouldn't 987 * happen though as management frames where we need 988 * the TSF/timers are not be transmitted in HE-MU. 989 */ 990 u8 ru = le32_get_bits(phy_data->d1, IWL_RX_PHY_DATA1_HE_RU_ALLOC_MASK); 991 u32 rate_n_flags = phy_data->rate_n_flags; 992 u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK_V1; 993 u8 offs = 0; 994 995 rx_status->bw = RATE_INFO_BW_HE_RU; 996 997 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN); 998 999 switch (ru) { 1000 case 0 ... 36: 1001 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_26; 1002 offs = ru; 1003 break; 1004 case 37 ... 52: 1005 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_52; 1006 offs = ru - 37; 1007 break; 1008 case 53 ... 60: 1009 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106; 1010 offs = ru - 53; 1011 break; 1012 case 61 ... 64: 1013 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_242; 1014 offs = ru - 61; 1015 break; 1016 case 65 ... 66: 1017 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_484; 1018 offs = ru - 65; 1019 break; 1020 case 67: 1021 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_996; 1022 break; 1023 case 68: 1024 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_2x996; 1025 break; 1026 } 1027 he->data2 |= le16_encode_bits(offs, 1028 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET); 1029 he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_KNOWN | 1030 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET_KNOWN); 1031 if (phy_data->d1 & cpu_to_le32(IWL_RX_PHY_DATA1_HE_RU_ALLOC_SEC80)) 1032 he->data2 |= 1033 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_SEC); 1034 1035 #define CHECK_BW(bw) \ 1036 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_ ## bw ## MHZ != \ 1037 RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS); \ 1038 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_ ## bw ## MHZ != \ 1039 RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS) 1040 CHECK_BW(20); 1041 CHECK_BW(40); 1042 CHECK_BW(80); 1043 CHECK_BW(160); 1044 1045 if (he_mu) 1046 he_mu->flags2 |= 1047 le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK_V1, 1048 rate_n_flags), 1049 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW); 1050 else if (he_type == RATE_MCS_HE_TYPE_TRIG_V1) 1051 he->data6 |= 1052 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_KNOWN) | 1053 le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK_V1, 1054 rate_n_flags), 1055 IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW); 1056 } 1057 1058 static void iwl_mvm_decode_he_phy_data(struct iwl_mvm *mvm, 1059 struct iwl_mvm_rx_phy_data *phy_data, 1060 struct ieee80211_radiotap_he *he, 1061 struct ieee80211_radiotap_he_mu *he_mu, 1062 struct ieee80211_rx_status *rx_status, 1063 int queue) 1064 { 1065 switch (phy_data->info_type) { 1066 case IWL_RX_PHY_INFO_TYPE_NONE: 1067 case IWL_RX_PHY_INFO_TYPE_CCK: 1068 case IWL_RX_PHY_INFO_TYPE_OFDM_LGCY: 1069 case IWL_RX_PHY_INFO_TYPE_HT: 1070 case IWL_RX_PHY_INFO_TYPE_VHT_SU: 1071 case IWL_RX_PHY_INFO_TYPE_VHT_MU: 1072 case IWL_RX_PHY_INFO_TYPE_EHT_MU: 1073 case IWL_RX_PHY_INFO_TYPE_EHT_TB: 1074 case IWL_RX_PHY_INFO_TYPE_EHT_MU_EXT: 1075 case IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT: 1076 return; 1077 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT: 1078 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN | 1079 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE2_KNOWN | 1080 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE3_KNOWN | 1081 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE4_KNOWN); 1082 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2, 1083 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE1), 1084 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE1); 1085 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2, 1086 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE2), 1087 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE2); 1088 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2, 1089 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE3), 1090 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE3); 1091 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2, 1092 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE4), 1093 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE4); 1094 fallthrough; 1095 case IWL_RX_PHY_INFO_TYPE_HE_SU: 1096 case IWL_RX_PHY_INFO_TYPE_HE_MU: 1097 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT: 1098 case IWL_RX_PHY_INFO_TYPE_HE_TB: 1099 /* HE common */ 1100 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_LDPC_XSYMSEG_KNOWN | 1101 IEEE80211_RADIOTAP_HE_DATA1_DOPPLER_KNOWN | 1102 IEEE80211_RADIOTAP_HE_DATA1_BSS_COLOR_KNOWN); 1103 he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRE_FEC_PAD_KNOWN | 1104 IEEE80211_RADIOTAP_HE_DATA2_PE_DISAMBIG_KNOWN | 1105 IEEE80211_RADIOTAP_HE_DATA2_TXOP_KNOWN | 1106 IEEE80211_RADIOTAP_HE_DATA2_NUM_LTF_SYMS_KNOWN); 1107 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1108 IWL_RX_PHY_DATA0_HE_BSS_COLOR_MASK), 1109 IEEE80211_RADIOTAP_HE_DATA3_BSS_COLOR); 1110 if (phy_data->info_type != IWL_RX_PHY_INFO_TYPE_HE_TB && 1111 phy_data->info_type != IWL_RX_PHY_INFO_TYPE_HE_TB_EXT) { 1112 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_UL_DL_KNOWN); 1113 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1114 IWL_RX_PHY_DATA0_HE_UPLINK), 1115 IEEE80211_RADIOTAP_HE_DATA3_UL_DL); 1116 } 1117 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1118 IWL_RX_PHY_DATA0_HE_LDPC_EXT_SYM), 1119 IEEE80211_RADIOTAP_HE_DATA3_LDPC_XSYMSEG); 1120 he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1121 IWL_RX_PHY_DATA0_HE_PRE_FEC_PAD_MASK), 1122 IEEE80211_RADIOTAP_HE_DATA5_PRE_FEC_PAD); 1123 he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1124 IWL_RX_PHY_DATA0_HE_PE_DISAMBIG), 1125 IEEE80211_RADIOTAP_HE_DATA5_PE_DISAMBIG); 1126 he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d1, 1127 IWL_RX_PHY_DATA1_HE_LTF_NUM_MASK), 1128 IEEE80211_RADIOTAP_HE_DATA5_NUM_LTF_SYMS); 1129 he->data6 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1130 IWL_RX_PHY_DATA0_HE_TXOP_DUR_MASK), 1131 IEEE80211_RADIOTAP_HE_DATA6_TXOP); 1132 he->data6 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1133 IWL_RX_PHY_DATA0_HE_DOPPLER), 1134 IEEE80211_RADIOTAP_HE_DATA6_DOPPLER); 1135 break; 1136 } 1137 1138 switch (phy_data->info_type) { 1139 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT: 1140 case IWL_RX_PHY_INFO_TYPE_HE_MU: 1141 case IWL_RX_PHY_INFO_TYPE_HE_SU: 1142 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN); 1143 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1144 IWL_RX_PHY_DATA0_HE_SPATIAL_REUSE_MASK), 1145 IEEE80211_RADIOTAP_HE_DATA4_SU_MU_SPTL_REUSE); 1146 break; 1147 default: 1148 /* nothing here */ 1149 break; 1150 } 1151 1152 switch (phy_data->info_type) { 1153 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT: 1154 he_mu->flags1 |= 1155 le16_encode_bits(le16_get_bits(phy_data->d4, 1156 IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_DCM), 1157 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM); 1158 he_mu->flags1 |= 1159 le16_encode_bits(le16_get_bits(phy_data->d4, 1160 IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_MCS_MASK), 1161 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS); 1162 he_mu->flags2 |= 1163 le16_encode_bits(le16_get_bits(phy_data->d4, 1164 IWL_RX_PHY_DATA4_HE_MU_EXT_PREAMBLE_PUNC_TYPE_MASK), 1165 IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW); 1166 iwl_mvm_decode_he_mu_ext(mvm, phy_data, he_mu); 1167 fallthrough; 1168 case IWL_RX_PHY_INFO_TYPE_HE_MU: 1169 he_mu->flags2 |= 1170 le16_encode_bits(le32_get_bits(phy_data->d1, 1171 IWL_RX_PHY_DATA1_HE_MU_SIBG_SYM_OR_USER_NUM_MASK), 1172 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_SYMS_USERS); 1173 he_mu->flags2 |= 1174 le16_encode_bits(le32_get_bits(phy_data->d1, 1175 IWL_RX_PHY_DATA1_HE_MU_SIGB_COMPRESSION), 1176 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_COMP); 1177 fallthrough; 1178 case IWL_RX_PHY_INFO_TYPE_HE_TB: 1179 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT: 1180 iwl_mvm_decode_he_phy_ru_alloc(phy_data, he, he_mu, rx_status); 1181 break; 1182 case IWL_RX_PHY_INFO_TYPE_HE_SU: 1183 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BEAM_CHANGE_KNOWN); 1184 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1185 IWL_RX_PHY_DATA0_HE_BEAM_CHNG), 1186 IEEE80211_RADIOTAP_HE_DATA3_BEAM_CHANGE); 1187 break; 1188 default: 1189 /* nothing */ 1190 break; 1191 } 1192 } 1193 1194 #define LE32_DEC_ENC(value, dec_bits, enc_bits) \ 1195 le32_encode_bits(le32_get_bits(value, dec_bits), enc_bits) 1196 1197 #define IWL_MVM_ENC_USIG_VALUE_MASK(usig, in_value, dec_bits, enc_bits) do { \ 1198 typeof(enc_bits) _enc_bits = enc_bits; \ 1199 typeof(usig) _usig = usig; \ 1200 (_usig)->mask |= cpu_to_le32(_enc_bits); \ 1201 (_usig)->value |= LE32_DEC_ENC(in_value, dec_bits, _enc_bits); \ 1202 } while (0) 1203 1204 #define __IWL_MVM_ENC_EHT_RU(rt_data, rt_ru, fw_data, fw_ru) \ 1205 eht->data[(rt_data)] |= \ 1206 (cpu_to_le32 \ 1207 (IEEE80211_RADIOTAP_EHT_DATA ## rt_data ## _RU_ALLOC_CC_ ## rt_ru ## _KNOWN) | \ 1208 LE32_DEC_ENC(data ## fw_data, \ 1209 IWL_RX_PHY_DATA ## fw_data ## _EHT_MU_EXT_RU_ALLOC_ ## fw_ru, \ 1210 IEEE80211_RADIOTAP_EHT_DATA ## rt_data ## _RU_ALLOC_CC_ ## rt_ru)) 1211 1212 #define _IWL_MVM_ENC_EHT_RU(rt_data, rt_ru, fw_data, fw_ru) \ 1213 __IWL_MVM_ENC_EHT_RU(rt_data, rt_ru, fw_data, fw_ru) 1214 1215 #define IEEE80211_RADIOTAP_RU_DATA_1_1_1 1 1216 #define IEEE80211_RADIOTAP_RU_DATA_2_1_1 2 1217 #define IEEE80211_RADIOTAP_RU_DATA_1_1_2 2 1218 #define IEEE80211_RADIOTAP_RU_DATA_2_1_2 2 1219 #define IEEE80211_RADIOTAP_RU_DATA_1_2_1 3 1220 #define IEEE80211_RADIOTAP_RU_DATA_2_2_1 3 1221 #define IEEE80211_RADIOTAP_RU_DATA_1_2_2 3 1222 #define IEEE80211_RADIOTAP_RU_DATA_2_2_2 4 1223 1224 #define IWL_RX_RU_DATA_A1 2 1225 #define IWL_RX_RU_DATA_A2 2 1226 #define IWL_RX_RU_DATA_B1 2 1227 #define IWL_RX_RU_DATA_B2 4 1228 #define IWL_RX_RU_DATA_C1 3 1229 #define IWL_RX_RU_DATA_C2 3 1230 #define IWL_RX_RU_DATA_D1 4 1231 #define IWL_RX_RU_DATA_D2 4 1232 1233 #define IWL_MVM_ENC_EHT_RU(rt_ru, fw_ru) \ 1234 _IWL_MVM_ENC_EHT_RU(IEEE80211_RADIOTAP_RU_DATA_ ## rt_ru, \ 1235 rt_ru, \ 1236 IWL_RX_RU_DATA_ ## fw_ru, \ 1237 fw_ru) 1238 1239 static void iwl_mvm_decode_eht_ext_mu(struct iwl_mvm *mvm, 1240 struct iwl_mvm_rx_phy_data *phy_data, 1241 struct ieee80211_rx_status *rx_status, 1242 struct ieee80211_radiotap_eht *eht, 1243 struct ieee80211_radiotap_eht_usig *usig) 1244 { 1245 if (phy_data->with_data) { 1246 __le32 data1 = phy_data->d1; 1247 __le32 data2 = phy_data->d2; 1248 __le32 data3 = phy_data->d3; 1249 __le32 data4 = phy_data->eht_d4; 1250 __le32 data5 = phy_data->d5; 1251 u32 phy_bw = phy_data->rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK; 1252 1253 IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5, 1254 IWL_RX_PHY_DATA5_EHT_TYPE_AND_COMP, 1255 IEEE80211_RADIOTAP_EHT_USIG2_MU_B0_B1_PPDU_TYPE); 1256 IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5, 1257 IWL_RX_PHY_DATA5_EHT_MU_PUNC_CH_CODE, 1258 IEEE80211_RADIOTAP_EHT_USIG2_MU_B3_B7_PUNCTURED_INFO); 1259 IWL_MVM_ENC_USIG_VALUE_MASK(usig, data4, 1260 IWL_RX_PHY_DATA4_EHT_MU_EXT_SIGB_MCS, 1261 IEEE80211_RADIOTAP_EHT_USIG2_MU_B9_B10_SIG_MCS); 1262 IWL_MVM_ENC_USIG_VALUE_MASK 1263 (usig, data1, IWL_RX_PHY_DATA1_EHT_MU_NUM_SIG_SYM_USIGA2, 1264 IEEE80211_RADIOTAP_EHT_USIG2_MU_B11_B15_EHT_SIG_SYMBOLS); 1265 1266 eht->user_info[0] |= 1267 cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_STA_ID_KNOWN) | 1268 LE32_DEC_ENC(data5, IWL_RX_PHY_DATA5_EHT_MU_STA_ID_USR, 1269 IEEE80211_RADIOTAP_EHT_USER_INFO_STA_ID); 1270 1271 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_NR_NON_OFDMA_USERS_M); 1272 eht->data[7] |= LE32_DEC_ENC 1273 (data5, IWL_RX_PHY_DATA5_EHT_MU_NUM_USR_NON_OFDMA, 1274 IEEE80211_RADIOTAP_EHT_DATA7_NUM_OF_NON_OFDMA_USERS); 1275 1276 /* 1277 * Hardware labels the content channels/RU allocation values 1278 * as follows: 1279 * Content Channel 1 Content Channel 2 1280 * 20 MHz: A1 1281 * 40 MHz: A1 B1 1282 * 80 MHz: A1 C1 B1 D1 1283 * 160 MHz: A1 C1 A2 C2 B1 D1 B2 D2 1284 * 320 MHz: A1 C1 A2 C2 A3 C3 A4 C4 B1 D1 B2 D2 B3 D3 B4 D4 1285 * 1286 * However firmware can only give us A1-D2, so the higher 1287 * frequencies are missing. 1288 */ 1289 1290 switch (phy_bw) { 1291 case RATE_MCS_CHAN_WIDTH_320: 1292 /* additional values are missing in RX metadata */ 1293 case RATE_MCS_CHAN_WIDTH_160: 1294 /* content channel 1 */ 1295 IWL_MVM_ENC_EHT_RU(1_2_1, A2); 1296 IWL_MVM_ENC_EHT_RU(1_2_2, C2); 1297 /* content channel 2 */ 1298 IWL_MVM_ENC_EHT_RU(2_2_1, B2); 1299 IWL_MVM_ENC_EHT_RU(2_2_2, D2); 1300 fallthrough; 1301 case RATE_MCS_CHAN_WIDTH_80: 1302 /* content channel 1 */ 1303 IWL_MVM_ENC_EHT_RU(1_1_2, C1); 1304 /* content channel 2 */ 1305 IWL_MVM_ENC_EHT_RU(2_1_2, D1); 1306 fallthrough; 1307 case RATE_MCS_CHAN_WIDTH_40: 1308 /* content channel 2 */ 1309 IWL_MVM_ENC_EHT_RU(2_1_1, B1); 1310 fallthrough; 1311 case RATE_MCS_CHAN_WIDTH_20: 1312 IWL_MVM_ENC_EHT_RU(1_1_1, A1); 1313 break; 1314 } 1315 } else { 1316 __le32 usig_a1 = phy_data->rx_vec[0]; 1317 __le32 usig_a2 = phy_data->rx_vec[1]; 1318 1319 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a1, 1320 IWL_RX_USIG_A1_DISREGARD, 1321 IEEE80211_RADIOTAP_EHT_USIG1_MU_B20_B24_DISREGARD); 1322 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a1, 1323 IWL_RX_USIG_A1_VALIDATE, 1324 IEEE80211_RADIOTAP_EHT_USIG1_MU_B25_VALIDATE); 1325 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1326 IWL_RX_USIG_A2_EHT_PPDU_TYPE, 1327 IEEE80211_RADIOTAP_EHT_USIG2_MU_B0_B1_PPDU_TYPE); 1328 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1329 IWL_RX_USIG_A2_EHT_USIG2_VALIDATE_B2, 1330 IEEE80211_RADIOTAP_EHT_USIG2_MU_B2_VALIDATE); 1331 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1332 IWL_RX_USIG_A2_EHT_PUNC_CHANNEL, 1333 IEEE80211_RADIOTAP_EHT_USIG2_MU_B3_B7_PUNCTURED_INFO); 1334 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1335 IWL_RX_USIG_A2_EHT_USIG2_VALIDATE_B8, 1336 IEEE80211_RADIOTAP_EHT_USIG2_MU_B8_VALIDATE); 1337 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1338 IWL_RX_USIG_A2_EHT_SIG_MCS, 1339 IEEE80211_RADIOTAP_EHT_USIG2_MU_B9_B10_SIG_MCS); 1340 IWL_MVM_ENC_USIG_VALUE_MASK 1341 (usig, usig_a2, IWL_RX_USIG_A2_EHT_SIG_SYM_NUM, 1342 IEEE80211_RADIOTAP_EHT_USIG2_MU_B11_B15_EHT_SIG_SYMBOLS); 1343 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1344 IWL_RX_USIG_A2_EHT_CRC_OK, 1345 IEEE80211_RADIOTAP_EHT_USIG2_MU_B16_B19_CRC); 1346 } 1347 } 1348 1349 static void iwl_mvm_decode_eht_ext_tb(struct iwl_mvm *mvm, 1350 struct iwl_mvm_rx_phy_data *phy_data, 1351 struct ieee80211_rx_status *rx_status, 1352 struct ieee80211_radiotap_eht *eht, 1353 struct ieee80211_radiotap_eht_usig *usig) 1354 { 1355 if (phy_data->with_data) { 1356 __le32 data5 = phy_data->d5; 1357 1358 IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5, 1359 IWL_RX_PHY_DATA5_EHT_TYPE_AND_COMP, 1360 IEEE80211_RADIOTAP_EHT_USIG2_TB_B0_B1_PPDU_TYPE); 1361 IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5, 1362 IWL_RX_PHY_DATA5_EHT_TB_SPATIAL_REUSE1, 1363 IEEE80211_RADIOTAP_EHT_USIG2_TB_B3_B6_SPATIAL_REUSE_1); 1364 1365 IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5, 1366 IWL_RX_PHY_DATA5_EHT_TB_SPATIAL_REUSE2, 1367 IEEE80211_RADIOTAP_EHT_USIG2_TB_B7_B10_SPATIAL_REUSE_2); 1368 } else { 1369 __le32 usig_a1 = phy_data->rx_vec[0]; 1370 __le32 usig_a2 = phy_data->rx_vec[1]; 1371 1372 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a1, 1373 IWL_RX_USIG_A1_DISREGARD, 1374 IEEE80211_RADIOTAP_EHT_USIG1_TB_B20_B25_DISREGARD); 1375 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1376 IWL_RX_USIG_A2_EHT_PPDU_TYPE, 1377 IEEE80211_RADIOTAP_EHT_USIG2_TB_B0_B1_PPDU_TYPE); 1378 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1379 IWL_RX_USIG_A2_EHT_USIG2_VALIDATE_B2, 1380 IEEE80211_RADIOTAP_EHT_USIG2_TB_B2_VALIDATE); 1381 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1382 IWL_RX_USIG_A2_EHT_TRIG_SPATIAL_REUSE_1, 1383 IEEE80211_RADIOTAP_EHT_USIG2_TB_B3_B6_SPATIAL_REUSE_1); 1384 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1385 IWL_RX_USIG_A2_EHT_TRIG_SPATIAL_REUSE_2, 1386 IEEE80211_RADIOTAP_EHT_USIG2_TB_B7_B10_SPATIAL_REUSE_2); 1387 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1388 IWL_RX_USIG_A2_EHT_TRIG_USIG2_DISREGARD, 1389 IEEE80211_RADIOTAP_EHT_USIG2_TB_B11_B15_DISREGARD); 1390 IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2, 1391 IWL_RX_USIG_A2_EHT_CRC_OK, 1392 IEEE80211_RADIOTAP_EHT_USIG2_TB_B16_B19_CRC); 1393 } 1394 } 1395 1396 static void iwl_mvm_decode_eht_ru(struct iwl_mvm *mvm, 1397 struct ieee80211_rx_status *rx_status, 1398 struct ieee80211_radiotap_eht *eht) 1399 { 1400 u32 ru = le32_get_bits(eht->data[8], 1401 IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_B7_B1); 1402 enum nl80211_eht_ru_alloc nl_ru; 1403 1404 /* Using D1.5 Table 9-53a - Encoding of PS160 and RU Allocation subfields 1405 * in an EHT variant User Info field 1406 */ 1407 1408 switch (ru) { 1409 case 0 ... 36: 1410 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_26; 1411 break; 1412 case 37 ... 52: 1413 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_52; 1414 break; 1415 case 53 ... 60: 1416 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_106; 1417 break; 1418 case 61 ... 64: 1419 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_242; 1420 break; 1421 case 65 ... 66: 1422 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_484; 1423 break; 1424 case 67: 1425 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_996; 1426 break; 1427 case 68: 1428 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_2x996; 1429 break; 1430 case 69: 1431 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_4x996; 1432 break; 1433 case 70 ... 81: 1434 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_52P26; 1435 break; 1436 case 82 ... 89: 1437 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_106P26; 1438 break; 1439 case 90 ... 93: 1440 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_484P242; 1441 break; 1442 case 94 ... 95: 1443 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_996P484; 1444 break; 1445 case 96 ... 99: 1446 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_996P484P242; 1447 break; 1448 case 100 ... 103: 1449 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_2x996P484; 1450 break; 1451 case 104: 1452 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_3x996; 1453 break; 1454 case 105 ... 106: 1455 nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_3x996P484; 1456 break; 1457 default: 1458 return; 1459 } 1460 1461 rx_status->bw = RATE_INFO_BW_EHT_RU; 1462 rx_status->eht.ru = nl_ru; 1463 } 1464 1465 static void iwl_mvm_decode_eht_phy_data(struct iwl_mvm *mvm, 1466 struct iwl_mvm_rx_phy_data *phy_data, 1467 struct ieee80211_rx_status *rx_status, 1468 struct ieee80211_radiotap_eht *eht, 1469 struct ieee80211_radiotap_eht_usig *usig) 1470 1471 { 1472 __le32 data0 = phy_data->d0; 1473 __le32 data1 = phy_data->d1; 1474 __le32 usig_a1 = phy_data->rx_vec[0]; 1475 u8 info_type = phy_data->info_type; 1476 1477 /* Not in EHT range */ 1478 if (info_type < IWL_RX_PHY_INFO_TYPE_EHT_MU || 1479 info_type > IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT) 1480 return; 1481 1482 usig->common |= cpu_to_le32 1483 (IEEE80211_RADIOTAP_EHT_USIG_COMMON_UL_DL_KNOWN | 1484 IEEE80211_RADIOTAP_EHT_USIG_COMMON_BSS_COLOR_KNOWN); 1485 if (phy_data->with_data) { 1486 usig->common |= LE32_DEC_ENC(data0, 1487 IWL_RX_PHY_DATA0_EHT_UPLINK, 1488 IEEE80211_RADIOTAP_EHT_USIG_COMMON_UL_DL); 1489 usig->common |= LE32_DEC_ENC(data0, 1490 IWL_RX_PHY_DATA0_EHT_BSS_COLOR_MASK, 1491 IEEE80211_RADIOTAP_EHT_USIG_COMMON_BSS_COLOR); 1492 } else { 1493 usig->common |= LE32_DEC_ENC(usig_a1, 1494 IWL_RX_USIG_A1_UL_FLAG, 1495 IEEE80211_RADIOTAP_EHT_USIG_COMMON_UL_DL); 1496 usig->common |= LE32_DEC_ENC(usig_a1, 1497 IWL_RX_USIG_A1_BSS_COLOR, 1498 IEEE80211_RADIOTAP_EHT_USIG_COMMON_BSS_COLOR); 1499 } 1500 1501 if (fw_has_capa(&mvm->fw->ucode_capa, 1502 IWL_UCODE_TLV_CAPA_SNIFF_VALIDATE_SUPPORT)) { 1503 usig->common |= 1504 cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_VALIDATE_BITS_CHECKED); 1505 usig->common |= 1506 LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_VALIDATE, 1507 IEEE80211_RADIOTAP_EHT_USIG_COMMON_VALIDATE_BITS_OK); 1508 } 1509 1510 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_SPATIAL_REUSE); 1511 eht->data[0] |= LE32_DEC_ENC(data0, 1512 IWL_RX_PHY_DATA0_ETH_SPATIAL_REUSE_MASK, 1513 IEEE80211_RADIOTAP_EHT_DATA0_SPATIAL_REUSE); 1514 1515 /* All RU allocating size/index is in TB format */ 1516 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_RU_ALLOC_TB_FMT); 1517 eht->data[8] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PS160, 1518 IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_PS_160); 1519 eht->data[8] |= LE32_DEC_ENC(data1, IWL_RX_PHY_DATA1_EHT_RU_ALLOC_B0, 1520 IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_B0); 1521 eht->data[8] |= LE32_DEC_ENC(data1, IWL_RX_PHY_DATA1_EHT_RU_ALLOC_B1_B7, 1522 IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_B7_B1); 1523 1524 iwl_mvm_decode_eht_ru(mvm, rx_status, eht); 1525 1526 /* We only get here in case of IWL_RX_MPDU_PHY_TSF_OVERLOAD is set 1527 * which is on only in case of monitor mode so no need to check monitor 1528 * mode 1529 */ 1530 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_PRIMARY_80); 1531 eht->data[1] |= 1532 le32_encode_bits(mvm->monitor_p80, 1533 IEEE80211_RADIOTAP_EHT_DATA1_PRIMARY_80); 1534 1535 usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_TXOP_KNOWN); 1536 if (phy_data->with_data) 1537 usig->common |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_TXOP_DUR_MASK, 1538 IEEE80211_RADIOTAP_EHT_USIG_COMMON_TXOP); 1539 else 1540 usig->common |= LE32_DEC_ENC(usig_a1, IWL_RX_USIG_A1_TXOP_DURATION, 1541 IEEE80211_RADIOTAP_EHT_USIG_COMMON_TXOP); 1542 1543 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_LDPC_EXTRA_SYM_OM); 1544 eht->data[0] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_LDPC_EXT_SYM, 1545 IEEE80211_RADIOTAP_EHT_DATA0_LDPC_EXTRA_SYM_OM); 1546 1547 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_PRE_PADD_FACOR_OM); 1548 eht->data[0] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PRE_FEC_PAD_MASK, 1549 IEEE80211_RADIOTAP_EHT_DATA0_PRE_PADD_FACOR_OM); 1550 1551 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_PE_DISAMBIGUITY_OM); 1552 eht->data[0] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PE_DISAMBIG, 1553 IEEE80211_RADIOTAP_EHT_DATA0_PE_DISAMBIGUITY_OM); 1554 1555 /* TODO: what about IWL_RX_PHY_DATA0_EHT_BW320_SLOT */ 1556 1557 if (!le32_get_bits(data0, IWL_RX_PHY_DATA0_EHT_SIGA_CRC_OK)) 1558 usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BAD_USIG_CRC); 1559 1560 usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_PHY_VER_KNOWN); 1561 usig->common |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PHY_VER, 1562 IEEE80211_RADIOTAP_EHT_USIG_COMMON_PHY_VER); 1563 1564 /* 1565 * TODO: what about TB - IWL_RX_PHY_DATA1_EHT_TB_PILOT_TYPE, 1566 * IWL_RX_PHY_DATA1_EHT_TB_LOW_SS 1567 */ 1568 1569 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_EHT_LTF); 1570 eht->data[0] |= LE32_DEC_ENC(data1, IWL_RX_PHY_DATA1_EHT_SIG_LTF_NUM, 1571 IEEE80211_RADIOTAP_EHT_DATA0_EHT_LTF); 1572 1573 if (info_type == IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT || 1574 info_type == IWL_RX_PHY_INFO_TYPE_EHT_TB) 1575 iwl_mvm_decode_eht_ext_tb(mvm, phy_data, rx_status, eht, usig); 1576 1577 if (info_type == IWL_RX_PHY_INFO_TYPE_EHT_MU_EXT || 1578 info_type == IWL_RX_PHY_INFO_TYPE_EHT_MU) 1579 iwl_mvm_decode_eht_ext_mu(mvm, phy_data, rx_status, eht, usig); 1580 } 1581 1582 static void iwl_mvm_rx_eht(struct iwl_mvm *mvm, struct sk_buff *skb, 1583 struct iwl_mvm_rx_phy_data *phy_data, 1584 int queue) 1585 { 1586 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 1587 1588 struct ieee80211_radiotap_eht *eht; 1589 struct ieee80211_radiotap_eht_usig *usig; 1590 size_t eht_len = sizeof(*eht); 1591 1592 u32 rate_n_flags = phy_data->rate_n_flags; 1593 u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK; 1594 /* EHT and HE have the same valus for LTF */ 1595 u8 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN; 1596 u16 phy_info = phy_data->phy_info; 1597 u32 bw; 1598 1599 /* u32 for 1 user_info */ 1600 if (phy_data->with_data) 1601 eht_len += sizeof(u32); 1602 1603 eht = iwl_mvm_radiotap_put_tlv(skb, IEEE80211_RADIOTAP_EHT, eht_len); 1604 1605 usig = iwl_mvm_radiotap_put_tlv(skb, IEEE80211_RADIOTAP_EHT_USIG, 1606 sizeof(*usig)); 1607 rx_status->flag |= RX_FLAG_RADIOTAP_TLV_AT_END; 1608 usig->common |= 1609 cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BW_KNOWN); 1610 1611 /* specific handling for 320MHz */ 1612 bw = FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK, rate_n_flags); 1613 if (bw == RATE_MCS_CHAN_WIDTH_320_VAL) 1614 bw += FIELD_GET(IWL_RX_PHY_DATA0_EHT_BW320_SLOT, 1615 le32_to_cpu(phy_data->d0)); 1616 1617 usig->common |= cpu_to_le32 1618 (FIELD_PREP(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BW, bw)); 1619 1620 /* report the AMPDU-EOF bit on single frames */ 1621 if (!queue && !(phy_info & IWL_RX_MPDU_PHY_AMPDU)) { 1622 rx_status->flag |= RX_FLAG_AMPDU_DETAILS; 1623 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN; 1624 if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_EHT_DELIM_EOF)) 1625 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT; 1626 } 1627 1628 /* update aggregation data for monitor sake on default queue */ 1629 if (!queue && (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) && 1630 (phy_info & IWL_RX_MPDU_PHY_AMPDU) && phy_data->first_subframe) { 1631 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN; 1632 if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_EHT_DELIM_EOF)) 1633 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT; 1634 } 1635 1636 if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) 1637 iwl_mvm_decode_eht_phy_data(mvm, phy_data, rx_status, eht, usig); 1638 1639 #define CHECK_TYPE(F) \ 1640 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_ ## F != \ 1641 (RATE_MCS_HE_TYPE_ ## F >> RATE_MCS_HE_TYPE_POS)) 1642 1643 CHECK_TYPE(SU); 1644 CHECK_TYPE(EXT_SU); 1645 CHECK_TYPE(MU); 1646 CHECK_TYPE(TRIG); 1647 1648 switch (FIELD_GET(RATE_MCS_HE_GI_LTF_MSK, rate_n_flags)) { 1649 case 0: 1650 if (he_type == RATE_MCS_HE_TYPE_TRIG) { 1651 rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_1_6; 1652 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X; 1653 } else { 1654 rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_0_8; 1655 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; 1656 } 1657 break; 1658 case 1: 1659 rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_1_6; 1660 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; 1661 break; 1662 case 2: 1663 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 1664 if (he_type == RATE_MCS_HE_TYPE_TRIG) 1665 rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_3_2; 1666 else 1667 rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_0_8; 1668 break; 1669 case 3: 1670 if (he_type != RATE_MCS_HE_TYPE_TRIG) { 1671 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 1672 rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_3_2; 1673 } 1674 break; 1675 default: 1676 /* nothing here */ 1677 break; 1678 } 1679 1680 if (ltf != IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN) { 1681 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_GI); 1682 eht->data[0] |= cpu_to_le32 1683 (FIELD_PREP(IEEE80211_RADIOTAP_EHT_DATA0_LTF, 1684 ltf) | 1685 FIELD_PREP(IEEE80211_RADIOTAP_EHT_DATA0_GI, 1686 rx_status->eht.gi)); 1687 } 1688 1689 1690 if (!phy_data->with_data) { 1691 eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_NSS_S | 1692 IEEE80211_RADIOTAP_EHT_KNOWN_BEAMFORMED_S); 1693 eht->data[7] |= 1694 le32_encode_bits(le32_get_bits(phy_data->rx_vec[2], 1695 RX_NO_DATA_RX_VEC2_EHT_NSTS_MSK), 1696 IEEE80211_RADIOTAP_EHT_DATA7_NSS_S); 1697 if (rate_n_flags & RATE_MCS_BF_MSK) 1698 eht->data[7] |= 1699 cpu_to_le32(IEEE80211_RADIOTAP_EHT_DATA7_BEAMFORMED_S); 1700 } else { 1701 eht->user_info[0] |= 1702 cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_MCS_KNOWN | 1703 IEEE80211_RADIOTAP_EHT_USER_INFO_CODING_KNOWN | 1704 IEEE80211_RADIOTAP_EHT_USER_INFO_NSS_KNOWN_O | 1705 IEEE80211_RADIOTAP_EHT_USER_INFO_BEAMFORMING_KNOWN_O | 1706 IEEE80211_RADIOTAP_EHT_USER_INFO_DATA_FOR_USER); 1707 1708 if (rate_n_flags & RATE_MCS_BF_MSK) 1709 eht->user_info[0] |= 1710 cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_BEAMFORMING_O); 1711 1712 if (rate_n_flags & RATE_MCS_LDPC_MSK) 1713 eht->user_info[0] |= 1714 cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_CODING); 1715 1716 eht->user_info[0] |= cpu_to_le32 1717 (FIELD_PREP(IEEE80211_RADIOTAP_EHT_USER_INFO_MCS, 1718 FIELD_GET(RATE_VHT_MCS_RATE_CODE_MSK, 1719 rate_n_flags)) | 1720 FIELD_PREP(IEEE80211_RADIOTAP_EHT_USER_INFO_NSS_O, 1721 FIELD_GET(RATE_MCS_NSS_MSK, rate_n_flags))); 1722 } 1723 } 1724 1725 static void iwl_mvm_rx_he(struct iwl_mvm *mvm, struct sk_buff *skb, 1726 struct iwl_mvm_rx_phy_data *phy_data, 1727 int queue) 1728 { 1729 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 1730 struct ieee80211_radiotap_he *he = NULL; 1731 struct ieee80211_radiotap_he_mu *he_mu = NULL; 1732 u32 rate_n_flags = phy_data->rate_n_flags; 1733 u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK; 1734 u8 ltf; 1735 static const struct ieee80211_radiotap_he known = { 1736 .data1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_DATA_MCS_KNOWN | 1737 IEEE80211_RADIOTAP_HE_DATA1_DATA_DCM_KNOWN | 1738 IEEE80211_RADIOTAP_HE_DATA1_STBC_KNOWN | 1739 IEEE80211_RADIOTAP_HE_DATA1_CODING_KNOWN), 1740 .data2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_GI_KNOWN | 1741 IEEE80211_RADIOTAP_HE_DATA2_TXBF_KNOWN), 1742 }; 1743 static const struct ieee80211_radiotap_he_mu mu_known = { 1744 .flags1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS_KNOWN | 1745 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM_KNOWN | 1746 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_SYMS_USERS_KNOWN | 1747 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_COMP_KNOWN), 1748 .flags2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW_KNOWN | 1749 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_KNOWN), 1750 }; 1751 u16 phy_info = phy_data->phy_info; 1752 1753 he = skb_put_data(skb, &known, sizeof(known)); 1754 rx_status->flag |= RX_FLAG_RADIOTAP_HE; 1755 1756 if (phy_data->info_type == IWL_RX_PHY_INFO_TYPE_HE_MU || 1757 phy_data->info_type == IWL_RX_PHY_INFO_TYPE_HE_MU_EXT) { 1758 he_mu = skb_put_data(skb, &mu_known, sizeof(mu_known)); 1759 rx_status->flag |= RX_FLAG_RADIOTAP_HE_MU; 1760 } 1761 1762 /* report the AMPDU-EOF bit on single frames */ 1763 if (!queue && !(phy_info & IWL_RX_MPDU_PHY_AMPDU)) { 1764 rx_status->flag |= RX_FLAG_AMPDU_DETAILS; 1765 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN; 1766 if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_HE_DELIM_EOF)) 1767 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT; 1768 } 1769 1770 if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) 1771 iwl_mvm_decode_he_phy_data(mvm, phy_data, he, he_mu, rx_status, 1772 queue); 1773 1774 /* update aggregation data for monitor sake on default queue */ 1775 if (!queue && (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) && 1776 (phy_info & IWL_RX_MPDU_PHY_AMPDU) && phy_data->first_subframe) { 1777 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN; 1778 if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_EHT_DELIM_EOF)) 1779 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT; 1780 } 1781 1782 if (he_type == RATE_MCS_HE_TYPE_EXT_SU && 1783 rate_n_flags & RATE_MCS_HE_106T_MSK) { 1784 rx_status->bw = RATE_INFO_BW_HE_RU; 1785 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106; 1786 } 1787 1788 /* actually data is filled in mac80211 */ 1789 if (he_type == RATE_MCS_HE_TYPE_SU || 1790 he_type == RATE_MCS_HE_TYPE_EXT_SU) 1791 he->data1 |= 1792 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN); 1793 1794 #define CHECK_TYPE(F) \ 1795 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_ ## F != \ 1796 (RATE_MCS_HE_TYPE_ ## F >> RATE_MCS_HE_TYPE_POS)) 1797 1798 CHECK_TYPE(SU); 1799 CHECK_TYPE(EXT_SU); 1800 CHECK_TYPE(MU); 1801 CHECK_TYPE(TRIG); 1802 1803 he->data1 |= cpu_to_le16(he_type >> RATE_MCS_HE_TYPE_POS); 1804 1805 if (rate_n_flags & RATE_MCS_BF_MSK) 1806 he->data5 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA5_TXBF); 1807 1808 switch ((rate_n_flags & RATE_MCS_HE_GI_LTF_MSK) >> 1809 RATE_MCS_HE_GI_LTF_POS) { 1810 case 0: 1811 if (he_type == RATE_MCS_HE_TYPE_TRIG) 1812 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 1813 else 1814 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 1815 if (he_type == RATE_MCS_HE_TYPE_MU) 1816 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 1817 else 1818 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X; 1819 break; 1820 case 1: 1821 if (he_type == RATE_MCS_HE_TYPE_TRIG) 1822 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 1823 else 1824 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 1825 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; 1826 break; 1827 case 2: 1828 if (he_type == RATE_MCS_HE_TYPE_TRIG) { 1829 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 1830 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 1831 } else { 1832 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 1833 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; 1834 } 1835 break; 1836 case 3: 1837 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 1838 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 1839 break; 1840 case 4: 1841 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 1842 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 1843 break; 1844 default: 1845 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN; 1846 } 1847 1848 he->data5 |= le16_encode_bits(ltf, 1849 IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE); 1850 } 1851 1852 static void iwl_mvm_decode_lsig(struct sk_buff *skb, 1853 struct iwl_mvm_rx_phy_data *phy_data) 1854 { 1855 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 1856 struct ieee80211_radiotap_lsig *lsig; 1857 1858 switch (phy_data->info_type) { 1859 case IWL_RX_PHY_INFO_TYPE_HT: 1860 case IWL_RX_PHY_INFO_TYPE_VHT_SU: 1861 case IWL_RX_PHY_INFO_TYPE_VHT_MU: 1862 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT: 1863 case IWL_RX_PHY_INFO_TYPE_HE_SU: 1864 case IWL_RX_PHY_INFO_TYPE_HE_MU: 1865 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT: 1866 case IWL_RX_PHY_INFO_TYPE_HE_TB: 1867 case IWL_RX_PHY_INFO_TYPE_EHT_MU: 1868 case IWL_RX_PHY_INFO_TYPE_EHT_TB: 1869 case IWL_RX_PHY_INFO_TYPE_EHT_MU_EXT: 1870 case IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT: 1871 lsig = skb_put(skb, sizeof(*lsig)); 1872 lsig->data1 = cpu_to_le16(IEEE80211_RADIOTAP_LSIG_DATA1_LENGTH_KNOWN); 1873 lsig->data2 = le16_encode_bits(le32_get_bits(phy_data->d1, 1874 IWL_RX_PHY_DATA1_LSIG_LEN_MASK), 1875 IEEE80211_RADIOTAP_LSIG_DATA2_LENGTH); 1876 rx_status->flag |= RX_FLAG_RADIOTAP_LSIG; 1877 break; 1878 default: 1879 break; 1880 } 1881 } 1882 1883 struct iwl_rx_sta_csa { 1884 bool all_sta_unblocked; 1885 struct ieee80211_vif *vif; 1886 }; 1887 1888 static void iwl_mvm_rx_get_sta_block_tx(void *data, struct ieee80211_sta *sta) 1889 { 1890 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 1891 struct iwl_rx_sta_csa *rx_sta_csa = data; 1892 1893 if (mvmsta->vif != rx_sta_csa->vif) 1894 return; 1895 1896 if (mvmsta->disable_tx) 1897 rx_sta_csa->all_sta_unblocked = false; 1898 } 1899 1900 /* 1901 * Note: requires also rx_status->band to be prefilled, as well 1902 * as phy_data (apart from phy_data->info_type) 1903 */ 1904 static void iwl_mvm_rx_fill_status(struct iwl_mvm *mvm, 1905 struct sk_buff *skb, 1906 struct iwl_mvm_rx_phy_data *phy_data, 1907 int queue) 1908 { 1909 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 1910 u32 rate_n_flags = phy_data->rate_n_flags; 1911 u8 stbc = u32_get_bits(rate_n_flags, RATE_MCS_STBC_MSK); 1912 u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK; 1913 bool is_sgi; 1914 1915 phy_data->info_type = IWL_RX_PHY_INFO_TYPE_NONE; 1916 1917 if (phy_data->phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) 1918 phy_data->info_type = 1919 le32_get_bits(phy_data->d1, 1920 IWL_RX_PHY_DATA1_INFO_TYPE_MASK); 1921 1922 /* This may be overridden by iwl_mvm_rx_he() to HE_RU */ 1923 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { 1924 case RATE_MCS_CHAN_WIDTH_20: 1925 break; 1926 case RATE_MCS_CHAN_WIDTH_40: 1927 rx_status->bw = RATE_INFO_BW_40; 1928 break; 1929 case RATE_MCS_CHAN_WIDTH_80: 1930 rx_status->bw = RATE_INFO_BW_80; 1931 break; 1932 case RATE_MCS_CHAN_WIDTH_160: 1933 rx_status->bw = RATE_INFO_BW_160; 1934 break; 1935 case RATE_MCS_CHAN_WIDTH_320: 1936 rx_status->bw = RATE_INFO_BW_320; 1937 break; 1938 } 1939 1940 /* must be before L-SIG data */ 1941 if (format == RATE_MCS_HE_MSK) 1942 iwl_mvm_rx_he(mvm, skb, phy_data, queue); 1943 1944 iwl_mvm_decode_lsig(skb, phy_data); 1945 1946 rx_status->device_timestamp = phy_data->gp2_on_air_rise; 1947 1948 if (mvm->rx_ts_ptp && mvm->monitor_on) { 1949 u64 adj_time = 1950 iwl_mvm_ptp_get_adj_time(mvm, phy_data->gp2_on_air_rise * NSEC_PER_USEC); 1951 1952 rx_status->mactime = div64_u64(adj_time, NSEC_PER_USEC); 1953 rx_status->flag |= RX_FLAG_MACTIME_IS_RTAP_TS64; 1954 rx_status->flag &= ~RX_FLAG_MACTIME; 1955 } 1956 1957 rx_status->freq = ieee80211_channel_to_frequency(phy_data->channel, 1958 rx_status->band); 1959 iwl_mvm_get_signal_strength(mvm, rx_status, rate_n_flags, 1960 phy_data->energy_a, phy_data->energy_b); 1961 1962 /* using TLV format and must be after all fixed len fields */ 1963 if (format == RATE_MCS_EHT_MSK) 1964 iwl_mvm_rx_eht(mvm, skb, phy_data, queue); 1965 1966 if (unlikely(mvm->monitor_on)) 1967 iwl_mvm_add_rtap_sniffer_config(mvm, skb); 1968 1969 is_sgi = format == RATE_MCS_HE_MSK ? 1970 iwl_he_is_sgi(rate_n_flags) : 1971 rate_n_flags & RATE_MCS_SGI_MSK; 1972 1973 if (!(format == RATE_MCS_CCK_MSK) && is_sgi) 1974 rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI; 1975 1976 if (rate_n_flags & RATE_MCS_LDPC_MSK) 1977 rx_status->enc_flags |= RX_ENC_FLAG_LDPC; 1978 1979 switch (format) { 1980 case RATE_MCS_VHT_MSK: 1981 rx_status->encoding = RX_ENC_VHT; 1982 break; 1983 case RATE_MCS_HE_MSK: 1984 rx_status->encoding = RX_ENC_HE; 1985 rx_status->he_dcm = 1986 !!(rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK); 1987 break; 1988 case RATE_MCS_EHT_MSK: 1989 rx_status->encoding = RX_ENC_EHT; 1990 break; 1991 } 1992 1993 switch (format) { 1994 case RATE_MCS_HT_MSK: 1995 rx_status->encoding = RX_ENC_HT; 1996 rx_status->rate_idx = RATE_HT_MCS_INDEX(rate_n_flags); 1997 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT; 1998 break; 1999 case RATE_MCS_VHT_MSK: 2000 case RATE_MCS_HE_MSK: 2001 case RATE_MCS_EHT_MSK: 2002 rx_status->nss = 2003 u32_get_bits(rate_n_flags, RATE_MCS_NSS_MSK) + 1; 2004 rx_status->rate_idx = rate_n_flags & RATE_MCS_CODE_MSK; 2005 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT; 2006 break; 2007 default: { 2008 int rate = iwl_mvm_legacy_hw_idx_to_mac80211_idx(rate_n_flags, 2009 rx_status->band); 2010 2011 rx_status->rate_idx = rate; 2012 2013 if ((rate < 0 || rate > 0xFF)) { 2014 rx_status->rate_idx = 0; 2015 if (net_ratelimit()) 2016 IWL_ERR(mvm, "Invalid rate flags 0x%x, band %d,\n", 2017 rate_n_flags, rx_status->band); 2018 } 2019 2020 break; 2021 } 2022 } 2023 } 2024 2025 void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi, 2026 struct iwl_rx_cmd_buffer *rxb, int queue) 2027 { 2028 struct ieee80211_rx_status *rx_status; 2029 struct iwl_rx_packet *pkt = rxb_addr(rxb); 2030 struct iwl_rx_mpdu_desc *desc = (void *)pkt->data; 2031 struct ieee80211_hdr *hdr; 2032 u32 len; 2033 u32 pkt_len = iwl_rx_packet_payload_len(pkt); 2034 struct ieee80211_sta *sta = NULL; 2035 struct sk_buff *skb; 2036 u8 crypt_len = 0; 2037 u8 sta_id = le32_get_bits(desc->status, IWL_RX_MPDU_STATUS_STA_ID); 2038 size_t desc_size; 2039 struct iwl_mvm_rx_phy_data phy_data = {}; 2040 u32 format; 2041 2042 if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))) 2043 return; 2044 2045 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) 2046 desc_size = sizeof(*desc); 2047 else 2048 desc_size = IWL_RX_DESC_SIZE_V1; 2049 2050 if (unlikely(pkt_len < desc_size)) { 2051 IWL_DEBUG_DROP(mvm, "Bad REPLY_RX_MPDU_CMD size\n"); 2052 return; 2053 } 2054 2055 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) { 2056 phy_data.rate_n_flags = le32_to_cpu(desc->v3.rate_n_flags); 2057 phy_data.channel = desc->v3.channel; 2058 phy_data.gp2_on_air_rise = le32_to_cpu(desc->v3.gp2_on_air_rise); 2059 phy_data.energy_a = desc->v3.energy_a; 2060 phy_data.energy_b = desc->v3.energy_b; 2061 2062 phy_data.d0 = desc->v3.phy_data0; 2063 phy_data.d1 = desc->v3.phy_data1; 2064 phy_data.d2 = desc->v3.phy_data2; 2065 phy_data.d3 = desc->v3.phy_data3; 2066 phy_data.eht_d4 = desc->phy_eht_data4; 2067 phy_data.d5 = desc->v3.phy_data5; 2068 } else { 2069 phy_data.rate_n_flags = le32_to_cpu(desc->v1.rate_n_flags); 2070 phy_data.channel = desc->v1.channel; 2071 phy_data.gp2_on_air_rise = le32_to_cpu(desc->v1.gp2_on_air_rise); 2072 phy_data.energy_a = desc->v1.energy_a; 2073 phy_data.energy_b = desc->v1.energy_b; 2074 2075 phy_data.d0 = desc->v1.phy_data0; 2076 phy_data.d1 = desc->v1.phy_data1; 2077 phy_data.d2 = desc->v1.phy_data2; 2078 phy_data.d3 = desc->v1.phy_data3; 2079 } 2080 2081 if (iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP, 2082 REPLY_RX_MPDU_CMD, 0) < 4) { 2083 phy_data.rate_n_flags = iwl_new_rate_from_v1(phy_data.rate_n_flags); 2084 IWL_DEBUG_DROP(mvm, "Got old format rate, converting. New rate: 0x%x\n", 2085 phy_data.rate_n_flags); 2086 } 2087 2088 format = phy_data.rate_n_flags & RATE_MCS_MOD_TYPE_MSK; 2089 2090 len = le16_to_cpu(desc->mpdu_len); 2091 2092 if (unlikely(len + desc_size > pkt_len)) { 2093 IWL_DEBUG_DROP(mvm, "FW lied about packet len\n"); 2094 return; 2095 } 2096 2097 phy_data.with_data = true; 2098 phy_data.phy_info = le16_to_cpu(desc->phy_info); 2099 phy_data.d4 = desc->phy_data4; 2100 2101 hdr = (void *)(pkt->data + desc_size); 2102 /* Dont use dev_alloc_skb(), we'll have enough headroom once 2103 * ieee80211_hdr pulled. 2104 */ 2105 skb = alloc_skb(128, GFP_ATOMIC); 2106 if (!skb) { 2107 IWL_ERR(mvm, "alloc_skb failed\n"); 2108 return; 2109 } 2110 2111 if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) { 2112 /* 2113 * If the device inserted padding it means that (it thought) 2114 * the 802.11 header wasn't a multiple of 4 bytes long. In 2115 * this case, reserve two bytes at the start of the SKB to 2116 * align the payload properly in case we end up copying it. 2117 */ 2118 skb_reserve(skb, 2); 2119 } 2120 2121 rx_status = IEEE80211_SKB_RXCB(skb); 2122 2123 /* 2124 * Keep packets with CRC errors (and with overrun) for monitor mode 2125 * (otherwise the firmware discards them) but mark them as bad. 2126 */ 2127 if (!(desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_CRC_OK)) || 2128 !(desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_OVERRUN_OK))) { 2129 IWL_DEBUG_RX(mvm, "Bad CRC or FIFO: 0x%08X.\n", 2130 le32_to_cpu(desc->status)); 2131 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; 2132 } 2133 2134 /* set the preamble flag if appropriate */ 2135 if (format == RATE_MCS_CCK_MSK && 2136 phy_data.phy_info & IWL_RX_MPDU_PHY_SHORT_PREAMBLE) 2137 rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE; 2138 2139 if (likely(!(phy_data.phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD))) { 2140 u64 tsf_on_air_rise; 2141 2142 if (mvm->trans->trans_cfg->device_family >= 2143 IWL_DEVICE_FAMILY_AX210) 2144 tsf_on_air_rise = le64_to_cpu(desc->v3.tsf_on_air_rise); 2145 else 2146 tsf_on_air_rise = le64_to_cpu(desc->v1.tsf_on_air_rise); 2147 2148 rx_status->mactime = tsf_on_air_rise; 2149 /* TSF as indicated by the firmware is at INA time */ 2150 rx_status->flag |= RX_FLAG_MACTIME_PLCP_START; 2151 } 2152 2153 if (iwl_mvm_is_band_in_rx_supported(mvm)) { 2154 u8 band = BAND_IN_RX_STATUS(desc->mac_phy_idx); 2155 2156 rx_status->band = iwl_mvm_nl80211_band_from_phy(band); 2157 } else { 2158 rx_status->band = phy_data.channel > 14 ? NL80211_BAND_5GHZ : 2159 NL80211_BAND_2GHZ; 2160 } 2161 2162 /* update aggregation data for monitor sake on default queue */ 2163 if (!queue && (phy_data.phy_info & IWL_RX_MPDU_PHY_AMPDU)) { 2164 bool toggle_bit; 2165 2166 toggle_bit = phy_data.phy_info & IWL_RX_MPDU_PHY_AMPDU_TOGGLE; 2167 rx_status->flag |= RX_FLAG_AMPDU_DETAILS; 2168 /* 2169 * Toggle is switched whenever new aggregation starts. Make 2170 * sure ampdu_reference is never 0 so we can later use it to 2171 * see if the frame was really part of an A-MPDU or not. 2172 */ 2173 if (toggle_bit != mvm->ampdu_toggle) { 2174 mvm->ampdu_ref++; 2175 if (mvm->ampdu_ref == 0) 2176 mvm->ampdu_ref++; 2177 mvm->ampdu_toggle = toggle_bit; 2178 phy_data.first_subframe = true; 2179 } 2180 rx_status->ampdu_reference = mvm->ampdu_ref; 2181 } 2182 2183 rcu_read_lock(); 2184 2185 if (desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_SRC_STA_FOUND)) { 2186 if (!WARN_ON_ONCE(sta_id >= mvm->fw->ucode_capa.num_stations)) { 2187 struct ieee80211_link_sta *link_sta; 2188 2189 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); 2190 if (IS_ERR(sta)) 2191 sta = NULL; 2192 link_sta = rcu_dereference(mvm->fw_id_to_link_sta[sta_id]); 2193 2194 if (sta && sta->valid_links && link_sta) { 2195 rx_status->link_valid = 1; 2196 rx_status->link_id = link_sta->link_id; 2197 } 2198 } 2199 } else if (!is_multicast_ether_addr(hdr->addr2)) { 2200 /* 2201 * This is fine since we prevent two stations with the same 2202 * address from being added. 2203 */ 2204 sta = ieee80211_find_sta_by_ifaddr(mvm->hw, hdr->addr2, NULL); 2205 } 2206 2207 if (iwl_mvm_rx_crypto(mvm, sta, hdr, rx_status, phy_data.phy_info, desc, 2208 le32_to_cpu(pkt->len_n_flags), queue, 2209 &crypt_len)) { 2210 kfree_skb(skb); 2211 goto out; 2212 } 2213 2214 iwl_mvm_rx_fill_status(mvm, skb, &phy_data, queue); 2215 2216 if (sta) { 2217 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 2218 struct ieee80211_vif *tx_blocked_vif = 2219 rcu_dereference(mvm->csa_tx_blocked_vif); 2220 u8 baid = (u8)((le32_to_cpu(desc->reorder_data) & 2221 IWL_RX_MPDU_REORDER_BAID_MASK) >> 2222 IWL_RX_MPDU_REORDER_BAID_SHIFT); 2223 struct iwl_fw_dbg_trigger_tlv *trig; 2224 struct ieee80211_vif *vif = mvmsta->vif; 2225 2226 if (!mvm->tcm.paused && len >= sizeof(*hdr) && 2227 !is_multicast_ether_addr(hdr->addr1) && 2228 ieee80211_is_data(hdr->frame_control) && 2229 time_after(jiffies, mvm->tcm.ts + MVM_TCM_PERIOD)) 2230 schedule_delayed_work(&mvm->tcm.work, 0); 2231 2232 /* 2233 * We have tx blocked stations (with CS bit). If we heard 2234 * frames from a blocked station on a new channel we can 2235 * TX to it again. 2236 */ 2237 if (unlikely(tx_blocked_vif) && tx_blocked_vif == vif) { 2238 struct iwl_mvm_vif *mvmvif = 2239 iwl_mvm_vif_from_mac80211(tx_blocked_vif); 2240 struct iwl_rx_sta_csa rx_sta_csa = { 2241 .all_sta_unblocked = true, 2242 .vif = tx_blocked_vif, 2243 }; 2244 2245 if (mvmvif->csa_target_freq == rx_status->freq) 2246 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, 2247 false); 2248 ieee80211_iterate_stations_atomic(mvm->hw, 2249 iwl_mvm_rx_get_sta_block_tx, 2250 &rx_sta_csa); 2251 2252 if (rx_sta_csa.all_sta_unblocked) { 2253 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); 2254 /* Unblock BCAST / MCAST station */ 2255 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false); 2256 cancel_delayed_work(&mvm->cs_tx_unblock_dwork); 2257 } 2258 } 2259 2260 rs_update_last_rssi(mvm, mvmsta, rx_status); 2261 2262 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, 2263 ieee80211_vif_to_wdev(vif), 2264 FW_DBG_TRIGGER_RSSI); 2265 2266 if (trig && ieee80211_is_beacon(hdr->frame_control)) { 2267 struct iwl_fw_dbg_trigger_low_rssi *rssi_trig; 2268 s32 rssi; 2269 2270 rssi_trig = (void *)trig->data; 2271 rssi = le32_to_cpu(rssi_trig->rssi); 2272 2273 if (rx_status->signal < rssi) 2274 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 2275 NULL); 2276 } 2277 2278 if (ieee80211_is_data(hdr->frame_control)) 2279 iwl_mvm_rx_csum(mvm, sta, skb, pkt); 2280 2281 if (iwl_mvm_is_dup(sta, queue, rx_status, hdr, desc)) { 2282 IWL_DEBUG_DROP(mvm, "Dropping duplicate packet 0x%x\n", 2283 le16_to_cpu(hdr->seq_ctrl)); 2284 kfree_skb(skb); 2285 goto out; 2286 } 2287 2288 /* 2289 * Our hardware de-aggregates AMSDUs but copies the mac header 2290 * as it to the de-aggregated MPDUs. We need to turn off the 2291 * AMSDU bit in the QoS control ourselves. 2292 * In addition, HW reverses addr3 and addr4 - reverse it back. 2293 */ 2294 if ((desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU) && 2295 !WARN_ON(!ieee80211_is_data_qos(hdr->frame_control))) { 2296 u8 *qc = ieee80211_get_qos_ctl(hdr); 2297 2298 *qc &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT; 2299 2300 if (mvm->trans->trans_cfg->device_family == 2301 IWL_DEVICE_FAMILY_9000) { 2302 iwl_mvm_flip_address(hdr->addr3); 2303 2304 if (ieee80211_has_a4(hdr->frame_control)) 2305 iwl_mvm_flip_address(hdr->addr4); 2306 } 2307 } 2308 if (baid != IWL_RX_REORDER_DATA_INVALID_BAID) { 2309 u32 reorder_data = le32_to_cpu(desc->reorder_data); 2310 2311 iwl_mvm_agg_rx_received(mvm, reorder_data, baid); 2312 } 2313 2314 if (ieee80211_is_data(hdr->frame_control)) { 2315 u8 sub_frame_idx = desc->amsdu_info & 2316 IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK; 2317 2318 /* 0 means not an A-MSDU, and 1 means a new A-MSDU */ 2319 if (!sub_frame_idx || sub_frame_idx == 1) 2320 iwl_mvm_count_mpdu(mvmsta, sta_id, 1, false, 2321 queue); 2322 } 2323 } 2324 2325 /* management stuff on default queue */ 2326 if (!queue) { 2327 if (unlikely((ieee80211_is_beacon(hdr->frame_control) || 2328 ieee80211_is_probe_resp(hdr->frame_control)) && 2329 mvm->sched_scan_pass_all == 2330 SCHED_SCAN_PASS_ALL_ENABLED)) 2331 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_FOUND; 2332 2333 if (unlikely(ieee80211_is_beacon(hdr->frame_control) || 2334 ieee80211_is_probe_resp(hdr->frame_control))) 2335 rx_status->boottime_ns = ktime_get_boottime_ns(); 2336 } 2337 2338 if (iwl_mvm_create_skb(mvm, skb, hdr, len, crypt_len, rxb)) { 2339 kfree_skb(skb); 2340 goto out; 2341 } 2342 2343 if (!iwl_mvm_reorder(mvm, napi, queue, sta, skb, desc) && 2344 likely(!iwl_mvm_time_sync_frame(mvm, skb, hdr->addr2)) && 2345 likely(!iwl_mvm_mei_filter_scan(mvm, skb))) { 2346 if (mvm->trans->trans_cfg->device_family == IWL_DEVICE_FAMILY_9000 && 2347 (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU) && 2348 !(desc->amsdu_info & IWL_RX_MPDU_AMSDU_LAST_SUBFRAME)) 2349 rx_status->flag |= RX_FLAG_AMSDU_MORE; 2350 2351 iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb, queue, sta); 2352 } 2353 out: 2354 rcu_read_unlock(); 2355 } 2356 2357 void iwl_mvm_rx_monitor_no_data(struct iwl_mvm *mvm, struct napi_struct *napi, 2358 struct iwl_rx_cmd_buffer *rxb, int queue) 2359 { 2360 struct ieee80211_rx_status *rx_status; 2361 struct iwl_rx_packet *pkt = rxb_addr(rxb); 2362 struct iwl_rx_no_data_ver_3 *desc = (void *)pkt->data; 2363 u32 rssi; 2364 struct ieee80211_sta *sta = NULL; 2365 struct sk_buff *skb; 2366 struct iwl_mvm_rx_phy_data phy_data; 2367 u32 format; 2368 2369 if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))) 2370 return; 2371 2372 if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(struct iwl_rx_no_data))) 2373 return; 2374 2375 rssi = le32_to_cpu(desc->rssi); 2376 phy_data.d0 = desc->phy_info[0]; 2377 phy_data.d1 = desc->phy_info[1]; 2378 phy_data.phy_info = IWL_RX_MPDU_PHY_TSF_OVERLOAD; 2379 phy_data.gp2_on_air_rise = le32_to_cpu(desc->on_air_rise_time); 2380 phy_data.rate_n_flags = le32_to_cpu(desc->rate); 2381 phy_data.energy_a = u32_get_bits(rssi, RX_NO_DATA_CHAIN_A_MSK); 2382 phy_data.energy_b = u32_get_bits(rssi, RX_NO_DATA_CHAIN_B_MSK); 2383 phy_data.channel = u32_get_bits(rssi, RX_NO_DATA_CHANNEL_MSK); 2384 phy_data.with_data = false; 2385 phy_data.rx_vec[0] = desc->rx_vec[0]; 2386 phy_data.rx_vec[1] = desc->rx_vec[1]; 2387 2388 if (iwl_fw_lookup_notif_ver(mvm->fw, DATA_PATH_GROUP, 2389 RX_NO_DATA_NOTIF, 0) < 2) { 2390 IWL_DEBUG_DROP(mvm, "Got an old rate format. Old rate: 0x%x\n", 2391 phy_data.rate_n_flags); 2392 phy_data.rate_n_flags = iwl_new_rate_from_v1(phy_data.rate_n_flags); 2393 IWL_DEBUG_DROP(mvm, " Rate after conversion to the new format: 0x%x\n", 2394 phy_data.rate_n_flags); 2395 } 2396 2397 format = phy_data.rate_n_flags & RATE_MCS_MOD_TYPE_MSK; 2398 2399 if (iwl_fw_lookup_notif_ver(mvm->fw, DATA_PATH_GROUP, 2400 RX_NO_DATA_NOTIF, 0) >= 3) { 2401 if (unlikely(iwl_rx_packet_payload_len(pkt) < 2402 sizeof(struct iwl_rx_no_data_ver_3))) 2403 /* invalid len for ver 3 */ 2404 return; 2405 phy_data.rx_vec[2] = desc->rx_vec[2]; 2406 phy_data.rx_vec[3] = desc->rx_vec[3]; 2407 } else { 2408 if (format == RATE_MCS_EHT_MSK) 2409 /* no support for EHT before version 3 API */ 2410 return; 2411 } 2412 2413 /* Dont use dev_alloc_skb(), we'll have enough headroom once 2414 * ieee80211_hdr pulled. 2415 */ 2416 skb = alloc_skb(128, GFP_ATOMIC); 2417 if (!skb) { 2418 IWL_ERR(mvm, "alloc_skb failed\n"); 2419 return; 2420 } 2421 2422 rx_status = IEEE80211_SKB_RXCB(skb); 2423 2424 /* 0-length PSDU */ 2425 rx_status->flag |= RX_FLAG_NO_PSDU; 2426 2427 /* mark as failed PLCP on any errors to skip checks in mac80211 */ 2428 if (le32_get_bits(desc->info, RX_NO_DATA_INFO_ERR_MSK) != 2429 RX_NO_DATA_INFO_ERR_NONE) 2430 rx_status->flag |= RX_FLAG_FAILED_PLCP_CRC; 2431 2432 switch (le32_get_bits(desc->info, RX_NO_DATA_INFO_TYPE_MSK)) { 2433 case RX_NO_DATA_INFO_TYPE_NDP: 2434 rx_status->zero_length_psdu_type = 2435 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_SOUNDING; 2436 break; 2437 case RX_NO_DATA_INFO_TYPE_MU_UNMATCHED: 2438 case RX_NO_DATA_INFO_TYPE_TB_UNMATCHED: 2439 rx_status->zero_length_psdu_type = 2440 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_NOT_CAPTURED; 2441 break; 2442 default: 2443 rx_status->zero_length_psdu_type = 2444 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_VENDOR; 2445 break; 2446 } 2447 2448 rx_status->band = phy_data.channel > 14 ? NL80211_BAND_5GHZ : 2449 NL80211_BAND_2GHZ; 2450 2451 iwl_mvm_rx_fill_status(mvm, skb, &phy_data, queue); 2452 2453 /* no more radio tap info should be put after this point. 2454 * 2455 * We mark it as mac header, for upper layers to know where 2456 * all radio tap header ends. 2457 * 2458 * Since data doesn't move data while putting data on skb and that is 2459 * the only way we use, data + len is the next place that hdr would be put 2460 */ 2461 skb_set_mac_header(skb, skb->len); 2462 2463 /* 2464 * Override the nss from the rx_vec since the rate_n_flags has 2465 * only 2 bits for the nss which gives a max of 4 ss but there 2466 * may be up to 8 spatial streams. 2467 */ 2468 switch (format) { 2469 case RATE_MCS_VHT_MSK: 2470 rx_status->nss = 2471 le32_get_bits(desc->rx_vec[0], 2472 RX_NO_DATA_RX_VEC0_VHT_NSTS_MSK) + 1; 2473 break; 2474 case RATE_MCS_HE_MSK: 2475 rx_status->nss = 2476 le32_get_bits(desc->rx_vec[0], 2477 RX_NO_DATA_RX_VEC0_HE_NSTS_MSK) + 1; 2478 break; 2479 case RATE_MCS_EHT_MSK: 2480 rx_status->nss = 2481 le32_get_bits(desc->rx_vec[2], 2482 RX_NO_DATA_RX_VEC2_EHT_NSTS_MSK) + 1; 2483 } 2484 2485 rcu_read_lock(); 2486 ieee80211_rx_napi(mvm->hw, sta, skb, napi); 2487 rcu_read_unlock(); 2488 } 2489 2490 void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi, 2491 struct iwl_rx_cmd_buffer *rxb, int queue) 2492 { 2493 struct iwl_rx_packet *pkt = rxb_addr(rxb); 2494 struct iwl_frame_release *release = (void *)pkt->data; 2495 2496 if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(*release))) 2497 return; 2498 2499 iwl_mvm_release_frames_from_notif(mvm, napi, release->baid, 2500 le16_to_cpu(release->nssn), 2501 queue); 2502 } 2503 2504 void iwl_mvm_rx_bar_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi, 2505 struct iwl_rx_cmd_buffer *rxb, int queue) 2506 { 2507 struct iwl_rx_packet *pkt = rxb_addr(rxb); 2508 struct iwl_bar_frame_release *release = (void *)pkt->data; 2509 unsigned int baid = le32_get_bits(release->ba_info, 2510 IWL_BAR_FRAME_RELEASE_BAID_MASK); 2511 unsigned int nssn = le32_get_bits(release->ba_info, 2512 IWL_BAR_FRAME_RELEASE_NSSN_MASK); 2513 unsigned int sta_id = le32_get_bits(release->sta_tid, 2514 IWL_BAR_FRAME_RELEASE_STA_MASK); 2515 unsigned int tid = le32_get_bits(release->sta_tid, 2516 IWL_BAR_FRAME_RELEASE_TID_MASK); 2517 struct iwl_mvm_baid_data *baid_data; 2518 2519 if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(*release))) 2520 return; 2521 2522 if (WARN_ON_ONCE(baid == IWL_RX_REORDER_DATA_INVALID_BAID || 2523 baid >= ARRAY_SIZE(mvm->baid_map))) 2524 return; 2525 2526 rcu_read_lock(); 2527 baid_data = rcu_dereference(mvm->baid_map[baid]); 2528 if (!baid_data) { 2529 IWL_DEBUG_RX(mvm, 2530 "Got valid BAID %d but not allocated, invalid BAR release!\n", 2531 baid); 2532 goto out; 2533 } 2534 2535 if (WARN(tid != baid_data->tid || sta_id > IWL_STATION_COUNT_MAX || 2536 !(baid_data->sta_mask & BIT(sta_id)), 2537 "baid 0x%x is mapped to sta_mask:0x%x tid:%d, but BAR release received for sta:%d tid:%d\n", 2538 baid, baid_data->sta_mask, baid_data->tid, sta_id, 2539 tid)) 2540 goto out; 2541 2542 IWL_DEBUG_DROP(mvm, "Received a BAR, expect packet loss: nssn %d\n", 2543 nssn); 2544 2545 iwl_mvm_release_frames_from_notif(mvm, napi, baid, nssn, queue); 2546 out: 2547 rcu_read_unlock(); 2548 } 2549