1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause 2 /* 3 * Copyright (C) 2012-2014, 2018-2020 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 13 static void *iwl_mvm_skb_get_hdr(struct sk_buff *skb) 14 { 15 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 16 u8 *data = skb->data; 17 18 /* Alignment concerns */ 19 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) % 4); 20 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) % 4); 21 BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_lsig) % 4); 22 BUILD_BUG_ON(sizeof(struct ieee80211_vendor_radiotap) % 4); 23 24 if (rx_status->flag & RX_FLAG_RADIOTAP_HE) 25 data += sizeof(struct ieee80211_radiotap_he); 26 if (rx_status->flag & RX_FLAG_RADIOTAP_HE_MU) 27 data += sizeof(struct ieee80211_radiotap_he_mu); 28 if (rx_status->flag & RX_FLAG_RADIOTAP_LSIG) 29 data += sizeof(struct ieee80211_radiotap_lsig); 30 if (rx_status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) { 31 struct ieee80211_vendor_radiotap *radiotap = (void *)data; 32 33 data += sizeof(*radiotap) + radiotap->len + radiotap->pad; 34 } 35 36 return data; 37 } 38 39 static inline int iwl_mvm_check_pn(struct iwl_mvm *mvm, struct sk_buff *skb, 40 int queue, struct ieee80211_sta *sta) 41 { 42 struct iwl_mvm_sta *mvmsta; 43 struct ieee80211_hdr *hdr = iwl_mvm_skb_get_hdr(skb); 44 struct ieee80211_rx_status *stats = IEEE80211_SKB_RXCB(skb); 45 struct iwl_mvm_key_pn *ptk_pn; 46 int res; 47 u8 tid, keyidx; 48 u8 pn[IEEE80211_CCMP_PN_LEN]; 49 u8 *extiv; 50 51 /* do PN checking */ 52 53 /* multicast and non-data only arrives on default queue */ 54 if (!ieee80211_is_data(hdr->frame_control) || 55 is_multicast_ether_addr(hdr->addr1)) 56 return 0; 57 58 /* do not check PN for open AP */ 59 if (!(stats->flag & RX_FLAG_DECRYPTED)) 60 return 0; 61 62 /* 63 * avoid checking for default queue - we don't want to replicate 64 * all the logic that's necessary for checking the PN on fragmented 65 * frames, leave that to mac80211 66 */ 67 if (queue == 0) 68 return 0; 69 70 /* if we are here - this for sure is either CCMP or GCMP */ 71 if (IS_ERR_OR_NULL(sta)) { 72 IWL_ERR(mvm, 73 "expected hw-decrypted unicast frame for station\n"); 74 return -1; 75 } 76 77 mvmsta = iwl_mvm_sta_from_mac80211(sta); 78 79 extiv = (u8 *)hdr + ieee80211_hdrlen(hdr->frame_control); 80 keyidx = extiv[3] >> 6; 81 82 ptk_pn = rcu_dereference(mvmsta->ptk_pn[keyidx]); 83 if (!ptk_pn) 84 return -1; 85 86 if (ieee80211_is_data_qos(hdr->frame_control)) 87 tid = ieee80211_get_tid(hdr); 88 else 89 tid = 0; 90 91 /* we don't use HCCA/802.11 QoS TSPECs, so drop such frames */ 92 if (tid >= IWL_MAX_TID_COUNT) 93 return -1; 94 95 /* load pn */ 96 pn[0] = extiv[7]; 97 pn[1] = extiv[6]; 98 pn[2] = extiv[5]; 99 pn[3] = extiv[4]; 100 pn[4] = extiv[1]; 101 pn[5] = extiv[0]; 102 103 res = memcmp(pn, ptk_pn->q[queue].pn[tid], IEEE80211_CCMP_PN_LEN); 104 if (res < 0) 105 return -1; 106 if (!res && !(stats->flag & RX_FLAG_ALLOW_SAME_PN)) 107 return -1; 108 109 memcpy(ptk_pn->q[queue].pn[tid], pn, IEEE80211_CCMP_PN_LEN); 110 stats->flag |= RX_FLAG_PN_VALIDATED; 111 112 return 0; 113 } 114 115 /* iwl_mvm_create_skb Adds the rxb to a new skb */ 116 static int iwl_mvm_create_skb(struct iwl_mvm *mvm, struct sk_buff *skb, 117 struct ieee80211_hdr *hdr, u16 len, u8 crypt_len, 118 struct iwl_rx_cmd_buffer *rxb) 119 { 120 struct iwl_rx_packet *pkt = rxb_addr(rxb); 121 struct iwl_rx_mpdu_desc *desc = (void *)pkt->data; 122 unsigned int headlen, fraglen, pad_len = 0; 123 unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control); 124 125 if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) { 126 len -= 2; 127 pad_len = 2; 128 } 129 130 /* If frame is small enough to fit in skb->head, pull it completely. 131 * If not, only pull ieee80211_hdr (including crypto if present, and 132 * an additional 8 bytes for SNAP/ethertype, see below) so that 133 * splice() or TCP coalesce are more efficient. 134 * 135 * Since, in addition, ieee80211_data_to_8023() always pull in at 136 * least 8 bytes (possibly more for mesh) we can do the same here 137 * to save the cost of doing it later. That still doesn't pull in 138 * the actual IP header since the typical case has a SNAP header. 139 * If the latter changes (there are efforts in the standards group 140 * to do so) we should revisit this and ieee80211_data_to_8023(). 141 */ 142 headlen = (len <= skb_tailroom(skb)) ? len : 143 hdrlen + crypt_len + 8; 144 145 /* The firmware may align the packet to DWORD. 146 * The padding is inserted after the IV. 147 * After copying the header + IV skip the padding if 148 * present before copying packet data. 149 */ 150 hdrlen += crypt_len; 151 152 if (WARN_ONCE(headlen < hdrlen, 153 "invalid packet lengths (hdrlen=%d, len=%d, crypt_len=%d)\n", 154 hdrlen, len, crypt_len)) { 155 /* 156 * We warn and trace because we want to be able to see 157 * it in trace-cmd as well. 158 */ 159 IWL_DEBUG_RX(mvm, 160 "invalid packet lengths (hdrlen=%d, len=%d, crypt_len=%d)\n", 161 hdrlen, len, crypt_len); 162 return -EINVAL; 163 } 164 165 skb_put_data(skb, hdr, hdrlen); 166 skb_put_data(skb, (u8 *)hdr + hdrlen + pad_len, headlen - hdrlen); 167 168 /* 169 * If we did CHECKSUM_COMPLETE, the hardware only does it right for 170 * certain cases and starts the checksum after the SNAP. Check if 171 * this is the case - it's easier to just bail out to CHECKSUM_NONE 172 * in the cases the hardware didn't handle, since it's rare to see 173 * such packets, even though the hardware did calculate the checksum 174 * in this case, just starting after the MAC header instead. 175 */ 176 if (skb->ip_summed == CHECKSUM_COMPLETE) { 177 struct { 178 u8 hdr[6]; 179 __be16 type; 180 } __packed *shdr = (void *)((u8 *)hdr + hdrlen + pad_len); 181 182 if (unlikely(headlen - hdrlen < sizeof(*shdr) || 183 !ether_addr_equal(shdr->hdr, rfc1042_header) || 184 (shdr->type != htons(ETH_P_IP) && 185 shdr->type != htons(ETH_P_ARP) && 186 shdr->type != htons(ETH_P_IPV6) && 187 shdr->type != htons(ETH_P_8021Q) && 188 shdr->type != htons(ETH_P_PAE) && 189 shdr->type != htons(ETH_P_TDLS)))) 190 skb->ip_summed = CHECKSUM_NONE; 191 } 192 193 fraglen = len - headlen; 194 195 if (fraglen) { 196 int offset = (void *)hdr + headlen + pad_len - 197 rxb_addr(rxb) + rxb_offset(rxb); 198 199 skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset, 200 fraglen, rxb->truesize); 201 } 202 203 return 0; 204 } 205 206 static void iwl_mvm_add_rtap_sniffer_config(struct iwl_mvm *mvm, 207 struct sk_buff *skb) 208 { 209 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 210 struct ieee80211_vendor_radiotap *radiotap; 211 const int size = sizeof(*radiotap) + sizeof(__le16); 212 213 if (!mvm->cur_aid) 214 return; 215 216 /* ensure alignment */ 217 BUILD_BUG_ON((size + 2) % 4); 218 219 radiotap = skb_put(skb, size + 2); 220 radiotap->align = 1; 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->subns = 1; 227 radiotap->present = 0x1; 228 radiotap->len = size - sizeof(*radiotap); 229 radiotap->pad = 2; 230 231 /* fill the data now */ 232 memcpy(radiotap->data, &mvm->cur_aid, sizeof(mvm->cur_aid)); 233 /* and clear the padding */ 234 memset(radiotap->data + sizeof(__le16), 0, radiotap->pad); 235 236 rx_status->flag |= RX_FLAG_RADIOTAP_VENDOR_DATA; 237 } 238 239 /* iwl_mvm_pass_packet_to_mac80211 - passes the packet for mac80211 */ 240 static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm *mvm, 241 struct napi_struct *napi, 242 struct sk_buff *skb, int queue, 243 struct ieee80211_sta *sta, 244 bool csi) 245 { 246 if (iwl_mvm_check_pn(mvm, skb, queue, sta)) 247 kfree_skb(skb); 248 else 249 ieee80211_rx_napi(mvm->hw, sta, skb, napi); 250 } 251 252 static void iwl_mvm_get_signal_strength(struct iwl_mvm *mvm, 253 struct ieee80211_rx_status *rx_status, 254 u32 rate_n_flags, int energy_a, 255 int energy_b) 256 { 257 int max_energy; 258 u32 rate_flags = rate_n_flags; 259 260 energy_a = energy_a ? -energy_a : S8_MIN; 261 energy_b = energy_b ? -energy_b : S8_MIN; 262 max_energy = max(energy_a, energy_b); 263 264 IWL_DEBUG_STATS(mvm, "energy In A %d B %d, and max %d\n", 265 energy_a, energy_b, max_energy); 266 267 rx_status->signal = max_energy; 268 rx_status->chains = 269 (rate_flags & RATE_MCS_ANT_AB_MSK) >> RATE_MCS_ANT_POS; 270 rx_status->chain_signal[0] = energy_a; 271 rx_status->chain_signal[1] = energy_b; 272 rx_status->chain_signal[2] = S8_MIN; 273 } 274 275 static int iwl_mvm_rx_mgmt_crypto(struct ieee80211_sta *sta, 276 struct ieee80211_hdr *hdr, 277 struct iwl_rx_mpdu_desc *desc, 278 u32 status) 279 { 280 struct iwl_mvm_sta *mvmsta; 281 struct iwl_mvm_vif *mvmvif; 282 u8 fwkeyid = u32_get_bits(status, IWL_RX_MPDU_STATUS_KEY); 283 u8 keyid; 284 struct ieee80211_key_conf *key; 285 u32 len = le16_to_cpu(desc->mpdu_len); 286 const u8 *frame = (void *)hdr; 287 288 /* 289 * For non-beacon, we don't really care. But beacons may 290 * be filtered out, and we thus need the firmware's replay 291 * detection, otherwise beacons the firmware previously 292 * filtered could be replayed, or something like that, and 293 * it can filter a lot - though usually only if nothing has 294 * changed. 295 */ 296 if (!ieee80211_is_beacon(hdr->frame_control)) 297 return 0; 298 299 /* good cases */ 300 if (likely(status & IWL_RX_MPDU_STATUS_MIC_OK && 301 !(status & IWL_RX_MPDU_STATUS_REPLAY_ERROR))) 302 return 0; 303 304 if (!sta) 305 return -1; 306 307 mvmsta = iwl_mvm_sta_from_mac80211(sta); 308 309 /* what? */ 310 if (fwkeyid != 6 && fwkeyid != 7) 311 return -1; 312 313 mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif); 314 315 key = rcu_dereference(mvmvif->bcn_prot.keys[fwkeyid - 6]); 316 if (!key) 317 return -1; 318 319 if (len < key->icv_len + IEEE80211_GMAC_PN_LEN + 2) 320 return -1; 321 322 /* 323 * See if the key ID matches - if not this may be due to a 324 * switch and the firmware may erroneously report !MIC_OK. 325 */ 326 keyid = frame[len - key->icv_len - IEEE80211_GMAC_PN_LEN - 2]; 327 if (keyid != fwkeyid) 328 return -1; 329 330 /* Report status to mac80211 */ 331 if (!(status & IWL_RX_MPDU_STATUS_MIC_OK)) 332 ieee80211_key_mic_failure(key); 333 else if (status & IWL_RX_MPDU_STATUS_REPLAY_ERROR) 334 ieee80211_key_replay(key); 335 336 return -1; 337 } 338 339 static int iwl_mvm_rx_crypto(struct iwl_mvm *mvm, struct ieee80211_sta *sta, 340 struct ieee80211_hdr *hdr, 341 struct ieee80211_rx_status *stats, u16 phy_info, 342 struct iwl_rx_mpdu_desc *desc, 343 u32 pkt_flags, int queue, u8 *crypt_len) 344 { 345 u32 status = le32_to_cpu(desc->status); 346 347 /* 348 * Drop UNKNOWN frames in aggregation, unless in monitor mode 349 * (where we don't have the keys). 350 * We limit this to aggregation because in TKIP this is a valid 351 * scenario, since we may not have the (correct) TTAK (phase 1 352 * key) in the firmware. 353 */ 354 if (phy_info & IWL_RX_MPDU_PHY_AMPDU && 355 (status & IWL_RX_MPDU_STATUS_SEC_MASK) == 356 IWL_RX_MPDU_STATUS_SEC_UNKNOWN && !mvm->monitor_on) 357 return -1; 358 359 if (!ieee80211_has_protected(hdr->frame_control) || 360 (status & IWL_RX_MPDU_STATUS_SEC_MASK) == 361 IWL_RX_MPDU_STATUS_SEC_NONE) 362 return 0; 363 364 /* TODO: handle packets encrypted with unknown alg */ 365 366 switch (status & IWL_RX_MPDU_STATUS_SEC_MASK) { 367 case IWL_RX_MPDU_STATUS_SEC_CCM: 368 case IWL_RX_MPDU_STATUS_SEC_GCM: 369 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN != IEEE80211_GCMP_PN_LEN); 370 /* alg is CCM: check MIC only */ 371 if (!(status & IWL_RX_MPDU_STATUS_MIC_OK)) 372 return -1; 373 374 stats->flag |= RX_FLAG_DECRYPTED; 375 if (pkt_flags & FH_RSCSR_RADA_EN) 376 stats->flag |= RX_FLAG_MIC_STRIPPED; 377 *crypt_len = IEEE80211_CCMP_HDR_LEN; 378 return 0; 379 case IWL_RX_MPDU_STATUS_SEC_TKIP: 380 /* Don't drop the frame and decrypt it in SW */ 381 if (!fw_has_api(&mvm->fw->ucode_capa, 382 IWL_UCODE_TLV_API_DEPRECATE_TTAK) && 383 !(status & IWL_RX_MPDU_RES_STATUS_TTAK_OK)) 384 return 0; 385 386 if (mvm->trans->trans_cfg->gen2 && 387 !(status & RX_MPDU_RES_STATUS_MIC_OK)) 388 stats->flag |= RX_FLAG_MMIC_ERROR; 389 390 *crypt_len = IEEE80211_TKIP_IV_LEN; 391 fallthrough; 392 case IWL_RX_MPDU_STATUS_SEC_WEP: 393 if (!(status & IWL_RX_MPDU_STATUS_ICV_OK)) 394 return -1; 395 396 stats->flag |= RX_FLAG_DECRYPTED; 397 if ((status & IWL_RX_MPDU_STATUS_SEC_MASK) == 398 IWL_RX_MPDU_STATUS_SEC_WEP) 399 *crypt_len = IEEE80211_WEP_IV_LEN; 400 401 if (pkt_flags & FH_RSCSR_RADA_EN) { 402 stats->flag |= RX_FLAG_ICV_STRIPPED; 403 if (mvm->trans->trans_cfg->gen2) 404 stats->flag |= RX_FLAG_MMIC_STRIPPED; 405 } 406 407 return 0; 408 case IWL_RX_MPDU_STATUS_SEC_EXT_ENC: 409 if (!(status & IWL_RX_MPDU_STATUS_MIC_OK)) 410 return -1; 411 stats->flag |= RX_FLAG_DECRYPTED; 412 return 0; 413 case RX_MPDU_RES_STATUS_SEC_CMAC_GMAC_ENC: 414 return iwl_mvm_rx_mgmt_crypto(sta, hdr, desc, status); 415 default: 416 /* 417 * Sometimes we can get frames that were not decrypted 418 * because the firmware didn't have the keys yet. This can 419 * happen after connection where we can get multicast frames 420 * before the GTK is installed. 421 * Silently drop those frames. 422 * Also drop un-decrypted frames in monitor mode. 423 */ 424 if (!is_multicast_ether_addr(hdr->addr1) && 425 !mvm->monitor_on && net_ratelimit()) 426 IWL_ERR(mvm, "Unhandled alg: 0x%x\n", status); 427 } 428 429 return 0; 430 } 431 432 static void iwl_mvm_rx_csum(struct iwl_mvm *mvm, 433 struct ieee80211_sta *sta, 434 struct sk_buff *skb, 435 struct iwl_rx_packet *pkt) 436 { 437 struct iwl_rx_mpdu_desc *desc = (void *)pkt->data; 438 439 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) { 440 if (pkt->len_n_flags & cpu_to_le32(FH_RSCSR_RPA_EN)) { 441 u16 hwsum = be16_to_cpu(desc->v3.raw_xsum); 442 443 skb->ip_summed = CHECKSUM_COMPLETE; 444 skb->csum = csum_unfold(~(__force __sum16)hwsum); 445 } 446 } else { 447 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 448 struct iwl_mvm_vif *mvmvif; 449 u16 flags = le16_to_cpu(desc->l3l4_flags); 450 u8 l3_prot = (u8)((flags & IWL_RX_L3L4_L3_PROTO_MASK) >> 451 IWL_RX_L3_PROTO_POS); 452 453 mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif); 454 455 if (mvmvif->features & NETIF_F_RXCSUM && 456 flags & IWL_RX_L3L4_TCP_UDP_CSUM_OK && 457 (flags & IWL_RX_L3L4_IP_HDR_CSUM_OK || 458 l3_prot == IWL_RX_L3_TYPE_IPV6 || 459 l3_prot == IWL_RX_L3_TYPE_IPV6_FRAG)) 460 skb->ip_summed = CHECKSUM_UNNECESSARY; 461 } 462 } 463 464 /* 465 * returns true if a packet is a duplicate and should be dropped. 466 * Updates AMSDU PN tracking info 467 */ 468 static bool iwl_mvm_is_dup(struct ieee80211_sta *sta, int queue, 469 struct ieee80211_rx_status *rx_status, 470 struct ieee80211_hdr *hdr, 471 struct iwl_rx_mpdu_desc *desc) 472 { 473 struct iwl_mvm_sta *mvm_sta; 474 struct iwl_mvm_rxq_dup_data *dup_data; 475 u8 tid, sub_frame_idx; 476 477 if (WARN_ON(IS_ERR_OR_NULL(sta))) 478 return false; 479 480 mvm_sta = iwl_mvm_sta_from_mac80211(sta); 481 dup_data = &mvm_sta->dup_data[queue]; 482 483 /* 484 * Drop duplicate 802.11 retransmissions 485 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery") 486 */ 487 if (ieee80211_is_ctl(hdr->frame_control) || 488 ieee80211_is_qos_nullfunc(hdr->frame_control) || 489 is_multicast_ether_addr(hdr->addr1)) { 490 rx_status->flag |= RX_FLAG_DUP_VALIDATED; 491 return false; 492 } 493 494 if (ieee80211_is_data_qos(hdr->frame_control)) 495 /* frame has qos control */ 496 tid = ieee80211_get_tid(hdr); 497 else 498 tid = IWL_MAX_TID_COUNT; 499 500 /* If this wasn't a part of an A-MSDU the sub-frame index will be 0 */ 501 sub_frame_idx = desc->amsdu_info & 502 IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK; 503 504 if (unlikely(ieee80211_has_retry(hdr->frame_control) && 505 dup_data->last_seq[tid] == hdr->seq_ctrl && 506 dup_data->last_sub_frame[tid] >= sub_frame_idx)) 507 return true; 508 509 /* Allow same PN as the first subframe for following sub frames */ 510 if (dup_data->last_seq[tid] == hdr->seq_ctrl && 511 sub_frame_idx > dup_data->last_sub_frame[tid] && 512 desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU) 513 rx_status->flag |= RX_FLAG_ALLOW_SAME_PN; 514 515 dup_data->last_seq[tid] = hdr->seq_ctrl; 516 dup_data->last_sub_frame[tid] = sub_frame_idx; 517 518 rx_status->flag |= RX_FLAG_DUP_VALIDATED; 519 520 return false; 521 } 522 523 int iwl_mvm_notify_rx_queue(struct iwl_mvm *mvm, u32 rxq_mask, 524 const struct iwl_mvm_internal_rxq_notif *notif, 525 u32 notif_size, bool async) 526 { 527 u8 buf[sizeof(struct iwl_rxq_sync_cmd) + 528 sizeof(struct iwl_mvm_rss_sync_notif)]; 529 struct iwl_rxq_sync_cmd *cmd = (void *)buf; 530 u32 data_size = sizeof(*cmd) + notif_size; 531 int ret; 532 533 /* 534 * size must be a multiple of DWORD 535 * Ensure we don't overflow buf 536 */ 537 if (WARN_ON(notif_size & 3 || 538 notif_size > sizeof(struct iwl_mvm_rss_sync_notif))) 539 return -EINVAL; 540 541 cmd->rxq_mask = cpu_to_le32(rxq_mask); 542 cmd->count = cpu_to_le32(notif_size); 543 cmd->flags = 0; 544 memcpy(cmd->payload, notif, notif_size); 545 546 ret = iwl_mvm_send_cmd_pdu(mvm, 547 WIDE_ID(DATA_PATH_GROUP, 548 TRIGGER_RX_QUEUES_NOTIF_CMD), 549 async ? CMD_ASYNC : 0, data_size, cmd); 550 551 return ret; 552 } 553 554 /* 555 * Returns true if sn2 - buffer_size < sn1 < sn2. 556 * To be used only in order to compare reorder buffer head with NSSN. 557 * We fully trust NSSN unless it is behind us due to reorder timeout. 558 * Reorder timeout can only bring us up to buffer_size SNs ahead of NSSN. 559 */ 560 static bool iwl_mvm_is_sn_less(u16 sn1, u16 sn2, u16 buffer_size) 561 { 562 return ieee80211_sn_less(sn1, sn2) && 563 !ieee80211_sn_less(sn1, sn2 - buffer_size); 564 } 565 566 static void iwl_mvm_sync_nssn(struct iwl_mvm *mvm, u8 baid, u16 nssn) 567 { 568 if (IWL_MVM_USE_NSSN_SYNC) { 569 struct iwl_mvm_rss_sync_notif notif = { 570 .metadata.type = IWL_MVM_RXQ_NSSN_SYNC, 571 .metadata.sync = 0, 572 .nssn_sync.baid = baid, 573 .nssn_sync.nssn = nssn, 574 }; 575 576 iwl_mvm_sync_rx_queues_internal(mvm, (void *)¬if, 577 sizeof(notif)); 578 } 579 } 580 581 #define RX_REORDER_BUF_TIMEOUT_MQ (HZ / 10) 582 583 enum iwl_mvm_release_flags { 584 IWL_MVM_RELEASE_SEND_RSS_SYNC = BIT(0), 585 IWL_MVM_RELEASE_FROM_RSS_SYNC = BIT(1), 586 }; 587 588 static void iwl_mvm_release_frames(struct iwl_mvm *mvm, 589 struct ieee80211_sta *sta, 590 struct napi_struct *napi, 591 struct iwl_mvm_baid_data *baid_data, 592 struct iwl_mvm_reorder_buffer *reorder_buf, 593 u16 nssn, u32 flags) 594 { 595 struct iwl_mvm_reorder_buf_entry *entries = 596 &baid_data->entries[reorder_buf->queue * 597 baid_data->entries_per_queue]; 598 u16 ssn = reorder_buf->head_sn; 599 600 lockdep_assert_held(&reorder_buf->lock); 601 602 /* 603 * We keep the NSSN not too far behind, if we are sync'ing it and it 604 * is more than 2048 ahead of us, it must be behind us. Discard it. 605 * This can happen if the queue that hit the 0 / 2048 seqno was lagging 606 * behind and this queue already processed packets. The next if 607 * would have caught cases where this queue would have processed less 608 * than 64 packets, but it may have processed more than 64 packets. 609 */ 610 if ((flags & IWL_MVM_RELEASE_FROM_RSS_SYNC) && 611 ieee80211_sn_less(nssn, ssn)) 612 goto set_timer; 613 614 /* ignore nssn smaller than head sn - this can happen due to timeout */ 615 if (iwl_mvm_is_sn_less(nssn, ssn, reorder_buf->buf_size)) 616 goto set_timer; 617 618 while (iwl_mvm_is_sn_less(ssn, nssn, reorder_buf->buf_size)) { 619 int index = ssn % reorder_buf->buf_size; 620 struct sk_buff_head *skb_list = &entries[index].e.frames; 621 struct sk_buff *skb; 622 623 ssn = ieee80211_sn_inc(ssn); 624 if ((flags & IWL_MVM_RELEASE_SEND_RSS_SYNC) && 625 (ssn == 2048 || ssn == 0)) 626 iwl_mvm_sync_nssn(mvm, baid_data->baid, ssn); 627 628 /* 629 * Empty the list. Will have more than one frame for A-MSDU. 630 * Empty list is valid as well since nssn indicates frames were 631 * received. 632 */ 633 while ((skb = __skb_dequeue(skb_list))) { 634 iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb, 635 reorder_buf->queue, 636 sta, false); 637 reorder_buf->num_stored--; 638 } 639 } 640 reorder_buf->head_sn = nssn; 641 642 set_timer: 643 if (reorder_buf->num_stored && !reorder_buf->removed) { 644 u16 index = reorder_buf->head_sn % reorder_buf->buf_size; 645 646 while (skb_queue_empty(&entries[index].e.frames)) 647 index = (index + 1) % reorder_buf->buf_size; 648 /* modify timer to match next frame's expiration time */ 649 mod_timer(&reorder_buf->reorder_timer, 650 entries[index].e.reorder_time + 1 + 651 RX_REORDER_BUF_TIMEOUT_MQ); 652 } else { 653 del_timer(&reorder_buf->reorder_timer); 654 } 655 } 656 657 void iwl_mvm_reorder_timer_expired(struct timer_list *t) 658 { 659 struct iwl_mvm_reorder_buffer *buf = from_timer(buf, t, reorder_timer); 660 struct iwl_mvm_baid_data *baid_data = 661 iwl_mvm_baid_data_from_reorder_buf(buf); 662 struct iwl_mvm_reorder_buf_entry *entries = 663 &baid_data->entries[buf->queue * baid_data->entries_per_queue]; 664 int i; 665 u16 sn = 0, index = 0; 666 bool expired = false; 667 bool cont = false; 668 669 spin_lock(&buf->lock); 670 671 if (!buf->num_stored || buf->removed) { 672 spin_unlock(&buf->lock); 673 return; 674 } 675 676 for (i = 0; i < buf->buf_size ; i++) { 677 index = (buf->head_sn + i) % buf->buf_size; 678 679 if (skb_queue_empty(&entries[index].e.frames)) { 680 /* 681 * If there is a hole and the next frame didn't expire 682 * we want to break and not advance SN 683 */ 684 cont = false; 685 continue; 686 } 687 if (!cont && 688 !time_after(jiffies, entries[index].e.reorder_time + 689 RX_REORDER_BUF_TIMEOUT_MQ)) 690 break; 691 692 expired = true; 693 /* continue until next hole after this expired frames */ 694 cont = true; 695 sn = ieee80211_sn_add(buf->head_sn, i + 1); 696 } 697 698 if (expired) { 699 struct ieee80211_sta *sta; 700 struct iwl_mvm_sta *mvmsta; 701 u8 sta_id = baid_data->sta_id; 702 703 rcu_read_lock(); 704 sta = rcu_dereference(buf->mvm->fw_id_to_mac_id[sta_id]); 705 mvmsta = iwl_mvm_sta_from_mac80211(sta); 706 707 /* SN is set to the last expired frame + 1 */ 708 IWL_DEBUG_HT(buf->mvm, 709 "Releasing expired frames for sta %u, sn %d\n", 710 sta_id, sn); 711 iwl_mvm_event_frame_timeout_callback(buf->mvm, mvmsta->vif, 712 sta, baid_data->tid); 713 iwl_mvm_release_frames(buf->mvm, sta, NULL, baid_data, 714 buf, sn, IWL_MVM_RELEASE_SEND_RSS_SYNC); 715 rcu_read_unlock(); 716 } else { 717 /* 718 * If no frame expired and there are stored frames, index is now 719 * pointing to the first unexpired frame - modify timer 720 * accordingly to this frame. 721 */ 722 mod_timer(&buf->reorder_timer, 723 entries[index].e.reorder_time + 724 1 + RX_REORDER_BUF_TIMEOUT_MQ); 725 } 726 spin_unlock(&buf->lock); 727 } 728 729 static void iwl_mvm_del_ba(struct iwl_mvm *mvm, int queue, 730 struct iwl_mvm_delba_data *data) 731 { 732 struct iwl_mvm_baid_data *ba_data; 733 struct ieee80211_sta *sta; 734 struct iwl_mvm_reorder_buffer *reorder_buf; 735 u8 baid = data->baid; 736 737 if (WARN_ONCE(baid >= IWL_MAX_BAID, "invalid BAID: %x\n", baid)) 738 return; 739 740 rcu_read_lock(); 741 742 ba_data = rcu_dereference(mvm->baid_map[baid]); 743 if (WARN_ON_ONCE(!ba_data)) 744 goto out; 745 746 sta = rcu_dereference(mvm->fw_id_to_mac_id[ba_data->sta_id]); 747 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) 748 goto out; 749 750 reorder_buf = &ba_data->reorder_buf[queue]; 751 752 /* release all frames that are in the reorder buffer to the stack */ 753 spin_lock_bh(&reorder_buf->lock); 754 iwl_mvm_release_frames(mvm, sta, NULL, ba_data, reorder_buf, 755 ieee80211_sn_add(reorder_buf->head_sn, 756 reorder_buf->buf_size), 757 0); 758 spin_unlock_bh(&reorder_buf->lock); 759 del_timer_sync(&reorder_buf->reorder_timer); 760 761 out: 762 rcu_read_unlock(); 763 } 764 765 static void iwl_mvm_release_frames_from_notif(struct iwl_mvm *mvm, 766 struct napi_struct *napi, 767 u8 baid, u16 nssn, int queue, 768 u32 flags) 769 { 770 struct ieee80211_sta *sta; 771 struct iwl_mvm_reorder_buffer *reorder_buf; 772 struct iwl_mvm_baid_data *ba_data; 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 (WARN_ON_ONCE(!ba_data)) 785 goto out; 786 787 sta = rcu_dereference(mvm->fw_id_to_mac_id[ba_data->sta_id]); 788 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) 789 goto out; 790 791 reorder_buf = &ba_data->reorder_buf[queue]; 792 793 spin_lock_bh(&reorder_buf->lock); 794 iwl_mvm_release_frames(mvm, sta, napi, ba_data, 795 reorder_buf, nssn, flags); 796 spin_unlock_bh(&reorder_buf->lock); 797 798 out: 799 rcu_read_unlock(); 800 } 801 802 static void iwl_mvm_nssn_sync(struct iwl_mvm *mvm, 803 struct napi_struct *napi, int queue, 804 const struct iwl_mvm_nssn_sync_data *data) 805 { 806 iwl_mvm_release_frames_from_notif(mvm, napi, data->baid, 807 data->nssn, queue, 808 IWL_MVM_RELEASE_FROM_RSS_SYNC); 809 } 810 811 void iwl_mvm_rx_queue_notif(struct iwl_mvm *mvm, struct napi_struct *napi, 812 struct iwl_rx_cmd_buffer *rxb, int queue) 813 { 814 struct iwl_rx_packet *pkt = rxb_addr(rxb); 815 struct iwl_rxq_sync_notification *notif; 816 struct iwl_mvm_internal_rxq_notif *internal_notif; 817 u32 len = iwl_rx_packet_payload_len(pkt); 818 819 notif = (void *)pkt->data; 820 internal_notif = (void *)notif->payload; 821 822 if (WARN_ONCE(len < sizeof(*notif) + sizeof(*internal_notif), 823 "invalid notification size %d (%d)", 824 len, (int)(sizeof(*notif) + sizeof(*internal_notif)))) 825 return; 826 /* remove only the firmware header, we want all of our payload below */ 827 len -= sizeof(*notif); 828 829 if (internal_notif->sync && 830 mvm->queue_sync_cookie != internal_notif->cookie) { 831 WARN_ONCE(1, "Received expired RX queue sync message\n"); 832 return; 833 } 834 835 switch (internal_notif->type) { 836 case IWL_MVM_RXQ_EMPTY: 837 WARN_ONCE(len != sizeof(*internal_notif), 838 "invalid empty notification size %d (%d)", 839 len, (int)sizeof(*internal_notif)); 840 break; 841 case IWL_MVM_RXQ_NOTIF_DEL_BA: 842 if (WARN_ONCE(len != sizeof(struct iwl_mvm_rss_sync_notif), 843 "invalid delba notification size %d (%d)", 844 len, (int)sizeof(struct iwl_mvm_rss_sync_notif))) 845 break; 846 iwl_mvm_del_ba(mvm, queue, (void *)internal_notif->data); 847 break; 848 case IWL_MVM_RXQ_NSSN_SYNC: 849 if (WARN_ONCE(len != sizeof(struct iwl_mvm_rss_sync_notif), 850 "invalid nssn sync notification size %d (%d)", 851 len, (int)sizeof(struct iwl_mvm_rss_sync_notif))) 852 break; 853 iwl_mvm_nssn_sync(mvm, napi, queue, 854 (void *)internal_notif->data); 855 break; 856 default: 857 WARN_ONCE(1, "Invalid identifier %d", internal_notif->type); 858 } 859 860 if (internal_notif->sync) { 861 WARN_ONCE(!test_and_clear_bit(queue, &mvm->queue_sync_state), 862 "queue sync: queue %d responded a second time!\n", 863 queue); 864 if (READ_ONCE(mvm->queue_sync_state) == 0) 865 wake_up(&mvm->rx_sync_waitq); 866 } 867 } 868 869 static void iwl_mvm_oldsn_workaround(struct iwl_mvm *mvm, 870 struct ieee80211_sta *sta, int tid, 871 struct iwl_mvm_reorder_buffer *buffer, 872 u32 reorder, u32 gp2, int queue) 873 { 874 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 875 876 if (gp2 != buffer->consec_oldsn_ampdu_gp2) { 877 /* we have a new (A-)MPDU ... */ 878 879 /* 880 * reset counter to 0 if we didn't have any oldsn in 881 * the last A-MPDU (as detected by GP2 being identical) 882 */ 883 if (!buffer->consec_oldsn_prev_drop) 884 buffer->consec_oldsn_drops = 0; 885 886 /* either way, update our tracking state */ 887 buffer->consec_oldsn_ampdu_gp2 = gp2; 888 } else if (buffer->consec_oldsn_prev_drop) { 889 /* 890 * tracking state didn't change, and we had an old SN 891 * indication before - do nothing in this case, we 892 * already noted this one down and are waiting for the 893 * next A-MPDU (by GP2) 894 */ 895 return; 896 } 897 898 /* return unless this MPDU has old SN */ 899 if (!(reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN)) 900 return; 901 902 /* update state */ 903 buffer->consec_oldsn_prev_drop = 1; 904 buffer->consec_oldsn_drops++; 905 906 /* if limit is reached, send del BA and reset state */ 907 if (buffer->consec_oldsn_drops == IWL_MVM_AMPDU_CONSEC_DROPS_DELBA) { 908 IWL_WARN(mvm, 909 "reached %d old SN frames from %pM on queue %d, stopping BA session on TID %d\n", 910 IWL_MVM_AMPDU_CONSEC_DROPS_DELBA, 911 sta->addr, queue, tid); 912 ieee80211_stop_rx_ba_session(mvmsta->vif, BIT(tid), sta->addr); 913 buffer->consec_oldsn_prev_drop = 0; 914 buffer->consec_oldsn_drops = 0; 915 } 916 } 917 918 /* 919 * Returns true if the MPDU was buffered\dropped, false if it should be passed 920 * to upper layer. 921 */ 922 static bool iwl_mvm_reorder(struct iwl_mvm *mvm, 923 struct napi_struct *napi, 924 int queue, 925 struct ieee80211_sta *sta, 926 struct sk_buff *skb, 927 struct iwl_rx_mpdu_desc *desc) 928 { 929 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 930 struct ieee80211_hdr *hdr = iwl_mvm_skb_get_hdr(skb); 931 struct iwl_mvm_sta *mvm_sta; 932 struct iwl_mvm_baid_data *baid_data; 933 struct iwl_mvm_reorder_buffer *buffer; 934 struct sk_buff *tail; 935 u32 reorder = le32_to_cpu(desc->reorder_data); 936 bool amsdu = desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU; 937 bool last_subframe = 938 desc->amsdu_info & IWL_RX_MPDU_AMSDU_LAST_SUBFRAME; 939 u8 tid = ieee80211_get_tid(hdr); 940 u8 sub_frame_idx = desc->amsdu_info & 941 IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK; 942 struct iwl_mvm_reorder_buf_entry *entries; 943 int index; 944 u16 nssn, sn; 945 u8 baid; 946 947 baid = (reorder & IWL_RX_MPDU_REORDER_BAID_MASK) >> 948 IWL_RX_MPDU_REORDER_BAID_SHIFT; 949 950 /* 951 * This also covers the case of receiving a Block Ack Request 952 * outside a BA session; we'll pass it to mac80211 and that 953 * then sends a delBA action frame. 954 * This also covers pure monitor mode, in which case we won't 955 * have any BA sessions. 956 */ 957 if (baid == IWL_RX_REORDER_DATA_INVALID_BAID) 958 return false; 959 960 /* no sta yet */ 961 if (WARN_ONCE(IS_ERR_OR_NULL(sta), 962 "Got valid BAID without a valid station assigned\n")) 963 return false; 964 965 mvm_sta = iwl_mvm_sta_from_mac80211(sta); 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 if (WARN(tid != baid_data->tid || mvm_sta->sta_id != baid_data->sta_id, 985 "baid 0x%x is mapped to sta:%d tid:%d, but was received for sta:%d tid:%d\n", 986 baid, baid_data->sta_id, baid_data->tid, mvm_sta->sta_id, 987 tid)) 988 return false; 989 990 nssn = reorder & IWL_RX_MPDU_REORDER_NSSN_MASK; 991 sn = (reorder & IWL_RX_MPDU_REORDER_SN_MASK) >> 992 IWL_RX_MPDU_REORDER_SN_SHIFT; 993 994 buffer = &baid_data->reorder_buf[queue]; 995 entries = &baid_data->entries[queue * baid_data->entries_per_queue]; 996 997 spin_lock_bh(&buffer->lock); 998 999 if (!buffer->valid) { 1000 if (reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN) { 1001 spin_unlock_bh(&buffer->lock); 1002 return false; 1003 } 1004 buffer->valid = true; 1005 } 1006 1007 if (ieee80211_is_back_req(hdr->frame_control)) { 1008 iwl_mvm_release_frames(mvm, sta, napi, baid_data, 1009 buffer, nssn, 0); 1010 goto drop; 1011 } 1012 1013 /* 1014 * If there was a significant jump in the nssn - adjust. 1015 * If the SN is smaller than the NSSN it might need to first go into 1016 * the reorder buffer, in which case we just release up to it and the 1017 * rest of the function will take care of storing it and releasing up to 1018 * the nssn. 1019 * This should not happen. This queue has been lagging and it should 1020 * have been updated by a IWL_MVM_RXQ_NSSN_SYNC notification. Be nice 1021 * and update the other queues. 1022 */ 1023 if (!iwl_mvm_is_sn_less(nssn, buffer->head_sn + buffer->buf_size, 1024 buffer->buf_size) || 1025 !ieee80211_sn_less(sn, buffer->head_sn + buffer->buf_size)) { 1026 u16 min_sn = ieee80211_sn_less(sn, nssn) ? sn : nssn; 1027 1028 iwl_mvm_release_frames(mvm, sta, napi, baid_data, buffer, 1029 min_sn, IWL_MVM_RELEASE_SEND_RSS_SYNC); 1030 } 1031 1032 iwl_mvm_oldsn_workaround(mvm, sta, tid, buffer, reorder, 1033 rx_status->device_timestamp, queue); 1034 1035 /* drop any oudated packets */ 1036 if (ieee80211_sn_less(sn, buffer->head_sn)) 1037 goto drop; 1038 1039 /* release immediately if allowed by nssn and no stored frames */ 1040 if (!buffer->num_stored && ieee80211_sn_less(sn, nssn)) { 1041 if (iwl_mvm_is_sn_less(buffer->head_sn, nssn, 1042 buffer->buf_size) && 1043 (!amsdu || last_subframe)) { 1044 /* 1045 * If we crossed the 2048 or 0 SN, notify all the 1046 * queues. This is done in order to avoid having a 1047 * head_sn that lags behind for too long. When that 1048 * happens, we can get to a situation where the head_sn 1049 * is within the interval [nssn - buf_size : nssn] 1050 * which will make us think that the nssn is a packet 1051 * that we already freed because of the reordering 1052 * buffer and we will ignore it. So maintain the 1053 * head_sn somewhat updated across all the queues: 1054 * when it crosses 0 and 2048. 1055 */ 1056 if (sn == 2048 || sn == 0) 1057 iwl_mvm_sync_nssn(mvm, baid, sn); 1058 buffer->head_sn = nssn; 1059 } 1060 /* No need to update AMSDU last SN - we are moving the head */ 1061 spin_unlock_bh(&buffer->lock); 1062 return false; 1063 } 1064 1065 /* 1066 * release immediately if there are no stored frames, and the sn is 1067 * equal to the head. 1068 * This can happen due to reorder timer, where NSSN is behind head_sn. 1069 * When we released everything, and we got the next frame in the 1070 * sequence, according to the NSSN we can't release immediately, 1071 * while technically there is no hole and we can move forward. 1072 */ 1073 if (!buffer->num_stored && sn == buffer->head_sn) { 1074 if (!amsdu || last_subframe) { 1075 if (sn == 2048 || sn == 0) 1076 iwl_mvm_sync_nssn(mvm, baid, sn); 1077 buffer->head_sn = ieee80211_sn_inc(buffer->head_sn); 1078 } 1079 /* No need to update AMSDU last SN - we are moving the head */ 1080 spin_unlock_bh(&buffer->lock); 1081 return false; 1082 } 1083 1084 index = sn % buffer->buf_size; 1085 1086 /* 1087 * Check if we already stored this frame 1088 * As AMSDU is either received or not as whole, logic is simple: 1089 * If we have frames in that position in the buffer and the last frame 1090 * originated from AMSDU had a different SN then it is a retransmission. 1091 * If it is the same SN then if the subframe index is incrementing it 1092 * is the same AMSDU - otherwise it is a retransmission. 1093 */ 1094 tail = skb_peek_tail(&entries[index].e.frames); 1095 if (tail && !amsdu) 1096 goto drop; 1097 else if (tail && (sn != buffer->last_amsdu || 1098 buffer->last_sub_index >= sub_frame_idx)) 1099 goto drop; 1100 1101 /* put in reorder buffer */ 1102 __skb_queue_tail(&entries[index].e.frames, skb); 1103 buffer->num_stored++; 1104 entries[index].e.reorder_time = jiffies; 1105 1106 if (amsdu) { 1107 buffer->last_amsdu = sn; 1108 buffer->last_sub_index = sub_frame_idx; 1109 } 1110 1111 /* 1112 * We cannot trust NSSN for AMSDU sub-frames that are not the last. 1113 * The reason is that NSSN advances on the first sub-frame, and may 1114 * cause the reorder buffer to advance before all the sub-frames arrive. 1115 * Example: reorder buffer contains SN 0 & 2, and we receive AMSDU with 1116 * SN 1. NSSN for first sub frame will be 3 with the result of driver 1117 * releasing SN 0,1, 2. When sub-frame 1 arrives - reorder buffer is 1118 * already ahead and it will be dropped. 1119 * If the last sub-frame is not on this queue - we will get frame 1120 * release notification with up to date NSSN. 1121 */ 1122 if (!amsdu || last_subframe) 1123 iwl_mvm_release_frames(mvm, sta, napi, baid_data, 1124 buffer, nssn, 1125 IWL_MVM_RELEASE_SEND_RSS_SYNC); 1126 1127 spin_unlock_bh(&buffer->lock); 1128 return true; 1129 1130 drop: 1131 kfree_skb(skb); 1132 spin_unlock_bh(&buffer->lock); 1133 return true; 1134 } 1135 1136 static void iwl_mvm_agg_rx_received(struct iwl_mvm *mvm, 1137 u32 reorder_data, u8 baid) 1138 { 1139 unsigned long now = jiffies; 1140 unsigned long timeout; 1141 struct iwl_mvm_baid_data *data; 1142 1143 rcu_read_lock(); 1144 1145 data = rcu_dereference(mvm->baid_map[baid]); 1146 if (!data) { 1147 IWL_DEBUG_RX(mvm, 1148 "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n", 1149 baid, reorder_data); 1150 goto out; 1151 } 1152 1153 if (!data->timeout) 1154 goto out; 1155 1156 timeout = data->timeout; 1157 /* 1158 * Do not update last rx all the time to avoid cache bouncing 1159 * between the rx queues. 1160 * Update it every timeout. Worst case is the session will 1161 * expire after ~ 2 * timeout, which doesn't matter that much. 1162 */ 1163 if (time_before(data->last_rx + TU_TO_JIFFIES(timeout), now)) 1164 /* Update is atomic */ 1165 data->last_rx = now; 1166 1167 out: 1168 rcu_read_unlock(); 1169 } 1170 1171 static void iwl_mvm_flip_address(u8 *addr) 1172 { 1173 int i; 1174 u8 mac_addr[ETH_ALEN]; 1175 1176 for (i = 0; i < ETH_ALEN; i++) 1177 mac_addr[i] = addr[ETH_ALEN - i - 1]; 1178 ether_addr_copy(addr, mac_addr); 1179 } 1180 1181 struct iwl_mvm_rx_phy_data { 1182 enum iwl_rx_phy_info_type info_type; 1183 __le32 d0, d1, d2, d3; 1184 __le16 d4; 1185 }; 1186 1187 static void iwl_mvm_decode_he_mu_ext(struct iwl_mvm *mvm, 1188 struct iwl_mvm_rx_phy_data *phy_data, 1189 u32 rate_n_flags, 1190 struct ieee80211_radiotap_he_mu *he_mu) 1191 { 1192 u32 phy_data2 = le32_to_cpu(phy_data->d2); 1193 u32 phy_data3 = le32_to_cpu(phy_data->d3); 1194 u16 phy_data4 = le16_to_cpu(phy_data->d4); 1195 1196 if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CRC_OK, phy_data4)) { 1197 he_mu->flags1 |= 1198 cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_RU_KNOWN | 1199 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU_KNOWN); 1200 1201 he_mu->flags1 |= 1202 le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CTR_RU, 1203 phy_data4), 1204 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU); 1205 1206 he_mu->ru_ch1[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU0, 1207 phy_data2); 1208 he_mu->ru_ch1[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU1, 1209 phy_data3); 1210 he_mu->ru_ch1[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU2, 1211 phy_data2); 1212 he_mu->ru_ch1[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU3, 1213 phy_data3); 1214 } 1215 1216 if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CRC_OK, phy_data4) && 1217 (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) != RATE_MCS_CHAN_WIDTH_20) { 1218 he_mu->flags1 |= 1219 cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_RU_KNOWN | 1220 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_CTR_26T_RU_KNOWN); 1221 1222 he_mu->flags2 |= 1223 le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CTR_RU, 1224 phy_data4), 1225 IEEE80211_RADIOTAP_HE_MU_FLAGS2_CH2_CTR_26T_RU); 1226 1227 he_mu->ru_ch2[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU0, 1228 phy_data2); 1229 he_mu->ru_ch2[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU1, 1230 phy_data3); 1231 he_mu->ru_ch2[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU2, 1232 phy_data2); 1233 he_mu->ru_ch2[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU3, 1234 phy_data3); 1235 } 1236 } 1237 1238 static void 1239 iwl_mvm_decode_he_phy_ru_alloc(struct iwl_mvm_rx_phy_data *phy_data, 1240 u32 rate_n_flags, 1241 struct ieee80211_radiotap_he *he, 1242 struct ieee80211_radiotap_he_mu *he_mu, 1243 struct ieee80211_rx_status *rx_status) 1244 { 1245 /* 1246 * Unfortunately, we have to leave the mac80211 data 1247 * incorrect for the case that we receive an HE-MU 1248 * transmission and *don't* have the HE phy data (due 1249 * to the bits being used for TSF). This shouldn't 1250 * happen though as management frames where we need 1251 * the TSF/timers are not be transmitted in HE-MU. 1252 */ 1253 u8 ru = le32_get_bits(phy_data->d1, IWL_RX_PHY_DATA1_HE_RU_ALLOC_MASK); 1254 u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK; 1255 u8 offs = 0; 1256 1257 rx_status->bw = RATE_INFO_BW_HE_RU; 1258 1259 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN); 1260 1261 switch (ru) { 1262 case 0 ... 36: 1263 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_26; 1264 offs = ru; 1265 break; 1266 case 37 ... 52: 1267 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_52; 1268 offs = ru - 37; 1269 break; 1270 case 53 ... 60: 1271 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106; 1272 offs = ru - 53; 1273 break; 1274 case 61 ... 64: 1275 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_242; 1276 offs = ru - 61; 1277 break; 1278 case 65 ... 66: 1279 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_484; 1280 offs = ru - 65; 1281 break; 1282 case 67: 1283 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_996; 1284 break; 1285 case 68: 1286 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_2x996; 1287 break; 1288 } 1289 he->data2 |= le16_encode_bits(offs, 1290 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET); 1291 he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_KNOWN | 1292 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET_KNOWN); 1293 if (phy_data->d1 & cpu_to_le32(IWL_RX_PHY_DATA1_HE_RU_ALLOC_SEC80)) 1294 he->data2 |= 1295 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_SEC); 1296 1297 #define CHECK_BW(bw) \ 1298 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_ ## bw ## MHZ != \ 1299 RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS); \ 1300 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_ ## bw ## MHZ != \ 1301 RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS) 1302 CHECK_BW(20); 1303 CHECK_BW(40); 1304 CHECK_BW(80); 1305 CHECK_BW(160); 1306 1307 if (he_mu) 1308 he_mu->flags2 |= 1309 le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK, 1310 rate_n_flags), 1311 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW); 1312 else if (he_type == RATE_MCS_HE_TYPE_TRIG) 1313 he->data6 |= 1314 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_KNOWN) | 1315 le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK, 1316 rate_n_flags), 1317 IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW); 1318 } 1319 1320 static void iwl_mvm_decode_he_phy_data(struct iwl_mvm *mvm, 1321 struct iwl_mvm_rx_phy_data *phy_data, 1322 struct ieee80211_radiotap_he *he, 1323 struct ieee80211_radiotap_he_mu *he_mu, 1324 struct ieee80211_rx_status *rx_status, 1325 u32 rate_n_flags, int queue) 1326 { 1327 switch (phy_data->info_type) { 1328 case IWL_RX_PHY_INFO_TYPE_NONE: 1329 case IWL_RX_PHY_INFO_TYPE_CCK: 1330 case IWL_RX_PHY_INFO_TYPE_OFDM_LGCY: 1331 case IWL_RX_PHY_INFO_TYPE_HT: 1332 case IWL_RX_PHY_INFO_TYPE_VHT_SU: 1333 case IWL_RX_PHY_INFO_TYPE_VHT_MU: 1334 return; 1335 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT: 1336 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN | 1337 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE2_KNOWN | 1338 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE3_KNOWN | 1339 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE4_KNOWN); 1340 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2, 1341 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE1), 1342 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE1); 1343 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2, 1344 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE2), 1345 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE2); 1346 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2, 1347 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE3), 1348 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE3); 1349 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2, 1350 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE4), 1351 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE4); 1352 fallthrough; 1353 case IWL_RX_PHY_INFO_TYPE_HE_SU: 1354 case IWL_RX_PHY_INFO_TYPE_HE_MU: 1355 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT: 1356 case IWL_RX_PHY_INFO_TYPE_HE_TB: 1357 /* HE common */ 1358 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_LDPC_XSYMSEG_KNOWN | 1359 IEEE80211_RADIOTAP_HE_DATA1_DOPPLER_KNOWN | 1360 IEEE80211_RADIOTAP_HE_DATA1_BSS_COLOR_KNOWN); 1361 he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRE_FEC_PAD_KNOWN | 1362 IEEE80211_RADIOTAP_HE_DATA2_PE_DISAMBIG_KNOWN | 1363 IEEE80211_RADIOTAP_HE_DATA2_TXOP_KNOWN | 1364 IEEE80211_RADIOTAP_HE_DATA2_NUM_LTF_SYMS_KNOWN); 1365 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1366 IWL_RX_PHY_DATA0_HE_BSS_COLOR_MASK), 1367 IEEE80211_RADIOTAP_HE_DATA3_BSS_COLOR); 1368 if (phy_data->info_type != IWL_RX_PHY_INFO_TYPE_HE_TB && 1369 phy_data->info_type != IWL_RX_PHY_INFO_TYPE_HE_TB_EXT) { 1370 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_UL_DL_KNOWN); 1371 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1372 IWL_RX_PHY_DATA0_HE_UPLINK), 1373 IEEE80211_RADIOTAP_HE_DATA3_UL_DL); 1374 } 1375 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1376 IWL_RX_PHY_DATA0_HE_LDPC_EXT_SYM), 1377 IEEE80211_RADIOTAP_HE_DATA3_LDPC_XSYMSEG); 1378 he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1379 IWL_RX_PHY_DATA0_HE_PRE_FEC_PAD_MASK), 1380 IEEE80211_RADIOTAP_HE_DATA5_PRE_FEC_PAD); 1381 he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1382 IWL_RX_PHY_DATA0_HE_PE_DISAMBIG), 1383 IEEE80211_RADIOTAP_HE_DATA5_PE_DISAMBIG); 1384 he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d1, 1385 IWL_RX_PHY_DATA1_HE_LTF_NUM_MASK), 1386 IEEE80211_RADIOTAP_HE_DATA5_NUM_LTF_SYMS); 1387 he->data6 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1388 IWL_RX_PHY_DATA0_HE_TXOP_DUR_MASK), 1389 IEEE80211_RADIOTAP_HE_DATA6_TXOP); 1390 he->data6 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1391 IWL_RX_PHY_DATA0_HE_DOPPLER), 1392 IEEE80211_RADIOTAP_HE_DATA6_DOPPLER); 1393 break; 1394 } 1395 1396 switch (phy_data->info_type) { 1397 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT: 1398 case IWL_RX_PHY_INFO_TYPE_HE_MU: 1399 case IWL_RX_PHY_INFO_TYPE_HE_SU: 1400 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN); 1401 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1402 IWL_RX_PHY_DATA0_HE_SPATIAL_REUSE_MASK), 1403 IEEE80211_RADIOTAP_HE_DATA4_SU_MU_SPTL_REUSE); 1404 break; 1405 default: 1406 /* nothing here */ 1407 break; 1408 } 1409 1410 switch (phy_data->info_type) { 1411 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT: 1412 he_mu->flags1 |= 1413 le16_encode_bits(le16_get_bits(phy_data->d4, 1414 IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_DCM), 1415 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM); 1416 he_mu->flags1 |= 1417 le16_encode_bits(le16_get_bits(phy_data->d4, 1418 IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_MCS_MASK), 1419 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS); 1420 he_mu->flags2 |= 1421 le16_encode_bits(le16_get_bits(phy_data->d4, 1422 IWL_RX_PHY_DATA4_HE_MU_EXT_PREAMBLE_PUNC_TYPE_MASK), 1423 IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW); 1424 iwl_mvm_decode_he_mu_ext(mvm, phy_data, rate_n_flags, he_mu); 1425 fallthrough; 1426 case IWL_RX_PHY_INFO_TYPE_HE_MU: 1427 he_mu->flags2 |= 1428 le16_encode_bits(le32_get_bits(phy_data->d1, 1429 IWL_RX_PHY_DATA1_HE_MU_SIBG_SYM_OR_USER_NUM_MASK), 1430 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_SYMS_USERS); 1431 he_mu->flags2 |= 1432 le16_encode_bits(le32_get_bits(phy_data->d1, 1433 IWL_RX_PHY_DATA1_HE_MU_SIGB_COMPRESSION), 1434 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_COMP); 1435 fallthrough; 1436 case IWL_RX_PHY_INFO_TYPE_HE_TB: 1437 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT: 1438 iwl_mvm_decode_he_phy_ru_alloc(phy_data, rate_n_flags, 1439 he, he_mu, rx_status); 1440 break; 1441 case IWL_RX_PHY_INFO_TYPE_HE_SU: 1442 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BEAM_CHANGE_KNOWN); 1443 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0, 1444 IWL_RX_PHY_DATA0_HE_BEAM_CHNG), 1445 IEEE80211_RADIOTAP_HE_DATA3_BEAM_CHANGE); 1446 break; 1447 default: 1448 /* nothing */ 1449 break; 1450 } 1451 } 1452 1453 static void iwl_mvm_rx_he(struct iwl_mvm *mvm, struct sk_buff *skb, 1454 struct iwl_mvm_rx_phy_data *phy_data, 1455 u32 rate_n_flags, u16 phy_info, int queue) 1456 { 1457 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 1458 struct ieee80211_radiotap_he *he = NULL; 1459 struct ieee80211_radiotap_he_mu *he_mu = NULL; 1460 u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK; 1461 u8 stbc, ltf; 1462 static const struct ieee80211_radiotap_he known = { 1463 .data1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_DATA_MCS_KNOWN | 1464 IEEE80211_RADIOTAP_HE_DATA1_DATA_DCM_KNOWN | 1465 IEEE80211_RADIOTAP_HE_DATA1_STBC_KNOWN | 1466 IEEE80211_RADIOTAP_HE_DATA1_CODING_KNOWN), 1467 .data2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_GI_KNOWN | 1468 IEEE80211_RADIOTAP_HE_DATA2_TXBF_KNOWN), 1469 }; 1470 static const struct ieee80211_radiotap_he_mu mu_known = { 1471 .flags1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS_KNOWN | 1472 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM_KNOWN | 1473 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_SYMS_USERS_KNOWN | 1474 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_COMP_KNOWN), 1475 .flags2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW_KNOWN | 1476 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_KNOWN), 1477 }; 1478 1479 he = skb_put_data(skb, &known, sizeof(known)); 1480 rx_status->flag |= RX_FLAG_RADIOTAP_HE; 1481 1482 if (phy_data->info_type == IWL_RX_PHY_INFO_TYPE_HE_MU || 1483 phy_data->info_type == IWL_RX_PHY_INFO_TYPE_HE_MU_EXT) { 1484 he_mu = skb_put_data(skb, &mu_known, sizeof(mu_known)); 1485 rx_status->flag |= RX_FLAG_RADIOTAP_HE_MU; 1486 } 1487 1488 /* report the AMPDU-EOF bit on single frames */ 1489 if (!queue && !(phy_info & IWL_RX_MPDU_PHY_AMPDU)) { 1490 rx_status->flag |= RX_FLAG_AMPDU_DETAILS; 1491 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN; 1492 if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_HE_DELIM_EOF)) 1493 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT; 1494 } 1495 1496 if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) 1497 iwl_mvm_decode_he_phy_data(mvm, phy_data, he, he_mu, rx_status, 1498 rate_n_flags, queue); 1499 1500 /* update aggregation data for monitor sake on default queue */ 1501 if (!queue && (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) && 1502 (phy_info & IWL_RX_MPDU_PHY_AMPDU)) { 1503 bool toggle_bit = phy_info & IWL_RX_MPDU_PHY_AMPDU_TOGGLE; 1504 1505 /* toggle is switched whenever new aggregation starts */ 1506 if (toggle_bit != mvm->ampdu_toggle) { 1507 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN; 1508 if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_HE_DELIM_EOF)) 1509 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT; 1510 } 1511 } 1512 1513 if (he_type == RATE_MCS_HE_TYPE_EXT_SU && 1514 rate_n_flags & RATE_MCS_HE_106T_MSK) { 1515 rx_status->bw = RATE_INFO_BW_HE_RU; 1516 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106; 1517 } 1518 1519 /* actually data is filled in mac80211 */ 1520 if (he_type == RATE_MCS_HE_TYPE_SU || 1521 he_type == RATE_MCS_HE_TYPE_EXT_SU) 1522 he->data1 |= 1523 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN); 1524 1525 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >> RATE_MCS_STBC_POS; 1526 rx_status->nss = 1527 ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >> 1528 RATE_VHT_MCS_NSS_POS) + 1; 1529 rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK; 1530 rx_status->encoding = RX_ENC_HE; 1531 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT; 1532 if (rate_n_flags & RATE_MCS_BF_MSK) 1533 rx_status->enc_flags |= RX_ENC_FLAG_BF; 1534 1535 rx_status->he_dcm = 1536 !!(rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK); 1537 1538 #define CHECK_TYPE(F) \ 1539 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_ ## F != \ 1540 (RATE_MCS_HE_TYPE_ ## F >> RATE_MCS_HE_TYPE_POS)) 1541 1542 CHECK_TYPE(SU); 1543 CHECK_TYPE(EXT_SU); 1544 CHECK_TYPE(MU); 1545 CHECK_TYPE(TRIG); 1546 1547 he->data1 |= cpu_to_le16(he_type >> RATE_MCS_HE_TYPE_POS); 1548 1549 if (rate_n_flags & RATE_MCS_BF_MSK) 1550 he->data5 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA5_TXBF); 1551 1552 switch ((rate_n_flags & RATE_MCS_HE_GI_LTF_MSK) >> 1553 RATE_MCS_HE_GI_LTF_POS) { 1554 case 0: 1555 if (he_type == RATE_MCS_HE_TYPE_TRIG) 1556 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 1557 else 1558 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 1559 if (he_type == RATE_MCS_HE_TYPE_MU) 1560 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 1561 else 1562 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X; 1563 break; 1564 case 1: 1565 if (he_type == RATE_MCS_HE_TYPE_TRIG) 1566 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 1567 else 1568 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 1569 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; 1570 break; 1571 case 2: 1572 if (he_type == RATE_MCS_HE_TYPE_TRIG) { 1573 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 1574 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 1575 } else { 1576 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 1577 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; 1578 } 1579 break; 1580 case 3: 1581 if ((he_type == RATE_MCS_HE_TYPE_SU || 1582 he_type == RATE_MCS_HE_TYPE_EXT_SU) && 1583 rate_n_flags & RATE_MCS_SGI_MSK) 1584 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 1585 else 1586 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 1587 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 1588 break; 1589 } 1590 1591 he->data5 |= le16_encode_bits(ltf, 1592 IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE); 1593 } 1594 1595 static void iwl_mvm_decode_lsig(struct sk_buff *skb, 1596 struct iwl_mvm_rx_phy_data *phy_data) 1597 { 1598 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 1599 struct ieee80211_radiotap_lsig *lsig; 1600 1601 switch (phy_data->info_type) { 1602 case IWL_RX_PHY_INFO_TYPE_HT: 1603 case IWL_RX_PHY_INFO_TYPE_VHT_SU: 1604 case IWL_RX_PHY_INFO_TYPE_VHT_MU: 1605 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT: 1606 case IWL_RX_PHY_INFO_TYPE_HE_SU: 1607 case IWL_RX_PHY_INFO_TYPE_HE_MU: 1608 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT: 1609 case IWL_RX_PHY_INFO_TYPE_HE_TB: 1610 lsig = skb_put(skb, sizeof(*lsig)); 1611 lsig->data1 = cpu_to_le16(IEEE80211_RADIOTAP_LSIG_DATA1_LENGTH_KNOWN); 1612 lsig->data2 = le16_encode_bits(le32_get_bits(phy_data->d1, 1613 IWL_RX_PHY_DATA1_LSIG_LEN_MASK), 1614 IEEE80211_RADIOTAP_LSIG_DATA2_LENGTH); 1615 rx_status->flag |= RX_FLAG_RADIOTAP_LSIG; 1616 break; 1617 default: 1618 break; 1619 } 1620 } 1621 1622 static inline u8 iwl_mvm_nl80211_band_from_rx_msdu(u8 phy_band) 1623 { 1624 switch (phy_band) { 1625 case PHY_BAND_24: 1626 return NL80211_BAND_2GHZ; 1627 case PHY_BAND_5: 1628 return NL80211_BAND_5GHZ; 1629 case PHY_BAND_6: 1630 return NL80211_BAND_6GHZ; 1631 default: 1632 WARN_ONCE(1, "Unsupported phy band (%u)\n", phy_band); 1633 return NL80211_BAND_5GHZ; 1634 } 1635 } 1636 1637 struct iwl_rx_sta_csa { 1638 bool all_sta_unblocked; 1639 struct ieee80211_vif *vif; 1640 }; 1641 1642 static void iwl_mvm_rx_get_sta_block_tx(void *data, struct ieee80211_sta *sta) 1643 { 1644 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 1645 struct iwl_rx_sta_csa *rx_sta_csa = data; 1646 1647 if (mvmsta->vif != rx_sta_csa->vif) 1648 return; 1649 1650 if (mvmsta->disable_tx) 1651 rx_sta_csa->all_sta_unblocked = false; 1652 } 1653 1654 void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi, 1655 struct iwl_rx_cmd_buffer *rxb, int queue) 1656 { 1657 struct ieee80211_rx_status *rx_status; 1658 struct iwl_rx_packet *pkt = rxb_addr(rxb); 1659 struct iwl_rx_mpdu_desc *desc = (void *)pkt->data; 1660 struct ieee80211_hdr *hdr; 1661 u32 len; 1662 u32 pkt_len = iwl_rx_packet_payload_len(pkt); 1663 u32 rate_n_flags, gp2_on_air_rise; 1664 u16 phy_info; 1665 struct ieee80211_sta *sta = NULL; 1666 struct sk_buff *skb; 1667 u8 crypt_len = 0, channel, energy_a, energy_b; 1668 size_t desc_size; 1669 struct iwl_mvm_rx_phy_data phy_data = { 1670 .info_type = IWL_RX_PHY_INFO_TYPE_NONE, 1671 }; 1672 bool csi = false; 1673 1674 if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))) 1675 return; 1676 1677 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) 1678 desc_size = sizeof(*desc); 1679 else 1680 desc_size = IWL_RX_DESC_SIZE_V1; 1681 1682 if (unlikely(pkt_len < desc_size)) { 1683 IWL_DEBUG_DROP(mvm, "Bad REPLY_RX_MPDU_CMD size\n"); 1684 return; 1685 } 1686 1687 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) { 1688 rate_n_flags = le32_to_cpu(desc->v3.rate_n_flags); 1689 channel = desc->v3.channel; 1690 gp2_on_air_rise = le32_to_cpu(desc->v3.gp2_on_air_rise); 1691 energy_a = desc->v3.energy_a; 1692 energy_b = desc->v3.energy_b; 1693 1694 phy_data.d0 = desc->v3.phy_data0; 1695 phy_data.d1 = desc->v3.phy_data1; 1696 phy_data.d2 = desc->v3.phy_data2; 1697 phy_data.d3 = desc->v3.phy_data3; 1698 } else { 1699 rate_n_flags = le32_to_cpu(desc->v1.rate_n_flags); 1700 channel = desc->v1.channel; 1701 gp2_on_air_rise = le32_to_cpu(desc->v1.gp2_on_air_rise); 1702 energy_a = desc->v1.energy_a; 1703 energy_b = desc->v1.energy_b; 1704 1705 phy_data.d0 = desc->v1.phy_data0; 1706 phy_data.d1 = desc->v1.phy_data1; 1707 phy_data.d2 = desc->v1.phy_data2; 1708 phy_data.d3 = desc->v1.phy_data3; 1709 } 1710 1711 len = le16_to_cpu(desc->mpdu_len); 1712 1713 if (unlikely(len + desc_size > pkt_len)) { 1714 IWL_DEBUG_DROP(mvm, "FW lied about packet len\n"); 1715 return; 1716 } 1717 1718 phy_info = le16_to_cpu(desc->phy_info); 1719 phy_data.d4 = desc->phy_data4; 1720 1721 if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) 1722 phy_data.info_type = 1723 le32_get_bits(phy_data.d1, 1724 IWL_RX_PHY_DATA1_INFO_TYPE_MASK); 1725 1726 hdr = (void *)(pkt->data + desc_size); 1727 /* Dont use dev_alloc_skb(), we'll have enough headroom once 1728 * ieee80211_hdr pulled. 1729 */ 1730 skb = alloc_skb(128, GFP_ATOMIC); 1731 if (!skb) { 1732 IWL_ERR(mvm, "alloc_skb failed\n"); 1733 return; 1734 } 1735 1736 if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) { 1737 /* 1738 * If the device inserted padding it means that (it thought) 1739 * the 802.11 header wasn't a multiple of 4 bytes long. In 1740 * this case, reserve two bytes at the start of the SKB to 1741 * align the payload properly in case we end up copying it. 1742 */ 1743 skb_reserve(skb, 2); 1744 } 1745 1746 rx_status = IEEE80211_SKB_RXCB(skb); 1747 1748 /* This may be overridden by iwl_mvm_rx_he() to HE_RU */ 1749 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { 1750 case RATE_MCS_CHAN_WIDTH_20: 1751 break; 1752 case RATE_MCS_CHAN_WIDTH_40: 1753 rx_status->bw = RATE_INFO_BW_40; 1754 break; 1755 case RATE_MCS_CHAN_WIDTH_80: 1756 rx_status->bw = RATE_INFO_BW_80; 1757 break; 1758 case RATE_MCS_CHAN_WIDTH_160: 1759 rx_status->bw = RATE_INFO_BW_160; 1760 break; 1761 } 1762 1763 if (rate_n_flags & RATE_MCS_HE_MSK) 1764 iwl_mvm_rx_he(mvm, skb, &phy_data, rate_n_flags, 1765 phy_info, queue); 1766 1767 iwl_mvm_decode_lsig(skb, &phy_data); 1768 1769 /* 1770 * Keep packets with CRC errors (and with overrun) for monitor mode 1771 * (otherwise the firmware discards them) but mark them as bad. 1772 */ 1773 if (!(desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_CRC_OK)) || 1774 !(desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_OVERRUN_OK))) { 1775 IWL_DEBUG_RX(mvm, "Bad CRC or FIFO: 0x%08X.\n", 1776 le32_to_cpu(desc->status)); 1777 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; 1778 } 1779 /* set the preamble flag if appropriate */ 1780 if (rate_n_flags & RATE_MCS_CCK_MSK && 1781 phy_info & IWL_RX_MPDU_PHY_SHORT_PREAMBLE) 1782 rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE; 1783 1784 if (likely(!(phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD))) { 1785 u64 tsf_on_air_rise; 1786 1787 if (mvm->trans->trans_cfg->device_family >= 1788 IWL_DEVICE_FAMILY_AX210) 1789 tsf_on_air_rise = le64_to_cpu(desc->v3.tsf_on_air_rise); 1790 else 1791 tsf_on_air_rise = le64_to_cpu(desc->v1.tsf_on_air_rise); 1792 1793 rx_status->mactime = tsf_on_air_rise; 1794 /* TSF as indicated by the firmware is at INA time */ 1795 rx_status->flag |= RX_FLAG_MACTIME_PLCP_START; 1796 } 1797 1798 rx_status->device_timestamp = gp2_on_air_rise; 1799 if (iwl_mvm_is_band_in_rx_supported(mvm)) { 1800 u8 band = BAND_IN_RX_STATUS(desc->mac_phy_idx); 1801 1802 rx_status->band = iwl_mvm_nl80211_band_from_rx_msdu(band); 1803 } else { 1804 rx_status->band = channel > 14 ? NL80211_BAND_5GHZ : 1805 NL80211_BAND_2GHZ; 1806 } 1807 rx_status->freq = ieee80211_channel_to_frequency(channel, 1808 rx_status->band); 1809 iwl_mvm_get_signal_strength(mvm, rx_status, rate_n_flags, energy_a, 1810 energy_b); 1811 1812 /* update aggregation data for monitor sake on default queue */ 1813 if (!queue && (phy_info & IWL_RX_MPDU_PHY_AMPDU)) { 1814 bool toggle_bit = phy_info & IWL_RX_MPDU_PHY_AMPDU_TOGGLE; 1815 1816 rx_status->flag |= RX_FLAG_AMPDU_DETAILS; 1817 /* 1818 * Toggle is switched whenever new aggregation starts. Make 1819 * sure ampdu_reference is never 0 so we can later use it to 1820 * see if the frame was really part of an A-MPDU or not. 1821 */ 1822 if (toggle_bit != mvm->ampdu_toggle) { 1823 mvm->ampdu_ref++; 1824 if (mvm->ampdu_ref == 0) 1825 mvm->ampdu_ref++; 1826 mvm->ampdu_toggle = toggle_bit; 1827 } 1828 rx_status->ampdu_reference = mvm->ampdu_ref; 1829 } 1830 1831 if (unlikely(mvm->monitor_on)) 1832 iwl_mvm_add_rtap_sniffer_config(mvm, skb); 1833 1834 rcu_read_lock(); 1835 1836 if (desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_SRC_STA_FOUND)) { 1837 u8 id = le32_get_bits(desc->status, IWL_RX_MPDU_STATUS_STA_ID); 1838 1839 if (!WARN_ON_ONCE(id >= mvm->fw->ucode_capa.num_stations)) { 1840 sta = rcu_dereference(mvm->fw_id_to_mac_id[id]); 1841 if (IS_ERR(sta)) 1842 sta = NULL; 1843 } 1844 } else if (!is_multicast_ether_addr(hdr->addr2)) { 1845 /* 1846 * This is fine since we prevent two stations with the same 1847 * address from being added. 1848 */ 1849 sta = ieee80211_find_sta_by_ifaddr(mvm->hw, hdr->addr2, NULL); 1850 } 1851 1852 if (iwl_mvm_rx_crypto(mvm, sta, hdr, rx_status, phy_info, desc, 1853 le32_to_cpu(pkt->len_n_flags), queue, 1854 &crypt_len)) { 1855 kfree_skb(skb); 1856 goto out; 1857 } 1858 1859 if (sta) { 1860 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 1861 struct ieee80211_vif *tx_blocked_vif = 1862 rcu_dereference(mvm->csa_tx_blocked_vif); 1863 u8 baid = (u8)((le32_to_cpu(desc->reorder_data) & 1864 IWL_RX_MPDU_REORDER_BAID_MASK) >> 1865 IWL_RX_MPDU_REORDER_BAID_SHIFT); 1866 struct iwl_fw_dbg_trigger_tlv *trig; 1867 struct ieee80211_vif *vif = mvmsta->vif; 1868 1869 if (!mvm->tcm.paused && len >= sizeof(*hdr) && 1870 !is_multicast_ether_addr(hdr->addr1) && 1871 ieee80211_is_data(hdr->frame_control) && 1872 time_after(jiffies, mvm->tcm.ts + MVM_TCM_PERIOD)) 1873 schedule_delayed_work(&mvm->tcm.work, 0); 1874 1875 /* 1876 * We have tx blocked stations (with CS bit). If we heard 1877 * frames from a blocked station on a new channel we can 1878 * TX to it again. 1879 */ 1880 if (unlikely(tx_blocked_vif) && tx_blocked_vif == vif) { 1881 struct iwl_mvm_vif *mvmvif = 1882 iwl_mvm_vif_from_mac80211(tx_blocked_vif); 1883 struct iwl_rx_sta_csa rx_sta_csa = { 1884 .all_sta_unblocked = true, 1885 .vif = tx_blocked_vif, 1886 }; 1887 1888 if (mvmvif->csa_target_freq == rx_status->freq) 1889 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, 1890 false); 1891 ieee80211_iterate_stations_atomic(mvm->hw, 1892 iwl_mvm_rx_get_sta_block_tx, 1893 &rx_sta_csa); 1894 1895 if (rx_sta_csa.all_sta_unblocked) { 1896 RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL); 1897 /* Unblock BCAST / MCAST station */ 1898 iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false); 1899 cancel_delayed_work_sync(&mvm->cs_tx_unblock_dwork); 1900 } 1901 } 1902 1903 rs_update_last_rssi(mvm, mvmsta, rx_status); 1904 1905 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, 1906 ieee80211_vif_to_wdev(vif), 1907 FW_DBG_TRIGGER_RSSI); 1908 1909 if (trig && ieee80211_is_beacon(hdr->frame_control)) { 1910 struct iwl_fw_dbg_trigger_low_rssi *rssi_trig; 1911 s32 rssi; 1912 1913 rssi_trig = (void *)trig->data; 1914 rssi = le32_to_cpu(rssi_trig->rssi); 1915 1916 if (rx_status->signal < rssi) 1917 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 1918 NULL); 1919 } 1920 1921 if (ieee80211_is_data(hdr->frame_control)) 1922 iwl_mvm_rx_csum(mvm, sta, skb, pkt); 1923 1924 if (iwl_mvm_is_dup(sta, queue, rx_status, hdr, desc)) { 1925 kfree_skb(skb); 1926 goto out; 1927 } 1928 1929 /* 1930 * Our hardware de-aggregates AMSDUs but copies the mac header 1931 * as it to the de-aggregated MPDUs. We need to turn off the 1932 * AMSDU bit in the QoS control ourselves. 1933 * In addition, HW reverses addr3 and addr4 - reverse it back. 1934 */ 1935 if ((desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU) && 1936 !WARN_ON(!ieee80211_is_data_qos(hdr->frame_control))) { 1937 u8 *qc = ieee80211_get_qos_ctl(hdr); 1938 1939 *qc &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT; 1940 1941 if (mvm->trans->trans_cfg->device_family == 1942 IWL_DEVICE_FAMILY_9000) { 1943 iwl_mvm_flip_address(hdr->addr3); 1944 1945 if (ieee80211_has_a4(hdr->frame_control)) 1946 iwl_mvm_flip_address(hdr->addr4); 1947 } 1948 } 1949 if (baid != IWL_RX_REORDER_DATA_INVALID_BAID) { 1950 u32 reorder_data = le32_to_cpu(desc->reorder_data); 1951 1952 iwl_mvm_agg_rx_received(mvm, reorder_data, baid); 1953 } 1954 } 1955 1956 if (!(rate_n_flags & RATE_MCS_CCK_MSK) && 1957 rate_n_flags & RATE_MCS_SGI_MSK) 1958 rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI; 1959 if (rate_n_flags & RATE_HT_MCS_GF_MSK) 1960 rx_status->enc_flags |= RX_ENC_FLAG_HT_GF; 1961 if (rate_n_flags & RATE_MCS_LDPC_MSK) 1962 rx_status->enc_flags |= RX_ENC_FLAG_LDPC; 1963 if (rate_n_flags & RATE_MCS_HT_MSK) { 1964 u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >> 1965 RATE_MCS_STBC_POS; 1966 rx_status->encoding = RX_ENC_HT; 1967 rx_status->rate_idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK; 1968 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT; 1969 } else if (rate_n_flags & RATE_MCS_VHT_MSK) { 1970 u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >> 1971 RATE_MCS_STBC_POS; 1972 rx_status->nss = 1973 ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >> 1974 RATE_VHT_MCS_NSS_POS) + 1; 1975 rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK; 1976 rx_status->encoding = RX_ENC_VHT; 1977 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT; 1978 if (rate_n_flags & RATE_MCS_BF_MSK) 1979 rx_status->enc_flags |= RX_ENC_FLAG_BF; 1980 } else if (!(rate_n_flags & RATE_MCS_HE_MSK)) { 1981 int rate = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags, 1982 rx_status->band); 1983 1984 if (WARN(rate < 0 || rate > 0xFF, 1985 "Invalid rate flags 0x%x, band %d,\n", 1986 rate_n_flags, rx_status->band)) { 1987 kfree_skb(skb); 1988 goto out; 1989 } 1990 rx_status->rate_idx = rate; 1991 } 1992 1993 /* management stuff on default queue */ 1994 if (!queue) { 1995 if (unlikely((ieee80211_is_beacon(hdr->frame_control) || 1996 ieee80211_is_probe_resp(hdr->frame_control)) && 1997 mvm->sched_scan_pass_all == 1998 SCHED_SCAN_PASS_ALL_ENABLED)) 1999 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_FOUND; 2000 2001 if (unlikely(ieee80211_is_beacon(hdr->frame_control) || 2002 ieee80211_is_probe_resp(hdr->frame_control))) 2003 rx_status->boottime_ns = ktime_get_boottime_ns(); 2004 } 2005 2006 if (iwl_mvm_create_skb(mvm, skb, hdr, len, crypt_len, rxb)) { 2007 kfree_skb(skb); 2008 goto out; 2009 } 2010 2011 if (!iwl_mvm_reorder(mvm, napi, queue, sta, skb, desc)) 2012 iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb, queue, 2013 sta, csi); 2014 out: 2015 rcu_read_unlock(); 2016 } 2017 2018 void iwl_mvm_rx_monitor_no_data(struct iwl_mvm *mvm, struct napi_struct *napi, 2019 struct iwl_rx_cmd_buffer *rxb, int queue) 2020 { 2021 struct ieee80211_rx_status *rx_status; 2022 struct iwl_rx_packet *pkt = rxb_addr(rxb); 2023 struct iwl_rx_no_data *desc = (void *)pkt->data; 2024 u32 rate_n_flags = le32_to_cpu(desc->rate); 2025 u32 gp2_on_air_rise = le32_to_cpu(desc->on_air_rise_time); 2026 u32 rssi = le32_to_cpu(desc->rssi); 2027 u32 info_type = le32_to_cpu(desc->info) & RX_NO_DATA_INFO_TYPE_MSK; 2028 u16 phy_info = IWL_RX_MPDU_PHY_TSF_OVERLOAD; 2029 struct ieee80211_sta *sta = NULL; 2030 struct sk_buff *skb; 2031 u8 channel, energy_a, energy_b; 2032 struct iwl_mvm_rx_phy_data phy_data = { 2033 .d0 = desc->phy_info[0], 2034 .info_type = IWL_RX_PHY_INFO_TYPE_NONE, 2035 }; 2036 2037 if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(*desc))) 2038 return; 2039 2040 if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))) 2041 return; 2042 2043 energy_a = (rssi & RX_NO_DATA_CHAIN_A_MSK) >> RX_NO_DATA_CHAIN_A_POS; 2044 energy_b = (rssi & RX_NO_DATA_CHAIN_B_MSK) >> RX_NO_DATA_CHAIN_B_POS; 2045 channel = (rssi & RX_NO_DATA_CHANNEL_MSK) >> RX_NO_DATA_CHANNEL_POS; 2046 2047 phy_data.info_type = 2048 le32_get_bits(desc->phy_info[1], 2049 IWL_RX_PHY_DATA1_INFO_TYPE_MASK); 2050 2051 /* Dont use dev_alloc_skb(), we'll have enough headroom once 2052 * ieee80211_hdr pulled. 2053 */ 2054 skb = alloc_skb(128, GFP_ATOMIC); 2055 if (!skb) { 2056 IWL_ERR(mvm, "alloc_skb failed\n"); 2057 return; 2058 } 2059 2060 rx_status = IEEE80211_SKB_RXCB(skb); 2061 2062 /* 0-length PSDU */ 2063 rx_status->flag |= RX_FLAG_NO_PSDU; 2064 2065 switch (info_type) { 2066 case RX_NO_DATA_INFO_TYPE_NDP: 2067 rx_status->zero_length_psdu_type = 2068 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_SOUNDING; 2069 break; 2070 case RX_NO_DATA_INFO_TYPE_MU_UNMATCHED: 2071 case RX_NO_DATA_INFO_TYPE_HE_TB_UNMATCHED: 2072 rx_status->zero_length_psdu_type = 2073 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_NOT_CAPTURED; 2074 break; 2075 default: 2076 rx_status->zero_length_psdu_type = 2077 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_VENDOR; 2078 break; 2079 } 2080 2081 /* This may be overridden by iwl_mvm_rx_he() to HE_RU */ 2082 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { 2083 case RATE_MCS_CHAN_WIDTH_20: 2084 break; 2085 case RATE_MCS_CHAN_WIDTH_40: 2086 rx_status->bw = RATE_INFO_BW_40; 2087 break; 2088 case RATE_MCS_CHAN_WIDTH_80: 2089 rx_status->bw = RATE_INFO_BW_80; 2090 break; 2091 case RATE_MCS_CHAN_WIDTH_160: 2092 rx_status->bw = RATE_INFO_BW_160; 2093 break; 2094 } 2095 2096 if (rate_n_flags & RATE_MCS_HE_MSK) 2097 iwl_mvm_rx_he(mvm, skb, &phy_data, rate_n_flags, 2098 phy_info, queue); 2099 2100 iwl_mvm_decode_lsig(skb, &phy_data); 2101 2102 rx_status->device_timestamp = gp2_on_air_rise; 2103 rx_status->band = channel > 14 ? NL80211_BAND_5GHZ : 2104 NL80211_BAND_2GHZ; 2105 rx_status->freq = ieee80211_channel_to_frequency(channel, 2106 rx_status->band); 2107 iwl_mvm_get_signal_strength(mvm, rx_status, rate_n_flags, energy_a, 2108 energy_b); 2109 2110 rcu_read_lock(); 2111 2112 if (!(rate_n_flags & RATE_MCS_CCK_MSK) && 2113 rate_n_flags & RATE_MCS_SGI_MSK) 2114 rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI; 2115 if (rate_n_flags & RATE_HT_MCS_GF_MSK) 2116 rx_status->enc_flags |= RX_ENC_FLAG_HT_GF; 2117 if (rate_n_flags & RATE_MCS_LDPC_MSK) 2118 rx_status->enc_flags |= RX_ENC_FLAG_LDPC; 2119 if (rate_n_flags & RATE_MCS_HT_MSK) { 2120 u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >> 2121 RATE_MCS_STBC_POS; 2122 rx_status->encoding = RX_ENC_HT; 2123 rx_status->rate_idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK; 2124 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT; 2125 } else if (rate_n_flags & RATE_MCS_VHT_MSK) { 2126 u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >> 2127 RATE_MCS_STBC_POS; 2128 rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK; 2129 rx_status->encoding = RX_ENC_VHT; 2130 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT; 2131 if (rate_n_flags & RATE_MCS_BF_MSK) 2132 rx_status->enc_flags |= RX_ENC_FLAG_BF; 2133 /* 2134 * take the nss from the rx_vec since the rate_n_flags has 2135 * only 2 bits for the nss which gives a max of 4 ss but 2136 * there may be up to 8 spatial streams 2137 */ 2138 rx_status->nss = 2139 le32_get_bits(desc->rx_vec[0], 2140 RX_NO_DATA_RX_VEC0_VHT_NSTS_MSK) + 1; 2141 } else if (rate_n_flags & RATE_MCS_HE_MSK) { 2142 rx_status->nss = 2143 le32_get_bits(desc->rx_vec[0], 2144 RX_NO_DATA_RX_VEC0_HE_NSTS_MSK) + 1; 2145 } else { 2146 int rate = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags, 2147 rx_status->band); 2148 2149 if (WARN(rate < 0 || rate > 0xFF, 2150 "Invalid rate flags 0x%x, band %d,\n", 2151 rate_n_flags, rx_status->band)) { 2152 kfree_skb(skb); 2153 goto out; 2154 } 2155 rx_status->rate_idx = rate; 2156 } 2157 2158 ieee80211_rx_napi(mvm->hw, sta, skb, napi); 2159 out: 2160 rcu_read_unlock(); 2161 } 2162 2163 void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi, 2164 struct iwl_rx_cmd_buffer *rxb, int queue) 2165 { 2166 struct iwl_rx_packet *pkt = rxb_addr(rxb); 2167 struct iwl_frame_release *release = (void *)pkt->data; 2168 2169 if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(*release))) 2170 return; 2171 2172 iwl_mvm_release_frames_from_notif(mvm, napi, release->baid, 2173 le16_to_cpu(release->nssn), 2174 queue, 0); 2175 } 2176 2177 void iwl_mvm_rx_bar_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi, 2178 struct iwl_rx_cmd_buffer *rxb, int queue) 2179 { 2180 struct iwl_rx_packet *pkt = rxb_addr(rxb); 2181 struct iwl_bar_frame_release *release = (void *)pkt->data; 2182 unsigned int baid = le32_get_bits(release->ba_info, 2183 IWL_BAR_FRAME_RELEASE_BAID_MASK); 2184 unsigned int nssn = le32_get_bits(release->ba_info, 2185 IWL_BAR_FRAME_RELEASE_NSSN_MASK); 2186 unsigned int sta_id = le32_get_bits(release->sta_tid, 2187 IWL_BAR_FRAME_RELEASE_STA_MASK); 2188 unsigned int tid = le32_get_bits(release->sta_tid, 2189 IWL_BAR_FRAME_RELEASE_TID_MASK); 2190 struct iwl_mvm_baid_data *baid_data; 2191 2192 if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(*release))) 2193 return; 2194 2195 if (WARN_ON_ONCE(baid == IWL_RX_REORDER_DATA_INVALID_BAID || 2196 baid >= ARRAY_SIZE(mvm->baid_map))) 2197 return; 2198 2199 rcu_read_lock(); 2200 baid_data = rcu_dereference(mvm->baid_map[baid]); 2201 if (!baid_data) { 2202 IWL_DEBUG_RX(mvm, 2203 "Got valid BAID %d but not allocated, invalid BAR release!\n", 2204 baid); 2205 goto out; 2206 } 2207 2208 if (WARN(tid != baid_data->tid || sta_id != baid_data->sta_id, 2209 "baid 0x%x is mapped to sta:%d tid:%d, but BAR release received for sta:%d tid:%d\n", 2210 baid, baid_data->sta_id, baid_data->tid, sta_id, 2211 tid)) 2212 goto out; 2213 2214 iwl_mvm_release_frames_from_notif(mvm, napi, baid, nssn, queue, 0); 2215 out: 2216 rcu_read_unlock(); 2217 } 2218