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