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