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 inline int iwl_mvm_check_pn(struct iwl_mvm *mvm, struct sk_buff *skb, 70 int queue, struct ieee80211_sta *sta) 71 { 72 struct iwl_mvm_sta *mvmsta; 73 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 74 struct ieee80211_rx_status *stats = IEEE80211_SKB_RXCB(skb); 75 struct iwl_mvm_key_pn *ptk_pn; 76 int res; 77 u8 tid, keyidx; 78 u8 pn[IEEE80211_CCMP_PN_LEN]; 79 u8 *extiv; 80 81 /* do PN checking */ 82 83 /* multicast and non-data only arrives on default queue */ 84 if (!ieee80211_is_data(hdr->frame_control) || 85 is_multicast_ether_addr(hdr->addr1)) 86 return 0; 87 88 /* do not check PN for open AP */ 89 if (!(stats->flag & RX_FLAG_DECRYPTED)) 90 return 0; 91 92 /* 93 * avoid checking for default queue - we don't want to replicate 94 * all the logic that's necessary for checking the PN on fragmented 95 * frames, leave that to mac80211 96 */ 97 if (queue == 0) 98 return 0; 99 100 /* if we are here - this for sure is either CCMP or GCMP */ 101 if (IS_ERR_OR_NULL(sta)) { 102 IWL_ERR(mvm, 103 "expected hw-decrypted unicast frame for station\n"); 104 return -1; 105 } 106 107 mvmsta = iwl_mvm_sta_from_mac80211(sta); 108 109 extiv = (u8 *)hdr + ieee80211_hdrlen(hdr->frame_control); 110 keyidx = extiv[3] >> 6; 111 112 ptk_pn = rcu_dereference(mvmsta->ptk_pn[keyidx]); 113 if (!ptk_pn) 114 return -1; 115 116 if (ieee80211_is_data_qos(hdr->frame_control)) 117 tid = ieee80211_get_tid(hdr); 118 else 119 tid = 0; 120 121 /* we don't use HCCA/802.11 QoS TSPECs, so drop such frames */ 122 if (tid >= IWL_MAX_TID_COUNT) 123 return -1; 124 125 /* load pn */ 126 pn[0] = extiv[7]; 127 pn[1] = extiv[6]; 128 pn[2] = extiv[5]; 129 pn[3] = extiv[4]; 130 pn[4] = extiv[1]; 131 pn[5] = extiv[0]; 132 133 res = memcmp(pn, ptk_pn->q[queue].pn[tid], IEEE80211_CCMP_PN_LEN); 134 if (res < 0) 135 return -1; 136 if (!res && !(stats->flag & RX_FLAG_ALLOW_SAME_PN)) 137 return -1; 138 139 memcpy(ptk_pn->q[queue].pn[tid], pn, IEEE80211_CCMP_PN_LEN); 140 stats->flag |= RX_FLAG_PN_VALIDATED; 141 142 return 0; 143 } 144 145 /* iwl_mvm_create_skb Adds the rxb to a new skb */ 146 static void iwl_mvm_create_skb(struct sk_buff *skb, struct ieee80211_hdr *hdr, 147 u16 len, u8 crypt_len, 148 struct iwl_rx_cmd_buffer *rxb) 149 { 150 struct iwl_rx_packet *pkt = rxb_addr(rxb); 151 struct iwl_rx_mpdu_desc *desc = (void *)pkt->data; 152 unsigned int headlen, fraglen, pad_len = 0; 153 unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control); 154 155 if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) { 156 len -= 2; 157 pad_len = 2; 158 } 159 160 /* If frame is small enough to fit in skb->head, pull it completely. 161 * If not, only pull ieee80211_hdr (including crypto if present, and 162 * an additional 8 bytes for SNAP/ethertype, see below) so that 163 * splice() or TCP coalesce are more efficient. 164 * 165 * Since, in addition, ieee80211_data_to_8023() always pull in at 166 * least 8 bytes (possibly more for mesh) we can do the same here 167 * to save the cost of doing it later. That still doesn't pull in 168 * the actual IP header since the typical case has a SNAP header. 169 * If the latter changes (there are efforts in the standards group 170 * to do so) we should revisit this and ieee80211_data_to_8023(). 171 */ 172 headlen = (len <= skb_tailroom(skb)) ? len : 173 hdrlen + crypt_len + 8; 174 175 /* The firmware may align the packet to DWORD. 176 * The padding is inserted after the IV. 177 * After copying the header + IV skip the padding if 178 * present before copying packet data. 179 */ 180 hdrlen += crypt_len; 181 skb_put_data(skb, hdr, hdrlen); 182 skb_put_data(skb, (u8 *)hdr + hdrlen + pad_len, headlen - hdrlen); 183 184 fraglen = len - headlen; 185 186 if (fraglen) { 187 int offset = (void *)hdr + headlen + pad_len - 188 rxb_addr(rxb) + rxb_offset(rxb); 189 190 skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset, 191 fraglen, rxb->truesize); 192 } 193 } 194 195 /* iwl_mvm_pass_packet_to_mac80211 - passes the packet for mac80211 */ 196 static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm *mvm, 197 struct napi_struct *napi, 198 struct sk_buff *skb, int queue, 199 struct ieee80211_sta *sta) 200 { 201 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 202 203 if (iwl_mvm_check_pn(mvm, skb, queue, sta)) { 204 kfree_skb(skb); 205 } else { 206 unsigned int radiotap_len = 0; 207 208 if (rx_status->flag & RX_FLAG_RADIOTAP_HE) 209 radiotap_len += sizeof(struct ieee80211_radiotap_he); 210 if (rx_status->flag & RX_FLAG_RADIOTAP_HE_MU) 211 radiotap_len += sizeof(struct ieee80211_radiotap_he_mu); 212 __skb_push(skb, radiotap_len); 213 ieee80211_rx_napi(mvm->hw, sta, skb, napi); 214 } 215 } 216 217 static void iwl_mvm_get_signal_strength(struct iwl_mvm *mvm, 218 struct ieee80211_rx_status *rx_status, 219 u32 rate_n_flags, int energy_a, 220 int energy_b) 221 { 222 int max_energy; 223 u32 rate_flags = rate_n_flags; 224 225 energy_a = energy_a ? -energy_a : S8_MIN; 226 energy_b = energy_b ? -energy_b : S8_MIN; 227 max_energy = max(energy_a, energy_b); 228 229 IWL_DEBUG_STATS(mvm, "energy In A %d B %d, and max %d\n", 230 energy_a, energy_b, max_energy); 231 232 rx_status->signal = max_energy; 233 rx_status->chains = 234 (rate_flags & RATE_MCS_ANT_AB_MSK) >> RATE_MCS_ANT_POS; 235 rx_status->chain_signal[0] = energy_a; 236 rx_status->chain_signal[1] = energy_b; 237 rx_status->chain_signal[2] = S8_MIN; 238 } 239 240 static int iwl_mvm_rx_crypto(struct iwl_mvm *mvm, struct ieee80211_hdr *hdr, 241 struct ieee80211_rx_status *stats, u16 phy_info, 242 struct iwl_rx_mpdu_desc *desc, 243 u32 pkt_flags, int queue, u8 *crypt_len) 244 { 245 u16 status = le16_to_cpu(desc->status); 246 247 /* 248 * Drop UNKNOWN frames in aggregation, unless in monitor mode 249 * (where we don't have the keys). 250 * We limit this to aggregation because in TKIP this is a valid 251 * scenario, since we may not have the (correct) TTAK (phase 1 252 * key) in the firmware. 253 */ 254 if (phy_info & IWL_RX_MPDU_PHY_AMPDU && 255 (status & IWL_RX_MPDU_STATUS_SEC_MASK) == 256 IWL_RX_MPDU_STATUS_SEC_UNKNOWN && !mvm->monitor_on) 257 return -1; 258 259 if (!ieee80211_has_protected(hdr->frame_control) || 260 (status & IWL_RX_MPDU_STATUS_SEC_MASK) == 261 IWL_RX_MPDU_STATUS_SEC_NONE) 262 return 0; 263 264 /* TODO: handle packets encrypted with unknown alg */ 265 266 switch (status & IWL_RX_MPDU_STATUS_SEC_MASK) { 267 case IWL_RX_MPDU_STATUS_SEC_CCM: 268 case IWL_RX_MPDU_STATUS_SEC_GCM: 269 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN != IEEE80211_GCMP_PN_LEN); 270 /* alg is CCM: check MIC only */ 271 if (!(status & IWL_RX_MPDU_STATUS_MIC_OK)) 272 return -1; 273 274 stats->flag |= RX_FLAG_DECRYPTED; 275 if (pkt_flags & FH_RSCSR_RADA_EN) 276 stats->flag |= RX_FLAG_MIC_STRIPPED; 277 *crypt_len = IEEE80211_CCMP_HDR_LEN; 278 return 0; 279 case IWL_RX_MPDU_STATUS_SEC_TKIP: 280 /* Don't drop the frame and decrypt it in SW */ 281 if (!fw_has_api(&mvm->fw->ucode_capa, 282 IWL_UCODE_TLV_API_DEPRECATE_TTAK) && 283 !(status & IWL_RX_MPDU_RES_STATUS_TTAK_OK)) 284 return 0; 285 286 if (mvm->trans->cfg->gen2 && 287 !(status & RX_MPDU_RES_STATUS_MIC_OK)) 288 stats->flag |= RX_FLAG_MMIC_ERROR; 289 290 *crypt_len = IEEE80211_TKIP_IV_LEN; 291 /* fall through if TTAK OK */ 292 case IWL_RX_MPDU_STATUS_SEC_WEP: 293 if (!(status & IWL_RX_MPDU_STATUS_ICV_OK)) 294 return -1; 295 296 stats->flag |= RX_FLAG_DECRYPTED; 297 if ((status & IWL_RX_MPDU_STATUS_SEC_MASK) == 298 IWL_RX_MPDU_STATUS_SEC_WEP) 299 *crypt_len = IEEE80211_WEP_IV_LEN; 300 301 if (pkt_flags & FH_RSCSR_RADA_EN) { 302 stats->flag |= RX_FLAG_ICV_STRIPPED; 303 if (mvm->trans->cfg->gen2) 304 stats->flag |= RX_FLAG_MMIC_STRIPPED; 305 } 306 307 return 0; 308 case IWL_RX_MPDU_STATUS_SEC_EXT_ENC: 309 if (!(status & IWL_RX_MPDU_STATUS_MIC_OK)) 310 return -1; 311 stats->flag |= RX_FLAG_DECRYPTED; 312 return 0; 313 default: 314 /* Expected in monitor (not having the keys) */ 315 if (!mvm->monitor_on) 316 IWL_ERR(mvm, "Unhandled alg: 0x%x\n", status); 317 } 318 319 return 0; 320 } 321 322 static void iwl_mvm_rx_csum(struct ieee80211_sta *sta, 323 struct sk_buff *skb, 324 struct iwl_rx_mpdu_desc *desc) 325 { 326 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 327 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif); 328 u16 flags = le16_to_cpu(desc->l3l4_flags); 329 u8 l3_prot = (u8)((flags & IWL_RX_L3L4_L3_PROTO_MASK) >> 330 IWL_RX_L3_PROTO_POS); 331 332 if (mvmvif->features & NETIF_F_RXCSUM && 333 flags & IWL_RX_L3L4_TCP_UDP_CSUM_OK && 334 (flags & IWL_RX_L3L4_IP_HDR_CSUM_OK || 335 l3_prot == IWL_RX_L3_TYPE_IPV6 || 336 l3_prot == IWL_RX_L3_TYPE_IPV6_FRAG)) 337 skb->ip_summed = CHECKSUM_UNNECESSARY; 338 } 339 340 /* 341 * returns true if a packet is a duplicate and should be dropped. 342 * Updates AMSDU PN tracking info 343 */ 344 static bool iwl_mvm_is_dup(struct ieee80211_sta *sta, int queue, 345 struct ieee80211_rx_status *rx_status, 346 struct ieee80211_hdr *hdr, 347 struct iwl_rx_mpdu_desc *desc) 348 { 349 struct iwl_mvm_sta *mvm_sta; 350 struct iwl_mvm_rxq_dup_data *dup_data; 351 u8 tid, sub_frame_idx; 352 353 if (WARN_ON(IS_ERR_OR_NULL(sta))) 354 return false; 355 356 mvm_sta = iwl_mvm_sta_from_mac80211(sta); 357 dup_data = &mvm_sta->dup_data[queue]; 358 359 /* 360 * Drop duplicate 802.11 retransmissions 361 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery") 362 */ 363 if (ieee80211_is_ctl(hdr->frame_control) || 364 ieee80211_is_qos_nullfunc(hdr->frame_control) || 365 is_multicast_ether_addr(hdr->addr1)) { 366 rx_status->flag |= RX_FLAG_DUP_VALIDATED; 367 return false; 368 } 369 370 if (ieee80211_is_data_qos(hdr->frame_control)) 371 /* frame has qos control */ 372 tid = ieee80211_get_tid(hdr); 373 else 374 tid = IWL_MAX_TID_COUNT; 375 376 /* If this wasn't a part of an A-MSDU the sub-frame index will be 0 */ 377 sub_frame_idx = desc->amsdu_info & 378 IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK; 379 380 if (unlikely(ieee80211_has_retry(hdr->frame_control) && 381 dup_data->last_seq[tid] == hdr->seq_ctrl && 382 dup_data->last_sub_frame[tid] >= sub_frame_idx)) 383 return true; 384 385 /* Allow same PN as the first subframe for following sub frames */ 386 if (dup_data->last_seq[tid] == hdr->seq_ctrl && 387 sub_frame_idx > dup_data->last_sub_frame[tid] && 388 desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU) 389 rx_status->flag |= RX_FLAG_ALLOW_SAME_PN; 390 391 dup_data->last_seq[tid] = hdr->seq_ctrl; 392 dup_data->last_sub_frame[tid] = sub_frame_idx; 393 394 rx_status->flag |= RX_FLAG_DUP_VALIDATED; 395 396 return false; 397 } 398 399 int iwl_mvm_notify_rx_queue(struct iwl_mvm *mvm, u32 rxq_mask, 400 const u8 *data, u32 count) 401 { 402 struct iwl_rxq_sync_cmd *cmd; 403 u32 data_size = sizeof(*cmd) + count; 404 int ret; 405 406 /* should be DWORD aligned */ 407 if (WARN_ON(count & 3 || count > IWL_MULTI_QUEUE_SYNC_MSG_MAX_SIZE)) 408 return -EINVAL; 409 410 cmd = kzalloc(data_size, GFP_KERNEL); 411 if (!cmd) 412 return -ENOMEM; 413 414 cmd->rxq_mask = cpu_to_le32(rxq_mask); 415 cmd->count = cpu_to_le32(count); 416 cmd->flags = 0; 417 memcpy(cmd->payload, data, count); 418 419 ret = iwl_mvm_send_cmd_pdu(mvm, 420 WIDE_ID(DATA_PATH_GROUP, 421 TRIGGER_RX_QUEUES_NOTIF_CMD), 422 0, data_size, cmd); 423 424 kfree(cmd); 425 return ret; 426 } 427 428 /* 429 * Returns true if sn2 - buffer_size < sn1 < sn2. 430 * To be used only in order to compare reorder buffer head with NSSN. 431 * We fully trust NSSN unless it is behind us due to reorder timeout. 432 * Reorder timeout can only bring us up to buffer_size SNs ahead of NSSN. 433 */ 434 static bool iwl_mvm_is_sn_less(u16 sn1, u16 sn2, u16 buffer_size) 435 { 436 return ieee80211_sn_less(sn1, sn2) && 437 !ieee80211_sn_less(sn1, sn2 - buffer_size); 438 } 439 440 #define RX_REORDER_BUF_TIMEOUT_MQ (HZ / 10) 441 442 static void iwl_mvm_release_frames(struct iwl_mvm *mvm, 443 struct ieee80211_sta *sta, 444 struct napi_struct *napi, 445 struct iwl_mvm_baid_data *baid_data, 446 struct iwl_mvm_reorder_buffer *reorder_buf, 447 u16 nssn) 448 { 449 struct iwl_mvm_reorder_buf_entry *entries = 450 &baid_data->entries[reorder_buf->queue * 451 baid_data->entries_per_queue]; 452 u16 ssn = reorder_buf->head_sn; 453 454 lockdep_assert_held(&reorder_buf->lock); 455 456 /* ignore nssn smaller than head sn - this can happen due to timeout */ 457 if (iwl_mvm_is_sn_less(nssn, ssn, reorder_buf->buf_size)) 458 goto set_timer; 459 460 while (iwl_mvm_is_sn_less(ssn, nssn, reorder_buf->buf_size)) { 461 int index = ssn % reorder_buf->buf_size; 462 struct sk_buff_head *skb_list = &entries[index].e.frames; 463 struct sk_buff *skb; 464 465 ssn = ieee80211_sn_inc(ssn); 466 467 /* 468 * Empty the list. Will have more than one frame for A-MSDU. 469 * Empty list is valid as well since nssn indicates frames were 470 * received. 471 */ 472 while ((skb = __skb_dequeue(skb_list))) { 473 iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb, 474 reorder_buf->queue, 475 sta); 476 reorder_buf->num_stored--; 477 } 478 } 479 reorder_buf->head_sn = nssn; 480 481 set_timer: 482 if (reorder_buf->num_stored && !reorder_buf->removed) { 483 u16 index = reorder_buf->head_sn % reorder_buf->buf_size; 484 485 while (skb_queue_empty(&entries[index].e.frames)) 486 index = (index + 1) % reorder_buf->buf_size; 487 /* modify timer to match next frame's expiration time */ 488 mod_timer(&reorder_buf->reorder_timer, 489 entries[index].e.reorder_time + 1 + 490 RX_REORDER_BUF_TIMEOUT_MQ); 491 } else { 492 del_timer(&reorder_buf->reorder_timer); 493 } 494 } 495 496 void iwl_mvm_reorder_timer_expired(struct timer_list *t) 497 { 498 struct iwl_mvm_reorder_buffer *buf = from_timer(buf, t, reorder_timer); 499 struct iwl_mvm_baid_data *baid_data = 500 iwl_mvm_baid_data_from_reorder_buf(buf); 501 struct iwl_mvm_reorder_buf_entry *entries = 502 &baid_data->entries[buf->queue * baid_data->entries_per_queue]; 503 int i; 504 u16 sn = 0, index = 0; 505 bool expired = false; 506 bool cont = false; 507 508 spin_lock(&buf->lock); 509 510 if (!buf->num_stored || buf->removed) { 511 spin_unlock(&buf->lock); 512 return; 513 } 514 515 for (i = 0; i < buf->buf_size ; i++) { 516 index = (buf->head_sn + i) % buf->buf_size; 517 518 if (skb_queue_empty(&entries[index].e.frames)) { 519 /* 520 * If there is a hole and the next frame didn't expire 521 * we want to break and not advance SN 522 */ 523 cont = false; 524 continue; 525 } 526 if (!cont && 527 !time_after(jiffies, entries[index].e.reorder_time + 528 RX_REORDER_BUF_TIMEOUT_MQ)) 529 break; 530 531 expired = true; 532 /* continue until next hole after this expired frames */ 533 cont = true; 534 sn = ieee80211_sn_add(buf->head_sn, i + 1); 535 } 536 537 if (expired) { 538 struct ieee80211_sta *sta; 539 struct iwl_mvm_sta *mvmsta; 540 u8 sta_id = baid_data->sta_id; 541 542 rcu_read_lock(); 543 sta = rcu_dereference(buf->mvm->fw_id_to_mac_id[sta_id]); 544 mvmsta = iwl_mvm_sta_from_mac80211(sta); 545 546 /* SN is set to the last expired frame + 1 */ 547 IWL_DEBUG_HT(buf->mvm, 548 "Releasing expired frames for sta %u, sn %d\n", 549 sta_id, sn); 550 iwl_mvm_event_frame_timeout_callback(buf->mvm, mvmsta->vif, 551 sta, baid_data->tid); 552 iwl_mvm_release_frames(buf->mvm, sta, NULL, baid_data, buf, sn); 553 rcu_read_unlock(); 554 } else { 555 /* 556 * If no frame expired and there are stored frames, index is now 557 * pointing to the first unexpired frame - modify timer 558 * accordingly to this frame. 559 */ 560 mod_timer(&buf->reorder_timer, 561 entries[index].e.reorder_time + 562 1 + RX_REORDER_BUF_TIMEOUT_MQ); 563 } 564 spin_unlock(&buf->lock); 565 } 566 567 static void iwl_mvm_del_ba(struct iwl_mvm *mvm, int queue, 568 struct iwl_mvm_delba_data *data) 569 { 570 struct iwl_mvm_baid_data *ba_data; 571 struct ieee80211_sta *sta; 572 struct iwl_mvm_reorder_buffer *reorder_buf; 573 u8 baid = data->baid; 574 575 if (WARN_ONCE(baid >= IWL_MAX_BAID, "invalid BAID: %x\n", baid)) 576 return; 577 578 rcu_read_lock(); 579 580 ba_data = rcu_dereference(mvm->baid_map[baid]); 581 if (WARN_ON_ONCE(!ba_data)) 582 goto out; 583 584 sta = rcu_dereference(mvm->fw_id_to_mac_id[ba_data->sta_id]); 585 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) 586 goto out; 587 588 reorder_buf = &ba_data->reorder_buf[queue]; 589 590 /* release all frames that are in the reorder buffer to the stack */ 591 spin_lock_bh(&reorder_buf->lock); 592 iwl_mvm_release_frames(mvm, sta, NULL, ba_data, reorder_buf, 593 ieee80211_sn_add(reorder_buf->head_sn, 594 reorder_buf->buf_size)); 595 spin_unlock_bh(&reorder_buf->lock); 596 del_timer_sync(&reorder_buf->reorder_timer); 597 598 out: 599 rcu_read_unlock(); 600 } 601 602 void iwl_mvm_rx_queue_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb, 603 int queue) 604 { 605 struct iwl_rx_packet *pkt = rxb_addr(rxb); 606 struct iwl_rxq_sync_notification *notif; 607 struct iwl_mvm_internal_rxq_notif *internal_notif; 608 609 notif = (void *)pkt->data; 610 internal_notif = (void *)notif->payload; 611 612 if (internal_notif->sync && 613 mvm->queue_sync_cookie != internal_notif->cookie) { 614 WARN_ONCE(1, "Received expired RX queue sync message\n"); 615 return; 616 } 617 618 switch (internal_notif->type) { 619 case IWL_MVM_RXQ_EMPTY: 620 break; 621 case IWL_MVM_RXQ_NOTIF_DEL_BA: 622 iwl_mvm_del_ba(mvm, queue, (void *)internal_notif->data); 623 break; 624 default: 625 WARN_ONCE(1, "Invalid identifier %d", internal_notif->type); 626 } 627 628 if (internal_notif->sync && 629 !atomic_dec_return(&mvm->queue_sync_counter)) 630 wake_up(&mvm->rx_sync_waitq); 631 } 632 633 /* 634 * Returns true if the MPDU was buffered\dropped, false if it should be passed 635 * to upper layer. 636 */ 637 static bool iwl_mvm_reorder(struct iwl_mvm *mvm, 638 struct napi_struct *napi, 639 int queue, 640 struct ieee80211_sta *sta, 641 struct sk_buff *skb, 642 struct iwl_rx_mpdu_desc *desc) 643 { 644 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 645 struct iwl_mvm_sta *mvm_sta; 646 struct iwl_mvm_baid_data *baid_data; 647 struct iwl_mvm_reorder_buffer *buffer; 648 struct sk_buff *tail; 649 u32 reorder = le32_to_cpu(desc->reorder_data); 650 bool amsdu = desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU; 651 bool last_subframe = 652 desc->amsdu_info & IWL_RX_MPDU_AMSDU_LAST_SUBFRAME; 653 u8 tid = ieee80211_get_tid(hdr); 654 u8 sub_frame_idx = desc->amsdu_info & 655 IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK; 656 struct iwl_mvm_reorder_buf_entry *entries; 657 int index; 658 u16 nssn, sn; 659 u8 baid; 660 661 baid = (reorder & IWL_RX_MPDU_REORDER_BAID_MASK) >> 662 IWL_RX_MPDU_REORDER_BAID_SHIFT; 663 664 /* 665 * This also covers the case of receiving a Block Ack Request 666 * outside a BA session; we'll pass it to mac80211 and that 667 * then sends a delBA action frame. 668 */ 669 if (baid == IWL_RX_REORDER_DATA_INVALID_BAID) 670 return false; 671 672 /* no sta yet */ 673 if (WARN_ONCE(IS_ERR_OR_NULL(sta), 674 "Got valid BAID without a valid station assigned\n")) 675 return false; 676 677 mvm_sta = iwl_mvm_sta_from_mac80211(sta); 678 679 /* not a data packet or a bar */ 680 if (!ieee80211_is_back_req(hdr->frame_control) && 681 (!ieee80211_is_data_qos(hdr->frame_control) || 682 is_multicast_ether_addr(hdr->addr1))) 683 return false; 684 685 if (unlikely(!ieee80211_is_data_present(hdr->frame_control))) 686 return false; 687 688 baid_data = rcu_dereference(mvm->baid_map[baid]); 689 if (!baid_data) { 690 IWL_DEBUG_RX(mvm, 691 "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n", 692 baid, reorder); 693 return false; 694 } 695 696 if (WARN(tid != baid_data->tid || mvm_sta->sta_id != baid_data->sta_id, 697 "baid 0x%x is mapped to sta:%d tid:%d, but was received for sta:%d tid:%d\n", 698 baid, baid_data->sta_id, baid_data->tid, mvm_sta->sta_id, 699 tid)) 700 return false; 701 702 nssn = reorder & IWL_RX_MPDU_REORDER_NSSN_MASK; 703 sn = (reorder & IWL_RX_MPDU_REORDER_SN_MASK) >> 704 IWL_RX_MPDU_REORDER_SN_SHIFT; 705 706 buffer = &baid_data->reorder_buf[queue]; 707 entries = &baid_data->entries[queue * baid_data->entries_per_queue]; 708 709 spin_lock_bh(&buffer->lock); 710 711 if (!buffer->valid) { 712 if (reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN) { 713 spin_unlock_bh(&buffer->lock); 714 return false; 715 } 716 buffer->valid = true; 717 } 718 719 if (ieee80211_is_back_req(hdr->frame_control)) { 720 iwl_mvm_release_frames(mvm, sta, napi, baid_data, buffer, nssn); 721 goto drop; 722 } 723 724 /* 725 * If there was a significant jump in the nssn - adjust. 726 * If the SN is smaller than the NSSN it might need to first go into 727 * the reorder buffer, in which case we just release up to it and the 728 * rest of the function will take care of storing it and releasing up to 729 * the nssn 730 */ 731 if (!iwl_mvm_is_sn_less(nssn, buffer->head_sn + buffer->buf_size, 732 buffer->buf_size) || 733 !ieee80211_sn_less(sn, buffer->head_sn + buffer->buf_size)) { 734 u16 min_sn = ieee80211_sn_less(sn, nssn) ? sn : nssn; 735 736 iwl_mvm_release_frames(mvm, sta, napi, baid_data, buffer, 737 min_sn); 738 } 739 740 /* drop any oudated packets */ 741 if (ieee80211_sn_less(sn, buffer->head_sn)) 742 goto drop; 743 744 /* release immediately if allowed by nssn and no stored frames */ 745 if (!buffer->num_stored && ieee80211_sn_less(sn, nssn)) { 746 if (iwl_mvm_is_sn_less(buffer->head_sn, nssn, 747 buffer->buf_size) && 748 (!amsdu || last_subframe)) 749 buffer->head_sn = nssn; 750 /* No need to update AMSDU last SN - we are moving the head */ 751 spin_unlock_bh(&buffer->lock); 752 return false; 753 } 754 755 /* 756 * release immediately if there are no stored frames, and the sn is 757 * equal to the head. 758 * This can happen due to reorder timer, where NSSN is behind head_sn. 759 * When we released everything, and we got the next frame in the 760 * sequence, according to the NSSN we can't release immediately, 761 * while technically there is no hole and we can move forward. 762 */ 763 if (!buffer->num_stored && sn == buffer->head_sn) { 764 if (!amsdu || last_subframe) 765 buffer->head_sn = ieee80211_sn_inc(buffer->head_sn); 766 /* No need to update AMSDU last SN - we are moving the head */ 767 spin_unlock_bh(&buffer->lock); 768 return false; 769 } 770 771 index = sn % buffer->buf_size; 772 773 /* 774 * Check if we already stored this frame 775 * As AMSDU is either received or not as whole, logic is simple: 776 * If we have frames in that position in the buffer and the last frame 777 * originated from AMSDU had a different SN then it is a retransmission. 778 * If it is the same SN then if the subframe index is incrementing it 779 * is the same AMSDU - otherwise it is a retransmission. 780 */ 781 tail = skb_peek_tail(&entries[index].e.frames); 782 if (tail && !amsdu) 783 goto drop; 784 else if (tail && (sn != buffer->last_amsdu || 785 buffer->last_sub_index >= sub_frame_idx)) 786 goto drop; 787 788 /* put in reorder buffer */ 789 __skb_queue_tail(&entries[index].e.frames, skb); 790 buffer->num_stored++; 791 entries[index].e.reorder_time = jiffies; 792 793 if (amsdu) { 794 buffer->last_amsdu = sn; 795 buffer->last_sub_index = sub_frame_idx; 796 } 797 798 /* 799 * We cannot trust NSSN for AMSDU sub-frames that are not the last. 800 * The reason is that NSSN advances on the first sub-frame, and may 801 * cause the reorder buffer to advance before all the sub-frames arrive. 802 * Example: reorder buffer contains SN 0 & 2, and we receive AMSDU with 803 * SN 1. NSSN for first sub frame will be 3 with the result of driver 804 * releasing SN 0,1, 2. When sub-frame 1 arrives - reorder buffer is 805 * already ahead and it will be dropped. 806 * If the last sub-frame is not on this queue - we will get frame 807 * release notification with up to date NSSN. 808 */ 809 if (!amsdu || last_subframe) 810 iwl_mvm_release_frames(mvm, sta, napi, baid_data, buffer, nssn); 811 812 spin_unlock_bh(&buffer->lock); 813 return true; 814 815 drop: 816 kfree_skb(skb); 817 spin_unlock_bh(&buffer->lock); 818 return true; 819 } 820 821 static void iwl_mvm_agg_rx_received(struct iwl_mvm *mvm, 822 u32 reorder_data, u8 baid) 823 { 824 unsigned long now = jiffies; 825 unsigned long timeout; 826 struct iwl_mvm_baid_data *data; 827 828 rcu_read_lock(); 829 830 data = rcu_dereference(mvm->baid_map[baid]); 831 if (!data) { 832 IWL_DEBUG_RX(mvm, 833 "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n", 834 baid, reorder_data); 835 goto out; 836 } 837 838 if (!data->timeout) 839 goto out; 840 841 timeout = data->timeout; 842 /* 843 * Do not update last rx all the time to avoid cache bouncing 844 * between the rx queues. 845 * Update it every timeout. Worst case is the session will 846 * expire after ~ 2 * timeout, which doesn't matter that much. 847 */ 848 if (time_before(data->last_rx + TU_TO_JIFFIES(timeout), now)) 849 /* Update is atomic */ 850 data->last_rx = now; 851 852 out: 853 rcu_read_unlock(); 854 } 855 856 static void iwl_mvm_flip_address(u8 *addr) 857 { 858 int i; 859 u8 mac_addr[ETH_ALEN]; 860 861 for (i = 0; i < ETH_ALEN; i++) 862 mac_addr[i] = addr[ETH_ALEN - i - 1]; 863 ether_addr_copy(addr, mac_addr); 864 } 865 866 static void iwl_mvm_decode_he_sigb(struct iwl_mvm *mvm, 867 struct iwl_rx_mpdu_desc *desc, 868 u32 rate_n_flags, 869 struct ieee80211_radiotap_he_mu *he_mu) 870 { 871 u32 sigb0, sigb1; 872 u16 sigb2; 873 874 if (mvm->trans->cfg->device_family >= IWL_DEVICE_FAMILY_22560) { 875 sigb0 = le32_to_cpu(desc->v3.sigb_common0); 876 sigb1 = le32_to_cpu(desc->v3.sigb_common1); 877 } else { 878 sigb0 = le32_to_cpu(desc->v1.sigb_common0); 879 sigb1 = le32_to_cpu(desc->v1.sigb_common1); 880 } 881 882 sigb2 = le16_to_cpu(desc->sigb_common2); 883 884 if (FIELD_GET(IWL_RX_HE_SIGB_COMMON2_CH1_CRC_OK, sigb2)) { 885 he_mu->flags1 |= 886 cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_RU_KNOWN | 887 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU_KNOWN); 888 889 he_mu->flags1 |= 890 le16_encode_bits(FIELD_GET(IWL_RX_HE_SIGB_COMMON2_CH1_CTR_RU, 891 sigb2), 892 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU); 893 894 he_mu->ru_ch1[0] = FIELD_GET(IWL_RX_HE_SIGB_COMMON0_CH1_RU0, 895 sigb0); 896 he_mu->ru_ch1[1] = FIELD_GET(IWL_RX_HE_SIGB_COMMON1_CH1_RU1, 897 sigb1); 898 he_mu->ru_ch1[2] = FIELD_GET(IWL_RX_HE_SIGB_COMMON0_CH1_RU2, 899 sigb0); 900 he_mu->ru_ch1[3] = FIELD_GET(IWL_RX_HE_SIGB_COMMON1_CH1_RU3, 901 sigb1); 902 } 903 904 if (FIELD_GET(IWL_RX_HE_SIGB_COMMON2_CH2_CRC_OK, sigb2) && 905 (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) != RATE_MCS_CHAN_WIDTH_20) { 906 he_mu->flags1 |= 907 cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_RU_KNOWN | 908 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_CTR_26T_RU_KNOWN); 909 910 he_mu->flags2 |= 911 le16_encode_bits(FIELD_GET(IWL_RX_HE_SIGB_COMMON2_CH2_CTR_RU, 912 sigb2), 913 IEEE80211_RADIOTAP_HE_MU_FLAGS2_CH2_CTR_26T_RU); 914 915 he_mu->ru_ch2[0] = FIELD_GET(IWL_RX_HE_SIGB_COMMON0_CH2_RU0, 916 sigb0); 917 he_mu->ru_ch2[1] = FIELD_GET(IWL_RX_HE_SIGB_COMMON1_CH2_RU1, 918 sigb1); 919 he_mu->ru_ch2[2] = FIELD_GET(IWL_RX_HE_SIGB_COMMON0_CH2_RU2, 920 sigb0); 921 he_mu->ru_ch2[3] = FIELD_GET(IWL_RX_HE_SIGB_COMMON1_CH2_RU3, 922 sigb1); 923 } 924 } 925 926 static void 927 iwl_mvm_decode_he_phy_ru_alloc(u64 he_phy_data, u32 rate_n_flags, 928 struct ieee80211_radiotap_he *he, 929 struct ieee80211_radiotap_he_mu *he_mu, 930 struct ieee80211_rx_status *rx_status) 931 { 932 /* 933 * Unfortunately, we have to leave the mac80211 data 934 * incorrect for the case that we receive an HE-MU 935 * transmission and *don't* have the HE phy data (due 936 * to the bits being used for TSF). This shouldn't 937 * happen though as management frames where we need 938 * the TSF/timers are not be transmitted in HE-MU. 939 */ 940 u8 ru = FIELD_GET(IWL_RX_HE_PHY_RU_ALLOC_MASK, he_phy_data); 941 u8 offs = 0; 942 943 rx_status->bw = RATE_INFO_BW_HE_RU; 944 945 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN); 946 947 switch (ru) { 948 case 0 ... 36: 949 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_26; 950 offs = ru; 951 break; 952 case 37 ... 52: 953 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_52; 954 offs = ru - 37; 955 break; 956 case 53 ... 60: 957 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106; 958 offs = ru - 53; 959 break; 960 case 61 ... 64: 961 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_242; 962 offs = ru - 61; 963 break; 964 case 65 ... 66: 965 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_484; 966 offs = ru - 65; 967 break; 968 case 67: 969 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_996; 970 break; 971 case 68: 972 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_2x996; 973 break; 974 } 975 he->data2 |= le16_encode_bits(offs, 976 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET); 977 he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_KNOWN | 978 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET_KNOWN); 979 if (he_phy_data & IWL_RX_HE_PHY_RU_ALLOC_SEC80) 980 he->data2 |= 981 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_SEC); 982 983 if (he_mu) { 984 #define CHECK_BW(bw) \ 985 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_ ## bw ## MHZ != \ 986 RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS) 987 CHECK_BW(20); 988 CHECK_BW(40); 989 CHECK_BW(80); 990 CHECK_BW(160); 991 he_mu->flags2 |= 992 le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK, 993 rate_n_flags), 994 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW); 995 } 996 } 997 998 static void iwl_mvm_decode_he_phy_data(struct iwl_mvm *mvm, 999 struct iwl_rx_mpdu_desc *desc, 1000 struct ieee80211_radiotap_he *he, 1001 struct ieee80211_radiotap_he_mu *he_mu, 1002 struct ieee80211_rx_status *rx_status, 1003 u64 he_phy_data, u32 rate_n_flags, 1004 int queue) 1005 { 1006 u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK; 1007 bool sigb_data; 1008 u16 d1known = IEEE80211_RADIOTAP_HE_DATA1_LDPC_XSYMSEG_KNOWN | 1009 IEEE80211_RADIOTAP_HE_DATA1_UL_DL_KNOWN | 1010 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN | 1011 IEEE80211_RADIOTAP_HE_DATA1_DOPPLER_KNOWN | 1012 IEEE80211_RADIOTAP_HE_DATA1_BSS_COLOR_KNOWN; 1013 u16 d2known = IEEE80211_RADIOTAP_HE_DATA2_PRE_FEC_PAD_KNOWN | 1014 IEEE80211_RADIOTAP_HE_DATA2_PE_DISAMBIG_KNOWN | 1015 IEEE80211_RADIOTAP_HE_DATA2_TXOP_KNOWN; 1016 1017 he->data1 |= cpu_to_le16(d1known); 1018 he->data2 |= cpu_to_le16(d2known); 1019 he->data3 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_BSS_COLOR_MASK, 1020 he_phy_data), 1021 IEEE80211_RADIOTAP_HE_DATA3_BSS_COLOR); 1022 he->data3 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_UPLINK, 1023 he_phy_data), 1024 IEEE80211_RADIOTAP_HE_DATA3_UL_DL); 1025 he->data3 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_LDPC_EXT_SYM, 1026 he_phy_data), 1027 IEEE80211_RADIOTAP_HE_DATA3_LDPC_XSYMSEG); 1028 he->data4 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_SPATIAL_REUSE_MASK, 1029 he_phy_data), 1030 IEEE80211_RADIOTAP_HE_DATA4_SU_MU_SPTL_REUSE); 1031 he->data5 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_PRE_FEC_PAD_MASK, 1032 he_phy_data), 1033 IEEE80211_RADIOTAP_HE_DATA5_PRE_FEC_PAD); 1034 he->data5 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_PE_DISAMBIG, 1035 he_phy_data), 1036 IEEE80211_RADIOTAP_HE_DATA5_PE_DISAMBIG); 1037 he->data6 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_TXOP_DUR_MASK, 1038 he_phy_data), 1039 IEEE80211_RADIOTAP_HE_DATA6_TXOP); 1040 he->data6 |= le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_DOPPLER, 1041 he_phy_data), 1042 IEEE80211_RADIOTAP_HE_DATA6_DOPPLER); 1043 1044 switch (he_type) { 1045 case RATE_MCS_HE_TYPE_MU: 1046 he_mu->flags1 |= 1047 le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_MU_SIGB_DCM, 1048 he_phy_data), 1049 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM); 1050 he_mu->flags1 |= 1051 le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_MU_SIGB_MCS_MASK, 1052 he_phy_data), 1053 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS); 1054 he_mu->flags2 |= 1055 le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_MU_SIBG_SYM_OR_USER_NUM_MASK, 1056 he_phy_data), 1057 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_SYMS_USERS); 1058 he_mu->flags2 |= 1059 le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_MU_SIGB_COMPRESSION, 1060 he_phy_data), 1061 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_COMP); 1062 he_mu->flags2 |= 1063 le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_MU_PREAMBLE_PUNC_TYPE_MASK, 1064 he_phy_data), 1065 IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW); 1066 1067 sigb_data = FIELD_GET(IWL_RX_HE_PHY_INFO_TYPE_MASK, 1068 he_phy_data) == 1069 IWL_RX_HE_PHY_INFO_TYPE_MU_EXT_INFO; 1070 if (sigb_data) 1071 iwl_mvm_decode_he_sigb(mvm, desc, rate_n_flags, he_mu); 1072 /* fall through */ 1073 case RATE_MCS_HE_TYPE_TRIG: 1074 he->data2 |= 1075 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_NUM_LTF_SYMS_KNOWN); 1076 he->data5 |= 1077 le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_HE_LTF_NUM_MASK, 1078 he_phy_data), 1079 IEEE80211_RADIOTAP_HE_DATA5_NUM_LTF_SYMS); 1080 break; 1081 case RATE_MCS_HE_TYPE_SU: 1082 case RATE_MCS_HE_TYPE_EXT_SU: 1083 he->data1 |= 1084 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BEAM_CHANGE_KNOWN); 1085 he->data3 |= 1086 le16_encode_bits(FIELD_GET(IWL_RX_HE_PHY_BEAM_CHNG, 1087 he_phy_data), 1088 IEEE80211_RADIOTAP_HE_DATA3_BEAM_CHANGE); 1089 break; 1090 } 1091 1092 switch (FIELD_GET(IWL_RX_HE_PHY_INFO_TYPE_MASK, he_phy_data)) { 1093 case IWL_RX_HE_PHY_INFO_TYPE_MU: 1094 case IWL_RX_HE_PHY_INFO_TYPE_MU_EXT_INFO: 1095 case IWL_RX_HE_PHY_INFO_TYPE_TB: 1096 iwl_mvm_decode_he_phy_ru_alloc(he_phy_data, rate_n_flags, 1097 he, he_mu, rx_status); 1098 break; 1099 default: 1100 /* nothing */ 1101 break; 1102 } 1103 } 1104 1105 static void iwl_mvm_rx_he(struct iwl_mvm *mvm, struct sk_buff *skb, 1106 struct iwl_rx_mpdu_desc *desc, 1107 u32 rate_n_flags, u16 phy_info, int queue) 1108 { 1109 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb); 1110 /* this is invalid e.g. because puncture type doesn't allow 0b11 */ 1111 #define HE_PHY_DATA_INVAL ((u64)-1) 1112 u64 he_phy_data = HE_PHY_DATA_INVAL; 1113 struct ieee80211_radiotap_he *he = NULL; 1114 struct ieee80211_radiotap_he_mu *he_mu = NULL; 1115 u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK; 1116 u8 stbc, ltf; 1117 static const struct ieee80211_radiotap_he known = { 1118 .data1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_DATA_MCS_KNOWN | 1119 IEEE80211_RADIOTAP_HE_DATA1_DATA_DCM_KNOWN | 1120 IEEE80211_RADIOTAP_HE_DATA1_STBC_KNOWN | 1121 IEEE80211_RADIOTAP_HE_DATA1_CODING_KNOWN), 1122 .data2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_GI_KNOWN | 1123 IEEE80211_RADIOTAP_HE_DATA2_TXBF_KNOWN), 1124 }; 1125 static const struct ieee80211_radiotap_he_mu mu_known = { 1126 .flags1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS_KNOWN | 1127 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM_KNOWN | 1128 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_SYMS_USERS_KNOWN | 1129 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_COMP_KNOWN), 1130 .flags2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW_KNOWN | 1131 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_KNOWN), 1132 }; 1133 unsigned int radiotap_len = 0; 1134 1135 he = skb_put_data(skb, &known, sizeof(known)); 1136 radiotap_len += sizeof(known); 1137 rx_status->flag |= RX_FLAG_RADIOTAP_HE; 1138 1139 if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) { 1140 if (mvm->trans->cfg->device_family >= IWL_DEVICE_FAMILY_22560) 1141 he_phy_data = le64_to_cpu(desc->v3.he_phy_data); 1142 else 1143 he_phy_data = le64_to_cpu(desc->v1.he_phy_data); 1144 1145 if (he_type == RATE_MCS_HE_TYPE_MU) { 1146 he_mu = skb_put_data(skb, &mu_known, sizeof(mu_known)); 1147 radiotap_len += sizeof(mu_known); 1148 rx_status->flag |= RX_FLAG_RADIOTAP_HE_MU; 1149 } 1150 } 1151 1152 /* temporarily hide the radiotap data */ 1153 __skb_pull(skb, radiotap_len); 1154 1155 if (he_phy_data != HE_PHY_DATA_INVAL && 1156 he_type == RATE_MCS_HE_TYPE_SU) { 1157 /* report the AMPDU-EOF bit on single frames */ 1158 if (!queue && !(phy_info & IWL_RX_MPDU_PHY_AMPDU)) { 1159 rx_status->flag |= RX_FLAG_AMPDU_DETAILS; 1160 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN; 1161 if (FIELD_GET(IWL_RX_HE_PHY_DELIM_EOF, he_phy_data)) 1162 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT; 1163 } 1164 } 1165 1166 if (he_phy_data != HE_PHY_DATA_INVAL) 1167 iwl_mvm_decode_he_phy_data(mvm, desc, he, he_mu, rx_status, 1168 he_phy_data, rate_n_flags, queue); 1169 1170 /* update aggregation data for monitor sake on default queue */ 1171 if (!queue && (phy_info & IWL_RX_MPDU_PHY_AMPDU)) { 1172 bool toggle_bit = phy_info & IWL_RX_MPDU_PHY_AMPDU_TOGGLE; 1173 1174 /* toggle is switched whenever new aggregation starts */ 1175 if (toggle_bit != mvm->ampdu_toggle && 1176 he_phy_data != HE_PHY_DATA_INVAL && 1177 (he_type == RATE_MCS_HE_TYPE_MU || 1178 he_type == RATE_MCS_HE_TYPE_SU)) { 1179 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN; 1180 if (FIELD_GET(IWL_RX_HE_PHY_DELIM_EOF, 1181 he_phy_data)) 1182 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT; 1183 } 1184 } 1185 1186 if (he_type == RATE_MCS_HE_TYPE_EXT_SU && 1187 rate_n_flags & RATE_MCS_HE_106T_MSK) { 1188 rx_status->bw = RATE_INFO_BW_HE_RU; 1189 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106; 1190 } 1191 1192 /* actually data is filled in mac80211 */ 1193 if (he_type == RATE_MCS_HE_TYPE_SU || 1194 he_type == RATE_MCS_HE_TYPE_EXT_SU) 1195 he->data1 |= 1196 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN); 1197 1198 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >> RATE_MCS_STBC_POS; 1199 rx_status->nss = 1200 ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >> 1201 RATE_VHT_MCS_NSS_POS) + 1; 1202 rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK; 1203 rx_status->encoding = RX_ENC_HE; 1204 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT; 1205 if (rate_n_flags & RATE_MCS_BF_MSK) 1206 rx_status->enc_flags |= RX_ENC_FLAG_BF; 1207 1208 rx_status->he_dcm = 1209 !!(rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK); 1210 1211 #define CHECK_TYPE(F) \ 1212 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_ ## F != \ 1213 (RATE_MCS_HE_TYPE_ ## F >> RATE_MCS_HE_TYPE_POS)) 1214 1215 CHECK_TYPE(SU); 1216 CHECK_TYPE(EXT_SU); 1217 CHECK_TYPE(MU); 1218 CHECK_TYPE(TRIG); 1219 1220 he->data1 |= cpu_to_le16(he_type >> RATE_MCS_HE_TYPE_POS); 1221 1222 if (rate_n_flags & RATE_MCS_BF_MSK) 1223 he->data5 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA5_TXBF); 1224 1225 switch ((rate_n_flags & RATE_MCS_HE_GI_LTF_MSK) >> 1226 RATE_MCS_HE_GI_LTF_POS) { 1227 case 0: 1228 if (he_type == RATE_MCS_HE_TYPE_TRIG) 1229 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 1230 else 1231 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 1232 if (he_type == RATE_MCS_HE_TYPE_MU) 1233 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 1234 else 1235 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X; 1236 break; 1237 case 1: 1238 if (he_type == RATE_MCS_HE_TYPE_TRIG) 1239 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 1240 else 1241 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 1242 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; 1243 break; 1244 case 2: 1245 if (he_type == RATE_MCS_HE_TYPE_TRIG) { 1246 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 1247 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 1248 } else { 1249 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6; 1250 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X; 1251 } 1252 break; 1253 case 3: 1254 if ((he_type == RATE_MCS_HE_TYPE_SU || 1255 he_type == RATE_MCS_HE_TYPE_EXT_SU) && 1256 rate_n_flags & RATE_MCS_SGI_MSK) 1257 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8; 1258 else 1259 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2; 1260 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X; 1261 break; 1262 } 1263 1264 he->data5 |= le16_encode_bits(ltf, IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE); 1265 1266 if (he_type == RATE_MCS_HE_TYPE_SU || 1267 he_type == RATE_MCS_HE_TYPE_EXT_SU) { 1268 u16 val; 1269 1270 /* LTF syms correspond to streams */ 1271 he->data2 |= 1272 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_NUM_LTF_SYMS_KNOWN); 1273 switch (rx_status->nss) { 1274 case 1: 1275 val = 0; 1276 break; 1277 case 2: 1278 val = 1; 1279 break; 1280 case 3: 1281 case 4: 1282 val = 2; 1283 break; 1284 case 5: 1285 case 6: 1286 val = 3; 1287 break; 1288 case 7: 1289 case 8: 1290 val = 4; 1291 break; 1292 default: 1293 WARN_ONCE(1, "invalid nss: %d\n", 1294 rx_status->nss); 1295 val = 0; 1296 } 1297 1298 he->data5 |= 1299 le16_encode_bits(val, 1300 IEEE80211_RADIOTAP_HE_DATA5_NUM_LTF_SYMS); 1301 } 1302 } 1303 1304 void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi, 1305 struct iwl_rx_cmd_buffer *rxb, int queue) 1306 { 1307 struct ieee80211_rx_status *rx_status; 1308 struct iwl_rx_packet *pkt = rxb_addr(rxb); 1309 struct iwl_rx_mpdu_desc *desc = (void *)pkt->data; 1310 struct ieee80211_hdr *hdr; 1311 u32 len = le16_to_cpu(desc->mpdu_len); 1312 u32 rate_n_flags, gp2_on_air_rise; 1313 u16 phy_info = le16_to_cpu(desc->phy_info); 1314 struct ieee80211_sta *sta = NULL; 1315 struct sk_buff *skb; 1316 u8 crypt_len = 0, channel, energy_a, energy_b; 1317 size_t desc_size; 1318 1319 if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))) 1320 return; 1321 1322 if (mvm->trans->cfg->device_family >= IWL_DEVICE_FAMILY_22560) { 1323 rate_n_flags = le32_to_cpu(desc->v3.rate_n_flags); 1324 channel = desc->v3.channel; 1325 gp2_on_air_rise = le32_to_cpu(desc->v3.gp2_on_air_rise); 1326 energy_a = desc->v3.energy_a; 1327 energy_b = desc->v3.energy_b; 1328 desc_size = sizeof(*desc); 1329 } else { 1330 rate_n_flags = le32_to_cpu(desc->v1.rate_n_flags); 1331 channel = desc->v1.channel; 1332 gp2_on_air_rise = le32_to_cpu(desc->v1.gp2_on_air_rise); 1333 energy_a = desc->v1.energy_a; 1334 energy_b = desc->v1.energy_b; 1335 desc_size = IWL_RX_DESC_SIZE_V1; 1336 } 1337 1338 hdr = (void *)(pkt->data + desc_size); 1339 /* Dont use dev_alloc_skb(), we'll have enough headroom once 1340 * ieee80211_hdr pulled. 1341 */ 1342 skb = alloc_skb(128, GFP_ATOMIC); 1343 if (!skb) { 1344 IWL_ERR(mvm, "alloc_skb failed\n"); 1345 return; 1346 } 1347 1348 if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) { 1349 /* 1350 * If the device inserted padding it means that (it thought) 1351 * the 802.11 header wasn't a multiple of 4 bytes long. In 1352 * this case, reserve two bytes at the start of the SKB to 1353 * align the payload properly in case we end up copying it. 1354 */ 1355 skb_reserve(skb, 2); 1356 } 1357 1358 rx_status = IEEE80211_SKB_RXCB(skb); 1359 1360 /* This may be overridden by iwl_mvm_rx_he() to HE_RU */ 1361 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) { 1362 case RATE_MCS_CHAN_WIDTH_20: 1363 break; 1364 case RATE_MCS_CHAN_WIDTH_40: 1365 rx_status->bw = RATE_INFO_BW_40; 1366 break; 1367 case RATE_MCS_CHAN_WIDTH_80: 1368 rx_status->bw = RATE_INFO_BW_80; 1369 break; 1370 case RATE_MCS_CHAN_WIDTH_160: 1371 rx_status->bw = RATE_INFO_BW_160; 1372 break; 1373 } 1374 1375 if (rate_n_flags & RATE_MCS_HE_MSK) 1376 iwl_mvm_rx_he(mvm, skb, desc, rate_n_flags, phy_info, queue); 1377 1378 rx_status = IEEE80211_SKB_RXCB(skb); 1379 1380 if (iwl_mvm_rx_crypto(mvm, hdr, rx_status, phy_info, desc, 1381 le32_to_cpu(pkt->len_n_flags), queue, 1382 &crypt_len)) { 1383 kfree_skb(skb); 1384 return; 1385 } 1386 1387 /* 1388 * Keep packets with CRC errors (and with overrun) for monitor mode 1389 * (otherwise the firmware discards them) but mark them as bad. 1390 */ 1391 if (!(desc->status & cpu_to_le16(IWL_RX_MPDU_STATUS_CRC_OK)) || 1392 !(desc->status & cpu_to_le16(IWL_RX_MPDU_STATUS_OVERRUN_OK))) { 1393 IWL_DEBUG_RX(mvm, "Bad CRC or FIFO: 0x%08X.\n", 1394 le16_to_cpu(desc->status)); 1395 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; 1396 } 1397 /* set the preamble flag if appropriate */ 1398 if (phy_info & IWL_RX_MPDU_PHY_SHORT_PREAMBLE) 1399 rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE; 1400 1401 if (likely(!(phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD))) { 1402 u64 tsf_on_air_rise; 1403 1404 if (mvm->trans->cfg->device_family >= IWL_DEVICE_FAMILY_22560) 1405 tsf_on_air_rise = le64_to_cpu(desc->v3.tsf_on_air_rise); 1406 else 1407 tsf_on_air_rise = le64_to_cpu(desc->v1.tsf_on_air_rise); 1408 1409 rx_status->mactime = tsf_on_air_rise; 1410 /* TSF as indicated by the firmware is at INA time */ 1411 rx_status->flag |= RX_FLAG_MACTIME_PLCP_START; 1412 } 1413 1414 rx_status->device_timestamp = gp2_on_air_rise; 1415 rx_status->band = channel > 14 ? NL80211_BAND_5GHZ : 1416 NL80211_BAND_2GHZ; 1417 rx_status->freq = ieee80211_channel_to_frequency(channel, 1418 rx_status->band); 1419 iwl_mvm_get_signal_strength(mvm, rx_status, rate_n_flags, energy_a, 1420 energy_b); 1421 1422 /* update aggregation data for monitor sake on default queue */ 1423 if (!queue && (phy_info & IWL_RX_MPDU_PHY_AMPDU)) { 1424 bool toggle_bit = phy_info & IWL_RX_MPDU_PHY_AMPDU_TOGGLE; 1425 u64 he_phy_data; 1426 1427 if (mvm->trans->cfg->device_family >= IWL_DEVICE_FAMILY_22560) 1428 he_phy_data = le64_to_cpu(desc->v3.he_phy_data); 1429 else 1430 he_phy_data = le64_to_cpu(desc->v1.he_phy_data); 1431 1432 rx_status->flag |= RX_FLAG_AMPDU_DETAILS; 1433 rx_status->ampdu_reference = mvm->ampdu_ref; 1434 /* toggle is switched whenever new aggregation starts */ 1435 if (toggle_bit != mvm->ampdu_toggle) { 1436 mvm->ampdu_ref++; 1437 mvm->ampdu_toggle = toggle_bit; 1438 } 1439 } 1440 1441 rcu_read_lock(); 1442 1443 if (desc->status & cpu_to_le16(IWL_RX_MPDU_STATUS_SRC_STA_FOUND)) { 1444 u8 id = desc->sta_id_flags & IWL_RX_MPDU_SIF_STA_ID_MASK; 1445 1446 if (!WARN_ON_ONCE(id >= ARRAY_SIZE(mvm->fw_id_to_mac_id))) { 1447 sta = rcu_dereference(mvm->fw_id_to_mac_id[id]); 1448 if (IS_ERR(sta)) 1449 sta = NULL; 1450 } 1451 } else if (!is_multicast_ether_addr(hdr->addr2)) { 1452 /* 1453 * This is fine since we prevent two stations with the same 1454 * address from being added. 1455 */ 1456 sta = ieee80211_find_sta_by_ifaddr(mvm->hw, hdr->addr2, NULL); 1457 } 1458 1459 if (sta) { 1460 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 1461 struct ieee80211_vif *tx_blocked_vif = 1462 rcu_dereference(mvm->csa_tx_blocked_vif); 1463 u8 baid = (u8)((le32_to_cpu(desc->reorder_data) & 1464 IWL_RX_MPDU_REORDER_BAID_MASK) >> 1465 IWL_RX_MPDU_REORDER_BAID_SHIFT); 1466 struct iwl_fw_dbg_trigger_tlv *trig; 1467 struct ieee80211_vif *vif = mvmsta->vif; 1468 1469 if (!mvm->tcm.paused && len >= sizeof(*hdr) && 1470 !is_multicast_ether_addr(hdr->addr1) && 1471 ieee80211_is_data(hdr->frame_control) && 1472 time_after(jiffies, mvm->tcm.ts + MVM_TCM_PERIOD)) 1473 schedule_delayed_work(&mvm->tcm.work, 0); 1474 1475 /* 1476 * We have tx blocked stations (with CS bit). If we heard 1477 * frames from a blocked station on a new channel we can 1478 * TX to it again. 1479 */ 1480 if (unlikely(tx_blocked_vif) && tx_blocked_vif == vif) { 1481 struct iwl_mvm_vif *mvmvif = 1482 iwl_mvm_vif_from_mac80211(tx_blocked_vif); 1483 1484 if (mvmvif->csa_target_freq == rx_status->freq) 1485 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, 1486 false); 1487 } 1488 1489 rs_update_last_rssi(mvm, mvmsta, rx_status); 1490 1491 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, 1492 ieee80211_vif_to_wdev(vif), 1493 FW_DBG_TRIGGER_RSSI); 1494 1495 if (trig && ieee80211_is_beacon(hdr->frame_control)) { 1496 struct iwl_fw_dbg_trigger_low_rssi *rssi_trig; 1497 s32 rssi; 1498 1499 rssi_trig = (void *)trig->data; 1500 rssi = le32_to_cpu(rssi_trig->rssi); 1501 1502 if (rx_status->signal < rssi) 1503 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig, 1504 NULL); 1505 } 1506 1507 if (ieee80211_is_data(hdr->frame_control)) 1508 iwl_mvm_rx_csum(sta, skb, desc); 1509 1510 if (iwl_mvm_is_dup(sta, queue, rx_status, hdr, desc)) { 1511 kfree_skb(skb); 1512 goto out; 1513 } 1514 1515 /* 1516 * Our hardware de-aggregates AMSDUs but copies the mac header 1517 * as it to the de-aggregated MPDUs. We need to turn off the 1518 * AMSDU bit in the QoS control ourselves. 1519 * In addition, HW reverses addr3 and addr4 - reverse it back. 1520 */ 1521 if ((desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU) && 1522 !WARN_ON(!ieee80211_is_data_qos(hdr->frame_control))) { 1523 u8 *qc = ieee80211_get_qos_ctl(hdr); 1524 1525 *qc &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT; 1526 1527 if (mvm->trans->cfg->device_family == 1528 IWL_DEVICE_FAMILY_9000) { 1529 iwl_mvm_flip_address(hdr->addr3); 1530 1531 if (ieee80211_has_a4(hdr->frame_control)) 1532 iwl_mvm_flip_address(hdr->addr4); 1533 } 1534 } 1535 if (baid != IWL_RX_REORDER_DATA_INVALID_BAID) { 1536 u32 reorder_data = le32_to_cpu(desc->reorder_data); 1537 1538 iwl_mvm_agg_rx_received(mvm, reorder_data, baid); 1539 } 1540 } 1541 1542 if (!(rate_n_flags & RATE_MCS_CCK_MSK) && 1543 rate_n_flags & RATE_MCS_SGI_MSK) 1544 rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI; 1545 if (rate_n_flags & RATE_HT_MCS_GF_MSK) 1546 rx_status->enc_flags |= RX_ENC_FLAG_HT_GF; 1547 if (rate_n_flags & RATE_MCS_LDPC_MSK) 1548 rx_status->enc_flags |= RX_ENC_FLAG_LDPC; 1549 if (rate_n_flags & RATE_MCS_HT_MSK) { 1550 u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >> 1551 RATE_MCS_STBC_POS; 1552 rx_status->encoding = RX_ENC_HT; 1553 rx_status->rate_idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK; 1554 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT; 1555 } else if (rate_n_flags & RATE_MCS_VHT_MSK) { 1556 u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >> 1557 RATE_MCS_STBC_POS; 1558 rx_status->nss = 1559 ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >> 1560 RATE_VHT_MCS_NSS_POS) + 1; 1561 rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK; 1562 rx_status->encoding = RX_ENC_VHT; 1563 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT; 1564 if (rate_n_flags & RATE_MCS_BF_MSK) 1565 rx_status->enc_flags |= RX_ENC_FLAG_BF; 1566 } else if (!(rate_n_flags & RATE_MCS_HE_MSK)) { 1567 int rate = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags, 1568 rx_status->band); 1569 1570 if (WARN(rate < 0 || rate > 0xFF, 1571 "Invalid rate flags 0x%x, band %d,\n", 1572 rate_n_flags, rx_status->band)) { 1573 kfree_skb(skb); 1574 goto out; 1575 } 1576 rx_status->rate_idx = rate; 1577 } 1578 1579 /* management stuff on default queue */ 1580 if (!queue) { 1581 if (unlikely((ieee80211_is_beacon(hdr->frame_control) || 1582 ieee80211_is_probe_resp(hdr->frame_control)) && 1583 mvm->sched_scan_pass_all == 1584 SCHED_SCAN_PASS_ALL_ENABLED)) 1585 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_FOUND; 1586 1587 if (unlikely(ieee80211_is_beacon(hdr->frame_control) || 1588 ieee80211_is_probe_resp(hdr->frame_control))) 1589 rx_status->boottime_ns = ktime_get_boot_ns(); 1590 } 1591 1592 iwl_mvm_create_skb(skb, hdr, len, crypt_len, rxb); 1593 if (!iwl_mvm_reorder(mvm, napi, queue, sta, skb, desc)) 1594 iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb, queue, sta); 1595 out: 1596 rcu_read_unlock(); 1597 } 1598 1599 void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi, 1600 struct iwl_rx_cmd_buffer *rxb, int queue) 1601 { 1602 struct iwl_rx_packet *pkt = rxb_addr(rxb); 1603 struct iwl_frame_release *release = (void *)pkt->data; 1604 struct ieee80211_sta *sta; 1605 struct iwl_mvm_reorder_buffer *reorder_buf; 1606 struct iwl_mvm_baid_data *ba_data; 1607 1608 int baid = release->baid; 1609 1610 IWL_DEBUG_HT(mvm, "Frame release notification for BAID %u, NSSN %d\n", 1611 release->baid, le16_to_cpu(release->nssn)); 1612 1613 if (WARN_ON_ONCE(baid == IWL_RX_REORDER_DATA_INVALID_BAID)) 1614 return; 1615 1616 rcu_read_lock(); 1617 1618 ba_data = rcu_dereference(mvm->baid_map[baid]); 1619 if (WARN_ON_ONCE(!ba_data)) 1620 goto out; 1621 1622 sta = rcu_dereference(mvm->fw_id_to_mac_id[ba_data->sta_id]); 1623 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) 1624 goto out; 1625 1626 reorder_buf = &ba_data->reorder_buf[queue]; 1627 1628 spin_lock_bh(&reorder_buf->lock); 1629 iwl_mvm_release_frames(mvm, sta, napi, ba_data, reorder_buf, 1630 le16_to_cpu(release->nssn)); 1631 spin_unlock_bh(&reorder_buf->lock); 1632 1633 out: 1634 rcu_read_unlock(); 1635 } 1636