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