1 /******************************************************************************
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.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
11 * Copyright(c) 2018 - 2019 Intel Corporation
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.
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.
22 * The full GNU General Public License is included in this distribution
23 * in the file called COPYING.
25 * Contact Information:
26 * Intel Linux Wireless <linuxwifi@intel.com>
27 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
34 * Copyright(c) 2018 - 2019 Intel Corporation
35 * All rights reserved.
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
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
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.
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"
69 static void *iwl_mvm_skb_get_hdr(struct sk_buff
*skb
)
71 struct ieee80211_rx_status
*rx_status
= IEEE80211_SKB_RXCB(skb
);
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);
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
;
89 data
+= sizeof(*radiotap
) + radiotap
->len
+ radiotap
->pad
;
95 static inline int iwl_mvm_check_pn(struct iwl_mvm
*mvm
, struct sk_buff
*skb
,
96 int queue
, struct ieee80211_sta
*sta
)
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
;
104 u8 pn
[IEEE80211_CCMP_PN_LEN
];
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
))
114 /* do not check PN for open AP */
115 if (!(stats
->flag
& RX_FLAG_DECRYPTED
))
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
126 /* if we are here - this for sure is either CCMP or GCMP */
127 if (IS_ERR_OR_NULL(sta
)) {
129 "expected hw-decrypted unicast frame for station\n");
133 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
135 extiv
= (u8
*)hdr
+ ieee80211_hdrlen(hdr
->frame_control
);
136 keyidx
= extiv
[3] >> 6;
138 ptk_pn
= rcu_dereference(mvmsta
->ptk_pn
[keyidx
]);
142 if (ieee80211_is_data_qos(hdr
->frame_control
))
143 tid
= ieee80211_get_tid(hdr
);
147 /* we don't use HCCA/802.11 QoS TSPECs, so drop such frames */
148 if (tid
>= IWL_MAX_TID_COUNT
)
159 res
= memcmp(pn
, ptk_pn
->q
[queue
].pn
[tid
], IEEE80211_CCMP_PN_LEN
);
162 if (!res
&& !(stats
->flag
& RX_FLAG_ALLOW_SAME_PN
))
165 memcpy(ptk_pn
->q
[queue
].pn
[tid
], pn
, IEEE80211_CCMP_PN_LEN
);
166 stats
->flag
|= RX_FLAG_PN_VALIDATED
;
171 /* iwl_mvm_create_skb Adds the rxb to a new skb */
172 static int iwl_mvm_create_skb(struct iwl_mvm
*mvm
, struct sk_buff
*skb
,
173 struct ieee80211_hdr
*hdr
, u16 len
, u8 crypt_len
,
174 struct iwl_rx_cmd_buffer
*rxb
)
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
);
181 if (desc
->mac_flags2
& IWL_RX_MPDU_MFLG2_PAD
) {
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.
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().
198 headlen
= (len
<= skb_tailroom(skb
)) ? len
:
199 hdrlen
+ crypt_len
+ 8;
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.
208 if (WARN_ONCE(headlen
< hdrlen
,
209 "invalid packet lengths (hdrlen=%d, len=%d, crypt_len=%d)\n",
210 hdrlen
, len
, crypt_len
)) {
212 * We warn and trace because we want to be able to see
213 * it in trace-cmd as well.
216 "invalid packet lengths (hdrlen=%d, len=%d, crypt_len=%d)\n",
217 hdrlen
, len
, crypt_len
);
221 skb_put_data(skb
, hdr
, hdrlen
);
222 skb_put_data(skb
, (u8
*)hdr
+ hdrlen
+ pad_len
, headlen
- hdrlen
);
224 fraglen
= len
- headlen
;
227 int offset
= (void *)hdr
+ headlen
+ pad_len
-
228 rxb_addr(rxb
) + rxb_offset(rxb
);
230 skb_add_rx_frag(skb
, 0, rxb_steal_page(rxb
), offset
,
231 fraglen
, rxb
->truesize
);
237 static void iwl_mvm_add_rtap_sniffer_config(struct iwl_mvm
*mvm
,
240 struct ieee80211_rx_status
*rx_status
= IEEE80211_SKB_RXCB(skb
);
241 struct ieee80211_vendor_radiotap
*radiotap
;
242 const int size
= sizeof(*radiotap
) + sizeof(__le16
);
247 /* ensure alignment */
248 BUILD_BUG_ON((size
+ 2) % 4);
250 radiotap
= skb_put(skb
, size
+ 2);
253 radiotap
->oui
[0] = 0xf6;
254 radiotap
->oui
[1] = 0x54;
255 radiotap
->oui
[2] = 0x25;
256 /* radiotap sniffer config sub-namespace */
258 radiotap
->present
= 0x1;
259 radiotap
->len
= size
- sizeof(*radiotap
);
262 /* fill the data now */
263 memcpy(radiotap
->data
, &mvm
->cur_aid
, sizeof(mvm
->cur_aid
));
264 /* and clear the padding */
265 memset(radiotap
->data
+ sizeof(__le16
), 0, radiotap
->pad
);
267 rx_status
->flag
|= RX_FLAG_RADIOTAP_VENDOR_DATA
;
270 /* iwl_mvm_pass_packet_to_mac80211 - passes the packet for mac80211 */
271 static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm
*mvm
,
272 struct napi_struct
*napi
,
273 struct sk_buff
*skb
, int queue
,
274 struct ieee80211_sta
*sta
,
277 if (iwl_mvm_check_pn(mvm
, skb
, queue
, sta
))
280 ieee80211_rx_napi(mvm
->hw
, sta
, skb
, napi
);
283 static void iwl_mvm_get_signal_strength(struct iwl_mvm
*mvm
,
284 struct ieee80211_rx_status
*rx_status
,
285 u32 rate_n_flags
, int energy_a
,
289 u32 rate_flags
= rate_n_flags
;
291 energy_a
= energy_a
? -energy_a
: S8_MIN
;
292 energy_b
= energy_b
? -energy_b
: S8_MIN
;
293 max_energy
= max(energy_a
, energy_b
);
295 IWL_DEBUG_STATS(mvm
, "energy In A %d B %d, and max %d\n",
296 energy_a
, energy_b
, max_energy
);
298 rx_status
->signal
= max_energy
;
300 (rate_flags
& RATE_MCS_ANT_AB_MSK
) >> RATE_MCS_ANT_POS
;
301 rx_status
->chain_signal
[0] = energy_a
;
302 rx_status
->chain_signal
[1] = energy_b
;
303 rx_status
->chain_signal
[2] = S8_MIN
;
306 static int iwl_mvm_rx_crypto(struct iwl_mvm
*mvm
, struct ieee80211_hdr
*hdr
,
307 struct ieee80211_rx_status
*stats
, u16 phy_info
,
308 struct iwl_rx_mpdu_desc
*desc
,
309 u32 pkt_flags
, int queue
, u8
*crypt_len
)
311 u16 status
= le16_to_cpu(desc
->status
);
314 * Drop UNKNOWN frames in aggregation, unless in monitor mode
315 * (where we don't have the keys).
316 * We limit this to aggregation because in TKIP this is a valid
317 * scenario, since we may not have the (correct) TTAK (phase 1
318 * key) in the firmware.
320 if (phy_info
& IWL_RX_MPDU_PHY_AMPDU
&&
321 (status
& IWL_RX_MPDU_STATUS_SEC_MASK
) ==
322 IWL_RX_MPDU_STATUS_SEC_UNKNOWN
&& !mvm
->monitor_on
)
325 if (!ieee80211_has_protected(hdr
->frame_control
) ||
326 (status
& IWL_RX_MPDU_STATUS_SEC_MASK
) ==
327 IWL_RX_MPDU_STATUS_SEC_NONE
)
330 /* TODO: handle packets encrypted with unknown alg */
332 switch (status
& IWL_RX_MPDU_STATUS_SEC_MASK
) {
333 case IWL_RX_MPDU_STATUS_SEC_CCM
:
334 case IWL_RX_MPDU_STATUS_SEC_GCM
:
335 BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN
!= IEEE80211_GCMP_PN_LEN
);
336 /* alg is CCM: check MIC only */
337 if (!(status
& IWL_RX_MPDU_STATUS_MIC_OK
))
340 stats
->flag
|= RX_FLAG_DECRYPTED
;
341 if (pkt_flags
& FH_RSCSR_RADA_EN
)
342 stats
->flag
|= RX_FLAG_MIC_STRIPPED
;
343 *crypt_len
= IEEE80211_CCMP_HDR_LEN
;
345 case IWL_RX_MPDU_STATUS_SEC_TKIP
:
346 /* Don't drop the frame and decrypt it in SW */
347 if (!fw_has_api(&mvm
->fw
->ucode_capa
,
348 IWL_UCODE_TLV_API_DEPRECATE_TTAK
) &&
349 !(status
& IWL_RX_MPDU_RES_STATUS_TTAK_OK
))
352 if (mvm
->trans
->trans_cfg
->gen2
&&
353 !(status
& RX_MPDU_RES_STATUS_MIC_OK
))
354 stats
->flag
|= RX_FLAG_MMIC_ERROR
;
356 *crypt_len
= IEEE80211_TKIP_IV_LEN
;
358 case IWL_RX_MPDU_STATUS_SEC_WEP
:
359 if (!(status
& IWL_RX_MPDU_STATUS_ICV_OK
))
362 stats
->flag
|= RX_FLAG_DECRYPTED
;
363 if ((status
& IWL_RX_MPDU_STATUS_SEC_MASK
) ==
364 IWL_RX_MPDU_STATUS_SEC_WEP
)
365 *crypt_len
= IEEE80211_WEP_IV_LEN
;
367 if (pkt_flags
& FH_RSCSR_RADA_EN
) {
368 stats
->flag
|= RX_FLAG_ICV_STRIPPED
;
369 if (mvm
->trans
->trans_cfg
->gen2
)
370 stats
->flag
|= RX_FLAG_MMIC_STRIPPED
;
374 case IWL_RX_MPDU_STATUS_SEC_EXT_ENC
:
375 if (!(status
& IWL_RX_MPDU_STATUS_MIC_OK
))
377 stats
->flag
|= RX_FLAG_DECRYPTED
;
381 * Sometimes we can get frames that were not decrypted
382 * because the firmware didn't have the keys yet. This can
383 * happen after connection where we can get multicast frames
384 * before the GTK is installed.
385 * Silently drop those frames.
386 * Also drop un-decrypted frames in monitor mode.
388 if (!is_multicast_ether_addr(hdr
->addr1
) &&
389 !mvm
->monitor_on
&& net_ratelimit())
390 IWL_ERR(mvm
, "Unhandled alg: 0x%x\n", status
);
396 static void iwl_mvm_rx_csum(struct ieee80211_sta
*sta
,
398 struct iwl_rx_mpdu_desc
*desc
)
400 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
401 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(mvmsta
->vif
);
402 u16 flags
= le16_to_cpu(desc
->l3l4_flags
);
403 u8 l3_prot
= (u8
)((flags
& IWL_RX_L3L4_L3_PROTO_MASK
) >>
404 IWL_RX_L3_PROTO_POS
);
406 if (mvmvif
->features
& NETIF_F_RXCSUM
&&
407 flags
& IWL_RX_L3L4_TCP_UDP_CSUM_OK
&&
408 (flags
& IWL_RX_L3L4_IP_HDR_CSUM_OK
||
409 l3_prot
== IWL_RX_L3_TYPE_IPV6
||
410 l3_prot
== IWL_RX_L3_TYPE_IPV6_FRAG
))
411 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
415 * returns true if a packet is a duplicate and should be dropped.
416 * Updates AMSDU PN tracking info
418 static bool iwl_mvm_is_dup(struct ieee80211_sta
*sta
, int queue
,
419 struct ieee80211_rx_status
*rx_status
,
420 struct ieee80211_hdr
*hdr
,
421 struct iwl_rx_mpdu_desc
*desc
)
423 struct iwl_mvm_sta
*mvm_sta
;
424 struct iwl_mvm_rxq_dup_data
*dup_data
;
425 u8 tid
, sub_frame_idx
;
427 if (WARN_ON(IS_ERR_OR_NULL(sta
)))
430 mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
431 dup_data
= &mvm_sta
->dup_data
[queue
];
434 * Drop duplicate 802.11 retransmissions
435 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
437 if (ieee80211_is_ctl(hdr
->frame_control
) ||
438 ieee80211_is_qos_nullfunc(hdr
->frame_control
) ||
439 is_multicast_ether_addr(hdr
->addr1
)) {
440 rx_status
->flag
|= RX_FLAG_DUP_VALIDATED
;
444 if (ieee80211_is_data_qos(hdr
->frame_control
))
445 /* frame has qos control */
446 tid
= ieee80211_get_tid(hdr
);
448 tid
= IWL_MAX_TID_COUNT
;
450 /* If this wasn't a part of an A-MSDU the sub-frame index will be 0 */
451 sub_frame_idx
= desc
->amsdu_info
&
452 IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK
;
454 if (unlikely(ieee80211_has_retry(hdr
->frame_control
) &&
455 dup_data
->last_seq
[tid
] == hdr
->seq_ctrl
&&
456 dup_data
->last_sub_frame
[tid
] >= sub_frame_idx
))
459 /* Allow same PN as the first subframe for following sub frames */
460 if (dup_data
->last_seq
[tid
] == hdr
->seq_ctrl
&&
461 sub_frame_idx
> dup_data
->last_sub_frame
[tid
] &&
462 desc
->mac_flags2
& IWL_RX_MPDU_MFLG2_AMSDU
)
463 rx_status
->flag
|= RX_FLAG_ALLOW_SAME_PN
;
465 dup_data
->last_seq
[tid
] = hdr
->seq_ctrl
;
466 dup_data
->last_sub_frame
[tid
] = sub_frame_idx
;
468 rx_status
->flag
|= RX_FLAG_DUP_VALIDATED
;
473 int iwl_mvm_notify_rx_queue(struct iwl_mvm
*mvm
, u32 rxq_mask
,
474 const u8
*data
, u32 count
, bool async
)
476 u8 buf
[sizeof(struct iwl_rxq_sync_cmd
) +
477 sizeof(struct iwl_mvm_rss_sync_notif
)];
478 struct iwl_rxq_sync_cmd
*cmd
= (void *)buf
;
479 u32 data_size
= sizeof(*cmd
) + count
;
483 * size must be a multiple of DWORD
484 * Ensure we don't overflow buf
486 if (WARN_ON(count
& 3 ||
487 count
> sizeof(struct iwl_mvm_rss_sync_notif
)))
490 cmd
->rxq_mask
= cpu_to_le32(rxq_mask
);
491 cmd
->count
= cpu_to_le32(count
);
493 memcpy(cmd
->payload
, data
, count
);
495 ret
= iwl_mvm_send_cmd_pdu(mvm
,
496 WIDE_ID(DATA_PATH_GROUP
,
497 TRIGGER_RX_QUEUES_NOTIF_CMD
),
498 async
? CMD_ASYNC
: 0, data_size
, cmd
);
504 * Returns true if sn2 - buffer_size < sn1 < sn2.
505 * To be used only in order to compare reorder buffer head with NSSN.
506 * We fully trust NSSN unless it is behind us due to reorder timeout.
507 * Reorder timeout can only bring us up to buffer_size SNs ahead of NSSN.
509 static bool iwl_mvm_is_sn_less(u16 sn1
, u16 sn2
, u16 buffer_size
)
511 return ieee80211_sn_less(sn1
, sn2
) &&
512 !ieee80211_sn_less(sn1
, sn2
- buffer_size
);
515 static void iwl_mvm_sync_nssn(struct iwl_mvm
*mvm
, u8 baid
, u16 nssn
)
517 if (IWL_MVM_USE_NSSN_SYNC
) {
518 struct iwl_mvm_rss_sync_notif notif
= {
519 .metadata
.type
= IWL_MVM_RXQ_NSSN_SYNC
,
521 .nssn_sync
.baid
= baid
,
522 .nssn_sync
.nssn
= nssn
,
525 iwl_mvm_sync_rx_queues_internal(mvm
, (void *)¬if
,
530 #define RX_REORDER_BUF_TIMEOUT_MQ (HZ / 10)
532 enum iwl_mvm_release_flags
{
533 IWL_MVM_RELEASE_SEND_RSS_SYNC
= BIT(0),
534 IWL_MVM_RELEASE_FROM_RSS_SYNC
= BIT(1),
537 static void iwl_mvm_release_frames(struct iwl_mvm
*mvm
,
538 struct ieee80211_sta
*sta
,
539 struct napi_struct
*napi
,
540 struct iwl_mvm_baid_data
*baid_data
,
541 struct iwl_mvm_reorder_buffer
*reorder_buf
,
544 struct iwl_mvm_reorder_buf_entry
*entries
=
545 &baid_data
->entries
[reorder_buf
->queue
*
546 baid_data
->entries_per_queue
];
547 u16 ssn
= reorder_buf
->head_sn
;
549 lockdep_assert_held(&reorder_buf
->lock
);
552 * We keep the NSSN not too far behind, if we are sync'ing it and it
553 * is more than 2048 ahead of us, it must be behind us. Discard it.
554 * This can happen if the queue that hit the 0 / 2048 seqno was lagging
555 * behind and this queue already processed packets. The next if
556 * would have caught cases where this queue would have processed less
557 * than 64 packets, but it may have processed more than 64 packets.
559 if ((flags
& IWL_MVM_RELEASE_FROM_RSS_SYNC
) &&
560 ieee80211_sn_less(nssn
, ssn
))
563 /* ignore nssn smaller than head sn - this can happen due to timeout */
564 if (iwl_mvm_is_sn_less(nssn
, ssn
, reorder_buf
->buf_size
))
567 while (iwl_mvm_is_sn_less(ssn
, nssn
, reorder_buf
->buf_size
)) {
568 int index
= ssn
% reorder_buf
->buf_size
;
569 struct sk_buff_head
*skb_list
= &entries
[index
].e
.frames
;
572 ssn
= ieee80211_sn_inc(ssn
);
573 if ((flags
& IWL_MVM_RELEASE_SEND_RSS_SYNC
) &&
574 (ssn
== 2048 || ssn
== 0))
575 iwl_mvm_sync_nssn(mvm
, baid_data
->baid
, ssn
);
578 * Empty the list. Will have more than one frame for A-MSDU.
579 * Empty list is valid as well since nssn indicates frames were
582 while ((skb
= __skb_dequeue(skb_list
))) {
583 iwl_mvm_pass_packet_to_mac80211(mvm
, napi
, skb
,
586 reorder_buf
->num_stored
--;
589 reorder_buf
->head_sn
= nssn
;
592 if (reorder_buf
->num_stored
&& !reorder_buf
->removed
) {
593 u16 index
= reorder_buf
->head_sn
% reorder_buf
->buf_size
;
595 while (skb_queue_empty(&entries
[index
].e
.frames
))
596 index
= (index
+ 1) % reorder_buf
->buf_size
;
597 /* modify timer to match next frame's expiration time */
598 mod_timer(&reorder_buf
->reorder_timer
,
599 entries
[index
].e
.reorder_time
+ 1 +
600 RX_REORDER_BUF_TIMEOUT_MQ
);
602 del_timer(&reorder_buf
->reorder_timer
);
606 void iwl_mvm_reorder_timer_expired(struct timer_list
*t
)
608 struct iwl_mvm_reorder_buffer
*buf
= from_timer(buf
, t
, reorder_timer
);
609 struct iwl_mvm_baid_data
*baid_data
=
610 iwl_mvm_baid_data_from_reorder_buf(buf
);
611 struct iwl_mvm_reorder_buf_entry
*entries
=
612 &baid_data
->entries
[buf
->queue
* baid_data
->entries_per_queue
];
614 u16 sn
= 0, index
= 0;
615 bool expired
= false;
618 spin_lock(&buf
->lock
);
620 if (!buf
->num_stored
|| buf
->removed
) {
621 spin_unlock(&buf
->lock
);
625 for (i
= 0; i
< buf
->buf_size
; i
++) {
626 index
= (buf
->head_sn
+ i
) % buf
->buf_size
;
628 if (skb_queue_empty(&entries
[index
].e
.frames
)) {
630 * If there is a hole and the next frame didn't expire
631 * we want to break and not advance SN
637 !time_after(jiffies
, entries
[index
].e
.reorder_time
+
638 RX_REORDER_BUF_TIMEOUT_MQ
))
642 /* continue until next hole after this expired frames */
644 sn
= ieee80211_sn_add(buf
->head_sn
, i
+ 1);
648 struct ieee80211_sta
*sta
;
649 struct iwl_mvm_sta
*mvmsta
;
650 u8 sta_id
= baid_data
->sta_id
;
653 sta
= rcu_dereference(buf
->mvm
->fw_id_to_mac_id
[sta_id
]);
654 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
656 /* SN is set to the last expired frame + 1 */
657 IWL_DEBUG_HT(buf
->mvm
,
658 "Releasing expired frames for sta %u, sn %d\n",
660 iwl_mvm_event_frame_timeout_callback(buf
->mvm
, mvmsta
->vif
,
661 sta
, baid_data
->tid
);
662 iwl_mvm_release_frames(buf
->mvm
, sta
, NULL
, baid_data
,
663 buf
, sn
, IWL_MVM_RELEASE_SEND_RSS_SYNC
);
667 * If no frame expired and there are stored frames, index is now
668 * pointing to the first unexpired frame - modify timer
669 * accordingly to this frame.
671 mod_timer(&buf
->reorder_timer
,
672 entries
[index
].e
.reorder_time
+
673 1 + RX_REORDER_BUF_TIMEOUT_MQ
);
675 spin_unlock(&buf
->lock
);
678 static void iwl_mvm_del_ba(struct iwl_mvm
*mvm
, int queue
,
679 struct iwl_mvm_delba_data
*data
)
681 struct iwl_mvm_baid_data
*ba_data
;
682 struct ieee80211_sta
*sta
;
683 struct iwl_mvm_reorder_buffer
*reorder_buf
;
684 u8 baid
= data
->baid
;
686 if (WARN_ONCE(baid
>= IWL_MAX_BAID
, "invalid BAID: %x\n", baid
))
691 ba_data
= rcu_dereference(mvm
->baid_map
[baid
]);
692 if (WARN_ON_ONCE(!ba_data
))
695 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[ba_data
->sta_id
]);
696 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta
)))
699 reorder_buf
= &ba_data
->reorder_buf
[queue
];
701 /* release all frames that are in the reorder buffer to the stack */
702 spin_lock_bh(&reorder_buf
->lock
);
703 iwl_mvm_release_frames(mvm
, sta
, NULL
, ba_data
, reorder_buf
,
704 ieee80211_sn_add(reorder_buf
->head_sn
,
705 reorder_buf
->buf_size
),
707 spin_unlock_bh(&reorder_buf
->lock
);
708 del_timer_sync(&reorder_buf
->reorder_timer
);
714 static void iwl_mvm_release_frames_from_notif(struct iwl_mvm
*mvm
,
715 struct napi_struct
*napi
,
716 u8 baid
, u16 nssn
, int queue
,
719 struct ieee80211_sta
*sta
;
720 struct iwl_mvm_reorder_buffer
*reorder_buf
;
721 struct iwl_mvm_baid_data
*ba_data
;
723 IWL_DEBUG_HT(mvm
, "Frame release notification for BAID %u, NSSN %d\n",
726 if (WARN_ON_ONCE(baid
== IWL_RX_REORDER_DATA_INVALID_BAID
||
727 baid
>= ARRAY_SIZE(mvm
->baid_map
)))
732 ba_data
= rcu_dereference(mvm
->baid_map
[baid
]);
733 if (WARN_ON_ONCE(!ba_data
))
736 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[ba_data
->sta_id
]);
737 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta
)))
740 reorder_buf
= &ba_data
->reorder_buf
[queue
];
742 spin_lock_bh(&reorder_buf
->lock
);
743 iwl_mvm_release_frames(mvm
, sta
, napi
, ba_data
,
744 reorder_buf
, nssn
, flags
);
745 spin_unlock_bh(&reorder_buf
->lock
);
751 static void iwl_mvm_nssn_sync(struct iwl_mvm
*mvm
,
752 struct napi_struct
*napi
, int queue
,
753 const struct iwl_mvm_nssn_sync_data
*data
)
755 iwl_mvm_release_frames_from_notif(mvm
, napi
, data
->baid
,
757 IWL_MVM_RELEASE_FROM_RSS_SYNC
);
760 void iwl_mvm_rx_queue_notif(struct iwl_mvm
*mvm
, struct napi_struct
*napi
,
761 struct iwl_rx_cmd_buffer
*rxb
, int queue
)
763 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
764 struct iwl_rxq_sync_notification
*notif
;
765 struct iwl_mvm_internal_rxq_notif
*internal_notif
;
767 notif
= (void *)pkt
->data
;
768 internal_notif
= (void *)notif
->payload
;
770 if (internal_notif
->sync
&&
771 mvm
->queue_sync_cookie
!= internal_notif
->cookie
) {
772 WARN_ONCE(1, "Received expired RX queue sync message\n");
776 switch (internal_notif
->type
) {
777 case IWL_MVM_RXQ_EMPTY
:
779 case IWL_MVM_RXQ_NOTIF_DEL_BA
:
780 iwl_mvm_del_ba(mvm
, queue
, (void *)internal_notif
->data
);
782 case IWL_MVM_RXQ_NSSN_SYNC
:
783 iwl_mvm_nssn_sync(mvm
, napi
, queue
,
784 (void *)internal_notif
->data
);
787 WARN_ONCE(1, "Invalid identifier %d", internal_notif
->type
);
790 if (internal_notif
->sync
&&
791 !atomic_dec_return(&mvm
->queue_sync_counter
))
792 wake_up(&mvm
->rx_sync_waitq
);
795 static void iwl_mvm_oldsn_workaround(struct iwl_mvm
*mvm
,
796 struct ieee80211_sta
*sta
, int tid
,
797 struct iwl_mvm_reorder_buffer
*buffer
,
798 u32 reorder
, u32 gp2
, int queue
)
800 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
802 if (gp2
!= buffer
->consec_oldsn_ampdu_gp2
) {
803 /* we have a new (A-)MPDU ... */
806 * reset counter to 0 if we didn't have any oldsn in
807 * the last A-MPDU (as detected by GP2 being identical)
809 if (!buffer
->consec_oldsn_prev_drop
)
810 buffer
->consec_oldsn_drops
= 0;
812 /* either way, update our tracking state */
813 buffer
->consec_oldsn_ampdu_gp2
= gp2
;
814 } else if (buffer
->consec_oldsn_prev_drop
) {
816 * tracking state didn't change, and we had an old SN
817 * indication before - do nothing in this case, we
818 * already noted this one down and are waiting for the
819 * next A-MPDU (by GP2)
824 /* return unless this MPDU has old SN */
825 if (!(reorder
& IWL_RX_MPDU_REORDER_BA_OLD_SN
))
829 buffer
->consec_oldsn_prev_drop
= 1;
830 buffer
->consec_oldsn_drops
++;
832 /* if limit is reached, send del BA and reset state */
833 if (buffer
->consec_oldsn_drops
== IWL_MVM_AMPDU_CONSEC_DROPS_DELBA
) {
835 "reached %d old SN frames from %pM on queue %d, stopping BA session on TID %d\n",
836 IWL_MVM_AMPDU_CONSEC_DROPS_DELBA
,
837 sta
->addr
, queue
, tid
);
838 ieee80211_stop_rx_ba_session(mvmsta
->vif
, BIT(tid
), sta
->addr
);
839 buffer
->consec_oldsn_prev_drop
= 0;
840 buffer
->consec_oldsn_drops
= 0;
845 * Returns true if the MPDU was buffered\dropped, false if it should be passed
848 static bool iwl_mvm_reorder(struct iwl_mvm
*mvm
,
849 struct napi_struct
*napi
,
851 struct ieee80211_sta
*sta
,
853 struct iwl_rx_mpdu_desc
*desc
)
855 struct ieee80211_rx_status
*rx_status
= IEEE80211_SKB_RXCB(skb
);
856 struct ieee80211_hdr
*hdr
= iwl_mvm_skb_get_hdr(skb
);
857 struct iwl_mvm_sta
*mvm_sta
;
858 struct iwl_mvm_baid_data
*baid_data
;
859 struct iwl_mvm_reorder_buffer
*buffer
;
860 struct sk_buff
*tail
;
861 u32 reorder
= le32_to_cpu(desc
->reorder_data
);
862 bool amsdu
= desc
->mac_flags2
& IWL_RX_MPDU_MFLG2_AMSDU
;
864 desc
->amsdu_info
& IWL_RX_MPDU_AMSDU_LAST_SUBFRAME
;
865 u8 tid
= ieee80211_get_tid(hdr
);
866 u8 sub_frame_idx
= desc
->amsdu_info
&
867 IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK
;
868 struct iwl_mvm_reorder_buf_entry
*entries
;
873 baid
= (reorder
& IWL_RX_MPDU_REORDER_BAID_MASK
) >>
874 IWL_RX_MPDU_REORDER_BAID_SHIFT
;
877 * This also covers the case of receiving a Block Ack Request
878 * outside a BA session; we'll pass it to mac80211 and that
879 * then sends a delBA action frame.
880 * This also covers pure monitor mode, in which case we won't
881 * have any BA sessions.
883 if (baid
== IWL_RX_REORDER_DATA_INVALID_BAID
)
887 if (WARN_ONCE(IS_ERR_OR_NULL(sta
),
888 "Got valid BAID without a valid station assigned\n"))
891 mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
893 /* not a data packet or a bar */
894 if (!ieee80211_is_back_req(hdr
->frame_control
) &&
895 (!ieee80211_is_data_qos(hdr
->frame_control
) ||
896 is_multicast_ether_addr(hdr
->addr1
)))
899 if (unlikely(!ieee80211_is_data_present(hdr
->frame_control
)))
902 baid_data
= rcu_dereference(mvm
->baid_map
[baid
]);
905 "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n",
910 if (WARN(tid
!= baid_data
->tid
|| mvm_sta
->sta_id
!= baid_data
->sta_id
,
911 "baid 0x%x is mapped to sta:%d tid:%d, but was received for sta:%d tid:%d\n",
912 baid
, baid_data
->sta_id
, baid_data
->tid
, mvm_sta
->sta_id
,
916 nssn
= reorder
& IWL_RX_MPDU_REORDER_NSSN_MASK
;
917 sn
= (reorder
& IWL_RX_MPDU_REORDER_SN_MASK
) >>
918 IWL_RX_MPDU_REORDER_SN_SHIFT
;
920 buffer
= &baid_data
->reorder_buf
[queue
];
921 entries
= &baid_data
->entries
[queue
* baid_data
->entries_per_queue
];
923 spin_lock_bh(&buffer
->lock
);
925 if (!buffer
->valid
) {
926 if (reorder
& IWL_RX_MPDU_REORDER_BA_OLD_SN
) {
927 spin_unlock_bh(&buffer
->lock
);
930 buffer
->valid
= true;
933 if (ieee80211_is_back_req(hdr
->frame_control
)) {
934 iwl_mvm_release_frames(mvm
, sta
, napi
, baid_data
,
940 * If there was a significant jump in the nssn - adjust.
941 * If the SN is smaller than the NSSN it might need to first go into
942 * the reorder buffer, in which case we just release up to it and the
943 * rest of the function will take care of storing it and releasing up to
945 * This should not happen. This queue has been lagging and it should
946 * have been updated by a IWL_MVM_RXQ_NSSN_SYNC notification. Be nice
947 * and update the other queues.
949 if (!iwl_mvm_is_sn_less(nssn
, buffer
->head_sn
+ buffer
->buf_size
,
951 !ieee80211_sn_less(sn
, buffer
->head_sn
+ buffer
->buf_size
)) {
952 u16 min_sn
= ieee80211_sn_less(sn
, nssn
) ? sn
: nssn
;
954 iwl_mvm_release_frames(mvm
, sta
, napi
, baid_data
, buffer
,
955 min_sn
, IWL_MVM_RELEASE_SEND_RSS_SYNC
);
958 iwl_mvm_oldsn_workaround(mvm
, sta
, tid
, buffer
, reorder
,
959 rx_status
->device_timestamp
, queue
);
961 /* drop any oudated packets */
962 if (ieee80211_sn_less(sn
, buffer
->head_sn
))
965 /* release immediately if allowed by nssn and no stored frames */
966 if (!buffer
->num_stored
&& ieee80211_sn_less(sn
, nssn
)) {
967 if (iwl_mvm_is_sn_less(buffer
->head_sn
, nssn
,
969 (!amsdu
|| last_subframe
)) {
971 * If we crossed the 2048 or 0 SN, notify all the
972 * queues. This is done in order to avoid having a
973 * head_sn that lags behind for too long. When that
974 * happens, we can get to a situation where the head_sn
975 * is within the interval [nssn - buf_size : nssn]
976 * which will make us think that the nssn is a packet
977 * that we already freed because of the reordering
978 * buffer and we will ignore it. So maintain the
979 * head_sn somewhat updated across all the queues:
980 * when it crosses 0 and 2048.
982 if (sn
== 2048 || sn
== 0)
983 iwl_mvm_sync_nssn(mvm
, baid
, sn
);
984 buffer
->head_sn
= nssn
;
986 /* No need to update AMSDU last SN - we are moving the head */
987 spin_unlock_bh(&buffer
->lock
);
992 * release immediately if there are no stored frames, and the sn is
994 * This can happen due to reorder timer, where NSSN is behind head_sn.
995 * When we released everything, and we got the next frame in the
996 * sequence, according to the NSSN we can't release immediately,
997 * while technically there is no hole and we can move forward.
999 if (!buffer
->num_stored
&& sn
== buffer
->head_sn
) {
1000 if (!amsdu
|| last_subframe
) {
1001 if (sn
== 2048 || sn
== 0)
1002 iwl_mvm_sync_nssn(mvm
, baid
, sn
);
1003 buffer
->head_sn
= ieee80211_sn_inc(buffer
->head_sn
);
1005 /* No need to update AMSDU last SN - we are moving the head */
1006 spin_unlock_bh(&buffer
->lock
);
1010 index
= sn
% buffer
->buf_size
;
1013 * Check if we already stored this frame
1014 * As AMSDU is either received or not as whole, logic is simple:
1015 * If we have frames in that position in the buffer and the last frame
1016 * originated from AMSDU had a different SN then it is a retransmission.
1017 * If it is the same SN then if the subframe index is incrementing it
1018 * is the same AMSDU - otherwise it is a retransmission.
1020 tail
= skb_peek_tail(&entries
[index
].e
.frames
);
1023 else if (tail
&& (sn
!= buffer
->last_amsdu
||
1024 buffer
->last_sub_index
>= sub_frame_idx
))
1027 /* put in reorder buffer */
1028 __skb_queue_tail(&entries
[index
].e
.frames
, skb
);
1029 buffer
->num_stored
++;
1030 entries
[index
].e
.reorder_time
= jiffies
;
1033 buffer
->last_amsdu
= sn
;
1034 buffer
->last_sub_index
= sub_frame_idx
;
1038 * We cannot trust NSSN for AMSDU sub-frames that are not the last.
1039 * The reason is that NSSN advances on the first sub-frame, and may
1040 * cause the reorder buffer to advance before all the sub-frames arrive.
1041 * Example: reorder buffer contains SN 0 & 2, and we receive AMSDU with
1042 * SN 1. NSSN for first sub frame will be 3 with the result of driver
1043 * releasing SN 0,1, 2. When sub-frame 1 arrives - reorder buffer is
1044 * already ahead and it will be dropped.
1045 * If the last sub-frame is not on this queue - we will get frame
1046 * release notification with up to date NSSN.
1048 if (!amsdu
|| last_subframe
)
1049 iwl_mvm_release_frames(mvm
, sta
, napi
, baid_data
,
1051 IWL_MVM_RELEASE_SEND_RSS_SYNC
);
1053 spin_unlock_bh(&buffer
->lock
);
1058 spin_unlock_bh(&buffer
->lock
);
1062 static void iwl_mvm_agg_rx_received(struct iwl_mvm
*mvm
,
1063 u32 reorder_data
, u8 baid
)
1065 unsigned long now
= jiffies
;
1066 unsigned long timeout
;
1067 struct iwl_mvm_baid_data
*data
;
1071 data
= rcu_dereference(mvm
->baid_map
[baid
]);
1074 "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n",
1075 baid
, reorder_data
);
1082 timeout
= data
->timeout
;
1084 * Do not update last rx all the time to avoid cache bouncing
1085 * between the rx queues.
1086 * Update it every timeout. Worst case is the session will
1087 * expire after ~ 2 * timeout, which doesn't matter that much.
1089 if (time_before(data
->last_rx
+ TU_TO_JIFFIES(timeout
), now
))
1090 /* Update is atomic */
1091 data
->last_rx
= now
;
1097 static void iwl_mvm_flip_address(u8
*addr
)
1100 u8 mac_addr
[ETH_ALEN
];
1102 for (i
= 0; i
< ETH_ALEN
; i
++)
1103 mac_addr
[i
] = addr
[ETH_ALEN
- i
- 1];
1104 ether_addr_copy(addr
, mac_addr
);
1107 struct iwl_mvm_rx_phy_data
{
1108 enum iwl_rx_phy_info_type info_type
;
1109 __le32 d0
, d1
, d2
, d3
;
1113 static void iwl_mvm_decode_he_mu_ext(struct iwl_mvm
*mvm
,
1114 struct iwl_mvm_rx_phy_data
*phy_data
,
1116 struct ieee80211_radiotap_he_mu
*he_mu
)
1118 u32 phy_data2
= le32_to_cpu(phy_data
->d2
);
1119 u32 phy_data3
= le32_to_cpu(phy_data
->d3
);
1120 u16 phy_data4
= le16_to_cpu(phy_data
->d4
);
1122 if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CRC_OK
, phy_data4
)) {
1124 cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_RU_KNOWN
|
1125 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU_KNOWN
);
1128 le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CTR_RU
,
1130 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU
);
1132 he_mu
->ru_ch1
[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU0
,
1134 he_mu
->ru_ch1
[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU1
,
1136 he_mu
->ru_ch1
[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU2
,
1138 he_mu
->ru_ch1
[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU3
,
1142 if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CRC_OK
, phy_data4
) &&
1143 (rate_n_flags
& RATE_MCS_CHAN_WIDTH_MSK
) != RATE_MCS_CHAN_WIDTH_20
) {
1145 cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_RU_KNOWN
|
1146 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_CTR_26T_RU_KNOWN
);
1149 le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CTR_RU
,
1151 IEEE80211_RADIOTAP_HE_MU_FLAGS2_CH2_CTR_26T_RU
);
1153 he_mu
->ru_ch2
[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU0
,
1155 he_mu
->ru_ch2
[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU1
,
1157 he_mu
->ru_ch2
[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU2
,
1159 he_mu
->ru_ch2
[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU3
,
1165 iwl_mvm_decode_he_phy_ru_alloc(struct iwl_mvm_rx_phy_data
*phy_data
,
1167 struct ieee80211_radiotap_he
*he
,
1168 struct ieee80211_radiotap_he_mu
*he_mu
,
1169 struct ieee80211_rx_status
*rx_status
)
1172 * Unfortunately, we have to leave the mac80211 data
1173 * incorrect for the case that we receive an HE-MU
1174 * transmission and *don't* have the HE phy data (due
1175 * to the bits being used for TSF). This shouldn't
1176 * happen though as management frames where we need
1177 * the TSF/timers are not be transmitted in HE-MU.
1179 u8 ru
= le32_get_bits(phy_data
->d1
, IWL_RX_PHY_DATA1_HE_RU_ALLOC_MASK
);
1180 u32 he_type
= rate_n_flags
& RATE_MCS_HE_TYPE_MSK
;
1183 rx_status
->bw
= RATE_INFO_BW_HE_RU
;
1185 he
->data1
|= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN
);
1189 rx_status
->he_ru
= NL80211_RATE_INFO_HE_RU_ALLOC_26
;
1193 rx_status
->he_ru
= NL80211_RATE_INFO_HE_RU_ALLOC_52
;
1197 rx_status
->he_ru
= NL80211_RATE_INFO_HE_RU_ALLOC_106
;
1201 rx_status
->he_ru
= NL80211_RATE_INFO_HE_RU_ALLOC_242
;
1205 rx_status
->he_ru
= NL80211_RATE_INFO_HE_RU_ALLOC_484
;
1209 rx_status
->he_ru
= NL80211_RATE_INFO_HE_RU_ALLOC_996
;
1212 rx_status
->he_ru
= NL80211_RATE_INFO_HE_RU_ALLOC_2x996
;
1215 he
->data2
|= le16_encode_bits(offs
,
1216 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET
);
1217 he
->data2
|= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_KNOWN
|
1218 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET_KNOWN
);
1219 if (phy_data
->d1
& cpu_to_le32(IWL_RX_PHY_DATA1_HE_RU_ALLOC_SEC80
))
1221 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_SEC
);
1223 #define CHECK_BW(bw) \
1224 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_ ## bw ## MHZ != \
1225 RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS); \
1226 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_ ## bw ## MHZ != \
1227 RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS)
1235 le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK
,
1237 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW
);
1238 else if (he_type
== RATE_MCS_HE_TYPE_TRIG
)
1240 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_KNOWN
) |
1241 le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK
,
1243 IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW
);
1246 static void iwl_mvm_decode_he_phy_data(struct iwl_mvm
*mvm
,
1247 struct iwl_mvm_rx_phy_data
*phy_data
,
1248 struct ieee80211_radiotap_he
*he
,
1249 struct ieee80211_radiotap_he_mu
*he_mu
,
1250 struct ieee80211_rx_status
*rx_status
,
1251 u32 rate_n_flags
, int queue
)
1253 switch (phy_data
->info_type
) {
1254 case IWL_RX_PHY_INFO_TYPE_NONE
:
1255 case IWL_RX_PHY_INFO_TYPE_CCK
:
1256 case IWL_RX_PHY_INFO_TYPE_OFDM_LGCY
:
1257 case IWL_RX_PHY_INFO_TYPE_HT
:
1258 case IWL_RX_PHY_INFO_TYPE_VHT_SU
:
1259 case IWL_RX_PHY_INFO_TYPE_VHT_MU
:
1261 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT
:
1262 he
->data1
|= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN
|
1263 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE2_KNOWN
|
1264 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE3_KNOWN
|
1265 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE4_KNOWN
);
1266 he
->data4
|= le16_encode_bits(le32_get_bits(phy_data
->d2
,
1267 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE1
),
1268 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE1
);
1269 he
->data4
|= le16_encode_bits(le32_get_bits(phy_data
->d2
,
1270 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE2
),
1271 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE2
);
1272 he
->data4
|= le16_encode_bits(le32_get_bits(phy_data
->d2
,
1273 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE3
),
1274 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE3
);
1275 he
->data4
|= le16_encode_bits(le32_get_bits(phy_data
->d2
,
1276 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE4
),
1277 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE4
);
1279 case IWL_RX_PHY_INFO_TYPE_HE_SU
:
1280 case IWL_RX_PHY_INFO_TYPE_HE_MU
:
1281 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT
:
1282 case IWL_RX_PHY_INFO_TYPE_HE_TB
:
1284 he
->data1
|= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_LDPC_XSYMSEG_KNOWN
|
1285 IEEE80211_RADIOTAP_HE_DATA1_DOPPLER_KNOWN
|
1286 IEEE80211_RADIOTAP_HE_DATA1_BSS_COLOR_KNOWN
);
1287 he
->data2
|= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRE_FEC_PAD_KNOWN
|
1288 IEEE80211_RADIOTAP_HE_DATA2_PE_DISAMBIG_KNOWN
|
1289 IEEE80211_RADIOTAP_HE_DATA2_TXOP_KNOWN
|
1290 IEEE80211_RADIOTAP_HE_DATA2_NUM_LTF_SYMS_KNOWN
);
1291 he
->data3
|= le16_encode_bits(le32_get_bits(phy_data
->d0
,
1292 IWL_RX_PHY_DATA0_HE_BSS_COLOR_MASK
),
1293 IEEE80211_RADIOTAP_HE_DATA3_BSS_COLOR
);
1294 if (phy_data
->info_type
!= IWL_RX_PHY_INFO_TYPE_HE_TB
&&
1295 phy_data
->info_type
!= IWL_RX_PHY_INFO_TYPE_HE_TB_EXT
) {
1296 he
->data1
|= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_UL_DL_KNOWN
);
1297 he
->data3
|= le16_encode_bits(le32_get_bits(phy_data
->d0
,
1298 IWL_RX_PHY_DATA0_HE_UPLINK
),
1299 IEEE80211_RADIOTAP_HE_DATA3_UL_DL
);
1301 he
->data3
|= le16_encode_bits(le32_get_bits(phy_data
->d0
,
1302 IWL_RX_PHY_DATA0_HE_LDPC_EXT_SYM
),
1303 IEEE80211_RADIOTAP_HE_DATA3_LDPC_XSYMSEG
);
1304 he
->data5
|= le16_encode_bits(le32_get_bits(phy_data
->d0
,
1305 IWL_RX_PHY_DATA0_HE_PRE_FEC_PAD_MASK
),
1306 IEEE80211_RADIOTAP_HE_DATA5_PRE_FEC_PAD
);
1307 he
->data5
|= le16_encode_bits(le32_get_bits(phy_data
->d0
,
1308 IWL_RX_PHY_DATA0_HE_PE_DISAMBIG
),
1309 IEEE80211_RADIOTAP_HE_DATA5_PE_DISAMBIG
);
1310 he
->data5
|= le16_encode_bits(le32_get_bits(phy_data
->d1
,
1311 IWL_RX_PHY_DATA1_HE_LTF_NUM_MASK
),
1312 IEEE80211_RADIOTAP_HE_DATA5_NUM_LTF_SYMS
);
1313 he
->data6
|= le16_encode_bits(le32_get_bits(phy_data
->d0
,
1314 IWL_RX_PHY_DATA0_HE_TXOP_DUR_MASK
),
1315 IEEE80211_RADIOTAP_HE_DATA6_TXOP
);
1316 he
->data6
|= le16_encode_bits(le32_get_bits(phy_data
->d0
,
1317 IWL_RX_PHY_DATA0_HE_DOPPLER
),
1318 IEEE80211_RADIOTAP_HE_DATA6_DOPPLER
);
1322 switch (phy_data
->info_type
) {
1323 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT
:
1324 case IWL_RX_PHY_INFO_TYPE_HE_MU
:
1325 case IWL_RX_PHY_INFO_TYPE_HE_SU
:
1326 he
->data1
|= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN
);
1327 he
->data4
|= le16_encode_bits(le32_get_bits(phy_data
->d0
,
1328 IWL_RX_PHY_DATA0_HE_SPATIAL_REUSE_MASK
),
1329 IEEE80211_RADIOTAP_HE_DATA4_SU_MU_SPTL_REUSE
);
1336 switch (phy_data
->info_type
) {
1337 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT
:
1339 le16_encode_bits(le16_get_bits(phy_data
->d4
,
1340 IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_DCM
),
1341 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM
);
1343 le16_encode_bits(le16_get_bits(phy_data
->d4
,
1344 IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_MCS_MASK
),
1345 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS
);
1347 le16_encode_bits(le16_get_bits(phy_data
->d4
,
1348 IWL_RX_PHY_DATA4_HE_MU_EXT_PREAMBLE_PUNC_TYPE_MASK
),
1349 IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW
);
1350 iwl_mvm_decode_he_mu_ext(mvm
, phy_data
, rate_n_flags
, he_mu
);
1352 case IWL_RX_PHY_INFO_TYPE_HE_MU
:
1354 le16_encode_bits(le32_get_bits(phy_data
->d1
,
1355 IWL_RX_PHY_DATA1_HE_MU_SIBG_SYM_OR_USER_NUM_MASK
),
1356 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_SYMS_USERS
);
1358 le16_encode_bits(le32_get_bits(phy_data
->d1
,
1359 IWL_RX_PHY_DATA1_HE_MU_SIGB_COMPRESSION
),
1360 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_COMP
);
1362 case IWL_RX_PHY_INFO_TYPE_HE_TB
:
1363 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT
:
1364 iwl_mvm_decode_he_phy_ru_alloc(phy_data
, rate_n_flags
,
1365 he
, he_mu
, rx_status
);
1367 case IWL_RX_PHY_INFO_TYPE_HE_SU
:
1368 he
->data1
|= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BEAM_CHANGE_KNOWN
);
1369 he
->data3
|= le16_encode_bits(le32_get_bits(phy_data
->d0
,
1370 IWL_RX_PHY_DATA0_HE_BEAM_CHNG
),
1371 IEEE80211_RADIOTAP_HE_DATA3_BEAM_CHANGE
);
1379 static void iwl_mvm_rx_he(struct iwl_mvm
*mvm
, struct sk_buff
*skb
,
1380 struct iwl_mvm_rx_phy_data
*phy_data
,
1381 u32 rate_n_flags
, u16 phy_info
, int queue
)
1383 struct ieee80211_rx_status
*rx_status
= IEEE80211_SKB_RXCB(skb
);
1384 struct ieee80211_radiotap_he
*he
= NULL
;
1385 struct ieee80211_radiotap_he_mu
*he_mu
= NULL
;
1386 u32 he_type
= rate_n_flags
& RATE_MCS_HE_TYPE_MSK
;
1388 static const struct ieee80211_radiotap_he known
= {
1389 .data1
= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_DATA_MCS_KNOWN
|
1390 IEEE80211_RADIOTAP_HE_DATA1_DATA_DCM_KNOWN
|
1391 IEEE80211_RADIOTAP_HE_DATA1_STBC_KNOWN
|
1392 IEEE80211_RADIOTAP_HE_DATA1_CODING_KNOWN
),
1393 .data2
= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_GI_KNOWN
|
1394 IEEE80211_RADIOTAP_HE_DATA2_TXBF_KNOWN
),
1396 static const struct ieee80211_radiotap_he_mu mu_known
= {
1397 .flags1
= cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS_KNOWN
|
1398 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM_KNOWN
|
1399 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_SYMS_USERS_KNOWN
|
1400 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_COMP_KNOWN
),
1401 .flags2
= cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW_KNOWN
|
1402 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_KNOWN
),
1405 he
= skb_put_data(skb
, &known
, sizeof(known
));
1406 rx_status
->flag
|= RX_FLAG_RADIOTAP_HE
;
1408 if (phy_data
->info_type
== IWL_RX_PHY_INFO_TYPE_HE_MU
||
1409 phy_data
->info_type
== IWL_RX_PHY_INFO_TYPE_HE_MU_EXT
) {
1410 he_mu
= skb_put_data(skb
, &mu_known
, sizeof(mu_known
));
1411 rx_status
->flag
|= RX_FLAG_RADIOTAP_HE_MU
;
1414 /* report the AMPDU-EOF bit on single frames */
1415 if (!queue
&& !(phy_info
& IWL_RX_MPDU_PHY_AMPDU
)) {
1416 rx_status
->flag
|= RX_FLAG_AMPDU_DETAILS
;
1417 rx_status
->flag
|= RX_FLAG_AMPDU_EOF_BIT_KNOWN
;
1418 if (phy_data
->d0
& cpu_to_le32(IWL_RX_PHY_DATA0_HE_DELIM_EOF
))
1419 rx_status
->flag
|= RX_FLAG_AMPDU_EOF_BIT
;
1422 if (phy_info
& IWL_RX_MPDU_PHY_TSF_OVERLOAD
)
1423 iwl_mvm_decode_he_phy_data(mvm
, phy_data
, he
, he_mu
, rx_status
,
1424 rate_n_flags
, queue
);
1426 /* update aggregation data for monitor sake on default queue */
1427 if (!queue
&& (phy_info
& IWL_RX_MPDU_PHY_TSF_OVERLOAD
) &&
1428 (phy_info
& IWL_RX_MPDU_PHY_AMPDU
)) {
1429 bool toggle_bit
= phy_info
& IWL_RX_MPDU_PHY_AMPDU_TOGGLE
;
1431 /* toggle is switched whenever new aggregation starts */
1432 if (toggle_bit
!= mvm
->ampdu_toggle
) {
1433 rx_status
->flag
|= RX_FLAG_AMPDU_EOF_BIT_KNOWN
;
1434 if (phy_data
->d0
& cpu_to_le32(IWL_RX_PHY_DATA0_HE_DELIM_EOF
))
1435 rx_status
->flag
|= RX_FLAG_AMPDU_EOF_BIT
;
1439 if (he_type
== RATE_MCS_HE_TYPE_EXT_SU
&&
1440 rate_n_flags
& RATE_MCS_HE_106T_MSK
) {
1441 rx_status
->bw
= RATE_INFO_BW_HE_RU
;
1442 rx_status
->he_ru
= NL80211_RATE_INFO_HE_RU_ALLOC_106
;
1445 /* actually data is filled in mac80211 */
1446 if (he_type
== RATE_MCS_HE_TYPE_SU
||
1447 he_type
== RATE_MCS_HE_TYPE_EXT_SU
)
1449 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN
);
1451 stbc
= (rate_n_flags
& RATE_MCS_STBC_MSK
) >> RATE_MCS_STBC_POS
;
1453 ((rate_n_flags
& RATE_VHT_MCS_NSS_MSK
) >>
1454 RATE_VHT_MCS_NSS_POS
) + 1;
1455 rx_status
->rate_idx
= rate_n_flags
& RATE_VHT_MCS_RATE_CODE_MSK
;
1456 rx_status
->encoding
= RX_ENC_HE
;
1457 rx_status
->enc_flags
|= stbc
<< RX_ENC_FLAG_STBC_SHIFT
;
1458 if (rate_n_flags
& RATE_MCS_BF_MSK
)
1459 rx_status
->enc_flags
|= RX_ENC_FLAG_BF
;
1462 !!(rate_n_flags
& RATE_HE_DUAL_CARRIER_MODE_MSK
);
1464 #define CHECK_TYPE(F) \
1465 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_ ## F != \
1466 (RATE_MCS_HE_TYPE_ ## F >> RATE_MCS_HE_TYPE_POS))
1473 he
->data1
|= cpu_to_le16(he_type
>> RATE_MCS_HE_TYPE_POS
);
1475 if (rate_n_flags
& RATE_MCS_BF_MSK
)
1476 he
->data5
|= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA5_TXBF
);
1478 switch ((rate_n_flags
& RATE_MCS_HE_GI_LTF_MSK
) >>
1479 RATE_MCS_HE_GI_LTF_POS
) {
1481 if (he_type
== RATE_MCS_HE_TYPE_TRIG
)
1482 rx_status
->he_gi
= NL80211_RATE_INFO_HE_GI_1_6
;
1484 rx_status
->he_gi
= NL80211_RATE_INFO_HE_GI_0_8
;
1485 if (he_type
== RATE_MCS_HE_TYPE_MU
)
1486 ltf
= IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X
;
1488 ltf
= IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X
;
1491 if (he_type
== RATE_MCS_HE_TYPE_TRIG
)
1492 rx_status
->he_gi
= NL80211_RATE_INFO_HE_GI_1_6
;
1494 rx_status
->he_gi
= NL80211_RATE_INFO_HE_GI_0_8
;
1495 ltf
= IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X
;
1498 if (he_type
== RATE_MCS_HE_TYPE_TRIG
) {
1499 rx_status
->he_gi
= NL80211_RATE_INFO_HE_GI_3_2
;
1500 ltf
= IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X
;
1502 rx_status
->he_gi
= NL80211_RATE_INFO_HE_GI_1_6
;
1503 ltf
= IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X
;
1507 if ((he_type
== RATE_MCS_HE_TYPE_SU
||
1508 he_type
== RATE_MCS_HE_TYPE_EXT_SU
) &&
1509 rate_n_flags
& RATE_MCS_SGI_MSK
)
1510 rx_status
->he_gi
= NL80211_RATE_INFO_HE_GI_0_8
;
1512 rx_status
->he_gi
= NL80211_RATE_INFO_HE_GI_3_2
;
1513 ltf
= IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X
;
1517 he
->data5
|= le16_encode_bits(ltf
,
1518 IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE
);
1521 static void iwl_mvm_decode_lsig(struct sk_buff
*skb
,
1522 struct iwl_mvm_rx_phy_data
*phy_data
)
1524 struct ieee80211_rx_status
*rx_status
= IEEE80211_SKB_RXCB(skb
);
1525 struct ieee80211_radiotap_lsig
*lsig
;
1527 switch (phy_data
->info_type
) {
1528 case IWL_RX_PHY_INFO_TYPE_HT
:
1529 case IWL_RX_PHY_INFO_TYPE_VHT_SU
:
1530 case IWL_RX_PHY_INFO_TYPE_VHT_MU
:
1531 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT
:
1532 case IWL_RX_PHY_INFO_TYPE_HE_SU
:
1533 case IWL_RX_PHY_INFO_TYPE_HE_MU
:
1534 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT
:
1535 case IWL_RX_PHY_INFO_TYPE_HE_TB
:
1536 lsig
= skb_put(skb
, sizeof(*lsig
));
1537 lsig
->data1
= cpu_to_le16(IEEE80211_RADIOTAP_LSIG_DATA1_LENGTH_KNOWN
);
1538 lsig
->data2
= le16_encode_bits(le32_get_bits(phy_data
->d1
,
1539 IWL_RX_PHY_DATA1_LSIG_LEN_MASK
),
1540 IEEE80211_RADIOTAP_LSIG_DATA2_LENGTH
);
1541 rx_status
->flag
|= RX_FLAG_RADIOTAP_LSIG
;
1548 static inline u8
iwl_mvm_nl80211_band_from_rx_msdu(u8 phy_band
)
1552 return NL80211_BAND_2GHZ
;
1554 return NL80211_BAND_5GHZ
;
1556 WARN_ONCE(1, "Unsupported phy band (%u)\n", phy_band
);
1557 return NL80211_BAND_5GHZ
;
1561 void iwl_mvm_rx_mpdu_mq(struct iwl_mvm
*mvm
, struct napi_struct
*napi
,
1562 struct iwl_rx_cmd_buffer
*rxb
, int queue
)
1564 struct ieee80211_rx_status
*rx_status
;
1565 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1566 struct iwl_rx_mpdu_desc
*desc
= (void *)pkt
->data
;
1567 struct ieee80211_hdr
*hdr
;
1568 u32 len
= le16_to_cpu(desc
->mpdu_len
);
1569 u32 rate_n_flags
, gp2_on_air_rise
;
1570 u16 phy_info
= le16_to_cpu(desc
->phy_info
);
1571 struct ieee80211_sta
*sta
= NULL
;
1572 struct sk_buff
*skb
;
1573 u8 crypt_len
= 0, channel
, energy_a
, energy_b
;
1575 struct iwl_mvm_rx_phy_data phy_data
= {
1576 .d4
= desc
->phy_data4
,
1577 .info_type
= IWL_RX_PHY_INFO_TYPE_NONE
,
1581 if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)))
1584 if (mvm
->trans
->trans_cfg
->device_family
>= IWL_DEVICE_FAMILY_AX210
) {
1585 rate_n_flags
= le32_to_cpu(desc
->v3
.rate_n_flags
);
1586 channel
= desc
->v3
.channel
;
1587 gp2_on_air_rise
= le32_to_cpu(desc
->v3
.gp2_on_air_rise
);
1588 energy_a
= desc
->v3
.energy_a
;
1589 energy_b
= desc
->v3
.energy_b
;
1590 desc_size
= sizeof(*desc
);
1592 phy_data
.d0
= desc
->v3
.phy_data0
;
1593 phy_data
.d1
= desc
->v3
.phy_data1
;
1594 phy_data
.d2
= desc
->v3
.phy_data2
;
1595 phy_data
.d3
= desc
->v3
.phy_data3
;
1597 rate_n_flags
= le32_to_cpu(desc
->v1
.rate_n_flags
);
1598 channel
= desc
->v1
.channel
;
1599 gp2_on_air_rise
= le32_to_cpu(desc
->v1
.gp2_on_air_rise
);
1600 energy_a
= desc
->v1
.energy_a
;
1601 energy_b
= desc
->v1
.energy_b
;
1602 desc_size
= IWL_RX_DESC_SIZE_V1
;
1604 phy_data
.d0
= desc
->v1
.phy_data0
;
1605 phy_data
.d1
= desc
->v1
.phy_data1
;
1606 phy_data
.d2
= desc
->v1
.phy_data2
;
1607 phy_data
.d3
= desc
->v1
.phy_data3
;
1610 if (phy_info
& IWL_RX_MPDU_PHY_TSF_OVERLOAD
)
1611 phy_data
.info_type
=
1612 le32_get_bits(phy_data
.d1
,
1613 IWL_RX_PHY_DATA1_INFO_TYPE_MASK
);
1615 hdr
= (void *)(pkt
->data
+ desc_size
);
1616 /* Dont use dev_alloc_skb(), we'll have enough headroom once
1617 * ieee80211_hdr pulled.
1619 skb
= alloc_skb(128, GFP_ATOMIC
);
1621 IWL_ERR(mvm
, "alloc_skb failed\n");
1625 if (desc
->mac_flags2
& IWL_RX_MPDU_MFLG2_PAD
) {
1627 * If the device inserted padding it means that (it thought)
1628 * the 802.11 header wasn't a multiple of 4 bytes long. In
1629 * this case, reserve two bytes at the start of the SKB to
1630 * align the payload properly in case we end up copying it.
1632 skb_reserve(skb
, 2);
1635 rx_status
= IEEE80211_SKB_RXCB(skb
);
1637 /* This may be overridden by iwl_mvm_rx_he() to HE_RU */
1638 switch (rate_n_flags
& RATE_MCS_CHAN_WIDTH_MSK
) {
1639 case RATE_MCS_CHAN_WIDTH_20
:
1641 case RATE_MCS_CHAN_WIDTH_40
:
1642 rx_status
->bw
= RATE_INFO_BW_40
;
1644 case RATE_MCS_CHAN_WIDTH_80
:
1645 rx_status
->bw
= RATE_INFO_BW_80
;
1647 case RATE_MCS_CHAN_WIDTH_160
:
1648 rx_status
->bw
= RATE_INFO_BW_160
;
1652 if (rate_n_flags
& RATE_MCS_HE_MSK
)
1653 iwl_mvm_rx_he(mvm
, skb
, &phy_data
, rate_n_flags
,
1656 iwl_mvm_decode_lsig(skb
, &phy_data
);
1658 rx_status
= IEEE80211_SKB_RXCB(skb
);
1660 if (iwl_mvm_rx_crypto(mvm
, hdr
, rx_status
, phy_info
, desc
,
1661 le32_to_cpu(pkt
->len_n_flags
), queue
,
1668 * Keep packets with CRC errors (and with overrun) for monitor mode
1669 * (otherwise the firmware discards them) but mark them as bad.
1671 if (!(desc
->status
& cpu_to_le16(IWL_RX_MPDU_STATUS_CRC_OK
)) ||
1672 !(desc
->status
& cpu_to_le16(IWL_RX_MPDU_STATUS_OVERRUN_OK
))) {
1673 IWL_DEBUG_RX(mvm
, "Bad CRC or FIFO: 0x%08X.\n",
1674 le16_to_cpu(desc
->status
));
1675 rx_status
->flag
|= RX_FLAG_FAILED_FCS_CRC
;
1677 /* set the preamble flag if appropriate */
1678 if (rate_n_flags
& RATE_MCS_CCK_MSK
&&
1679 phy_info
& IWL_RX_MPDU_PHY_SHORT_PREAMBLE
)
1680 rx_status
->enc_flags
|= RX_ENC_FLAG_SHORTPRE
;
1682 if (likely(!(phy_info
& IWL_RX_MPDU_PHY_TSF_OVERLOAD
))) {
1683 u64 tsf_on_air_rise
;
1685 if (mvm
->trans
->trans_cfg
->device_family
>=
1686 IWL_DEVICE_FAMILY_AX210
)
1687 tsf_on_air_rise
= le64_to_cpu(desc
->v3
.tsf_on_air_rise
);
1689 tsf_on_air_rise
= le64_to_cpu(desc
->v1
.tsf_on_air_rise
);
1691 rx_status
->mactime
= tsf_on_air_rise
;
1692 /* TSF as indicated by the firmware is at INA time */
1693 rx_status
->flag
|= RX_FLAG_MACTIME_PLCP_START
;
1696 rx_status
->device_timestamp
= gp2_on_air_rise
;
1697 if (iwl_mvm_is_band_in_rx_supported(mvm
)) {
1698 u8 band
= BAND_IN_RX_STATUS(desc
->mac_phy_idx
);
1700 rx_status
->band
= iwl_mvm_nl80211_band_from_rx_msdu(band
);
1702 rx_status
->band
= channel
> 14 ? NL80211_BAND_5GHZ
:
1705 rx_status
->freq
= ieee80211_channel_to_frequency(channel
,
1707 iwl_mvm_get_signal_strength(mvm
, rx_status
, rate_n_flags
, energy_a
,
1710 /* update aggregation data for monitor sake on default queue */
1711 if (!queue
&& (phy_info
& IWL_RX_MPDU_PHY_AMPDU
)) {
1712 bool toggle_bit
= phy_info
& IWL_RX_MPDU_PHY_AMPDU_TOGGLE
;
1714 rx_status
->flag
|= RX_FLAG_AMPDU_DETAILS
;
1716 * Toggle is switched whenever new aggregation starts. Make
1717 * sure ampdu_reference is never 0 so we can later use it to
1718 * see if the frame was really part of an A-MPDU or not.
1720 if (toggle_bit
!= mvm
->ampdu_toggle
) {
1722 if (mvm
->ampdu_ref
== 0)
1724 mvm
->ampdu_toggle
= toggle_bit
;
1726 rx_status
->ampdu_reference
= mvm
->ampdu_ref
;
1729 if (unlikely(mvm
->monitor_on
))
1730 iwl_mvm_add_rtap_sniffer_config(mvm
, skb
);
1734 if (desc
->status
& cpu_to_le16(IWL_RX_MPDU_STATUS_SRC_STA_FOUND
)) {
1735 u8 id
= desc
->sta_id_flags
& IWL_RX_MPDU_SIF_STA_ID_MASK
;
1737 if (!WARN_ON_ONCE(id
>= ARRAY_SIZE(mvm
->fw_id_to_mac_id
))) {
1738 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[id
]);
1742 } else if (!is_multicast_ether_addr(hdr
->addr2
)) {
1744 * This is fine since we prevent two stations with the same
1745 * address from being added.
1747 sta
= ieee80211_find_sta_by_ifaddr(mvm
->hw
, hdr
->addr2
, NULL
);
1751 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1752 struct ieee80211_vif
*tx_blocked_vif
=
1753 rcu_dereference(mvm
->csa_tx_blocked_vif
);
1754 u8 baid
= (u8
)((le32_to_cpu(desc
->reorder_data
) &
1755 IWL_RX_MPDU_REORDER_BAID_MASK
) >>
1756 IWL_RX_MPDU_REORDER_BAID_SHIFT
);
1757 struct iwl_fw_dbg_trigger_tlv
*trig
;
1758 struct ieee80211_vif
*vif
= mvmsta
->vif
;
1760 if (!mvm
->tcm
.paused
&& len
>= sizeof(*hdr
) &&
1761 !is_multicast_ether_addr(hdr
->addr1
) &&
1762 ieee80211_is_data(hdr
->frame_control
) &&
1763 time_after(jiffies
, mvm
->tcm
.ts
+ MVM_TCM_PERIOD
))
1764 schedule_delayed_work(&mvm
->tcm
.work
, 0);
1767 * We have tx blocked stations (with CS bit). If we heard
1768 * frames from a blocked station on a new channel we can
1771 if (unlikely(tx_blocked_vif
) && tx_blocked_vif
== vif
) {
1772 struct iwl_mvm_vif
*mvmvif
=
1773 iwl_mvm_vif_from_mac80211(tx_blocked_vif
);
1775 if (mvmvif
->csa_target_freq
== rx_status
->freq
)
1776 iwl_mvm_sta_modify_disable_tx_ap(mvm
, sta
,
1780 rs_update_last_rssi(mvm
, mvmsta
, rx_status
);
1782 trig
= iwl_fw_dbg_trigger_on(&mvm
->fwrt
,
1783 ieee80211_vif_to_wdev(vif
),
1784 FW_DBG_TRIGGER_RSSI
);
1786 if (trig
&& ieee80211_is_beacon(hdr
->frame_control
)) {
1787 struct iwl_fw_dbg_trigger_low_rssi
*rssi_trig
;
1790 rssi_trig
= (void *)trig
->data
;
1791 rssi
= le32_to_cpu(rssi_trig
->rssi
);
1793 if (rx_status
->signal
< rssi
)
1794 iwl_fw_dbg_collect_trig(&mvm
->fwrt
, trig
,
1798 if (ieee80211_is_data(hdr
->frame_control
))
1799 iwl_mvm_rx_csum(sta
, skb
, desc
);
1801 if (iwl_mvm_is_dup(sta
, queue
, rx_status
, hdr
, desc
)) {
1807 * Our hardware de-aggregates AMSDUs but copies the mac header
1808 * as it to the de-aggregated MPDUs. We need to turn off the
1809 * AMSDU bit in the QoS control ourselves.
1810 * In addition, HW reverses addr3 and addr4 - reverse it back.
1812 if ((desc
->mac_flags2
& IWL_RX_MPDU_MFLG2_AMSDU
) &&
1813 !WARN_ON(!ieee80211_is_data_qos(hdr
->frame_control
))) {
1814 u8
*qc
= ieee80211_get_qos_ctl(hdr
);
1816 *qc
&= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT
;
1818 if (mvm
->trans
->trans_cfg
->device_family
==
1819 IWL_DEVICE_FAMILY_9000
) {
1820 iwl_mvm_flip_address(hdr
->addr3
);
1822 if (ieee80211_has_a4(hdr
->frame_control
))
1823 iwl_mvm_flip_address(hdr
->addr4
);
1826 if (baid
!= IWL_RX_REORDER_DATA_INVALID_BAID
) {
1827 u32 reorder_data
= le32_to_cpu(desc
->reorder_data
);
1829 iwl_mvm_agg_rx_received(mvm
, reorder_data
, baid
);
1833 if (!(rate_n_flags
& RATE_MCS_CCK_MSK
) &&
1834 rate_n_flags
& RATE_MCS_SGI_MSK
)
1835 rx_status
->enc_flags
|= RX_ENC_FLAG_SHORT_GI
;
1836 if (rate_n_flags
& RATE_HT_MCS_GF_MSK
)
1837 rx_status
->enc_flags
|= RX_ENC_FLAG_HT_GF
;
1838 if (rate_n_flags
& RATE_MCS_LDPC_MSK
)
1839 rx_status
->enc_flags
|= RX_ENC_FLAG_LDPC
;
1840 if (rate_n_flags
& RATE_MCS_HT_MSK
) {
1841 u8 stbc
= (rate_n_flags
& RATE_MCS_STBC_MSK
) >>
1843 rx_status
->encoding
= RX_ENC_HT
;
1844 rx_status
->rate_idx
= rate_n_flags
& RATE_HT_MCS_INDEX_MSK
;
1845 rx_status
->enc_flags
|= stbc
<< RX_ENC_FLAG_STBC_SHIFT
;
1846 } else if (rate_n_flags
& RATE_MCS_VHT_MSK
) {
1847 u8 stbc
= (rate_n_flags
& RATE_MCS_STBC_MSK
) >>
1850 ((rate_n_flags
& RATE_VHT_MCS_NSS_MSK
) >>
1851 RATE_VHT_MCS_NSS_POS
) + 1;
1852 rx_status
->rate_idx
= rate_n_flags
& RATE_VHT_MCS_RATE_CODE_MSK
;
1853 rx_status
->encoding
= RX_ENC_VHT
;
1854 rx_status
->enc_flags
|= stbc
<< RX_ENC_FLAG_STBC_SHIFT
;
1855 if (rate_n_flags
& RATE_MCS_BF_MSK
)
1856 rx_status
->enc_flags
|= RX_ENC_FLAG_BF
;
1857 } else if (!(rate_n_flags
& RATE_MCS_HE_MSK
)) {
1858 int rate
= iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags
,
1861 if (WARN(rate
< 0 || rate
> 0xFF,
1862 "Invalid rate flags 0x%x, band %d,\n",
1863 rate_n_flags
, rx_status
->band
)) {
1867 rx_status
->rate_idx
= rate
;
1870 /* management stuff on default queue */
1872 if (unlikely((ieee80211_is_beacon(hdr
->frame_control
) ||
1873 ieee80211_is_probe_resp(hdr
->frame_control
)) &&
1874 mvm
->sched_scan_pass_all
==
1875 SCHED_SCAN_PASS_ALL_ENABLED
))
1876 mvm
->sched_scan_pass_all
= SCHED_SCAN_PASS_ALL_FOUND
;
1878 if (unlikely(ieee80211_is_beacon(hdr
->frame_control
) ||
1879 ieee80211_is_probe_resp(hdr
->frame_control
)))
1880 rx_status
->boottime_ns
= ktime_get_boottime_ns();
1883 if (iwl_mvm_create_skb(mvm
, skb
, hdr
, len
, crypt_len
, rxb
)) {
1888 if (!iwl_mvm_reorder(mvm
, napi
, queue
, sta
, skb
, desc
))
1889 iwl_mvm_pass_packet_to_mac80211(mvm
, napi
, skb
, queue
,
1895 void iwl_mvm_rx_monitor_no_data(struct iwl_mvm
*mvm
, struct napi_struct
*napi
,
1896 struct iwl_rx_cmd_buffer
*rxb
, int queue
)
1898 struct ieee80211_rx_status
*rx_status
;
1899 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1900 struct iwl_rx_no_data
*desc
= (void *)pkt
->data
;
1901 u32 rate_n_flags
= le32_to_cpu(desc
->rate
);
1902 u32 gp2_on_air_rise
= le32_to_cpu(desc
->on_air_rise_time
);
1903 u32 rssi
= le32_to_cpu(desc
->rssi
);
1904 u32 info_type
= le32_to_cpu(desc
->info
) & RX_NO_DATA_INFO_TYPE_MSK
;
1905 u16 phy_info
= IWL_RX_MPDU_PHY_TSF_OVERLOAD
;
1906 struct ieee80211_sta
*sta
= NULL
;
1907 struct sk_buff
*skb
;
1908 u8 channel
, energy_a
, energy_b
;
1909 struct iwl_mvm_rx_phy_data phy_data
= {
1910 .d0
= desc
->phy_info
[0],
1911 .info_type
= IWL_RX_PHY_INFO_TYPE_NONE
,
1914 if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)))
1917 energy_a
= (rssi
& RX_NO_DATA_CHAIN_A_MSK
) >> RX_NO_DATA_CHAIN_A_POS
;
1918 energy_b
= (rssi
& RX_NO_DATA_CHAIN_B_MSK
) >> RX_NO_DATA_CHAIN_B_POS
;
1919 channel
= (rssi
& RX_NO_DATA_CHANNEL_MSK
) >> RX_NO_DATA_CHANNEL_POS
;
1921 phy_data
.info_type
=
1922 le32_get_bits(desc
->phy_info
[1],
1923 IWL_RX_PHY_DATA1_INFO_TYPE_MASK
);
1925 /* Dont use dev_alloc_skb(), we'll have enough headroom once
1926 * ieee80211_hdr pulled.
1928 skb
= alloc_skb(128, GFP_ATOMIC
);
1930 IWL_ERR(mvm
, "alloc_skb failed\n");
1934 rx_status
= IEEE80211_SKB_RXCB(skb
);
1937 rx_status
->flag
|= RX_FLAG_NO_PSDU
;
1939 switch (info_type
) {
1940 case RX_NO_DATA_INFO_TYPE_NDP
:
1941 rx_status
->zero_length_psdu_type
=
1942 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_SOUNDING
;
1944 case RX_NO_DATA_INFO_TYPE_MU_UNMATCHED
:
1945 case RX_NO_DATA_INFO_TYPE_HE_TB_UNMATCHED
:
1946 rx_status
->zero_length_psdu_type
=
1947 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_NOT_CAPTURED
;
1950 rx_status
->zero_length_psdu_type
=
1951 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_VENDOR
;
1955 /* This may be overridden by iwl_mvm_rx_he() to HE_RU */
1956 switch (rate_n_flags
& RATE_MCS_CHAN_WIDTH_MSK
) {
1957 case RATE_MCS_CHAN_WIDTH_20
:
1959 case RATE_MCS_CHAN_WIDTH_40
:
1960 rx_status
->bw
= RATE_INFO_BW_40
;
1962 case RATE_MCS_CHAN_WIDTH_80
:
1963 rx_status
->bw
= RATE_INFO_BW_80
;
1965 case RATE_MCS_CHAN_WIDTH_160
:
1966 rx_status
->bw
= RATE_INFO_BW_160
;
1970 if (rate_n_flags
& RATE_MCS_HE_MSK
)
1971 iwl_mvm_rx_he(mvm
, skb
, &phy_data
, rate_n_flags
,
1974 iwl_mvm_decode_lsig(skb
, &phy_data
);
1976 rx_status
->device_timestamp
= gp2_on_air_rise
;
1977 rx_status
->band
= channel
> 14 ? NL80211_BAND_5GHZ
:
1979 rx_status
->freq
= ieee80211_channel_to_frequency(channel
,
1981 iwl_mvm_get_signal_strength(mvm
, rx_status
, rate_n_flags
, energy_a
,
1986 if (!(rate_n_flags
& RATE_MCS_CCK_MSK
) &&
1987 rate_n_flags
& RATE_MCS_SGI_MSK
)
1988 rx_status
->enc_flags
|= RX_ENC_FLAG_SHORT_GI
;
1989 if (rate_n_flags
& RATE_HT_MCS_GF_MSK
)
1990 rx_status
->enc_flags
|= RX_ENC_FLAG_HT_GF
;
1991 if (rate_n_flags
& RATE_MCS_LDPC_MSK
)
1992 rx_status
->enc_flags
|= RX_ENC_FLAG_LDPC
;
1993 if (rate_n_flags
& RATE_MCS_HT_MSK
) {
1994 u8 stbc
= (rate_n_flags
& RATE_MCS_STBC_MSK
) >>
1996 rx_status
->encoding
= RX_ENC_HT
;
1997 rx_status
->rate_idx
= rate_n_flags
& RATE_HT_MCS_INDEX_MSK
;
1998 rx_status
->enc_flags
|= stbc
<< RX_ENC_FLAG_STBC_SHIFT
;
1999 } else if (rate_n_flags
& RATE_MCS_VHT_MSK
) {
2000 u8 stbc
= (rate_n_flags
& RATE_MCS_STBC_MSK
) >>
2002 rx_status
->rate_idx
= rate_n_flags
& RATE_VHT_MCS_RATE_CODE_MSK
;
2003 rx_status
->encoding
= RX_ENC_VHT
;
2004 rx_status
->enc_flags
|= stbc
<< RX_ENC_FLAG_STBC_SHIFT
;
2005 if (rate_n_flags
& RATE_MCS_BF_MSK
)
2006 rx_status
->enc_flags
|= RX_ENC_FLAG_BF
;
2008 * take the nss from the rx_vec since the rate_n_flags has
2009 * only 2 bits for the nss which gives a max of 4 ss but
2010 * there may be up to 8 spatial streams
2013 le32_get_bits(desc
->rx_vec
[0],
2014 RX_NO_DATA_RX_VEC0_VHT_NSTS_MSK
) + 1;
2015 } else if (rate_n_flags
& RATE_MCS_HE_MSK
) {
2017 le32_get_bits(desc
->rx_vec
[0],
2018 RX_NO_DATA_RX_VEC0_HE_NSTS_MSK
) + 1;
2020 int rate
= iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags
,
2023 if (WARN(rate
< 0 || rate
> 0xFF,
2024 "Invalid rate flags 0x%x, band %d,\n",
2025 rate_n_flags
, rx_status
->band
)) {
2029 rx_status
->rate_idx
= rate
;
2032 ieee80211_rx_napi(mvm
->hw
, sta
, skb
, napi
);
2037 void iwl_mvm_rx_frame_release(struct iwl_mvm
*mvm
, struct napi_struct
*napi
,
2038 struct iwl_rx_cmd_buffer
*rxb
, int queue
)
2040 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
2041 struct iwl_frame_release
*release
= (void *)pkt
->data
;
2043 iwl_mvm_release_frames_from_notif(mvm
, napi
, release
->baid
,
2044 le16_to_cpu(release
->nssn
),
2048 void iwl_mvm_rx_bar_frame_release(struct iwl_mvm
*mvm
, struct napi_struct
*napi
,
2049 struct iwl_rx_cmd_buffer
*rxb
, int queue
)
2051 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
2052 struct iwl_bar_frame_release
*release
= (void *)pkt
->data
;
2053 unsigned int baid
= le32_get_bits(release
->ba_info
,
2054 IWL_BAR_FRAME_RELEASE_BAID_MASK
);
2055 unsigned int nssn
= le32_get_bits(release
->ba_info
,
2056 IWL_BAR_FRAME_RELEASE_NSSN_MASK
);
2057 unsigned int sta_id
= le32_get_bits(release
->sta_tid
,
2058 IWL_BAR_FRAME_RELEASE_STA_MASK
);
2059 unsigned int tid
= le32_get_bits(release
->sta_tid
,
2060 IWL_BAR_FRAME_RELEASE_TID_MASK
);
2061 struct iwl_mvm_baid_data
*baid_data
;
2063 if (WARN_ON_ONCE(baid
== IWL_RX_REORDER_DATA_INVALID_BAID
||
2064 baid
>= ARRAY_SIZE(mvm
->baid_map
)))
2068 baid_data
= rcu_dereference(mvm
->baid_map
[baid
]);
2071 "Got valid BAID %d but not allocated, invalid BAR release!\n",
2076 if (WARN(tid
!= baid_data
->tid
|| sta_id
!= baid_data
->sta_id
,
2077 "baid 0x%x is mapped to sta:%d tid:%d, but BAR release received for sta:%d tid:%d\n",
2078 baid
, baid_data
->sta_id
, baid_data
->tid
, sta_id
,
2082 iwl_mvm_release_frames_from_notif(mvm
, napi
, baid
, nssn
, queue
, 0);