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