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