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