xref: /openbmc/linux/drivers/net/wireless/intel/iwlwifi/mvm/rxmq.c (revision 6c71a0574249f5e5a45fe055ab5f837023d5eeca)
18e99ea8dSJohannes Berg // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
28e99ea8dSJohannes Berg /*
34ec82585SMordechay Goodstein  * Copyright (C) 2012-2014, 2018-2023 Intel Corporation
48e99ea8dSJohannes Berg  * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
58e99ea8dSJohannes Berg  * Copyright (C) 2015-2017 Intel Deutschland GmbH
68e99ea8dSJohannes Berg  */
7780e87c2SJohannes Berg #include <linux/etherdevice.h>
8780e87c2SJohannes Berg #include <linux/skbuff.h>
9780e87c2SJohannes Berg #include "iwl-trans.h"
10780e87c2SJohannes Berg #include "mvm.h"
11780e87c2SJohannes Berg #include "fw-api.h"
12c7eca79dSAvraham Stern #include "time-sync.h"
13780e87c2SJohannes Berg 
iwl_mvm_check_pn(struct iwl_mvm * mvm,struct sk_buff * skb,int queue,struct ieee80211_sta * sta)14f5e28eacSJohannes Berg static inline int iwl_mvm_check_pn(struct iwl_mvm *mvm, struct sk_buff *skb,
15f5e28eacSJohannes Berg 				   int queue, struct ieee80211_sta *sta)
16f5e28eacSJohannes Berg {
17f5e28eacSJohannes Berg 	struct iwl_mvm_sta *mvmsta;
183f7a9d57SMordechay Goodstein 	struct ieee80211_hdr *hdr = (void *)skb_mac_header(skb);
19f5e28eacSJohannes Berg 	struct ieee80211_rx_status *stats = IEEE80211_SKB_RXCB(skb);
20f5e28eacSJohannes Berg 	struct iwl_mvm_key_pn *ptk_pn;
215ab2ba93SSara Sharon 	int res;
22f5e28eacSJohannes Berg 	u8 tid, keyidx;
23f5e28eacSJohannes Berg 	u8 pn[IEEE80211_CCMP_PN_LEN];
24f5e28eacSJohannes Berg 	u8 *extiv;
25f5e28eacSJohannes Berg 
26f5e28eacSJohannes Berg 	/* do PN checking */
27f5e28eacSJohannes Berg 
28f5e28eacSJohannes Berg 	/* multicast and non-data only arrives on default queue */
29f5e28eacSJohannes Berg 	if (!ieee80211_is_data(hdr->frame_control) ||
30f5e28eacSJohannes Berg 	    is_multicast_ether_addr(hdr->addr1))
31f5e28eacSJohannes Berg 		return 0;
32f5e28eacSJohannes Berg 
33f5e28eacSJohannes Berg 	/* do not check PN for open AP */
34f5e28eacSJohannes Berg 	if (!(stats->flag & RX_FLAG_DECRYPTED))
35f5e28eacSJohannes Berg 		return 0;
36f5e28eacSJohannes Berg 
37f5e28eacSJohannes Berg 	/*
38f5e28eacSJohannes Berg 	 * avoid checking for default queue - we don't want to replicate
39f5e28eacSJohannes Berg 	 * all the logic that's necessary for checking the PN on fragmented
40f5e28eacSJohannes Berg 	 * frames, leave that to mac80211
41f5e28eacSJohannes Berg 	 */
42f5e28eacSJohannes Berg 	if (queue == 0)
43f5e28eacSJohannes Berg 		return 0;
44f5e28eacSJohannes Berg 
45f5e28eacSJohannes Berg 	/* if we are here - this for sure is either CCMP or GCMP */
46f5e28eacSJohannes Berg 	if (IS_ERR_OR_NULL(sta)) {
473df5c0ddSAvraham Stern 		IWL_DEBUG_DROP(mvm,
48f5e28eacSJohannes Berg 			       "expected hw-decrypted unicast frame for station\n");
49f5e28eacSJohannes Berg 		return -1;
50f5e28eacSJohannes Berg 	}
51f5e28eacSJohannes Berg 
52f5e28eacSJohannes Berg 	mvmsta = iwl_mvm_sta_from_mac80211(sta);
53f5e28eacSJohannes Berg 
54f5e28eacSJohannes Berg 	extiv = (u8 *)hdr + ieee80211_hdrlen(hdr->frame_control);
55f5e28eacSJohannes Berg 	keyidx = extiv[3] >> 6;
56f5e28eacSJohannes Berg 
57f5e28eacSJohannes Berg 	ptk_pn = rcu_dereference(mvmsta->ptk_pn[keyidx]);
58f5e28eacSJohannes Berg 	if (!ptk_pn)
59f5e28eacSJohannes Berg 		return -1;
60f5e28eacSJohannes Berg 
61f5e28eacSJohannes Berg 	if (ieee80211_is_data_qos(hdr->frame_control))
628f66e064SSara Sharon 		tid = ieee80211_get_tid(hdr);
63f5e28eacSJohannes Berg 	else
64f5e28eacSJohannes Berg 		tid = 0;
65f5e28eacSJohannes Berg 
66f5e28eacSJohannes Berg 	/* we don't use HCCA/802.11 QoS TSPECs, so drop such frames */
67f5e28eacSJohannes Berg 	if (tid >= IWL_MAX_TID_COUNT)
68f5e28eacSJohannes Berg 		return -1;
69f5e28eacSJohannes Berg 
70f5e28eacSJohannes Berg 	/* load pn */
71f5e28eacSJohannes Berg 	pn[0] = extiv[7];
72f5e28eacSJohannes Berg 	pn[1] = extiv[6];
73f5e28eacSJohannes Berg 	pn[2] = extiv[5];
74f5e28eacSJohannes Berg 	pn[3] = extiv[4];
75f5e28eacSJohannes Berg 	pn[4] = extiv[1];
76f5e28eacSJohannes Berg 	pn[5] = extiv[0];
77f5e28eacSJohannes Berg 
785ab2ba93SSara Sharon 	res = memcmp(pn, ptk_pn->q[queue].pn[tid], IEEE80211_CCMP_PN_LEN);
795ab2ba93SSara Sharon 	if (res < 0)
805ab2ba93SSara Sharon 		return -1;
815ab2ba93SSara Sharon 	if (!res && !(stats->flag & RX_FLAG_ALLOW_SAME_PN))
82f5e28eacSJohannes Berg 		return -1;
83f5e28eacSJohannes Berg 
84f5e28eacSJohannes Berg 	memcpy(ptk_pn->q[queue].pn[tid], pn, IEEE80211_CCMP_PN_LEN);
85f5e28eacSJohannes Berg 	stats->flag |= RX_FLAG_PN_VALIDATED;
86f5e28eacSJohannes Berg 
87f5e28eacSJohannes Berg 	return 0;
88f5e28eacSJohannes Berg }
89f5e28eacSJohannes Berg 
90f5e28eacSJohannes Berg /* iwl_mvm_create_skb Adds the rxb to a new skb */
iwl_mvm_create_skb(struct iwl_mvm * mvm,struct sk_buff * skb,struct ieee80211_hdr * hdr,u16 len,u8 crypt_len,struct iwl_rx_cmd_buffer * rxb)91de1887c0SLuca Coelho static int iwl_mvm_create_skb(struct iwl_mvm *mvm, struct sk_buff *skb,
92de1887c0SLuca Coelho 			      struct ieee80211_hdr *hdr, u16 len, u8 crypt_len,
93780e87c2SJohannes Berg 			      struct iwl_rx_cmd_buffer *rxb)
94780e87c2SJohannes Berg {
95e29cc6b9SSara Sharon 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
96e29cc6b9SSara Sharon 	struct iwl_rx_mpdu_desc *desc = (void *)pkt->data;
97e29cc6b9SSara Sharon 	unsigned int headlen, fraglen, pad_len = 0;
98e29cc6b9SSara Sharon 	unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control);
9940a0b38dSIlan Peer 	u8 mic_crc_len = u8_get_bits(desc->mac_flags1,
10040a0b38dSIlan Peer 				     IWL_RX_MPDU_MFLG1_MIC_CRC_LEN_MASK) << 1;
101e29cc6b9SSara Sharon 
1024b40571eSJohannes Berg 	if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) {
1031e5b7750SJohannes Berg 		len -= 2;
104e29cc6b9SSara Sharon 		pad_len = 2;
1054b40571eSJohannes Berg 	}
106780e87c2SJohannes Berg 
10740a0b38dSIlan Peer 	/*
10840a0b38dSIlan Peer 	 * For non monitor interface strip the bytes the RADA might not have
1097b41a99cSJohannes Berg 	 * removed (it might be disabled, e.g. for mgmt frames). As a monitor
1107b41a99cSJohannes Berg 	 * interface cannot exist with other interfaces, this removal is safe
1117b41a99cSJohannes Berg 	 * and sufficient, in monitor mode there's no decryption being done.
11240a0b38dSIlan Peer 	 */
1137b41a99cSJohannes Berg 	if (len > mic_crc_len && !ieee80211_hw_check(mvm->hw, RX_INCLUDES_FCS))
11440a0b38dSIlan Peer 		len -= mic_crc_len;
11540a0b38dSIlan Peer 
116780e87c2SJohannes Berg 	/* If frame is small enough to fit in skb->head, pull it completely.
117780e87c2SJohannes Berg 	 * If not, only pull ieee80211_hdr (including crypto if present, and
118780e87c2SJohannes Berg 	 * an additional 8 bytes for SNAP/ethertype, see below) so that
119780e87c2SJohannes Berg 	 * splice() or TCP coalesce are more efficient.
120780e87c2SJohannes Berg 	 *
121780e87c2SJohannes Berg 	 * Since, in addition, ieee80211_data_to_8023() always pull in at
122780e87c2SJohannes Berg 	 * least 8 bytes (possibly more for mesh) we can do the same here
123780e87c2SJohannes Berg 	 * to save the cost of doing it later. That still doesn't pull in
124780e87c2SJohannes Berg 	 * the actual IP header since the typical case has a SNAP header.
125780e87c2SJohannes Berg 	 * If the latter changes (there are efforts in the standards group
126780e87c2SJohannes Berg 	 * to do so) we should revisit this and ieee80211_data_to_8023().
127780e87c2SJohannes Berg 	 */
128e29cc6b9SSara Sharon 	headlen = (len <= skb_tailroom(skb)) ? len :
129e29cc6b9SSara Sharon 					       hdrlen + crypt_len + 8;
130780e87c2SJohannes Berg 
131e29cc6b9SSara Sharon 	/* The firmware may align the packet to DWORD.
132e29cc6b9SSara Sharon 	 * The padding is inserted after the IV.
133e29cc6b9SSara Sharon 	 * After copying the header + IV skip the padding if
134e29cc6b9SSara Sharon 	 * present before copying packet data.
135e29cc6b9SSara Sharon 	 */
136e29cc6b9SSara Sharon 	hdrlen += crypt_len;
137de1887c0SLuca Coelho 
1388ccb768cSJohannes Berg 	if (unlikely(headlen < hdrlen))
139de1887c0SLuca Coelho 		return -EINVAL;
140de1887c0SLuca Coelho 
1413f7a9d57SMordechay Goodstein 	/* Since data doesn't move data while putting data on skb and that is
1423f7a9d57SMordechay Goodstein 	 * the only way we use, data + len is the next place that hdr would be put
1433f7a9d57SMordechay Goodstein 	 */
1443f7a9d57SMordechay Goodstein 	skb_set_mac_header(skb, skb->len);
14559ae1d12SJohannes Berg 	skb_put_data(skb, hdr, hdrlen);
14659ae1d12SJohannes Berg 	skb_put_data(skb, (u8 *)hdr + hdrlen + pad_len, headlen - hdrlen);
147e29cc6b9SSara Sharon 
14859ca9572SJohannes Berg 	/*
14959ca9572SJohannes Berg 	 * If we did CHECKSUM_COMPLETE, the hardware only does it right for
15059ca9572SJohannes Berg 	 * certain cases and starts the checksum after the SNAP. Check if
15159ca9572SJohannes Berg 	 * this is the case - it's easier to just bail out to CHECKSUM_NONE
15259ca9572SJohannes Berg 	 * in the cases the hardware didn't handle, since it's rare to see
15359ca9572SJohannes Berg 	 * such packets, even though the hardware did calculate the checksum
15459ca9572SJohannes Berg 	 * in this case, just starting after the MAC header instead.
155b6f5b647SJohannes Berg 	 *
156b6f5b647SJohannes Berg 	 * Starting from Bz hardware, it calculates starting directly after
157b6f5b647SJohannes Berg 	 * the MAC header, so that matches mac80211's expectation.
15859ca9572SJohannes Berg 	 */
159217f3c52SAvraham Stern 	if (skb->ip_summed == CHECKSUM_COMPLETE) {
16059ca9572SJohannes Berg 		struct {
16159ca9572SJohannes Berg 			u8 hdr[6];
16259ca9572SJohannes Berg 			__be16 type;
16359ca9572SJohannes Berg 		} __packed *shdr = (void *)((u8 *)hdr + hdrlen + pad_len);
16459ca9572SJohannes Berg 
16559ca9572SJohannes Berg 		if (unlikely(headlen - hdrlen < sizeof(*shdr) ||
16659ca9572SJohannes Berg 			     !ether_addr_equal(shdr->hdr, rfc1042_header) ||
16759ca9572SJohannes Berg 			     (shdr->type != htons(ETH_P_IP) &&
16859ca9572SJohannes Berg 			      shdr->type != htons(ETH_P_ARP) &&
16959ca9572SJohannes Berg 			      shdr->type != htons(ETH_P_IPV6) &&
17059ca9572SJohannes Berg 			      shdr->type != htons(ETH_P_8021Q) &&
17159ca9572SJohannes Berg 			      shdr->type != htons(ETH_P_PAE) &&
17259ca9572SJohannes Berg 			      shdr->type != htons(ETH_P_TDLS))))
17359ca9572SJohannes Berg 			skb->ip_summed = CHECKSUM_NONE;
174217f3c52SAvraham Stern 		else if (mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_BZ)
175667aa742SJohannes Berg 			/* mac80211 assumes full CSUM including SNAP header */
176667aa742SJohannes Berg 			skb_postpush_rcsum(skb, shdr, sizeof(*shdr));
17759ca9572SJohannes Berg 	}
17859ca9572SJohannes Berg 
179e29cc6b9SSara Sharon 	fraglen = len - headlen;
180780e87c2SJohannes Berg 
181780e87c2SJohannes Berg 	if (fraglen) {
1823827cb59SJohannes Berg 		int offset = (u8 *)hdr + headlen + pad_len -
1833827cb59SJohannes Berg 			     (u8 *)rxb_addr(rxb) + rxb_offset(rxb);
184780e87c2SJohannes Berg 
185780e87c2SJohannes Berg 		skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset,
186780e87c2SJohannes Berg 				fraglen, rxb->truesize);
187780e87c2SJohannes Berg 	}
188de1887c0SLuca Coelho 
189de1887c0SLuca Coelho 	return 0;
190f5e28eacSJohannes Berg }
191780e87c2SJohannes Berg 
192056805bcSMordechay Goodstein /* put a TLV on the skb and return data pointer
193056805bcSMordechay Goodstein  *
194056805bcSMordechay Goodstein  * Also pad to 4 the len and zero out all data part
195056805bcSMordechay Goodstein  */
196056805bcSMordechay Goodstein static void *
iwl_mvm_radiotap_put_tlv(struct sk_buff * skb,u16 type,u16 len)197056805bcSMordechay Goodstein iwl_mvm_radiotap_put_tlv(struct sk_buff *skb, u16 type, u16 len)
198056805bcSMordechay Goodstein {
199056805bcSMordechay Goodstein 	struct ieee80211_radiotap_tlv *tlv;
200056805bcSMordechay Goodstein 
201056805bcSMordechay Goodstein 	tlv = skb_put(skb, sizeof(*tlv));
202056805bcSMordechay Goodstein 	tlv->type = cpu_to_le16(type);
203056805bcSMordechay Goodstein 	tlv->len = cpu_to_le16(len);
204056805bcSMordechay Goodstein 	return skb_put_zero(skb, ALIGN(len, 4));
205056805bcSMordechay Goodstein }
206056805bcSMordechay Goodstein 
iwl_mvm_add_rtap_sniffer_config(struct iwl_mvm * mvm,struct sk_buff * skb)2079bf13beeSJohannes Berg static void iwl_mvm_add_rtap_sniffer_config(struct iwl_mvm *mvm,
2089bf13beeSJohannes Berg 					    struct sk_buff *skb)
2099bf13beeSJohannes Berg {
2109bf13beeSJohannes Berg 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
211056805bcSMordechay Goodstein 	struct ieee80211_radiotap_vendor_content *radiotap;
2129179dff8SMordechay Goodstein 	const u16 vendor_data_len = sizeof(mvm->cur_aid);
2139bf13beeSJohannes Berg 
2149bf13beeSJohannes Berg 	if (!mvm->cur_aid)
2159bf13beeSJohannes Berg 		return;
2169bf13beeSJohannes Berg 
217056805bcSMordechay Goodstein 	radiotap = iwl_mvm_radiotap_put_tlv(skb,
218056805bcSMordechay Goodstein 					    IEEE80211_RADIOTAP_VENDOR_NAMESPACE,
219056805bcSMordechay Goodstein 					    sizeof(*radiotap) + vendor_data_len);
2203619b088SJohannes Berg 
2219bf13beeSJohannes Berg 	/* Intel OUI */
222056805bcSMordechay Goodstein 	radiotap->oui[0] = 0xf6;
223056805bcSMordechay Goodstein 	radiotap->oui[1] = 0x54;
224056805bcSMordechay Goodstein 	radiotap->oui[2] = 0x25;
2259bf13beeSJohannes Berg 	/* radiotap sniffer config sub-namespace */
226056805bcSMordechay Goodstein 	radiotap->oui_subtype = 1;
227056805bcSMordechay Goodstein 	radiotap->vendor_type = 0;
228056805bcSMordechay Goodstein 
2299bf13beeSJohannes Berg 	/* fill the data now */
230056805bcSMordechay Goodstein 	memcpy(radiotap->data, &mvm->cur_aid, sizeof(mvm->cur_aid));
2319bf13beeSJohannes Berg 
2329179dff8SMordechay Goodstein 	rx_status->flag |= RX_FLAG_RADIOTAP_TLV_AT_END;
2339bf13beeSJohannes Berg }
2349bf13beeSJohannes Berg 
235f5e28eacSJohannes Berg /* iwl_mvm_pass_packet_to_mac80211 - passes the packet for mac80211 */
iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm * mvm,struct napi_struct * napi,struct sk_buff * skb,int queue,struct ieee80211_sta * sta)236f5e28eacSJohannes Berg static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm *mvm,
237f5e28eacSJohannes Berg 					    struct napi_struct *napi,
238f5e28eacSJohannes Berg 					    struct sk_buff *skb, int queue,
239dc1ec9c5SBenjamin Berg 					    struct ieee80211_sta *sta)
240f5e28eacSJohannes Berg {
241b8a85a1dSJohannes Berg 	if (unlikely(iwl_mvm_check_pn(mvm, skb, queue, sta))) {
242f5e28eacSJohannes Berg 		kfree_skb(skb);
243b8a85a1dSJohannes Berg 		return;
244b8a85a1dSJohannes Berg 	}
245b8a85a1dSJohannes Berg 
24643ec72b7SJohannes Berg 	ieee80211_rx_napi(mvm->hw, sta, skb, napi);
247780e87c2SJohannes Berg }
248780e87c2SJohannes Berg 
iwl_mvm_get_signal_strength(struct iwl_mvm * mvm,struct ieee80211_rx_status * rx_status,u32 rate_n_flags,int energy_a,int energy_b)249780e87c2SJohannes Berg static void iwl_mvm_get_signal_strength(struct iwl_mvm *mvm,
25018ead597SGolan Ben Ami 					struct ieee80211_rx_status *rx_status,
25118ead597SGolan Ben Ami 					u32 rate_n_flags, int energy_a,
25218ead597SGolan Ben Ami 					int energy_b)
253780e87c2SJohannes Berg {
25418ead597SGolan Ben Ami 	int max_energy;
25518ead597SGolan Ben Ami 	u32 rate_flags = rate_n_flags;
256780e87c2SJohannes Berg 
257780e87c2SJohannes Berg 	energy_a = energy_a ? -energy_a : S8_MIN;
258780e87c2SJohannes Berg 	energy_b = energy_b ? -energy_b : S8_MIN;
259780e87c2SJohannes Berg 	max_energy = max(energy_a, energy_b);
260780e87c2SJohannes Berg 
261d56a7801SSara Sharon 	IWL_DEBUG_STATS(mvm, "energy In A %d B %d, and max %d\n",
262d56a7801SSara Sharon 			energy_a, energy_b, max_energy);
263780e87c2SJohannes Berg 
264780e87c2SJohannes Berg 	rx_status->signal = max_energy;
265c4e45c84SShaul Triebitz 	rx_status->chains =
266c4e45c84SShaul Triebitz 		(rate_flags & RATE_MCS_ANT_AB_MSK) >> RATE_MCS_ANT_POS;
267780e87c2SJohannes Berg 	rx_status->chain_signal[0] = energy_a;
268780e87c2SJohannes Berg 	rx_status->chain_signal[1] = energy_b;
269780e87c2SJohannes Berg }
270780e87c2SJohannes Berg 
iwl_mvm_rx_mgmt_prot(struct ieee80211_sta * sta,struct ieee80211_hdr * hdr,struct iwl_rx_mpdu_desc * desc,u32 status,struct ieee80211_rx_status * stats)27165db391dSJohannes Berg static int iwl_mvm_rx_mgmt_prot(struct ieee80211_sta *sta,
272b1fdc250SJohannes Berg 				struct ieee80211_hdr *hdr,
273b1fdc250SJohannes Berg 				struct iwl_rx_mpdu_desc *desc,
2742db72b8aSJohannes Berg 				u32 status,
2752db72b8aSJohannes Berg 				struct ieee80211_rx_status *stats)
276b1fdc250SJohannes Berg {
27770104eb7SJohannes Berg 	struct wireless_dev *wdev;
278b1fdc250SJohannes Berg 	struct iwl_mvm_sta *mvmsta;
279b1fdc250SJohannes Berg 	struct iwl_mvm_vif *mvmvif;
280b1fdc250SJohannes Berg 	u8 keyid;
281b1fdc250SJohannes Berg 	struct ieee80211_key_conf *key;
282b1fdc250SJohannes Berg 	u32 len = le16_to_cpu(desc->mpdu_len);
283b1fdc250SJohannes Berg 	const u8 *frame = (void *)hdr;
284b1fdc250SJohannes Berg 
28565db391dSJohannes Berg 	if ((status & IWL_RX_MPDU_STATUS_SEC_MASK) == IWL_RX_MPDU_STATUS_SEC_NONE)
28665db391dSJohannes Berg 		return 0;
28765db391dSJohannes Berg 
288b1fdc250SJohannes Berg 	/*
289b1fdc250SJohannes Berg 	 * For non-beacon, we don't really care. But beacons may
290b1fdc250SJohannes Berg 	 * be filtered out, and we thus need the firmware's replay
291b1fdc250SJohannes Berg 	 * detection, otherwise beacons the firmware previously
292b1fdc250SJohannes Berg 	 * filtered could be replayed, or something like that, and
293b1fdc250SJohannes Berg 	 * it can filter a lot - though usually only if nothing has
294b1fdc250SJohannes Berg 	 * changed.
295b1fdc250SJohannes Berg 	 */
296b1fdc250SJohannes Berg 	if (!ieee80211_is_beacon(hdr->frame_control))
297b1fdc250SJohannes Berg 		return 0;
298b1fdc250SJohannes Berg 
29970104eb7SJohannes Berg 	if (!sta)
30070104eb7SJohannes Berg 		return -1;
30170104eb7SJohannes Berg 
30270104eb7SJohannes Berg 	mvmsta = iwl_mvm_sta_from_mac80211(sta);
30370104eb7SJohannes Berg 	mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
30470104eb7SJohannes Berg 
305e257d969SJohannes Berg 	/* key mismatch - will also report !MIC_OK but we shouldn't count it */
306e257d969SJohannes Berg 	if (!(status & IWL_RX_MPDU_STATUS_KEY_VALID))
30770104eb7SJohannes Berg 		goto report;
308e257d969SJohannes Berg 
309b1fdc250SJohannes Berg 	/* good cases */
310b1fdc250SJohannes Berg 	if (likely(status & IWL_RX_MPDU_STATUS_MIC_OK &&
3112db72b8aSJohannes Berg 		   !(status & IWL_RX_MPDU_STATUS_REPLAY_ERROR))) {
3122db72b8aSJohannes Berg 		stats->flag |= RX_FLAG_DECRYPTED;
313b1fdc250SJohannes Berg 		return 0;
3142db72b8aSJohannes Berg 	}
315b1fdc250SJohannes Berg 
316e257d969SJohannes Berg 	/*
317e257d969SJohannes Berg 	 * both keys will have the same cipher and MIC length, use
318e257d969SJohannes Berg 	 * whichever one is available
319e257d969SJohannes Berg 	 */
320e257d969SJohannes Berg 	key = rcu_dereference(mvmvif->bcn_prot.keys[0]);
321e257d969SJohannes Berg 	if (!key) {
322e257d969SJohannes Berg 		key = rcu_dereference(mvmvif->bcn_prot.keys[1]);
323b1fdc250SJohannes Berg 		if (!key)
32470104eb7SJohannes Berg 			goto report;
325e257d969SJohannes Berg 	}
326b1fdc250SJohannes Berg 
327b1fdc250SJohannes Berg 	if (len < key->icv_len + IEEE80211_GMAC_PN_LEN + 2)
32870104eb7SJohannes Berg 		goto report;
329b1fdc250SJohannes Berg 
330e257d969SJohannes Berg 	/* get the real key ID */
331b1fdc250SJohannes Berg 	keyid = frame[len - key->icv_len - IEEE80211_GMAC_PN_LEN - 2];
332e257d969SJohannes Berg 	/* and if that's the other key, look it up */
333e257d969SJohannes Berg 	if (keyid != key->keyidx) {
334e257d969SJohannes Berg 		/*
335e257d969SJohannes Berg 		 * shouldn't happen since firmware checked, but be safe
336e257d969SJohannes Berg 		 * in case the MIC length is wrong too, for example
337e257d969SJohannes Berg 		 */
338e257d969SJohannes Berg 		if (keyid != 6 && keyid != 7)
339b1fdc250SJohannes Berg 			return -1;
340e257d969SJohannes Berg 		key = rcu_dereference(mvmvif->bcn_prot.keys[keyid - 6]);
341e257d969SJohannes Berg 		if (!key)
34270104eb7SJohannes Berg 			goto report;
343e257d969SJohannes Berg 	}
344b1fdc250SJohannes Berg 
345b1fdc250SJohannes Berg 	/* Report status to mac80211 */
346b1fdc250SJohannes Berg 	if (!(status & IWL_RX_MPDU_STATUS_MIC_OK))
347b1fdc250SJohannes Berg 		ieee80211_key_mic_failure(key);
348b1fdc250SJohannes Berg 	else if (status & IWL_RX_MPDU_STATUS_REPLAY_ERROR)
349b1fdc250SJohannes Berg 		ieee80211_key_replay(key);
35070104eb7SJohannes Berg report:
35170104eb7SJohannes Berg 	wdev = ieee80211_vif_to_wdev(mvmsta->vif);
35270104eb7SJohannes Berg 	if (wdev->netdev)
35370104eb7SJohannes Berg 		cfg80211_rx_unprot_mlme_mgmt(wdev->netdev, (void *)hdr, len);
354b1fdc250SJohannes Berg 
355b1fdc250SJohannes Berg 	return -1;
356b1fdc250SJohannes Berg }
357b1fdc250SJohannes Berg 
iwl_mvm_rx_crypto(struct iwl_mvm * mvm,struct ieee80211_sta * sta,struct ieee80211_hdr * hdr,struct ieee80211_rx_status * stats,u16 phy_info,struct iwl_rx_mpdu_desc * desc,u32 pkt_flags,int queue,u8 * crypt_len)358b1fdc250SJohannes Berg static int iwl_mvm_rx_crypto(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
359b1fdc250SJohannes Berg 			     struct ieee80211_hdr *hdr,
360fabdcc2eSSara Sharon 			     struct ieee80211_rx_status *stats, u16 phy_info,
361fabdcc2eSSara Sharon 			     struct iwl_rx_mpdu_desc *desc,
362fabdcc2eSSara Sharon 			     u32 pkt_flags, int queue, u8 *crypt_len)
363780e87c2SJohannes Berg {
364e365e7deSJohannes Berg 	u32 status = le32_to_cpu(desc->status);
365780e87c2SJohannes Berg 
366fabdcc2eSSara Sharon 	/*
367fabdcc2eSSara Sharon 	 * Drop UNKNOWN frames in aggregation, unless in monitor mode
368fabdcc2eSSara Sharon 	 * (where we don't have the keys).
369fabdcc2eSSara Sharon 	 * We limit this to aggregation because in TKIP this is a valid
370fabdcc2eSSara Sharon 	 * scenario, since we may not have the (correct) TTAK (phase 1
371fabdcc2eSSara Sharon 	 * key) in the firmware.
372fabdcc2eSSara Sharon 	 */
373fabdcc2eSSara Sharon 	if (phy_info & IWL_RX_MPDU_PHY_AMPDU &&
374fabdcc2eSSara Sharon 	    (status & IWL_RX_MPDU_STATUS_SEC_MASK) ==
375fabdcc2eSSara Sharon 	    IWL_RX_MPDU_STATUS_SEC_UNKNOWN && !mvm->monitor_on)
376fabdcc2eSSara Sharon 		return -1;
377fabdcc2eSSara Sharon 
37865db391dSJohannes Berg 	if (unlikely(ieee80211_is_mgmt(hdr->frame_control) &&
37965db391dSJohannes Berg 		     !ieee80211_has_protected(hdr->frame_control)))
3802db72b8aSJohannes Berg 		return iwl_mvm_rx_mgmt_prot(sta, hdr, desc, status, stats);
38165db391dSJohannes Berg 
382780e87c2SJohannes Berg 	if (!ieee80211_has_protected(hdr->frame_control) ||
383780e87c2SJohannes Berg 	    (status & IWL_RX_MPDU_STATUS_SEC_MASK) ==
384780e87c2SJohannes Berg 	    IWL_RX_MPDU_STATUS_SEC_NONE)
385780e87c2SJohannes Berg 		return 0;
386780e87c2SJohannes Berg 
387780e87c2SJohannes Berg 	/* TODO: handle packets encrypted with unknown alg */
388780e87c2SJohannes Berg 
389780e87c2SJohannes Berg 	switch (status & IWL_RX_MPDU_STATUS_SEC_MASK) {
390780e87c2SJohannes Berg 	case IWL_RX_MPDU_STATUS_SEC_CCM:
391780e87c2SJohannes Berg 	case IWL_RX_MPDU_STATUS_SEC_GCM:
392f5e28eacSJohannes Berg 		BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN != IEEE80211_GCMP_PN_LEN);
393780e87c2SJohannes Berg 		/* alg is CCM: check MIC only */
394780e87c2SJohannes Berg 		if (!(status & IWL_RX_MPDU_STATUS_MIC_OK))
395780e87c2SJohannes Berg 			return -1;
396780e87c2SJohannes Berg 
3977b41a99cSJohannes Berg 		stats->flag |= RX_FLAG_DECRYPTED | RX_FLAG_MIC_STRIPPED;
398780e87c2SJohannes Berg 		*crypt_len = IEEE80211_CCMP_HDR_LEN;
399780e87c2SJohannes Berg 		return 0;
400780e87c2SJohannes Berg 	case IWL_RX_MPDU_STATUS_SEC_TKIP:
401780e87c2SJohannes Berg 		/* Don't drop the frame and decrypt it in SW */
40257df3839SSara Sharon 		if (!fw_has_api(&mvm->fw->ucode_capa,
40357df3839SSara Sharon 				IWL_UCODE_TLV_API_DEPRECATE_TTAK) &&
40457df3839SSara Sharon 		    !(status & IWL_RX_MPDU_RES_STATUS_TTAK_OK))
405780e87c2SJohannes Berg 			return 0;
406780e87c2SJohannes Berg 
407286ca8ebSLuca Coelho 		if (mvm->trans->trans_cfg->gen2 &&
4087f768ad5SDavid Spinadel 		    !(status & RX_MPDU_RES_STATUS_MIC_OK))
4097f768ad5SDavid Spinadel 			stats->flag |= RX_FLAG_MMIC_ERROR;
4107f768ad5SDavid Spinadel 
411780e87c2SJohannes Berg 		*crypt_len = IEEE80211_TKIP_IV_LEN;
4125a2abdcaSGustavo A. R. Silva 		fallthrough;
413780e87c2SJohannes Berg 	case IWL_RX_MPDU_STATUS_SEC_WEP:
414780e87c2SJohannes Berg 		if (!(status & IWL_RX_MPDU_STATUS_ICV_OK))
415780e87c2SJohannes Berg 			return -1;
416780e87c2SJohannes Berg 
417780e87c2SJohannes Berg 		stats->flag |= RX_FLAG_DECRYPTED;
418780e87c2SJohannes Berg 		if ((status & IWL_RX_MPDU_STATUS_SEC_MASK) ==
419780e87c2SJohannes Berg 				IWL_RX_MPDU_STATUS_SEC_WEP)
420780e87c2SJohannes Berg 			*crypt_len = IEEE80211_WEP_IV_LEN;
4219d0fc5a5SDavid Spinadel 
4227f768ad5SDavid Spinadel 		if (pkt_flags & FH_RSCSR_RADA_EN) {
4239d0fc5a5SDavid Spinadel 			stats->flag |= RX_FLAG_ICV_STRIPPED;
424286ca8ebSLuca Coelho 			if (mvm->trans->trans_cfg->gen2)
4257f768ad5SDavid Spinadel 				stats->flag |= RX_FLAG_MMIC_STRIPPED;
4267f768ad5SDavid Spinadel 		}
4279d0fc5a5SDavid Spinadel 
428780e87c2SJohannes Berg 		return 0;
429780e87c2SJohannes Berg 	case IWL_RX_MPDU_STATUS_SEC_EXT_ENC:
430780e87c2SJohannes Berg 		if (!(status & IWL_RX_MPDU_STATUS_MIC_OK))
431780e87c2SJohannes Berg 			return -1;
432780e87c2SJohannes Berg 		stats->flag |= RX_FLAG_DECRYPTED;
433780e87c2SJohannes Berg 		return 0;
434b1fdc250SJohannes Berg 	case RX_MPDU_RES_STATUS_SEC_CMAC_GMAC_ENC:
43565db391dSJohannes Berg 		break;
436780e87c2SJohannes Berg 	default:
43794b952b5SEmmanuel Grumbach 		/*
43894b952b5SEmmanuel Grumbach 		 * Sometimes we can get frames that were not decrypted
43994b952b5SEmmanuel Grumbach 		 * because the firmware didn't have the keys yet. This can
44094b952b5SEmmanuel Grumbach 		 * happen after connection where we can get multicast frames
44194b952b5SEmmanuel Grumbach 		 * before the GTK is installed.
44294b952b5SEmmanuel Grumbach 		 * Silently drop those frames.
44394b952b5SEmmanuel Grumbach 		 * Also drop un-decrypted frames in monitor mode.
44494b952b5SEmmanuel Grumbach 		 */
44594b952b5SEmmanuel Grumbach 		if (!is_multicast_ether_addr(hdr->addr1) &&
44694b952b5SEmmanuel Grumbach 		    !mvm->monitor_on && net_ratelimit())
447876882b5SGolan Ben Ami 			IWL_WARN(mvm, "Unhandled alg: 0x%x\n", status);
448780e87c2SJohannes Berg 	}
449780e87c2SJohannes Berg 
450780e87c2SJohannes Berg 	return 0;
451780e87c2SJohannes Berg }
452780e87c2SJohannes Berg 
iwl_mvm_rx_csum(struct iwl_mvm * mvm,struct ieee80211_sta * sta,struct sk_buff * skb,struct iwl_rx_packet * pkt)45359ca9572SJohannes Berg static void iwl_mvm_rx_csum(struct iwl_mvm *mvm,
45459ca9572SJohannes Berg 			    struct ieee80211_sta *sta,
455780e87c2SJohannes Berg 			    struct sk_buff *skb,
45659ca9572SJohannes Berg 			    struct iwl_rx_packet *pkt)
457780e87c2SJohannes Berg {
45859ca9572SJohannes Berg 	struct iwl_rx_mpdu_desc *desc = (void *)pkt->data;
45959ca9572SJohannes Berg 
46059ca9572SJohannes Berg 	if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) {
46159ca9572SJohannes Berg 		if (pkt->len_n_flags & cpu_to_le32(FH_RSCSR_RPA_EN)) {
46259ca9572SJohannes Berg 			u16 hwsum = be16_to_cpu(desc->v3.raw_xsum);
46359ca9572SJohannes Berg 
46459ca9572SJohannes Berg 			skb->ip_summed = CHECKSUM_COMPLETE;
46559ca9572SJohannes Berg 			skb->csum = csum_unfold(~(__force __sum16)hwsum);
46659ca9572SJohannes Berg 		}
46759ca9572SJohannes Berg 	} else {
468780e87c2SJohannes Berg 		struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
46959ca9572SJohannes Berg 		struct iwl_mvm_vif *mvmvif;
470b238be07SSara Sharon 		u16 flags = le16_to_cpu(desc->l3l4_flags);
471b238be07SSara Sharon 		u8 l3_prot = (u8)((flags & IWL_RX_L3L4_L3_PROTO_MASK) >>
472b238be07SSara Sharon 				  IWL_RX_L3_PROTO_POS);
473780e87c2SJohannes Berg 
47459ca9572SJohannes Berg 		mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
47559ca9572SJohannes Berg 
476780e87c2SJohannes Berg 		if (mvmvif->features & NETIF_F_RXCSUM &&
477b238be07SSara Sharon 		    flags & IWL_RX_L3L4_TCP_UDP_CSUM_OK &&
478b238be07SSara Sharon 		    (flags & IWL_RX_L3L4_IP_HDR_CSUM_OK ||
479b238be07SSara Sharon 		     l3_prot == IWL_RX_L3_TYPE_IPV6 ||
480b238be07SSara Sharon 		     l3_prot == IWL_RX_L3_TYPE_IPV6_FRAG))
481780e87c2SJohannes Berg 			skb->ip_summed = CHECKSUM_UNNECESSARY;
482780e87c2SJohannes Berg 	}
48359ca9572SJohannes Berg }
484780e87c2SJohannes Berg 
485a571f5f6SSara Sharon /*
486aedb2b38SAnjaneyulu  * returns true if a packet is a duplicate or invalid tid and should be dropped.
4875ab2ba93SSara Sharon  * Updates AMSDU PN tracking info
488a571f5f6SSara Sharon  */
iwl_mvm_is_dup(struct ieee80211_sta * sta,int queue,struct ieee80211_rx_status * rx_status,struct ieee80211_hdr * hdr,struct iwl_rx_mpdu_desc * desc)4895ab2ba93SSara Sharon static bool iwl_mvm_is_dup(struct ieee80211_sta *sta, int queue,
490a571f5f6SSara Sharon 			   struct ieee80211_rx_status *rx_status,
491a571f5f6SSara Sharon 			   struct ieee80211_hdr *hdr,
492a571f5f6SSara Sharon 			   struct iwl_rx_mpdu_desc *desc)
493a571f5f6SSara Sharon {
494a571f5f6SSara Sharon 	struct iwl_mvm_sta *mvm_sta;
495a571f5f6SSara Sharon 	struct iwl_mvm_rxq_dup_data *dup_data;
4965ab2ba93SSara Sharon 	u8 tid, sub_frame_idx;
497a571f5f6SSara Sharon 
498a571f5f6SSara Sharon 	if (WARN_ON(IS_ERR_OR_NULL(sta)))
499a571f5f6SSara Sharon 		return false;
500a571f5f6SSara Sharon 
501a571f5f6SSara Sharon 	mvm_sta = iwl_mvm_sta_from_mac80211(sta);
50200f4eb31SEmmanuel Grumbach 
50300f4eb31SEmmanuel Grumbach 	if (WARN_ON_ONCE(!mvm_sta->dup_data))
50400f4eb31SEmmanuel Grumbach 		return false;
50500f4eb31SEmmanuel Grumbach 
506a571f5f6SSara Sharon 	dup_data = &mvm_sta->dup_data[queue];
507a571f5f6SSara Sharon 
508a571f5f6SSara Sharon 	/*
509a571f5f6SSara Sharon 	 * Drop duplicate 802.11 retransmissions
510a571f5f6SSara Sharon 	 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
511a571f5f6SSara Sharon 	 */
512a571f5f6SSara Sharon 	if (ieee80211_is_ctl(hdr->frame_control) ||
513a571f5f6SSara Sharon 	    ieee80211_is_qos_nullfunc(hdr->frame_control) ||
514a571f5f6SSara Sharon 	    is_multicast_ether_addr(hdr->addr1)) {
515a571f5f6SSara Sharon 		rx_status->flag |= RX_FLAG_DUP_VALIDATED;
516a571f5f6SSara Sharon 		return false;
517a571f5f6SSara Sharon 	}
518a571f5f6SSara Sharon 
519aedb2b38SAnjaneyulu 	if (ieee80211_is_data_qos(hdr->frame_control)) {
520a571f5f6SSara Sharon 		/* frame has qos control */
5218f66e064SSara Sharon 		tid = ieee80211_get_tid(hdr);
522aedb2b38SAnjaneyulu 		if (tid >= IWL_MAX_TID_COUNT)
523aedb2b38SAnjaneyulu 			return true;
524aedb2b38SAnjaneyulu 	} else {
525a571f5f6SSara Sharon 		tid = IWL_MAX_TID_COUNT;
526aedb2b38SAnjaneyulu 	}
527a571f5f6SSara Sharon 
528a571f5f6SSara Sharon 	/* If this wasn't a part of an A-MSDU the sub-frame index will be 0 */
52918ead597SGolan Ben Ami 	sub_frame_idx = desc->amsdu_info &
53018ead597SGolan Ben Ami 		IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK;
531a571f5f6SSara Sharon 
532a571f5f6SSara Sharon 	if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
533a571f5f6SSara Sharon 		     dup_data->last_seq[tid] == hdr->seq_ctrl &&
534a571f5f6SSara Sharon 		     dup_data->last_sub_frame[tid] >= sub_frame_idx))
535a571f5f6SSara Sharon 		return true;
536a571f5f6SSara Sharon 
5375ab2ba93SSara Sharon 	/* Allow same PN as the first subframe for following sub frames */
5385ab2ba93SSara Sharon 	if (dup_data->last_seq[tid] == hdr->seq_ctrl &&
5395ab2ba93SSara Sharon 	    sub_frame_idx > dup_data->last_sub_frame[tid] &&
5405ab2ba93SSara Sharon 	    desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU)
5415ab2ba93SSara Sharon 		rx_status->flag |= RX_FLAG_ALLOW_SAME_PN;
5425ab2ba93SSara Sharon 
543a571f5f6SSara Sharon 	dup_data->last_seq[tid] = hdr->seq_ctrl;
544a571f5f6SSara Sharon 	dup_data->last_sub_frame[tid] = sub_frame_idx;
545a571f5f6SSara Sharon 
546a571f5f6SSara Sharon 	rx_status->flag |= RX_FLAG_DUP_VALIDATED;
547a571f5f6SSara Sharon 
548a571f5f6SSara Sharon 	return false;
549a571f5f6SSara Sharon }
550a571f5f6SSara Sharon 
55174dd1764SSara Sharon /*
55274dd1764SSara Sharon  * Returns true if sn2 - buffer_size < sn1 < sn2.
55374dd1764SSara Sharon  * To be used only in order to compare reorder buffer head with NSSN.
55474dd1764SSara Sharon  * We fully trust NSSN unless it is behind us due to reorder timeout.
55574dd1764SSara Sharon  * Reorder timeout can only bring us up to buffer_size SNs ahead of NSSN.
55674dd1764SSara Sharon  */
iwl_mvm_is_sn_less(u16 sn1,u16 sn2,u16 buffer_size)55774dd1764SSara Sharon static bool iwl_mvm_is_sn_less(u16 sn1, u16 sn2, u16 buffer_size)
55874dd1764SSara Sharon {
55974dd1764SSara Sharon 	return ieee80211_sn_less(sn1, sn2) &&
56074dd1764SSara Sharon 	       !ieee80211_sn_less(sn1, sn2 - buffer_size);
56174dd1764SSara Sharon }
56274dd1764SSara Sharon 
iwl_mvm_sync_nssn(struct iwl_mvm * mvm,u8 baid,u16 nssn)5633c514bf8SEmmanuel Grumbach static void iwl_mvm_sync_nssn(struct iwl_mvm *mvm, u8 baid, u16 nssn)
5643c514bf8SEmmanuel Grumbach {
565d829229eSEmmanuel Grumbach 	if (IWL_MVM_USE_NSSN_SYNC) {
5665e1688ceSJohannes Berg 		struct iwl_mvm_nssn_sync_data notif = {
5675e1688ceSJohannes Berg 			.baid = baid,
5685e1688ceSJohannes Berg 			.nssn = nssn,
5693c514bf8SEmmanuel Grumbach 		};
5703c514bf8SEmmanuel Grumbach 
5715e1688ceSJohannes Berg 		iwl_mvm_sync_rx_queues_internal(mvm, IWL_MVM_RXQ_NSSN_SYNC, false,
5725e1688ceSJohannes Berg 						&notif, sizeof(notif));
573d829229eSEmmanuel Grumbach 	}
5743c514bf8SEmmanuel Grumbach }
5753c514bf8SEmmanuel Grumbach 
5760690405fSSara Sharon #define RX_REORDER_BUF_TIMEOUT_MQ (HZ / 10)
5770690405fSSara Sharon 
578ecd09ddcSEmmanuel Grumbach enum iwl_mvm_release_flags {
579ecd09ddcSEmmanuel Grumbach 	IWL_MVM_RELEASE_SEND_RSS_SYNC = BIT(0),
580ecd09ddcSEmmanuel Grumbach 	IWL_MVM_RELEASE_FROM_RSS_SYNC = BIT(1),
581ecd09ddcSEmmanuel Grumbach };
582ecd09ddcSEmmanuel Grumbach 
iwl_mvm_release_frames(struct iwl_mvm * mvm,struct ieee80211_sta * sta,struct napi_struct * napi,struct iwl_mvm_baid_data * baid_data,struct iwl_mvm_reorder_buffer * reorder_buf,u16 nssn,u32 flags)583b915c101SSara Sharon static void iwl_mvm_release_frames(struct iwl_mvm *mvm,
584b915c101SSara Sharon 				   struct ieee80211_sta *sta,
585b915c101SSara Sharon 				   struct napi_struct *napi,
58676f4a85eSJohannes Berg 				   struct iwl_mvm_baid_data *baid_data,
587b915c101SSara Sharon 				   struct iwl_mvm_reorder_buffer *reorder_buf,
588ecd09ddcSEmmanuel Grumbach 				   u16 nssn, u32 flags)
589b915c101SSara Sharon {
590dfdddd92SJohannes Berg 	struct iwl_mvm_reorder_buf_entry *entries =
591dfdddd92SJohannes Berg 		&baid_data->entries[reorder_buf->queue *
592dfdddd92SJohannes Berg 				    baid_data->entries_per_queue];
593b915c101SSara Sharon 	u16 ssn = reorder_buf->head_sn;
594b915c101SSara Sharon 
5950690405fSSara Sharon 	lockdep_assert_held(&reorder_buf->lock);
5960690405fSSara Sharon 
597ecd09ddcSEmmanuel Grumbach 	/*
598ecd09ddcSEmmanuel Grumbach 	 * We keep the NSSN not too far behind, if we are sync'ing it and it
599ecd09ddcSEmmanuel Grumbach 	 * is more than 2048 ahead of us, it must be behind us. Discard it.
600ecd09ddcSEmmanuel Grumbach 	 * This can happen if the queue that hit the 0 / 2048 seqno was lagging
601ecd09ddcSEmmanuel Grumbach 	 * behind and this queue already processed packets. The next if
602ecd09ddcSEmmanuel Grumbach 	 * would have caught cases where this queue would have processed less
603ecd09ddcSEmmanuel Grumbach 	 * than 64 packets, but it may have processed more than 64 packets.
604ecd09ddcSEmmanuel Grumbach 	 */
605ecd09ddcSEmmanuel Grumbach 	if ((flags & IWL_MVM_RELEASE_FROM_RSS_SYNC) &&
606ecd09ddcSEmmanuel Grumbach 	    ieee80211_sn_less(nssn, ssn))
607ecd09ddcSEmmanuel Grumbach 		goto set_timer;
608ecd09ddcSEmmanuel Grumbach 
6090690405fSSara Sharon 	/* ignore nssn smaller than head sn - this can happen due to timeout */
61074dd1764SSara Sharon 	if (iwl_mvm_is_sn_less(nssn, ssn, reorder_buf->buf_size))
6115351f9abSSara Sharon 		goto set_timer;
6120690405fSSara Sharon 
61374dd1764SSara Sharon 	while (iwl_mvm_is_sn_less(ssn, nssn, reorder_buf->buf_size)) {
614b915c101SSara Sharon 		int index = ssn % reorder_buf->buf_size;
615dfdddd92SJohannes Berg 		struct sk_buff_head *skb_list = &entries[index].e.frames;
616b915c101SSara Sharon 		struct sk_buff *skb;
617b915c101SSara Sharon 
618b915c101SSara Sharon 		ssn = ieee80211_sn_inc(ssn);
619ecd09ddcSEmmanuel Grumbach 		if ((flags & IWL_MVM_RELEASE_SEND_RSS_SYNC) &&
620ecd09ddcSEmmanuel Grumbach 		    (ssn == 2048 || ssn == 0))
6213c514bf8SEmmanuel Grumbach 			iwl_mvm_sync_nssn(mvm, baid_data->baid, ssn);
622b915c101SSara Sharon 
6235a710b86SSara Sharon 		/*
6245a710b86SSara Sharon 		 * Empty the list. Will have more than one frame for A-MSDU.
6255a710b86SSara Sharon 		 * Empty list is valid as well since nssn indicates frames were
6265a710b86SSara Sharon 		 * received.
6275a710b86SSara Sharon 		 */
628b915c101SSara Sharon 		while ((skb = __skb_dequeue(skb_list))) {
629b915c101SSara Sharon 			iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb,
630b915c101SSara Sharon 							reorder_buf->queue,
631dc1ec9c5SBenjamin Berg 							sta);
632b915c101SSara Sharon 			reorder_buf->num_stored--;
633b915c101SSara Sharon 		}
634b915c101SSara Sharon 	}
635b915c101SSara Sharon 	reorder_buf->head_sn = nssn;
6360690405fSSara Sharon 
6375351f9abSSara Sharon set_timer:
6380690405fSSara Sharon 	if (reorder_buf->num_stored && !reorder_buf->removed) {
6390690405fSSara Sharon 		u16 index = reorder_buf->head_sn % reorder_buf->buf_size;
6400690405fSSara Sharon 
641dfdddd92SJohannes Berg 		while (skb_queue_empty(&entries[index].e.frames))
6420690405fSSara Sharon 			index = (index + 1) % reorder_buf->buf_size;
6430690405fSSara Sharon 		/* modify timer to match next frame's expiration time */
6440690405fSSara Sharon 		mod_timer(&reorder_buf->reorder_timer,
645dfdddd92SJohannes Berg 			  entries[index].e.reorder_time + 1 +
6460690405fSSara Sharon 			  RX_REORDER_BUF_TIMEOUT_MQ);
6470690405fSSara Sharon 	} else {
6480690405fSSara Sharon 		del_timer(&reorder_buf->reorder_timer);
6490690405fSSara Sharon 	}
6500690405fSSara Sharon }
6510690405fSSara Sharon 
iwl_mvm_reorder_timer_expired(struct timer_list * t)6528cef5344SKees Cook void iwl_mvm_reorder_timer_expired(struct timer_list *t)
6530690405fSSara Sharon {
6548cef5344SKees Cook 	struct iwl_mvm_reorder_buffer *buf = from_timer(buf, t, reorder_timer);
655dfdddd92SJohannes Berg 	struct iwl_mvm_baid_data *baid_data =
656dfdddd92SJohannes Berg 		iwl_mvm_baid_data_from_reorder_buf(buf);
657dfdddd92SJohannes Berg 	struct iwl_mvm_reorder_buf_entry *entries =
658dfdddd92SJohannes Berg 		&baid_data->entries[buf->queue * baid_data->entries_per_queue];
6590690405fSSara Sharon 	int i;
6600690405fSSara Sharon 	u16 sn = 0, index = 0;
6610690405fSSara Sharon 	bool expired = false;
6629c36fd71SSara Sharon 	bool cont = false;
6630690405fSSara Sharon 
6649b856836SJohannes Berg 	spin_lock(&buf->lock);
6650690405fSSara Sharon 
6660690405fSSara Sharon 	if (!buf->num_stored || buf->removed) {
6679b856836SJohannes Berg 		spin_unlock(&buf->lock);
6680690405fSSara Sharon 		return;
6690690405fSSara Sharon 	}
6700690405fSSara Sharon 
6710690405fSSara Sharon 	for (i = 0; i < buf->buf_size ; i++) {
6720690405fSSara Sharon 		index = (buf->head_sn + i) % buf->buf_size;
6730690405fSSara Sharon 
674dfdddd92SJohannes Berg 		if (skb_queue_empty(&entries[index].e.frames)) {
6759c36fd71SSara Sharon 			/*
6769c36fd71SSara Sharon 			 * If there is a hole and the next frame didn't expire
6779c36fd71SSara Sharon 			 * we want to break and not advance SN
6789c36fd71SSara Sharon 			 */
6799c36fd71SSara Sharon 			cont = false;
6800690405fSSara Sharon 			continue;
6819c36fd71SSara Sharon 		}
682dfdddd92SJohannes Berg 		if (!cont &&
683dfdddd92SJohannes Berg 		    !time_after(jiffies, entries[index].e.reorder_time +
6840690405fSSara Sharon 					 RX_REORDER_BUF_TIMEOUT_MQ))
6850690405fSSara Sharon 			break;
6869c36fd71SSara Sharon 
6870690405fSSara Sharon 		expired = true;
6889c36fd71SSara Sharon 		/* continue until next hole after this expired frames */
6899c36fd71SSara Sharon 		cont = true;
6900690405fSSara Sharon 		sn = ieee80211_sn_add(buf->head_sn, i + 1);
6910690405fSSara Sharon 	}
6920690405fSSara Sharon 
6930690405fSSara Sharon 	if (expired) {
6940690405fSSara Sharon 		struct ieee80211_sta *sta;
695528a542aSEmmanuel Grumbach 		struct iwl_mvm_sta *mvmsta;
6969aa3856dSJohannes Berg 		u8 sta_id = ffs(baid_data->sta_mask) - 1;
6970690405fSSara Sharon 
6980690405fSSara Sharon 		rcu_read_lock();
6993f1c4c58SSara Sharon 		sta = rcu_dereference(buf->mvm->fw_id_to_mac_id[sta_id]);
70068182662SGregory Greenman 		if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
70168182662SGregory Greenman 			rcu_read_unlock();
70268182662SGregory Greenman 			goto out;
70368182662SGregory Greenman 		}
70468182662SGregory Greenman 
705528a542aSEmmanuel Grumbach 		mvmsta = iwl_mvm_sta_from_mac80211(sta);
706528a542aSEmmanuel Grumbach 
7070690405fSSara Sharon 		/* SN is set to the last expired frame + 1 */
70835263a03SSara Sharon 		IWL_DEBUG_HT(buf->mvm,
70935263a03SSara Sharon 			     "Releasing expired frames for sta %u, sn %d\n",
7103f1c4c58SSara Sharon 			     sta_id, sn);
711528a542aSEmmanuel Grumbach 		iwl_mvm_event_frame_timeout_callback(buf->mvm, mvmsta->vif,
7123f1c4c58SSara Sharon 						     sta, baid_data->tid);
7133c514bf8SEmmanuel Grumbach 		iwl_mvm_release_frames(buf->mvm, sta, NULL, baid_data,
714ecd09ddcSEmmanuel Grumbach 				       buf, sn, IWL_MVM_RELEASE_SEND_RSS_SYNC);
7150690405fSSara Sharon 		rcu_read_unlock();
716aeb8012cSJohannes Berg 	} else {
7170690405fSSara Sharon 		/*
7180690405fSSara Sharon 		 * If no frame expired and there are stored frames, index is now
7190690405fSSara Sharon 		 * pointing to the first unexpired frame - modify timer
7200690405fSSara Sharon 		 * accordingly to this frame.
7210690405fSSara Sharon 		 */
7220690405fSSara Sharon 		mod_timer(&buf->reorder_timer,
723dfdddd92SJohannes Berg 			  entries[index].e.reorder_time +
7240690405fSSara Sharon 			  1 + RX_REORDER_BUF_TIMEOUT_MQ);
7250690405fSSara Sharon 	}
72668182662SGregory Greenman 
72768182662SGregory Greenman out:
7289b856836SJohannes Berg 	spin_unlock(&buf->lock);
729b915c101SSara Sharon }
730b915c101SSara Sharon 
iwl_mvm_del_ba(struct iwl_mvm * mvm,int queue,struct iwl_mvm_delba_data * data)731b915c101SSara Sharon static void iwl_mvm_del_ba(struct iwl_mvm *mvm, int queue,
732b915c101SSara Sharon 			   struct iwl_mvm_delba_data *data)
733b915c101SSara Sharon {
734b915c101SSara Sharon 	struct iwl_mvm_baid_data *ba_data;
735b915c101SSara Sharon 	struct ieee80211_sta *sta;
736b915c101SSara Sharon 	struct iwl_mvm_reorder_buffer *reorder_buf;
737b915c101SSara Sharon 	u8 baid = data->baid;
7389aa3856dSJohannes Berg 	u32 sta_id;
739b915c101SSara Sharon 
740fd659f8eSJohannes Berg 	if (WARN_ONCE(baid >= IWL_MAX_BAID, "invalid BAID: %x\n", baid))
741b915c101SSara Sharon 		return;
742b915c101SSara Sharon 
743b915c101SSara Sharon 	rcu_read_lock();
744b915c101SSara Sharon 
745b915c101SSara Sharon 	ba_data = rcu_dereference(mvm->baid_map[baid]);
746b915c101SSara Sharon 	if (WARN_ON_ONCE(!ba_data))
747b915c101SSara Sharon 		goto out;
748b915c101SSara Sharon 
7499aa3856dSJohannes Berg 	/* pick any STA ID to find the pointer */
7509aa3856dSJohannes Berg 	sta_id = ffs(ba_data->sta_mask) - 1;
7519aa3856dSJohannes Berg 	sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
752b915c101SSara Sharon 	if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
753b915c101SSara Sharon 		goto out;
754b915c101SSara Sharon 
755b915c101SSara Sharon 	reorder_buf = &ba_data->reorder_buf[queue];
756b915c101SSara Sharon 
757b915c101SSara Sharon 	/* release all frames that are in the reorder buffer to the stack */
7580690405fSSara Sharon 	spin_lock_bh(&reorder_buf->lock);
75976f4a85eSJohannes Berg 	iwl_mvm_release_frames(mvm, sta, NULL, ba_data, reorder_buf,
760b915c101SSara Sharon 			       ieee80211_sn_add(reorder_buf->head_sn,
7613c514bf8SEmmanuel Grumbach 						reorder_buf->buf_size),
762ecd09ddcSEmmanuel Grumbach 			       0);
7630690405fSSara Sharon 	spin_unlock_bh(&reorder_buf->lock);
7640690405fSSara Sharon 	del_timer_sync(&reorder_buf->reorder_timer);
765b915c101SSara Sharon 
766b915c101SSara Sharon out:
767b915c101SSara Sharon 	rcu_read_unlock();
768b915c101SSara Sharon }
769b915c101SSara Sharon 
iwl_mvm_release_frames_from_notif(struct iwl_mvm * mvm,struct napi_struct * napi,u8 baid,u16 nssn,int queue,u32 flags)770c61b655aSEmmanuel Grumbach static void iwl_mvm_release_frames_from_notif(struct iwl_mvm *mvm,
771c61b655aSEmmanuel Grumbach 					      struct napi_struct *napi,
772ecd09ddcSEmmanuel Grumbach 					      u8 baid, u16 nssn, int queue,
773ecd09ddcSEmmanuel Grumbach 					      u32 flags)
774c61b655aSEmmanuel Grumbach {
775c61b655aSEmmanuel Grumbach 	struct ieee80211_sta *sta;
776c61b655aSEmmanuel Grumbach 	struct iwl_mvm_reorder_buffer *reorder_buf;
777c61b655aSEmmanuel Grumbach 	struct iwl_mvm_baid_data *ba_data;
7789aa3856dSJohannes Berg 	u32 sta_id;
779c61b655aSEmmanuel Grumbach 
780c61b655aSEmmanuel Grumbach 	IWL_DEBUG_HT(mvm, "Frame release notification for BAID %u, NSSN %d\n",
781c61b655aSEmmanuel Grumbach 		     baid, nssn);
782c61b655aSEmmanuel Grumbach 
783c61b655aSEmmanuel Grumbach 	if (WARN_ON_ONCE(baid == IWL_RX_REORDER_DATA_INVALID_BAID ||
784c61b655aSEmmanuel Grumbach 			 baid >= ARRAY_SIZE(mvm->baid_map)))
785c61b655aSEmmanuel Grumbach 		return;
786c61b655aSEmmanuel Grumbach 
787c61b655aSEmmanuel Grumbach 	rcu_read_lock();
788c61b655aSEmmanuel Grumbach 
789c61b655aSEmmanuel Grumbach 	ba_data = rcu_dereference(mvm->baid_map[baid]);
7902438d430SJohannes Berg 	if (!ba_data) {
7912438d430SJohannes Berg 		WARN(!(flags & IWL_MVM_RELEASE_FROM_RSS_SYNC),
7922438d430SJohannes Berg 		     "BAID %d not found in map\n", baid);
793c61b655aSEmmanuel Grumbach 		goto out;
7942438d430SJohannes Berg 	}
795c61b655aSEmmanuel Grumbach 
7969aa3856dSJohannes Berg 	/* pick any STA ID to find the pointer */
7979aa3856dSJohannes Berg 	sta_id = ffs(ba_data->sta_mask) - 1;
7989aa3856dSJohannes Berg 	sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
799c61b655aSEmmanuel Grumbach 	if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
800c61b655aSEmmanuel Grumbach 		goto out;
801c61b655aSEmmanuel Grumbach 
802c61b655aSEmmanuel Grumbach 	reorder_buf = &ba_data->reorder_buf[queue];
803c61b655aSEmmanuel Grumbach 
804c61b655aSEmmanuel Grumbach 	spin_lock_bh(&reorder_buf->lock);
8053c514bf8SEmmanuel Grumbach 	iwl_mvm_release_frames(mvm, sta, napi, ba_data,
806ecd09ddcSEmmanuel Grumbach 			       reorder_buf, nssn, flags);
807c61b655aSEmmanuel Grumbach 	spin_unlock_bh(&reorder_buf->lock);
808c61b655aSEmmanuel Grumbach 
809c61b655aSEmmanuel Grumbach out:
810c61b655aSEmmanuel Grumbach 	rcu_read_unlock();
811c61b655aSEmmanuel Grumbach }
812c61b655aSEmmanuel Grumbach 
iwl_mvm_nssn_sync(struct iwl_mvm * mvm,struct napi_struct * napi,int queue,const struct iwl_mvm_nssn_sync_data * data)813c61b655aSEmmanuel Grumbach static void iwl_mvm_nssn_sync(struct iwl_mvm *mvm,
814c61b655aSEmmanuel Grumbach 			      struct napi_struct *napi, int queue,
815c61b655aSEmmanuel Grumbach 			      const struct iwl_mvm_nssn_sync_data *data)
816c61b655aSEmmanuel Grumbach {
817c61b655aSEmmanuel Grumbach 	iwl_mvm_release_frames_from_notif(mvm, napi, data->baid,
818ecd09ddcSEmmanuel Grumbach 					  data->nssn, queue,
819ecd09ddcSEmmanuel Grumbach 					  IWL_MVM_RELEASE_FROM_RSS_SYNC);
820c61b655aSEmmanuel Grumbach }
821c61b655aSEmmanuel Grumbach 
iwl_mvm_rx_queue_notif(struct iwl_mvm * mvm,struct napi_struct * napi,struct iwl_rx_cmd_buffer * rxb,int queue)822c61b655aSEmmanuel Grumbach void iwl_mvm_rx_queue_notif(struct iwl_mvm *mvm, struct napi_struct *napi,
823c61b655aSEmmanuel Grumbach 			    struct iwl_rx_cmd_buffer *rxb, int queue)
82494bb4481SSara Sharon {
82594bb4481SSara Sharon 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
82694bb4481SSara Sharon 	struct iwl_rxq_sync_notification *notif;
82794bb4481SSara Sharon 	struct iwl_mvm_internal_rxq_notif *internal_notif;
828b570e5b0SJohannes Berg 	u32 len = iwl_rx_packet_payload_len(pkt);
82994bb4481SSara Sharon 
83094bb4481SSara Sharon 	notif = (void *)pkt->data;
83194bb4481SSara Sharon 	internal_notif = (void *)notif->payload;
83294bb4481SSara Sharon 
833b570e5b0SJohannes Berg 	if (WARN_ONCE(len < sizeof(*notif) + sizeof(*internal_notif),
834b570e5b0SJohannes Berg 		      "invalid notification size %d (%d)",
835b570e5b0SJohannes Berg 		      len, (int)(sizeof(*notif) + sizeof(*internal_notif))))
836b570e5b0SJohannes Berg 		return;
8375e1688ceSJohannes Berg 	len -= sizeof(*notif) + sizeof(*internal_notif);
838b570e5b0SJohannes Berg 
83942116705SJohannes Berg 	if (internal_notif->sync &&
84042116705SJohannes Berg 	    mvm->queue_sync_cookie != internal_notif->cookie) {
84142116705SJohannes Berg 		WARN_ONCE(1, "Received expired RX queue sync message\n");
842d0ff5d22SSara Sharon 		return;
843d0ff5d22SSara Sharon 	}
844d0ff5d22SSara Sharon 
845d0ff5d22SSara Sharon 	switch (internal_notif->type) {
846d0ff5d22SSara Sharon 	case IWL_MVM_RXQ_EMPTY:
8475e1688ceSJohannes Berg 		WARN_ONCE(len, "invalid empty notification size %d", len);
8480636b938SSara Sharon 		break;
84994bb4481SSara Sharon 	case IWL_MVM_RXQ_NOTIF_DEL_BA:
8505e1688ceSJohannes Berg 		if (WARN_ONCE(len != sizeof(struct iwl_mvm_delba_data),
851b570e5b0SJohannes Berg 			      "invalid delba notification size %d (%d)",
8525e1688ceSJohannes Berg 			      len, (int)sizeof(struct iwl_mvm_delba_data)))
853b570e5b0SJohannes Berg 			break;
854b915c101SSara Sharon 		iwl_mvm_del_ba(mvm, queue, (void *)internal_notif->data);
85594bb4481SSara Sharon 		break;
856c61b655aSEmmanuel Grumbach 	case IWL_MVM_RXQ_NSSN_SYNC:
8575e1688ceSJohannes Berg 		if (WARN_ONCE(len != sizeof(struct iwl_mvm_nssn_sync_data),
858b570e5b0SJohannes Berg 			      "invalid nssn sync notification size %d (%d)",
8595e1688ceSJohannes Berg 			      len, (int)sizeof(struct iwl_mvm_nssn_sync_data)))
860b570e5b0SJohannes Berg 			break;
861c61b655aSEmmanuel Grumbach 		iwl_mvm_nssn_sync(mvm, napi, queue,
862c61b655aSEmmanuel Grumbach 				  (void *)internal_notif->data);
863c61b655aSEmmanuel Grumbach 		break;
86494bb4481SSara Sharon 	default:
86594bb4481SSara Sharon 		WARN_ONCE(1, "Invalid identifier %d", internal_notif->type);
86694bb4481SSara Sharon 	}
86742116705SJohannes Berg 
8682f7a04c7SJohannes Berg 	if (internal_notif->sync) {
8692f7a04c7SJohannes Berg 		WARN_ONCE(!test_and_clear_bit(queue, &mvm->queue_sync_state),
8702f7a04c7SJohannes Berg 			  "queue sync: queue %d responded a second time!\n",
8712f7a04c7SJohannes Berg 			  queue);
8722f7a04c7SJohannes Berg 		if (READ_ONCE(mvm->queue_sync_state) == 0)
87342116705SJohannes Berg 			wake_up(&mvm->rx_sync_waitq);
87494bb4481SSara Sharon 	}
8752f7a04c7SJohannes Berg }
87694bb4481SSara Sharon 
iwl_mvm_oldsn_workaround(struct iwl_mvm * mvm,struct ieee80211_sta * sta,int tid,struct iwl_mvm_reorder_buffer * buffer,u32 reorder,u32 gp2,int queue)8770968fbfaSJohannes Berg static void iwl_mvm_oldsn_workaround(struct iwl_mvm *mvm,
8780968fbfaSJohannes Berg 				     struct ieee80211_sta *sta, int tid,
8790968fbfaSJohannes Berg 				     struct iwl_mvm_reorder_buffer *buffer,
8800968fbfaSJohannes Berg 				     u32 reorder, u32 gp2, int queue)
8810968fbfaSJohannes Berg {
8820968fbfaSJohannes Berg 	struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
8830968fbfaSJohannes Berg 
8840968fbfaSJohannes Berg 	if (gp2 != buffer->consec_oldsn_ampdu_gp2) {
8850968fbfaSJohannes Berg 		/* we have a new (A-)MPDU ... */
8860968fbfaSJohannes Berg 
8870968fbfaSJohannes Berg 		/*
8880968fbfaSJohannes Berg 		 * reset counter to 0 if we didn't have any oldsn in
8890968fbfaSJohannes Berg 		 * the last A-MPDU (as detected by GP2 being identical)
8900968fbfaSJohannes Berg 		 */
8910968fbfaSJohannes Berg 		if (!buffer->consec_oldsn_prev_drop)
8920968fbfaSJohannes Berg 			buffer->consec_oldsn_drops = 0;
8930968fbfaSJohannes Berg 
8940968fbfaSJohannes Berg 		/* either way, update our tracking state */
8950968fbfaSJohannes Berg 		buffer->consec_oldsn_ampdu_gp2 = gp2;
8960968fbfaSJohannes Berg 	} else if (buffer->consec_oldsn_prev_drop) {
8970968fbfaSJohannes Berg 		/*
8980968fbfaSJohannes Berg 		 * tracking state didn't change, and we had an old SN
8990968fbfaSJohannes Berg 		 * indication before - do nothing in this case, we
9000968fbfaSJohannes Berg 		 * already noted this one down and are waiting for the
9010968fbfaSJohannes Berg 		 * next A-MPDU (by GP2)
9020968fbfaSJohannes Berg 		 */
9030968fbfaSJohannes Berg 		return;
9040968fbfaSJohannes Berg 	}
9050968fbfaSJohannes Berg 
9060968fbfaSJohannes Berg 	/* return unless this MPDU has old SN */
9070968fbfaSJohannes Berg 	if (!(reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN))
9080968fbfaSJohannes Berg 		return;
9090968fbfaSJohannes Berg 
9100968fbfaSJohannes Berg 	/* update state */
9110968fbfaSJohannes Berg 	buffer->consec_oldsn_prev_drop = 1;
9120968fbfaSJohannes Berg 	buffer->consec_oldsn_drops++;
9130968fbfaSJohannes Berg 
9140968fbfaSJohannes Berg 	/* if limit is reached, send del BA and reset state */
9150968fbfaSJohannes Berg 	if (buffer->consec_oldsn_drops == IWL_MVM_AMPDU_CONSEC_DROPS_DELBA) {
9160968fbfaSJohannes Berg 		IWL_WARN(mvm,
9170968fbfaSJohannes Berg 			 "reached %d old SN frames from %pM on queue %d, stopping BA session on TID %d\n",
9180968fbfaSJohannes Berg 			 IWL_MVM_AMPDU_CONSEC_DROPS_DELBA,
9190968fbfaSJohannes Berg 			 sta->addr, queue, tid);
9200968fbfaSJohannes Berg 		ieee80211_stop_rx_ba_session(mvmsta->vif, BIT(tid), sta->addr);
9210968fbfaSJohannes Berg 		buffer->consec_oldsn_prev_drop = 0;
9220968fbfaSJohannes Berg 		buffer->consec_oldsn_drops = 0;
9230968fbfaSJohannes Berg 	}
9240968fbfaSJohannes Berg }
9250968fbfaSJohannes Berg 
926b915c101SSara Sharon /*
927b915c101SSara Sharon  * Returns true if the MPDU was buffered\dropped, false if it should be passed
928b915c101SSara Sharon  * to upper layer.
929b915c101SSara Sharon  */
iwl_mvm_reorder(struct iwl_mvm * mvm,struct napi_struct * napi,int queue,struct ieee80211_sta * sta,struct sk_buff * skb,struct iwl_rx_mpdu_desc * desc)930b915c101SSara Sharon static bool iwl_mvm_reorder(struct iwl_mvm *mvm,
931b915c101SSara Sharon 			    struct napi_struct *napi,
932b915c101SSara Sharon 			    int queue,
933b915c101SSara Sharon 			    struct ieee80211_sta *sta,
934b915c101SSara Sharon 			    struct sk_buff *skb,
935b915c101SSara Sharon 			    struct iwl_rx_mpdu_desc *desc)
936b915c101SSara Sharon {
9370968fbfaSJohannes Berg 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
9383f7a9d57SMordechay Goodstein 	struct ieee80211_hdr *hdr = (void *)skb_mac_header(skb);
939b915c101SSara Sharon 	struct iwl_mvm_baid_data *baid_data;
940b915c101SSara Sharon 	struct iwl_mvm_reorder_buffer *buffer;
941b915c101SSara Sharon 	struct sk_buff *tail;
942b915c101SSara Sharon 	u32 reorder = le32_to_cpu(desc->reorder_data);
943b915c101SSara Sharon 	bool amsdu = desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU;
944e7e14089SSara Sharon 	bool last_subframe =
945e7e14089SSara Sharon 		desc->amsdu_info & IWL_RX_MPDU_AMSDU_LAST_SUBFRAME;
9468f66e064SSara Sharon 	u8 tid = ieee80211_get_tid(hdr);
947b915c101SSara Sharon 	u8 sub_frame_idx = desc->amsdu_info &
948b915c101SSara Sharon 			   IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK;
949dfdddd92SJohannes Berg 	struct iwl_mvm_reorder_buf_entry *entries;
9509aa3856dSJohannes Berg 	u32 sta_mask;
951b915c101SSara Sharon 	int index;
952b915c101SSara Sharon 	u16 nssn, sn;
953b915c101SSara Sharon 	u8 baid;
954b915c101SSara Sharon 
955b915c101SSara Sharon 	baid = (reorder & IWL_RX_MPDU_REORDER_BAID_MASK) >>
956b915c101SSara Sharon 		IWL_RX_MPDU_REORDER_BAID_SHIFT;
957b915c101SSara Sharon 
95813fd96c9SEmmanuel Grumbach 	if (mvm->trans->trans_cfg->device_family == IWL_DEVICE_FAMILY_9000)
95913fd96c9SEmmanuel Grumbach 		return false;
96013fd96c9SEmmanuel Grumbach 
9618ec8ed43SJohannes Berg 	/*
9628ec8ed43SJohannes Berg 	 * This also covers the case of receiving a Block Ack Request
9638ec8ed43SJohannes Berg 	 * outside a BA session; we'll pass it to mac80211 and that
9648ec8ed43SJohannes Berg 	 * then sends a delBA action frame.
96581444538SJohannes Berg 	 * This also covers pure monitor mode, in which case we won't
96681444538SJohannes Berg 	 * have any BA sessions.
9678ec8ed43SJohannes Berg 	 */
968b915c101SSara Sharon 	if (baid == IWL_RX_REORDER_DATA_INVALID_BAID)
969b915c101SSara Sharon 		return false;
970b915c101SSara Sharon 
971b915c101SSara Sharon 	/* no sta yet */
972417795a3SSara Sharon 	if (WARN_ONCE(IS_ERR_OR_NULL(sta),
973417795a3SSara Sharon 		      "Got valid BAID without a valid station assigned\n"))
974b915c101SSara Sharon 		return false;
975b915c101SSara Sharon 
9769a73a7d2SSara Sharon 	/* not a data packet or a bar */
9779a73a7d2SSara Sharon 	if (!ieee80211_is_back_req(hdr->frame_control) &&
9789a73a7d2SSara Sharon 	    (!ieee80211_is_data_qos(hdr->frame_control) ||
9799a73a7d2SSara Sharon 	     is_multicast_ether_addr(hdr->addr1)))
980b915c101SSara Sharon 		return false;
981b915c101SSara Sharon 
982b915c101SSara Sharon 	if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
983b915c101SSara Sharon 		return false;
984b915c101SSara Sharon 
985b915c101SSara Sharon 	baid_data = rcu_dereference(mvm->baid_map[baid]);
9865d43eab6SSara Sharon 	if (!baid_data) {
987a600852aSEmmanuel Grumbach 		IWL_DEBUG_RX(mvm,
988a600852aSEmmanuel Grumbach 			     "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n",
989a600852aSEmmanuel Grumbach 			      baid, reorder);
990b915c101SSara Sharon 		return false;
9915d43eab6SSara Sharon 	}
9925d43eab6SSara Sharon 
9939aa3856dSJohannes Berg 	rcu_read_lock();
9949aa3856dSJohannes Berg 	sta_mask = iwl_mvm_sta_fw_id_mask(mvm, sta, -1);
9959aa3856dSJohannes Berg 	rcu_read_unlock();
9969aa3856dSJohannes Berg 
997568db7fdSJohannes Berg 	if (IWL_FW_CHECK(mvm,
998568db7fdSJohannes Berg 			 tid != baid_data->tid ||
9999aa3856dSJohannes Berg 			 !(sta_mask & baid_data->sta_mask),
10009aa3856dSJohannes Berg 			 "baid 0x%x is mapped to sta_mask:0x%x tid:%d, but was received for sta_mask:0x%x tid:%d\n",
1001568db7fdSJohannes Berg 			 baid, baid_data->sta_mask, baid_data->tid,
1002568db7fdSJohannes Berg 			 sta_mask, tid))
1003b915c101SSara Sharon 		return false;
1004b915c101SSara Sharon 
1005b915c101SSara Sharon 	nssn = reorder & IWL_RX_MPDU_REORDER_NSSN_MASK;
1006b915c101SSara Sharon 	sn = (reorder & IWL_RX_MPDU_REORDER_SN_MASK) >>
1007b915c101SSara Sharon 		IWL_RX_MPDU_REORDER_SN_SHIFT;
1008b915c101SSara Sharon 
1009b915c101SSara Sharon 	buffer = &baid_data->reorder_buf[queue];
1010dfdddd92SJohannes Berg 	entries = &baid_data->entries[queue * baid_data->entries_per_queue];
1011b915c101SSara Sharon 
10120690405fSSara Sharon 	spin_lock_bh(&buffer->lock);
10130690405fSSara Sharon 
10145d43eab6SSara Sharon 	if (!buffer->valid) {
10155d43eab6SSara Sharon 		if (reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN) {
10165d43eab6SSara Sharon 			spin_unlock_bh(&buffer->lock);
10175d43eab6SSara Sharon 			return false;
10185d43eab6SSara Sharon 		}
10195d43eab6SSara Sharon 		buffer->valid = true;
10205d43eab6SSara Sharon 	}
10215d43eab6SSara Sharon 
10229a73a7d2SSara Sharon 	if (ieee80211_is_back_req(hdr->frame_control)) {
10233c514bf8SEmmanuel Grumbach 		iwl_mvm_release_frames(mvm, sta, napi, baid_data,
1024ecd09ddcSEmmanuel Grumbach 				       buffer, nssn, 0);
10259a73a7d2SSara Sharon 		goto drop;
10269a73a7d2SSara Sharon 	}
10279a73a7d2SSara Sharon 
1028b915c101SSara Sharon 	/*
1029b915c101SSara Sharon 	 * If there was a significant jump in the nssn - adjust.
1030b915c101SSara Sharon 	 * If the SN is smaller than the NSSN it might need to first go into
1031b915c101SSara Sharon 	 * the reorder buffer, in which case we just release up to it and the
10325f90472cSSara Sharon 	 * rest of the function will take care of storing it and releasing up to
10333c514bf8SEmmanuel Grumbach 	 * the nssn.
10343c514bf8SEmmanuel Grumbach 	 * This should not happen. This queue has been lagging and it should
10353c514bf8SEmmanuel Grumbach 	 * have been updated by a IWL_MVM_RXQ_NSSN_SYNC notification. Be nice
10363c514bf8SEmmanuel Grumbach 	 * and update the other queues.
1037b915c101SSara Sharon 	 */
103874dd1764SSara Sharon 	if (!iwl_mvm_is_sn_less(nssn, buffer->head_sn + buffer->buf_size,
10395f90472cSSara Sharon 				buffer->buf_size) ||
10405f90472cSSara Sharon 	    !ieee80211_sn_less(sn, buffer->head_sn + buffer->buf_size)) {
1041b915c101SSara Sharon 		u16 min_sn = ieee80211_sn_less(sn, nssn) ? sn : nssn;
1042b915c101SSara Sharon 
104376f4a85eSJohannes Berg 		iwl_mvm_release_frames(mvm, sta, napi, baid_data, buffer,
1044ecd09ddcSEmmanuel Grumbach 				       min_sn, IWL_MVM_RELEASE_SEND_RSS_SYNC);
1045b915c101SSara Sharon 	}
1046b915c101SSara Sharon 
10470968fbfaSJohannes Berg 	iwl_mvm_oldsn_workaround(mvm, sta, tid, buffer, reorder,
10480968fbfaSJohannes Berg 				 rx_status->device_timestamp, queue);
10490968fbfaSJohannes Berg 
1050b915c101SSara Sharon 	/* drop any oudated packets */
1051b915c101SSara Sharon 	if (ieee80211_sn_less(sn, buffer->head_sn))
1052b915c101SSara Sharon 		goto drop;
1053b915c101SSara Sharon 
1054b915c101SSara Sharon 	/* release immediately if allowed by nssn and no stored frames */
1055b915c101SSara Sharon 	if (!buffer->num_stored && ieee80211_sn_less(sn, nssn)) {
105674dd1764SSara Sharon 		if (iwl_mvm_is_sn_less(buffer->head_sn, nssn,
1057e7e14089SSara Sharon 				       buffer->buf_size) &&
10583c514bf8SEmmanuel Grumbach 		   (!amsdu || last_subframe)) {
10593c514bf8SEmmanuel Grumbach 			/*
10603c514bf8SEmmanuel Grumbach 			 * If we crossed the 2048 or 0 SN, notify all the
10613c514bf8SEmmanuel Grumbach 			 * queues. This is done in order to avoid having a
10623c514bf8SEmmanuel Grumbach 			 * head_sn that lags behind for too long. When that
10633c514bf8SEmmanuel Grumbach 			 * happens, we can get to a situation where the head_sn
10643c514bf8SEmmanuel Grumbach 			 * is within the interval [nssn - buf_size : nssn]
10653c514bf8SEmmanuel Grumbach 			 * which will make us think that the nssn is a packet
10663c514bf8SEmmanuel Grumbach 			 * that we already freed because of the reordering
10673c514bf8SEmmanuel Grumbach 			 * buffer and we will ignore it. So maintain the
10683c514bf8SEmmanuel Grumbach 			 * head_sn somewhat updated across all the queues:
10693c514bf8SEmmanuel Grumbach 			 * when it crosses 0 and 2048.
10703c514bf8SEmmanuel Grumbach 			 */
10713c514bf8SEmmanuel Grumbach 			if (sn == 2048 || sn == 0)
10723c514bf8SEmmanuel Grumbach 				iwl_mvm_sync_nssn(mvm, baid, sn);
1073b915c101SSara Sharon 			buffer->head_sn = nssn;
10743c514bf8SEmmanuel Grumbach 		}
1075b915c101SSara Sharon 		/* No need to update AMSDU last SN - we are moving the head */
10760690405fSSara Sharon 		spin_unlock_bh(&buffer->lock);
1077b915c101SSara Sharon 		return false;
1078b915c101SSara Sharon 	}
1079b915c101SSara Sharon 
108014a1f85bSSara Sharon 	/*
108114a1f85bSSara Sharon 	 * release immediately if there are no stored frames, and the sn is
108214a1f85bSSara Sharon 	 * equal to the head.
108314a1f85bSSara Sharon 	 * This can happen due to reorder timer, where NSSN is behind head_sn.
108414a1f85bSSara Sharon 	 * When we released everything, and we got the next frame in the
108514a1f85bSSara Sharon 	 * sequence, according to the NSSN we can't release immediately,
108614a1f85bSSara Sharon 	 * while technically there is no hole and we can move forward.
108714a1f85bSSara Sharon 	 */
108814a1f85bSSara Sharon 	if (!buffer->num_stored && sn == buffer->head_sn) {
10893c514bf8SEmmanuel Grumbach 		if (!amsdu || last_subframe) {
10903c514bf8SEmmanuel Grumbach 			if (sn == 2048 || sn == 0)
10913c514bf8SEmmanuel Grumbach 				iwl_mvm_sync_nssn(mvm, baid, sn);
109214a1f85bSSara Sharon 			buffer->head_sn = ieee80211_sn_inc(buffer->head_sn);
10933c514bf8SEmmanuel Grumbach 		}
109414a1f85bSSara Sharon 		/* No need to update AMSDU last SN - we are moving the head */
109514a1f85bSSara Sharon 		spin_unlock_bh(&buffer->lock);
109614a1f85bSSara Sharon 		return false;
109714a1f85bSSara Sharon 	}
109814a1f85bSSara Sharon 
1099b915c101SSara Sharon 	index = sn % buffer->buf_size;
1100b915c101SSara Sharon 
1101b915c101SSara Sharon 	/*
1102b915c101SSara Sharon 	 * Check if we already stored this frame
1103b915c101SSara Sharon 	 * As AMSDU is either received or not as whole, logic is simple:
1104b915c101SSara Sharon 	 * If we have frames in that position in the buffer and the last frame
1105b915c101SSara Sharon 	 * originated from AMSDU had a different SN then it is a retransmission.
1106b915c101SSara Sharon 	 * If it is the same SN then if the subframe index is incrementing it
1107b915c101SSara Sharon 	 * is the same AMSDU - otherwise it is a retransmission.
1108b915c101SSara Sharon 	 */
1109dfdddd92SJohannes Berg 	tail = skb_peek_tail(&entries[index].e.frames);
1110b915c101SSara Sharon 	if (tail && !amsdu)
1111b915c101SSara Sharon 		goto drop;
1112b915c101SSara Sharon 	else if (tail && (sn != buffer->last_amsdu ||
1113b915c101SSara Sharon 			  buffer->last_sub_index >= sub_frame_idx))
1114b915c101SSara Sharon 		goto drop;
1115b915c101SSara Sharon 
1116b915c101SSara Sharon 	/* put in reorder buffer */
1117dfdddd92SJohannes Berg 	__skb_queue_tail(&entries[index].e.frames, skb);
1118b915c101SSara Sharon 	buffer->num_stored++;
1119dfdddd92SJohannes Berg 	entries[index].e.reorder_time = jiffies;
11200690405fSSara Sharon 
1121b915c101SSara Sharon 	if (amsdu) {
1122b915c101SSara Sharon 		buffer->last_amsdu = sn;
1123b915c101SSara Sharon 		buffer->last_sub_index = sub_frame_idx;
1124b915c101SSara Sharon 	}
1125b915c101SSara Sharon 
1126e7e14089SSara Sharon 	/*
1127e7e14089SSara Sharon 	 * We cannot trust NSSN for AMSDU sub-frames that are not the last.
1128e7e14089SSara Sharon 	 * The reason is that NSSN advances on the first sub-frame, and may
1129e7e14089SSara Sharon 	 * cause the reorder buffer to advance before all the sub-frames arrive.
1130e7e14089SSara Sharon 	 * Example: reorder buffer contains SN 0 & 2, and we receive AMSDU with
1131e7e14089SSara Sharon 	 * SN 1. NSSN for first sub frame will be 3 with the result of driver
1132e7e14089SSara Sharon 	 * releasing SN 0,1, 2. When sub-frame 1 arrives - reorder buffer is
1133e7e14089SSara Sharon 	 * already ahead and it will be dropped.
1134e7e14089SSara Sharon 	 * If the last sub-frame is not on this queue - we will get frame
1135e7e14089SSara Sharon 	 * release notification with up to date NSSN.
1136e7e14089SSara Sharon 	 */
1137e7e14089SSara Sharon 	if (!amsdu || last_subframe)
11383c514bf8SEmmanuel Grumbach 		iwl_mvm_release_frames(mvm, sta, napi, baid_data,
1139ecd09ddcSEmmanuel Grumbach 				       buffer, nssn,
1140ecd09ddcSEmmanuel Grumbach 				       IWL_MVM_RELEASE_SEND_RSS_SYNC);
1141e7e14089SSara Sharon 
11420690405fSSara Sharon 	spin_unlock_bh(&buffer->lock);
1143b915c101SSara Sharon 	return true;
1144b915c101SSara Sharon 
1145b915c101SSara Sharon drop:
1146b915c101SSara Sharon 	kfree_skb(skb);
11470690405fSSara Sharon 	spin_unlock_bh(&buffer->lock);
1148b915c101SSara Sharon 	return true;
1149b915c101SSara Sharon }
1150b915c101SSara Sharon 
iwl_mvm_agg_rx_received(struct iwl_mvm * mvm,u32 reorder_data,u8 baid)11515d43eab6SSara Sharon static void iwl_mvm_agg_rx_received(struct iwl_mvm *mvm,
11525d43eab6SSara Sharon 				    u32 reorder_data, u8 baid)
115310b2b201SSara Sharon {
115410b2b201SSara Sharon 	unsigned long now = jiffies;
115510b2b201SSara Sharon 	unsigned long timeout;
115610b2b201SSara Sharon 	struct iwl_mvm_baid_data *data;
115710b2b201SSara Sharon 
115810b2b201SSara Sharon 	rcu_read_lock();
115910b2b201SSara Sharon 
116010b2b201SSara Sharon 	data = rcu_dereference(mvm->baid_map[baid]);
11615d43eab6SSara Sharon 	if (!data) {
1162a600852aSEmmanuel Grumbach 		IWL_DEBUG_RX(mvm,
1163a600852aSEmmanuel Grumbach 			     "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n",
1164a600852aSEmmanuel Grumbach 			      baid, reorder_data);
116510b2b201SSara Sharon 		goto out;
11665d43eab6SSara Sharon 	}
116710b2b201SSara Sharon 
116810b2b201SSara Sharon 	if (!data->timeout)
116910b2b201SSara Sharon 		goto out;
117010b2b201SSara Sharon 
117110b2b201SSara Sharon 	timeout = data->timeout;
117210b2b201SSara Sharon 	/*
117310b2b201SSara Sharon 	 * Do not update last rx all the time to avoid cache bouncing
117410b2b201SSara Sharon 	 * between the rx queues.
117510b2b201SSara Sharon 	 * Update it every timeout. Worst case is the session will
117610b2b201SSara Sharon 	 * expire after ~ 2 * timeout, which doesn't matter that much.
117710b2b201SSara Sharon 	 */
117810b2b201SSara Sharon 	if (time_before(data->last_rx + TU_TO_JIFFIES(timeout), now))
117910b2b201SSara Sharon 		/* Update is atomic */
118010b2b201SSara Sharon 		data->last_rx = now;
118110b2b201SSara Sharon 
118210b2b201SSara Sharon out:
118310b2b201SSara Sharon 	rcu_read_unlock();
118410b2b201SSara Sharon }
118510b2b201SSara Sharon 
iwl_mvm_flip_address(u8 * addr)1186e4d72208SSara Sharon static void iwl_mvm_flip_address(u8 *addr)
1187e4d72208SSara Sharon {
1188e4d72208SSara Sharon 	int i;
1189e4d72208SSara Sharon 	u8 mac_addr[ETH_ALEN];
1190e4d72208SSara Sharon 
1191e4d72208SSara Sharon 	for (i = 0; i < ETH_ALEN; i++)
1192e4d72208SSara Sharon 		mac_addr[i] = addr[ETH_ALEN - i - 1];
1193e4d72208SSara Sharon 	ether_addr_copy(addr, mac_addr);
1194e4d72208SSara Sharon }
1195e4d72208SSara Sharon 
1196bdf180c8SShaul Triebitz struct iwl_mvm_rx_phy_data {
11976721039dSShaul Triebitz 	enum iwl_rx_phy_info_type info_type;
1198feb4a0e2SMordechay Goodstein 	__le32 d0, d1, d2, d3, eht_d4, d5;
1199bdf180c8SShaul Triebitz 	__le16 d4;
1200feb4a0e2SMordechay Goodstein 	bool with_data;
1201da118544SJohannes Berg 	bool first_subframe;
1202feb4a0e2SMordechay Goodstein 	__le32 rx_vec[4];
1203f1490546SJohannes Berg 
1204f1490546SJohannes Berg 	u32 rate_n_flags;
1205f1490546SJohannes Berg 	u32 gp2_on_air_rise;
1206f1490546SJohannes Berg 	u16 phy_info;
1207f1490546SJohannes Berg 	u8 energy_a, energy_b;
1208f1490546SJohannes Berg 	u8 channel;
1209bdf180c8SShaul Triebitz };
1210bdf180c8SShaul Triebitz 
iwl_mvm_decode_he_mu_ext(struct iwl_mvm * mvm,struct iwl_mvm_rx_phy_data * phy_data,struct ieee80211_radiotap_he_mu * he_mu)1211bdf180c8SShaul Triebitz static void iwl_mvm_decode_he_mu_ext(struct iwl_mvm *mvm,
1212bdf180c8SShaul Triebitz 				     struct iwl_mvm_rx_phy_data *phy_data,
1213dabf9844SJohannes Berg 				     struct ieee80211_radiotap_he_mu *he_mu)
1214dabf9844SJohannes Berg {
1215bdf180c8SShaul Triebitz 	u32 phy_data2 = le32_to_cpu(phy_data->d2);
1216bdf180c8SShaul Triebitz 	u32 phy_data3 = le32_to_cpu(phy_data->d3);
1217bdf180c8SShaul Triebitz 	u16 phy_data4 = le16_to_cpu(phy_data->d4);
1218f1490546SJohannes Berg 	u32 rate_n_flags = phy_data->rate_n_flags;
1219dabf9844SJohannes Berg 
1220bdf180c8SShaul Triebitz 	if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CRC_OK, phy_data4)) {
1221dabf9844SJohannes Berg 		he_mu->flags1 |=
1222dabf9844SJohannes Berg 			cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_RU_KNOWN |
1223dabf9844SJohannes Berg 				    IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU_KNOWN);
1224dabf9844SJohannes Berg 
1225dabf9844SJohannes Berg 		he_mu->flags1 |=
1226bdf180c8SShaul Triebitz 			le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CTR_RU,
1227bdf180c8SShaul Triebitz 						   phy_data4),
1228dabf9844SJohannes Berg 					 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU);
1229dabf9844SJohannes Berg 
1230bdf180c8SShaul Triebitz 		he_mu->ru_ch1[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU0,
1231bdf180c8SShaul Triebitz 					     phy_data2);
1232bdf180c8SShaul Triebitz 		he_mu->ru_ch1[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU1,
1233bdf180c8SShaul Triebitz 					     phy_data3);
1234bdf180c8SShaul Triebitz 		he_mu->ru_ch1[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU2,
1235bdf180c8SShaul Triebitz 					     phy_data2);
1236bdf180c8SShaul Triebitz 		he_mu->ru_ch1[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU3,
1237bdf180c8SShaul Triebitz 					     phy_data3);
1238dabf9844SJohannes Berg 	}
1239dabf9844SJohannes Berg 
1240bdf180c8SShaul Triebitz 	if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CRC_OK, phy_data4) &&
124148c6ebc1SMiri Korenblit 	    (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK_V1) != RATE_MCS_CHAN_WIDTH_20) {
1242dabf9844SJohannes Berg 		he_mu->flags1 |=
1243dabf9844SJohannes Berg 			cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_RU_KNOWN |
1244dabf9844SJohannes Berg 				    IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_CTR_26T_RU_KNOWN);
1245dabf9844SJohannes Berg 
1246dabf9844SJohannes Berg 		he_mu->flags2 |=
1247bdf180c8SShaul Triebitz 			le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CTR_RU,
1248bdf180c8SShaul Triebitz 						   phy_data4),
1249dabf9844SJohannes Berg 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_CH2_CTR_26T_RU);
1250dabf9844SJohannes Berg 
1251bdf180c8SShaul Triebitz 		he_mu->ru_ch2[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU0,
1252bdf180c8SShaul Triebitz 					     phy_data2);
1253bdf180c8SShaul Triebitz 		he_mu->ru_ch2[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU1,
1254bdf180c8SShaul Triebitz 					     phy_data3);
1255bdf180c8SShaul Triebitz 		he_mu->ru_ch2[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU2,
1256bdf180c8SShaul Triebitz 					     phy_data2);
1257bdf180c8SShaul Triebitz 		he_mu->ru_ch2[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU3,
1258bdf180c8SShaul Triebitz 					     phy_data3);
1259dabf9844SJohannes Berg 	}
1260dabf9844SJohannes Berg }
1261dabf9844SJohannes Berg 
1262ffe9d734SJohannes Berg static void
iwl_mvm_decode_he_phy_ru_alloc(struct iwl_mvm_rx_phy_data * phy_data,struct ieee80211_radiotap_he * he,struct ieee80211_radiotap_he_mu * he_mu,struct ieee80211_rx_status * rx_status)1263bdf180c8SShaul Triebitz iwl_mvm_decode_he_phy_ru_alloc(struct iwl_mvm_rx_phy_data *phy_data,
1264ffe9d734SJohannes Berg 			       struct ieee80211_radiotap_he *he,
1265ffe9d734SJohannes Berg 			       struct ieee80211_radiotap_he_mu *he_mu,
1266ffe9d734SJohannes Berg 			       struct ieee80211_rx_status *rx_status)
1267ffe9d734SJohannes Berg {
1268ffe9d734SJohannes Berg 	/*
1269ffe9d734SJohannes Berg 	 * Unfortunately, we have to leave the mac80211 data
1270ffe9d734SJohannes Berg 	 * incorrect for the case that we receive an HE-MU
1271ffe9d734SJohannes Berg 	 * transmission and *don't* have the HE phy data (due
1272ffe9d734SJohannes Berg 	 * to the bits being used for TSF). This shouldn't
1273ffe9d734SJohannes Berg 	 * happen though as management frames where we need
1274ffe9d734SJohannes Berg 	 * the TSF/timers are not be transmitted in HE-MU.
1275ffe9d734SJohannes Berg 	 */
1276bdf180c8SShaul Triebitz 	u8 ru = le32_get_bits(phy_data->d1, IWL_RX_PHY_DATA1_HE_RU_ALLOC_MASK);
1277f1490546SJohannes Berg 	u32 rate_n_flags = phy_data->rate_n_flags;
127848c6ebc1SMiri Korenblit 	u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK_V1;
1279ffe9d734SJohannes Berg 	u8 offs = 0;
1280ffe9d734SJohannes Berg 
1281ffe9d734SJohannes Berg 	rx_status->bw = RATE_INFO_BW_HE_RU;
1282ffe9d734SJohannes Berg 
1283ffe9d734SJohannes Berg 	he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN);
1284ffe9d734SJohannes Berg 
1285ffe9d734SJohannes Berg 	switch (ru) {
1286ffe9d734SJohannes Berg 	case 0 ... 36:
1287ffe9d734SJohannes Berg 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_26;
1288ffe9d734SJohannes Berg 		offs = ru;
1289ffe9d734SJohannes Berg 		break;
1290ffe9d734SJohannes Berg 	case 37 ... 52:
1291ffe9d734SJohannes Berg 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_52;
1292ffe9d734SJohannes Berg 		offs = ru - 37;
1293ffe9d734SJohannes Berg 		break;
1294ffe9d734SJohannes Berg 	case 53 ... 60:
1295ffe9d734SJohannes Berg 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106;
1296ffe9d734SJohannes Berg 		offs = ru - 53;
1297ffe9d734SJohannes Berg 		break;
1298ffe9d734SJohannes Berg 	case 61 ... 64:
1299ffe9d734SJohannes Berg 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_242;
1300ffe9d734SJohannes Berg 		offs = ru - 61;
1301ffe9d734SJohannes Berg 		break;
1302ffe9d734SJohannes Berg 	case 65 ... 66:
1303ffe9d734SJohannes Berg 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_484;
1304ffe9d734SJohannes Berg 		offs = ru - 65;
1305ffe9d734SJohannes Berg 		break;
1306ffe9d734SJohannes Berg 	case 67:
1307ffe9d734SJohannes Berg 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_996;
1308ffe9d734SJohannes Berg 		break;
1309ffe9d734SJohannes Berg 	case 68:
1310ffe9d734SJohannes Berg 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_2x996;
1311ffe9d734SJohannes Berg 		break;
1312ffe9d734SJohannes Berg 	}
1313ffe9d734SJohannes Berg 	he->data2 |= le16_encode_bits(offs,
1314ffe9d734SJohannes Berg 				      IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET);
1315ffe9d734SJohannes Berg 	he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_KNOWN |
1316ffe9d734SJohannes Berg 				 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET_KNOWN);
1317bdf180c8SShaul Triebitz 	if (phy_data->d1 & cpu_to_le32(IWL_RX_PHY_DATA1_HE_RU_ALLOC_SEC80))
1318ffe9d734SJohannes Berg 		he->data2 |=
1319ffe9d734SJohannes Berg 			cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_SEC);
1320ffe9d734SJohannes Berg 
1321ffe9d734SJohannes Berg #define CHECK_BW(bw) \
1322ffe9d734SJohannes Berg 	BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_ ## bw ## MHZ != \
132374cf15cbSJohannes Berg 		     RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS); \
132474cf15cbSJohannes Berg 	BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_ ## bw ## MHZ != \
1325ffe9d734SJohannes Berg 		     RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS)
1326ffe9d734SJohannes Berg 	CHECK_BW(20);
1327ffe9d734SJohannes Berg 	CHECK_BW(40);
1328ffe9d734SJohannes Berg 	CHECK_BW(80);
1329ffe9d734SJohannes Berg 	CHECK_BW(160);
133074cf15cbSJohannes Berg 
133174cf15cbSJohannes Berg 	if (he_mu)
1332ffe9d734SJohannes Berg 		he_mu->flags2 |=
133348c6ebc1SMiri Korenblit 			le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK_V1,
1334ffe9d734SJohannes Berg 						   rate_n_flags),
1335ffe9d734SJohannes Berg 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW);
133648c6ebc1SMiri Korenblit 	else if (he_type == RATE_MCS_HE_TYPE_TRIG_V1)
133774cf15cbSJohannes Berg 		he->data6 |=
133874cf15cbSJohannes Berg 			cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_KNOWN) |
133948c6ebc1SMiri Korenblit 			le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK_V1,
134074cf15cbSJohannes Berg 						   rate_n_flags),
134174cf15cbSJohannes Berg 					 IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW);
1342ffe9d734SJohannes Berg }
1343ffe9d734SJohannes Berg 
iwl_mvm_decode_he_phy_data(struct iwl_mvm * mvm,struct iwl_mvm_rx_phy_data * phy_data,struct ieee80211_radiotap_he * he,struct ieee80211_radiotap_he_mu * he_mu,struct ieee80211_rx_status * rx_status,int queue)134459b8cf0cSJohannes Berg static void iwl_mvm_decode_he_phy_data(struct iwl_mvm *mvm,
1345bdf180c8SShaul Triebitz 				       struct iwl_mvm_rx_phy_data *phy_data,
134659b8cf0cSJohannes Berg 				       struct ieee80211_radiotap_he *he,
134759b8cf0cSJohannes Berg 				       struct ieee80211_radiotap_he_mu *he_mu,
1348ffe9d734SJohannes Berg 				       struct ieee80211_rx_status *rx_status,
1349f1490546SJohannes Berg 				       int queue)
135059b8cf0cSJohannes Berg {
13516721039dSShaul Triebitz 	switch (phy_data->info_type) {
1352bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_NONE:
1353bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_CCK:
1354bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_OFDM_LGCY:
1355bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HT:
1356bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_VHT_SU:
1357bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_VHT_MU:
13580ac93c06SMordechay Goodstein 	case IWL_RX_PHY_INFO_TYPE_EHT_MU:
13590ac93c06SMordechay Goodstein 	case IWL_RX_PHY_INFO_TYPE_EHT_TB:
13600ac93c06SMordechay Goodstein 	case IWL_RX_PHY_INFO_TYPE_EHT_MU_EXT:
13610ac93c06SMordechay Goodstein 	case IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT:
1362bdf180c8SShaul Triebitz 		return;
1363bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT:
1364bdf180c8SShaul Triebitz 		he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN |
1365bdf180c8SShaul Triebitz 					 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE2_KNOWN |
1366bdf180c8SShaul Triebitz 					 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE3_KNOWN |
1367bdf180c8SShaul Triebitz 					 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE4_KNOWN);
1368a197e6d1SEmmanuel Grumbach 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1369bdf180c8SShaul Triebitz 							    IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE1),
1370bdf180c8SShaul Triebitz 					      IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE1);
1371a197e6d1SEmmanuel Grumbach 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1372bdf180c8SShaul Triebitz 							    IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE2),
1373bdf180c8SShaul Triebitz 					      IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE2);
1374a197e6d1SEmmanuel Grumbach 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1375bdf180c8SShaul Triebitz 							    IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE3),
1376bdf180c8SShaul Triebitz 					      IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE3);
1377a197e6d1SEmmanuel Grumbach 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1378bdf180c8SShaul Triebitz 							    IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE4),
1379bdf180c8SShaul Triebitz 					      IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE4);
13805a2abdcaSGustavo A. R. Silva 		fallthrough;
1381bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_SU:
1382bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_MU:
1383bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
1384bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_TB:
1385bdf180c8SShaul Triebitz 		/* HE common */
1386bdf180c8SShaul Triebitz 		he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_LDPC_XSYMSEG_KNOWN |
138769f3ca8eSJohannes Berg 					 IEEE80211_RADIOTAP_HE_DATA1_DOPPLER_KNOWN |
1388bdf180c8SShaul Triebitz 					 IEEE80211_RADIOTAP_HE_DATA1_BSS_COLOR_KNOWN);
1389bdf180c8SShaul Triebitz 		he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRE_FEC_PAD_KNOWN |
139069f3ca8eSJohannes Berg 					 IEEE80211_RADIOTAP_HE_DATA2_PE_DISAMBIG_KNOWN |
1391bdf180c8SShaul Triebitz 					 IEEE80211_RADIOTAP_HE_DATA2_TXOP_KNOWN |
1392bdf180c8SShaul Triebitz 					 IEEE80211_RADIOTAP_HE_DATA2_NUM_LTF_SYMS_KNOWN);
1393bdf180c8SShaul Triebitz 		he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1394bdf180c8SShaul Triebitz 							    IWL_RX_PHY_DATA0_HE_BSS_COLOR_MASK),
139559b8cf0cSJohannes Berg 					      IEEE80211_RADIOTAP_HE_DATA3_BSS_COLOR);
13967969454bSShaul Triebitz 		if (phy_data->info_type != IWL_RX_PHY_INFO_TYPE_HE_TB &&
13977969454bSShaul Triebitz 		    phy_data->info_type != IWL_RX_PHY_INFO_TYPE_HE_TB_EXT) {
13987969454bSShaul Triebitz 			he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_UL_DL_KNOWN);
1399bdf180c8SShaul Triebitz 			he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1400bdf180c8SShaul Triebitz 							    IWL_RX_PHY_DATA0_HE_UPLINK),
140169f3ca8eSJohannes Berg 						      IEEE80211_RADIOTAP_HE_DATA3_UL_DL);
14027969454bSShaul Triebitz 		}
1403bdf180c8SShaul Triebitz 		he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1404bdf180c8SShaul Triebitz 							    IWL_RX_PHY_DATA0_HE_LDPC_EXT_SYM),
140569f3ca8eSJohannes Berg 					      IEEE80211_RADIOTAP_HE_DATA3_LDPC_XSYMSEG);
1406bdf180c8SShaul Triebitz 		he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1407bdf180c8SShaul Triebitz 							    IWL_RX_PHY_DATA0_HE_PRE_FEC_PAD_MASK),
140869f3ca8eSJohannes Berg 					      IEEE80211_RADIOTAP_HE_DATA5_PRE_FEC_PAD);
1409bdf180c8SShaul Triebitz 		he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1410bdf180c8SShaul Triebitz 							    IWL_RX_PHY_DATA0_HE_PE_DISAMBIG),
141169f3ca8eSJohannes Berg 					      IEEE80211_RADIOTAP_HE_DATA5_PE_DISAMBIG);
1412bdf180c8SShaul Triebitz 		he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d1,
1413bdf180c8SShaul Triebitz 							    IWL_RX_PHY_DATA1_HE_LTF_NUM_MASK),
141442d8a9d5SJohannes Berg 					      IEEE80211_RADIOTAP_HE_DATA5_NUM_LTF_SYMS);
1415bdf180c8SShaul Triebitz 		he->data6 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1416bdf180c8SShaul Triebitz 							    IWL_RX_PHY_DATA0_HE_TXOP_DUR_MASK),
1417bdf180c8SShaul Triebitz 					      IEEE80211_RADIOTAP_HE_DATA6_TXOP);
1418bdf180c8SShaul Triebitz 		he->data6 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1419bdf180c8SShaul Triebitz 							    IWL_RX_PHY_DATA0_HE_DOPPLER),
1420bdf180c8SShaul Triebitz 					      IEEE80211_RADIOTAP_HE_DATA6_DOPPLER);
1421fed3c4eaSJohannes Berg 		break;
142259b8cf0cSJohannes Berg 	}
142359b8cf0cSJohannes Berg 
14246721039dSShaul Triebitz 	switch (phy_data->info_type) {
1425bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
14262286a99cSJohannes Berg 	case IWL_RX_PHY_INFO_TYPE_HE_MU:
14272286a99cSJohannes Berg 	case IWL_RX_PHY_INFO_TYPE_HE_SU:
14282286a99cSJohannes Berg 		he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN);
14292286a99cSJohannes Berg 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d0,
14302286a99cSJohannes Berg 							    IWL_RX_PHY_DATA0_HE_SPATIAL_REUSE_MASK),
14312286a99cSJohannes Berg 					      IEEE80211_RADIOTAP_HE_DATA4_SU_MU_SPTL_REUSE);
14322286a99cSJohannes Berg 		break;
14332286a99cSJohannes Berg 	default:
14342286a99cSJohannes Berg 		/* nothing here */
14352286a99cSJohannes Berg 		break;
14362286a99cSJohannes Berg 	}
14372286a99cSJohannes Berg 
14382286a99cSJohannes Berg 	switch (phy_data->info_type) {
14392286a99cSJohannes Berg 	case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
1440bdf180c8SShaul Triebitz 		he_mu->flags1 |=
1441bdf180c8SShaul Triebitz 			le16_encode_bits(le16_get_bits(phy_data->d4,
1442bdf180c8SShaul Triebitz 						       IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_DCM),
1443bdf180c8SShaul Triebitz 					 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM);
1444bdf180c8SShaul Triebitz 		he_mu->flags1 |=
1445bdf180c8SShaul Triebitz 			le16_encode_bits(le16_get_bits(phy_data->d4,
1446bdf180c8SShaul Triebitz 						       IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_MCS_MASK),
1447bdf180c8SShaul Triebitz 					 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS);
1448bdf180c8SShaul Triebitz 		he_mu->flags2 |=
1449bdf180c8SShaul Triebitz 			le16_encode_bits(le16_get_bits(phy_data->d4,
1450bdf180c8SShaul Triebitz 						       IWL_RX_PHY_DATA4_HE_MU_EXT_PREAMBLE_PUNC_TYPE_MASK),
1451bdf180c8SShaul Triebitz 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW);
1452f1490546SJohannes Berg 		iwl_mvm_decode_he_mu_ext(mvm, phy_data, he_mu);
14535a2abdcaSGustavo A. R. Silva 		fallthrough;
1454bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_MU:
1455bdf180c8SShaul Triebitz 		he_mu->flags2 |=
1456bdf180c8SShaul Triebitz 			le16_encode_bits(le32_get_bits(phy_data->d1,
1457bdf180c8SShaul Triebitz 						       IWL_RX_PHY_DATA1_HE_MU_SIBG_SYM_OR_USER_NUM_MASK),
1458bdf180c8SShaul Triebitz 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_SYMS_USERS);
1459bdf180c8SShaul Triebitz 		he_mu->flags2 |=
1460bdf180c8SShaul Triebitz 			le16_encode_bits(le32_get_bits(phy_data->d1,
1461bdf180c8SShaul Triebitz 						       IWL_RX_PHY_DATA1_HE_MU_SIGB_COMPRESSION),
1462bdf180c8SShaul Triebitz 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_COMP);
14635a2abdcaSGustavo A. R. Silva 		fallthrough;
1464bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_TB:
1465bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT:
1466f1490546SJohannes Berg 		iwl_mvm_decode_he_phy_ru_alloc(phy_data, he, he_mu, rx_status);
1467ffe9d734SJohannes Berg 		break;
1468bdf180c8SShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_SU:
1469bdf180c8SShaul Triebitz 		he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BEAM_CHANGE_KNOWN);
1470bdf180c8SShaul Triebitz 		he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1471bdf180c8SShaul Triebitz 							    IWL_RX_PHY_DATA0_HE_BEAM_CHNG),
1472bdf180c8SShaul Triebitz 					      IEEE80211_RADIOTAP_HE_DATA3_BEAM_CHANGE);
1473bdf180c8SShaul Triebitz 		break;
1474ffe9d734SJohannes Berg 	default:
1475ffe9d734SJohannes Berg 		/* nothing */
1476ffe9d734SJohannes Berg 		break;
1477ffe9d734SJohannes Berg 	}
147859b8cf0cSJohannes Berg }
147959b8cf0cSJohannes Berg 
14804ec82585SMordechay Goodstein #define LE32_DEC_ENC(value, dec_bits, enc_bits) \
14814ec82585SMordechay Goodstein 	le32_encode_bits(le32_get_bits(value, dec_bits), enc_bits)
14824ec82585SMordechay Goodstein 
1483feb4a0e2SMordechay Goodstein #define IWL_MVM_ENC_USIG_VALUE_MASK(usig, in_value, dec_bits, enc_bits) do { \
1484feb4a0e2SMordechay Goodstein 	typeof(enc_bits) _enc_bits = enc_bits; \
1485feb4a0e2SMordechay Goodstein 	typeof(usig) _usig = usig; \
1486feb4a0e2SMordechay Goodstein 	(_usig)->mask |= cpu_to_le32(_enc_bits); \
1487feb4a0e2SMordechay Goodstein 	(_usig)->value |= LE32_DEC_ENC(in_value, dec_bits, _enc_bits); \
1488feb4a0e2SMordechay Goodstein } while (0)
1489feb4a0e2SMordechay Goodstein 
14907696c07bSMordechay Goodstein #define __IWL_MVM_ENC_EHT_RU(rt_data, rt_ru, fw_data, fw_ru) \
14917696c07bSMordechay Goodstein 	eht->data[(rt_data)] |= \
14927696c07bSMordechay Goodstein 		(cpu_to_le32 \
14937696c07bSMordechay Goodstein 		 (IEEE80211_RADIOTAP_EHT_DATA ## rt_data ## _RU_ALLOC_CC_ ## rt_ru ## _KNOWN) | \
14947696c07bSMordechay Goodstein 		 LE32_DEC_ENC(data ## fw_data, \
14957696c07bSMordechay Goodstein 			      IWL_RX_PHY_DATA ## fw_data ## _EHT_MU_EXT_RU_ALLOC_ ## fw_ru, \
14967696c07bSMordechay Goodstein 			      IEEE80211_RADIOTAP_EHT_DATA ## rt_data ## _RU_ALLOC_CC_ ## rt_ru))
14977696c07bSMordechay Goodstein 
14987696c07bSMordechay Goodstein #define _IWL_MVM_ENC_EHT_RU(rt_data, rt_ru, fw_data, fw_ru)	\
14997696c07bSMordechay Goodstein 	__IWL_MVM_ENC_EHT_RU(rt_data, rt_ru, fw_data, fw_ru)
15007696c07bSMordechay Goodstein 
15017696c07bSMordechay Goodstein #define IEEE80211_RADIOTAP_RU_DATA_1_1_1	1
15027696c07bSMordechay Goodstein #define IEEE80211_RADIOTAP_RU_DATA_2_1_1	2
15037696c07bSMordechay Goodstein #define IEEE80211_RADIOTAP_RU_DATA_1_1_2	2
15047696c07bSMordechay Goodstein #define IEEE80211_RADIOTAP_RU_DATA_2_1_2	2
15057696c07bSMordechay Goodstein #define IEEE80211_RADIOTAP_RU_DATA_1_2_1	3
15067696c07bSMordechay Goodstein #define IEEE80211_RADIOTAP_RU_DATA_2_2_1	3
15077696c07bSMordechay Goodstein #define IEEE80211_RADIOTAP_RU_DATA_1_2_2	3
15087696c07bSMordechay Goodstein #define IEEE80211_RADIOTAP_RU_DATA_2_2_2	4
15097696c07bSMordechay Goodstein 
15107696c07bSMordechay Goodstein #define IWL_RX_RU_DATA_A1			2
15117696c07bSMordechay Goodstein #define IWL_RX_RU_DATA_A2			2
15127696c07bSMordechay Goodstein #define IWL_RX_RU_DATA_B1			2
15137696c07bSMordechay Goodstein #define IWL_RX_RU_DATA_B2			3
15147696c07bSMordechay Goodstein #define IWL_RX_RU_DATA_C1			3
15157696c07bSMordechay Goodstein #define IWL_RX_RU_DATA_C2			3
15167696c07bSMordechay Goodstein #define IWL_RX_RU_DATA_D1			4
15177696c07bSMordechay Goodstein #define IWL_RX_RU_DATA_D2			4
15187696c07bSMordechay Goodstein 
15197696c07bSMordechay Goodstein #define IWL_MVM_ENC_EHT_RU(rt_ru, fw_ru)				\
15207696c07bSMordechay Goodstein 	_IWL_MVM_ENC_EHT_RU(IEEE80211_RADIOTAP_RU_DATA_ ## rt_ru,	\
15217696c07bSMordechay Goodstein 			    rt_ru,					\
15227696c07bSMordechay Goodstein 			    IWL_RX_RU_DATA_ ## fw_ru,			\
15237696c07bSMordechay Goodstein 			    fw_ru)
15247696c07bSMordechay Goodstein 
iwl_mvm_decode_eht_ext_mu(struct iwl_mvm * mvm,struct iwl_mvm_rx_phy_data * phy_data,struct ieee80211_rx_status * rx_status,struct ieee80211_radiotap_eht * eht,struct ieee80211_radiotap_eht_usig * usig)1525feb4a0e2SMordechay Goodstein static void iwl_mvm_decode_eht_ext_mu(struct iwl_mvm *mvm,
1526feb4a0e2SMordechay Goodstein 				      struct iwl_mvm_rx_phy_data *phy_data,
1527feb4a0e2SMordechay Goodstein 				      struct ieee80211_rx_status *rx_status,
1528feb4a0e2SMordechay Goodstein 				      struct ieee80211_radiotap_eht *eht,
1529feb4a0e2SMordechay Goodstein 				      struct ieee80211_radiotap_eht_usig *usig)
1530feb4a0e2SMordechay Goodstein {
1531feb4a0e2SMordechay Goodstein 	if (phy_data->with_data) {
15327696c07bSMordechay Goodstein 		__le32 data1 = phy_data->d1;
15337696c07bSMordechay Goodstein 		__le32 data2 = phy_data->d2;
15347696c07bSMordechay Goodstein 		__le32 data3 = phy_data->d3;
1535feb4a0e2SMordechay Goodstein 		__le32 data4 = phy_data->eht_d4;
1536feb4a0e2SMordechay Goodstein 		__le32 data5 = phy_data->d5;
15377696c07bSMordechay Goodstein 		u32 phy_bw = phy_data->rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK;
1538feb4a0e2SMordechay Goodstein 
1539feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5,
1540feb4a0e2SMordechay Goodstein 					    IWL_RX_PHY_DATA5_EHT_TYPE_AND_COMP,
1541feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B0_B1_PPDU_TYPE);
1542feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5,
1543feb4a0e2SMordechay Goodstein 					    IWL_RX_PHY_DATA5_EHT_MU_PUNC_CH_CODE,
1544feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B3_B7_PUNCTURED_INFO);
1545feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, data4,
1546feb4a0e2SMordechay Goodstein 					    IWL_RX_PHY_DATA4_EHT_MU_EXT_SIGB_MCS,
1547feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B9_B10_SIG_MCS);
1548feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK
1549feb4a0e2SMordechay Goodstein 			(usig, data1, IWL_RX_PHY_DATA1_EHT_MU_NUM_SIG_SYM_USIGA2,
1550feb4a0e2SMordechay Goodstein 			 IEEE80211_RADIOTAP_EHT_USIG2_MU_B11_B15_EHT_SIG_SYMBOLS);
1551feb4a0e2SMordechay Goodstein 
15527696c07bSMordechay Goodstein 		eht->user_info[0] |=
15537696c07bSMordechay Goodstein 			cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_STA_ID_KNOWN) |
15547696c07bSMordechay Goodstein 			LE32_DEC_ENC(data5, IWL_RX_PHY_DATA5_EHT_MU_STA_ID_USR,
15557696c07bSMordechay Goodstein 				     IEEE80211_RADIOTAP_EHT_USER_INFO_STA_ID);
15567696c07bSMordechay Goodstein 
15577696c07bSMordechay Goodstein 		eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_NR_NON_OFDMA_USERS_M);
15587696c07bSMordechay Goodstein 		eht->data[7] |= LE32_DEC_ENC
15597696c07bSMordechay Goodstein 			(data5, IWL_RX_PHY_DATA5_EHT_MU_NUM_USR_NON_OFDMA,
15607696c07bSMordechay Goodstein 			 IEEE80211_RADIOTAP_EHT_DATA7_NUM_OF_NON_OFDMA_USERS);
15617696c07bSMordechay Goodstein 
15627696c07bSMordechay Goodstein 		/*
15637696c07bSMordechay Goodstein 		 * Hardware labels the content channels/RU allocation values
15647696c07bSMordechay Goodstein 		 * as follows:
15657696c07bSMordechay Goodstein 		 *           Content Channel 1		Content Channel 2
15667696c07bSMordechay Goodstein 		 *   20 MHz: A1
15677696c07bSMordechay Goodstein 		 *   40 MHz: A1				B1
15687696c07bSMordechay Goodstein 		 *   80 MHz: A1 C1			B1 D1
15697696c07bSMordechay Goodstein 		 *  160 MHz: A1 C1 A2 C2		B1 D1 B2 D2
15707696c07bSMordechay Goodstein 		 *  320 MHz: A1 C1 A2 C2 A3 C3 A4 C4	B1 D1 B2 D2 B3 D3 B4 D4
15717696c07bSMordechay Goodstein 		 *
15727696c07bSMordechay Goodstein 		 * However firmware can only give us A1-D2, so the higher
15737696c07bSMordechay Goodstein 		 * frequencies are missing.
15747696c07bSMordechay Goodstein 		 */
15757696c07bSMordechay Goodstein 
15767696c07bSMordechay Goodstein 		switch (phy_bw) {
15777696c07bSMordechay Goodstein 		case RATE_MCS_CHAN_WIDTH_320:
15787696c07bSMordechay Goodstein 			/* additional values are missing in RX metadata */
15797696c07bSMordechay Goodstein 		case RATE_MCS_CHAN_WIDTH_160:
15807696c07bSMordechay Goodstein 			/* content channel 1 */
15817696c07bSMordechay Goodstein 			IWL_MVM_ENC_EHT_RU(1_2_1, A2);
15827696c07bSMordechay Goodstein 			IWL_MVM_ENC_EHT_RU(1_2_2, C2);
15837696c07bSMordechay Goodstein 			/* content channel 2 */
15847696c07bSMordechay Goodstein 			IWL_MVM_ENC_EHT_RU(2_2_1, B2);
15857696c07bSMordechay Goodstein 			IWL_MVM_ENC_EHT_RU(2_2_2, D2);
15867696c07bSMordechay Goodstein 			fallthrough;
15877696c07bSMordechay Goodstein 		case RATE_MCS_CHAN_WIDTH_80:
15887696c07bSMordechay Goodstein 			/* content channel 1 */
15897696c07bSMordechay Goodstein 			IWL_MVM_ENC_EHT_RU(1_1_2, C1);
15907696c07bSMordechay Goodstein 			/* content channel 2 */
15917696c07bSMordechay Goodstein 			IWL_MVM_ENC_EHT_RU(2_1_2, D1);
15927696c07bSMordechay Goodstein 			fallthrough;
15937696c07bSMordechay Goodstein 		case RATE_MCS_CHAN_WIDTH_40:
15947696c07bSMordechay Goodstein 			/* content channel 2 */
15957696c07bSMordechay Goodstein 			IWL_MVM_ENC_EHT_RU(2_1_1, B1);
15967696c07bSMordechay Goodstein 			fallthrough;
15977696c07bSMordechay Goodstein 		case RATE_MCS_CHAN_WIDTH_20:
15987696c07bSMordechay Goodstein 			IWL_MVM_ENC_EHT_RU(1_1_1, A1);
15997696c07bSMordechay Goodstein 			break;
16007696c07bSMordechay Goodstein 		}
1601feb4a0e2SMordechay Goodstein 	} else {
1602feb4a0e2SMordechay Goodstein 		__le32 usig_a1 = phy_data->rx_vec[0];
1603feb4a0e2SMordechay Goodstein 		__le32 usig_a2 = phy_data->rx_vec[1];
1604feb4a0e2SMordechay Goodstein 
1605feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a1,
1606feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A1_DISREGARD,
1607feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG1_MU_B20_B24_DISREGARD);
1608feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a1,
1609feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A1_VALIDATE,
1610feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG1_MU_B25_VALIDATE);
1611feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1612feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A2_EHT_PPDU_TYPE,
1613feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B0_B1_PPDU_TYPE);
1614feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1615feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A2_EHT_USIG2_VALIDATE_B2,
1616feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B2_VALIDATE);
1617feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1618feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A2_EHT_PUNC_CHANNEL,
1619feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B3_B7_PUNCTURED_INFO);
1620feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1621feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A2_EHT_USIG2_VALIDATE_B8,
1622feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B8_VALIDATE);
1623feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1624feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A2_EHT_SIG_MCS,
1625feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B9_B10_SIG_MCS);
1626feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK
1627feb4a0e2SMordechay Goodstein 			(usig, usig_a2, IWL_RX_USIG_A2_EHT_SIG_SYM_NUM,
1628feb4a0e2SMordechay Goodstein 			 IEEE80211_RADIOTAP_EHT_USIG2_MU_B11_B15_EHT_SIG_SYMBOLS);
1629feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1630feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A2_EHT_CRC_OK,
1631feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_MU_B16_B19_CRC);
1632feb4a0e2SMordechay Goodstein 	}
1633feb4a0e2SMordechay Goodstein }
1634feb4a0e2SMordechay Goodstein 
iwl_mvm_decode_eht_ext_tb(struct iwl_mvm * mvm,struct iwl_mvm_rx_phy_data * phy_data,struct ieee80211_rx_status * rx_status,struct ieee80211_radiotap_eht * eht,struct ieee80211_radiotap_eht_usig * usig)1635feb4a0e2SMordechay Goodstein static void iwl_mvm_decode_eht_ext_tb(struct iwl_mvm *mvm,
1636feb4a0e2SMordechay Goodstein 				      struct iwl_mvm_rx_phy_data *phy_data,
1637feb4a0e2SMordechay Goodstein 				      struct ieee80211_rx_status *rx_status,
1638feb4a0e2SMordechay Goodstein 				      struct ieee80211_radiotap_eht *eht,
1639feb4a0e2SMordechay Goodstein 				      struct ieee80211_radiotap_eht_usig *usig)
1640feb4a0e2SMordechay Goodstein {
1641feb4a0e2SMordechay Goodstein 	if (phy_data->with_data) {
1642feb4a0e2SMordechay Goodstein 		__le32 data5 = phy_data->d5;
1643feb4a0e2SMordechay Goodstein 
1644feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5,
1645feb4a0e2SMordechay Goodstein 					    IWL_RX_PHY_DATA5_EHT_TYPE_AND_COMP,
1646feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B0_B1_PPDU_TYPE);
1647feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5,
1648feb4a0e2SMordechay Goodstein 					    IWL_RX_PHY_DATA5_EHT_TB_SPATIAL_REUSE1,
1649feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B3_B6_SPATIAL_REUSE_1);
1650feb4a0e2SMordechay Goodstein 
1651feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, data5,
1652feb4a0e2SMordechay Goodstein 					    IWL_RX_PHY_DATA5_EHT_TB_SPATIAL_REUSE2,
1653feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B7_B10_SPATIAL_REUSE_2);
1654feb4a0e2SMordechay Goodstein 	} else {
1655feb4a0e2SMordechay Goodstein 		__le32 usig_a1 = phy_data->rx_vec[0];
1656feb4a0e2SMordechay Goodstein 		__le32 usig_a2 = phy_data->rx_vec[1];
1657feb4a0e2SMordechay Goodstein 
1658feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a1,
1659feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A1_DISREGARD,
1660feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG1_TB_B20_B25_DISREGARD);
1661feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1662feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A2_EHT_PPDU_TYPE,
1663feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B0_B1_PPDU_TYPE);
1664feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1665feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A2_EHT_USIG2_VALIDATE_B2,
1666feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B2_VALIDATE);
1667feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1668feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A2_EHT_TRIG_SPATIAL_REUSE_1,
1669feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B3_B6_SPATIAL_REUSE_1);
1670feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1671feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A2_EHT_TRIG_SPATIAL_REUSE_2,
1672feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B7_B10_SPATIAL_REUSE_2);
1673feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1674feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A2_EHT_TRIG_USIG2_DISREGARD,
1675feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B11_B15_DISREGARD);
1676feb4a0e2SMordechay Goodstein 		IWL_MVM_ENC_USIG_VALUE_MASK(usig, usig_a2,
1677feb4a0e2SMordechay Goodstein 					    IWL_RX_USIG_A2_EHT_CRC_OK,
1678feb4a0e2SMordechay Goodstein 					    IEEE80211_RADIOTAP_EHT_USIG2_TB_B16_B19_CRC);
1679feb4a0e2SMordechay Goodstein 	}
1680feb4a0e2SMordechay Goodstein }
1681feb4a0e2SMordechay Goodstein 
iwl_mvm_decode_eht_ru(struct iwl_mvm * mvm,struct ieee80211_rx_status * rx_status,struct ieee80211_radiotap_eht * eht)1682e8c0a6fdSMordechay Goodstein static void iwl_mvm_decode_eht_ru(struct iwl_mvm *mvm,
1683e8c0a6fdSMordechay Goodstein 				  struct ieee80211_rx_status *rx_status,
1684e8c0a6fdSMordechay Goodstein 				  struct ieee80211_radiotap_eht *eht)
1685e8c0a6fdSMordechay Goodstein {
1686e8c0a6fdSMordechay Goodstein 	u32 ru = le32_get_bits(eht->data[8],
1687e8c0a6fdSMordechay Goodstein 			       IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_B7_B1);
1688e8c0a6fdSMordechay Goodstein 	enum nl80211_eht_ru_alloc nl_ru;
1689e8c0a6fdSMordechay Goodstein 
1690e8c0a6fdSMordechay Goodstein 	/* Using D1.5 Table 9-53a - Encoding of PS160 and RU Allocation subfields
1691e8c0a6fdSMordechay Goodstein 	 * in an EHT variant User Info field
1692e8c0a6fdSMordechay Goodstein 	 */
1693e8c0a6fdSMordechay Goodstein 
1694e8c0a6fdSMordechay Goodstein 	switch (ru) {
1695e8c0a6fdSMordechay Goodstein 	case 0 ... 36:
1696e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_26;
1697e8c0a6fdSMordechay Goodstein 		break;
1698e8c0a6fdSMordechay Goodstein 	case 37 ... 52:
1699e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_52;
1700e8c0a6fdSMordechay Goodstein 		break;
1701e8c0a6fdSMordechay Goodstein 	case 53 ... 60:
1702e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_106;
1703e8c0a6fdSMordechay Goodstein 		break;
1704e8c0a6fdSMordechay Goodstein 	case 61 ... 64:
1705e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_242;
1706e8c0a6fdSMordechay Goodstein 		break;
1707e8c0a6fdSMordechay Goodstein 	case 65 ... 66:
1708e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_484;
1709e8c0a6fdSMordechay Goodstein 		break;
1710e8c0a6fdSMordechay Goodstein 	case 67:
1711e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_996;
1712e8c0a6fdSMordechay Goodstein 		break;
1713e8c0a6fdSMordechay Goodstein 	case 68:
1714e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_2x996;
1715e8c0a6fdSMordechay Goodstein 		break;
1716e8c0a6fdSMordechay Goodstein 	case 69:
1717e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_4x996;
1718e8c0a6fdSMordechay Goodstein 		break;
1719e8c0a6fdSMordechay Goodstein 	case 70 ... 81:
1720e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_52P26;
1721e8c0a6fdSMordechay Goodstein 		break;
1722e8c0a6fdSMordechay Goodstein 	case 82 ... 89:
1723e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_106P26;
1724e8c0a6fdSMordechay Goodstein 		break;
1725e8c0a6fdSMordechay Goodstein 	case 90 ... 93:
1726e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_484P242;
1727e8c0a6fdSMordechay Goodstein 		break;
1728e8c0a6fdSMordechay Goodstein 	case 94 ... 95:
1729e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_996P484;
1730e8c0a6fdSMordechay Goodstein 		break;
1731e8c0a6fdSMordechay Goodstein 	case 96 ... 99:
1732e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_996P484P242;
1733e8c0a6fdSMordechay Goodstein 		break;
1734e8c0a6fdSMordechay Goodstein 	case 100 ... 103:
1735e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_2x996P484;
1736e8c0a6fdSMordechay Goodstein 		break;
1737e8c0a6fdSMordechay Goodstein 	case 104:
1738e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_3x996;
1739e8c0a6fdSMordechay Goodstein 		break;
1740e8c0a6fdSMordechay Goodstein 	case 105 ... 106:
1741e8c0a6fdSMordechay Goodstein 		nl_ru = NL80211_RATE_INFO_EHT_RU_ALLOC_3x996P484;
1742e8c0a6fdSMordechay Goodstein 		break;
1743e8c0a6fdSMordechay Goodstein 	default:
1744e8c0a6fdSMordechay Goodstein 		return;
1745e8c0a6fdSMordechay Goodstein 	}
1746e8c0a6fdSMordechay Goodstein 
1747e8c0a6fdSMordechay Goodstein 	rx_status->bw = RATE_INFO_BW_EHT_RU;
1748e8c0a6fdSMordechay Goodstein 	rx_status->eht.ru = nl_ru;
1749e8c0a6fdSMordechay Goodstein }
1750e8c0a6fdSMordechay Goodstein 
iwl_mvm_decode_eht_phy_data(struct iwl_mvm * mvm,struct iwl_mvm_rx_phy_data * phy_data,struct ieee80211_rx_status * rx_status,struct ieee80211_radiotap_eht * eht,struct ieee80211_radiotap_eht_usig * usig)17514ec82585SMordechay Goodstein static void iwl_mvm_decode_eht_phy_data(struct iwl_mvm *mvm,
17524ec82585SMordechay Goodstein 					struct iwl_mvm_rx_phy_data *phy_data,
17534ec82585SMordechay Goodstein 					struct ieee80211_rx_status *rx_status,
17544ec82585SMordechay Goodstein 					struct ieee80211_radiotap_eht *eht,
17554ec82585SMordechay Goodstein 					struct ieee80211_radiotap_eht_usig *usig)
17564ec82585SMordechay Goodstein 
17574ec82585SMordechay Goodstein {
17584ec82585SMordechay Goodstein 	__le32 data0 = phy_data->d0;
17594ec82585SMordechay Goodstein 	__le32 data1 = phy_data->d1;
1760feb4a0e2SMordechay Goodstein 	__le32 usig_a1 = phy_data->rx_vec[0];
17614ec82585SMordechay Goodstein 	u8 info_type = phy_data->info_type;
17624ec82585SMordechay Goodstein 
17634ec82585SMordechay Goodstein 	/* Not in EHT range */
17644ec82585SMordechay Goodstein 	if (info_type < IWL_RX_PHY_INFO_TYPE_EHT_MU ||
17654ec82585SMordechay Goodstein 	    info_type > IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT)
17664ec82585SMordechay Goodstein 		return;
17674ec82585SMordechay Goodstein 
17684ec82585SMordechay Goodstein 	usig->common |= cpu_to_le32
17694ec82585SMordechay Goodstein 		(IEEE80211_RADIOTAP_EHT_USIG_COMMON_UL_DL_KNOWN |
17704ec82585SMordechay Goodstein 		 IEEE80211_RADIOTAP_EHT_USIG_COMMON_BSS_COLOR_KNOWN);
1771feb4a0e2SMordechay Goodstein 	if (phy_data->with_data) {
17724ec82585SMordechay Goodstein 		usig->common |= LE32_DEC_ENC(data0,
17734ec82585SMordechay Goodstein 					     IWL_RX_PHY_DATA0_EHT_UPLINK,
17744ec82585SMordechay Goodstein 					     IEEE80211_RADIOTAP_EHT_USIG_COMMON_UL_DL);
17754ec82585SMordechay Goodstein 		usig->common |= LE32_DEC_ENC(data0,
17764ec82585SMordechay Goodstein 					     IWL_RX_PHY_DATA0_EHT_BSS_COLOR_MASK,
1777feb4a0e2SMordechay Goodstein 					     IEEE80211_RADIOTAP_EHT_USIG_COMMON_BSS_COLOR);
1778feb4a0e2SMordechay Goodstein 	} else {
1779feb4a0e2SMordechay Goodstein 		usig->common |= LE32_DEC_ENC(usig_a1,
1780feb4a0e2SMordechay Goodstein 					     IWL_RX_USIG_A1_UL_FLAG,
1781feb4a0e2SMordechay Goodstein 					     IEEE80211_RADIOTAP_EHT_USIG_COMMON_UL_DL);
1782feb4a0e2SMordechay Goodstein 		usig->common |= LE32_DEC_ENC(usig_a1,
1783feb4a0e2SMordechay Goodstein 					     IWL_RX_USIG_A1_BSS_COLOR,
1784feb4a0e2SMordechay Goodstein 					     IEEE80211_RADIOTAP_EHT_USIG_COMMON_BSS_COLOR);
1785feb4a0e2SMordechay Goodstein 	}
17864ec82585SMordechay Goodstein 
1787557b56d5SJohannes Berg 	if (fw_has_capa(&mvm->fw->ucode_capa,
1788557b56d5SJohannes Berg 			IWL_UCODE_TLV_CAPA_SNIFF_VALIDATE_SUPPORT)) {
1789557b56d5SJohannes Berg 		usig->common |=
1790557b56d5SJohannes Berg 			cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_VALIDATE_BITS_CHECKED);
1791557b56d5SJohannes Berg 		usig->common |=
1792557b56d5SJohannes Berg 			LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_VALIDATE,
1793557b56d5SJohannes Berg 				     IEEE80211_RADIOTAP_EHT_USIG_COMMON_VALIDATE_BITS_OK);
1794557b56d5SJohannes Berg 	}
1795557b56d5SJohannes Berg 
17964ec82585SMordechay Goodstein 	eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_SPATIAL_REUSE);
17974ec82585SMordechay Goodstein 	eht->data[0] |= LE32_DEC_ENC(data0,
17984ec82585SMordechay Goodstein 				     IWL_RX_PHY_DATA0_ETH_SPATIAL_REUSE_MASK,
17994ec82585SMordechay Goodstein 				     IEEE80211_RADIOTAP_EHT_DATA0_SPATIAL_REUSE);
18004ec82585SMordechay Goodstein 
18014ec82585SMordechay Goodstein 	/* All RU allocating size/index is in TB format */
18024ec82585SMordechay Goodstein 	eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_RU_ALLOC_TB_FMT);
18034ec82585SMordechay Goodstein 	eht->data[8] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PS160,
18044ec82585SMordechay Goodstein 				     IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_PS_160);
18050e394135SJohannes Berg 	eht->data[8] |= LE32_DEC_ENC(data1, IWL_RX_PHY_DATA1_EHT_RU_ALLOC_B0,
18064ec82585SMordechay Goodstein 				     IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_B0);
18070e394135SJohannes Berg 	eht->data[8] |= LE32_DEC_ENC(data1, IWL_RX_PHY_DATA1_EHT_RU_ALLOC_B1_B7,
18084ec82585SMordechay Goodstein 				     IEEE80211_RADIOTAP_EHT_DATA8_RU_ALLOC_TB_FMT_B7_B1);
18094ec82585SMordechay Goodstein 
1810e8c0a6fdSMordechay Goodstein 	iwl_mvm_decode_eht_ru(mvm, rx_status, eht);
1811e8c0a6fdSMordechay Goodstein 
18125abf3154SMordechay Goodstein 	/* We only get here in case of IWL_RX_MPDU_PHY_TSF_OVERLOAD is set
18135abf3154SMordechay Goodstein 	 * which is on only in case of monitor mode so no need to check monitor
18145abf3154SMordechay Goodstein 	 * mode
18155abf3154SMordechay Goodstein 	 */
18165abf3154SMordechay Goodstein 	eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_PRIMARY_80);
18175abf3154SMordechay Goodstein 	eht->data[1] |=
18185abf3154SMordechay Goodstein 		le32_encode_bits(mvm->monitor_p80,
18195abf3154SMordechay Goodstein 				 IEEE80211_RADIOTAP_EHT_DATA1_PRIMARY_80);
18205abf3154SMordechay Goodstein 
18214ec82585SMordechay Goodstein 	usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_TXOP_KNOWN);
1822feb4a0e2SMordechay Goodstein 	if (phy_data->with_data)
18234ec82585SMordechay Goodstein 		usig->common |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_TXOP_DUR_MASK,
18244ec82585SMordechay Goodstein 					     IEEE80211_RADIOTAP_EHT_USIG_COMMON_TXOP);
1825feb4a0e2SMordechay Goodstein 	else
1826feb4a0e2SMordechay Goodstein 		usig->common |= LE32_DEC_ENC(usig_a1, IWL_RX_USIG_A1_TXOP_DURATION,
1827feb4a0e2SMordechay Goodstein 					     IEEE80211_RADIOTAP_EHT_USIG_COMMON_TXOP);
1828feb4a0e2SMordechay Goodstein 
18294ec82585SMordechay Goodstein 	eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_LDPC_EXTRA_SYM_OM);
18304ec82585SMordechay Goodstein 	eht->data[0] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_LDPC_EXT_SYM,
18314ec82585SMordechay Goodstein 				     IEEE80211_RADIOTAP_EHT_DATA0_LDPC_EXTRA_SYM_OM);
18324ec82585SMordechay Goodstein 
18334ec82585SMordechay Goodstein 	eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_PRE_PADD_FACOR_OM);
18344ec82585SMordechay Goodstein 	eht->data[0] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PRE_FEC_PAD_MASK,
18354ec82585SMordechay Goodstein 				    IEEE80211_RADIOTAP_EHT_DATA0_PRE_PADD_FACOR_OM);
18364ec82585SMordechay Goodstein 
18374ec82585SMordechay Goodstein 	eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_PE_DISAMBIGUITY_OM);
18384ec82585SMordechay Goodstein 	eht->data[0] |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PE_DISAMBIG,
18394ec82585SMordechay Goodstein 				     IEEE80211_RADIOTAP_EHT_DATA0_PE_DISAMBIGUITY_OM);
18404ec82585SMordechay Goodstein 
18414ec82585SMordechay Goodstein 	/* TODO: what about IWL_RX_PHY_DATA0_EHT_BW320_SLOT */
18424ec82585SMordechay Goodstein 
18434ec82585SMordechay Goodstein 	if (!le32_get_bits(data0, IWL_RX_PHY_DATA0_EHT_SIGA_CRC_OK))
18444ec82585SMordechay Goodstein 		usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BAD_USIG_CRC);
18454ec82585SMordechay Goodstein 
18464ec82585SMordechay Goodstein 	usig->common |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_PHY_VER_KNOWN);
18474ec82585SMordechay Goodstein 	usig->common |= LE32_DEC_ENC(data0, IWL_RX_PHY_DATA0_EHT_PHY_VER,
18484ec82585SMordechay Goodstein 				     IEEE80211_RADIOTAP_EHT_USIG_COMMON_PHY_VER);
1849feb4a0e2SMordechay Goodstein 
1850feb4a0e2SMordechay Goodstein 	/*
1851feb4a0e2SMordechay Goodstein 	 * TODO: what about TB - IWL_RX_PHY_DATA1_EHT_TB_PILOT_TYPE,
1852feb4a0e2SMordechay Goodstein 	 *			 IWL_RX_PHY_DATA1_EHT_TB_LOW_SS
1853feb4a0e2SMordechay Goodstein 	 */
1854feb4a0e2SMordechay Goodstein 
1855feb4a0e2SMordechay Goodstein 	eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_EHT_LTF);
1856feb4a0e2SMordechay Goodstein 	eht->data[0] |= LE32_DEC_ENC(data1, IWL_RX_PHY_DATA1_EHT_SIG_LTF_NUM,
1857feb4a0e2SMordechay Goodstein 				     IEEE80211_RADIOTAP_EHT_DATA0_EHT_LTF);
1858feb4a0e2SMordechay Goodstein 
1859feb4a0e2SMordechay Goodstein 	if (info_type == IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT ||
1860feb4a0e2SMordechay Goodstein 	    info_type == IWL_RX_PHY_INFO_TYPE_EHT_TB)
1861feb4a0e2SMordechay Goodstein 		iwl_mvm_decode_eht_ext_tb(mvm, phy_data, rx_status, eht, usig);
1862feb4a0e2SMordechay Goodstein 
1863feb4a0e2SMordechay Goodstein 	if (info_type == IWL_RX_PHY_INFO_TYPE_EHT_MU_EXT ||
1864feb4a0e2SMordechay Goodstein 	    info_type == IWL_RX_PHY_INFO_TYPE_EHT_MU)
1865feb4a0e2SMordechay Goodstein 		iwl_mvm_decode_eht_ext_mu(mvm, phy_data, rx_status, eht, usig);
18664ec82585SMordechay Goodstein }
18674ec82585SMordechay Goodstein 
iwl_mvm_rx_eht(struct iwl_mvm * mvm,struct sk_buff * skb,struct iwl_mvm_rx_phy_data * phy_data,int queue)186824f7f6e3SMordechay Goodstein static void iwl_mvm_rx_eht(struct iwl_mvm *mvm, struct sk_buff *skb,
186924f7f6e3SMordechay Goodstein 			   struct iwl_mvm_rx_phy_data *phy_data,
187024f7f6e3SMordechay Goodstein 			   int queue)
187124f7f6e3SMordechay Goodstein {
187224f7f6e3SMordechay Goodstein 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
187324f7f6e3SMordechay Goodstein 
187424f7f6e3SMordechay Goodstein 	struct ieee80211_radiotap_eht *eht;
187524f7f6e3SMordechay Goodstein 	struct ieee80211_radiotap_eht_usig *usig;
1876b55c1f4eSIlan Peer 	size_t eht_len = sizeof(*eht);
187724f7f6e3SMordechay Goodstein 
187824f7f6e3SMordechay Goodstein 	u32 rate_n_flags = phy_data->rate_n_flags;
187924f7f6e3SMordechay Goodstein 	u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK;
188024f7f6e3SMordechay Goodstein 	/* EHT and HE have the same valus for LTF */
188124f7f6e3SMordechay Goodstein 	u8 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN;
188224f7f6e3SMordechay Goodstein 	u16 phy_info = phy_data->phy_info;
188324f7f6e3SMordechay Goodstein 	u32 bw;
188424f7f6e3SMordechay Goodstein 
188524f7f6e3SMordechay Goodstein 	/* u32 for 1 user_info */
1886b55c1f4eSIlan Peer 	if (phy_data->with_data)
1887b55c1f4eSIlan Peer 		eht_len += sizeof(u32);
1888b55c1f4eSIlan Peer 
1889b55c1f4eSIlan Peer 	eht = iwl_mvm_radiotap_put_tlv(skb, IEEE80211_RADIOTAP_EHT, eht_len);
189024f7f6e3SMordechay Goodstein 
189124f7f6e3SMordechay Goodstein 	usig = iwl_mvm_radiotap_put_tlv(skb, IEEE80211_RADIOTAP_EHT_USIG,
189224f7f6e3SMordechay Goodstein 					sizeof(*usig));
189324f7f6e3SMordechay Goodstein 	rx_status->flag |= RX_FLAG_RADIOTAP_TLV_AT_END;
189424f7f6e3SMordechay Goodstein 	usig->common |=
189524f7f6e3SMordechay Goodstein 		cpu_to_le32(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BW_KNOWN);
189624f7f6e3SMordechay Goodstein 
189724f7f6e3SMordechay Goodstein 	/* specific handling for 320MHz */
189824f7f6e3SMordechay Goodstein 	bw = FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK, rate_n_flags);
189924f7f6e3SMordechay Goodstein 	if (bw == RATE_MCS_CHAN_WIDTH_320_VAL)
190024f7f6e3SMordechay Goodstein 		bw += FIELD_GET(IWL_RX_PHY_DATA0_EHT_BW320_SLOT,
190124f7f6e3SMordechay Goodstein 				le32_to_cpu(phy_data->d0));
190224f7f6e3SMordechay Goodstein 
190324f7f6e3SMordechay Goodstein 	usig->common |= cpu_to_le32
190424f7f6e3SMordechay Goodstein 		(FIELD_PREP(IEEE80211_RADIOTAP_EHT_USIG_COMMON_BW, bw));
190524f7f6e3SMordechay Goodstein 
190624f7f6e3SMordechay Goodstein 	/* report the AMPDU-EOF bit on single frames */
190724f7f6e3SMordechay Goodstein 	if (!queue && !(phy_info & IWL_RX_MPDU_PHY_AMPDU)) {
190824f7f6e3SMordechay Goodstein 		rx_status->flag |= RX_FLAG_AMPDU_DETAILS;
190924f7f6e3SMordechay Goodstein 		rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN;
191024f7f6e3SMordechay Goodstein 		if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_EHT_DELIM_EOF))
191124f7f6e3SMordechay Goodstein 			rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT;
191224f7f6e3SMordechay Goodstein 	}
191324f7f6e3SMordechay Goodstein 
191424f7f6e3SMordechay Goodstein 	/* update aggregation data for monitor sake on default queue */
191524f7f6e3SMordechay Goodstein 	if (!queue && (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) &&
1916da118544SJohannes Berg 	    (phy_info & IWL_RX_MPDU_PHY_AMPDU) && phy_data->first_subframe) {
191724f7f6e3SMordechay Goodstein 		rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN;
191824f7f6e3SMordechay Goodstein 		if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_EHT_DELIM_EOF))
191924f7f6e3SMordechay Goodstein 			rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT;
192024f7f6e3SMordechay Goodstein 	}
192124f7f6e3SMordechay Goodstein 
19224ec82585SMordechay Goodstein 	if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD)
19234ec82585SMordechay Goodstein 		iwl_mvm_decode_eht_phy_data(mvm, phy_data, rx_status, eht, usig);
192424f7f6e3SMordechay Goodstein 
192524f7f6e3SMordechay Goodstein #define CHECK_TYPE(F)							\
192624f7f6e3SMordechay Goodstein 	BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_ ## F !=	\
192724f7f6e3SMordechay Goodstein 		     (RATE_MCS_HE_TYPE_ ## F >> RATE_MCS_HE_TYPE_POS))
192824f7f6e3SMordechay Goodstein 
192924f7f6e3SMordechay Goodstein 	CHECK_TYPE(SU);
193024f7f6e3SMordechay Goodstein 	CHECK_TYPE(EXT_SU);
193124f7f6e3SMordechay Goodstein 	CHECK_TYPE(MU);
193224f7f6e3SMordechay Goodstein 	CHECK_TYPE(TRIG);
193324f7f6e3SMordechay Goodstein 
193424f7f6e3SMordechay Goodstein 	switch (FIELD_GET(RATE_MCS_HE_GI_LTF_MSK, rate_n_flags)) {
193524f7f6e3SMordechay Goodstein 	case 0:
193624f7f6e3SMordechay Goodstein 		if (he_type == RATE_MCS_HE_TYPE_TRIG) {
193724f7f6e3SMordechay Goodstein 			rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_1_6;
193824f7f6e3SMordechay Goodstein 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X;
193924f7f6e3SMordechay Goodstein 		} else {
194024f7f6e3SMordechay Goodstein 			rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_0_8;
194124f7f6e3SMordechay Goodstein 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X;
194224f7f6e3SMordechay Goodstein 		}
194324f7f6e3SMordechay Goodstein 		break;
194424f7f6e3SMordechay Goodstein 	case 1:
194524f7f6e3SMordechay Goodstein 		rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_1_6;
194624f7f6e3SMordechay Goodstein 		ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X;
194724f7f6e3SMordechay Goodstein 		break;
194824f7f6e3SMordechay Goodstein 	case 2:
194924f7f6e3SMordechay Goodstein 		ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
195024f7f6e3SMordechay Goodstein 		if (he_type == RATE_MCS_HE_TYPE_TRIG)
195124f7f6e3SMordechay Goodstein 			rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_3_2;
195224f7f6e3SMordechay Goodstein 		else
195324f7f6e3SMordechay Goodstein 			rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_0_8;
195424f7f6e3SMordechay Goodstein 		break;
195524f7f6e3SMordechay Goodstein 	case 3:
195624f7f6e3SMordechay Goodstein 		if (he_type != RATE_MCS_HE_TYPE_TRIG) {
195724f7f6e3SMordechay Goodstein 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
195824f7f6e3SMordechay Goodstein 			rx_status->eht.gi = NL80211_RATE_INFO_EHT_GI_3_2;
195924f7f6e3SMordechay Goodstein 		}
196024f7f6e3SMordechay Goodstein 		break;
196124f7f6e3SMordechay Goodstein 	default:
196224f7f6e3SMordechay Goodstein 		/* nothing here */
196324f7f6e3SMordechay Goodstein 		break;
196424f7f6e3SMordechay Goodstein 	}
196524f7f6e3SMordechay Goodstein 
196624f7f6e3SMordechay Goodstein 	if (ltf != IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN) {
196724f7f6e3SMordechay Goodstein 		eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_GI);
196824f7f6e3SMordechay Goodstein 		eht->data[0] |= cpu_to_le32
196924f7f6e3SMordechay Goodstein 			(FIELD_PREP(IEEE80211_RADIOTAP_EHT_DATA0_LTF,
197024f7f6e3SMordechay Goodstein 				    ltf) |
197124f7f6e3SMordechay Goodstein 			 FIELD_PREP(IEEE80211_RADIOTAP_EHT_DATA0_GI,
197224f7f6e3SMordechay Goodstein 				    rx_status->eht.gi));
197324f7f6e3SMordechay Goodstein 	}
197424f7f6e3SMordechay Goodstein 
1975b55c1f4eSIlan Peer 
1976b55c1f4eSIlan Peer 	if (!phy_data->with_data) {
1977b55c1f4eSIlan Peer 		eht->known |= cpu_to_le32(IEEE80211_RADIOTAP_EHT_KNOWN_NSS_S |
1978b55c1f4eSIlan Peer 					  IEEE80211_RADIOTAP_EHT_KNOWN_BEAMFORMED_S);
1979b55c1f4eSIlan Peer 		eht->data[7] |=
1980b55c1f4eSIlan Peer 			le32_encode_bits(le32_get_bits(phy_data->rx_vec[2],
1981b55c1f4eSIlan Peer 						       RX_NO_DATA_RX_VEC2_EHT_NSTS_MSK),
1982b55c1f4eSIlan Peer 					 IEEE80211_RADIOTAP_EHT_DATA7_NSS_S);
1983b55c1f4eSIlan Peer 		if (rate_n_flags & RATE_MCS_BF_MSK)
1984b55c1f4eSIlan Peer 			eht->data[7] |=
1985b55c1f4eSIlan Peer 				cpu_to_le32(IEEE80211_RADIOTAP_EHT_DATA7_BEAMFORMED_S);
1986b55c1f4eSIlan Peer 	} else {
1987b55c1f4eSIlan Peer 		eht->user_info[0] |=
1988b55c1f4eSIlan Peer 			cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_MCS_KNOWN |
198924f7f6e3SMordechay Goodstein 				    IEEE80211_RADIOTAP_EHT_USER_INFO_CODING_KNOWN |
199024f7f6e3SMordechay Goodstein 				    IEEE80211_RADIOTAP_EHT_USER_INFO_NSS_KNOWN_O |
199124f7f6e3SMordechay Goodstein 				    IEEE80211_RADIOTAP_EHT_USER_INFO_BEAMFORMING_KNOWN_O |
199224f7f6e3SMordechay Goodstein 				    IEEE80211_RADIOTAP_EHT_USER_INFO_DATA_FOR_USER);
199324f7f6e3SMordechay Goodstein 
199424f7f6e3SMordechay Goodstein 		if (rate_n_flags & RATE_MCS_BF_MSK)
199524f7f6e3SMordechay Goodstein 			eht->user_info[0] |=
199624f7f6e3SMordechay Goodstein 				cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_BEAMFORMING_O);
199724f7f6e3SMordechay Goodstein 
199824f7f6e3SMordechay Goodstein 		if (rate_n_flags & RATE_MCS_LDPC_MSK)
199924f7f6e3SMordechay Goodstein 			eht->user_info[0] |=
200024f7f6e3SMordechay Goodstein 				cpu_to_le32(IEEE80211_RADIOTAP_EHT_USER_INFO_CODING);
200124f7f6e3SMordechay Goodstein 
200224f7f6e3SMordechay Goodstein 		eht->user_info[0] |= cpu_to_le32
200324f7f6e3SMordechay Goodstein 			(FIELD_PREP(IEEE80211_RADIOTAP_EHT_USER_INFO_MCS,
200424f7f6e3SMordechay Goodstein 				    FIELD_GET(RATE_VHT_MCS_RATE_CODE_MSK,
200524f7f6e3SMordechay Goodstein 					      rate_n_flags)) |
200624f7f6e3SMordechay Goodstein 			 FIELD_PREP(IEEE80211_RADIOTAP_EHT_USER_INFO_NSS_O,
200724f7f6e3SMordechay Goodstein 				    FIELD_GET(RATE_MCS_NSS_MSK, rate_n_flags)));
200824f7f6e3SMordechay Goodstein 	}
2009b55c1f4eSIlan Peer }
201024f7f6e3SMordechay Goodstein 
iwl_mvm_rx_he(struct iwl_mvm * mvm,struct sk_buff * skb,struct iwl_mvm_rx_phy_data * phy_data,int queue)2011c630b477SSara Sharon static void iwl_mvm_rx_he(struct iwl_mvm *mvm, struct sk_buff *skb,
20126721039dSShaul Triebitz 			  struct iwl_mvm_rx_phy_data *phy_data,
2013f1490546SJohannes Berg 			  int queue)
2014c630b477SSara Sharon {
2015c630b477SSara Sharon 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
2016c630b477SSara Sharon 	struct ieee80211_radiotap_he *he = NULL;
2017c630b477SSara Sharon 	struct ieee80211_radiotap_he_mu *he_mu = NULL;
2018f1490546SJohannes Berg 	u32 rate_n_flags = phy_data->rate_n_flags;
2019ce712478SLuca Coelho 	u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK;
20203d579204SJohannes Berg 	u8 ltf;
2021c630b477SSara Sharon 	static const struct ieee80211_radiotap_he known = {
2022c630b477SSara Sharon 		.data1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_DATA_MCS_KNOWN |
2023c630b477SSara Sharon 				     IEEE80211_RADIOTAP_HE_DATA1_DATA_DCM_KNOWN |
2024c630b477SSara Sharon 				     IEEE80211_RADIOTAP_HE_DATA1_STBC_KNOWN |
2025c630b477SSara Sharon 				     IEEE80211_RADIOTAP_HE_DATA1_CODING_KNOWN),
2026c630b477SSara Sharon 		.data2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_GI_KNOWN |
2027c630b477SSara Sharon 				     IEEE80211_RADIOTAP_HE_DATA2_TXBF_KNOWN),
2028c630b477SSara Sharon 	};
2029c630b477SSara Sharon 	static const struct ieee80211_radiotap_he_mu mu_known = {
2030c630b477SSara Sharon 		.flags1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS_KNOWN |
2031c630b477SSara Sharon 				      IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM_KNOWN |
2032c630b477SSara Sharon 				      IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_SYMS_USERS_KNOWN |
2033c630b477SSara Sharon 				      IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_COMP_KNOWN),
2034dabf9844SJohannes Berg 		.flags2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW_KNOWN |
2035dabf9844SJohannes Berg 				      IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_KNOWN),
2036c630b477SSara Sharon 	};
2037f1490546SJohannes Berg 	u16 phy_info = phy_data->phy_info;
2038c630b477SSara Sharon 
2039c630b477SSara Sharon 	he = skb_put_data(skb, &known, sizeof(known));
2040c630b477SSara Sharon 	rx_status->flag |= RX_FLAG_RADIOTAP_HE;
2041c630b477SSara Sharon 
20426721039dSShaul Triebitz 	if (phy_data->info_type == IWL_RX_PHY_INFO_TYPE_HE_MU ||
20436721039dSShaul Triebitz 	    phy_data->info_type == IWL_RX_PHY_INFO_TYPE_HE_MU_EXT) {
2044f9fe5793SJohannes Berg 		he_mu = skb_put_data(skb, &mu_known, sizeof(mu_known));
2045c630b477SSara Sharon 		rx_status->flag |= RX_FLAG_RADIOTAP_HE_MU;
2046c630b477SSara Sharon 	}
2047c630b477SSara Sharon 
204859b8cf0cSJohannes Berg 	/* report the AMPDU-EOF bit on single frames */
2049c630b477SSara Sharon 	if (!queue && !(phy_info & IWL_RX_MPDU_PHY_AMPDU)) {
2050c630b477SSara Sharon 		rx_status->flag |= RX_FLAG_AMPDU_DETAILS;
2051c630b477SSara Sharon 		rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN;
20526721039dSShaul Triebitz 		if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_HE_DELIM_EOF))
2053c630b477SSara Sharon 			rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT;
2054c630b477SSara Sharon 	}
2055c630b477SSara Sharon 
2056bdf180c8SShaul Triebitz 	if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD)
20576721039dSShaul Triebitz 		iwl_mvm_decode_he_phy_data(mvm, phy_data, he, he_mu, rx_status,
2058f1490546SJohannes Berg 					   queue);
2059c630b477SSara Sharon 
2060c630b477SSara Sharon 	/* update aggregation data for monitor sake on default queue */
2061bdf180c8SShaul Triebitz 	if (!queue && (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) &&
2062da118544SJohannes Berg 	    (phy_info & IWL_RX_MPDU_PHY_AMPDU) && phy_data->first_subframe) {
2063c630b477SSara Sharon 		rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN;
2064da118544SJohannes Berg 		if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_EHT_DELIM_EOF))
2065c630b477SSara Sharon 			rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT;
2066c630b477SSara Sharon 	}
2067c630b477SSara Sharon 
2068ce712478SLuca Coelho 	if (he_type == RATE_MCS_HE_TYPE_EXT_SU &&
2069ce712478SLuca Coelho 	    rate_n_flags & RATE_MCS_HE_106T_MSK) {
2070c630b477SSara Sharon 		rx_status->bw = RATE_INFO_BW_HE_RU;
2071c630b477SSara Sharon 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106;
2072c630b477SSara Sharon 	}
2073dabf9844SJohannes Berg 
2074ffe9d734SJohannes Berg 	/* actually data is filled in mac80211 */
2075ce712478SLuca Coelho 	if (he_type == RATE_MCS_HE_TYPE_SU ||
2076ce712478SLuca Coelho 	    he_type == RATE_MCS_HE_TYPE_EXT_SU)
2077dabf9844SJohannes Berg 		he->data1 |=
2078dabf9844SJohannes Berg 			cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN);
2079dabf9844SJohannes Berg 
2080c630b477SSara Sharon #define CHECK_TYPE(F)							\
2081c630b477SSara Sharon 	BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_ ## F !=	\
2082ce712478SLuca Coelho 		     (RATE_MCS_HE_TYPE_ ## F >> RATE_MCS_HE_TYPE_POS))
2083c630b477SSara Sharon 
2084c630b477SSara Sharon 	CHECK_TYPE(SU);
2085c630b477SSara Sharon 	CHECK_TYPE(EXT_SU);
2086c630b477SSara Sharon 	CHECK_TYPE(MU);
2087c630b477SSara Sharon 	CHECK_TYPE(TRIG);
2088c630b477SSara Sharon 
2089ce712478SLuca Coelho 	he->data1 |= cpu_to_le16(he_type >> RATE_MCS_HE_TYPE_POS);
2090c630b477SSara Sharon 
2091caf3216fSShaul Triebitz 	if (rate_n_flags & RATE_MCS_BF_MSK)
2092c630b477SSara Sharon 		he->data5 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA5_TXBF);
2093c630b477SSara Sharon 
2094ce712478SLuca Coelho 	switch ((rate_n_flags & RATE_MCS_HE_GI_LTF_MSK) >>
2095c630b477SSara Sharon 		RATE_MCS_HE_GI_LTF_POS) {
2096c630b477SSara Sharon 	case 0:
2097ce712478SLuca Coelho 		if (he_type == RATE_MCS_HE_TYPE_TRIG)
209893cc712aSJohannes Berg 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
209993cc712aSJohannes Berg 		else
2100c630b477SSara Sharon 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
2101ce712478SLuca Coelho 		if (he_type == RATE_MCS_HE_TYPE_MU)
2102de8da230SJohannes Berg 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
2103de8da230SJohannes Berg 		else
2104de8da230SJohannes Berg 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X;
2105c630b477SSara Sharon 		break;
2106c630b477SSara Sharon 	case 1:
2107ce712478SLuca Coelho 		if (he_type == RATE_MCS_HE_TYPE_TRIG)
210893cc712aSJohannes Berg 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
210993cc712aSJohannes Berg 		else
2110c630b477SSara Sharon 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
2111de8da230SJohannes Berg 		ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X;
2112c630b477SSara Sharon 		break;
2113c630b477SSara Sharon 	case 2:
2114ce712478SLuca Coelho 		if (he_type == RATE_MCS_HE_TYPE_TRIG) {
211593cc712aSJohannes Berg 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
2116de8da230SJohannes Berg 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
211793cc712aSJohannes Berg 		} else {
211893cc712aSJohannes Berg 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
2119de8da230SJohannes Berg 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X;
212093cc712aSJohannes Berg 		}
2121c630b477SSara Sharon 		break;
2122c630b477SSara Sharon 	case 3:
2123c630b477SSara Sharon 		rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
2124de8da230SJohannes Berg 		ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
2125c630b477SSara Sharon 		break;
2126ce712478SLuca Coelho 	case 4:
2127ce712478SLuca Coelho 		rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
2128ce712478SLuca Coelho 		ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
2129ce712478SLuca Coelho 		break;
2130ce712478SLuca Coelho 	default:
2131ce712478SLuca Coelho 		ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_UNKNOWN;
2132c630b477SSara Sharon 	}
2133c630b477SSara Sharon 
2134bdf180c8SShaul Triebitz 	he->data5 |= le16_encode_bits(ltf,
2135bdf180c8SShaul Triebitz 				      IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE);
2136c630b477SSara Sharon }
2137c630b477SSara Sharon 
iwl_mvm_decode_lsig(struct sk_buff * skb,struct iwl_mvm_rx_phy_data * phy_data)21386721039dSShaul Triebitz static void iwl_mvm_decode_lsig(struct sk_buff *skb,
21396721039dSShaul Triebitz 				struct iwl_mvm_rx_phy_data *phy_data)
21406721039dSShaul Triebitz {
21416721039dSShaul Triebitz 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
21426721039dSShaul Triebitz 	struct ieee80211_radiotap_lsig *lsig;
21436721039dSShaul Triebitz 
21446721039dSShaul Triebitz 	switch (phy_data->info_type) {
21456721039dSShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HT:
21466721039dSShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_VHT_SU:
21476721039dSShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_VHT_MU:
21486721039dSShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT:
21496721039dSShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_SU:
21506721039dSShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_MU:
21516721039dSShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
21526721039dSShaul Triebitz 	case IWL_RX_PHY_INFO_TYPE_HE_TB:
2153eccfe017SMordechay Goodstein 	case IWL_RX_PHY_INFO_TYPE_EHT_MU:
2154eccfe017SMordechay Goodstein 	case IWL_RX_PHY_INFO_TYPE_EHT_TB:
2155eccfe017SMordechay Goodstein 	case IWL_RX_PHY_INFO_TYPE_EHT_MU_EXT:
2156eccfe017SMordechay Goodstein 	case IWL_RX_PHY_INFO_TYPE_EHT_TB_EXT:
21576721039dSShaul Triebitz 		lsig = skb_put(skb, sizeof(*lsig));
21586721039dSShaul Triebitz 		lsig->data1 = cpu_to_le16(IEEE80211_RADIOTAP_LSIG_DATA1_LENGTH_KNOWN);
21596721039dSShaul Triebitz 		lsig->data2 = le16_encode_bits(le32_get_bits(phy_data->d1,
21606721039dSShaul Triebitz 							     IWL_RX_PHY_DATA1_LSIG_LEN_MASK),
21616721039dSShaul Triebitz 					       IEEE80211_RADIOTAP_LSIG_DATA2_LENGTH);
21626721039dSShaul Triebitz 		rx_status->flag |= RX_FLAG_RADIOTAP_LSIG;
21636721039dSShaul Triebitz 		break;
21646721039dSShaul Triebitz 	default:
21656721039dSShaul Triebitz 		break;
21666721039dSShaul Triebitz 	}
21676721039dSShaul Triebitz }
21686721039dSShaul Triebitz 
iwl_mvm_nl80211_band_from_rx_msdu(u8 phy_band)216965b9425cSTova Mussai static inline u8 iwl_mvm_nl80211_band_from_rx_msdu(u8 phy_band)
217065b9425cSTova Mussai {
217165b9425cSTova Mussai 	switch (phy_band) {
217265b9425cSTova Mussai 	case PHY_BAND_24:
217365b9425cSTova Mussai 		return NL80211_BAND_2GHZ;
217465b9425cSTova Mussai 	case PHY_BAND_5:
217565b9425cSTova Mussai 		return NL80211_BAND_5GHZ;
2176eae94cf8SLuca Coelho 	case PHY_BAND_6:
2177eae94cf8SLuca Coelho 		return NL80211_BAND_6GHZ;
217865b9425cSTova Mussai 	default:
217965b9425cSTova Mussai 		WARN_ONCE(1, "Unsupported phy band (%u)\n", phy_band);
218065b9425cSTova Mussai 		return NL80211_BAND_5GHZ;
218165b9425cSTova Mussai 	}
218265b9425cSTova Mussai }
218365b9425cSTova Mussai 
2184e5d153ecSEmmanuel Grumbach struct iwl_rx_sta_csa {
2185e5d153ecSEmmanuel Grumbach 	bool all_sta_unblocked;
2186e5d153ecSEmmanuel Grumbach 	struct ieee80211_vif *vif;
2187e5d153ecSEmmanuel Grumbach };
2188e5d153ecSEmmanuel Grumbach 
iwl_mvm_rx_get_sta_block_tx(void * data,struct ieee80211_sta * sta)2189e5d153ecSEmmanuel Grumbach static void iwl_mvm_rx_get_sta_block_tx(void *data, struct ieee80211_sta *sta)
2190e5d153ecSEmmanuel Grumbach {
2191e5d153ecSEmmanuel Grumbach 	struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2192e5d153ecSEmmanuel Grumbach 	struct iwl_rx_sta_csa *rx_sta_csa = data;
2193e5d153ecSEmmanuel Grumbach 
2194e5d153ecSEmmanuel Grumbach 	if (mvmsta->vif != rx_sta_csa->vif)
2195e5d153ecSEmmanuel Grumbach 		return;
2196e5d153ecSEmmanuel Grumbach 
2197e5d153ecSEmmanuel Grumbach 	if (mvmsta->disable_tx)
2198e5d153ecSEmmanuel Grumbach 		rx_sta_csa->all_sta_unblocked = false;
2199e5d153ecSEmmanuel Grumbach }
2200e5d153ecSEmmanuel Grumbach 
2201f1490546SJohannes Berg /*
2202f1490546SJohannes Berg  * Note: requires also rx_status->band to be prefilled, as well
2203f1490546SJohannes Berg  * as phy_data (apart from phy_data->info_type)
2204f1490546SJohannes Berg  */
iwl_mvm_rx_fill_status(struct iwl_mvm * mvm,struct sk_buff * skb,struct iwl_mvm_rx_phy_data * phy_data,int queue)2205f1490546SJohannes Berg static void iwl_mvm_rx_fill_status(struct iwl_mvm *mvm,
2206f1490546SJohannes Berg 				   struct sk_buff *skb,
2207f1490546SJohannes Berg 				   struct iwl_mvm_rx_phy_data *phy_data,
2208f1490546SJohannes Berg 				   int queue)
2209f1490546SJohannes Berg {
2210f1490546SJohannes Berg 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
2211f1490546SJohannes Berg 	u32 rate_n_flags = phy_data->rate_n_flags;
2212f1490546SJohannes Berg 	u8 stbc = u32_get_bits(rate_n_flags, RATE_MCS_STBC_MSK);
2213f1490546SJohannes Berg 	u32 format = rate_n_flags & RATE_MCS_MOD_TYPE_MSK;
2214f1490546SJohannes Berg 	bool is_sgi;
2215f1490546SJohannes Berg 
2216f1490546SJohannes Berg 	phy_data->info_type = IWL_RX_PHY_INFO_TYPE_NONE;
2217f1490546SJohannes Berg 
2218f1490546SJohannes Berg 	if (phy_data->phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD)
2219f1490546SJohannes Berg 		phy_data->info_type =
2220f1490546SJohannes Berg 			le32_get_bits(phy_data->d1,
2221f1490546SJohannes Berg 				      IWL_RX_PHY_DATA1_INFO_TYPE_MASK);
2222f1490546SJohannes Berg 
2223f1490546SJohannes Berg 	/* This may be overridden by iwl_mvm_rx_he() to HE_RU */
2224f1490546SJohannes Berg 	switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
2225f1490546SJohannes Berg 	case RATE_MCS_CHAN_WIDTH_20:
2226f1490546SJohannes Berg 		break;
2227f1490546SJohannes Berg 	case RATE_MCS_CHAN_WIDTH_40:
2228f1490546SJohannes Berg 		rx_status->bw = RATE_INFO_BW_40;
2229f1490546SJohannes Berg 		break;
2230f1490546SJohannes Berg 	case RATE_MCS_CHAN_WIDTH_80:
2231f1490546SJohannes Berg 		rx_status->bw = RATE_INFO_BW_80;
2232f1490546SJohannes Berg 		break;
2233f1490546SJohannes Berg 	case RATE_MCS_CHAN_WIDTH_160:
2234f1490546SJohannes Berg 		rx_status->bw = RATE_INFO_BW_160;
2235f1490546SJohannes Berg 		break;
223623dcee94SJohannes Berg 	case RATE_MCS_CHAN_WIDTH_320:
223723dcee94SJohannes Berg 		rx_status->bw = RATE_INFO_BW_320;
223823dcee94SJohannes Berg 		break;
2239f1490546SJohannes Berg 	}
2240f1490546SJohannes Berg 
2241f1490546SJohannes Berg 	/* must be before L-SIG data */
2242f1490546SJohannes Berg 	if (format == RATE_MCS_HE_MSK)
2243f1490546SJohannes Berg 		iwl_mvm_rx_he(mvm, skb, phy_data, queue);
2244f1490546SJohannes Berg 
2245f1490546SJohannes Berg 	iwl_mvm_decode_lsig(skb, phy_data);
2246f1490546SJohannes Berg 
2247f1490546SJohannes Berg 	rx_status->device_timestamp = phy_data->gp2_on_air_rise;
2248f1490546SJohannes Berg 	rx_status->freq = ieee80211_channel_to_frequency(phy_data->channel,
2249f1490546SJohannes Berg 							 rx_status->band);
2250f1490546SJohannes Berg 	iwl_mvm_get_signal_strength(mvm, rx_status, rate_n_flags,
2251f1490546SJohannes Berg 				    phy_data->energy_a, phy_data->energy_b);
2252f1490546SJohannes Berg 
225324f7f6e3SMordechay Goodstein 	/* using TLV format and must be after all fixed len fields */
225424f7f6e3SMordechay Goodstein 	if (format == RATE_MCS_EHT_MSK)
225524f7f6e3SMordechay Goodstein 		iwl_mvm_rx_eht(mvm, skb, phy_data, queue);
225624f7f6e3SMordechay Goodstein 
2257f1490546SJohannes Berg 	if (unlikely(mvm->monitor_on))
2258f1490546SJohannes Berg 		iwl_mvm_add_rtap_sniffer_config(mvm, skb);
2259f1490546SJohannes Berg 
2260f1490546SJohannes Berg 	is_sgi = format == RATE_MCS_HE_MSK ?
2261f1490546SJohannes Berg 		iwl_he_is_sgi(rate_n_flags) :
2262f1490546SJohannes Berg 		rate_n_flags & RATE_MCS_SGI_MSK;
2263f1490546SJohannes Berg 
2264f1490546SJohannes Berg 	if (!(format == RATE_MCS_CCK_MSK) && is_sgi)
2265f1490546SJohannes Berg 		rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
2266f1490546SJohannes Berg 
2267f1490546SJohannes Berg 	if (rate_n_flags & RATE_MCS_LDPC_MSK)
2268f1490546SJohannes Berg 		rx_status->enc_flags |= RX_ENC_FLAG_LDPC;
2269f1490546SJohannes Berg 
2270f1490546SJohannes Berg 	switch (format) {
22713d579204SJohannes Berg 	case RATE_MCS_VHT_MSK:
22723d579204SJohannes Berg 		rx_status->encoding = RX_ENC_VHT;
22733d579204SJohannes Berg 		break;
22743d579204SJohannes Berg 	case RATE_MCS_HE_MSK:
22753d579204SJohannes Berg 		rx_status->encoding = RX_ENC_HE;
22763d579204SJohannes Berg 		rx_status->he_dcm =
22773d579204SJohannes Berg 			!!(rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK);
22783d579204SJohannes Berg 		break;
227923dcee94SJohannes Berg 	case RATE_MCS_EHT_MSK:
228023dcee94SJohannes Berg 		rx_status->encoding = RX_ENC_EHT;
228123dcee94SJohannes Berg 		break;
22823d579204SJohannes Berg 	}
22833d579204SJohannes Berg 
22843d579204SJohannes Berg 	switch (format) {
2285f1490546SJohannes Berg 	case RATE_MCS_HT_MSK:
2286f1490546SJohannes Berg 		rx_status->encoding = RX_ENC_HT;
2287f1490546SJohannes Berg 		rx_status->rate_idx = RATE_HT_MCS_INDEX(rate_n_flags);
2288f1490546SJohannes Berg 		rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
2289f1490546SJohannes Berg 		break;
2290f1490546SJohannes Berg 	case RATE_MCS_VHT_MSK:
2291f1490546SJohannes Berg 	case RATE_MCS_HE_MSK:
229223dcee94SJohannes Berg 	case RATE_MCS_EHT_MSK:
22933d579204SJohannes Berg 		rx_status->nss =
22943d579204SJohannes Berg 			u32_get_bits(rate_n_flags, RATE_MCS_NSS_MSK) + 1;
22953d579204SJohannes Berg 		rx_status->rate_idx = rate_n_flags & RATE_MCS_CODE_MSK;
22963d579204SJohannes Berg 		rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
2297f1490546SJohannes Berg 		break;
2298f1490546SJohannes Berg 	default: {
2299f1490546SJohannes Berg 		int rate = iwl_mvm_legacy_hw_idx_to_mac80211_idx(rate_n_flags,
2300f1490546SJohannes Berg 								 rx_status->band);
2301f1490546SJohannes Berg 
2302f1490546SJohannes Berg 		rx_status->rate_idx = rate;
2303f1490546SJohannes Berg 
23049387e359SMukesh Sisodiya 		if ((rate < 0 || rate > 0xFF)) {
23059387e359SMukesh Sisodiya 			rx_status->rate_idx = 0;
23069387e359SMukesh Sisodiya 			if (net_ratelimit())
2307b79d2219SLuca Coelho 				IWL_ERR(mvm, "Invalid rate flags 0x%x, band %d,\n",
2308b79d2219SLuca Coelho 					rate_n_flags, rx_status->band);
2309b79d2219SLuca Coelho 		}
2310b79d2219SLuca Coelho 
2311f1490546SJohannes Berg 		break;
2312f1490546SJohannes Berg 		}
2313f1490546SJohannes Berg 	}
2314f1490546SJohannes Berg }
2315f1490546SJohannes Berg 
iwl_mvm_rx_mpdu_mq(struct iwl_mvm * mvm,struct napi_struct * napi,struct iwl_rx_cmd_buffer * rxb,int queue)2316780e87c2SJohannes Berg void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi,
2317780e87c2SJohannes Berg 			struct iwl_rx_cmd_buffer *rxb, int queue)
2318780e87c2SJohannes Berg {
2319780e87c2SJohannes Berg 	struct ieee80211_rx_status *rx_status;
2320780e87c2SJohannes Berg 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
2321780e87c2SJohannes Berg 	struct iwl_rx_mpdu_desc *desc = (void *)pkt->data;
232218ead597SGolan Ben Ami 	struct ieee80211_hdr *hdr;
2323b8aba27cSJohannes Berg 	u32 len;
2324efc0ec5aSJohannes Berg 	u32 pkt_len = iwl_rx_packet_payload_len(pkt);
2325780e87c2SJohannes Berg 	struct ieee80211_sta *sta = NULL;
2326b8a85a1dSJohannes Berg 	struct ieee80211_link_sta *link_sta = NULL;
2327780e87c2SJohannes Berg 	struct sk_buff *skb;
2328f1490546SJohannes Berg 	u8 crypt_len = 0;
232918ead597SGolan Ben Ami 	size_t desc_size;
2330f1490546SJohannes Berg 	struct iwl_mvm_rx_phy_data phy_data = {};
2331ce712478SLuca Coelho 	u32 format;
2332780e87c2SJohannes Berg 
2333364a1ab9SShahar S Matityahu 	if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
2334364a1ab9SShahar S Matityahu 		return;
2335364a1ab9SShahar S Matityahu 
2336b8aba27cSJohannes Berg 	if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210)
2337b8aba27cSJohannes Berg 		desc_size = sizeof(*desc);
2338b8aba27cSJohannes Berg 	else
2339b8aba27cSJohannes Berg 		desc_size = IWL_RX_DESC_SIZE_V1;
2340b8aba27cSJohannes Berg 
2341b8aba27cSJohannes Berg 	if (unlikely(pkt_len < desc_size)) {
2342b8aba27cSJohannes Berg 		IWL_DEBUG_DROP(mvm, "Bad REPLY_RX_MPDU_CMD size\n");
2343b8aba27cSJohannes Berg 		return;
2344b8aba27cSJohannes Berg 	}
2345b8aba27cSJohannes Berg 
23463681021fSJohannes Berg 	if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210) {
2347f1490546SJohannes Berg 		phy_data.rate_n_flags = le32_to_cpu(desc->v3.rate_n_flags);
2348f1490546SJohannes Berg 		phy_data.channel = desc->v3.channel;
2349f1490546SJohannes Berg 		phy_data.gp2_on_air_rise = le32_to_cpu(desc->v3.gp2_on_air_rise);
2350f1490546SJohannes Berg 		phy_data.energy_a = desc->v3.energy_a;
2351f1490546SJohannes Berg 		phy_data.energy_b = desc->v3.energy_b;
23526721039dSShaul Triebitz 
23536721039dSShaul Triebitz 		phy_data.d0 = desc->v3.phy_data0;
23546721039dSShaul Triebitz 		phy_data.d1 = desc->v3.phy_data1;
23556721039dSShaul Triebitz 		phy_data.d2 = desc->v3.phy_data2;
23566721039dSShaul Triebitz 		phy_data.d3 = desc->v3.phy_data3;
2357feb4a0e2SMordechay Goodstein 		phy_data.eht_d4 = desc->phy_eht_data4;
2358feb4a0e2SMordechay Goodstein 		phy_data.d5 = desc->v3.phy_data5;
235918ead597SGolan Ben Ami 	} else {
2360f1490546SJohannes Berg 		phy_data.rate_n_flags = le32_to_cpu(desc->v1.rate_n_flags);
2361f1490546SJohannes Berg 		phy_data.channel = desc->v1.channel;
2362f1490546SJohannes Berg 		phy_data.gp2_on_air_rise = le32_to_cpu(desc->v1.gp2_on_air_rise);
2363f1490546SJohannes Berg 		phy_data.energy_a = desc->v1.energy_a;
2364f1490546SJohannes Berg 		phy_data.energy_b = desc->v1.energy_b;
23656721039dSShaul Triebitz 
23666721039dSShaul Triebitz 		phy_data.d0 = desc->v1.phy_data0;
23676721039dSShaul Triebitz 		phy_data.d1 = desc->v1.phy_data1;
23686721039dSShaul Triebitz 		phy_data.d2 = desc->v1.phy_data2;
23696721039dSShaul Triebitz 		phy_data.d3 = desc->v1.phy_data3;
237018ead597SGolan Ben Ami 	}
2371f1490546SJohannes Berg 
2372ce712478SLuca Coelho 	if (iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,
2373ce712478SLuca Coelho 				    REPLY_RX_MPDU_CMD, 0) < 4) {
2374f1490546SJohannes Berg 		phy_data.rate_n_flags = iwl_new_rate_from_v1(phy_data.rate_n_flags);
2375ce712478SLuca Coelho 		IWL_DEBUG_DROP(mvm, "Got old format rate, converting. New rate: 0x%x\n",
2376f1490546SJohannes Berg 			       phy_data.rate_n_flags);
2377ce712478SLuca Coelho 	}
2378f1490546SJohannes Berg 
2379f1490546SJohannes Berg 	format = phy_data.rate_n_flags & RATE_MCS_MOD_TYPE_MSK;
238018ead597SGolan Ben Ami 
2381b8aba27cSJohannes Berg 	len = le16_to_cpu(desc->mpdu_len);
2382b8aba27cSJohannes Berg 
2383b8aba27cSJohannes Berg 	if (unlikely(len + desc_size > pkt_len)) {
2384b8aba27cSJohannes Berg 		IWL_DEBUG_DROP(mvm, "FW lied about packet len\n");
2385b8aba27cSJohannes Berg 		return;
2386b8aba27cSJohannes Berg 	}
2387b8aba27cSJohannes Berg 
2388feb4a0e2SMordechay Goodstein 	phy_data.with_data = true;
2389f1490546SJohannes Berg 	phy_data.phy_info = le16_to_cpu(desc->phy_info);
2390b8aba27cSJohannes Berg 	phy_data.d4 = desc->phy_data4;
2391b8aba27cSJohannes Berg 
239218ead597SGolan Ben Ami 	hdr = (void *)(pkt->data + desc_size);
2393780e87c2SJohannes Berg 	/* Dont use dev_alloc_skb(), we'll have enough headroom once
2394780e87c2SJohannes Berg 	 * ieee80211_hdr pulled.
2395780e87c2SJohannes Berg 	 */
2396780e87c2SJohannes Berg 	skb = alloc_skb(128, GFP_ATOMIC);
2397780e87c2SJohannes Berg 	if (!skb) {
2398780e87c2SJohannes Berg 		IWL_ERR(mvm, "alloc_skb failed\n");
2399780e87c2SJohannes Berg 		return;
2400780e87c2SJohannes Berg 	}
2401780e87c2SJohannes Berg 
24021e5b7750SJohannes Berg 	if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) {
24031e5b7750SJohannes Berg 		/*
24041e5b7750SJohannes Berg 		 * If the device inserted padding it means that (it thought)
24051e5b7750SJohannes Berg 		 * the 802.11 header wasn't a multiple of 4 bytes long. In
24061e5b7750SJohannes Berg 		 * this case, reserve two bytes at the start of the SKB to
24071e5b7750SJohannes Berg 		 * align the payload properly in case we end up copying it.
24081e5b7750SJohannes Berg 		 */
24091e5b7750SJohannes Berg 		skb_reserve(skb, 2);
24101e5b7750SJohannes Berg 	}
24111e5b7750SJohannes Berg 
2412780e87c2SJohannes Berg 	rx_status = IEEE80211_SKB_RXCB(skb);
2413780e87c2SJohannes Berg 
2414780e87c2SJohannes Berg 	/*
2415780e87c2SJohannes Berg 	 * Keep packets with CRC errors (and with overrun) for monitor mode
2416780e87c2SJohannes Berg 	 * (otherwise the firmware discards them) but mark them as bad.
2417780e87c2SJohannes Berg 	 */
2418e365e7deSJohannes Berg 	if (!(desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_CRC_OK)) ||
2419e365e7deSJohannes Berg 	    !(desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_OVERRUN_OK))) {
2420780e87c2SJohannes Berg 		IWL_DEBUG_RX(mvm, "Bad CRC or FIFO: 0x%08X.\n",
2421e365e7deSJohannes Berg 			     le32_to_cpu(desc->status));
2422780e87c2SJohannes Berg 		rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
2423780e87c2SJohannes Berg 	}
2424f1490546SJohannes Berg 
2425fbe41127SSara Sharon 	/* set the preamble flag if appropriate */
2426ce712478SLuca Coelho 	if (format == RATE_MCS_CCK_MSK &&
2427f1490546SJohannes Berg 	    phy_data.phy_info & IWL_RX_MPDU_PHY_SHORT_PREAMBLE)
24287fdd69c5SJohannes Berg 		rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE;
2429780e87c2SJohannes Berg 
2430f1490546SJohannes Berg 	if (likely(!(phy_data.phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD))) {
243118ead597SGolan Ben Ami 		u64 tsf_on_air_rise;
243218ead597SGolan Ben Ami 
2433286ca8ebSLuca Coelho 		if (mvm->trans->trans_cfg->device_family >=
24343681021fSJohannes Berg 		    IWL_DEVICE_FAMILY_AX210)
243518ead597SGolan Ben Ami 			tsf_on_air_rise = le64_to_cpu(desc->v3.tsf_on_air_rise);
243618ead597SGolan Ben Ami 		else
243718ead597SGolan Ben Ami 			tsf_on_air_rise = le64_to_cpu(desc->v1.tsf_on_air_rise);
243818ead597SGolan Ben Ami 
243918ead597SGolan Ben Ami 		rx_status->mactime = tsf_on_air_rise;
2440fbe41127SSara Sharon 		/* TSF as indicated by the firmware is at INA time */
2441fbe41127SSara Sharon 		rx_status->flag |= RX_FLAG_MACTIME_PLCP_START;
2442bd6fc655SLiad Kaufman 	}
2443bd6fc655SLiad Kaufman 
244465b9425cSTova Mussai 	if (iwl_mvm_is_band_in_rx_supported(mvm)) {
244565b9425cSTova Mussai 		u8 band = BAND_IN_RX_STATUS(desc->mac_phy_idx);
244665b9425cSTova Mussai 
244765b9425cSTova Mussai 		rx_status->band = iwl_mvm_nl80211_band_from_rx_msdu(band);
244865b9425cSTova Mussai 	} else {
2449f1490546SJohannes Berg 		rx_status->band = phy_data.channel > 14 ? NL80211_BAND_5GHZ :
245057fbcce3SJohannes Berg 			NL80211_BAND_2GHZ;
245165b9425cSTova Mussai 	}
2452fbe41127SSara Sharon 
2453fbe41127SSara Sharon 	/* update aggregation data for monitor sake on default queue */
2454f1490546SJohannes Berg 	if (!queue && (phy_data.phy_info & IWL_RX_MPDU_PHY_AMPDU)) {
2455f1490546SJohannes Berg 		bool toggle_bit;
2456fbe41127SSara Sharon 
2457f1490546SJohannes Berg 		toggle_bit = phy_data.phy_info & IWL_RX_MPDU_PHY_AMPDU_TOGGLE;
2458fbe41127SSara Sharon 		rx_status->flag |= RX_FLAG_AMPDU_DETAILS;
24595213e8a8SJohannes Berg 		/*
24605213e8a8SJohannes Berg 		 * Toggle is switched whenever new aggregation starts. Make
24615213e8a8SJohannes Berg 		 * sure ampdu_reference is never 0 so we can later use it to
24625213e8a8SJohannes Berg 		 * see if the frame was really part of an A-MPDU or not.
24635213e8a8SJohannes Berg 		 */
2464fbe41127SSara Sharon 		if (toggle_bit != mvm->ampdu_toggle) {
2465fbe41127SSara Sharon 			mvm->ampdu_ref++;
24665213e8a8SJohannes Berg 			if (mvm->ampdu_ref == 0)
24675213e8a8SJohannes Berg 				mvm->ampdu_ref++;
2468fbe41127SSara Sharon 			mvm->ampdu_toggle = toggle_bit;
2469da118544SJohannes Berg 			phy_data.first_subframe = true;
2470fbe41127SSara Sharon 		}
24711f7698abSJohannes Berg 		rx_status->ampdu_reference = mvm->ampdu_ref;
2472fbe41127SSara Sharon 	}
2473780e87c2SJohannes Berg 
2474780e87c2SJohannes Berg 	rcu_read_lock();
2475780e87c2SJohannes Berg 
2476e365e7deSJohannes Berg 	if (desc->status & cpu_to_le32(IWL_RX_MPDU_STATUS_SRC_STA_FOUND)) {
2477e365e7deSJohannes Berg 		u8 id = le32_get_bits(desc->status, IWL_RX_MPDU_STATUS_STA_ID);
2478780e87c2SJohannes Berg 
2479be9ae34eSNathan Errera 		if (!WARN_ON_ONCE(id >= mvm->fw->ucode_capa.num_stations)) {
2480780e87c2SJohannes Berg 			sta = rcu_dereference(mvm->fw_id_to_mac_id[id]);
2481780e87c2SJohannes Berg 			if (IS_ERR(sta))
2482780e87c2SJohannes Berg 				sta = NULL;
2483b8a85a1dSJohannes Berg 			link_sta = rcu_dereference(mvm->fw_id_to_link_sta[id]);
2484dc1ec9c5SBenjamin Berg 
2485dc1ec9c5SBenjamin Berg 			if (sta && sta->valid_links && link_sta) {
2486dc1ec9c5SBenjamin Berg 				rx_status->link_valid = 1;
2487dc1ec9c5SBenjamin Berg 				rx_status->link_id = link_sta->link_id;
2488dc1ec9c5SBenjamin Berg 			}
2489780e87c2SJohannes Berg 		}
2490780e87c2SJohannes Berg 	} else if (!is_multicast_ether_addr(hdr->addr2)) {
2491780e87c2SJohannes Berg 		/*
2492780e87c2SJohannes Berg 		 * This is fine since we prevent two stations with the same
2493780e87c2SJohannes Berg 		 * address from being added.
2494780e87c2SJohannes Berg 		 */
2495780e87c2SJohannes Berg 		sta = ieee80211_find_sta_by_ifaddr(mvm->hw, hdr->addr2, NULL);
2496780e87c2SJohannes Berg 	}
2497780e87c2SJohannes Berg 
2498f1490546SJohannes Berg 	if (iwl_mvm_rx_crypto(mvm, sta, hdr, rx_status, phy_data.phy_info, desc,
2499b1fdc250SJohannes Berg 			      le32_to_cpu(pkt->len_n_flags), queue,
2500b1fdc250SJohannes Berg 			      &crypt_len)) {
2501b1fdc250SJohannes Berg 		kfree_skb(skb);
2502b1fdc250SJohannes Berg 		goto out;
2503b1fdc250SJohannes Berg 	}
2504b1fdc250SJohannes Berg 
2505f1490546SJohannes Berg 	iwl_mvm_rx_fill_status(mvm, skb, &phy_data, queue);
2506f1490546SJohannes Berg 
2507780e87c2SJohannes Berg 	if (sta) {
2508780e87c2SJohannes Berg 		struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2509d3a108a4SAndrei Otcheretianski 		struct ieee80211_vif *tx_blocked_vif =
2510d3a108a4SAndrei Otcheretianski 			rcu_dereference(mvm->csa_tx_blocked_vif);
251110b2b201SSara Sharon 		u8 baid = (u8)((le32_to_cpu(desc->reorder_data) &
251210b2b201SSara Sharon 			       IWL_RX_MPDU_REORDER_BAID_MASK) >>
251310b2b201SSara Sharon 			       IWL_RX_MPDU_REORDER_BAID_SHIFT);
25146c042d75SSara Sharon 		struct iwl_fw_dbg_trigger_tlv *trig;
25156c042d75SSara Sharon 		struct ieee80211_vif *vif = mvmsta->vif;
2516780e87c2SJohannes Berg 
25177d9d0d56SLuca Coelho 		if (!mvm->tcm.paused && len >= sizeof(*hdr) &&
25187d9d0d56SLuca Coelho 		    !is_multicast_ether_addr(hdr->addr1) &&
25197d9d0d56SLuca Coelho 		    ieee80211_is_data(hdr->frame_control) &&
25207d9d0d56SLuca Coelho 		    time_after(jiffies, mvm->tcm.ts + MVM_TCM_PERIOD))
25217d9d0d56SLuca Coelho 			schedule_delayed_work(&mvm->tcm.work, 0);
25227d9d0d56SLuca Coelho 
2523780e87c2SJohannes Berg 		/*
2524780e87c2SJohannes Berg 		 * We have tx blocked stations (with CS bit). If we heard
2525780e87c2SJohannes Berg 		 * frames from a blocked station on a new channel we can
2526780e87c2SJohannes Berg 		 * TX to it again.
2527780e87c2SJohannes Berg 		 */
25286c042d75SSara Sharon 		if (unlikely(tx_blocked_vif) && tx_blocked_vif == vif) {
2529d3a108a4SAndrei Otcheretianski 			struct iwl_mvm_vif *mvmvif =
2530d3a108a4SAndrei Otcheretianski 				iwl_mvm_vif_from_mac80211(tx_blocked_vif);
2531e5d153ecSEmmanuel Grumbach 			struct iwl_rx_sta_csa rx_sta_csa = {
2532e5d153ecSEmmanuel Grumbach 				.all_sta_unblocked = true,
2533e5d153ecSEmmanuel Grumbach 				.vif = tx_blocked_vif,
2534e5d153ecSEmmanuel Grumbach 			};
2535d3a108a4SAndrei Otcheretianski 
2536d3a108a4SAndrei Otcheretianski 			if (mvmvif->csa_target_freq == rx_status->freq)
2537d3a108a4SAndrei Otcheretianski 				iwl_mvm_sta_modify_disable_tx_ap(mvm, sta,
2538d3a108a4SAndrei Otcheretianski 								 false);
2539e5d153ecSEmmanuel Grumbach 			ieee80211_iterate_stations_atomic(mvm->hw,
2540e5d153ecSEmmanuel Grumbach 							  iwl_mvm_rx_get_sta_block_tx,
2541e5d153ecSEmmanuel Grumbach 							  &rx_sta_csa);
2542e5d153ecSEmmanuel Grumbach 
2543e5d153ecSEmmanuel Grumbach 			if (rx_sta_csa.all_sta_unblocked) {
2544e5d153ecSEmmanuel Grumbach 				RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
2545e5d153ecSEmmanuel Grumbach 				/* Unblock BCAST / MCAST station */
2546e5d153ecSEmmanuel Grumbach 				iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false);
2547c2d8b7f2SJohannes Berg 				cancel_delayed_work(&mvm->cs_tx_unblock_dwork);
2548e5d153ecSEmmanuel Grumbach 			}
2549d3a108a4SAndrei Otcheretianski 		}
2550780e87c2SJohannes Berg 
2551ecaf71deSGregory Greenman 		rs_update_last_rssi(mvm, mvmsta, rx_status);
2552780e87c2SJohannes Berg 
25536c042d75SSara Sharon 		trig = iwl_fw_dbg_trigger_on(&mvm->fwrt,
25546c042d75SSara Sharon 					     ieee80211_vif_to_wdev(vif),
25556c042d75SSara Sharon 					     FW_DBG_TRIGGER_RSSI);
25566c042d75SSara Sharon 
25576c042d75SSara Sharon 		if (trig && ieee80211_is_beacon(hdr->frame_control)) {
2558780e87c2SJohannes Berg 			struct iwl_fw_dbg_trigger_low_rssi *rssi_trig;
2559780e87c2SJohannes Berg 			s32 rssi;
2560780e87c2SJohannes Berg 
2561780e87c2SJohannes Berg 			rssi_trig = (void *)trig->data;
2562780e87c2SJohannes Berg 			rssi = le32_to_cpu(rssi_trig->rssi);
2563780e87c2SJohannes Berg 
25646c042d75SSara Sharon 			if (rx_status->signal < rssi)
25657174beb6SJohannes Berg 				iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
25667174beb6SJohannes Berg 							NULL);
2567780e87c2SJohannes Berg 		}
2568780e87c2SJohannes Berg 
2569780e87c2SJohannes Berg 		if (ieee80211_is_data(hdr->frame_control))
257059ca9572SJohannes Berg 			iwl_mvm_rx_csum(mvm, sta, skb, pkt);
2571a571f5f6SSara Sharon 
25725ab2ba93SSara Sharon 		if (iwl_mvm_is_dup(sta, queue, rx_status, hdr, desc)) {
2573a571f5f6SSara Sharon 			kfree_skb(skb);
2574cb2de6bbSSara Sharon 			goto out;
2575a571f5f6SSara Sharon 		}
257662d23403SSara Sharon 
257762d23403SSara Sharon 		/*
257862d23403SSara Sharon 		 * Our hardware de-aggregates AMSDUs but copies the mac header
257962d23403SSara Sharon 		 * as it to the de-aggregated MPDUs. We need to turn off the
258062d23403SSara Sharon 		 * AMSDU bit in the QoS control ourselves.
25819dfa2151SSara Sharon 		 * In addition, HW reverses addr3 and addr4 - reverse it back.
258262d23403SSara Sharon 		 */
258362d23403SSara Sharon 		if ((desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU) &&
258462d23403SSara Sharon 		    !WARN_ON(!ieee80211_is_data_qos(hdr->frame_control))) {
258562d23403SSara Sharon 			u8 *qc = ieee80211_get_qos_ctl(hdr);
258662d23403SSara Sharon 
258762d23403SSara Sharon 			*qc &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT;
2588a56cb4f0SSara Sharon 
2589286ca8ebSLuca Coelho 			if (mvm->trans->trans_cfg->device_family ==
2590e4d72208SSara Sharon 			    IWL_DEVICE_FAMILY_9000) {
2591e4d72208SSara Sharon 				iwl_mvm_flip_address(hdr->addr3);
25929dfa2151SSara Sharon 
2593e4d72208SSara Sharon 				if (ieee80211_has_a4(hdr->frame_control))
2594e4d72208SSara Sharon 					iwl_mvm_flip_address(hdr->addr4);
25959dfa2151SSara Sharon 			}
259662d23403SSara Sharon 		}
25975d43eab6SSara Sharon 		if (baid != IWL_RX_REORDER_DATA_INVALID_BAID) {
25985d43eab6SSara Sharon 			u32 reorder_data = le32_to_cpu(desc->reorder_data);
25995d43eab6SSara Sharon 
26005d43eab6SSara Sharon 			iwl_mvm_agg_rx_received(mvm, reorder_data, baid);
26015d43eab6SSara Sharon 		}
2602780e87c2SJohannes Berg 	}
2603780e87c2SJohannes Berg 
2604fbe41127SSara Sharon 	/* management stuff on default queue */
2605fbe41127SSara Sharon 	if (!queue) {
2606fbe41127SSara Sharon 		if (unlikely((ieee80211_is_beacon(hdr->frame_control) ||
2607fbe41127SSara Sharon 			      ieee80211_is_probe_resp(hdr->frame_control)) &&
2608fbe41127SSara Sharon 			     mvm->sched_scan_pass_all ==
2609fbe41127SSara Sharon 			     SCHED_SCAN_PASS_ALL_ENABLED))
2610fbe41127SSara Sharon 			mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_FOUND;
2611fbe41127SSara Sharon 
2612fbe41127SSara Sharon 		if (unlikely(ieee80211_is_beacon(hdr->frame_control) ||
2613fbe41127SSara Sharon 			     ieee80211_is_probe_resp(hdr->frame_control)))
26149285ec4cSJason A. Donenfeld 			rx_status->boottime_ns = ktime_get_boottime_ns();
2615fbe41127SSara Sharon 	}
2616780e87c2SJohannes Berg 
2617de1887c0SLuca Coelho 	if (iwl_mvm_create_skb(mvm, skb, hdr, len, crypt_len, rxb)) {
2618de1887c0SLuca Coelho 		kfree_skb(skb);
2619de1887c0SLuca Coelho 		goto out;
2620de1887c0SLuca Coelho 	}
2621de1887c0SLuca Coelho 
2622c7eca79dSAvraham Stern 	if (!iwl_mvm_reorder(mvm, napi, queue, sta, skb, desc) &&
26230d255883SAvraham Stern 	    likely(!iwl_mvm_time_sync_frame(mvm, skb, hdr->addr2)) &&
262413fd96c9SEmmanuel Grumbach 	    likely(!iwl_mvm_mei_filter_scan(mvm, skb))) {
262513fd96c9SEmmanuel Grumbach 		if (mvm->trans->trans_cfg->device_family == IWL_DEVICE_FAMILY_9000 &&
262613fd96c9SEmmanuel Grumbach 		    (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU) &&
262713fd96c9SEmmanuel Grumbach 		    !(desc->amsdu_info & IWL_RX_MPDU_AMSDU_LAST_SUBFRAME))
262813fd96c9SEmmanuel Grumbach 			rx_status->flag |= RX_FLAG_AMSDU_MORE;
262913fd96c9SEmmanuel Grumbach 
2630dc1ec9c5SBenjamin Berg 		iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb, queue, sta);
263113fd96c9SEmmanuel Grumbach 	}
2632cb2de6bbSSara Sharon out:
2633f5e28eacSJohannes Berg 	rcu_read_unlock();
2634780e87c2SJohannes Berg }
2635585a6fccSSara Sharon 
iwl_mvm_rx_monitor_no_data(struct iwl_mvm * mvm,struct napi_struct * napi,struct iwl_rx_cmd_buffer * rxb,int queue)2636d47cdb88SJohannes Berg void iwl_mvm_rx_monitor_no_data(struct iwl_mvm *mvm, struct napi_struct *napi,
2637bf9dfedaSShaul Triebitz 				struct iwl_rx_cmd_buffer *rxb, int queue)
2638bf9dfedaSShaul Triebitz {
2639bf9dfedaSShaul Triebitz 	struct ieee80211_rx_status *rx_status;
2640bf9dfedaSShaul Triebitz 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
26418dd51b5fSMordechay Goodstein 	struct iwl_rx_no_data_ver_3 *desc = (void *)pkt->data;
26421174e8fcSMordechay Goodstein 	u32 rssi;
26431174e8fcSMordechay Goodstein 	u32 info_type;
2644bf9dfedaSShaul Triebitz 	struct ieee80211_sta *sta = NULL;
2645bf9dfedaSShaul Triebitz 	struct sk_buff *skb;
26461174e8fcSMordechay Goodstein 	struct iwl_mvm_rx_phy_data phy_data;
2647f1490546SJohannes Berg 	u32 format;
2648ce712478SLuca Coelho 
26491174e8fcSMordechay Goodstein 	if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
26501174e8fcSMordechay Goodstein 		return;
26511174e8fcSMordechay Goodstein 
26521174e8fcSMordechay Goodstein 	if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(struct iwl_rx_no_data)))
26531174e8fcSMordechay Goodstein 		return;
26541174e8fcSMordechay Goodstein 
26551174e8fcSMordechay Goodstein 	rssi = le32_to_cpu(desc->rssi);
26561174e8fcSMordechay Goodstein 	info_type = le32_to_cpu(desc->info) & RX_NO_DATA_INFO_TYPE_MSK;
26571174e8fcSMordechay Goodstein 	phy_data.d0 = desc->phy_info[0];
26581174e8fcSMordechay Goodstein 	phy_data.d1 = desc->phy_info[1];
26591174e8fcSMordechay Goodstein 	phy_data.phy_info = IWL_RX_MPDU_PHY_TSF_OVERLOAD;
26601174e8fcSMordechay Goodstein 	phy_data.gp2_on_air_rise = le32_to_cpu(desc->on_air_rise_time);
26611174e8fcSMordechay Goodstein 	phy_data.rate_n_flags = le32_to_cpu(desc->rate);
26621174e8fcSMordechay Goodstein 	phy_data.energy_a = u32_get_bits(rssi, RX_NO_DATA_CHAIN_A_MSK);
26631174e8fcSMordechay Goodstein 	phy_data.energy_b = u32_get_bits(rssi, RX_NO_DATA_CHAIN_B_MSK);
26641174e8fcSMordechay Goodstein 	phy_data.channel = u32_get_bits(rssi, RX_NO_DATA_CHANNEL_MSK);
2665feb4a0e2SMordechay Goodstein 	phy_data.with_data = false;
266697110233SMukesh Sisodiya 	phy_data.rx_vec[0] = desc->rx_vec[0];
266797110233SMukesh Sisodiya 	phy_data.rx_vec[1] = desc->rx_vec[1];
26681174e8fcSMordechay Goodstein 
2669ce712478SLuca Coelho 	if (iwl_fw_lookup_notif_ver(mvm->fw, DATA_PATH_GROUP,
2670ce712478SLuca Coelho 				    RX_NO_DATA_NOTIF, 0) < 2) {
2671ce712478SLuca Coelho 		IWL_DEBUG_DROP(mvm, "Got an old rate format. Old rate: 0x%x\n",
2672f1490546SJohannes Berg 			       phy_data.rate_n_flags);
2673f1490546SJohannes Berg 		phy_data.rate_n_flags = iwl_new_rate_from_v1(phy_data.rate_n_flags);
2674ce712478SLuca Coelho 		IWL_DEBUG_DROP(mvm, " Rate after conversion to the new format: 0x%x\n",
2675f1490546SJohannes Berg 			       phy_data.rate_n_flags);
2676ce712478SLuca Coelho 	}
2677f1490546SJohannes Berg 
2678f1490546SJohannes Berg 	format = phy_data.rate_n_flags & RATE_MCS_MOD_TYPE_MSK;
2679bf9dfedaSShaul Triebitz 
26808dd51b5fSMordechay Goodstein 	if (iwl_fw_lookup_notif_ver(mvm->fw, DATA_PATH_GROUP,
26818dd51b5fSMordechay Goodstein 				    RX_NO_DATA_NOTIF, 0) >= 3) {
26828dd51b5fSMordechay Goodstein 		if (unlikely(iwl_rx_packet_payload_len(pkt) <
26838dd51b5fSMordechay Goodstein 		    sizeof(struct iwl_rx_no_data_ver_3)))
26848dd51b5fSMordechay Goodstein 		/* invalid len for ver 3 */
26858dd51b5fSMordechay Goodstein 			return;
268697110233SMukesh Sisodiya 		phy_data.rx_vec[2] = desc->rx_vec[2];
268797110233SMukesh Sisodiya 		phy_data.rx_vec[3] = desc->rx_vec[3];
26888dd51b5fSMordechay Goodstein 	} else {
26898dd51b5fSMordechay Goodstein 		if (format == RATE_MCS_EHT_MSK)
26908dd51b5fSMordechay Goodstein 			/* no support for EHT before version 3 API */
26918dd51b5fSMordechay Goodstein 			return;
26928dd51b5fSMordechay Goodstein 	}
26938dd51b5fSMordechay Goodstein 
2694bf9dfedaSShaul Triebitz 	/* Dont use dev_alloc_skb(), we'll have enough headroom once
2695bf9dfedaSShaul Triebitz 	 * ieee80211_hdr pulled.
2696bf9dfedaSShaul Triebitz 	 */
2697bf9dfedaSShaul Triebitz 	skb = alloc_skb(128, GFP_ATOMIC);
2698bf9dfedaSShaul Triebitz 	if (!skb) {
2699bf9dfedaSShaul Triebitz 		IWL_ERR(mvm, "alloc_skb failed\n");
2700bf9dfedaSShaul Triebitz 		return;
2701bf9dfedaSShaul Triebitz 	}
2702bf9dfedaSShaul Triebitz 
2703bf9dfedaSShaul Triebitz 	rx_status = IEEE80211_SKB_RXCB(skb);
2704bf9dfedaSShaul Triebitz 
2705bf9dfedaSShaul Triebitz 	/* 0-length PSDU */
2706bf9dfedaSShaul Triebitz 	rx_status->flag |= RX_FLAG_NO_PSDU;
2707d47cdb88SJohannes Berg 
2708d47cdb88SJohannes Berg 	switch (info_type) {
2709d47cdb88SJohannes Berg 	case RX_NO_DATA_INFO_TYPE_NDP:
2710bf9dfedaSShaul Triebitz 		rx_status->zero_length_psdu_type =
2711bf9dfedaSShaul Triebitz 			IEEE80211_RADIOTAP_ZERO_LEN_PSDU_SOUNDING;
2712d47cdb88SJohannes Berg 		break;
2713d47cdb88SJohannes Berg 	case RX_NO_DATA_INFO_TYPE_MU_UNMATCHED:
2714c0da321bSMordechay Goodstein 	case RX_NO_DATA_INFO_TYPE_TB_UNMATCHED:
2715d47cdb88SJohannes Berg 		rx_status->zero_length_psdu_type =
2716d47cdb88SJohannes Berg 			IEEE80211_RADIOTAP_ZERO_LEN_PSDU_NOT_CAPTURED;
2717d47cdb88SJohannes Berg 		break;
2718d47cdb88SJohannes Berg 	default:
2719d47cdb88SJohannes Berg 		rx_status->zero_length_psdu_type =
2720d47cdb88SJohannes Berg 			IEEE80211_RADIOTAP_ZERO_LEN_PSDU_VENDOR;
2721d47cdb88SJohannes Berg 		break;
2722d47cdb88SJohannes Berg 	}
2723bf9dfedaSShaul Triebitz 
2724f1490546SJohannes Berg 	rx_status->band = phy_data.channel > 14 ? NL80211_BAND_5GHZ :
2725bf9dfedaSShaul Triebitz 		NL80211_BAND_2GHZ;
2726bf9dfedaSShaul Triebitz 
2727f1490546SJohannes Berg 	iwl_mvm_rx_fill_status(mvm, skb, &phy_data, queue);
2728bf9dfedaSShaul Triebitz 
27293f7a9d57SMordechay Goodstein 	/* no more radio tap info should be put after this point.
27303f7a9d57SMordechay Goodstein 	 *
27313f7a9d57SMordechay Goodstein 	 * We mark it as mac header, for upper layers to know where
27323f7a9d57SMordechay Goodstein 	 * all radio tap header ends.
2733*bdfa7cf3SMordechay Goodstein 	 *
2734*bdfa7cf3SMordechay Goodstein 	 * Since data doesn't move data while putting data on skb and that is
2735*bdfa7cf3SMordechay Goodstein 	 * the only way we use, data + len is the next place that hdr would be put
27363f7a9d57SMordechay Goodstein 	 */
2737*bdfa7cf3SMordechay Goodstein 	skb_set_mac_header(skb, skb->len);
27383f7a9d57SMordechay Goodstein 
2739c97781d1SShaul Triebitz 	/*
2740f1490546SJohannes Berg 	 * Override the nss from the rx_vec since the rate_n_flags has
2741f1490546SJohannes Berg 	 * only 2 bits for the nss which gives a max of 4 ss but there
2742f1490546SJohannes Berg 	 * may be up to 8 spatial streams.
2743c97781d1SShaul Triebitz 	 */
2744f1490546SJohannes Berg 	switch (format) {
2745f1490546SJohannes Berg 	case RATE_MCS_VHT_MSK:
2746c97781d1SShaul Triebitz 		rx_status->nss =
2747c97781d1SShaul Triebitz 			le32_get_bits(desc->rx_vec[0],
2748c97781d1SShaul Triebitz 				      RX_NO_DATA_RX_VEC0_VHT_NSTS_MSK) + 1;
2749f1490546SJohannes Berg 		break;
2750f1490546SJohannes Berg 	case RATE_MCS_HE_MSK:
2751c97781d1SShaul Triebitz 		rx_status->nss =
2752c97781d1SShaul Triebitz 			le32_get_bits(desc->rx_vec[0],
2753c97781d1SShaul Triebitz 				      RX_NO_DATA_RX_VEC0_HE_NSTS_MSK) + 1;
2754f1490546SJohannes Berg 		break;
27558dd51b5fSMordechay Goodstein 	case RATE_MCS_EHT_MSK:
27568dd51b5fSMordechay Goodstein 		rx_status->nss =
27578dd51b5fSMordechay Goodstein 			le32_get_bits(desc->rx_vec[2],
27588dd51b5fSMordechay Goodstein 				      RX_NO_DATA_RX_VEC2_EHT_NSTS_MSK) + 1;
2759bf9dfedaSShaul Triebitz 	}
2760bf9dfedaSShaul Triebitz 
2761f1490546SJohannes Berg 	rcu_read_lock();
2762ed714460SJohannes Berg 	ieee80211_rx_napi(mvm->hw, sta, skb, napi);
2763bf9dfedaSShaul Triebitz 	rcu_read_unlock();
2764bf9dfedaSShaul Triebitz }
2765c61b655aSEmmanuel Grumbach 
iwl_mvm_rx_frame_release(struct iwl_mvm * mvm,struct napi_struct * napi,struct iwl_rx_cmd_buffer * rxb,int queue)2766a338384bSSara Sharon void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
2767585a6fccSSara Sharon 			      struct iwl_rx_cmd_buffer *rxb, int queue)
2768585a6fccSSara Sharon {
2769a338384bSSara Sharon 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
2770a338384bSSara Sharon 	struct iwl_frame_release *release = (void *)pkt->data;
2771a338384bSSara Sharon 
27721e1a58beSJohannes Berg 	if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(*release)))
27731e1a58beSJohannes Berg 		return;
27741e1a58beSJohannes Berg 
2775c61b655aSEmmanuel Grumbach 	iwl_mvm_release_frames_from_notif(mvm, napi, release->baid,
2776ecd09ddcSEmmanuel Grumbach 					  le16_to_cpu(release->nssn),
2777ecd09ddcSEmmanuel Grumbach 					  queue, 0);
2778585a6fccSSara Sharon }
2779fe69b7d1SJohannes Berg 
iwl_mvm_rx_bar_frame_release(struct iwl_mvm * mvm,struct napi_struct * napi,struct iwl_rx_cmd_buffer * rxb,int queue)2780fe69b7d1SJohannes Berg void iwl_mvm_rx_bar_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
2781fe69b7d1SJohannes Berg 				  struct iwl_rx_cmd_buffer *rxb, int queue)
2782fe69b7d1SJohannes Berg {
2783fe69b7d1SJohannes Berg 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
2784fe69b7d1SJohannes Berg 	struct iwl_bar_frame_release *release = (void *)pkt->data;
2785fe69b7d1SJohannes Berg 	unsigned int baid = le32_get_bits(release->ba_info,
2786fe69b7d1SJohannes Berg 					  IWL_BAR_FRAME_RELEASE_BAID_MASK);
2787fe69b7d1SJohannes Berg 	unsigned int nssn = le32_get_bits(release->ba_info,
2788fe69b7d1SJohannes Berg 					  IWL_BAR_FRAME_RELEASE_NSSN_MASK);
2789fe69b7d1SJohannes Berg 	unsigned int sta_id = le32_get_bits(release->sta_tid,
2790fe69b7d1SJohannes Berg 					    IWL_BAR_FRAME_RELEASE_STA_MASK);
2791fe69b7d1SJohannes Berg 	unsigned int tid = le32_get_bits(release->sta_tid,
2792fe69b7d1SJohannes Berg 					 IWL_BAR_FRAME_RELEASE_TID_MASK);
2793fe69b7d1SJohannes Berg 	struct iwl_mvm_baid_data *baid_data;
2794fe69b7d1SJohannes Berg 
27951e1a58beSJohannes Berg 	if (unlikely(iwl_rx_packet_payload_len(pkt) < sizeof(*release)))
27961e1a58beSJohannes Berg 		return;
27971e1a58beSJohannes Berg 
2798fe69b7d1SJohannes Berg 	if (WARN_ON_ONCE(baid == IWL_RX_REORDER_DATA_INVALID_BAID ||
2799fe69b7d1SJohannes Berg 			 baid >= ARRAY_SIZE(mvm->baid_map)))
2800fe69b7d1SJohannes Berg 		return;
2801fe69b7d1SJohannes Berg 
2802fe69b7d1SJohannes Berg 	rcu_read_lock();
2803fe69b7d1SJohannes Berg 	baid_data = rcu_dereference(mvm->baid_map[baid]);
2804fe69b7d1SJohannes Berg 	if (!baid_data) {
2805fe69b7d1SJohannes Berg 		IWL_DEBUG_RX(mvm,
2806fe69b7d1SJohannes Berg 			     "Got valid BAID %d but not allocated, invalid BAR release!\n",
2807fe69b7d1SJohannes Berg 			      baid);
2808fe69b7d1SJohannes Berg 		goto out;
2809fe69b7d1SJohannes Berg 	}
2810fe69b7d1SJohannes Berg 
28119aa3856dSJohannes Berg 	if (WARN(tid != baid_data->tid || sta_id > IWL_MVM_STATION_COUNT_MAX ||
28129aa3856dSJohannes Berg 		 !(baid_data->sta_mask & BIT(sta_id)),
28139aa3856dSJohannes Berg 		 "baid 0x%x is mapped to sta_mask:0x%x tid:%d, but BAR release received for sta:%d tid:%d\n",
28149aa3856dSJohannes Berg 		 baid, baid_data->sta_mask, baid_data->tid, sta_id,
2815fe69b7d1SJohannes Berg 		 tid))
2816fe69b7d1SJohannes Berg 		goto out;
2817fe69b7d1SJohannes Berg 
2818fe69b7d1SJohannes Berg 	iwl_mvm_release_frames_from_notif(mvm, napi, baid, nssn, queue, 0);
2819fe69b7d1SJohannes Berg out:
2820fe69b7d1SJohannes Berg 	rcu_read_unlock();
2821fe69b7d1SJohannes Berg }
2822