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