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