xref: /freebsd/sys/contrib/dev/iwlwifi/mvm/rxmq.c (revision edf8578117e8844e02c0121147f45e4609b30680)
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3  * Copyright (C) 2012-2014, 2018-2023 Intel Corporation
4  * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5  * Copyright (C) 2015-2017 Intel Deutschland GmbH
6  */
7 #include <linux/etherdevice.h>
8 #include <linux/skbuff.h>
9 #if defined(__FreeBSD__)
10 #include <net/ieee80211_radiotap.h>
11 #endif
12 #include "iwl-trans.h"
13 #include "mvm.h"
14 #include "fw-api.h"
15 #include "time-sync.h"
16 
17 static inline int iwl_mvm_check_pn(struct iwl_mvm *mvm, struct sk_buff *skb,
18 				   int queue, struct ieee80211_sta *sta)
19 {
20 	struct iwl_mvm_sta *mvmsta;
21 	struct ieee80211_hdr *hdr = (void *)skb_mac_header(skb);
22 	struct ieee80211_rx_status *stats = IEEE80211_SKB_RXCB(skb);
23 	struct iwl_mvm_key_pn *ptk_pn;
24 	int res;
25 	u8 tid, keyidx;
26 	u8 pn[IEEE80211_CCMP_PN_LEN];
27 	u8 *extiv;
28 
29 	/* do PN checking */
30 
31 	/* multicast and non-data only arrives on default queue */
32 	if (!ieee80211_is_data(hdr->frame_control) ||
33 	    is_multicast_ether_addr(hdr->addr1))
34 		return 0;
35 
36 	/* do not check PN for open AP */
37 	if (!(stats->flag & RX_FLAG_DECRYPTED))
38 		return 0;
39 
40 	/*
41 	 * avoid checking for default queue - we don't want to replicate
42 	 * all the logic that's necessary for checking the PN on fragmented
43 	 * frames, leave that to mac80211
44 	 */
45 	if (queue == 0)
46 		return 0;
47 
48 	/* if we are here - this for sure is either CCMP or GCMP */
49 	if (IS_ERR_OR_NULL(sta)) {
50 		IWL_DEBUG_DROP(mvm,
51 			       "expected hw-decrypted unicast frame for station\n");
52 		return -1;
53 	}
54 
55 	mvmsta = iwl_mvm_sta_from_mac80211(sta);
56 
57 	extiv = (u8 *)hdr + ieee80211_hdrlen(hdr->frame_control);
58 	keyidx = extiv[3] >> 6;
59 
60 	ptk_pn = rcu_dereference(mvmsta->ptk_pn[keyidx]);
61 	if (!ptk_pn)
62 		return -1;
63 
64 	if (ieee80211_is_data_qos(hdr->frame_control))
65 		tid = ieee80211_get_tid(hdr);
66 	else
67 		tid = 0;
68 
69 	/* we don't use HCCA/802.11 QoS TSPECs, so drop such frames */
70 	if (tid >= IWL_MAX_TID_COUNT)
71 		return -1;
72 
73 	/* load pn */
74 	pn[0] = extiv[7];
75 	pn[1] = extiv[6];
76 	pn[2] = extiv[5];
77 	pn[3] = extiv[4];
78 	pn[4] = extiv[1];
79 	pn[5] = extiv[0];
80 
81 	res = memcmp(pn, ptk_pn->q[queue].pn[tid], IEEE80211_CCMP_PN_LEN);
82 	if (res < 0)
83 		return -1;
84 	if (!res && !(stats->flag & RX_FLAG_ALLOW_SAME_PN))
85 		return -1;
86 
87 	memcpy(ptk_pn->q[queue].pn[tid], pn, IEEE80211_CCMP_PN_LEN);
88 	stats->flag |= RX_FLAG_PN_VALIDATED;
89 
90 	return 0;
91 }
92 
93 /* iwl_mvm_create_skb Adds the rxb to a new skb */
94 static int iwl_mvm_create_skb(struct iwl_mvm *mvm, struct sk_buff *skb,
95 			      struct ieee80211_hdr *hdr, u16 len, u8 crypt_len,
96 			      struct iwl_rx_cmd_buffer *rxb)
97 {
98 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
99 	struct iwl_rx_mpdu_desc *desc = (void *)pkt->data;
100 	unsigned int headlen, fraglen, pad_len = 0;
101 	unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control);
102 	u8 mic_crc_len = u8_get_bits(desc->mac_flags1,
103 				     IWL_RX_MPDU_MFLG1_MIC_CRC_LEN_MASK) << 1;
104 
105 	if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) {
106 		len -= 2;
107 		pad_len = 2;
108 	}
109 
110 	/*
111 	 * For non monitor interface strip the bytes the RADA might not have
112 	 * removed (it might be disabled, e.g. for mgmt frames). As a monitor
113 	 * interface cannot exist with other interfaces, this removal is safe
114 	 * and sufficient, in monitor mode there's no decryption being done.
115 	 */
116 	if (len > mic_crc_len && !ieee80211_hw_check(mvm->hw, RX_INCLUDES_FCS))
117 		len -= mic_crc_len;
118 
119 	/* If frame is small enough to fit in skb->head, pull it completely.
120 	 * If not, only pull ieee80211_hdr (including crypto if present, and
121 	 * an additional 8 bytes for SNAP/ethertype, see below) so that
122 	 * splice() or TCP coalesce are more efficient.
123 	 *
124 	 * Since, in addition, ieee80211_data_to_8023() always pull in at
125 	 * least 8 bytes (possibly more for mesh) we can do the same here
126 	 * to save the cost of doing it later. That still doesn't pull in
127 	 * the actual IP header since the typical case has a SNAP header.
128 	 * If the latter changes (there are efforts in the standards group
129 	 * to do so) we should revisit this and ieee80211_data_to_8023().
130 	 */
131 	headlen = (len <= skb_tailroom(skb)) ? len :
132 					       hdrlen + crypt_len + 8;
133 
134 	/* The firmware may align the packet to DWORD.
135 	 * The padding is inserted after the IV.
136 	 * After copying the header + IV skip the padding if
137 	 * present before copying packet data.
138 	 */
139 	hdrlen += crypt_len;
140 
141 	if (unlikely(headlen < hdrlen))
142 		return -EINVAL;
143 
144 	/* Since data doesn't move data while putting data on skb and that is
145 	 * the only way we use, data + len is the next place that hdr would be put
146 	 */
147 	skb_set_mac_header(skb, skb->len);
148 	skb_put_data(skb, hdr, hdrlen);
149 	skb_put_data(skb, (u8 *)hdr + hdrlen + pad_len, headlen - hdrlen);
150 
151 	/*
152 	 * If we did CHECKSUM_COMPLETE, the hardware only does it right for
153 	 * certain cases and starts the checksum after the SNAP. Check if
154 	 * this is the case - it's easier to just bail out to CHECKSUM_NONE
155 	 * in the cases the hardware didn't handle, since it's rare to see
156 	 * such packets, even though the hardware did calculate the checksum
157 	 * in this case, just starting after the MAC header instead.
158 	 *
159 	 * Starting from Bz hardware, it calculates starting directly after
160 	 * the MAC header, so that matches mac80211's expectation.
161 	 */
162 	if (skb->ip_summed == CHECKSUM_COMPLETE) {
163 		struct {
164 			u8 hdr[6];
165 			__be16 type;
166 		} __packed *shdr = (void *)((u8 *)hdr + hdrlen + pad_len);
167 
168 		if (unlikely(headlen - hdrlen < sizeof(*shdr) ||
169 			     !ether_addr_equal(shdr->hdr, rfc1042_header) ||
170 			     (shdr->type != htons(ETH_P_IP) &&
171 			      shdr->type != htons(ETH_P_ARP) &&
172 			      shdr->type != htons(ETH_P_IPV6) &&
173 			      shdr->type != htons(ETH_P_8021Q) &&
174 			      shdr->type != htons(ETH_P_PAE) &&
175 			      shdr->type != htons(ETH_P_TDLS))))
176 			skb->ip_summed = CHECKSUM_NONE;
177 		else if (mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_BZ)
178 			/* mac80211 assumes full CSUM including SNAP header */
179 			skb_postpush_rcsum(skb, shdr, sizeof(*shdr));
180 	}
181 
182 	fraglen = len - headlen;
183 
184 	if (fraglen) {
185 		int offset = (u8 *)hdr + headlen + pad_len -
186 			     (u8 *)rxb_addr(rxb) + rxb_offset(rxb);
187 
188 		skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset,
189 				fraglen, rxb->truesize);
190 	}
191 
192 	return 0;
193 }
194 
195 /* put a TLV on the skb and return data pointer
196  *
197  * Also pad to 4 the len and zero out all data part
198  */
199 static void *
200 iwl_mvm_radiotap_put_tlv(struct sk_buff *skb, u16 type, u16 len)
201 {
202 	struct ieee80211_radiotap_tlv *tlv;
203 
204 	tlv = skb_put(skb, sizeof(*tlv));
205 	tlv->type = cpu_to_le16(type);
206 	tlv->len = cpu_to_le16(len);
207 	return skb_put_zero(skb, ALIGN(len, 4));
208 }
209 
210 static void iwl_mvm_add_rtap_sniffer_config(struct iwl_mvm *mvm,
211 					    struct sk_buff *skb)
212 {
213 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
214 	struct ieee80211_radiotap_vendor_content *radiotap;
215 	const u16 vendor_data_len = sizeof(mvm->cur_aid);
216 
217 	if (!mvm->cur_aid)
218 		return;
219 
220 	radiotap = iwl_mvm_radiotap_put_tlv(skb,
221 					    IEEE80211_RADIOTAP_VENDOR_NAMESPACE,
222 					    sizeof(*radiotap) + vendor_data_len);
223 
224 	/* Intel OUI */
225 	radiotap->oui[0] = 0xf6;
226 	radiotap->oui[1] = 0x54;
227 	radiotap->oui[2] = 0x25;
228 	/* radiotap sniffer config sub-namespace */
229 	radiotap->oui_subtype = 1;
230 	radiotap->vendor_type = 0;
231 
232 	/* fill the data now */
233 	memcpy(radiotap->data, &mvm->cur_aid, sizeof(mvm->cur_aid));
234 
235 	rx_status->flag |= RX_FLAG_RADIOTAP_TLV_AT_END;
236 }
237 
238 /* iwl_mvm_pass_packet_to_mac80211 - passes the packet for mac80211 */
239 static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm *mvm,
240 					    struct napi_struct *napi,
241 					    struct sk_buff *skb, int queue,
242 					    struct ieee80211_sta *sta,
243 					    struct ieee80211_link_sta *link_sta)
244 {
245 	if (unlikely(iwl_mvm_check_pn(mvm, skb, queue, sta))) {
246 		kfree_skb(skb);
247 		return;
248 	}
249 
250 	if (sta && sta->valid_links && link_sta) {
251 		struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
252 
253 		rx_status->link_valid = 1;
254 		rx_status->link_id = link_sta->link_id;
255 	}
256 
257 	ieee80211_rx_napi(mvm->hw, sta, skb, napi);
258 }
259 
260 static void iwl_mvm_get_signal_strength(struct iwl_mvm *mvm,
261 					struct ieee80211_rx_status *rx_status,
262 					u32 rate_n_flags, int energy_a,
263 					int energy_b)
264 {
265 	int max_energy;
266 	u32 rate_flags = rate_n_flags;
267 
268 	energy_a = energy_a ? -energy_a : S8_MIN;
269 	energy_b = energy_b ? -energy_b : S8_MIN;
270 	max_energy = max(energy_a, energy_b);
271 
272 	IWL_DEBUG_STATS(mvm, "energy In A %d B %d, and max %d\n",
273 			energy_a, energy_b, max_energy);
274 
275 	rx_status->signal = max_energy;
276 	rx_status->chains =
277 		(rate_flags & RATE_MCS_ANT_AB_MSK) >> RATE_MCS_ANT_POS;
278 	rx_status->chain_signal[0] = energy_a;
279 	rx_status->chain_signal[1] = energy_b;
280 }
281 
282 static int iwl_mvm_rx_mgmt_prot(struct ieee80211_sta *sta,
283 				struct ieee80211_hdr *hdr,
284 				struct iwl_rx_mpdu_desc *desc,
285 				u32 status,
286 				struct ieee80211_rx_status *stats)
287 {
288 	struct iwl_mvm_sta *mvmsta;
289 	struct iwl_mvm_vif *mvmvif;
290 	u8 keyid;
291 	struct ieee80211_key_conf *key;
292 	u32 len = le16_to_cpu(desc->mpdu_len);
293 	const u8 *frame = (void *)hdr;
294 
295 	if ((status & IWL_RX_MPDU_STATUS_SEC_MASK) == IWL_RX_MPDU_STATUS_SEC_NONE)
296 		return 0;
297 
298 	/*
299 	 * For non-beacon, we don't really care. But beacons may
300 	 * be filtered out, and we thus need the firmware's replay
301 	 * detection, otherwise beacons the firmware previously
302 	 * filtered could be replayed, or something like that, and
303 	 * it can filter a lot - though usually only if nothing has
304 	 * changed.
305 	 */
306 	if (!ieee80211_is_beacon(hdr->frame_control))
307 		return 0;
308 
309 	/* key mismatch - will also report !MIC_OK but we shouldn't count it */
310 	if (!(status & IWL_RX_MPDU_STATUS_KEY_VALID))
311 		return -1;
312 
313 	/* good cases */
314 	if (likely(status & IWL_RX_MPDU_STATUS_MIC_OK &&
315 		   !(status & IWL_RX_MPDU_STATUS_REPLAY_ERROR))) {
316 		stats->flag |= RX_FLAG_DECRYPTED;
317 		return 0;
318 	}
319 
320 	if (!sta)
321 		return -1;
322 
323 	mvmsta = iwl_mvm_sta_from_mac80211(sta);
324 
325 	mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
326 
327 	/*
328 	 * both keys will have the same cipher and MIC length, use
329 	 * whichever one is available
330 	 */
331 	key = rcu_dereference(mvmvif->bcn_prot.keys[0]);
332 	if (!key) {
333 		key = rcu_dereference(mvmvif->bcn_prot.keys[1]);
334 		if (!key)
335 			return -1;
336 	}
337 
338 	if (len < key->icv_len + IEEE80211_GMAC_PN_LEN + 2)
339 		return -1;
340 
341 	/* get the real key ID */
342 	keyid = frame[len - key->icv_len - IEEE80211_GMAC_PN_LEN - 2];
343 	/* and if that's the other key, look it up */
344 	if (keyid != key->keyidx) {
345 		/*
346 		 * shouldn't happen since firmware checked, but be safe
347 		 * in case the MIC length is wrong too, for example
348 		 */
349 		if (keyid != 6 && keyid != 7)
350 			return -1;
351 		key = rcu_dereference(mvmvif->bcn_prot.keys[keyid - 6]);
352 		if (!key)
353 			return -1;
354 	}
355 
356 	/* Report status to mac80211 */
357 	if (!(status & IWL_RX_MPDU_STATUS_MIC_OK))
358 		ieee80211_key_mic_failure(key);
359 	else if (status & IWL_RX_MPDU_STATUS_REPLAY_ERROR)
360 		ieee80211_key_replay(key);
361 
362 	return -1;
363 }
364 
365 static int iwl_mvm_rx_crypto(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
366 			     struct ieee80211_hdr *hdr,
367 			     struct ieee80211_rx_status *stats, u16 phy_info,
368 			     struct iwl_rx_mpdu_desc *desc,
369 			     u32 pkt_flags, int queue, u8 *crypt_len)
370 {
371 	u32 status = le32_to_cpu(desc->status);
372 
373 	/*
374 	 * Drop UNKNOWN frames in aggregation, unless in monitor mode
375 	 * (where we don't have the keys).
376 	 * We limit this to aggregation because in TKIP this is a valid
377 	 * scenario, since we may not have the (correct) TTAK (phase 1
378 	 * key) in the firmware.
379 	 */
380 	if (phy_info & IWL_RX_MPDU_PHY_AMPDU &&
381 	    (status & IWL_RX_MPDU_STATUS_SEC_MASK) ==
382 	    IWL_RX_MPDU_STATUS_SEC_UNKNOWN && !mvm->monitor_on)
383 		return -1;
384 
385 	if (unlikely(ieee80211_is_mgmt(hdr->frame_control) &&
386 		     !ieee80211_has_protected(hdr->frame_control)))
387 		return iwl_mvm_rx_mgmt_prot(sta, hdr, desc, status, stats);
388 
389 	if (!ieee80211_has_protected(hdr->frame_control) ||
390 	    (status & IWL_RX_MPDU_STATUS_SEC_MASK) ==
391 	    IWL_RX_MPDU_STATUS_SEC_NONE)
392 		return 0;
393 
394 	/* TODO: handle packets encrypted with unknown alg */
395 #if defined(__FreeBSD__)
396 	/* XXX-BZ do similar to rx.c for now as these are plenty. */
397 	if ((status & IWL_RX_MPDU_STATUS_SEC_MASK) ==
398 	    IWL_RX_MPDU_STATUS_SEC_ENC_ERR)
399 		return (0);
400 #endif
401 
402 	switch (status & IWL_RX_MPDU_STATUS_SEC_MASK) {
403 	case IWL_RX_MPDU_STATUS_SEC_CCM:
404 	case IWL_RX_MPDU_STATUS_SEC_GCM:
405 		BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN != IEEE80211_GCMP_PN_LEN);
406 		/* alg is CCM: check MIC only */
407 		if (!(status & IWL_RX_MPDU_STATUS_MIC_OK))
408 			return -1;
409 
410 		stats->flag |= RX_FLAG_DECRYPTED | RX_FLAG_MIC_STRIPPED;
411 		*crypt_len = IEEE80211_CCMP_HDR_LEN;
412 		return 0;
413 	case IWL_RX_MPDU_STATUS_SEC_TKIP:
414 		/* Don't drop the frame and decrypt it in SW */
415 		if (!fw_has_api(&mvm->fw->ucode_capa,
416 				IWL_UCODE_TLV_API_DEPRECATE_TTAK) &&
417 		    !(status & IWL_RX_MPDU_RES_STATUS_TTAK_OK))
418 			return 0;
419 
420 		if (mvm->trans->trans_cfg->gen2 &&
421 		    !(status & RX_MPDU_RES_STATUS_MIC_OK))
422 			stats->flag |= RX_FLAG_MMIC_ERROR;
423 
424 		*crypt_len = IEEE80211_TKIP_IV_LEN;
425 		fallthrough;
426 	case IWL_RX_MPDU_STATUS_SEC_WEP:
427 		if (!(status & IWL_RX_MPDU_STATUS_ICV_OK))
428 			return -1;
429 
430 		stats->flag |= RX_FLAG_DECRYPTED;
431 		if ((status & IWL_RX_MPDU_STATUS_SEC_MASK) ==
432 				IWL_RX_MPDU_STATUS_SEC_WEP)
433 			*crypt_len = IEEE80211_WEP_IV_LEN;
434 
435 		if (pkt_flags & FH_RSCSR_RADA_EN) {
436 			stats->flag |= RX_FLAG_ICV_STRIPPED;
437 			if (mvm->trans->trans_cfg->gen2)
438 				stats->flag |= RX_FLAG_MMIC_STRIPPED;
439 		}
440 
441 		return 0;
442 	case IWL_RX_MPDU_STATUS_SEC_EXT_ENC:
443 		if (!(status & IWL_RX_MPDU_STATUS_MIC_OK))
444 			return -1;
445 		stats->flag |= RX_FLAG_DECRYPTED;
446 		return 0;
447 	case RX_MPDU_RES_STATUS_SEC_CMAC_GMAC_ENC:
448 		break;
449 	default:
450 		/*
451 		 * Sometimes we can get frames that were not decrypted
452 		 * because the firmware didn't have the keys yet. This can
453 		 * happen after connection where we can get multicast frames
454 		 * before the GTK is installed.
455 		 * Silently drop those frames.
456 		 * Also drop un-decrypted frames in monitor mode.
457 		 */
458 		if (!is_multicast_ether_addr(hdr->addr1) &&
459 		    !mvm->monitor_on && net_ratelimit())
460 #if defined(__linux__)
461 			IWL_WARN(mvm, "Unhandled alg: 0x%x\n", status);
462 #elif defined(__FreeBSD__)
463 			IWL_WARN(mvm, "%s: Unhandled alg: 0x%x\n", __func__, status);
464 #endif
465 	}
466 
467 	return 0;
468 }
469 
470 static void iwl_mvm_rx_csum(struct iwl_mvm *mvm,
471 			    struct ieee80211_sta *sta,
472 			    struct sk_buff *skb,
473 			    struct iwl_rx_packet *pkt)
474 {
475 	struct iwl_rx_mpdu_desc *desc = (void *)pkt->data;
476 
477 	if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) {
478 		if (pkt->len_n_flags & cpu_to_le32(FH_RSCSR_RPA_EN)) {
479 			u16 hwsum = be16_to_cpu(desc->v3.raw_xsum);
480 
481 			skb->ip_summed = CHECKSUM_COMPLETE;
482 			skb->csum = csum_unfold(~(__force __sum16)hwsum);
483 		}
484 	} else {
485 		struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
486 		struct iwl_mvm_vif *mvmvif;
487 		u16 flags = le16_to_cpu(desc->l3l4_flags);
488 		u8 l3_prot = (u8)((flags & IWL_RX_L3L4_L3_PROTO_MASK) >>
489 				  IWL_RX_L3_PROTO_POS);
490 
491 		mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
492 
493 		if (mvmvif->features & NETIF_F_RXCSUM &&
494 		    flags & IWL_RX_L3L4_TCP_UDP_CSUM_OK &&
495 		    (flags & IWL_RX_L3L4_IP_HDR_CSUM_OK ||
496 		     l3_prot == IWL_RX_L3_TYPE_IPV6 ||
497 		     l3_prot == IWL_RX_L3_TYPE_IPV6_FRAG))
498 			skb->ip_summed = CHECKSUM_UNNECESSARY;
499 	}
500 }
501 
502 /*
503  * returns true if a packet is a duplicate or invalid tid and should be dropped.
504  * Updates AMSDU PN tracking info
505  */
506 static bool iwl_mvm_is_dup(struct ieee80211_sta *sta, int queue,
507 			   struct ieee80211_rx_status *rx_status,
508 			   struct ieee80211_hdr *hdr,
509 			   struct iwl_rx_mpdu_desc *desc)
510 {
511 	struct iwl_mvm_sta *mvm_sta;
512 	struct iwl_mvm_rxq_dup_data *dup_data;
513 	u8 tid, sub_frame_idx;
514 
515 	if (WARN_ON(IS_ERR_OR_NULL(sta)))
516 		return false;
517 
518 	mvm_sta = iwl_mvm_sta_from_mac80211(sta);
519 #if defined(__FreeBSD__)
520 	if (WARN_ON(mvm_sta->dup_data == NULL))
521 		return false;
522 #endif
523 	dup_data = &mvm_sta->dup_data[queue];
524 
525 	/*
526 	 * Drop duplicate 802.11 retransmissions
527 	 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
528 	 */
529 	if (ieee80211_is_ctl(hdr->frame_control) ||
530 	    ieee80211_is_qos_nullfunc(hdr->frame_control) ||
531 	    is_multicast_ether_addr(hdr->addr1)) {
532 		rx_status->flag |= RX_FLAG_DUP_VALIDATED;
533 		return false;
534 	}
535 
536 	if (ieee80211_is_data_qos(hdr->frame_control)) {
537 		/* frame has qos control */
538 		tid = ieee80211_get_tid(hdr);
539 		if (tid >= IWL_MAX_TID_COUNT)
540 			return true;
541 	} else {
542 		tid = IWL_MAX_TID_COUNT;
543 	}
544 
545 	/* If this wasn't a part of an A-MSDU the sub-frame index will be 0 */
546 	sub_frame_idx = desc->amsdu_info &
547 		IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK;
548 
549 	if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
550 		     dup_data->last_seq[tid] == hdr->seq_ctrl &&
551 		     dup_data->last_sub_frame[tid] >= sub_frame_idx))
552 		return true;
553 
554 	/* Allow same PN as the first subframe for following sub frames */
555 	if (dup_data->last_seq[tid] == hdr->seq_ctrl &&
556 	    sub_frame_idx > dup_data->last_sub_frame[tid] &&
557 	    desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU)
558 		rx_status->flag |= RX_FLAG_ALLOW_SAME_PN;
559 
560 	dup_data->last_seq[tid] = hdr->seq_ctrl;
561 	dup_data->last_sub_frame[tid] = sub_frame_idx;
562 
563 	rx_status->flag |= RX_FLAG_DUP_VALIDATED;
564 
565 	return false;
566 }
567 
568 /*
569  * Returns true if sn2 - buffer_size < sn1 < sn2.
570  * To be used only in order to compare reorder buffer head with NSSN.
571  * We fully trust NSSN unless it is behind us due to reorder timeout.
572  * Reorder timeout can only bring us up to buffer_size SNs ahead of NSSN.
573  */
574 static bool iwl_mvm_is_sn_less(u16 sn1, u16 sn2, u16 buffer_size)
575 {
576 	return ieee80211_sn_less(sn1, sn2) &&
577 	       !ieee80211_sn_less(sn1, sn2 - buffer_size);
578 }
579 
580 static void iwl_mvm_sync_nssn(struct iwl_mvm *mvm, u8 baid, u16 nssn)
581 {
582 	if (IWL_MVM_USE_NSSN_SYNC) {
583 		struct iwl_mvm_nssn_sync_data notif = {
584 			.baid = baid,
585 			.nssn = nssn,
586 		};
587 
588 		iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_NSSN_SYNC, false,
589 						&notif, sizeof(notif));
590 	}
591 }
592 
593 #define RX_REORDER_BUF_TIMEOUT_MQ (HZ / 10)
594 
595 enum iwl_mvm_release_flags {
596 	IWL_MVM_RELEASE_SEND_RSS_SYNC = BIT(0),
597 	IWL_MVM_RELEASE_FROM_RSS_SYNC = BIT(1),
598 };
599 
600 static void iwl_mvm_release_frames(struct iwl_mvm *mvm,
601 				   struct ieee80211_sta *sta,
602 				   struct napi_struct *napi,
603 				   struct iwl_mvm_baid_data *baid_data,
604 				   struct iwl_mvm_reorder_buffer *reorder_buf,
605 				   u16 nssn, u32 flags)
606 {
607 	struct iwl_mvm_reorder_buf_entry *entries =
608 		&baid_data->entries[reorder_buf->queue *
609 				    baid_data->entries_per_queue];
610 	u16 ssn = reorder_buf->head_sn;
611 
612 	lockdep_assert_held(&reorder_buf->lock);
613 
614 	/*
615 	 * We keep the NSSN not too far behind, if we are sync'ing it and it
616 	 * is more than 2048 ahead of us, it must be behind us. Discard it.
617 	 * This can happen if the queue that hit the 0 / 2048 seqno was lagging
618 	 * behind and this queue already processed packets. The next if
619 	 * would have caught cases where this queue would have processed less
620 	 * than 64 packets, but it may have processed more than 64 packets.
621 	 */
622 	if ((flags & IWL_MVM_RELEASE_FROM_RSS_SYNC) &&
623 	    ieee80211_sn_less(nssn, ssn))
624 		goto set_timer;
625 
626 	/* ignore nssn smaller than head sn - this can happen due to timeout */
627 	if (iwl_mvm_is_sn_less(nssn, ssn, reorder_buf->buf_size))
628 		goto set_timer;
629 
630 	while (iwl_mvm_is_sn_less(ssn, nssn, reorder_buf->buf_size)) {
631 		int index = ssn % reorder_buf->buf_size;
632 		struct sk_buff_head *skb_list = &entries[index].e.frames;
633 		struct sk_buff *skb;
634 
635 		ssn = ieee80211_sn_inc(ssn);
636 		if ((flags & IWL_MVM_RELEASE_SEND_RSS_SYNC) &&
637 		    (ssn == 2048 || ssn == 0))
638 			iwl_mvm_sync_nssn(mvm, baid_data->baid, ssn);
639 
640 		/*
641 		 * Empty the list. Will have more than one frame for A-MSDU.
642 		 * Empty list is valid as well since nssn indicates frames were
643 		 * received.
644 		 */
645 		while ((skb = __skb_dequeue(skb_list))) {
646 			iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb,
647 							reorder_buf->queue,
648 							sta, NULL /* FIXME */);
649 			reorder_buf->num_stored--;
650 		}
651 	}
652 	reorder_buf->head_sn = nssn;
653 
654 set_timer:
655 	if (reorder_buf->num_stored && !reorder_buf->removed) {
656 		u16 index = reorder_buf->head_sn % reorder_buf->buf_size;
657 
658 		while (skb_queue_empty(&entries[index].e.frames))
659 			index = (index + 1) % reorder_buf->buf_size;
660 		/* modify timer to match next frame's expiration time */
661 		mod_timer(&reorder_buf->reorder_timer,
662 			  entries[index].e.reorder_time + 1 +
663 			  RX_REORDER_BUF_TIMEOUT_MQ);
664 	} else {
665 		del_timer(&reorder_buf->reorder_timer);
666 	}
667 }
668 
669 void iwl_mvm_reorder_timer_expired(struct timer_list *t)
670 {
671 	struct iwl_mvm_reorder_buffer *buf = from_timer(buf, t, reorder_timer);
672 	struct iwl_mvm_baid_data *baid_data =
673 		iwl_mvm_baid_data_from_reorder_buf(buf);
674 	struct iwl_mvm_reorder_buf_entry *entries =
675 		&baid_data->entries[buf->queue * baid_data->entries_per_queue];
676 	int i;
677 	u16 sn = 0, index = 0;
678 	bool expired = false;
679 	bool cont = false;
680 
681 	spin_lock(&buf->lock);
682 
683 	if (!buf->num_stored || buf->removed) {
684 		spin_unlock(&buf->lock);
685 		return;
686 	}
687 
688 	for (i = 0; i < buf->buf_size ; i++) {
689 		index = (buf->head_sn + i) % buf->buf_size;
690 
691 		if (skb_queue_empty(&entries[index].e.frames)) {
692 			/*
693 			 * If there is a hole and the next frame didn't expire
694 			 * we want to break and not advance SN
695 			 */
696 			cont = false;
697 			continue;
698 		}
699 		if (!cont &&
700 		    !time_after(jiffies, entries[index].e.reorder_time +
701 					 RX_REORDER_BUF_TIMEOUT_MQ))
702 			break;
703 
704 		expired = true;
705 		/* continue until next hole after this expired frames */
706 		cont = true;
707 		sn = ieee80211_sn_add(buf->head_sn, i + 1);
708 	}
709 
710 	if (expired) {
711 		struct ieee80211_sta *sta;
712 		struct iwl_mvm_sta *mvmsta;
713 		u8 sta_id = ffs(baid_data->sta_mask) - 1;
714 
715 		rcu_read_lock();
716 		sta = rcu_dereference(buf->mvm->fw_id_to_mac_id[sta_id]);
717 		if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
718 			rcu_read_unlock();
719 			goto out;
720 		}
721 
722 		mvmsta = iwl_mvm_sta_from_mac80211(sta);
723 
724 		/* SN is set to the last expired frame + 1 */
725 		IWL_DEBUG_HT(buf->mvm,
726 			     "Releasing expired frames for sta %u, sn %d\n",
727 			     sta_id, sn);
728 		iwl_mvm_event_frame_timeout_callback(buf->mvm, mvmsta->vif,
729 						     sta, baid_data->tid);
730 		iwl_mvm_release_frames(buf->mvm, sta, NULL, baid_data,
731 				       buf, sn, IWL_MVM_RELEASE_SEND_RSS_SYNC);
732 		rcu_read_unlock();
733 	} else {
734 		/*
735 		 * If no frame expired and there are stored frames, index is now
736 		 * pointing to the first unexpired frame - modify timer
737 		 * accordingly to this frame.
738 		 */
739 		mod_timer(&buf->reorder_timer,
740 			  entries[index].e.reorder_time +
741 			  1 + RX_REORDER_BUF_TIMEOUT_MQ);
742 	}
743 
744 out:
745 	spin_unlock(&buf->lock);
746 }
747 
748 static void iwl_mvm_del_ba(struct iwl_mvm *mvm, int queue,
749 			   struct iwl_mvm_delba_data *data)
750 {
751 	struct iwl_mvm_baid_data *ba_data;
752 	struct ieee80211_sta *sta;
753 	struct iwl_mvm_reorder_buffer *reorder_buf;
754 	u8 baid = data->baid;
755 	u32 sta_id;
756 
757 	if (WARN_ONCE(baid >= IWL_MAX_BAID, "invalid BAID: %x\n", baid))
758 		return;
759 
760 	rcu_read_lock();
761 
762 	ba_data = rcu_dereference(mvm->baid_map[baid]);
763 	if (WARN_ON_ONCE(!ba_data))
764 		goto out;
765 
766 	/* pick any STA ID to find the pointer */
767 	sta_id = ffs(ba_data->sta_mask) - 1;
768 	sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
769 	if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
770 		goto out;
771 
772 	reorder_buf = &ba_data->reorder_buf[queue];
773 
774 	/* release all frames that are in the reorder buffer to the stack */
775 	spin_lock_bh(&reorder_buf->lock);
776 	iwl_mvm_release_frames(mvm, sta, NULL, ba_data, reorder_buf,
777 			       ieee80211_sn_add(reorder_buf->head_sn,
778 						reorder_buf->buf_size),
779 			       0);
780 	spin_unlock_bh(&reorder_buf->lock);
781 	del_timer_sync(&reorder_buf->reorder_timer);
782 
783 out:
784 	rcu_read_unlock();
785 }
786 
787 static void iwl_mvm_release_frames_from_notif(struct iwl_mvm *mvm,
788 					      struct napi_struct *napi,
789 					      u8 baid, u16 nssn, int queue,
790 					      u32 flags)
791 {
792 	struct ieee80211_sta *sta;
793 	struct iwl_mvm_reorder_buffer *reorder_buf;
794 	struct iwl_mvm_baid_data *ba_data;
795 	u32 sta_id;
796 
797 	IWL_DEBUG_HT(mvm, "Frame release notification for BAID %u, NSSN %d\n",
798 		     baid, nssn);
799 
800 	if (WARN_ON_ONCE(baid == IWL_RX_REORDER_DATA_INVALID_BAID ||
801 			 baid >= ARRAY_SIZE(mvm->baid_map)))
802 		return;
803 
804 	rcu_read_lock();
805 
806 	ba_data = rcu_dereference(mvm->baid_map[baid]);
807 	if (!ba_data) {
808 		WARN(!(flags & IWL_MVM_RELEASE_FROM_RSS_SYNC),
809 		     "BAID %d not found in map\n", baid);
810 		goto out;
811 	}
812 
813 	/* pick any STA ID to find the pointer */
814 	sta_id = ffs(ba_data->sta_mask) - 1;
815 	sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
816 	if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
817 		goto out;
818 
819 	reorder_buf = &ba_data->reorder_buf[queue];
820 
821 	spin_lock_bh(&reorder_buf->lock);
822 	iwl_mvm_release_frames(mvm, sta, napi, ba_data,
823 			       reorder_buf, nssn, flags);
824 	spin_unlock_bh(&reorder_buf->lock);
825 
826 out:
827 	rcu_read_unlock();
828 }
829 
830 static void iwl_mvm_nssn_sync(struct iwl_mvm *mvm,
831 			      struct napi_struct *napi, int queue,
832 			      const struct iwl_mvm_nssn_sync_data *data)
833 {
834 	iwl_mvm_release_frames_from_notif(mvm, napi, data->baid,
835 					  data->nssn, queue,
836 					  IWL_MVM_RELEASE_FROM_RSS_SYNC);
837 }
838 
839 void iwl_mvm_rx_queue_notif(struct iwl_mvm *mvm, struct napi_struct *napi,
840 			    struct iwl_rx_cmd_buffer *rxb, int queue)
841 {
842 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
843 	struct iwl_rxq_sync_notification *notif;
844 	struct iwl_mvm_internal_rxq_notif *internal_notif;
845 	u32 len = iwl_rx_packet_payload_len(pkt);
846 
847 	notif = (void *)pkt->data;
848 	internal_notif = (void *)notif->payload;
849 
850 	if (WARN_ONCE(len < sizeof(*notif) + sizeof(*internal_notif),
851 		      "invalid notification size %d (%d)",
852 		      len, (int)(sizeof(*notif) + sizeof(*internal_notif))))
853 		return;
854 	len -= sizeof(*notif) + sizeof(*internal_notif);
855 
856 	if (internal_notif->sync &&
857 	    mvm->queue_sync_cookie != internal_notif->cookie) {
858 		WARN_ONCE(1, "Received expired RX queue sync message\n");
859 		return;
860 	}
861 
862 	switch (internal_notif->type) {
863 	case IWL_MVM_RXQ_EMPTY:
864 		WARN_ONCE(len, "invalid empty notification size %d", len);
865 		break;
866 	case IWL_MVM_RXQ_NOTIF_DEL_BA:
867 		if (WARN_ONCE(len != sizeof(struct iwl_mvm_delba_data),
868 			      "invalid delba notification size %d (%d)",
869 			      len, (int)sizeof(struct iwl_mvm_delba_data)))
870 			break;
871 		iwl_mvm_del_ba(mvm, queue, (void *)internal_notif->data);
872 		break;
873 	case IWL_MVM_RXQ_NSSN_SYNC:
874 		if (WARN_ONCE(len != sizeof(struct iwl_mvm_nssn_sync_data),
875 			      "invalid nssn sync notification size %d (%d)",
876 			      len, (int)sizeof(struct iwl_mvm_nssn_sync_data)))
877 			break;
878 		iwl_mvm_nssn_sync(mvm, napi, queue,
879 				  (void *)internal_notif->data);
880 		break;
881 	default:
882 		WARN_ONCE(1, "Invalid identifier %d", internal_notif->type);
883 	}
884 
885 	if (internal_notif->sync) {
886 		WARN_ONCE(!test_and_clear_bit(queue, &mvm->queue_sync_state),
887 			  "queue sync: queue %d responded a second time!\n",
888 			  queue);
889 		if (READ_ONCE(mvm->queue_sync_state) == 0)
890 			wake_up(&mvm->rx_sync_waitq);
891 	}
892 }
893 
894 static void iwl_mvm_oldsn_workaround(struct iwl_mvm *mvm,
895 				     struct ieee80211_sta *sta, int tid,
896 				     struct iwl_mvm_reorder_buffer *buffer,
897 				     u32 reorder, u32 gp2, int queue)
898 {
899 	struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
900 
901 	if (gp2 != buffer->consec_oldsn_ampdu_gp2) {
902 		/* we have a new (A-)MPDU ... */
903 
904 		/*
905 		 * reset counter to 0 if we didn't have any oldsn in
906 		 * the last A-MPDU (as detected by GP2 being identical)
907 		 */
908 		if (!buffer->consec_oldsn_prev_drop)
909 			buffer->consec_oldsn_drops = 0;
910 
911 		/* either way, update our tracking state */
912 		buffer->consec_oldsn_ampdu_gp2 = gp2;
913 	} else if (buffer->consec_oldsn_prev_drop) {
914 		/*
915 		 * tracking state didn't change, and we had an old SN
916 		 * indication before - do nothing in this case, we
917 		 * already noted this one down and are waiting for the
918 		 * next A-MPDU (by GP2)
919 		 */
920 		return;
921 	}
922 
923 	/* return unless this MPDU has old SN */
924 	if (!(reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN))
925 		return;
926 
927 	/* update state */
928 	buffer->consec_oldsn_prev_drop = 1;
929 	buffer->consec_oldsn_drops++;
930 
931 	/* if limit is reached, send del BA and reset state */
932 	if (buffer->consec_oldsn_drops == IWL_MVM_AMPDU_CONSEC_DROPS_DELBA) {
933 		IWL_WARN(mvm,
934 			 "reached %d old SN frames from %pM on queue %d, stopping BA session on TID %d\n",
935 			 IWL_MVM_AMPDU_CONSEC_DROPS_DELBA,
936 			 sta->addr, queue, tid);
937 		ieee80211_stop_rx_ba_session(mvmsta->vif, BIT(tid), sta->addr);
938 		buffer->consec_oldsn_prev_drop = 0;
939 		buffer->consec_oldsn_drops = 0;
940 	}
941 }
942 
943 /*
944  * Returns true if the MPDU was buffered\dropped, false if it should be passed
945  * to upper layer.
946  */
947 static bool iwl_mvm_reorder(struct iwl_mvm *mvm,
948 			    struct napi_struct *napi,
949 			    int queue,
950 			    struct ieee80211_sta *sta,
951 			    struct sk_buff *skb,
952 			    struct iwl_rx_mpdu_desc *desc)
953 {
954 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
955 	struct ieee80211_hdr *hdr = (void *)skb_mac_header(skb);
956 	struct iwl_mvm_baid_data *baid_data;
957 	struct iwl_mvm_reorder_buffer *buffer;
958 	struct sk_buff *tail;
959 	u32 reorder = le32_to_cpu(desc->reorder_data);
960 	bool amsdu = desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU;
961 	bool last_subframe =
962 		desc->amsdu_info & IWL_RX_MPDU_AMSDU_LAST_SUBFRAME;
963 #if defined(__linux__)
964 	u8 tid = ieee80211_get_tid(hdr);
965 #elif defined(__FreeBSD__)
966 	u8 tid;
967 #endif
968 	u8 sub_frame_idx = desc->amsdu_info &
969 			   IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK;
970 	struct iwl_mvm_reorder_buf_entry *entries;
971 	u32 sta_mask;
972 	int index;
973 	u16 nssn, sn;
974 	u8 baid;
975 
976 	baid = (reorder & IWL_RX_MPDU_REORDER_BAID_MASK) >>
977 		IWL_RX_MPDU_REORDER_BAID_SHIFT;
978 
979 	/*
980 	 * This also covers the case of receiving a Block Ack Request
981 	 * outside a BA session; we'll pass it to mac80211 and that
982 	 * then sends a delBA action frame.
983 	 * This also covers pure monitor mode, in which case we won't
984 	 * have any BA sessions.
985 	 */
986 	if (baid == IWL_RX_REORDER_DATA_INVALID_BAID)
987 		return false;
988 
989 	/* no sta yet */
990 	if (WARN_ONCE(IS_ERR_OR_NULL(sta),
991 		      "Got valid BAID without a valid station assigned\n"))
992 		return false;
993 
994 	/* not a data packet or a bar */
995 	if (!ieee80211_is_back_req(hdr->frame_control) &&
996 	    (!ieee80211_is_data_qos(hdr->frame_control) ||
997 	     is_multicast_ether_addr(hdr->addr1)))
998 		return false;
999 
1000 	if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
1001 		return false;
1002 
1003 	baid_data = rcu_dereference(mvm->baid_map[baid]);
1004 	if (!baid_data) {
1005 		IWL_DEBUG_RX(mvm,
1006 			     "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n",
1007 			      baid, reorder);
1008 		return false;
1009 	}
1010 
1011 #if defined(__FreeBSD__)
1012 	tid = ieee80211_get_tid(hdr);
1013 #endif
1014 	rcu_read_lock();
1015 	sta_mask = iwl_mvm_sta_fw_id_mask(mvm, sta, -1);
1016 	rcu_read_unlock();
1017 
1018 	if (IWL_FW_CHECK(mvm,
1019 			 tid != baid_data->tid ||
1020 			 !(sta_mask & baid_data->sta_mask),
1021 			 "baid 0x%x is mapped to sta_mask:0x%x tid:%d, but was received for sta_mask:0x%x tid:%d\n",
1022 			 baid, baid_data->sta_mask, baid_data->tid,
1023 			 sta_mask, tid))
1024 		return false;
1025 
1026 	nssn = reorder & IWL_RX_MPDU_REORDER_NSSN_MASK;
1027 	sn = (reorder & IWL_RX_MPDU_REORDER_SN_MASK) >>
1028 		IWL_RX_MPDU_REORDER_SN_SHIFT;
1029 
1030 	buffer = &baid_data->reorder_buf[queue];
1031 	entries = &baid_data->entries[queue * baid_data->entries_per_queue];
1032 
1033 	spin_lock_bh(&buffer->lock);
1034 
1035 	if (!buffer->valid) {
1036 		if (reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN) {
1037 			spin_unlock_bh(&buffer->lock);
1038 			return false;
1039 		}
1040 		buffer->valid = true;
1041 	}
1042 
1043 	if (ieee80211_is_back_req(hdr->frame_control)) {
1044 		iwl_mvm_release_frames(mvm, sta, napi, baid_data,
1045 				       buffer, nssn, 0);
1046 		goto drop;
1047 	}
1048 
1049 	/*
1050 	 * If there was a significant jump in the nssn - adjust.
1051 	 * If the SN is smaller than the NSSN it might need to first go into
1052 	 * the reorder buffer, in which case we just release up to it and the
1053 	 * rest of the function will take care of storing it and releasing up to
1054 	 * the nssn.
1055 	 * This should not happen. This queue has been lagging and it should
1056 	 * have been updated by a IWL_MVM_RXQ_NSSN_SYNC notification. Be nice
1057 	 * and update the other queues.
1058 	 */
1059 	if (!iwl_mvm_is_sn_less(nssn, buffer->head_sn + buffer->buf_size,
1060 				buffer->buf_size) ||
1061 	    !ieee80211_sn_less(sn, buffer->head_sn + buffer->buf_size)) {
1062 		u16 min_sn = ieee80211_sn_less(sn, nssn) ? sn : nssn;
1063 
1064 		iwl_mvm_release_frames(mvm, sta, napi, baid_data, buffer,
1065 				       min_sn, IWL_MVM_RELEASE_SEND_RSS_SYNC);
1066 	}
1067 
1068 	iwl_mvm_oldsn_workaround(mvm, sta, tid, buffer, reorder,
1069 				 rx_status->device_timestamp, queue);
1070 
1071 	/* drop any oudated packets */
1072 	if (ieee80211_sn_less(sn, buffer->head_sn))
1073 		goto drop;
1074 
1075 	/* release immediately if allowed by nssn and no stored frames */
1076 	if (!buffer->num_stored && ieee80211_sn_less(sn, nssn)) {
1077 		if (iwl_mvm_is_sn_less(buffer->head_sn, nssn,
1078 				       buffer->buf_size) &&
1079 		   (!amsdu || last_subframe)) {
1080 			/*
1081 			 * If we crossed the 2048 or 0 SN, notify all the
1082 			 * queues. This is done in order to avoid having a
1083 			 * head_sn that lags behind for too long. When that
1084 			 * happens, we can get to a situation where the head_sn
1085 			 * is within the interval [nssn - buf_size : nssn]
1086 			 * which will make us think that the nssn is a packet
1087 			 * that we already freed because of the reordering
1088 			 * buffer and we will ignore it. So maintain the
1089 			 * head_sn somewhat updated across all the queues:
1090 			 * when it crosses 0 and 2048.
1091 			 */
1092 			if (sn == 2048 || sn == 0)
1093 				iwl_mvm_sync_nssn(mvm, baid, sn);
1094 			buffer->head_sn = nssn;
1095 		}
1096 		/* No need to update AMSDU last SN - we are moving the head */
1097 		spin_unlock_bh(&buffer->lock);
1098 		return false;
1099 	}
1100 
1101 	/*
1102 	 * release immediately if there are no stored frames, and the sn is
1103 	 * equal to the head.
1104 	 * This can happen due to reorder timer, where NSSN is behind head_sn.
1105 	 * When we released everything, and we got the next frame in the
1106 	 * sequence, according to the NSSN we can't release immediately,
1107 	 * while technically there is no hole and we can move forward.
1108 	 */
1109 	if (!buffer->num_stored && sn == buffer->head_sn) {
1110 		if (!amsdu || last_subframe) {
1111 			if (sn == 2048 || sn == 0)
1112 				iwl_mvm_sync_nssn(mvm, baid, sn);
1113 			buffer->head_sn = ieee80211_sn_inc(buffer->head_sn);
1114 		}
1115 		/* No need to update AMSDU last SN - we are moving the head */
1116 		spin_unlock_bh(&buffer->lock);
1117 		return false;
1118 	}
1119 
1120 	index = sn % buffer->buf_size;
1121 
1122 	/*
1123 	 * Check if we already stored this frame
1124 	 * As AMSDU is either received or not as whole, logic is simple:
1125 	 * If we have frames in that position in the buffer and the last frame
1126 	 * originated from AMSDU had a different SN then it is a retransmission.
1127 	 * If it is the same SN then if the subframe index is incrementing it
1128 	 * is the same AMSDU - otherwise it is a retransmission.
1129 	 */
1130 	tail = skb_peek_tail(&entries[index].e.frames);
1131 	if (tail && !amsdu)
1132 		goto drop;
1133 	else if (tail && (sn != buffer->last_amsdu ||
1134 			  buffer->last_sub_index >= sub_frame_idx))
1135 		goto drop;
1136 
1137 	/* put in reorder buffer */
1138 	__skb_queue_tail(&entries[index].e.frames, skb);
1139 	buffer->num_stored++;
1140 	entries[index].e.reorder_time = jiffies;
1141 
1142 	if (amsdu) {
1143 		buffer->last_amsdu = sn;
1144 		buffer->last_sub_index = sub_frame_idx;
1145 	}
1146 
1147 	/*
1148 	 * We cannot trust NSSN for AMSDU sub-frames that are not the last.
1149 	 * The reason is that NSSN advances on the first sub-frame, and may
1150 	 * cause the reorder buffer to advance before all the sub-frames arrive.
1151 	 * Example: reorder buffer contains SN 0 & 2, and we receive AMSDU with
1152 	 * SN 1. NSSN for first sub frame will be 3 with the result of driver
1153 	 * releasing SN 0,1, 2. When sub-frame 1 arrives - reorder buffer is
1154 	 * already ahead and it will be dropped.
1155 	 * If the last sub-frame is not on this queue - we will get frame
1156 	 * release notification with up to date NSSN.
1157 	 */
1158 	if (!amsdu || last_subframe)
1159 		iwl_mvm_release_frames(mvm, sta, napi, baid_data,
1160 				       buffer, nssn,
1161 				       IWL_MVM_RELEASE_SEND_RSS_SYNC);
1162 
1163 	spin_unlock_bh(&buffer->lock);
1164 	return true;
1165 
1166 drop:
1167 	kfree_skb(skb);
1168 	spin_unlock_bh(&buffer->lock);
1169 	return true;
1170 }
1171 
1172 static void iwl_mvm_agg_rx_received(struct iwl_mvm *mvm,
1173 				    u32 reorder_data, u8 baid)
1174 {
1175 	unsigned long now = jiffies;
1176 	unsigned long timeout;
1177 	struct iwl_mvm_baid_data *data;
1178 
1179 	rcu_read_lock();
1180 
1181 	data = rcu_dereference(mvm->baid_map[baid]);
1182 	if (!data) {
1183 		IWL_DEBUG_RX(mvm,
1184 			     "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n",
1185 			      baid, reorder_data);
1186 		goto out;
1187 	}
1188 
1189 	if (!data->timeout)
1190 		goto out;
1191 
1192 	timeout = data->timeout;
1193 	/*
1194 	 * Do not update last rx all the time to avoid cache bouncing
1195 	 * between the rx queues.
1196 	 * Update it every timeout. Worst case is the session will
1197 	 * expire after ~ 2 * timeout, which doesn't matter that much.
1198 	 */
1199 	if (time_before(data->last_rx + TU_TO_JIFFIES(timeout), now))
1200 		/* Update is atomic */
1201 		data->last_rx = now;
1202 
1203 out:
1204 	rcu_read_unlock();
1205 }
1206 
1207 static void iwl_mvm_flip_address(u8 *addr)
1208 {
1209 	int i;
1210 	u8 mac_addr[ETH_ALEN];
1211 
1212 	for (i = 0; i < ETH_ALEN; i++)
1213 		mac_addr[i] = addr[ETH_ALEN - i - 1];
1214 	ether_addr_copy(addr, mac_addr);
1215 }
1216 
1217 struct iwl_mvm_rx_phy_data {
1218 	enum iwl_rx_phy_info_type info_type;
1219 	__le32 d0, d1, d2, d3, eht_d4, d5;
1220 	__le16 d4;
1221 	bool with_data;
1222 	bool first_subframe;
1223 	__le32 rx_vec[4];
1224 
1225 	u32 rate_n_flags;
1226 	u32 gp2_on_air_rise;
1227 	u16 phy_info;
1228 	u8 energy_a, energy_b;
1229 	u8 channel;
1230 };
1231 
1232 static void iwl_mvm_decode_he_mu_ext(struct iwl_mvm *mvm,
1233 				     struct iwl_mvm_rx_phy_data *phy_data,
1234 				     struct ieee80211_radiotap_he_mu *he_mu)
1235 {
1236 	u32 phy_data2 = le32_to_cpu(phy_data->d2);
1237 	u32 phy_data3 = le32_to_cpu(phy_data->d3);
1238 	u16 phy_data4 = le16_to_cpu(phy_data->d4);
1239 	u32 rate_n_flags = phy_data->rate_n_flags;
1240 
1241 	if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CRC_OK, phy_data4)) {
1242 		he_mu->flags1 |=
1243 			cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_RU_KNOWN |
1244 				    IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU_KNOWN);
1245 
1246 		he_mu->flags1 |=
1247 			le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CTR_RU,
1248 						   phy_data4),
1249 					 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU);
1250 
1251 		he_mu->ru_ch1[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU0,
1252 					     phy_data2);
1253 		he_mu->ru_ch1[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU1,
1254 					     phy_data3);
1255 		he_mu->ru_ch1[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU2,
1256 					     phy_data2);
1257 		he_mu->ru_ch1[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU3,
1258 					     phy_data3);
1259 	}
1260 
1261 	if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CRC_OK, phy_data4) &&
1262 	    (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK_V1) != RATE_MCS_CHAN_WIDTH_20) {
1263 		he_mu->flags1 |=
1264 			cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_RU_KNOWN |
1265 				    IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_CTR_26T_RU_KNOWN);
1266 
1267 		he_mu->flags2 |=
1268 			le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CTR_RU,
1269 						   phy_data4),
1270 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_CH2_CTR_26T_RU);
1271 
1272 		he_mu->ru_ch2[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU0,
1273 					     phy_data2);
1274 		he_mu->ru_ch2[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU1,
1275 					     phy_data3);
1276 		he_mu->ru_ch2[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU2,
1277 					     phy_data2);
1278 		he_mu->ru_ch2[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU3,
1279 					     phy_data3);
1280 	}
1281 }
1282 
1283 static void
1284 iwl_mvm_decode_he_phy_ru_alloc(struct iwl_mvm_rx_phy_data *phy_data,
1285 			       struct ieee80211_radiotap_he *he,
1286 			       struct ieee80211_radiotap_he_mu *he_mu,
1287 			       struct ieee80211_rx_status *rx_status)
1288 {
1289 	/*
1290 	 * Unfortunately, we have to leave the mac80211 data
1291 	 * incorrect for the case that we receive an HE-MU
1292 	 * transmission and *don't* have the HE phy data (due
1293 	 * to the bits being used for TSF). This shouldn't
1294 	 * happen though as management frames where we need
1295 	 * the TSF/timers are not be transmitted in HE-MU.
1296 	 */
1297 	u8 ru = le32_get_bits(phy_data->d1, IWL_RX_PHY_DATA1_HE_RU_ALLOC_MASK);
1298 	u32 rate_n_flags = phy_data->rate_n_flags;
1299 	u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK_V1;
1300 	u8 offs = 0;
1301 
1302 	rx_status->bw = RATE_INFO_BW_HE_RU;
1303 
1304 	he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN);
1305 
1306 	switch (ru) {
1307 	case 0 ... 36:
1308 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_26;
1309 		offs = ru;
1310 		break;
1311 	case 37 ... 52:
1312 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_52;
1313 		offs = ru - 37;
1314 		break;
1315 	case 53 ... 60:
1316 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106;
1317 		offs = ru - 53;
1318 		break;
1319 	case 61 ... 64:
1320 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_242;
1321 		offs = ru - 61;
1322 		break;
1323 	case 65 ... 66:
1324 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_484;
1325 		offs = ru - 65;
1326 		break;
1327 	case 67:
1328 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_996;
1329 		break;
1330 	case 68:
1331 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_2x996;
1332 		break;
1333 	}
1334 	he->data2 |= le16_encode_bits(offs,
1335 				      IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET);
1336 	he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_KNOWN |
1337 				 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET_KNOWN);
1338 	if (phy_data->d1 & cpu_to_le32(IWL_RX_PHY_DATA1_HE_RU_ALLOC_SEC80))
1339 		he->data2 |=
1340 			cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_SEC);
1341 
1342 #define CHECK_BW(bw) \
1343 	BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_ ## bw ## MHZ != \
1344 		     RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS); \
1345 	BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_ ## bw ## MHZ != \
1346 		     RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS)
1347 	CHECK_BW(20);
1348 	CHECK_BW(40);
1349 	CHECK_BW(80);
1350 	CHECK_BW(160);
1351 
1352 	if (he_mu)
1353 		he_mu->flags2 |=
1354 			le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK_V1,
1355 						   rate_n_flags),
1356 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW);
1357 	else if (he_type == RATE_MCS_HE_TYPE_TRIG_V1)
1358 		he->data6 |=
1359 			cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_KNOWN) |
1360 			le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK_V1,
1361 						   rate_n_flags),
1362 					 IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW);
1363 }
1364 
1365 static void iwl_mvm_decode_he_phy_data(struct iwl_mvm *mvm,
1366 				       struct iwl_mvm_rx_phy_data *phy_data,
1367 				       struct ieee80211_radiotap_he *he,
1368 				       struct ieee80211_radiotap_he_mu *he_mu,
1369 				       struct ieee80211_rx_status *rx_status,
1370 				       int queue)
1371 {
1372 	switch (phy_data->info_type) {
1373 	case IWL_RX_PHY_INFO_TYPE_NONE:
1374 	case IWL_RX_PHY_INFO_TYPE_CCK:
1375 	case IWL_RX_PHY_INFO_TYPE_OFDM_LGCY:
1376 	case IWL_RX_PHY_INFO_TYPE_HT:
1377 	case IWL_RX_PHY_INFO_TYPE_VHT_SU:
1378 	case IWL_RX_PHY_INFO_TYPE_VHT_MU:
1379 	case IWL_RX_PHY_INFO_TYPE_EHT_MU:
1380 	case IWL_RX_PHY_INFO_TYPE_EHT_TB:
1381 	case IWL_RX_PHY_INFO_TYPE_EHT_MU_EXT:
1382 	case IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT:
1383 		return;
1384 	case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT:
1385 		he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN |
1386 					 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE2_KNOWN |
1387 					 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE3_KNOWN |
1388 					 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE4_KNOWN);
1389 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1390 							    IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE1),
1391 					      IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE1);
1392 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1393 							    IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE2),
1394 					      IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE2);
1395 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1396 							    IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE3),
1397 					      IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE3);
1398 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1399 							    IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE4),
1400 					      IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE4);
1401 		fallthrough;
1402 	case IWL_RX_PHY_INFO_TYPE_HE_SU:
1403 	case IWL_RX_PHY_INFO_TYPE_HE_MU:
1404 	case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
1405 	case IWL_RX_PHY_INFO_TYPE_HE_TB:
1406 		/* HE common */
1407 		he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_LDPC_XSYMSEG_KNOWN |
1408 					 IEEE80211_RADIOTAP_HE_DATA1_DOPPLER_KNOWN |
1409 					 IEEE80211_RADIOTAP_HE_DATA1_BSS_COLOR_KNOWN);
1410 		he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRE_FEC_PAD_KNOWN |
1411 					 IEEE80211_RADIOTAP_HE_DATA2_PE_DISAMBIG_KNOWN |
1412 					 IEEE80211_RADIOTAP_HE_DATA2_TXOP_KNOWN |
1413 					 IEEE80211_RADIOTAP_HE_DATA2_NUM_LTF_SYMS_KNOWN);
1414 		he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1415 							    IWL_RX_PHY_DATA0_HE_BSS_COLOR_MASK),
1416 					      IEEE80211_RADIOTAP_HE_DATA3_BSS_COLOR);
1417 		if (phy_data->info_type != IWL_RX_PHY_INFO_TYPE_HE_TB &&
1418 		    phy_data->info_type != IWL_RX_PHY_INFO_TYPE_HE_TB_EXT) {
1419 			he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_UL_DL_KNOWN);
1420 			he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1421 							    IWL_RX_PHY_DATA0_HE_UPLINK),
1422 						      IEEE80211_RADIOTAP_HE_DATA3_UL_DL);
1423 		}
1424 		he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1425 							    IWL_RX_PHY_DATA0_HE_LDPC_EXT_SYM),
1426 					      IEEE80211_RADIOTAP_HE_DATA3_LDPC_XSYMSEG);
1427 		he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1428 							    IWL_RX_PHY_DATA0_HE_PRE_FEC_PAD_MASK),
1429 					      IEEE80211_RADIOTAP_HE_DATA5_PRE_FEC_PAD);
1430 		he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1431 							    IWL_RX_PHY_DATA0_HE_PE_DISAMBIG),
1432 					      IEEE80211_RADIOTAP_HE_DATA5_PE_DISAMBIG);
1433 		he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d1,
1434 							    IWL_RX_PHY_DATA1_HE_LTF_NUM_MASK),
1435 					      IEEE80211_RADIOTAP_HE_DATA5_NUM_LTF_SYMS);
1436 		he->data6 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1437 							    IWL_RX_PHY_DATA0_HE_TXOP_DUR_MASK),
1438 					      IEEE80211_RADIOTAP_HE_DATA6_TXOP);
1439 		he->data6 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1440 							    IWL_RX_PHY_DATA0_HE_DOPPLER),
1441 					      IEEE80211_RADIOTAP_HE_DATA6_DOPPLER);
1442 		break;
1443 	}
1444 
1445 	switch (phy_data->info_type) {
1446 	case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
1447 	case IWL_RX_PHY_INFO_TYPE_HE_MU:
1448 	case IWL_RX_PHY_INFO_TYPE_HE_SU:
1449 		he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN);
1450 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1451 							    IWL_RX_PHY_DATA0_HE_SPATIAL_REUSE_MASK),
1452 					      IEEE80211_RADIOTAP_HE_DATA4_SU_MU_SPTL_REUSE);
1453 		break;
1454 	default:
1455 		/* nothing here */
1456 		break;
1457 	}
1458 
1459 	switch (phy_data->info_type) {
1460 	case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
1461 		he_mu->flags1 |=
1462 			le16_encode_bits(le16_get_bits(phy_data->d4,
1463 						       IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_DCM),
1464 					 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM);
1465 		he_mu->flags1 |=
1466 			le16_encode_bits(le16_get_bits(phy_data->d4,
1467 						       IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_MCS_MASK),
1468 					 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS);
1469 		he_mu->flags2 |=
1470 			le16_encode_bits(le16_get_bits(phy_data->d4,
1471 						       IWL_RX_PHY_DATA4_HE_MU_EXT_PREAMBLE_PUNC_TYPE_MASK),
1472 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW);
1473 		iwl_mvm_decode_he_mu_ext(mvm, phy_data, he_mu);
1474 		fallthrough;
1475 	case IWL_RX_PHY_INFO_TYPE_HE_MU:
1476 		he_mu->flags2 |=
1477 			le16_encode_bits(le32_get_bits(phy_data->d1,
1478 						       IWL_RX_PHY_DATA1_HE_MU_SIBG_SYM_OR_USER_NUM_MASK),
1479 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_SYMS_USERS);
1480 		he_mu->flags2 |=
1481 			le16_encode_bits(le32_get_bits(phy_data->d1,
1482 						       IWL_RX_PHY_DATA1_HE_MU_SIGB_COMPRESSION),
1483 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_COMP);
1484 		fallthrough;
1485 	case IWL_RX_PHY_INFO_TYPE_HE_TB:
1486 	case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT:
1487 		iwl_mvm_decode_he_phy_ru_alloc(phy_data, he, he_mu, rx_status);
1488 		break;
1489 	case IWL_RX_PHY_INFO_TYPE_HE_SU:
1490 		he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BEAM_CHANGE_KNOWN);
1491 		he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1492 							    IWL_RX_PHY_DATA0_HE_BEAM_CHNG),
1493 					      IEEE80211_RADIOTAP_HE_DATA3_BEAM_CHANGE);
1494 		break;
1495 	default:
1496 		/* nothing */
1497 		break;
1498 	}
1499 }
1500 
1501 #define LE32_DEC_ENC(value, dec_bits, enc_bits) \
1502 	le32_encode_bits(le32_get_bits(value, dec_bits), enc_bits)
1503 
1504 #define IWL_MVM_ENC_USIG_VALUE_MASK(usig, in_value, dec_bits, enc_bits) do { \
1505 	typeof(enc_bits) _enc_bits = enc_bits; \
1506 	typeof(usig) _usig = usig; \
1507 	(_usig)->mask |= cpu_to_le32(_enc_bits); \
1508 	(_usig)->value |= LE32_DEC_ENC(in_value, dec_bits, _enc_bits); \
1509 } while (0)
1510 
1511 #define __IWL_MVM_ENC_EHT_RU(rt_data, rt_ru, fw_data, fw_ru) \
1512 	eht->data[(rt_data)] |= \
1513 		(cpu_to_le32 \
1514 		 (IEEE80211_RADIOTAP_EHT_DATA ## rt_data ## _RU_ALLOC_CC_ ## rt_ru ## _KNOWN) | \
1515 		 LE32_DEC_ENC(data ## fw_data, \
1516 			      IWL_RX_PHY_DATA ## fw_data ## _EHT_MU_EXT_RU_ALLOC_ ## fw_ru, \
1517 			      IEEE80211_RADIOTAP_EHT_DATA ## rt_data ## _RU_ALLOC_CC_ ## rt_ru))
1518 
1519 #define _IWL_MVM_ENC_EHT_RU(rt_data, rt_ru, fw_data, fw_ru)	\
1520 	__IWL_MVM_ENC_EHT_RU(rt_data, rt_ru, fw_data, fw_ru)
1521 
1522 #define IEEE80211_RADIOTAP_RU_DATA_1_1_1	1
1523 #define IEEE80211_RADIOTAP_RU_DATA_2_1_1	2
1524 #define IEEE80211_RADIOTAP_RU_DATA_1_1_2	2
1525 #define IEEE80211_RADIOTAP_RU_DATA_2_1_2	2
1526 #define IEEE80211_RADIOTAP_RU_DATA_1_2_1	3
1527 #define IEEE80211_RADIOTAP_RU_DATA_2_2_1	3
1528 #define IEEE80211_RADIOTAP_RU_DATA_1_2_2	3
1529 #define IEEE80211_RADIOTAP_RU_DATA_2_2_2	4
1530 
1531 #define IWL_RX_RU_DATA_A1			2
1532 #define IWL_RX_RU_DATA_A2			2
1533 #define IWL_RX_RU_DATA_B1			2
1534 #define IWL_RX_RU_DATA_B2			3
1535 #define IWL_RX_RU_DATA_C1			3
1536 #define IWL_RX_RU_DATA_C2			3
1537 #define IWL_RX_RU_DATA_D1			4
1538 #define IWL_RX_RU_DATA_D2			4
1539 
1540 #define IWL_MVM_ENC_EHT_RU(rt_ru, fw_ru)				\
1541 	_IWL_MVM_ENC_EHT_RU(IEEE80211_RADIOTAP_RU_DATA_ ## rt_ru,	\
1542 			    rt_ru,					\
1543 			    IWL_RX_RU_DATA_ ## fw_ru,			\
1544 			    fw_ru)
1545 
1546 static void iwl_mvm_decode_eht_ext_mu(struct iwl_mvm *mvm,
1547 				      struct iwl_mvm_rx_phy_data *phy_data,
1548 				      struct ieee80211_rx_status *rx_status,
1549 				      struct ieee80211_radiotap_eht *eht,
1550 				      struct ieee80211_radiotap_eht_usig *usig)
1551 {
1552 	if (phy_data->with_data) {
1553 		__le32 data1 = phy_data->d1;
1554 		__le32 data2 = phy_data->d2;
1555 		__le32 data3 = phy_data->d3;
1556 		__le32 data4 = phy_data->eht_d4;
1557 		__le32 data5 = phy_data->d5;
1558 		u32 phy_bw = phy_data->rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK;
1559 
1560 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5,
1561 					    IWL_RX_PHY_DATA5_EHT_TYPE_AND_COMP,
1562 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B0_B1_PPDU_TYPE);
1563 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5,
1564 					    IWL_RX_PHY_DATA5_EHT_MU_PUNC_CH_CODE,
1565 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B3_B7_PUNCTURED_INFO);
1566 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, data4,
1567 					    IWL_RX_PHY_DATA4_EHT_MU_EXT_SIGB_MCS,
1568 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B9_B10_SIG_MCS);
1569 		IWL_MVM_ENC_USIG_VALUE_MASK
1570 			(usig, data1, IWL_RX_PHY_DATA1_EHT_MU_NUM_SIG_SYM_USIGA2,
1571 			 IEEE80211_RADIOTAP_EHT_USIG2_MU_B11_B15_EHT_SIG_SYMBOLS);
1572 
1573 		eht->user_info[0] |=
1574 			cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_STA_ID_KNOWN) |
1575 			LE32_DEC_ENC(data5, IWL_RX_PHY_DATA5_EHT_MU_STA_ID_USR,
1576 				     IEEE80211_RADIOTAP_EHT_USER_INFO_STA_ID);
1577 
1578 		eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_NR_NON_OFDMA_USERS_M);
1579 		eht->data[7] |= LE32_DEC_ENC
1580 			(data5, IWL_RX_PHY_DATA5_EHT_MU_NUM_USR_NON_OFDMA,
1581 			 IEEE80211_RADIOTAP_EHT_DATA7_NUM_OF_NON_OFDMA_USERS);
1582 
1583 		/*
1584 		 * Hardware labels the content channels/RU allocation values
1585 		 * as follows:
1586 		 *           Content Channel 1		Content Channel 2
1587 		 *   20 MHz: A1
1588 		 *   40 MHz: A1				B1
1589 		 *   80 MHz: A1 C1			B1 D1
1590 		 *  160 MHz: A1 C1 A2 C2		B1 D1 B2 D2
1591 		 *  320 MHz: A1 C1 A2 C2 A3 C3 A4 C4	B1 D1 B2 D2 B3 D3 B4 D4
1592 		 *
1593 		 * However firmware can only give us A1-D2, so the higher
1594 		 * frequencies are missing.
1595 		 */
1596 
1597 		switch (phy_bw) {
1598 		case RATE_MCS_CHAN_WIDTH_320:
1599 			/* additional values are missing in RX metadata */
1600 		case RATE_MCS_CHAN_WIDTH_160:
1601 			/* content channel 1 */
1602 			IWL_MVM_ENC_EHT_RU(1_2_1, A2);
1603 			IWL_MVM_ENC_EHT_RU(1_2_2, C2);
1604 			/* content channel 2 */
1605 			IWL_MVM_ENC_EHT_RU(2_2_1, B2);
1606 			IWL_MVM_ENC_EHT_RU(2_2_2, D2);
1607 			fallthrough;
1608 		case RATE_MCS_CHAN_WIDTH_80:
1609 			/* content channel 1 */
1610 			IWL_MVM_ENC_EHT_RU(1_1_2, C1);
1611 			/* content channel 2 */
1612 			IWL_MVM_ENC_EHT_RU(2_1_2, D1);
1613 			fallthrough;
1614 		case RATE_MCS_CHAN_WIDTH_40:
1615 			/* content channel 2 */
1616 			IWL_MVM_ENC_EHT_RU(2_1_1, B1);
1617 			fallthrough;
1618 		case RATE_MCS_CHAN_WIDTH_20:
1619 			IWL_MVM_ENC_EHT_RU(1_1_1, A1);
1620 			break;
1621 		}
1622 	} else {
1623 		__le32 usig_a1 = phy_data->rx_vec[0];
1624 		__le32 usig_a2 = phy_data->rx_vec[1];
1625 
1626 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a1,
1627 					    IWL_RX_USIG_A1_DISREGARD,
1628 					    IEEE80211_RADIOTAP_EHT_USIG1_MU_B20_B24_DISREGARD);
1629 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a1,
1630 					    IWL_RX_USIG_A1_VALIDATE,
1631 					    IEEE80211_RADIOTAP_EHT_USIG1_MU_B25_VALIDATE);
1632 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1633 					    IWL_RX_USIG_A2_EHT_PPDU_TYPE,
1634 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B0_B1_PPDU_TYPE);
1635 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1636 					    IWL_RX_USIG_A2_EHT_USIG2_VALIDATE_B2,
1637 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B2_VALIDATE);
1638 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1639 					    IWL_RX_USIG_A2_EHT_PUNC_CHANNEL,
1640 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B3_B7_PUNCTURED_INFO);
1641 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1642 					    IWL_RX_USIG_A2_EHT_USIG2_VALIDATE_B8,
1643 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B8_VALIDATE);
1644 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1645 					    IWL_RX_USIG_A2_EHT_SIG_MCS,
1646 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B9_B10_SIG_MCS);
1647 		IWL_MVM_ENC_USIG_VALUE_MASK
1648 			(usig, usig_a2, IWL_RX_USIG_A2_EHT_SIG_SYM_NUM,
1649 			 IEEE80211_RADIOTAP_EHT_USIG2_MU_B11_B15_EHT_SIG_SYMBOLS);
1650 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1651 					    IWL_RX_USIG_A2_EHT_CRC_OK,
1652 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B16_B19_CRC);
1653 	}
1654 }
1655 
1656 static void iwl_mvm_decode_eht_ext_tb(struct iwl_mvm *mvm,
1657 				      struct iwl_mvm_rx_phy_data *phy_data,
1658 				      struct ieee80211_rx_status *rx_status,
1659 				      struct ieee80211_radiotap_eht *eht,
1660 				      struct ieee80211_radiotap_eht_usig *usig)
1661 {
1662 	if (phy_data->with_data) {
1663 		__le32 data5 = phy_data->d5;
1664 
1665 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5,
1666 					    IWL_RX_PHY_DATA5_EHT_TYPE_AND_COMP,
1667 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B0_B1_PPDU_TYPE);
1668 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5,
1669 					    IWL_RX_PHY_DATA5_EHT_TB_SPATIAL_REUSE1,
1670 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B3_B6_SPATIAL_REUSE_1);
1671 
1672 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5,
1673 					    IWL_RX_PHY_DATA5_EHT_TB_SPATIAL_REUSE2,
1674 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B7_B10_SPATIAL_REUSE_2);
1675 	} else {
1676 		__le32 usig_a1 = phy_data->rx_vec[0];
1677 		__le32 usig_a2 = phy_data->rx_vec[1];
1678 
1679 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a1,
1680 					    IWL_RX_USIG_A1_DISREGARD,
1681 					    IEEE80211_RADIOTAP_EHT_USIG1_TB_B20_B25_DISREGARD);
1682 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1683 					    IWL_RX_USIG_A2_EHT_PPDU_TYPE,
1684 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B0_B1_PPDU_TYPE);
1685 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1686 					    IWL_RX_USIG_A2_EHT_USIG2_VALIDATE_B2,
1687 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B2_VALIDATE);
1688 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1689 					    IWL_RX_USIG_A2_EHT_TRIG_SPATIAL_REUSE_1,
1690 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B3_B6_SPATIAL_REUSE_1);
1691 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1692 					    IWL_RX_USIG_A2_EHT_TRIG_SPATIAL_REUSE_2,
1693 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B7_B10_SPATIAL_REUSE_2);
1694 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1695 					    IWL_RX_USIG_A2_EHT_TRIG_USIG2_DISREGARD,
1696 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B11_B15_DISREGARD);
1697 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1698 					    IWL_RX_USIG_A2_EHT_CRC_OK,
1699 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B16_B19_CRC);
1700 	}
1701 }
1702 
1703 static void iwl_mvm_decode_eht_ru(struct iwl_mvm *mvm,
1704 				  struct ieee80211_rx_status *rx_status,
1705 				  struct ieee80211_radiotap_eht *eht)
1706 {
1707 	u32 ru = le32_get_bits(eht->data[8],
1708 			       IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_B7_B1);
1709 	enum nl80211_eht_ru_alloc nl_ru;
1710 
1711 	/* Using D1.5 Table 9-53a - Encoding of PS160 and RU Allocation subfields
1712 	 * in an EHT variant User Info field
1713 	 */
1714 
1715 	switch (ru) {
1716 	case 0 ... 36:
1717 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_26;
1718 		break;
1719 	case 37 ... 52:
1720 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_52;
1721 		break;
1722 	case 53 ... 60:
1723 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_106;
1724 		break;
1725 	case 61 ... 64:
1726 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_242;
1727 		break;
1728 	case 65 ... 66:
1729 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_484;
1730 		break;
1731 	case 67:
1732 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_996;
1733 		break;
1734 	case 68:
1735 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_2x996;
1736 		break;
1737 	case 69:
1738 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_4x996;
1739 		break;
1740 	case 70 ... 81:
1741 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_52P26;
1742 		break;
1743 	case 82 ... 89:
1744 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_106P26;
1745 		break;
1746 	case 90 ... 93:
1747 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_484P242;
1748 		break;
1749 	case 94 ... 95:
1750 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_996P484;
1751 		break;
1752 	case 96 ... 99:
1753 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_996P484P242;
1754 		break;
1755 	case 100 ... 103:
1756 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_2x996P484;
1757 		break;
1758 	case 104:
1759 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_3x996;
1760 		break;
1761 	case 105 ... 106:
1762 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_3x996P484;
1763 		break;
1764 	default:
1765 		return;
1766 	}
1767 
1768 	rx_status->bw = RATE_INFO_BW_EHT_RU;
1769 	rx_status->eht.ru = nl_ru;
1770 }
1771 
1772 static void iwl_mvm_decode_eht_phy_data(struct iwl_mvm *mvm,
1773 					struct iwl_mvm_rx_phy_data *phy_data,
1774 					struct ieee80211_rx_status *rx_status,
1775 					struct ieee80211_radiotap_eht *eht,
1776 					struct ieee80211_radiotap_eht_usig *usig)
1777 
1778 {
1779 	__le32 data0 = phy_data->d0;
1780 	__le32 data1 = phy_data->d1;
1781 	__le32 usig_a1 = phy_data->rx_vec[0];
1782 	u8 info_type = phy_data->info_type;
1783 
1784 	/* Not in EHT range */
1785 	if (info_type < IWL_RX_PHY_INFO_TYPE_EHT_MU ||
1786 	    info_type > IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT)
1787 		return;
1788 
1789 	usig->common |= cpu_to_le32
1790 		(IEEE80211_RADIOTAP_EHT_USIG_COMMON_UL_DL_KNOWN |
1791 		 IEEE80211_RADIOTAP_EHT_USIG_COMMON_BSS_COLOR_KNOWN);
1792 	if (phy_data->with_data) {
1793 		usig->common |= LE32_DEC_ENC(data0,
1794 					     IWL_RX_PHY_DATA0_EHT_UPLINK,
1795 					     IEEE80211_RADIOTAP_EHT_USIG_COMMON_UL_DL);
1796 		usig->common |= LE32_DEC_ENC(data0,
1797 					     IWL_RX_PHY_DATA0_EHT_BSS_COLOR_MASK,
1798 					     IEEE80211_RADIOTAP_EHT_USIG_COMMON_BSS_COLOR);
1799 	} else {
1800 		usig->common |= LE32_DEC_ENC(usig_a1,
1801 					     IWL_RX_USIG_A1_UL_FLAG,
1802 					     IEEE80211_RADIOTAP_EHT_USIG_COMMON_UL_DL);
1803 		usig->common |= LE32_DEC_ENC(usig_a1,
1804 					     IWL_RX_USIG_A1_BSS_COLOR,
1805 					     IEEE80211_RADIOTAP_EHT_USIG_COMMON_BSS_COLOR);
1806 	}
1807 
1808 	if (fw_has_capa(&mvm->fw->ucode_capa,
1809 			IWL_UCODE_TLV_CAPA_SNIFF_VALIDATE_SUPPORT)) {
1810 		usig->common |=
1811 			cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_VALIDATE_BITS_CHECKED);
1812 		usig->common |=
1813 			LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_VALIDATE,
1814 				     IEEE80211_RADIOTAP_EHT_USIG_COMMON_VALIDATE_BITS_OK);
1815 	}
1816 
1817 	eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_SPATIAL_REUSE);
1818 	eht->data[0] |= LE32_DEC_ENC(data0,
1819 				     IWL_RX_PHY_DATA0_ETH_SPATIAL_REUSE_MASK,
1820 				     IEEE80211_RADIOTAP_EHT_DATA0_SPATIAL_REUSE);
1821 
1822 	/* All RU allocating size/index is in TB format */
1823 	eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_RU_ALLOC_TB_FMT);
1824 	eht->data[8] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PS160,
1825 				     IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_PS_160);
1826 	eht->data[8] |= LE32_DEC_ENC(data1, IWL_RX_PHY_DATA1_EHT_RU_ALLOC_B0,
1827 				     IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_B0);
1828 	eht->data[8] |= LE32_DEC_ENC(data1, IWL_RX_PHY_DATA1_EHT_RU_ALLOC_B1_B7,
1829 				     IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_B7_B1);
1830 
1831 	iwl_mvm_decode_eht_ru(mvm, rx_status, eht);
1832 
1833 	/* We only get here in case of IWL_RX_MPDU_PHY_TSF_OVERLOAD is set
1834 	 * which is on only in case of monitor mode so no need to check monitor
1835 	 * mode
1836 	 */
1837 	eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_PRIMARY_80);
1838 	eht->data[1] |=
1839 		le32_encode_bits(mvm->monitor_p80,
1840 				 IEEE80211_RADIOTAP_EHT_DATA1_PRIMARY_80);
1841 
1842 	usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_TXOP_KNOWN);
1843 	if (phy_data->with_data)
1844 		usig->common |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_TXOP_DUR_MASK,
1845 					     IEEE80211_RADIOTAP_EHT_USIG_COMMON_TXOP);
1846 	else
1847 		usig->common |= LE32_DEC_ENC(usig_a1, IWL_RX_USIG_A1_TXOP_DURATION,
1848 					     IEEE80211_RADIOTAP_EHT_USIG_COMMON_TXOP);
1849 
1850 	eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_LDPC_EXTRA_SYM_OM);
1851 	eht->data[0] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_LDPC_EXT_SYM,
1852 				     IEEE80211_RADIOTAP_EHT_DATA0_LDPC_EXTRA_SYM_OM);
1853 
1854 	eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_PRE_PADD_FACOR_OM);
1855 	eht->data[0] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PRE_FEC_PAD_MASK,
1856 				    IEEE80211_RADIOTAP_EHT_DATA0_PRE_PADD_FACOR_OM);
1857 
1858 	eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_PE_DISAMBIGUITY_OM);
1859 	eht->data[0] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PE_DISAMBIG,
1860 				     IEEE80211_RADIOTAP_EHT_DATA0_PE_DISAMBIGUITY_OM);
1861 
1862 	/* TODO: what about IWL_RX_PHY_DATA0_EHT_BW320_SLOT */
1863 
1864 	if (!le32_get_bits(data0, IWL_RX_PHY_DATA0_EHT_SIGA_CRC_OK))
1865 		usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BAD_USIG_CRC);
1866 
1867 	usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_PHY_VER_KNOWN);
1868 	usig->common |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PHY_VER,
1869 				     IEEE80211_RADIOTAP_EHT_USIG_COMMON_PHY_VER);
1870 
1871 	/*
1872 	 * TODO: what about TB - IWL_RX_PHY_DATA1_EHT_TB_PILOT_TYPE,
1873 	 *			 IWL_RX_PHY_DATA1_EHT_TB_LOW_SS
1874 	 */
1875 
1876 	eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_EHT_LTF);
1877 	eht->data[0] |= LE32_DEC_ENC(data1, IWL_RX_PHY_DATA1_EHT_SIG_LTF_NUM,
1878 				     IEEE80211_RADIOTAP_EHT_DATA0_EHT_LTF);
1879 
1880 	if (info_type == IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT ||
1881 	    info_type == IWL_RX_PHY_INFO_TYPE_EHT_TB)
1882 		iwl_mvm_decode_eht_ext_tb(mvm, phy_data, rx_status, eht, usig);
1883 
1884 	if (info_type == IWL_RX_PHY_INFO_TYPE_EHT_MU_EXT ||
1885 	    info_type == IWL_RX_PHY_INFO_TYPE_EHT_MU)
1886 		iwl_mvm_decode_eht_ext_mu(mvm, phy_data, rx_status, eht, usig);
1887 }
1888 
1889 static void iwl_mvm_rx_eht(struct iwl_mvm *mvm, struct sk_buff *skb,
1890 			   struct iwl_mvm_rx_phy_data *phy_data,
1891 			   int queue)
1892 {
1893 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
1894 
1895 	struct ieee80211_radiotap_eht *eht;
1896 	struct ieee80211_radiotap_eht_usig *usig;
1897 	size_t eht_len = sizeof(*eht);
1898 
1899 	u32 rate_n_flags = phy_data->rate_n_flags;
1900 	u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK;
1901 	/* EHT and HE have the same valus for LTF */
1902 	u8 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN;
1903 	u16 phy_info = phy_data->phy_info;
1904 	u32 bw;
1905 
1906 	/* u32 for 1 user_info */
1907 	if (phy_data->with_data)
1908 		eht_len += sizeof(u32);
1909 
1910 	eht = iwl_mvm_radiotap_put_tlv(skb, IEEE80211_RADIOTAP_EHT, eht_len);
1911 
1912 	usig = iwl_mvm_radiotap_put_tlv(skb, IEEE80211_RADIOTAP_EHT_USIG,
1913 					sizeof(*usig));
1914 	rx_status->flag |= RX_FLAG_RADIOTAP_TLV_AT_END;
1915 	usig->common |=
1916 		cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BW_KNOWN);
1917 
1918 	/* specific handling for 320MHz */
1919 	bw = FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK, rate_n_flags);
1920 	if (bw == RATE_MCS_CHAN_WIDTH_320_VAL)
1921 		bw += FIELD_GET(IWL_RX_PHY_DATA0_EHT_BW320_SLOT,
1922 				le32_to_cpu(phy_data->d0));
1923 
1924 	usig->common |= cpu_to_le32
1925 		(FIELD_PREP(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BW, bw));
1926 
1927 	/* report the AMPDU-EOF bit on single frames */
1928 	if (!queue && !(phy_info & IWL_RX_MPDU_PHY_AMPDU)) {
1929 		rx_status->flag |= RX_FLAG_AMPDU_DETAILS;
1930 		rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN;
1931 		if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_EHT_DELIM_EOF))
1932 			rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT;
1933 	}
1934 
1935 	/* update aggregation data for monitor sake on default queue */
1936 	if (!queue && (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) &&
1937 	    (phy_info & IWL_RX_MPDU_PHY_AMPDU) && phy_data->first_subframe) {
1938 		rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN;
1939 		if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_EHT_DELIM_EOF))
1940 			rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT;
1941 	}
1942 
1943 	if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD)
1944 		iwl_mvm_decode_eht_phy_data(mvm, phy_data, rx_status, eht, usig);
1945 
1946 #define CHECK_TYPE(F)							\
1947 	BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_ ## F !=	\
1948 		     (RATE_MCS_HE_TYPE_ ## F >> RATE_MCS_HE_TYPE_POS))
1949 
1950 	CHECK_TYPE(SU);
1951 	CHECK_TYPE(EXT_SU);
1952 	CHECK_TYPE(MU);
1953 	CHECK_TYPE(TRIG);
1954 
1955 	switch (FIELD_GET(RATE_MCS_HE_GI_LTF_MSK, rate_n_flags)) {
1956 	case 0:
1957 		if (he_type == RATE_MCS_HE_TYPE_TRIG) {
1958 			rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_1_6;
1959 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X;
1960 		} else {
1961 			rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_0_8;
1962 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X;
1963 		}
1964 		break;
1965 	case 1:
1966 		rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_1_6;
1967 		ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X;
1968 		break;
1969 	case 2:
1970 		ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
1971 		if (he_type == RATE_MCS_HE_TYPE_TRIG)
1972 			rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_3_2;
1973 		else
1974 			rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_0_8;
1975 		break;
1976 	case 3:
1977 		if (he_type != RATE_MCS_HE_TYPE_TRIG) {
1978 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
1979 			rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_3_2;
1980 		}
1981 		break;
1982 	default:
1983 		/* nothing here */
1984 		break;
1985 	}
1986 
1987 	if (ltf != IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN) {
1988 		eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_GI);
1989 		eht->data[0] |= cpu_to_le32
1990 			(FIELD_PREP(IEEE80211_RADIOTAP_EHT_DATA0_LTF,
1991 				    ltf) |
1992 			 FIELD_PREP(IEEE80211_RADIOTAP_EHT_DATA0_GI,
1993 				    rx_status->eht.gi));
1994 	}
1995 
1996 
1997 	if (!phy_data->with_data) {
1998 		eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_NSS_S |
1999 					  IEEE80211_RADIOTAP_EHT_KNOWN_BEAMFORMED_S);
2000 		eht->data[7] |=
2001 			le32_encode_bits(le32_get_bits(phy_data->rx_vec[2],
2002 						       RX_NO_DATA_RX_VEC2_EHT_NSTS_MSK),
2003 					 IEEE80211_RADIOTAP_EHT_DATA7_NSS_S);
2004 		if (rate_n_flags & RATE_MCS_BF_MSK)
2005 			eht->data[7] |=
2006 				cpu_to_le32(IEEE80211_RADIOTAP_EHT_DATA7_BEAMFORMED_S);
2007 	} else {
2008 		eht->user_info[0] |=
2009 			cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_MCS_KNOWN |
2010 				    IEEE80211_RADIOTAP_EHT_USER_INFO_CODING_KNOWN |
2011 				    IEEE80211_RADIOTAP_EHT_USER_INFO_NSS_KNOWN_O |
2012 				    IEEE80211_RADIOTAP_EHT_USER_INFO_BEAMFORMING_KNOWN_O |
2013 				    IEEE80211_RADIOTAP_EHT_USER_INFO_DATA_FOR_USER);
2014 
2015 		if (rate_n_flags & RATE_MCS_BF_MSK)
2016 			eht->user_info[0] |=
2017 				cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_BEAMFORMING_O);
2018 
2019 		if (rate_n_flags & RATE_MCS_LDPC_MSK)
2020 			eht->user_info[0] |=
2021 				cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_CODING);
2022 
2023 		eht->user_info[0] |= cpu_to_le32
2024 			(FIELD_PREP(IEEE80211_RADIOTAP_EHT_USER_INFO_MCS,
2025 				    FIELD_GET(RATE_VHT_MCS_RATE_CODE_MSK,
2026 					      rate_n_flags)) |
2027 			 FIELD_PREP(IEEE80211_RADIOTAP_EHT_USER_INFO_NSS_O,
2028 				    FIELD_GET(RATE_MCS_NSS_MSK, rate_n_flags)));
2029 	}
2030 }
2031 
2032 static void iwl_mvm_rx_he(struct iwl_mvm *mvm, struct sk_buff *skb,
2033 			  struct iwl_mvm_rx_phy_data *phy_data,
2034 			  int queue)
2035 {
2036 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
2037 	struct ieee80211_radiotap_he *he = NULL;
2038 	struct ieee80211_radiotap_he_mu *he_mu = NULL;
2039 	u32 rate_n_flags = phy_data->rate_n_flags;
2040 	u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK;
2041 	u8 ltf;
2042 	static const struct ieee80211_radiotap_he known = {
2043 		.data1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_DATA_MCS_KNOWN |
2044 				     IEEE80211_RADIOTAP_HE_DATA1_DATA_DCM_KNOWN |
2045 				     IEEE80211_RADIOTAP_HE_DATA1_STBC_KNOWN |
2046 				     IEEE80211_RADIOTAP_HE_DATA1_CODING_KNOWN),
2047 		.data2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_GI_KNOWN |
2048 				     IEEE80211_RADIOTAP_HE_DATA2_TXBF_KNOWN),
2049 	};
2050 	static const struct ieee80211_radiotap_he_mu mu_known = {
2051 		.flags1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS_KNOWN |
2052 				      IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM_KNOWN |
2053 				      IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_SYMS_USERS_KNOWN |
2054 				      IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_COMP_KNOWN),
2055 		.flags2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW_KNOWN |
2056 				      IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_KNOWN),
2057 	};
2058 	u16 phy_info = phy_data->phy_info;
2059 
2060 	he = skb_put_data(skb, &known, sizeof(known));
2061 	rx_status->flag |= RX_FLAG_RADIOTAP_HE;
2062 
2063 	if (phy_data->info_type == IWL_RX_PHY_INFO_TYPE_HE_MU ||
2064 	    phy_data->info_type == IWL_RX_PHY_INFO_TYPE_HE_MU_EXT) {
2065 		he_mu = skb_put_data(skb, &mu_known, sizeof(mu_known));
2066 		rx_status->flag |= RX_FLAG_RADIOTAP_HE_MU;
2067 	}
2068 
2069 	/* report the AMPDU-EOF bit on single frames */
2070 	if (!queue && !(phy_info & IWL_RX_MPDU_PHY_AMPDU)) {
2071 		rx_status->flag |= RX_FLAG_AMPDU_DETAILS;
2072 		rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN;
2073 		if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_HE_DELIM_EOF))
2074 			rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT;
2075 	}
2076 
2077 	if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD)
2078 		iwl_mvm_decode_he_phy_data(mvm, phy_data, he, he_mu, rx_status,
2079 					   queue);
2080 
2081 	/* update aggregation data for monitor sake on default queue */
2082 	if (!queue && (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) &&
2083 	    (phy_info & IWL_RX_MPDU_PHY_AMPDU) && phy_data->first_subframe) {
2084 		rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN;
2085 		if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_EHT_DELIM_EOF))
2086 			rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT;
2087 	}
2088 
2089 	if (he_type == RATE_MCS_HE_TYPE_EXT_SU &&
2090 	    rate_n_flags & RATE_MCS_HE_106T_MSK) {
2091 		rx_status->bw = RATE_INFO_BW_HE_RU;
2092 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106;
2093 	}
2094 
2095 	/* actually data is filled in mac80211 */
2096 	if (he_type == RATE_MCS_HE_TYPE_SU ||
2097 	    he_type == RATE_MCS_HE_TYPE_EXT_SU)
2098 		he->data1 |=
2099 			cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN);
2100 
2101 #define CHECK_TYPE(F)							\
2102 	BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_ ## F !=	\
2103 		     (RATE_MCS_HE_TYPE_ ## F >> RATE_MCS_HE_TYPE_POS))
2104 
2105 	CHECK_TYPE(SU);
2106 	CHECK_TYPE(EXT_SU);
2107 	CHECK_TYPE(MU);
2108 	CHECK_TYPE(TRIG);
2109 
2110 	he->data1 |= cpu_to_le16(he_type >> RATE_MCS_HE_TYPE_POS);
2111 
2112 	if (rate_n_flags & RATE_MCS_BF_MSK)
2113 		he->data5 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA5_TXBF);
2114 
2115 	switch ((rate_n_flags & RATE_MCS_HE_GI_LTF_MSK) >>
2116 		RATE_MCS_HE_GI_LTF_POS) {
2117 	case 0:
2118 		if (he_type == RATE_MCS_HE_TYPE_TRIG)
2119 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
2120 		else
2121 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
2122 		if (he_type == RATE_MCS_HE_TYPE_MU)
2123 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
2124 		else
2125 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X;
2126 		break;
2127 	case 1:
2128 		if (he_type == RATE_MCS_HE_TYPE_TRIG)
2129 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
2130 		else
2131 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
2132 		ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X;
2133 		break;
2134 	case 2:
2135 		if (he_type == RATE_MCS_HE_TYPE_TRIG) {
2136 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
2137 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
2138 		} else {
2139 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
2140 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X;
2141 		}
2142 		break;
2143 	case 3:
2144 		rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
2145 		ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
2146 		break;
2147 	case 4:
2148 		rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
2149 		ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
2150 		break;
2151 	default:
2152 		ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN;
2153 	}
2154 
2155 	he->data5 |= le16_encode_bits(ltf,
2156 				      IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE);
2157 }
2158 
2159 static void iwl_mvm_decode_lsig(struct sk_buff *skb,
2160 				struct iwl_mvm_rx_phy_data *phy_data)
2161 {
2162 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
2163 	struct ieee80211_radiotap_lsig *lsig;
2164 
2165 	switch (phy_data->info_type) {
2166 	case IWL_RX_PHY_INFO_TYPE_HT:
2167 	case IWL_RX_PHY_INFO_TYPE_VHT_SU:
2168 	case IWL_RX_PHY_INFO_TYPE_VHT_MU:
2169 	case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT:
2170 	case IWL_RX_PHY_INFO_TYPE_HE_SU:
2171 	case IWL_RX_PHY_INFO_TYPE_HE_MU:
2172 	case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
2173 	case IWL_RX_PHY_INFO_TYPE_HE_TB:
2174 	case IWL_RX_PHY_INFO_TYPE_EHT_MU:
2175 	case IWL_RX_PHY_INFO_TYPE_EHT_TB:
2176 	case IWL_RX_PHY_INFO_TYPE_EHT_MU_EXT:
2177 	case IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT:
2178 		lsig = skb_put(skb, sizeof(*lsig));
2179 		lsig->data1 = cpu_to_le16(IEEE80211_RADIOTAP_LSIG_DATA1_LENGTH_KNOWN);
2180 		lsig->data2 = le16_encode_bits(le32_get_bits(phy_data->d1,
2181 							     IWL_RX_PHY_DATA1_LSIG_LEN_MASK),
2182 					       IEEE80211_RADIOTAP_LSIG_DATA2_LENGTH);
2183 		rx_status->flag |= RX_FLAG_RADIOTAP_LSIG;
2184 		break;
2185 	default:
2186 		break;
2187 	}
2188 }
2189 
2190 static inline u8 iwl_mvm_nl80211_band_from_rx_msdu(u8 phy_band)
2191 {
2192 	switch (phy_band) {
2193 	case PHY_BAND_24:
2194 		return NL80211_BAND_2GHZ;
2195 	case PHY_BAND_5:
2196 		return NL80211_BAND_5GHZ;
2197 	case PHY_BAND_6:
2198 		return NL80211_BAND_6GHZ;
2199 	default:
2200 		WARN_ONCE(1, "Unsupported phy band (%u)\n", phy_band);
2201 		return NL80211_BAND_5GHZ;
2202 	}
2203 }
2204 
2205 struct iwl_rx_sta_csa {
2206 	bool all_sta_unblocked;
2207 	struct ieee80211_vif *vif;
2208 };
2209 
2210 static void iwl_mvm_rx_get_sta_block_tx(void *data, struct ieee80211_sta *sta)
2211 {
2212 	struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2213 	struct iwl_rx_sta_csa *rx_sta_csa = data;
2214 
2215 	if (mvmsta->vif != rx_sta_csa->vif)
2216 		return;
2217 
2218 	if (mvmsta->disable_tx)
2219 		rx_sta_csa->all_sta_unblocked = false;
2220 }
2221 
2222 /*
2223  * Note: requires also rx_status->band to be prefilled, as well
2224  * as phy_data (apart from phy_data->info_type)
2225  */
2226 static void iwl_mvm_rx_fill_status(struct iwl_mvm *mvm,
2227 				   struct sk_buff *skb,
2228 				   struct iwl_mvm_rx_phy_data *phy_data,
2229 				   int queue)
2230 {
2231 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
2232 	u32 rate_n_flags = phy_data->rate_n_flags;
2233 	u8 stbc = u32_get_bits(rate_n_flags, RATE_MCS_STBC_MSK);
2234 	u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK;
2235 	bool is_sgi;
2236 
2237 	phy_data->info_type = IWL_RX_PHY_INFO_TYPE_NONE;
2238 
2239 	if (phy_data->phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD)
2240 		phy_data->info_type =
2241 			le32_get_bits(phy_data->d1,
2242 				      IWL_RX_PHY_DATA1_INFO_TYPE_MASK);
2243 
2244 	/* This may be overridden by iwl_mvm_rx_he() to HE_RU */
2245 	switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
2246 	case RATE_MCS_CHAN_WIDTH_20:
2247 		break;
2248 	case RATE_MCS_CHAN_WIDTH_40:
2249 		rx_status->bw = RATE_INFO_BW_40;
2250 		break;
2251 	case RATE_MCS_CHAN_WIDTH_80:
2252 		rx_status->bw = RATE_INFO_BW_80;
2253 		break;
2254 	case RATE_MCS_CHAN_WIDTH_160:
2255 		rx_status->bw = RATE_INFO_BW_160;
2256 		break;
2257 	case RATE_MCS_CHAN_WIDTH_320:
2258 		rx_status->bw = RATE_INFO_BW_320;
2259 		break;
2260 	}
2261 
2262 	/* must be before L-SIG data */
2263 	if (format == RATE_MCS_HE_MSK)
2264 		iwl_mvm_rx_he(mvm, skb, phy_data, queue);
2265 
2266 	iwl_mvm_decode_lsig(skb, phy_data);
2267 
2268 	rx_status->device_timestamp = phy_data->gp2_on_air_rise;
2269 	rx_status->freq = ieee80211_channel_to_frequency(phy_data->channel,
2270 							 rx_status->band);
2271 	iwl_mvm_get_signal_strength(mvm, rx_status, rate_n_flags,
2272 				    phy_data->energy_a, phy_data->energy_b);
2273 
2274 	/* using TLV format and must be after all fixed len fields */
2275 	if (format == RATE_MCS_EHT_MSK)
2276 		iwl_mvm_rx_eht(mvm, skb, phy_data, queue);
2277 
2278 	if (unlikely(mvm->monitor_on))
2279 		iwl_mvm_add_rtap_sniffer_config(mvm, skb);
2280 
2281 	is_sgi = format == RATE_MCS_HE_MSK ?
2282 		iwl_he_is_sgi(rate_n_flags) :
2283 		rate_n_flags & RATE_MCS_SGI_MSK;
2284 
2285 	if (!(format == RATE_MCS_CCK_MSK) && is_sgi)
2286 		rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
2287 
2288 	if (rate_n_flags & RATE_MCS_LDPC_MSK)
2289 		rx_status->enc_flags |= RX_ENC_FLAG_LDPC;
2290 
2291 	switch (format) {
2292 	case RATE_MCS_VHT_MSK:
2293 		rx_status->encoding = RX_ENC_VHT;
2294 		break;
2295 	case RATE_MCS_HE_MSK:
2296 		rx_status->encoding = RX_ENC_HE;
2297 		rx_status->he_dcm =
2298 			!!(rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK);
2299 		break;
2300 	case RATE_MCS_EHT_MSK:
2301 		rx_status->encoding = RX_ENC_EHT;
2302 		break;
2303 	}
2304 
2305 	switch (format) {
2306 	case RATE_MCS_HT_MSK:
2307 		rx_status->encoding = RX_ENC_HT;
2308 		rx_status->rate_idx = RATE_HT_MCS_INDEX(rate_n_flags);
2309 		rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
2310 		break;
2311 	case RATE_MCS_VHT_MSK:
2312 	case RATE_MCS_HE_MSK:
2313 	case RATE_MCS_EHT_MSK:
2314 		rx_status->nss =
2315 			u32_get_bits(rate_n_flags, RATE_MCS_NSS_MSK) + 1;
2316 		rx_status->rate_idx = rate_n_flags & RATE_MCS_CODE_MSK;
2317 		rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
2318 		break;
2319 	default: {
2320 		int rate = iwl_mvm_legacy_hw_idx_to_mac80211_idx(rate_n_flags,
2321 								 rx_status->band);
2322 
2323 		rx_status->rate_idx = rate;
2324 
2325 		if ((rate < 0 || rate > 0xFF)) {
2326 			rx_status->rate_idx = 0;
2327 			if (net_ratelimit())
2328 				IWL_ERR(mvm, "Invalid rate flags 0x%x, band %d,\n",
2329 					rate_n_flags, rx_status->band);
2330 		}
2331 
2332 		break;
2333 		}
2334 	}
2335 }
2336 
2337 void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi,
2338 			struct iwl_rx_cmd_buffer *rxb, int queue)
2339 {
2340 	struct ieee80211_rx_status *rx_status;
2341 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
2342 	struct iwl_rx_mpdu_desc *desc = (void *)pkt->data;
2343 	struct ieee80211_hdr *hdr;
2344 	u32 len;
2345 	u32 pkt_len = iwl_rx_packet_payload_len(pkt);
2346 	struct ieee80211_sta *sta = NULL;
2347 	struct ieee80211_link_sta *link_sta = NULL;
2348 	struct sk_buff *skb;
2349 	u8 crypt_len = 0;
2350 	size_t desc_size;
2351 	struct iwl_mvm_rx_phy_data phy_data = {};
2352 	u32 format;
2353 
2354 	if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
2355 		return;
2356 
2357 	if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210)
2358 		desc_size = sizeof(*desc);
2359 	else
2360 		desc_size = IWL_RX_DESC_SIZE_V1;
2361 
2362 	if (unlikely(pkt_len < desc_size)) {
2363 		IWL_DEBUG_DROP(mvm, "Bad REPLY_RX_MPDU_CMD size\n");
2364 		return;
2365 	}
2366 
2367 	if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) {
2368 		phy_data.rate_n_flags = le32_to_cpu(desc->v3.rate_n_flags);
2369 		phy_data.channel = desc->v3.channel;
2370 		phy_data.gp2_on_air_rise = le32_to_cpu(desc->v3.gp2_on_air_rise);
2371 		phy_data.energy_a = desc->v3.energy_a;
2372 		phy_data.energy_b = desc->v3.energy_b;
2373 
2374 		phy_data.d0 = desc->v3.phy_data0;
2375 		phy_data.d1 = desc->v3.phy_data1;
2376 		phy_data.d2 = desc->v3.phy_data2;
2377 		phy_data.d3 = desc->v3.phy_data3;
2378 		phy_data.eht_d4 = desc->phy_eht_data4;
2379 		phy_data.d5 = desc->v3.phy_data5;
2380 	} else {
2381 		phy_data.rate_n_flags = le32_to_cpu(desc->v1.rate_n_flags);
2382 		phy_data.channel = desc->v1.channel;
2383 		phy_data.gp2_on_air_rise = le32_to_cpu(desc->v1.gp2_on_air_rise);
2384 		phy_data.energy_a = desc->v1.energy_a;
2385 		phy_data.energy_b = desc->v1.energy_b;
2386 
2387 		phy_data.d0 = desc->v1.phy_data0;
2388 		phy_data.d1 = desc->v1.phy_data1;
2389 		phy_data.d2 = desc->v1.phy_data2;
2390 		phy_data.d3 = desc->v1.phy_data3;
2391 	}
2392 
2393 	if (iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,
2394 				    REPLY_RX_MPDU_CMD, 0) < 4) {
2395 		phy_data.rate_n_flags = iwl_new_rate_from_v1(phy_data.rate_n_flags);
2396 		IWL_DEBUG_DROP(mvm, "Got old format rate, converting. New rate: 0x%x\n",
2397 			       phy_data.rate_n_flags);
2398 	}
2399 
2400 	format = phy_data.rate_n_flags & RATE_MCS_MOD_TYPE_MSK;
2401 
2402 	len = le16_to_cpu(desc->mpdu_len);
2403 
2404 	if (unlikely(len + desc_size > pkt_len)) {
2405 		IWL_DEBUG_DROP(mvm, "FW lied about packet len\n");
2406 		return;
2407 	}
2408 
2409 	phy_data.with_data = true;
2410 	phy_data.phy_info = le16_to_cpu(desc->phy_info);
2411 	phy_data.d4 = desc->phy_data4;
2412 
2413 	hdr = (void *)(pkt->data + desc_size);
2414 	/* Dont use dev_alloc_skb(), we'll have enough headroom once
2415 	 * ieee80211_hdr pulled.
2416 	 */
2417 	skb = alloc_skb(128, GFP_ATOMIC);
2418 	if (!skb) {
2419 		IWL_ERR(mvm, "alloc_skb failed\n");
2420 		return;
2421 	}
2422 
2423 	if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) {
2424 		/*
2425 		 * If the device inserted padding it means that (it thought)
2426 		 * the 802.11 header wasn't a multiple of 4 bytes long. In
2427 		 * this case, reserve two bytes at the start of the SKB to
2428 		 * align the payload properly in case we end up copying it.
2429 		 */
2430 		skb_reserve(skb, 2);
2431 	}
2432 
2433 	rx_status = IEEE80211_SKB_RXCB(skb);
2434 
2435 	/*
2436 	 * Keep packets with CRC errors (and with overrun) for monitor mode
2437 	 * (otherwise the firmware discards them) but mark them as bad.
2438 	 */
2439 	if (!(desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_CRC_OK)) ||
2440 	    !(desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_OVERRUN_OK))) {
2441 		IWL_DEBUG_RX(mvm, "Bad CRC or FIFO: 0x%08X.\n",
2442 			     le32_to_cpu(desc->status));
2443 		rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
2444 	}
2445 
2446 	/* set the preamble flag if appropriate */
2447 	if (format == RATE_MCS_CCK_MSK &&
2448 	    phy_data.phy_info & IWL_RX_MPDU_PHY_SHORT_PREAMBLE)
2449 		rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE;
2450 
2451 	if (likely(!(phy_data.phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD))) {
2452 		u64 tsf_on_air_rise;
2453 
2454 		if (mvm->trans->trans_cfg->device_family >=
2455 		    IWL_DEVICE_FAMILY_AX210)
2456 			tsf_on_air_rise = le64_to_cpu(desc->v3.tsf_on_air_rise);
2457 		else
2458 			tsf_on_air_rise = le64_to_cpu(desc->v1.tsf_on_air_rise);
2459 
2460 		rx_status->mactime = tsf_on_air_rise;
2461 		/* TSF as indicated by the firmware is at INA time */
2462 		rx_status->flag |= RX_FLAG_MACTIME_PLCP_START;
2463 	}
2464 
2465 	if (iwl_mvm_is_band_in_rx_supported(mvm)) {
2466 		u8 band = BAND_IN_RX_STATUS(desc->mac_phy_idx);
2467 
2468 		rx_status->band = iwl_mvm_nl80211_band_from_rx_msdu(band);
2469 	} else {
2470 		rx_status->band = phy_data.channel > 14 ? NL80211_BAND_5GHZ :
2471 			NL80211_BAND_2GHZ;
2472 	}
2473 
2474 	/* update aggregation data for monitor sake on default queue */
2475 	if (!queue && (phy_data.phy_info & IWL_RX_MPDU_PHY_AMPDU)) {
2476 		bool toggle_bit;
2477 
2478 		toggle_bit = phy_data.phy_info & IWL_RX_MPDU_PHY_AMPDU_TOGGLE;
2479 		rx_status->flag |= RX_FLAG_AMPDU_DETAILS;
2480 		/*
2481 		 * Toggle is switched whenever new aggregation starts. Make
2482 		 * sure ampdu_reference is never 0 so we can later use it to
2483 		 * see if the frame was really part of an A-MPDU or not.
2484 		 */
2485 		if (toggle_bit != mvm->ampdu_toggle) {
2486 			mvm->ampdu_ref++;
2487 			if (mvm->ampdu_ref == 0)
2488 				mvm->ampdu_ref++;
2489 			mvm->ampdu_toggle = toggle_bit;
2490 			phy_data.first_subframe = true;
2491 		}
2492 		rx_status->ampdu_reference = mvm->ampdu_ref;
2493 	}
2494 
2495 	rcu_read_lock();
2496 
2497 	if (desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_SRC_STA_FOUND)) {
2498 		u8 id = le32_get_bits(desc->status, IWL_RX_MPDU_STATUS_STA_ID);
2499 
2500 		if (!WARN_ON_ONCE(id >= mvm->fw->ucode_capa.num_stations)) {
2501 			sta = rcu_dereference(mvm->fw_id_to_mac_id[id]);
2502 			if (IS_ERR(sta))
2503 				sta = NULL;
2504 			link_sta = rcu_dereference(mvm->fw_id_to_link_sta[id]);
2505 		}
2506 	} else if (!is_multicast_ether_addr(hdr->addr2)) {
2507 		/*
2508 		 * This is fine since we prevent two stations with the same
2509 		 * address from being added.
2510 		 */
2511 		sta = ieee80211_find_sta_by_ifaddr(mvm->hw, hdr->addr2, NULL);
2512 	}
2513 
2514 	if (iwl_mvm_rx_crypto(mvm, sta, hdr, rx_status, phy_data.phy_info, desc,
2515 			      le32_to_cpu(pkt->len_n_flags), queue,
2516 			      &crypt_len)) {
2517 		kfree_skb(skb);
2518 		goto out;
2519 	}
2520 
2521 	iwl_mvm_rx_fill_status(mvm, skb, &phy_data, queue);
2522 
2523 	if (sta) {
2524 		struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2525 		struct ieee80211_vif *tx_blocked_vif =
2526 			rcu_dereference(mvm->csa_tx_blocked_vif);
2527 		u8 baid = (u8)((le32_to_cpu(desc->reorder_data) &
2528 			       IWL_RX_MPDU_REORDER_BAID_MASK) >>
2529 			       IWL_RX_MPDU_REORDER_BAID_SHIFT);
2530 		struct iwl_fw_dbg_trigger_tlv *trig;
2531 		struct ieee80211_vif *vif = mvmsta->vif;
2532 
2533 		if (!mvm->tcm.paused && len >= sizeof(*hdr) &&
2534 		    !is_multicast_ether_addr(hdr->addr1) &&
2535 		    ieee80211_is_data(hdr->frame_control) &&
2536 		    time_after(jiffies, mvm->tcm.ts + MVM_TCM_PERIOD))
2537 			schedule_delayed_work(&mvm->tcm.work, 0);
2538 
2539 		/*
2540 		 * We have tx blocked stations (with CS bit). If we heard
2541 		 * frames from a blocked station on a new channel we can
2542 		 * TX to it again.
2543 		 */
2544 		if (unlikely(tx_blocked_vif) && tx_blocked_vif == vif) {
2545 			struct iwl_mvm_vif *mvmvif =
2546 				iwl_mvm_vif_from_mac80211(tx_blocked_vif);
2547 			struct iwl_rx_sta_csa rx_sta_csa = {
2548 				.all_sta_unblocked = true,
2549 				.vif = tx_blocked_vif,
2550 			};
2551 
2552 			if (mvmvif->csa_target_freq == rx_status->freq)
2553 				iwl_mvm_sta_modify_disable_tx_ap(mvm, sta,
2554 								 false);
2555 			ieee80211_iterate_stations_atomic(mvm->hw,
2556 							  iwl_mvm_rx_get_sta_block_tx,
2557 							  &rx_sta_csa);
2558 
2559 			if (rx_sta_csa.all_sta_unblocked) {
2560 				RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2561 				/* Unblock BCAST / MCAST station */
2562 				iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false);
2563 				cancel_delayed_work(&mvm->cs_tx_unblock_dwork);
2564 			}
2565 		}
2566 
2567 		rs_update_last_rssi(mvm, mvmsta, rx_status);
2568 
2569 		trig = iwl_fw_dbg_trigger_on(&mvm->fwrt,
2570 					     ieee80211_vif_to_wdev(vif),
2571 					     FW_DBG_TRIGGER_RSSI);
2572 
2573 		if (trig && ieee80211_is_beacon(hdr->frame_control)) {
2574 			struct iwl_fw_dbg_trigger_low_rssi *rssi_trig;
2575 			s32 rssi;
2576 
2577 			rssi_trig = (void *)trig->data;
2578 			rssi = le32_to_cpu(rssi_trig->rssi);
2579 
2580 			if (rx_status->signal < rssi)
2581 				iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
2582 #if defined(__linux__)
2583 							NULL);
2584 #elif defined(__FreeBSD__)
2585 							"");
2586 #endif
2587 		}
2588 
2589 		if (ieee80211_is_data(hdr->frame_control))
2590 			iwl_mvm_rx_csum(mvm, sta, skb, pkt);
2591 
2592 		if (iwl_mvm_is_dup(sta, queue, rx_status, hdr, desc)) {
2593 			kfree_skb(skb);
2594 			goto out;
2595 		}
2596 
2597 		/*
2598 		 * Our hardware de-aggregates AMSDUs but copies the mac header
2599 		 * as it to the de-aggregated MPDUs. We need to turn off the
2600 		 * AMSDU bit in the QoS control ourselves.
2601 		 * In addition, HW reverses addr3 and addr4 - reverse it back.
2602 		 */
2603 		if ((desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU) &&
2604 		    !WARN_ON(!ieee80211_is_data_qos(hdr->frame_control))) {
2605 			u8 *qc = ieee80211_get_qos_ctl(hdr);
2606 
2607 			*qc &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT;
2608 
2609 			if (mvm->trans->trans_cfg->device_family ==
2610 			    IWL_DEVICE_FAMILY_9000) {
2611 				iwl_mvm_flip_address(hdr->addr3);
2612 
2613 				if (ieee80211_has_a4(hdr->frame_control))
2614 					iwl_mvm_flip_address(hdr->addr4);
2615 			}
2616 		}
2617 		if (baid != IWL_RX_REORDER_DATA_INVALID_BAID) {
2618 			u32 reorder_data = le32_to_cpu(desc->reorder_data);
2619 
2620 			iwl_mvm_agg_rx_received(mvm, reorder_data, baid);
2621 		}
2622 	}
2623 
2624 	/* management stuff on default queue */
2625 	if (!queue) {
2626 		if (unlikely((ieee80211_is_beacon(hdr->frame_control) ||
2627 			      ieee80211_is_probe_resp(hdr->frame_control)) &&
2628 			     mvm->sched_scan_pass_all ==
2629 			     SCHED_SCAN_PASS_ALL_ENABLED))
2630 			mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_FOUND;
2631 
2632 		if (unlikely(ieee80211_is_beacon(hdr->frame_control) ||
2633 			     ieee80211_is_probe_resp(hdr->frame_control)))
2634 			rx_status->boottime_ns = ktime_get_boottime_ns();
2635 	}
2636 
2637 	if (iwl_mvm_create_skb(mvm, skb, hdr, len, crypt_len, rxb)) {
2638 		kfree_skb(skb);
2639 		goto out;
2640 	}
2641 
2642 	if (!iwl_mvm_reorder(mvm, napi, queue, sta, skb, desc) &&
2643 	    likely(!iwl_mvm_time_sync_frame(mvm, skb, hdr->addr2)) &&
2644 	    likely(!iwl_mvm_mei_filter_scan(mvm, skb)))
2645 		iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb, queue, sta,
2646 						link_sta);
2647 out:
2648 	rcu_read_unlock();
2649 }
2650 
2651 void iwl_mvm_rx_monitor_no_data(struct iwl_mvm *mvm, struct napi_struct *napi,
2652 				struct iwl_rx_cmd_buffer *rxb, int queue)
2653 {
2654 	struct ieee80211_rx_status *rx_status;
2655 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
2656 	struct iwl_rx_no_data_ver_3 *desc = (void *)pkt->data;
2657 	u32 rssi;
2658 	u32 info_type;
2659 	struct ieee80211_sta *sta = NULL;
2660 	struct sk_buff *skb;
2661 	struct iwl_mvm_rx_phy_data phy_data;
2662 	u32 format;
2663 
2664 	if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
2665 		return;
2666 
2667 	if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(struct iwl_rx_no_data)))
2668 		return;
2669 
2670 	rssi = le32_to_cpu(desc->rssi);
2671 	info_type = le32_to_cpu(desc->info) & RX_NO_DATA_INFO_TYPE_MSK;
2672 	phy_data.d0 = desc->phy_info[0];
2673 	phy_data.d1 = desc->phy_info[1];
2674 	phy_data.phy_info = IWL_RX_MPDU_PHY_TSF_OVERLOAD;
2675 	phy_data.gp2_on_air_rise = le32_to_cpu(desc->on_air_rise_time);
2676 	phy_data.rate_n_flags = le32_to_cpu(desc->rate);
2677 	phy_data.energy_a = u32_get_bits(rssi, RX_NO_DATA_CHAIN_A_MSK);
2678 	phy_data.energy_b = u32_get_bits(rssi, RX_NO_DATA_CHAIN_B_MSK);
2679 	phy_data.channel = u32_get_bits(rssi, RX_NO_DATA_CHANNEL_MSK);
2680 	phy_data.with_data = false;
2681 	phy_data.rx_vec[0] = desc->rx_vec[0];
2682 	phy_data.rx_vec[1] = desc->rx_vec[1];
2683 
2684 	if (iwl_fw_lookup_notif_ver(mvm->fw, DATA_PATH_GROUP,
2685 				    RX_NO_DATA_NOTIF, 0) < 2) {
2686 		IWL_DEBUG_DROP(mvm, "Got an old rate format. Old rate: 0x%x\n",
2687 			       phy_data.rate_n_flags);
2688 		phy_data.rate_n_flags = iwl_new_rate_from_v1(phy_data.rate_n_flags);
2689 		IWL_DEBUG_DROP(mvm, " Rate after conversion to the new format: 0x%x\n",
2690 			       phy_data.rate_n_flags);
2691 	}
2692 
2693 	format = phy_data.rate_n_flags & RATE_MCS_MOD_TYPE_MSK;
2694 
2695 	if (iwl_fw_lookup_notif_ver(mvm->fw, DATA_PATH_GROUP,
2696 				    RX_NO_DATA_NOTIF, 0) >= 3) {
2697 		if (unlikely(iwl_rx_packet_payload_len(pkt) <
2698 		    sizeof(struct iwl_rx_no_data_ver_3)))
2699 		/* invalid len for ver 3 */
2700 			return;
2701 		phy_data.rx_vec[2] = desc->rx_vec[2];
2702 		phy_data.rx_vec[3] = desc->rx_vec[3];
2703 	} else {
2704 		if (format == RATE_MCS_EHT_MSK)
2705 			/* no support for EHT before version 3 API */
2706 			return;
2707 	}
2708 
2709 	/* Dont use dev_alloc_skb(), we'll have enough headroom once
2710 	 * ieee80211_hdr pulled.
2711 	 */
2712 	skb = alloc_skb(128, GFP_ATOMIC);
2713 	if (!skb) {
2714 		IWL_ERR(mvm, "alloc_skb failed\n");
2715 		return;
2716 	}
2717 
2718 	rx_status = IEEE80211_SKB_RXCB(skb);
2719 
2720 	/* 0-length PSDU */
2721 	rx_status->flag |= RX_FLAG_NO_PSDU;
2722 
2723 	switch (info_type) {
2724 	case RX_NO_DATA_INFO_TYPE_NDP:
2725 		rx_status->zero_length_psdu_type =
2726 			IEEE80211_RADIOTAP_ZERO_LEN_PSDU_SOUNDING;
2727 		break;
2728 	case RX_NO_DATA_INFO_TYPE_MU_UNMATCHED:
2729 	case RX_NO_DATA_INFO_TYPE_TB_UNMATCHED:
2730 		rx_status->zero_length_psdu_type =
2731 			IEEE80211_RADIOTAP_ZERO_LEN_PSDU_NOT_CAPTURED;
2732 		break;
2733 	default:
2734 		rx_status->zero_length_psdu_type =
2735 			IEEE80211_RADIOTAP_ZERO_LEN_PSDU_VENDOR;
2736 		break;
2737 	}
2738 
2739 	rx_status->band = phy_data.channel > 14 ? NL80211_BAND_5GHZ :
2740 		NL80211_BAND_2GHZ;
2741 
2742 	iwl_mvm_rx_fill_status(mvm, skb, &phy_data, queue);
2743 
2744 	/* no more radio tap info should be put after this point.
2745 	 *
2746 	 * We mark it as mac header, for upper layers to know where
2747 	 * all radio tap header ends.
2748 	 */
2749 	skb_reset_mac_header(skb);
2750 
2751 	/*
2752 	 * Override the nss from the rx_vec since the rate_n_flags has
2753 	 * only 2 bits for the nss which gives a max of 4 ss but there
2754 	 * may be up to 8 spatial streams.
2755 	 */
2756 	switch (format) {
2757 	case RATE_MCS_VHT_MSK:
2758 		rx_status->nss =
2759 			le32_get_bits(desc->rx_vec[0],
2760 				      RX_NO_DATA_RX_VEC0_VHT_NSTS_MSK) + 1;
2761 		break;
2762 	case RATE_MCS_HE_MSK:
2763 		rx_status->nss =
2764 			le32_get_bits(desc->rx_vec[0],
2765 				      RX_NO_DATA_RX_VEC0_HE_NSTS_MSK) + 1;
2766 		break;
2767 	case RATE_MCS_EHT_MSK:
2768 		rx_status->nss =
2769 			le32_get_bits(desc->rx_vec[2],
2770 				      RX_NO_DATA_RX_VEC2_EHT_NSTS_MSK) + 1;
2771 	}
2772 
2773 	rcu_read_lock();
2774 	ieee80211_rx_napi(mvm->hw, sta, skb, napi);
2775 	rcu_read_unlock();
2776 }
2777 
2778 void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
2779 			      struct iwl_rx_cmd_buffer *rxb, int queue)
2780 {
2781 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
2782 	struct iwl_frame_release *release = (void *)pkt->data;
2783 
2784 	if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(*release)))
2785 		return;
2786 
2787 	iwl_mvm_release_frames_from_notif(mvm, napi, release->baid,
2788 					  le16_to_cpu(release->nssn),
2789 					  queue, 0);
2790 }
2791 
2792 void iwl_mvm_rx_bar_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
2793 				  struct iwl_rx_cmd_buffer *rxb, int queue)
2794 {
2795 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
2796 	struct iwl_bar_frame_release *release = (void *)pkt->data;
2797 	unsigned int baid = le32_get_bits(release->ba_info,
2798 					  IWL_BAR_FRAME_RELEASE_BAID_MASK);
2799 	unsigned int nssn = le32_get_bits(release->ba_info,
2800 					  IWL_BAR_FRAME_RELEASE_NSSN_MASK);
2801 	unsigned int sta_id = le32_get_bits(release->sta_tid,
2802 					    IWL_BAR_FRAME_RELEASE_STA_MASK);
2803 	unsigned int tid = le32_get_bits(release->sta_tid,
2804 					 IWL_BAR_FRAME_RELEASE_TID_MASK);
2805 	struct iwl_mvm_baid_data *baid_data;
2806 
2807 	if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(*release)))
2808 		return;
2809 
2810 	if (WARN_ON_ONCE(baid == IWL_RX_REORDER_DATA_INVALID_BAID ||
2811 			 baid >= ARRAY_SIZE(mvm->baid_map)))
2812 		return;
2813 
2814 	rcu_read_lock();
2815 	baid_data = rcu_dereference(mvm->baid_map[baid]);
2816 	if (!baid_data) {
2817 		IWL_DEBUG_RX(mvm,
2818 			     "Got valid BAID %d but not allocated, invalid BAR release!\n",
2819 			      baid);
2820 		goto out;
2821 	}
2822 
2823 	if (WARN(tid != baid_data->tid || sta_id > IWL_MVM_STATION_COUNT_MAX ||
2824 		 !(baid_data->sta_mask & BIT(sta_id)),
2825 		 "baid 0x%x is mapped to sta_mask:0x%x tid:%d, but BAR release received for sta:%d tid:%d\n",
2826 		 baid, baid_data->sta_mask, baid_data->tid, sta_id,
2827 		 tid))
2828 		goto out;
2829 
2830 	iwl_mvm_release_frames_from_notif(mvm, napi, baid, nssn, queue, 0);
2831 out:
2832 	rcu_read_unlock();
2833 }
2834