1 /******************************************************************************
2  *
3  * This file is provided under a dual BSD/GPLv2 license.  When using or
4  * redistributing this file, you may do so under either license.
5  *
6  * GPL LICENSE SUMMARY
7  *
8  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10  * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
11  * Copyright(c) 2018 - 2019 Intel Corporation
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of version 2 of the GNU General Public License as
15  * published by the Free Software Foundation.
16  *
17  * This program is distributed in the hope that it will be useful, but
18  * WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * General Public License for more details.
21  *
22  * The full GNU General Public License is included in this distribution
23  * in the file called COPYING.
24  *
25  * Contact Information:
26  *  Intel Linux Wireless <ilw@linux.intel.com>
27  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28  *
29  * BSD LICENSE
30  *
31  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33  * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
34  * Copyright(c) 2018 - 2019 Intel Corporation
35  * All rights reserved.
36  *
37  * Redistribution and use in source and binary forms, with or without
38  * modification, are permitted provided that the following conditions
39  * are met:
40  *
41  *  * Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  *  * Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in
45  *    the documentation and/or other materials provided with the
46  *    distribution.
47  *  * Neither the name Intel Corporation nor the names of its
48  *    contributors may be used to endorse or promote products derived
49  *    from this software without specific prior written permission.
50  *
51  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62  *****************************************************************************/
63 #include <linux/etherdevice.h>
64 #include <linux/skbuff.h>
65 #include "iwl-trans.h"
66 #include "mvm.h"
67 #include "fw-api.h"
68 
69 static void *iwl_mvm_skb_get_hdr(struct sk_buff *skb)
70 {
71 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
72 	u8 *data = skb->data;
73 
74 	/* Alignment concerns */
75 	BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) % 4);
76 	BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) % 4);
77 	BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_lsig) % 4);
78 	BUILD_BUG_ON(sizeof(struct ieee80211_vendor_radiotap) % 4);
79 
80 	if (rx_status->flag & RX_FLAG_RADIOTAP_HE)
81 		data += sizeof(struct ieee80211_radiotap_he);
82 	if (rx_status->flag & RX_FLAG_RADIOTAP_HE_MU)
83 		data += sizeof(struct ieee80211_radiotap_he_mu);
84 	if (rx_status->flag & RX_FLAG_RADIOTAP_LSIG)
85 		data += sizeof(struct ieee80211_radiotap_lsig);
86 	if (rx_status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
87 		struct ieee80211_vendor_radiotap *radiotap = (void *)data;
88 
89 		data += sizeof(*radiotap) + radiotap->len + radiotap->pad;
90 	}
91 
92 	return data;
93 }
94 
95 static inline int iwl_mvm_check_pn(struct iwl_mvm *mvm, struct sk_buff *skb,
96 				   int queue, struct ieee80211_sta *sta)
97 {
98 	struct iwl_mvm_sta *mvmsta;
99 	struct ieee80211_hdr *hdr = iwl_mvm_skb_get_hdr(skb);
100 	struct ieee80211_rx_status *stats = IEEE80211_SKB_RXCB(skb);
101 	struct iwl_mvm_key_pn *ptk_pn;
102 	int res;
103 	u8 tid, keyidx;
104 	u8 pn[IEEE80211_CCMP_PN_LEN];
105 	u8 *extiv;
106 
107 	/* do PN checking */
108 
109 	/* multicast and non-data only arrives on default queue */
110 	if (!ieee80211_is_data(hdr->frame_control) ||
111 	    is_multicast_ether_addr(hdr->addr1))
112 		return 0;
113 
114 	/* do not check PN for open AP */
115 	if (!(stats->flag & RX_FLAG_DECRYPTED))
116 		return 0;
117 
118 	/*
119 	 * avoid checking for default queue - we don't want to replicate
120 	 * all the logic that's necessary for checking the PN on fragmented
121 	 * frames, leave that to mac80211
122 	 */
123 	if (queue == 0)
124 		return 0;
125 
126 	/* if we are here - this for sure is either CCMP or GCMP */
127 	if (IS_ERR_OR_NULL(sta)) {
128 		IWL_ERR(mvm,
129 			"expected hw-decrypted unicast frame for station\n");
130 		return -1;
131 	}
132 
133 	mvmsta = iwl_mvm_sta_from_mac80211(sta);
134 
135 	extiv = (u8 *)hdr + ieee80211_hdrlen(hdr->frame_control);
136 	keyidx = extiv[3] >> 6;
137 
138 	ptk_pn = rcu_dereference(mvmsta->ptk_pn[keyidx]);
139 	if (!ptk_pn)
140 		return -1;
141 
142 	if (ieee80211_is_data_qos(hdr->frame_control))
143 		tid = ieee80211_get_tid(hdr);
144 	else
145 		tid = 0;
146 
147 	/* we don't use HCCA/802.11 QoS TSPECs, so drop such frames */
148 	if (tid >= IWL_MAX_TID_COUNT)
149 		return -1;
150 
151 	/* load pn */
152 	pn[0] = extiv[7];
153 	pn[1] = extiv[6];
154 	pn[2] = extiv[5];
155 	pn[3] = extiv[4];
156 	pn[4] = extiv[1];
157 	pn[5] = extiv[0];
158 
159 	res = memcmp(pn, ptk_pn->q[queue].pn[tid], IEEE80211_CCMP_PN_LEN);
160 	if (res < 0)
161 		return -1;
162 	if (!res && !(stats->flag & RX_FLAG_ALLOW_SAME_PN))
163 		return -1;
164 
165 	memcpy(ptk_pn->q[queue].pn[tid], pn, IEEE80211_CCMP_PN_LEN);
166 	stats->flag |= RX_FLAG_PN_VALIDATED;
167 
168 	return 0;
169 }
170 
171 /* iwl_mvm_create_skb Adds the rxb to a new skb */
172 static int iwl_mvm_create_skb(struct iwl_mvm *mvm, struct sk_buff *skb,
173 			      struct ieee80211_hdr *hdr, u16 len, u8 crypt_len,
174 			      struct iwl_rx_cmd_buffer *rxb)
175 {
176 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
177 	struct iwl_rx_mpdu_desc *desc = (void *)pkt->data;
178 	unsigned int headlen, fraglen, pad_len = 0;
179 	unsigned int hdrlen = ieee80211_hdrlen(hdr->frame_control);
180 
181 	if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) {
182 		len -= 2;
183 		pad_len = 2;
184 	}
185 
186 	/* If frame is small enough to fit in skb->head, pull it completely.
187 	 * If not, only pull ieee80211_hdr (including crypto if present, and
188 	 * an additional 8 bytes for SNAP/ethertype, see below) so that
189 	 * splice() or TCP coalesce are more efficient.
190 	 *
191 	 * Since, in addition, ieee80211_data_to_8023() always pull in at
192 	 * least 8 bytes (possibly more for mesh) we can do the same here
193 	 * to save the cost of doing it later. That still doesn't pull in
194 	 * the actual IP header since the typical case has a SNAP header.
195 	 * If the latter changes (there are efforts in the standards group
196 	 * to do so) we should revisit this and ieee80211_data_to_8023().
197 	 */
198 	headlen = (len <= skb_tailroom(skb)) ? len :
199 					       hdrlen + crypt_len + 8;
200 
201 	/* The firmware may align the packet to DWORD.
202 	 * The padding is inserted after the IV.
203 	 * After copying the header + IV skip the padding if
204 	 * present before copying packet data.
205 	 */
206 	hdrlen += crypt_len;
207 
208 	if (WARN_ONCE(headlen < hdrlen,
209 		      "invalid packet lengths (hdrlen=%d, len=%d, crypt_len=%d)\n",
210 		      hdrlen, len, crypt_len)) {
211 		/*
212 		 * We warn and trace because we want to be able to see
213 		 * it in trace-cmd as well.
214 		 */
215 		IWL_DEBUG_RX(mvm,
216 			     "invalid packet lengths (hdrlen=%d, len=%d, crypt_len=%d)\n",
217 			     hdrlen, len, crypt_len);
218 		return -EINVAL;
219 	}
220 
221 	skb_put_data(skb, hdr, hdrlen);
222 	skb_put_data(skb, (u8 *)hdr + hdrlen + pad_len, headlen - hdrlen);
223 
224 	fraglen = len - headlen;
225 
226 	if (fraglen) {
227 		int offset = (void *)hdr + headlen + pad_len -
228 			     rxb_addr(rxb) + rxb_offset(rxb);
229 
230 		skb_add_rx_frag(skb, 0, rxb_steal_page(rxb), offset,
231 				fraglen, rxb->truesize);
232 	}
233 
234 	return 0;
235 }
236 
237 static void iwl_mvm_add_rtap_sniffer_config(struct iwl_mvm *mvm,
238 					    struct sk_buff *skb)
239 {
240 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
241 	struct ieee80211_vendor_radiotap *radiotap;
242 	const int size = sizeof(*radiotap) + sizeof(__le16);
243 
244 	if (!mvm->cur_aid)
245 		return;
246 
247 	/* ensure alignment */
248 	BUILD_BUG_ON((size + 2) % 4);
249 
250 	radiotap = skb_put(skb, size + 2);
251 	radiotap->align = 1;
252 	/* Intel OUI */
253 	radiotap->oui[0] = 0xf6;
254 	radiotap->oui[1] = 0x54;
255 	radiotap->oui[2] = 0x25;
256 	/* radiotap sniffer config sub-namespace */
257 	radiotap->subns = 1;
258 	radiotap->present = 0x1;
259 	radiotap->len = size - sizeof(*radiotap);
260 	radiotap->pad = 2;
261 
262 	/* fill the data now */
263 	memcpy(radiotap->data, &mvm->cur_aid, sizeof(mvm->cur_aid));
264 	/* and clear the padding */
265 	memset(radiotap->data + sizeof(__le16), 0, radiotap->pad);
266 
267 	rx_status->flag |= RX_FLAG_RADIOTAP_VENDOR_DATA;
268 }
269 
270 /* iwl_mvm_pass_packet_to_mac80211 - passes the packet for mac80211 */
271 static void iwl_mvm_pass_packet_to_mac80211(struct iwl_mvm *mvm,
272 					    struct napi_struct *napi,
273 					    struct sk_buff *skb, int queue,
274 					    struct ieee80211_sta *sta,
275 					    bool csi)
276 {
277 	if (iwl_mvm_check_pn(mvm, skb, queue, sta))
278 		kfree_skb(skb);
279 	else
280 		ieee80211_rx_napi(mvm->hw, sta, skb, napi);
281 }
282 
283 static void iwl_mvm_get_signal_strength(struct iwl_mvm *mvm,
284 					struct ieee80211_rx_status *rx_status,
285 					u32 rate_n_flags, int energy_a,
286 					int energy_b)
287 {
288 	int max_energy;
289 	u32 rate_flags = rate_n_flags;
290 
291 	energy_a = energy_a ? -energy_a : S8_MIN;
292 	energy_b = energy_b ? -energy_b : S8_MIN;
293 	max_energy = max(energy_a, energy_b);
294 
295 	IWL_DEBUG_STATS(mvm, "energy In A %d B %d, and max %d\n",
296 			energy_a, energy_b, max_energy);
297 
298 	rx_status->signal = max_energy;
299 	rx_status->chains =
300 		(rate_flags & RATE_MCS_ANT_AB_MSK) >> RATE_MCS_ANT_POS;
301 	rx_status->chain_signal[0] = energy_a;
302 	rx_status->chain_signal[1] = energy_b;
303 	rx_status->chain_signal[2] = S8_MIN;
304 }
305 
306 static int iwl_mvm_rx_crypto(struct iwl_mvm *mvm, struct ieee80211_hdr *hdr,
307 			     struct ieee80211_rx_status *stats, u16 phy_info,
308 			     struct iwl_rx_mpdu_desc *desc,
309 			     u32 pkt_flags, int queue, u8 *crypt_len)
310 {
311 	u16 status = le16_to_cpu(desc->status);
312 
313 	/*
314 	 * Drop UNKNOWN frames in aggregation, unless in monitor mode
315 	 * (where we don't have the keys).
316 	 * We limit this to aggregation because in TKIP this is a valid
317 	 * scenario, since we may not have the (correct) TTAK (phase 1
318 	 * key) in the firmware.
319 	 */
320 	if (phy_info & IWL_RX_MPDU_PHY_AMPDU &&
321 	    (status & IWL_RX_MPDU_STATUS_SEC_MASK) ==
322 	    IWL_RX_MPDU_STATUS_SEC_UNKNOWN && !mvm->monitor_on)
323 		return -1;
324 
325 	if (!ieee80211_has_protected(hdr->frame_control) ||
326 	    (status & IWL_RX_MPDU_STATUS_SEC_MASK) ==
327 	    IWL_RX_MPDU_STATUS_SEC_NONE)
328 		return 0;
329 
330 	/* TODO: handle packets encrypted with unknown alg */
331 
332 	switch (status & IWL_RX_MPDU_STATUS_SEC_MASK) {
333 	case IWL_RX_MPDU_STATUS_SEC_CCM:
334 	case IWL_RX_MPDU_STATUS_SEC_GCM:
335 		BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN != IEEE80211_GCMP_PN_LEN);
336 		/* alg is CCM: check MIC only */
337 		if (!(status & IWL_RX_MPDU_STATUS_MIC_OK))
338 			return -1;
339 
340 		stats->flag |= RX_FLAG_DECRYPTED;
341 		if (pkt_flags & FH_RSCSR_RADA_EN)
342 			stats->flag |= RX_FLAG_MIC_STRIPPED;
343 		*crypt_len = IEEE80211_CCMP_HDR_LEN;
344 		return 0;
345 	case IWL_RX_MPDU_STATUS_SEC_TKIP:
346 		/* Don't drop the frame and decrypt it in SW */
347 		if (!fw_has_api(&mvm->fw->ucode_capa,
348 				IWL_UCODE_TLV_API_DEPRECATE_TTAK) &&
349 		    !(status & IWL_RX_MPDU_RES_STATUS_TTAK_OK))
350 			return 0;
351 
352 		if (mvm->trans->cfg->gen2 &&
353 		    !(status & RX_MPDU_RES_STATUS_MIC_OK))
354 			stats->flag |= RX_FLAG_MMIC_ERROR;
355 
356 		*crypt_len = IEEE80211_TKIP_IV_LEN;
357 		/* fall through */
358 	case IWL_RX_MPDU_STATUS_SEC_WEP:
359 		if (!(status & IWL_RX_MPDU_STATUS_ICV_OK))
360 			return -1;
361 
362 		stats->flag |= RX_FLAG_DECRYPTED;
363 		if ((status & IWL_RX_MPDU_STATUS_SEC_MASK) ==
364 				IWL_RX_MPDU_STATUS_SEC_WEP)
365 			*crypt_len = IEEE80211_WEP_IV_LEN;
366 
367 		if (pkt_flags & FH_RSCSR_RADA_EN) {
368 			stats->flag |= RX_FLAG_ICV_STRIPPED;
369 			if (mvm->trans->cfg->gen2)
370 				stats->flag |= RX_FLAG_MMIC_STRIPPED;
371 		}
372 
373 		return 0;
374 	case IWL_RX_MPDU_STATUS_SEC_EXT_ENC:
375 		if (!(status & IWL_RX_MPDU_STATUS_MIC_OK))
376 			return -1;
377 		stats->flag |= RX_FLAG_DECRYPTED;
378 		return 0;
379 	default:
380 		/* Expected in monitor (not having the keys) */
381 		if (!mvm->monitor_on)
382 			IWL_ERR(mvm, "Unhandled alg: 0x%x\n", status);
383 	}
384 
385 	return 0;
386 }
387 
388 static void iwl_mvm_rx_csum(struct ieee80211_sta *sta,
389 			    struct sk_buff *skb,
390 			    struct iwl_rx_mpdu_desc *desc)
391 {
392 	struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
393 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
394 	u16 flags = le16_to_cpu(desc->l3l4_flags);
395 	u8 l3_prot = (u8)((flags & IWL_RX_L3L4_L3_PROTO_MASK) >>
396 			  IWL_RX_L3_PROTO_POS);
397 
398 	if (mvmvif->features & NETIF_F_RXCSUM &&
399 	    flags & IWL_RX_L3L4_TCP_UDP_CSUM_OK &&
400 	    (flags & IWL_RX_L3L4_IP_HDR_CSUM_OK ||
401 	     l3_prot == IWL_RX_L3_TYPE_IPV6 ||
402 	     l3_prot == IWL_RX_L3_TYPE_IPV6_FRAG))
403 		skb->ip_summed = CHECKSUM_UNNECESSARY;
404 }
405 
406 /*
407  * returns true if a packet is a duplicate and should be dropped.
408  * Updates AMSDU PN tracking info
409  */
410 static bool iwl_mvm_is_dup(struct ieee80211_sta *sta, int queue,
411 			   struct ieee80211_rx_status *rx_status,
412 			   struct ieee80211_hdr *hdr,
413 			   struct iwl_rx_mpdu_desc *desc)
414 {
415 	struct iwl_mvm_sta *mvm_sta;
416 	struct iwl_mvm_rxq_dup_data *dup_data;
417 	u8 tid, sub_frame_idx;
418 
419 	if (WARN_ON(IS_ERR_OR_NULL(sta)))
420 		return false;
421 
422 	mvm_sta = iwl_mvm_sta_from_mac80211(sta);
423 	dup_data = &mvm_sta->dup_data[queue];
424 
425 	/*
426 	 * Drop duplicate 802.11 retransmissions
427 	 * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
428 	 */
429 	if (ieee80211_is_ctl(hdr->frame_control) ||
430 	    ieee80211_is_qos_nullfunc(hdr->frame_control) ||
431 	    is_multicast_ether_addr(hdr->addr1)) {
432 		rx_status->flag |= RX_FLAG_DUP_VALIDATED;
433 		return false;
434 	}
435 
436 	if (ieee80211_is_data_qos(hdr->frame_control))
437 		/* frame has qos control */
438 		tid = ieee80211_get_tid(hdr);
439 	else
440 		tid = IWL_MAX_TID_COUNT;
441 
442 	/* If this wasn't a part of an A-MSDU the sub-frame index will be 0 */
443 	sub_frame_idx = desc->amsdu_info &
444 		IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK;
445 
446 	if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
447 		     dup_data->last_seq[tid] == hdr->seq_ctrl &&
448 		     dup_data->last_sub_frame[tid] >= sub_frame_idx))
449 		return true;
450 
451 	/* Allow same PN as the first subframe for following sub frames */
452 	if (dup_data->last_seq[tid] == hdr->seq_ctrl &&
453 	    sub_frame_idx > dup_data->last_sub_frame[tid] &&
454 	    desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU)
455 		rx_status->flag |= RX_FLAG_ALLOW_SAME_PN;
456 
457 	dup_data->last_seq[tid] = hdr->seq_ctrl;
458 	dup_data->last_sub_frame[tid] = sub_frame_idx;
459 
460 	rx_status->flag |= RX_FLAG_DUP_VALIDATED;
461 
462 	return false;
463 }
464 
465 int iwl_mvm_notify_rx_queue(struct iwl_mvm *mvm, u32 rxq_mask,
466 			    const u8 *data, u32 count)
467 {
468 	struct iwl_rxq_sync_cmd *cmd;
469 	u32 data_size = sizeof(*cmd) + count;
470 	int ret;
471 
472 	/* should be DWORD aligned */
473 	if (WARN_ON(count & 3 || count > IWL_MULTI_QUEUE_SYNC_MSG_MAX_SIZE))
474 		return -EINVAL;
475 
476 	cmd = kzalloc(data_size, GFP_KERNEL);
477 	if (!cmd)
478 		return -ENOMEM;
479 
480 	cmd->rxq_mask = cpu_to_le32(rxq_mask);
481 	cmd->count =  cpu_to_le32(count);
482 	cmd->flags = 0;
483 	memcpy(cmd->payload, data, count);
484 
485 	ret = iwl_mvm_send_cmd_pdu(mvm,
486 				   WIDE_ID(DATA_PATH_GROUP,
487 					   TRIGGER_RX_QUEUES_NOTIF_CMD),
488 				   0, data_size, cmd);
489 
490 	kfree(cmd);
491 	return ret;
492 }
493 
494 /*
495  * Returns true if sn2 - buffer_size < sn1 < sn2.
496  * To be used only in order to compare reorder buffer head with NSSN.
497  * We fully trust NSSN unless it is behind us due to reorder timeout.
498  * Reorder timeout can only bring us up to buffer_size SNs ahead of NSSN.
499  */
500 static bool iwl_mvm_is_sn_less(u16 sn1, u16 sn2, u16 buffer_size)
501 {
502 	return ieee80211_sn_less(sn1, sn2) &&
503 	       !ieee80211_sn_less(sn1, sn2 - buffer_size);
504 }
505 
506 #define RX_REORDER_BUF_TIMEOUT_MQ (HZ / 10)
507 
508 static void iwl_mvm_release_frames(struct iwl_mvm *mvm,
509 				   struct ieee80211_sta *sta,
510 				   struct napi_struct *napi,
511 				   struct iwl_mvm_baid_data *baid_data,
512 				   struct iwl_mvm_reorder_buffer *reorder_buf,
513 				   u16 nssn)
514 {
515 	struct iwl_mvm_reorder_buf_entry *entries =
516 		&baid_data->entries[reorder_buf->queue *
517 				    baid_data->entries_per_queue];
518 	u16 ssn = reorder_buf->head_sn;
519 
520 	lockdep_assert_held(&reorder_buf->lock);
521 
522 	/* ignore nssn smaller than head sn - this can happen due to timeout */
523 	if (iwl_mvm_is_sn_less(nssn, ssn, reorder_buf->buf_size))
524 		goto set_timer;
525 
526 	while (iwl_mvm_is_sn_less(ssn, nssn, reorder_buf->buf_size)) {
527 		int index = ssn % reorder_buf->buf_size;
528 		struct sk_buff_head *skb_list = &entries[index].e.frames;
529 		struct sk_buff *skb;
530 
531 		ssn = ieee80211_sn_inc(ssn);
532 
533 		/*
534 		 * Empty the list. Will have more than one frame for A-MSDU.
535 		 * Empty list is valid as well since nssn indicates frames were
536 		 * received.
537 		 */
538 		while ((skb = __skb_dequeue(skb_list))) {
539 			iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb,
540 							reorder_buf->queue,
541 							sta, false);
542 			reorder_buf->num_stored--;
543 		}
544 	}
545 	reorder_buf->head_sn = nssn;
546 
547 set_timer:
548 	if (reorder_buf->num_stored && !reorder_buf->removed) {
549 		u16 index = reorder_buf->head_sn % reorder_buf->buf_size;
550 
551 		while (skb_queue_empty(&entries[index].e.frames))
552 			index = (index + 1) % reorder_buf->buf_size;
553 		/* modify timer to match next frame's expiration time */
554 		mod_timer(&reorder_buf->reorder_timer,
555 			  entries[index].e.reorder_time + 1 +
556 			  RX_REORDER_BUF_TIMEOUT_MQ);
557 	} else {
558 		del_timer(&reorder_buf->reorder_timer);
559 	}
560 }
561 
562 void iwl_mvm_reorder_timer_expired(struct timer_list *t)
563 {
564 	struct iwl_mvm_reorder_buffer *buf = from_timer(buf, t, reorder_timer);
565 	struct iwl_mvm_baid_data *baid_data =
566 		iwl_mvm_baid_data_from_reorder_buf(buf);
567 	struct iwl_mvm_reorder_buf_entry *entries =
568 		&baid_data->entries[buf->queue * baid_data->entries_per_queue];
569 	int i;
570 	u16 sn = 0, index = 0;
571 	bool expired = false;
572 	bool cont = false;
573 
574 	spin_lock(&buf->lock);
575 
576 	if (!buf->num_stored || buf->removed) {
577 		spin_unlock(&buf->lock);
578 		return;
579 	}
580 
581 	for (i = 0; i < buf->buf_size ; i++) {
582 		index = (buf->head_sn + i) % buf->buf_size;
583 
584 		if (skb_queue_empty(&entries[index].e.frames)) {
585 			/*
586 			 * If there is a hole and the next frame didn't expire
587 			 * we want to break and not advance SN
588 			 */
589 			cont = false;
590 			continue;
591 		}
592 		if (!cont &&
593 		    !time_after(jiffies, entries[index].e.reorder_time +
594 					 RX_REORDER_BUF_TIMEOUT_MQ))
595 			break;
596 
597 		expired = true;
598 		/* continue until next hole after this expired frames */
599 		cont = true;
600 		sn = ieee80211_sn_add(buf->head_sn, i + 1);
601 	}
602 
603 	if (expired) {
604 		struct ieee80211_sta *sta;
605 		struct iwl_mvm_sta *mvmsta;
606 		u8 sta_id = baid_data->sta_id;
607 
608 		rcu_read_lock();
609 		sta = rcu_dereference(buf->mvm->fw_id_to_mac_id[sta_id]);
610 		mvmsta = iwl_mvm_sta_from_mac80211(sta);
611 
612 		/* SN is set to the last expired frame + 1 */
613 		IWL_DEBUG_HT(buf->mvm,
614 			     "Releasing expired frames for sta %u, sn %d\n",
615 			     sta_id, sn);
616 		iwl_mvm_event_frame_timeout_callback(buf->mvm, mvmsta->vif,
617 						     sta, baid_data->tid);
618 		iwl_mvm_release_frames(buf->mvm, sta, NULL, baid_data, buf, sn);
619 		rcu_read_unlock();
620 	} else {
621 		/*
622 		 * If no frame expired and there are stored frames, index is now
623 		 * pointing to the first unexpired frame - modify timer
624 		 * accordingly to this frame.
625 		 */
626 		mod_timer(&buf->reorder_timer,
627 			  entries[index].e.reorder_time +
628 			  1 + RX_REORDER_BUF_TIMEOUT_MQ);
629 	}
630 	spin_unlock(&buf->lock);
631 }
632 
633 static void iwl_mvm_del_ba(struct iwl_mvm *mvm, int queue,
634 			   struct iwl_mvm_delba_data *data)
635 {
636 	struct iwl_mvm_baid_data *ba_data;
637 	struct ieee80211_sta *sta;
638 	struct iwl_mvm_reorder_buffer *reorder_buf;
639 	u8 baid = data->baid;
640 
641 	if (WARN_ONCE(baid >= IWL_MAX_BAID, "invalid BAID: %x\n", baid))
642 		return;
643 
644 	rcu_read_lock();
645 
646 	ba_data = rcu_dereference(mvm->baid_map[baid]);
647 	if (WARN_ON_ONCE(!ba_data))
648 		goto out;
649 
650 	sta = rcu_dereference(mvm->fw_id_to_mac_id[ba_data->sta_id]);
651 	if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
652 		goto out;
653 
654 	reorder_buf = &ba_data->reorder_buf[queue];
655 
656 	/* release all frames that are in the reorder buffer to the stack */
657 	spin_lock_bh(&reorder_buf->lock);
658 	iwl_mvm_release_frames(mvm, sta, NULL, ba_data, reorder_buf,
659 			       ieee80211_sn_add(reorder_buf->head_sn,
660 						reorder_buf->buf_size));
661 	spin_unlock_bh(&reorder_buf->lock);
662 	del_timer_sync(&reorder_buf->reorder_timer);
663 
664 out:
665 	rcu_read_unlock();
666 }
667 
668 void iwl_mvm_rx_queue_notif(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
669 			    int queue)
670 {
671 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
672 	struct iwl_rxq_sync_notification *notif;
673 	struct iwl_mvm_internal_rxq_notif *internal_notif;
674 
675 	notif = (void *)pkt->data;
676 	internal_notif = (void *)notif->payload;
677 
678 	if (internal_notif->sync &&
679 	    mvm->queue_sync_cookie != internal_notif->cookie) {
680 		WARN_ONCE(1, "Received expired RX queue sync message\n");
681 		return;
682 	}
683 
684 	switch (internal_notif->type) {
685 	case IWL_MVM_RXQ_EMPTY:
686 		break;
687 	case IWL_MVM_RXQ_NOTIF_DEL_BA:
688 		iwl_mvm_del_ba(mvm, queue, (void *)internal_notif->data);
689 		break;
690 	default:
691 		WARN_ONCE(1, "Invalid identifier %d", internal_notif->type);
692 	}
693 
694 	if (internal_notif->sync &&
695 	    !atomic_dec_return(&mvm->queue_sync_counter))
696 		wake_up(&mvm->rx_sync_waitq);
697 }
698 
699 /*
700  * Returns true if the MPDU was buffered\dropped, false if it should be passed
701  * to upper layer.
702  */
703 static bool iwl_mvm_reorder(struct iwl_mvm *mvm,
704 			    struct napi_struct *napi,
705 			    int queue,
706 			    struct ieee80211_sta *sta,
707 			    struct sk_buff *skb,
708 			    struct iwl_rx_mpdu_desc *desc)
709 {
710 	struct ieee80211_hdr *hdr = iwl_mvm_skb_get_hdr(skb);
711 	struct iwl_mvm_sta *mvm_sta;
712 	struct iwl_mvm_baid_data *baid_data;
713 	struct iwl_mvm_reorder_buffer *buffer;
714 	struct sk_buff *tail;
715 	u32 reorder = le32_to_cpu(desc->reorder_data);
716 	bool amsdu = desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU;
717 	bool last_subframe =
718 		desc->amsdu_info & IWL_RX_MPDU_AMSDU_LAST_SUBFRAME;
719 	u8 tid = ieee80211_get_tid(hdr);
720 	u8 sub_frame_idx = desc->amsdu_info &
721 			   IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK;
722 	struct iwl_mvm_reorder_buf_entry *entries;
723 	int index;
724 	u16 nssn, sn;
725 	u8 baid;
726 
727 	baid = (reorder & IWL_RX_MPDU_REORDER_BAID_MASK) >>
728 		IWL_RX_MPDU_REORDER_BAID_SHIFT;
729 
730 	/*
731 	 * This also covers the case of receiving a Block Ack Request
732 	 * outside a BA session; we'll pass it to mac80211 and that
733 	 * then sends a delBA action frame.
734 	 * This also covers pure monitor mode, in which case we won't
735 	 * have any BA sessions.
736 	 */
737 	if (baid == IWL_RX_REORDER_DATA_INVALID_BAID)
738 		return false;
739 
740 	/* no sta yet */
741 	if (WARN_ONCE(IS_ERR_OR_NULL(sta),
742 		      "Got valid BAID without a valid station assigned\n"))
743 		return false;
744 
745 	mvm_sta = iwl_mvm_sta_from_mac80211(sta);
746 
747 	/* not a data packet or a bar */
748 	if (!ieee80211_is_back_req(hdr->frame_control) &&
749 	    (!ieee80211_is_data_qos(hdr->frame_control) ||
750 	     is_multicast_ether_addr(hdr->addr1)))
751 		return false;
752 
753 	if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
754 		return false;
755 
756 	baid_data = rcu_dereference(mvm->baid_map[baid]);
757 	if (!baid_data) {
758 		IWL_DEBUG_RX(mvm,
759 			     "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n",
760 			      baid, reorder);
761 		return false;
762 	}
763 
764 	if (WARN(tid != baid_data->tid || mvm_sta->sta_id != baid_data->sta_id,
765 		 "baid 0x%x is mapped to sta:%d tid:%d, but was received for sta:%d tid:%d\n",
766 		 baid, baid_data->sta_id, baid_data->tid, mvm_sta->sta_id,
767 		 tid))
768 		return false;
769 
770 	nssn = reorder & IWL_RX_MPDU_REORDER_NSSN_MASK;
771 	sn = (reorder & IWL_RX_MPDU_REORDER_SN_MASK) >>
772 		IWL_RX_MPDU_REORDER_SN_SHIFT;
773 
774 	buffer = &baid_data->reorder_buf[queue];
775 	entries = &baid_data->entries[queue * baid_data->entries_per_queue];
776 
777 	spin_lock_bh(&buffer->lock);
778 
779 	if (!buffer->valid) {
780 		if (reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN) {
781 			spin_unlock_bh(&buffer->lock);
782 			return false;
783 		}
784 		buffer->valid = true;
785 	}
786 
787 	if (ieee80211_is_back_req(hdr->frame_control)) {
788 		iwl_mvm_release_frames(mvm, sta, napi, baid_data, buffer, nssn);
789 		goto drop;
790 	}
791 
792 	/*
793 	 * If there was a significant jump in the nssn - adjust.
794 	 * If the SN is smaller than the NSSN it might need to first go into
795 	 * the reorder buffer, in which case we just release up to it and the
796 	 * rest of the function will take care of storing it and releasing up to
797 	 * the nssn
798 	 */
799 	if (!iwl_mvm_is_sn_less(nssn, buffer->head_sn + buffer->buf_size,
800 				buffer->buf_size) ||
801 	    !ieee80211_sn_less(sn, buffer->head_sn + buffer->buf_size)) {
802 		u16 min_sn = ieee80211_sn_less(sn, nssn) ? sn : nssn;
803 
804 		iwl_mvm_release_frames(mvm, sta, napi, baid_data, buffer,
805 				       min_sn);
806 	}
807 
808 	/* drop any oudated packets */
809 	if (ieee80211_sn_less(sn, buffer->head_sn))
810 		goto drop;
811 
812 	/* release immediately if allowed by nssn and no stored frames */
813 	if (!buffer->num_stored && ieee80211_sn_less(sn, nssn)) {
814 		if (iwl_mvm_is_sn_less(buffer->head_sn, nssn,
815 				       buffer->buf_size) &&
816 		   (!amsdu || last_subframe))
817 			buffer->head_sn = nssn;
818 		/* No need to update AMSDU last SN - we are moving the head */
819 		spin_unlock_bh(&buffer->lock);
820 		return false;
821 	}
822 
823 	/*
824 	 * release immediately if there are no stored frames, and the sn is
825 	 * equal to the head.
826 	 * This can happen due to reorder timer, where NSSN is behind head_sn.
827 	 * When we released everything, and we got the next frame in the
828 	 * sequence, according to the NSSN we can't release immediately,
829 	 * while technically there is no hole and we can move forward.
830 	 */
831 	if (!buffer->num_stored && sn == buffer->head_sn) {
832 		if (!amsdu || last_subframe)
833 			buffer->head_sn = ieee80211_sn_inc(buffer->head_sn);
834 		/* No need to update AMSDU last SN - we are moving the head */
835 		spin_unlock_bh(&buffer->lock);
836 		return false;
837 	}
838 
839 	index = sn % buffer->buf_size;
840 
841 	/*
842 	 * Check if we already stored this frame
843 	 * As AMSDU is either received or not as whole, logic is simple:
844 	 * If we have frames in that position in the buffer and the last frame
845 	 * originated from AMSDU had a different SN then it is a retransmission.
846 	 * If it is the same SN then if the subframe index is incrementing it
847 	 * is the same AMSDU - otherwise it is a retransmission.
848 	 */
849 	tail = skb_peek_tail(&entries[index].e.frames);
850 	if (tail && !amsdu)
851 		goto drop;
852 	else if (tail && (sn != buffer->last_amsdu ||
853 			  buffer->last_sub_index >= sub_frame_idx))
854 		goto drop;
855 
856 	/* put in reorder buffer */
857 	__skb_queue_tail(&entries[index].e.frames, skb);
858 	buffer->num_stored++;
859 	entries[index].e.reorder_time = jiffies;
860 
861 	if (amsdu) {
862 		buffer->last_amsdu = sn;
863 		buffer->last_sub_index = sub_frame_idx;
864 	}
865 
866 	/*
867 	 * We cannot trust NSSN for AMSDU sub-frames that are not the last.
868 	 * The reason is that NSSN advances on the first sub-frame, and may
869 	 * cause the reorder buffer to advance before all the sub-frames arrive.
870 	 * Example: reorder buffer contains SN 0 & 2, and we receive AMSDU with
871 	 * SN 1. NSSN for first sub frame will be 3 with the result of driver
872 	 * releasing SN 0,1, 2. When sub-frame 1 arrives - reorder buffer is
873 	 * already ahead and it will be dropped.
874 	 * If the last sub-frame is not on this queue - we will get frame
875 	 * release notification with up to date NSSN.
876 	 */
877 	if (!amsdu || last_subframe)
878 		iwl_mvm_release_frames(mvm, sta, napi, baid_data, buffer, nssn);
879 
880 	spin_unlock_bh(&buffer->lock);
881 	return true;
882 
883 drop:
884 	kfree_skb(skb);
885 	spin_unlock_bh(&buffer->lock);
886 	return true;
887 }
888 
889 static void iwl_mvm_agg_rx_received(struct iwl_mvm *mvm,
890 				    u32 reorder_data, u8 baid)
891 {
892 	unsigned long now = jiffies;
893 	unsigned long timeout;
894 	struct iwl_mvm_baid_data *data;
895 
896 	rcu_read_lock();
897 
898 	data = rcu_dereference(mvm->baid_map[baid]);
899 	if (!data) {
900 		IWL_DEBUG_RX(mvm,
901 			     "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n",
902 			      baid, reorder_data);
903 		goto out;
904 	}
905 
906 	if (!data->timeout)
907 		goto out;
908 
909 	timeout = data->timeout;
910 	/*
911 	 * Do not update last rx all the time to avoid cache bouncing
912 	 * between the rx queues.
913 	 * Update it every timeout. Worst case is the session will
914 	 * expire after ~ 2 * timeout, which doesn't matter that much.
915 	 */
916 	if (time_before(data->last_rx + TU_TO_JIFFIES(timeout), now))
917 		/* Update is atomic */
918 		data->last_rx = now;
919 
920 out:
921 	rcu_read_unlock();
922 }
923 
924 static void iwl_mvm_flip_address(u8 *addr)
925 {
926 	int i;
927 	u8 mac_addr[ETH_ALEN];
928 
929 	for (i = 0; i < ETH_ALEN; i++)
930 		mac_addr[i] = addr[ETH_ALEN - i - 1];
931 	ether_addr_copy(addr, mac_addr);
932 }
933 
934 struct iwl_mvm_rx_phy_data {
935 	enum iwl_rx_phy_info_type info_type;
936 	__le32 d0, d1, d2, d3;
937 	__le16 d4;
938 };
939 
940 static void iwl_mvm_decode_he_mu_ext(struct iwl_mvm *mvm,
941 				     struct iwl_mvm_rx_phy_data *phy_data,
942 				     u32 rate_n_flags,
943 				     struct ieee80211_radiotap_he_mu *he_mu)
944 {
945 	u32 phy_data2 = le32_to_cpu(phy_data->d2);
946 	u32 phy_data3 = le32_to_cpu(phy_data->d3);
947 	u16 phy_data4 = le16_to_cpu(phy_data->d4);
948 
949 	if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CRC_OK, phy_data4)) {
950 		he_mu->flags1 |=
951 			cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_RU_KNOWN |
952 				    IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU_KNOWN);
953 
954 		he_mu->flags1 |=
955 			le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CTR_RU,
956 						   phy_data4),
957 					 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU);
958 
959 		he_mu->ru_ch1[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU0,
960 					     phy_data2);
961 		he_mu->ru_ch1[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU1,
962 					     phy_data3);
963 		he_mu->ru_ch1[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU2,
964 					     phy_data2);
965 		he_mu->ru_ch1[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU3,
966 					     phy_data3);
967 	}
968 
969 	if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CRC_OK, phy_data4) &&
970 	    (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) != RATE_MCS_CHAN_WIDTH_20) {
971 		he_mu->flags1 |=
972 			cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_RU_KNOWN |
973 				    IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_CTR_26T_RU_KNOWN);
974 
975 		he_mu->flags2 |=
976 			le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CTR_RU,
977 						   phy_data4),
978 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_CH2_CTR_26T_RU);
979 
980 		he_mu->ru_ch2[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU0,
981 					     phy_data2);
982 		he_mu->ru_ch2[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU1,
983 					     phy_data3);
984 		he_mu->ru_ch2[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU2,
985 					     phy_data2);
986 		he_mu->ru_ch2[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU3,
987 					     phy_data3);
988 	}
989 }
990 
991 static void
992 iwl_mvm_decode_he_phy_ru_alloc(struct iwl_mvm_rx_phy_data *phy_data,
993 			       u32 rate_n_flags,
994 			       struct ieee80211_radiotap_he *he,
995 			       struct ieee80211_radiotap_he_mu *he_mu,
996 			       struct ieee80211_rx_status *rx_status)
997 {
998 	/*
999 	 * Unfortunately, we have to leave the mac80211 data
1000 	 * incorrect for the case that we receive an HE-MU
1001 	 * transmission and *don't* have the HE phy data (due
1002 	 * to the bits being used for TSF). This shouldn't
1003 	 * happen though as management frames where we need
1004 	 * the TSF/timers are not be transmitted in HE-MU.
1005 	 */
1006 	u8 ru = le32_get_bits(phy_data->d1, IWL_RX_PHY_DATA1_HE_RU_ALLOC_MASK);
1007 	u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK;
1008 	u8 offs = 0;
1009 
1010 	rx_status->bw = RATE_INFO_BW_HE_RU;
1011 
1012 	he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN);
1013 
1014 	switch (ru) {
1015 	case 0 ... 36:
1016 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_26;
1017 		offs = ru;
1018 		break;
1019 	case 37 ... 52:
1020 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_52;
1021 		offs = ru - 37;
1022 		break;
1023 	case 53 ... 60:
1024 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106;
1025 		offs = ru - 53;
1026 		break;
1027 	case 61 ... 64:
1028 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_242;
1029 		offs = ru - 61;
1030 		break;
1031 	case 65 ... 66:
1032 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_484;
1033 		offs = ru - 65;
1034 		break;
1035 	case 67:
1036 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_996;
1037 		break;
1038 	case 68:
1039 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_2x996;
1040 		break;
1041 	}
1042 	he->data2 |= le16_encode_bits(offs,
1043 				      IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET);
1044 	he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_KNOWN |
1045 				 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET_KNOWN);
1046 	if (phy_data->d1 & cpu_to_le32(IWL_RX_PHY_DATA1_HE_RU_ALLOC_SEC80))
1047 		he->data2 |=
1048 			cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_SEC);
1049 
1050 #define CHECK_BW(bw) \
1051 	BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_ ## bw ## MHZ != \
1052 		     RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS); \
1053 	BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_ ## bw ## MHZ != \
1054 		     RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS)
1055 	CHECK_BW(20);
1056 	CHECK_BW(40);
1057 	CHECK_BW(80);
1058 	CHECK_BW(160);
1059 
1060 	if (he_mu)
1061 		he_mu->flags2 |=
1062 			le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK,
1063 						   rate_n_flags),
1064 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW);
1065 	else if (he_type == RATE_MCS_HE_TYPE_TRIG)
1066 		he->data6 |=
1067 			cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_KNOWN) |
1068 			le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK,
1069 						   rate_n_flags),
1070 					 IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW);
1071 }
1072 
1073 static void iwl_mvm_decode_he_phy_data(struct iwl_mvm *mvm,
1074 				       struct iwl_mvm_rx_phy_data *phy_data,
1075 				       struct ieee80211_radiotap_he *he,
1076 				       struct ieee80211_radiotap_he_mu *he_mu,
1077 				       struct ieee80211_rx_status *rx_status,
1078 				       u32 rate_n_flags, int queue)
1079 {
1080 	switch (phy_data->info_type) {
1081 	case IWL_RX_PHY_INFO_TYPE_NONE:
1082 	case IWL_RX_PHY_INFO_TYPE_CCK:
1083 	case IWL_RX_PHY_INFO_TYPE_OFDM_LGCY:
1084 	case IWL_RX_PHY_INFO_TYPE_HT:
1085 	case IWL_RX_PHY_INFO_TYPE_VHT_SU:
1086 	case IWL_RX_PHY_INFO_TYPE_VHT_MU:
1087 		return;
1088 	case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT:
1089 		he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN |
1090 					 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE2_KNOWN |
1091 					 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE3_KNOWN |
1092 					 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE4_KNOWN);
1093 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1094 							    IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE1),
1095 					      IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE1);
1096 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1097 							    IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE2),
1098 					      IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE2);
1099 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1100 							    IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE3),
1101 					      IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE3);
1102 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1103 							    IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE4),
1104 					      IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE4);
1105 		/* fall through */
1106 	case IWL_RX_PHY_INFO_TYPE_HE_SU:
1107 	case IWL_RX_PHY_INFO_TYPE_HE_MU:
1108 	case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
1109 	case IWL_RX_PHY_INFO_TYPE_HE_TB:
1110 		/* HE common */
1111 		he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_LDPC_XSYMSEG_KNOWN |
1112 					 IEEE80211_RADIOTAP_HE_DATA1_DOPPLER_KNOWN |
1113 					 IEEE80211_RADIOTAP_HE_DATA1_BSS_COLOR_KNOWN);
1114 		he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRE_FEC_PAD_KNOWN |
1115 					 IEEE80211_RADIOTAP_HE_DATA2_PE_DISAMBIG_KNOWN |
1116 					 IEEE80211_RADIOTAP_HE_DATA2_TXOP_KNOWN |
1117 					 IEEE80211_RADIOTAP_HE_DATA2_NUM_LTF_SYMS_KNOWN);
1118 		he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1119 							    IWL_RX_PHY_DATA0_HE_BSS_COLOR_MASK),
1120 					      IEEE80211_RADIOTAP_HE_DATA3_BSS_COLOR);
1121 		if (phy_data->info_type != IWL_RX_PHY_INFO_TYPE_HE_TB &&
1122 		    phy_data->info_type != IWL_RX_PHY_INFO_TYPE_HE_TB_EXT) {
1123 			he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_UL_DL_KNOWN);
1124 			he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1125 							    IWL_RX_PHY_DATA0_HE_UPLINK),
1126 						      IEEE80211_RADIOTAP_HE_DATA3_UL_DL);
1127 		}
1128 		he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1129 							    IWL_RX_PHY_DATA0_HE_LDPC_EXT_SYM),
1130 					      IEEE80211_RADIOTAP_HE_DATA3_LDPC_XSYMSEG);
1131 		he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1132 							    IWL_RX_PHY_DATA0_HE_PRE_FEC_PAD_MASK),
1133 					      IEEE80211_RADIOTAP_HE_DATA5_PRE_FEC_PAD);
1134 		he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1135 							    IWL_RX_PHY_DATA0_HE_PE_DISAMBIG),
1136 					      IEEE80211_RADIOTAP_HE_DATA5_PE_DISAMBIG);
1137 		he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d1,
1138 							    IWL_RX_PHY_DATA1_HE_LTF_NUM_MASK),
1139 					      IEEE80211_RADIOTAP_HE_DATA5_NUM_LTF_SYMS);
1140 		he->data6 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1141 							    IWL_RX_PHY_DATA0_HE_TXOP_DUR_MASK),
1142 					      IEEE80211_RADIOTAP_HE_DATA6_TXOP);
1143 		he->data6 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1144 							    IWL_RX_PHY_DATA0_HE_DOPPLER),
1145 					      IEEE80211_RADIOTAP_HE_DATA6_DOPPLER);
1146 		break;
1147 	}
1148 
1149 	switch (phy_data->info_type) {
1150 	case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
1151 	case IWL_RX_PHY_INFO_TYPE_HE_MU:
1152 	case IWL_RX_PHY_INFO_TYPE_HE_SU:
1153 		he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN);
1154 		he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1155 							    IWL_RX_PHY_DATA0_HE_SPATIAL_REUSE_MASK),
1156 					      IEEE80211_RADIOTAP_HE_DATA4_SU_MU_SPTL_REUSE);
1157 		break;
1158 	default:
1159 		/* nothing here */
1160 		break;
1161 	}
1162 
1163 	switch (phy_data->info_type) {
1164 	case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
1165 		he_mu->flags1 |=
1166 			le16_encode_bits(le16_get_bits(phy_data->d4,
1167 						       IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_DCM),
1168 					 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM);
1169 		he_mu->flags1 |=
1170 			le16_encode_bits(le16_get_bits(phy_data->d4,
1171 						       IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_MCS_MASK),
1172 					 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS);
1173 		he_mu->flags2 |=
1174 			le16_encode_bits(le16_get_bits(phy_data->d4,
1175 						       IWL_RX_PHY_DATA4_HE_MU_EXT_PREAMBLE_PUNC_TYPE_MASK),
1176 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW);
1177 		iwl_mvm_decode_he_mu_ext(mvm, phy_data, rate_n_flags, he_mu);
1178 		/* fall through */
1179 	case IWL_RX_PHY_INFO_TYPE_HE_MU:
1180 		he_mu->flags2 |=
1181 			le16_encode_bits(le32_get_bits(phy_data->d1,
1182 						       IWL_RX_PHY_DATA1_HE_MU_SIBG_SYM_OR_USER_NUM_MASK),
1183 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_SYMS_USERS);
1184 		he_mu->flags2 |=
1185 			le16_encode_bits(le32_get_bits(phy_data->d1,
1186 						       IWL_RX_PHY_DATA1_HE_MU_SIGB_COMPRESSION),
1187 					 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_COMP);
1188 		/* fall through */
1189 	case IWL_RX_PHY_INFO_TYPE_HE_TB:
1190 	case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT:
1191 		iwl_mvm_decode_he_phy_ru_alloc(phy_data, rate_n_flags,
1192 					       he, he_mu, rx_status);
1193 		break;
1194 	case IWL_RX_PHY_INFO_TYPE_HE_SU:
1195 		he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BEAM_CHANGE_KNOWN);
1196 		he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1197 							    IWL_RX_PHY_DATA0_HE_BEAM_CHNG),
1198 					      IEEE80211_RADIOTAP_HE_DATA3_BEAM_CHANGE);
1199 		break;
1200 	default:
1201 		/* nothing */
1202 		break;
1203 	}
1204 }
1205 
1206 static void iwl_mvm_rx_he(struct iwl_mvm *mvm, struct sk_buff *skb,
1207 			  struct iwl_mvm_rx_phy_data *phy_data,
1208 			  u32 rate_n_flags, u16 phy_info, int queue)
1209 {
1210 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
1211 	struct ieee80211_radiotap_he *he = NULL;
1212 	struct ieee80211_radiotap_he_mu *he_mu = NULL;
1213 	u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK;
1214 	u8 stbc, ltf;
1215 	static const struct ieee80211_radiotap_he known = {
1216 		.data1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_DATA_MCS_KNOWN |
1217 				     IEEE80211_RADIOTAP_HE_DATA1_DATA_DCM_KNOWN |
1218 				     IEEE80211_RADIOTAP_HE_DATA1_STBC_KNOWN |
1219 				     IEEE80211_RADIOTAP_HE_DATA1_CODING_KNOWN),
1220 		.data2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_GI_KNOWN |
1221 				     IEEE80211_RADIOTAP_HE_DATA2_TXBF_KNOWN),
1222 	};
1223 	static const struct ieee80211_radiotap_he_mu mu_known = {
1224 		.flags1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS_KNOWN |
1225 				      IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM_KNOWN |
1226 				      IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_SYMS_USERS_KNOWN |
1227 				      IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_COMP_KNOWN),
1228 		.flags2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW_KNOWN |
1229 				      IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_KNOWN),
1230 	};
1231 
1232 	he = skb_put_data(skb, &known, sizeof(known));
1233 	rx_status->flag |= RX_FLAG_RADIOTAP_HE;
1234 
1235 	if (phy_data->info_type == IWL_RX_PHY_INFO_TYPE_HE_MU ||
1236 	    phy_data->info_type == IWL_RX_PHY_INFO_TYPE_HE_MU_EXT) {
1237 		he_mu = skb_put_data(skb, &mu_known, sizeof(mu_known));
1238 		rx_status->flag |= RX_FLAG_RADIOTAP_HE_MU;
1239 	}
1240 
1241 	/* report the AMPDU-EOF bit on single frames */
1242 	if (!queue && !(phy_info & IWL_RX_MPDU_PHY_AMPDU)) {
1243 		rx_status->flag |= RX_FLAG_AMPDU_DETAILS;
1244 		rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN;
1245 		if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_HE_DELIM_EOF))
1246 			rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT;
1247 	}
1248 
1249 	if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD)
1250 		iwl_mvm_decode_he_phy_data(mvm, phy_data, he, he_mu, rx_status,
1251 					   rate_n_flags, queue);
1252 
1253 	/* update aggregation data for monitor sake on default queue */
1254 	if (!queue && (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) &&
1255 	    (phy_info & IWL_RX_MPDU_PHY_AMPDU)) {
1256 		bool toggle_bit = phy_info & IWL_RX_MPDU_PHY_AMPDU_TOGGLE;
1257 
1258 		/* toggle is switched whenever new aggregation starts */
1259 		if (toggle_bit != mvm->ampdu_toggle) {
1260 			rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN;
1261 			if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_HE_DELIM_EOF))
1262 				rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT;
1263 		}
1264 	}
1265 
1266 	if (he_type == RATE_MCS_HE_TYPE_EXT_SU &&
1267 	    rate_n_flags & RATE_MCS_HE_106T_MSK) {
1268 		rx_status->bw = RATE_INFO_BW_HE_RU;
1269 		rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106;
1270 	}
1271 
1272 	/* actually data is filled in mac80211 */
1273 	if (he_type == RATE_MCS_HE_TYPE_SU ||
1274 	    he_type == RATE_MCS_HE_TYPE_EXT_SU)
1275 		he->data1 |=
1276 			cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN);
1277 
1278 	stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >> RATE_MCS_STBC_POS;
1279 	rx_status->nss =
1280 		((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >>
1281 					RATE_VHT_MCS_NSS_POS) + 1;
1282 	rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK;
1283 	rx_status->encoding = RX_ENC_HE;
1284 	rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
1285 	if (rate_n_flags & RATE_MCS_BF_MSK)
1286 		rx_status->enc_flags |= RX_ENC_FLAG_BF;
1287 
1288 	rx_status->he_dcm =
1289 		!!(rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK);
1290 
1291 #define CHECK_TYPE(F)							\
1292 	BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_ ## F !=	\
1293 		     (RATE_MCS_HE_TYPE_ ## F >> RATE_MCS_HE_TYPE_POS))
1294 
1295 	CHECK_TYPE(SU);
1296 	CHECK_TYPE(EXT_SU);
1297 	CHECK_TYPE(MU);
1298 	CHECK_TYPE(TRIG);
1299 
1300 	he->data1 |= cpu_to_le16(he_type >> RATE_MCS_HE_TYPE_POS);
1301 
1302 	if (rate_n_flags & RATE_MCS_BF_MSK)
1303 		he->data5 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA5_TXBF);
1304 
1305 	switch ((rate_n_flags & RATE_MCS_HE_GI_LTF_MSK) >>
1306 		RATE_MCS_HE_GI_LTF_POS) {
1307 	case 0:
1308 		if (he_type == RATE_MCS_HE_TYPE_TRIG)
1309 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
1310 		else
1311 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
1312 		if (he_type == RATE_MCS_HE_TYPE_MU)
1313 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
1314 		else
1315 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X;
1316 		break;
1317 	case 1:
1318 		if (he_type == RATE_MCS_HE_TYPE_TRIG)
1319 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
1320 		else
1321 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
1322 		ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X;
1323 		break;
1324 	case 2:
1325 		if (he_type == RATE_MCS_HE_TYPE_TRIG) {
1326 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
1327 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
1328 		} else {
1329 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
1330 			ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X;
1331 		}
1332 		break;
1333 	case 3:
1334 		if ((he_type == RATE_MCS_HE_TYPE_SU ||
1335 		     he_type == RATE_MCS_HE_TYPE_EXT_SU) &&
1336 		    rate_n_flags & RATE_MCS_SGI_MSK)
1337 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
1338 		else
1339 			rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
1340 		ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
1341 		break;
1342 	}
1343 
1344 	he->data5 |= le16_encode_bits(ltf,
1345 				      IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE);
1346 }
1347 
1348 static void iwl_mvm_decode_lsig(struct sk_buff *skb,
1349 				struct iwl_mvm_rx_phy_data *phy_data)
1350 {
1351 	struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
1352 	struct ieee80211_radiotap_lsig *lsig;
1353 
1354 	switch (phy_data->info_type) {
1355 	case IWL_RX_PHY_INFO_TYPE_HT:
1356 	case IWL_RX_PHY_INFO_TYPE_VHT_SU:
1357 	case IWL_RX_PHY_INFO_TYPE_VHT_MU:
1358 	case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT:
1359 	case IWL_RX_PHY_INFO_TYPE_HE_SU:
1360 	case IWL_RX_PHY_INFO_TYPE_HE_MU:
1361 	case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
1362 	case IWL_RX_PHY_INFO_TYPE_HE_TB:
1363 		lsig = skb_put(skb, sizeof(*lsig));
1364 		lsig->data1 = cpu_to_le16(IEEE80211_RADIOTAP_LSIG_DATA1_LENGTH_KNOWN);
1365 		lsig->data2 = le16_encode_bits(le32_get_bits(phy_data->d1,
1366 							     IWL_RX_PHY_DATA1_LSIG_LEN_MASK),
1367 					       IEEE80211_RADIOTAP_LSIG_DATA2_LENGTH);
1368 		rx_status->flag |= RX_FLAG_RADIOTAP_LSIG;
1369 		break;
1370 	default:
1371 		break;
1372 	}
1373 }
1374 
1375 void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi,
1376 			struct iwl_rx_cmd_buffer *rxb, int queue)
1377 {
1378 	struct ieee80211_rx_status *rx_status;
1379 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
1380 	struct iwl_rx_mpdu_desc *desc = (void *)pkt->data;
1381 	struct ieee80211_hdr *hdr;
1382 	u32 len = le16_to_cpu(desc->mpdu_len);
1383 	u32 rate_n_flags, gp2_on_air_rise;
1384 	u16 phy_info = le16_to_cpu(desc->phy_info);
1385 	struct ieee80211_sta *sta = NULL;
1386 	struct sk_buff *skb;
1387 	u8 crypt_len = 0, channel, energy_a, energy_b;
1388 	size_t desc_size;
1389 	struct iwl_mvm_rx_phy_data phy_data = {
1390 		.d4 = desc->phy_data4,
1391 		.info_type = IWL_RX_PHY_INFO_TYPE_NONE,
1392 	};
1393 	bool csi = false;
1394 
1395 	if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
1396 		return;
1397 
1398 	if (mvm->trans->cfg->device_family >= IWL_DEVICE_FAMILY_22560) {
1399 		rate_n_flags = le32_to_cpu(desc->v3.rate_n_flags);
1400 		channel = desc->v3.channel;
1401 		gp2_on_air_rise = le32_to_cpu(desc->v3.gp2_on_air_rise);
1402 		energy_a = desc->v3.energy_a;
1403 		energy_b = desc->v3.energy_b;
1404 		desc_size = sizeof(*desc);
1405 
1406 		phy_data.d0 = desc->v3.phy_data0;
1407 		phy_data.d1 = desc->v3.phy_data1;
1408 		phy_data.d2 = desc->v3.phy_data2;
1409 		phy_data.d3 = desc->v3.phy_data3;
1410 	} else {
1411 		rate_n_flags = le32_to_cpu(desc->v1.rate_n_flags);
1412 		channel = desc->v1.channel;
1413 		gp2_on_air_rise = le32_to_cpu(desc->v1.gp2_on_air_rise);
1414 		energy_a = desc->v1.energy_a;
1415 		energy_b = desc->v1.energy_b;
1416 		desc_size = IWL_RX_DESC_SIZE_V1;
1417 
1418 		phy_data.d0 = desc->v1.phy_data0;
1419 		phy_data.d1 = desc->v1.phy_data1;
1420 		phy_data.d2 = desc->v1.phy_data2;
1421 		phy_data.d3 = desc->v1.phy_data3;
1422 	}
1423 
1424 	if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD)
1425 		phy_data.info_type =
1426 			le32_get_bits(phy_data.d1,
1427 				      IWL_RX_PHY_DATA1_INFO_TYPE_MASK);
1428 
1429 	hdr = (void *)(pkt->data + desc_size);
1430 	/* Dont use dev_alloc_skb(), we'll have enough headroom once
1431 	 * ieee80211_hdr pulled.
1432 	 */
1433 	skb = alloc_skb(128, GFP_ATOMIC);
1434 	if (!skb) {
1435 		IWL_ERR(mvm, "alloc_skb failed\n");
1436 		return;
1437 	}
1438 
1439 	if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) {
1440 		/*
1441 		 * If the device inserted padding it means that (it thought)
1442 		 * the 802.11 header wasn't a multiple of 4 bytes long. In
1443 		 * this case, reserve two bytes at the start of the SKB to
1444 		 * align the payload properly in case we end up copying it.
1445 		 */
1446 		skb_reserve(skb, 2);
1447 	}
1448 
1449 	rx_status = IEEE80211_SKB_RXCB(skb);
1450 
1451 	/* This may be overridden by iwl_mvm_rx_he() to HE_RU */
1452 	switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
1453 	case RATE_MCS_CHAN_WIDTH_20:
1454 		break;
1455 	case RATE_MCS_CHAN_WIDTH_40:
1456 		rx_status->bw = RATE_INFO_BW_40;
1457 		break;
1458 	case RATE_MCS_CHAN_WIDTH_80:
1459 		rx_status->bw = RATE_INFO_BW_80;
1460 		break;
1461 	case RATE_MCS_CHAN_WIDTH_160:
1462 		rx_status->bw = RATE_INFO_BW_160;
1463 		break;
1464 	}
1465 
1466 	if (rate_n_flags & RATE_MCS_HE_MSK)
1467 		iwl_mvm_rx_he(mvm, skb, &phy_data, rate_n_flags,
1468 			      phy_info, queue);
1469 
1470 	iwl_mvm_decode_lsig(skb, &phy_data);
1471 
1472 	rx_status = IEEE80211_SKB_RXCB(skb);
1473 
1474 	if (iwl_mvm_rx_crypto(mvm, hdr, rx_status, phy_info, desc,
1475 			      le32_to_cpu(pkt->len_n_flags), queue,
1476 			      &crypt_len)) {
1477 		kfree_skb(skb);
1478 		return;
1479 	}
1480 
1481 	/*
1482 	 * Keep packets with CRC errors (and with overrun) for monitor mode
1483 	 * (otherwise the firmware discards them) but mark them as bad.
1484 	 */
1485 	if (!(desc->status & cpu_to_le16(IWL_RX_MPDU_STATUS_CRC_OK)) ||
1486 	    !(desc->status & cpu_to_le16(IWL_RX_MPDU_STATUS_OVERRUN_OK))) {
1487 		IWL_DEBUG_RX(mvm, "Bad CRC or FIFO: 0x%08X.\n",
1488 			     le16_to_cpu(desc->status));
1489 		rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
1490 	}
1491 	/* set the preamble flag if appropriate */
1492 	if (rate_n_flags & RATE_MCS_CCK_MSK &&
1493 	    phy_info & IWL_RX_MPDU_PHY_SHORT_PREAMBLE)
1494 		rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE;
1495 
1496 	if (likely(!(phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD))) {
1497 		u64 tsf_on_air_rise;
1498 
1499 		if (mvm->trans->cfg->device_family >= IWL_DEVICE_FAMILY_22560)
1500 			tsf_on_air_rise = le64_to_cpu(desc->v3.tsf_on_air_rise);
1501 		else
1502 			tsf_on_air_rise = le64_to_cpu(desc->v1.tsf_on_air_rise);
1503 
1504 		rx_status->mactime = tsf_on_air_rise;
1505 		/* TSF as indicated by the firmware is at INA time */
1506 		rx_status->flag |= RX_FLAG_MACTIME_PLCP_START;
1507 	}
1508 
1509 	rx_status->device_timestamp = gp2_on_air_rise;
1510 	rx_status->band = channel > 14 ? NL80211_BAND_5GHZ :
1511 		NL80211_BAND_2GHZ;
1512 	rx_status->freq = ieee80211_channel_to_frequency(channel,
1513 							 rx_status->band);
1514 	iwl_mvm_get_signal_strength(mvm, rx_status, rate_n_flags, energy_a,
1515 				    energy_b);
1516 
1517 	/* update aggregation data for monitor sake on default queue */
1518 	if (!queue && (phy_info & IWL_RX_MPDU_PHY_AMPDU)) {
1519 		bool toggle_bit = phy_info & IWL_RX_MPDU_PHY_AMPDU_TOGGLE;
1520 
1521 		rx_status->flag |= RX_FLAG_AMPDU_DETAILS;
1522 		/*
1523 		 * Toggle is switched whenever new aggregation starts. Make
1524 		 * sure ampdu_reference is never 0 so we can later use it to
1525 		 * see if the frame was really part of an A-MPDU or not.
1526 		 */
1527 		if (toggle_bit != mvm->ampdu_toggle) {
1528 			mvm->ampdu_ref++;
1529 			if (mvm->ampdu_ref == 0)
1530 				mvm->ampdu_ref++;
1531 			mvm->ampdu_toggle = toggle_bit;
1532 		}
1533 		rx_status->ampdu_reference = mvm->ampdu_ref;
1534 	}
1535 
1536 	if (unlikely(mvm->monitor_on))
1537 		iwl_mvm_add_rtap_sniffer_config(mvm, skb);
1538 
1539 	rcu_read_lock();
1540 
1541 	if (desc->status & cpu_to_le16(IWL_RX_MPDU_STATUS_SRC_STA_FOUND)) {
1542 		u8 id = desc->sta_id_flags & IWL_RX_MPDU_SIF_STA_ID_MASK;
1543 
1544 		if (!WARN_ON_ONCE(id >= ARRAY_SIZE(mvm->fw_id_to_mac_id))) {
1545 			sta = rcu_dereference(mvm->fw_id_to_mac_id[id]);
1546 			if (IS_ERR(sta))
1547 				sta = NULL;
1548 		}
1549 	} else if (!is_multicast_ether_addr(hdr->addr2)) {
1550 		/*
1551 		 * This is fine since we prevent two stations with the same
1552 		 * address from being added.
1553 		 */
1554 		sta = ieee80211_find_sta_by_ifaddr(mvm->hw, hdr->addr2, NULL);
1555 	}
1556 
1557 	if (sta) {
1558 		struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1559 		struct ieee80211_vif *tx_blocked_vif =
1560 			rcu_dereference(mvm->csa_tx_blocked_vif);
1561 		u8 baid = (u8)((le32_to_cpu(desc->reorder_data) &
1562 			       IWL_RX_MPDU_REORDER_BAID_MASK) >>
1563 			       IWL_RX_MPDU_REORDER_BAID_SHIFT);
1564 		struct iwl_fw_dbg_trigger_tlv *trig;
1565 		struct ieee80211_vif *vif = mvmsta->vif;
1566 
1567 		if (!mvm->tcm.paused && len >= sizeof(*hdr) &&
1568 		    !is_multicast_ether_addr(hdr->addr1) &&
1569 		    ieee80211_is_data(hdr->frame_control) &&
1570 		    time_after(jiffies, mvm->tcm.ts + MVM_TCM_PERIOD))
1571 			schedule_delayed_work(&mvm->tcm.work, 0);
1572 
1573 		/*
1574 		 * We have tx blocked stations (with CS bit). If we heard
1575 		 * frames from a blocked station on a new channel we can
1576 		 * TX to it again.
1577 		 */
1578 		if (unlikely(tx_blocked_vif) && tx_blocked_vif == vif) {
1579 			struct iwl_mvm_vif *mvmvif =
1580 				iwl_mvm_vif_from_mac80211(tx_blocked_vif);
1581 
1582 			if (mvmvif->csa_target_freq == rx_status->freq)
1583 				iwl_mvm_sta_modify_disable_tx_ap(mvm, sta,
1584 								 false);
1585 		}
1586 
1587 		rs_update_last_rssi(mvm, mvmsta, rx_status);
1588 
1589 		trig = iwl_fw_dbg_trigger_on(&mvm->fwrt,
1590 					     ieee80211_vif_to_wdev(vif),
1591 					     FW_DBG_TRIGGER_RSSI);
1592 
1593 		if (trig && ieee80211_is_beacon(hdr->frame_control)) {
1594 			struct iwl_fw_dbg_trigger_low_rssi *rssi_trig;
1595 			s32 rssi;
1596 
1597 			rssi_trig = (void *)trig->data;
1598 			rssi = le32_to_cpu(rssi_trig->rssi);
1599 
1600 			if (rx_status->signal < rssi)
1601 				iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
1602 							NULL);
1603 		}
1604 
1605 		if (ieee80211_is_data(hdr->frame_control))
1606 			iwl_mvm_rx_csum(sta, skb, desc);
1607 
1608 		if (iwl_mvm_is_dup(sta, queue, rx_status, hdr, desc)) {
1609 			kfree_skb(skb);
1610 			goto out;
1611 		}
1612 
1613 		/*
1614 		 * Our hardware de-aggregates AMSDUs but copies the mac header
1615 		 * as it to the de-aggregated MPDUs. We need to turn off the
1616 		 * AMSDU bit in the QoS control ourselves.
1617 		 * In addition, HW reverses addr3 and addr4 - reverse it back.
1618 		 */
1619 		if ((desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU) &&
1620 		    !WARN_ON(!ieee80211_is_data_qos(hdr->frame_control))) {
1621 			u8 *qc = ieee80211_get_qos_ctl(hdr);
1622 
1623 			*qc &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT;
1624 
1625 			if (mvm->trans->cfg->device_family ==
1626 			    IWL_DEVICE_FAMILY_9000) {
1627 				iwl_mvm_flip_address(hdr->addr3);
1628 
1629 				if (ieee80211_has_a4(hdr->frame_control))
1630 					iwl_mvm_flip_address(hdr->addr4);
1631 			}
1632 		}
1633 		if (baid != IWL_RX_REORDER_DATA_INVALID_BAID) {
1634 			u32 reorder_data = le32_to_cpu(desc->reorder_data);
1635 
1636 			iwl_mvm_agg_rx_received(mvm, reorder_data, baid);
1637 		}
1638 	}
1639 
1640 	if (!(rate_n_flags & RATE_MCS_CCK_MSK) &&
1641 	    rate_n_flags & RATE_MCS_SGI_MSK)
1642 		rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
1643 	if (rate_n_flags & RATE_HT_MCS_GF_MSK)
1644 		rx_status->enc_flags |= RX_ENC_FLAG_HT_GF;
1645 	if (rate_n_flags & RATE_MCS_LDPC_MSK)
1646 		rx_status->enc_flags |= RX_ENC_FLAG_LDPC;
1647 	if (rate_n_flags & RATE_MCS_HT_MSK) {
1648 		u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
1649 				RATE_MCS_STBC_POS;
1650 		rx_status->encoding = RX_ENC_HT;
1651 		rx_status->rate_idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK;
1652 		rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
1653 	} else if (rate_n_flags & RATE_MCS_VHT_MSK) {
1654 		u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
1655 				RATE_MCS_STBC_POS;
1656 		rx_status->nss =
1657 			((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >>
1658 						RATE_VHT_MCS_NSS_POS) + 1;
1659 		rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK;
1660 		rx_status->encoding = RX_ENC_VHT;
1661 		rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
1662 		if (rate_n_flags & RATE_MCS_BF_MSK)
1663 			rx_status->enc_flags |= RX_ENC_FLAG_BF;
1664 	} else if (!(rate_n_flags & RATE_MCS_HE_MSK)) {
1665 		int rate = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags,
1666 							       rx_status->band);
1667 
1668 		if (WARN(rate < 0 || rate > 0xFF,
1669 			 "Invalid rate flags 0x%x, band %d,\n",
1670 			 rate_n_flags, rx_status->band)) {
1671 			kfree_skb(skb);
1672 			goto out;
1673 		}
1674 		rx_status->rate_idx = rate;
1675 	}
1676 
1677 	/* management stuff on default queue */
1678 	if (!queue) {
1679 		if (unlikely((ieee80211_is_beacon(hdr->frame_control) ||
1680 			      ieee80211_is_probe_resp(hdr->frame_control)) &&
1681 			     mvm->sched_scan_pass_all ==
1682 			     SCHED_SCAN_PASS_ALL_ENABLED))
1683 			mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_FOUND;
1684 
1685 		if (unlikely(ieee80211_is_beacon(hdr->frame_control) ||
1686 			     ieee80211_is_probe_resp(hdr->frame_control)))
1687 			rx_status->boottime_ns = ktime_get_boottime_ns();
1688 	}
1689 
1690 	if (iwl_mvm_create_skb(mvm, skb, hdr, len, crypt_len, rxb)) {
1691 		kfree_skb(skb);
1692 		goto out;
1693 	}
1694 
1695 	if (!iwl_mvm_reorder(mvm, napi, queue, sta, skb, desc))
1696 		iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb, queue,
1697 						sta, csi);
1698 out:
1699 	rcu_read_unlock();
1700 }
1701 
1702 void iwl_mvm_rx_monitor_no_data(struct iwl_mvm *mvm, struct napi_struct *napi,
1703 				struct iwl_rx_cmd_buffer *rxb, int queue)
1704 {
1705 	struct ieee80211_rx_status *rx_status;
1706 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
1707 	struct iwl_rx_no_data *desc = (void *)pkt->data;
1708 	u32 rate_n_flags = le32_to_cpu(desc->rate);
1709 	u32 gp2_on_air_rise = le32_to_cpu(desc->on_air_rise_time);
1710 	u32 rssi = le32_to_cpu(desc->rssi);
1711 	u32 info_type = le32_to_cpu(desc->info) & RX_NO_DATA_INFO_TYPE_MSK;
1712 	u16 phy_info = IWL_RX_MPDU_PHY_TSF_OVERLOAD;
1713 	struct ieee80211_sta *sta = NULL;
1714 	struct sk_buff *skb;
1715 	u8 channel, energy_a, energy_b;
1716 	struct iwl_mvm_rx_phy_data phy_data = {
1717 		.d0 = desc->phy_info[0],
1718 		.info_type = IWL_RX_PHY_INFO_TYPE_NONE,
1719 	};
1720 
1721 	if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
1722 		return;
1723 
1724 	energy_a = (rssi & RX_NO_DATA_CHAIN_A_MSK) >> RX_NO_DATA_CHAIN_A_POS;
1725 	energy_b = (rssi & RX_NO_DATA_CHAIN_B_MSK) >> RX_NO_DATA_CHAIN_B_POS;
1726 	channel = (rssi & RX_NO_DATA_CHANNEL_MSK) >> RX_NO_DATA_CHANNEL_POS;
1727 
1728 	phy_data.info_type =
1729 		le32_get_bits(desc->phy_info[1],
1730 			      IWL_RX_PHY_DATA1_INFO_TYPE_MASK);
1731 
1732 	/* Dont use dev_alloc_skb(), we'll have enough headroom once
1733 	 * ieee80211_hdr pulled.
1734 	 */
1735 	skb = alloc_skb(128, GFP_ATOMIC);
1736 	if (!skb) {
1737 		IWL_ERR(mvm, "alloc_skb failed\n");
1738 		return;
1739 	}
1740 
1741 	rx_status = IEEE80211_SKB_RXCB(skb);
1742 
1743 	/* 0-length PSDU */
1744 	rx_status->flag |= RX_FLAG_NO_PSDU;
1745 
1746 	switch (info_type) {
1747 	case RX_NO_DATA_INFO_TYPE_NDP:
1748 		rx_status->zero_length_psdu_type =
1749 			IEEE80211_RADIOTAP_ZERO_LEN_PSDU_SOUNDING;
1750 		break;
1751 	case RX_NO_DATA_INFO_TYPE_MU_UNMATCHED:
1752 	case RX_NO_DATA_INFO_TYPE_HE_TB_UNMATCHED:
1753 		rx_status->zero_length_psdu_type =
1754 			IEEE80211_RADIOTAP_ZERO_LEN_PSDU_NOT_CAPTURED;
1755 		break;
1756 	default:
1757 		rx_status->zero_length_psdu_type =
1758 			IEEE80211_RADIOTAP_ZERO_LEN_PSDU_VENDOR;
1759 		break;
1760 	}
1761 
1762 	/* This may be overridden by iwl_mvm_rx_he() to HE_RU */
1763 	switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
1764 	case RATE_MCS_CHAN_WIDTH_20:
1765 		break;
1766 	case RATE_MCS_CHAN_WIDTH_40:
1767 		rx_status->bw = RATE_INFO_BW_40;
1768 		break;
1769 	case RATE_MCS_CHAN_WIDTH_80:
1770 		rx_status->bw = RATE_INFO_BW_80;
1771 		break;
1772 	case RATE_MCS_CHAN_WIDTH_160:
1773 		rx_status->bw = RATE_INFO_BW_160;
1774 		break;
1775 	}
1776 
1777 	if (rate_n_flags & RATE_MCS_HE_MSK)
1778 		iwl_mvm_rx_he(mvm, skb, &phy_data, rate_n_flags,
1779 			      phy_info, queue);
1780 
1781 	iwl_mvm_decode_lsig(skb, &phy_data);
1782 
1783 	rx_status->device_timestamp = gp2_on_air_rise;
1784 	rx_status->band = channel > 14 ? NL80211_BAND_5GHZ :
1785 		NL80211_BAND_2GHZ;
1786 	rx_status->freq = ieee80211_channel_to_frequency(channel,
1787 							 rx_status->band);
1788 	iwl_mvm_get_signal_strength(mvm, rx_status, rate_n_flags, energy_a,
1789 				    energy_b);
1790 
1791 	rcu_read_lock();
1792 
1793 	if (!(rate_n_flags & RATE_MCS_CCK_MSK) &&
1794 	    rate_n_flags & RATE_MCS_SGI_MSK)
1795 		rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
1796 	if (rate_n_flags & RATE_HT_MCS_GF_MSK)
1797 		rx_status->enc_flags |= RX_ENC_FLAG_HT_GF;
1798 	if (rate_n_flags & RATE_MCS_LDPC_MSK)
1799 		rx_status->enc_flags |= RX_ENC_FLAG_LDPC;
1800 	if (rate_n_flags & RATE_MCS_HT_MSK) {
1801 		u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
1802 				RATE_MCS_STBC_POS;
1803 		rx_status->encoding = RX_ENC_HT;
1804 		rx_status->rate_idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK;
1805 		rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
1806 	} else if (rate_n_flags & RATE_MCS_VHT_MSK) {
1807 		u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
1808 				RATE_MCS_STBC_POS;
1809 		rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK;
1810 		rx_status->encoding = RX_ENC_VHT;
1811 		rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
1812 		if (rate_n_flags & RATE_MCS_BF_MSK)
1813 			rx_status->enc_flags |= RX_ENC_FLAG_BF;
1814 		/*
1815 		 * take the nss from the rx_vec since the rate_n_flags has
1816 		 * only 2 bits for the nss which gives a max of 4 ss but
1817 		 * there may be up to 8 spatial streams
1818 		 */
1819 		rx_status->nss =
1820 			le32_get_bits(desc->rx_vec[0],
1821 				      RX_NO_DATA_RX_VEC0_VHT_NSTS_MSK) + 1;
1822 	} else if (rate_n_flags & RATE_MCS_HE_MSK) {
1823 		rx_status->nss =
1824 			le32_get_bits(desc->rx_vec[0],
1825 				      RX_NO_DATA_RX_VEC0_HE_NSTS_MSK) + 1;
1826 	} else {
1827 		int rate = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags,
1828 							       rx_status->band);
1829 
1830 		if (WARN(rate < 0 || rate > 0xFF,
1831 			 "Invalid rate flags 0x%x, band %d,\n",
1832 			 rate_n_flags, rx_status->band)) {
1833 			kfree_skb(skb);
1834 			goto out;
1835 		}
1836 		rx_status->rate_idx = rate;
1837 	}
1838 
1839 	ieee80211_rx_napi(mvm->hw, sta, skb, napi);
1840 out:
1841 	rcu_read_unlock();
1842 }
1843 void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
1844 			      struct iwl_rx_cmd_buffer *rxb, int queue)
1845 {
1846 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
1847 	struct iwl_frame_release *release = (void *)pkt->data;
1848 	struct ieee80211_sta *sta;
1849 	struct iwl_mvm_reorder_buffer *reorder_buf;
1850 	struct iwl_mvm_baid_data *ba_data;
1851 
1852 	int baid = release->baid;
1853 
1854 	IWL_DEBUG_HT(mvm, "Frame release notification for BAID %u, NSSN %d\n",
1855 		     release->baid, le16_to_cpu(release->nssn));
1856 
1857 	if (WARN_ON_ONCE(baid == IWL_RX_REORDER_DATA_INVALID_BAID))
1858 		return;
1859 
1860 	rcu_read_lock();
1861 
1862 	ba_data = rcu_dereference(mvm->baid_map[baid]);
1863 	if (WARN_ON_ONCE(!ba_data))
1864 		goto out;
1865 
1866 	sta = rcu_dereference(mvm->fw_id_to_mac_id[ba_data->sta_id]);
1867 	if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
1868 		goto out;
1869 
1870 	reorder_buf = &ba_data->reorder_buf[queue];
1871 
1872 	spin_lock_bh(&reorder_buf->lock);
1873 	iwl_mvm_release_frames(mvm, sta, napi, ba_data, reorder_buf,
1874 			       le16_to_cpu(release->nssn));
1875 	spin_unlock_bh(&reorder_buf->lock);
1876 
1877 out:
1878 	rcu_read_unlock();
1879 }
1880