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