This source file includes following definitions.
- iwl_mvm_skb_get_hdr
- iwl_mvm_check_pn
- iwl_mvm_create_skb
- iwl_mvm_add_rtap_sniffer_config
- iwl_mvm_pass_packet_to_mac80211
- iwl_mvm_get_signal_strength
- iwl_mvm_rx_crypto
- iwl_mvm_rx_csum
- iwl_mvm_is_dup
- iwl_mvm_notify_rx_queue
- iwl_mvm_is_sn_less
- iwl_mvm_sync_nssn
- iwl_mvm_release_frames
- iwl_mvm_reorder_timer_expired
- iwl_mvm_del_ba
- iwl_mvm_release_frames_from_notif
- iwl_mvm_nssn_sync
- iwl_mvm_rx_queue_notif
- iwl_mvm_oldsn_workaround
- iwl_mvm_reorder
- iwl_mvm_agg_rx_received
- iwl_mvm_flip_address
- iwl_mvm_decode_he_mu_ext
- iwl_mvm_decode_he_phy_ru_alloc
- iwl_mvm_decode_he_phy_data
- iwl_mvm_rx_he
- iwl_mvm_decode_lsig
- iwl_mvm_rx_mpdu_mq
- iwl_mvm_rx_monitor_no_data
- iwl_mvm_rx_frame_release
- iwl_mvm_rx_bar_frame_release
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
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
108
109
110 if (!ieee80211_is_data(hdr->frame_control) ||
111 is_multicast_ether_addr(hdr->addr1))
112 return 0;
113
114
115 if (!(stats->flag & RX_FLAG_DECRYPTED))
116 return 0;
117
118
119
120
121
122
123 if (queue == 0)
124 return 0;
125
126
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
148 if (tid >= IWL_MAX_TID_COUNT)
149 return -1;
150
151
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
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
187
188
189
190
191
192
193
194
195
196
197
198 headlen = (len <= skb_tailroom(skb)) ? len :
199 hdrlen + crypt_len + 8;
200
201
202
203
204
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
213
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
248 BUILD_BUG_ON((size + 2) % 4);
249
250 radiotap = skb_put(skb, size + 2);
251 radiotap->align = 1;
252
253 radiotap->oui[0] = 0xf6;
254 radiotap->oui[1] = 0x54;
255 radiotap->oui[2] = 0x25;
256
257 radiotap->subns = 1;
258 radiotap->present = 0x1;
259 radiotap->len = size - sizeof(*radiotap);
260 radiotap->pad = 2;
261
262
263 memcpy(radiotap->data, &mvm->cur_aid, sizeof(mvm->cur_aid));
264
265 memset(radiotap->data + sizeof(__le16), 0, radiotap->pad);
266
267 rx_status->flag |= RX_FLAG_RADIOTAP_VENDOR_DATA;
268 }
269
270
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
315
316
317
318
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
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
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
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->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
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->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
381
382
383
384
385
386
387
388 if (!is_multicast_ether_addr(hdr->addr1) &&
389 !mvm->monitor_on && net_ratelimit())
390 IWL_ERR(mvm, "Unhandled alg: 0x%x\n", status);
391 }
392
393 return 0;
394 }
395
396 static void iwl_mvm_rx_csum(struct ieee80211_sta *sta,
397 struct sk_buff *skb,
398 struct iwl_rx_mpdu_desc *desc)
399 {
400 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
401 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(mvmsta->vif);
402 u16 flags = le16_to_cpu(desc->l3l4_flags);
403 u8 l3_prot = (u8)((flags & IWL_RX_L3L4_L3_PROTO_MASK) >>
404 IWL_RX_L3_PROTO_POS);
405
406 if (mvmvif->features & NETIF_F_RXCSUM &&
407 flags & IWL_RX_L3L4_TCP_UDP_CSUM_OK &&
408 (flags & IWL_RX_L3L4_IP_HDR_CSUM_OK ||
409 l3_prot == IWL_RX_L3_TYPE_IPV6 ||
410 l3_prot == IWL_RX_L3_TYPE_IPV6_FRAG))
411 skb->ip_summed = CHECKSUM_UNNECESSARY;
412 }
413
414
415
416
417
418 static bool iwl_mvm_is_dup(struct ieee80211_sta *sta, int queue,
419 struct ieee80211_rx_status *rx_status,
420 struct ieee80211_hdr *hdr,
421 struct iwl_rx_mpdu_desc *desc)
422 {
423 struct iwl_mvm_sta *mvm_sta;
424 struct iwl_mvm_rxq_dup_data *dup_data;
425 u8 tid, sub_frame_idx;
426
427 if (WARN_ON(IS_ERR_OR_NULL(sta)))
428 return false;
429
430 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
431 dup_data = &mvm_sta->dup_data[queue];
432
433
434
435
436
437 if (ieee80211_is_ctl(hdr->frame_control) ||
438 ieee80211_is_qos_nullfunc(hdr->frame_control) ||
439 is_multicast_ether_addr(hdr->addr1)) {
440 rx_status->flag |= RX_FLAG_DUP_VALIDATED;
441 return false;
442 }
443
444 if (ieee80211_is_data_qos(hdr->frame_control))
445
446 tid = ieee80211_get_tid(hdr);
447 else
448 tid = IWL_MAX_TID_COUNT;
449
450
451 sub_frame_idx = desc->amsdu_info &
452 IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK;
453
454 if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
455 dup_data->last_seq[tid] == hdr->seq_ctrl &&
456 dup_data->last_sub_frame[tid] >= sub_frame_idx))
457 return true;
458
459
460 if (dup_data->last_seq[tid] == hdr->seq_ctrl &&
461 sub_frame_idx > dup_data->last_sub_frame[tid] &&
462 desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU)
463 rx_status->flag |= RX_FLAG_ALLOW_SAME_PN;
464
465 dup_data->last_seq[tid] = hdr->seq_ctrl;
466 dup_data->last_sub_frame[tid] = sub_frame_idx;
467
468 rx_status->flag |= RX_FLAG_DUP_VALIDATED;
469
470 return false;
471 }
472
473 int iwl_mvm_notify_rx_queue(struct iwl_mvm *mvm, u32 rxq_mask,
474 const u8 *data, u32 count, bool async)
475 {
476 u8 buf[sizeof(struct iwl_rxq_sync_cmd) +
477 sizeof(struct iwl_mvm_rss_sync_notif)];
478 struct iwl_rxq_sync_cmd *cmd = (void *)buf;
479 u32 data_size = sizeof(*cmd) + count;
480 int ret;
481
482
483
484
485
486 if (WARN_ON(count & 3 ||
487 count > sizeof(struct iwl_mvm_rss_sync_notif)))
488 return -EINVAL;
489
490 cmd->rxq_mask = cpu_to_le32(rxq_mask);
491 cmd->count = cpu_to_le32(count);
492 cmd->flags = 0;
493 memcpy(cmd->payload, data, count);
494
495 ret = iwl_mvm_send_cmd_pdu(mvm,
496 WIDE_ID(DATA_PATH_GROUP,
497 TRIGGER_RX_QUEUES_NOTIF_CMD),
498 async ? CMD_ASYNC : 0, data_size, cmd);
499
500 return ret;
501 }
502
503
504
505
506
507
508
509 static bool iwl_mvm_is_sn_less(u16 sn1, u16 sn2, u16 buffer_size)
510 {
511 return ieee80211_sn_less(sn1, sn2) &&
512 !ieee80211_sn_less(sn1, sn2 - buffer_size);
513 }
514
515 static void iwl_mvm_sync_nssn(struct iwl_mvm *mvm, u8 baid, u16 nssn)
516 {
517 if (IWL_MVM_USE_NSSN_SYNC) {
518 struct iwl_mvm_rss_sync_notif notif = {
519 .metadata.type = IWL_MVM_RXQ_NSSN_SYNC,
520 .metadata.sync = 0,
521 .nssn_sync.baid = baid,
522 .nssn_sync.nssn = nssn,
523 };
524
525 iwl_mvm_sync_rx_queues_internal(mvm, (void *)¬if,
526 sizeof(notif));
527 }
528 }
529
530 #define RX_REORDER_BUF_TIMEOUT_MQ (HZ / 10)
531
532 enum iwl_mvm_release_flags {
533 IWL_MVM_RELEASE_SEND_RSS_SYNC = BIT(0),
534 IWL_MVM_RELEASE_FROM_RSS_SYNC = BIT(1),
535 };
536
537 static void iwl_mvm_release_frames(struct iwl_mvm *mvm,
538 struct ieee80211_sta *sta,
539 struct napi_struct *napi,
540 struct iwl_mvm_baid_data *baid_data,
541 struct iwl_mvm_reorder_buffer *reorder_buf,
542 u16 nssn, u32 flags)
543 {
544 struct iwl_mvm_reorder_buf_entry *entries =
545 &baid_data->entries[reorder_buf->queue *
546 baid_data->entries_per_queue];
547 u16 ssn = reorder_buf->head_sn;
548
549 lockdep_assert_held(&reorder_buf->lock);
550
551
552
553
554
555
556
557
558
559 if ((flags & IWL_MVM_RELEASE_FROM_RSS_SYNC) &&
560 ieee80211_sn_less(nssn, ssn))
561 goto set_timer;
562
563
564 if (iwl_mvm_is_sn_less(nssn, ssn, reorder_buf->buf_size))
565 goto set_timer;
566
567 while (iwl_mvm_is_sn_less(ssn, nssn, reorder_buf->buf_size)) {
568 int index = ssn % reorder_buf->buf_size;
569 struct sk_buff_head *skb_list = &entries[index].e.frames;
570 struct sk_buff *skb;
571
572 ssn = ieee80211_sn_inc(ssn);
573 if ((flags & IWL_MVM_RELEASE_SEND_RSS_SYNC) &&
574 (ssn == 2048 || ssn == 0))
575 iwl_mvm_sync_nssn(mvm, baid_data->baid, ssn);
576
577
578
579
580
581
582 while ((skb = __skb_dequeue(skb_list))) {
583 iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb,
584 reorder_buf->queue,
585 sta, false);
586 reorder_buf->num_stored--;
587 }
588 }
589 reorder_buf->head_sn = nssn;
590
591 set_timer:
592 if (reorder_buf->num_stored && !reorder_buf->removed) {
593 u16 index = reorder_buf->head_sn % reorder_buf->buf_size;
594
595 while (skb_queue_empty(&entries[index].e.frames))
596 index = (index + 1) % reorder_buf->buf_size;
597
598 mod_timer(&reorder_buf->reorder_timer,
599 entries[index].e.reorder_time + 1 +
600 RX_REORDER_BUF_TIMEOUT_MQ);
601 } else {
602 del_timer(&reorder_buf->reorder_timer);
603 }
604 }
605
606 void iwl_mvm_reorder_timer_expired(struct timer_list *t)
607 {
608 struct iwl_mvm_reorder_buffer *buf = from_timer(buf, t, reorder_timer);
609 struct iwl_mvm_baid_data *baid_data =
610 iwl_mvm_baid_data_from_reorder_buf(buf);
611 struct iwl_mvm_reorder_buf_entry *entries =
612 &baid_data->entries[buf->queue * baid_data->entries_per_queue];
613 int i;
614 u16 sn = 0, index = 0;
615 bool expired = false;
616 bool cont = false;
617
618 spin_lock(&buf->lock);
619
620 if (!buf->num_stored || buf->removed) {
621 spin_unlock(&buf->lock);
622 return;
623 }
624
625 for (i = 0; i < buf->buf_size ; i++) {
626 index = (buf->head_sn + i) % buf->buf_size;
627
628 if (skb_queue_empty(&entries[index].e.frames)) {
629
630
631
632
633 cont = false;
634 continue;
635 }
636 if (!cont &&
637 !time_after(jiffies, entries[index].e.reorder_time +
638 RX_REORDER_BUF_TIMEOUT_MQ))
639 break;
640
641 expired = true;
642
643 cont = true;
644 sn = ieee80211_sn_add(buf->head_sn, i + 1);
645 }
646
647 if (expired) {
648 struct ieee80211_sta *sta;
649 struct iwl_mvm_sta *mvmsta;
650 u8 sta_id = baid_data->sta_id;
651
652 rcu_read_lock();
653 sta = rcu_dereference(buf->mvm->fw_id_to_mac_id[sta_id]);
654 mvmsta = iwl_mvm_sta_from_mac80211(sta);
655
656
657 IWL_DEBUG_HT(buf->mvm,
658 "Releasing expired frames for sta %u, sn %d\n",
659 sta_id, sn);
660 iwl_mvm_event_frame_timeout_callback(buf->mvm, mvmsta->vif,
661 sta, baid_data->tid);
662 iwl_mvm_release_frames(buf->mvm, sta, NULL, baid_data,
663 buf, sn, IWL_MVM_RELEASE_SEND_RSS_SYNC);
664 rcu_read_unlock();
665 } else {
666
667
668
669
670
671 mod_timer(&buf->reorder_timer,
672 entries[index].e.reorder_time +
673 1 + RX_REORDER_BUF_TIMEOUT_MQ);
674 }
675 spin_unlock(&buf->lock);
676 }
677
678 static void iwl_mvm_del_ba(struct iwl_mvm *mvm, int queue,
679 struct iwl_mvm_delba_data *data)
680 {
681 struct iwl_mvm_baid_data *ba_data;
682 struct ieee80211_sta *sta;
683 struct iwl_mvm_reorder_buffer *reorder_buf;
684 u8 baid = data->baid;
685
686 if (WARN_ONCE(baid >= IWL_MAX_BAID, "invalid BAID: %x\n", baid))
687 return;
688
689 rcu_read_lock();
690
691 ba_data = rcu_dereference(mvm->baid_map[baid]);
692 if (WARN_ON_ONCE(!ba_data))
693 goto out;
694
695 sta = rcu_dereference(mvm->fw_id_to_mac_id[ba_data->sta_id]);
696 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
697 goto out;
698
699 reorder_buf = &ba_data->reorder_buf[queue];
700
701
702 spin_lock_bh(&reorder_buf->lock);
703 iwl_mvm_release_frames(mvm, sta, NULL, ba_data, reorder_buf,
704 ieee80211_sn_add(reorder_buf->head_sn,
705 reorder_buf->buf_size),
706 0);
707 spin_unlock_bh(&reorder_buf->lock);
708 del_timer_sync(&reorder_buf->reorder_timer);
709
710 out:
711 rcu_read_unlock();
712 }
713
714 static void iwl_mvm_release_frames_from_notif(struct iwl_mvm *mvm,
715 struct napi_struct *napi,
716 u8 baid, u16 nssn, int queue,
717 u32 flags)
718 {
719 struct ieee80211_sta *sta;
720 struct iwl_mvm_reorder_buffer *reorder_buf;
721 struct iwl_mvm_baid_data *ba_data;
722
723 IWL_DEBUG_HT(mvm, "Frame release notification for BAID %u, NSSN %d\n",
724 baid, nssn);
725
726 if (WARN_ON_ONCE(baid == IWL_RX_REORDER_DATA_INVALID_BAID ||
727 baid >= ARRAY_SIZE(mvm->baid_map)))
728 return;
729
730 rcu_read_lock();
731
732 ba_data = rcu_dereference(mvm->baid_map[baid]);
733 if (WARN_ON_ONCE(!ba_data))
734 goto out;
735
736 sta = rcu_dereference(mvm->fw_id_to_mac_id[ba_data->sta_id]);
737 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
738 goto out;
739
740 reorder_buf = &ba_data->reorder_buf[queue];
741
742 spin_lock_bh(&reorder_buf->lock);
743 iwl_mvm_release_frames(mvm, sta, napi, ba_data,
744 reorder_buf, nssn, flags);
745 spin_unlock_bh(&reorder_buf->lock);
746
747 out:
748 rcu_read_unlock();
749 }
750
751 static void iwl_mvm_nssn_sync(struct iwl_mvm *mvm,
752 struct napi_struct *napi, int queue,
753 const struct iwl_mvm_nssn_sync_data *data)
754 {
755 iwl_mvm_release_frames_from_notif(mvm, napi, data->baid,
756 data->nssn, queue,
757 IWL_MVM_RELEASE_FROM_RSS_SYNC);
758 }
759
760 void iwl_mvm_rx_queue_notif(struct iwl_mvm *mvm, struct napi_struct *napi,
761 struct iwl_rx_cmd_buffer *rxb, int queue)
762 {
763 struct iwl_rx_packet *pkt = rxb_addr(rxb);
764 struct iwl_rxq_sync_notification *notif;
765 struct iwl_mvm_internal_rxq_notif *internal_notif;
766
767 notif = (void *)pkt->data;
768 internal_notif = (void *)notif->payload;
769
770 if (internal_notif->sync &&
771 mvm->queue_sync_cookie != internal_notif->cookie) {
772 WARN_ONCE(1, "Received expired RX queue sync message\n");
773 return;
774 }
775
776 switch (internal_notif->type) {
777 case IWL_MVM_RXQ_EMPTY:
778 break;
779 case IWL_MVM_RXQ_NOTIF_DEL_BA:
780 iwl_mvm_del_ba(mvm, queue, (void *)internal_notif->data);
781 break;
782 case IWL_MVM_RXQ_NSSN_SYNC:
783 iwl_mvm_nssn_sync(mvm, napi, queue,
784 (void *)internal_notif->data);
785 break;
786 default:
787 WARN_ONCE(1, "Invalid identifier %d", internal_notif->type);
788 }
789
790 if (internal_notif->sync &&
791 !atomic_dec_return(&mvm->queue_sync_counter))
792 wake_up(&mvm->rx_sync_waitq);
793 }
794
795 static void iwl_mvm_oldsn_workaround(struct iwl_mvm *mvm,
796 struct ieee80211_sta *sta, int tid,
797 struct iwl_mvm_reorder_buffer *buffer,
798 u32 reorder, u32 gp2, int queue)
799 {
800 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
801
802 if (gp2 != buffer->consec_oldsn_ampdu_gp2) {
803
804
805
806
807
808
809 if (!buffer->consec_oldsn_prev_drop)
810 buffer->consec_oldsn_drops = 0;
811
812
813 buffer->consec_oldsn_ampdu_gp2 = gp2;
814 } else if (buffer->consec_oldsn_prev_drop) {
815
816
817
818
819
820
821 return;
822 }
823
824
825 if (!(reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN))
826 return;
827
828
829 buffer->consec_oldsn_prev_drop = 1;
830 buffer->consec_oldsn_drops++;
831
832
833 if (buffer->consec_oldsn_drops == IWL_MVM_AMPDU_CONSEC_DROPS_DELBA) {
834 IWL_WARN(mvm,
835 "reached %d old SN frames from %pM on queue %d, stopping BA session on TID %d\n",
836 IWL_MVM_AMPDU_CONSEC_DROPS_DELBA,
837 sta->addr, queue, tid);
838 ieee80211_stop_rx_ba_session(mvmsta->vif, BIT(tid), sta->addr);
839 buffer->consec_oldsn_prev_drop = 0;
840 buffer->consec_oldsn_drops = 0;
841 }
842 }
843
844
845
846
847
848 static bool iwl_mvm_reorder(struct iwl_mvm *mvm,
849 struct napi_struct *napi,
850 int queue,
851 struct ieee80211_sta *sta,
852 struct sk_buff *skb,
853 struct iwl_rx_mpdu_desc *desc)
854 {
855 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
856 struct ieee80211_hdr *hdr = iwl_mvm_skb_get_hdr(skb);
857 struct iwl_mvm_sta *mvm_sta;
858 struct iwl_mvm_baid_data *baid_data;
859 struct iwl_mvm_reorder_buffer *buffer;
860 struct sk_buff *tail;
861 u32 reorder = le32_to_cpu(desc->reorder_data);
862 bool amsdu = desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU;
863 bool last_subframe =
864 desc->amsdu_info & IWL_RX_MPDU_AMSDU_LAST_SUBFRAME;
865 u8 tid = ieee80211_get_tid(hdr);
866 u8 sub_frame_idx = desc->amsdu_info &
867 IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK;
868 struct iwl_mvm_reorder_buf_entry *entries;
869 int index;
870 u16 nssn, sn;
871 u8 baid;
872
873 baid = (reorder & IWL_RX_MPDU_REORDER_BAID_MASK) >>
874 IWL_RX_MPDU_REORDER_BAID_SHIFT;
875
876
877
878
879
880
881
882
883 if (baid == IWL_RX_REORDER_DATA_INVALID_BAID)
884 return false;
885
886
887 if (WARN_ONCE(IS_ERR_OR_NULL(sta),
888 "Got valid BAID without a valid station assigned\n"))
889 return false;
890
891 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
892
893
894 if (!ieee80211_is_back_req(hdr->frame_control) &&
895 (!ieee80211_is_data_qos(hdr->frame_control) ||
896 is_multicast_ether_addr(hdr->addr1)))
897 return false;
898
899 if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
900 return false;
901
902 baid_data = rcu_dereference(mvm->baid_map[baid]);
903 if (!baid_data) {
904 IWL_DEBUG_RX(mvm,
905 "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n",
906 baid, reorder);
907 return false;
908 }
909
910 if (WARN(tid != baid_data->tid || mvm_sta->sta_id != baid_data->sta_id,
911 "baid 0x%x is mapped to sta:%d tid:%d, but was received for sta:%d tid:%d\n",
912 baid, baid_data->sta_id, baid_data->tid, mvm_sta->sta_id,
913 tid))
914 return false;
915
916 nssn = reorder & IWL_RX_MPDU_REORDER_NSSN_MASK;
917 sn = (reorder & IWL_RX_MPDU_REORDER_SN_MASK) >>
918 IWL_RX_MPDU_REORDER_SN_SHIFT;
919
920 buffer = &baid_data->reorder_buf[queue];
921 entries = &baid_data->entries[queue * baid_data->entries_per_queue];
922
923 spin_lock_bh(&buffer->lock);
924
925 if (!buffer->valid) {
926 if (reorder & IWL_RX_MPDU_REORDER_BA_OLD_SN) {
927 spin_unlock_bh(&buffer->lock);
928 return false;
929 }
930 buffer->valid = true;
931 }
932
933 if (ieee80211_is_back_req(hdr->frame_control)) {
934 iwl_mvm_release_frames(mvm, sta, napi, baid_data,
935 buffer, nssn, 0);
936 goto drop;
937 }
938
939
940
941
942
943
944
945
946
947
948
949 if (!iwl_mvm_is_sn_less(nssn, buffer->head_sn + buffer->buf_size,
950 buffer->buf_size) ||
951 !ieee80211_sn_less(sn, buffer->head_sn + buffer->buf_size)) {
952 u16 min_sn = ieee80211_sn_less(sn, nssn) ? sn : nssn;
953
954 iwl_mvm_release_frames(mvm, sta, napi, baid_data, buffer,
955 min_sn, IWL_MVM_RELEASE_SEND_RSS_SYNC);
956 }
957
958 iwl_mvm_oldsn_workaround(mvm, sta, tid, buffer, reorder,
959 rx_status->device_timestamp, queue);
960
961
962 if (ieee80211_sn_less(sn, buffer->head_sn))
963 goto drop;
964
965
966 if (!buffer->num_stored && ieee80211_sn_less(sn, nssn)) {
967 if (iwl_mvm_is_sn_less(buffer->head_sn, nssn,
968 buffer->buf_size) &&
969 (!amsdu || last_subframe)) {
970
971
972
973
974
975
976
977
978
979
980
981
982 if (sn == 2048 || sn == 0)
983 iwl_mvm_sync_nssn(mvm, baid, sn);
984 buffer->head_sn = nssn;
985 }
986
987 spin_unlock_bh(&buffer->lock);
988 return false;
989 }
990
991
992
993
994
995
996
997
998
999 if (!buffer->num_stored && sn == buffer->head_sn) {
1000 if (!amsdu || last_subframe) {
1001 if (sn == 2048 || sn == 0)
1002 iwl_mvm_sync_nssn(mvm, baid, sn);
1003 buffer->head_sn = ieee80211_sn_inc(buffer->head_sn);
1004 }
1005
1006 spin_unlock_bh(&buffer->lock);
1007 return false;
1008 }
1009
1010 index = sn % buffer->buf_size;
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020 tail = skb_peek_tail(&entries[index].e.frames);
1021 if (tail && !amsdu)
1022 goto drop;
1023 else if (tail && (sn != buffer->last_amsdu ||
1024 buffer->last_sub_index >= sub_frame_idx))
1025 goto drop;
1026
1027
1028 __skb_queue_tail(&entries[index].e.frames, skb);
1029 buffer->num_stored++;
1030 entries[index].e.reorder_time = jiffies;
1031
1032 if (amsdu) {
1033 buffer->last_amsdu = sn;
1034 buffer->last_sub_index = sub_frame_idx;
1035 }
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048 if (!amsdu || last_subframe)
1049 iwl_mvm_release_frames(mvm, sta, napi, baid_data,
1050 buffer, nssn,
1051 IWL_MVM_RELEASE_SEND_RSS_SYNC);
1052
1053 spin_unlock_bh(&buffer->lock);
1054 return true;
1055
1056 drop:
1057 kfree_skb(skb);
1058 spin_unlock_bh(&buffer->lock);
1059 return true;
1060 }
1061
1062 static void iwl_mvm_agg_rx_received(struct iwl_mvm *mvm,
1063 u32 reorder_data, u8 baid)
1064 {
1065 unsigned long now = jiffies;
1066 unsigned long timeout;
1067 struct iwl_mvm_baid_data *data;
1068
1069 rcu_read_lock();
1070
1071 data = rcu_dereference(mvm->baid_map[baid]);
1072 if (!data) {
1073 IWL_DEBUG_RX(mvm,
1074 "Got valid BAID but no baid allocated, bypass the re-ordering buffer. Baid %d reorder 0x%x\n",
1075 baid, reorder_data);
1076 goto out;
1077 }
1078
1079 if (!data->timeout)
1080 goto out;
1081
1082 timeout = data->timeout;
1083
1084
1085
1086
1087
1088
1089 if (time_before(data->last_rx + TU_TO_JIFFIES(timeout), now))
1090
1091 data->last_rx = now;
1092
1093 out:
1094 rcu_read_unlock();
1095 }
1096
1097 static void iwl_mvm_flip_address(u8 *addr)
1098 {
1099 int i;
1100 u8 mac_addr[ETH_ALEN];
1101
1102 for (i = 0; i < ETH_ALEN; i++)
1103 mac_addr[i] = addr[ETH_ALEN - i - 1];
1104 ether_addr_copy(addr, mac_addr);
1105 }
1106
1107 struct iwl_mvm_rx_phy_data {
1108 enum iwl_rx_phy_info_type info_type;
1109 __le32 d0, d1, d2, d3;
1110 __le16 d4;
1111 };
1112
1113 static void iwl_mvm_decode_he_mu_ext(struct iwl_mvm *mvm,
1114 struct iwl_mvm_rx_phy_data *phy_data,
1115 u32 rate_n_flags,
1116 struct ieee80211_radiotap_he_mu *he_mu)
1117 {
1118 u32 phy_data2 = le32_to_cpu(phy_data->d2);
1119 u32 phy_data3 = le32_to_cpu(phy_data->d3);
1120 u16 phy_data4 = le16_to_cpu(phy_data->d4);
1121
1122 if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CRC_OK, phy_data4)) {
1123 he_mu->flags1 |=
1124 cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_RU_KNOWN |
1125 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU_KNOWN);
1126
1127 he_mu->flags1 |=
1128 le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH1_CTR_RU,
1129 phy_data4),
1130 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH1_CTR_26T_RU);
1131
1132 he_mu->ru_ch1[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU0,
1133 phy_data2);
1134 he_mu->ru_ch1[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU1,
1135 phy_data3);
1136 he_mu->ru_ch1[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH1_RU2,
1137 phy_data2);
1138 he_mu->ru_ch1[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH1_RU3,
1139 phy_data3);
1140 }
1141
1142 if (FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CRC_OK, phy_data4) &&
1143 (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) != RATE_MCS_CHAN_WIDTH_20) {
1144 he_mu->flags1 |=
1145 cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_RU_KNOWN |
1146 IEEE80211_RADIOTAP_HE_MU_FLAGS1_CH2_CTR_26T_RU_KNOWN);
1147
1148 he_mu->flags2 |=
1149 le16_encode_bits(FIELD_GET(IWL_RX_PHY_DATA4_HE_MU_EXT_CH2_CTR_RU,
1150 phy_data4),
1151 IEEE80211_RADIOTAP_HE_MU_FLAGS2_CH2_CTR_26T_RU);
1152
1153 he_mu->ru_ch2[0] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU0,
1154 phy_data2);
1155 he_mu->ru_ch2[1] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU1,
1156 phy_data3);
1157 he_mu->ru_ch2[2] = FIELD_GET(IWL_RX_PHY_DATA2_HE_MU_EXT_CH2_RU2,
1158 phy_data2);
1159 he_mu->ru_ch2[3] = FIELD_GET(IWL_RX_PHY_DATA3_HE_MU_EXT_CH2_RU3,
1160 phy_data3);
1161 }
1162 }
1163
1164 static void
1165 iwl_mvm_decode_he_phy_ru_alloc(struct iwl_mvm_rx_phy_data *phy_data,
1166 u32 rate_n_flags,
1167 struct ieee80211_radiotap_he *he,
1168 struct ieee80211_radiotap_he_mu *he_mu,
1169 struct ieee80211_rx_status *rx_status)
1170 {
1171
1172
1173
1174
1175
1176
1177
1178
1179 u8 ru = le32_get_bits(phy_data->d1, IWL_RX_PHY_DATA1_HE_RU_ALLOC_MASK);
1180 u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK;
1181 u8 offs = 0;
1182
1183 rx_status->bw = RATE_INFO_BW_HE_RU;
1184
1185 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN);
1186
1187 switch (ru) {
1188 case 0 ... 36:
1189 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_26;
1190 offs = ru;
1191 break;
1192 case 37 ... 52:
1193 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_52;
1194 offs = ru - 37;
1195 break;
1196 case 53 ... 60:
1197 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106;
1198 offs = ru - 53;
1199 break;
1200 case 61 ... 64:
1201 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_242;
1202 offs = ru - 61;
1203 break;
1204 case 65 ... 66:
1205 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_484;
1206 offs = ru - 65;
1207 break;
1208 case 67:
1209 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_996;
1210 break;
1211 case 68:
1212 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_2x996;
1213 break;
1214 }
1215 he->data2 |= le16_encode_bits(offs,
1216 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET);
1217 he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_KNOWN |
1218 IEEE80211_RADIOTAP_HE_DATA2_RU_OFFSET_KNOWN);
1219 if (phy_data->d1 & cpu_to_le32(IWL_RX_PHY_DATA1_HE_RU_ALLOC_SEC80))
1220 he->data2 |=
1221 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRISEC_80_SEC);
1222
1223 #define CHECK_BW(bw) \
1224 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_ ## bw ## MHZ != \
1225 RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS); \
1226 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_ ## bw ## MHZ != \
1227 RATE_MCS_CHAN_WIDTH_##bw >> RATE_MCS_CHAN_WIDTH_POS)
1228 CHECK_BW(20);
1229 CHECK_BW(40);
1230 CHECK_BW(80);
1231 CHECK_BW(160);
1232
1233 if (he_mu)
1234 he_mu->flags2 |=
1235 le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK,
1236 rate_n_flags),
1237 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW);
1238 else if (he_type == RATE_MCS_HE_TYPE_TRIG)
1239 he->data6 |=
1240 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW_KNOWN) |
1241 le16_encode_bits(FIELD_GET(RATE_MCS_CHAN_WIDTH_MSK,
1242 rate_n_flags),
1243 IEEE80211_RADIOTAP_HE_DATA6_TB_PPDU_BW);
1244 }
1245
1246 static void iwl_mvm_decode_he_phy_data(struct iwl_mvm *mvm,
1247 struct iwl_mvm_rx_phy_data *phy_data,
1248 struct ieee80211_radiotap_he *he,
1249 struct ieee80211_radiotap_he_mu *he_mu,
1250 struct ieee80211_rx_status *rx_status,
1251 u32 rate_n_flags, int queue)
1252 {
1253 switch (phy_data->info_type) {
1254 case IWL_RX_PHY_INFO_TYPE_NONE:
1255 case IWL_RX_PHY_INFO_TYPE_CCK:
1256 case IWL_RX_PHY_INFO_TYPE_OFDM_LGCY:
1257 case IWL_RX_PHY_INFO_TYPE_HT:
1258 case IWL_RX_PHY_INFO_TYPE_VHT_SU:
1259 case IWL_RX_PHY_INFO_TYPE_VHT_MU:
1260 return;
1261 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT:
1262 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN |
1263 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE2_KNOWN |
1264 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE3_KNOWN |
1265 IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE4_KNOWN);
1266 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1267 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE1),
1268 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE1);
1269 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1270 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE2),
1271 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE2);
1272 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1273 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE3),
1274 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE3);
1275 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d2,
1276 IWL_RX_PHY_DATA2_HE_TB_EXT_SPTL_REUSE4),
1277 IEEE80211_RADIOTAP_HE_DATA4_TB_SPTL_REUSE4);
1278
1279 case IWL_RX_PHY_INFO_TYPE_HE_SU:
1280 case IWL_RX_PHY_INFO_TYPE_HE_MU:
1281 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
1282 case IWL_RX_PHY_INFO_TYPE_HE_TB:
1283
1284 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_LDPC_XSYMSEG_KNOWN |
1285 IEEE80211_RADIOTAP_HE_DATA1_DOPPLER_KNOWN |
1286 IEEE80211_RADIOTAP_HE_DATA1_BSS_COLOR_KNOWN);
1287 he->data2 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_PRE_FEC_PAD_KNOWN |
1288 IEEE80211_RADIOTAP_HE_DATA2_PE_DISAMBIG_KNOWN |
1289 IEEE80211_RADIOTAP_HE_DATA2_TXOP_KNOWN |
1290 IEEE80211_RADIOTAP_HE_DATA2_NUM_LTF_SYMS_KNOWN);
1291 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1292 IWL_RX_PHY_DATA0_HE_BSS_COLOR_MASK),
1293 IEEE80211_RADIOTAP_HE_DATA3_BSS_COLOR);
1294 if (phy_data->info_type != IWL_RX_PHY_INFO_TYPE_HE_TB &&
1295 phy_data->info_type != IWL_RX_PHY_INFO_TYPE_HE_TB_EXT) {
1296 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_UL_DL_KNOWN);
1297 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1298 IWL_RX_PHY_DATA0_HE_UPLINK),
1299 IEEE80211_RADIOTAP_HE_DATA3_UL_DL);
1300 }
1301 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1302 IWL_RX_PHY_DATA0_HE_LDPC_EXT_SYM),
1303 IEEE80211_RADIOTAP_HE_DATA3_LDPC_XSYMSEG);
1304 he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1305 IWL_RX_PHY_DATA0_HE_PRE_FEC_PAD_MASK),
1306 IEEE80211_RADIOTAP_HE_DATA5_PRE_FEC_PAD);
1307 he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1308 IWL_RX_PHY_DATA0_HE_PE_DISAMBIG),
1309 IEEE80211_RADIOTAP_HE_DATA5_PE_DISAMBIG);
1310 he->data5 |= le16_encode_bits(le32_get_bits(phy_data->d1,
1311 IWL_RX_PHY_DATA1_HE_LTF_NUM_MASK),
1312 IEEE80211_RADIOTAP_HE_DATA5_NUM_LTF_SYMS);
1313 he->data6 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1314 IWL_RX_PHY_DATA0_HE_TXOP_DUR_MASK),
1315 IEEE80211_RADIOTAP_HE_DATA6_TXOP);
1316 he->data6 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1317 IWL_RX_PHY_DATA0_HE_DOPPLER),
1318 IEEE80211_RADIOTAP_HE_DATA6_DOPPLER);
1319 break;
1320 }
1321
1322 switch (phy_data->info_type) {
1323 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
1324 case IWL_RX_PHY_INFO_TYPE_HE_MU:
1325 case IWL_RX_PHY_INFO_TYPE_HE_SU:
1326 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_SPTL_REUSE_KNOWN);
1327 he->data4 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1328 IWL_RX_PHY_DATA0_HE_SPATIAL_REUSE_MASK),
1329 IEEE80211_RADIOTAP_HE_DATA4_SU_MU_SPTL_REUSE);
1330 break;
1331 default:
1332
1333 break;
1334 }
1335
1336 switch (phy_data->info_type) {
1337 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
1338 he_mu->flags1 |=
1339 le16_encode_bits(le16_get_bits(phy_data->d4,
1340 IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_DCM),
1341 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM);
1342 he_mu->flags1 |=
1343 le16_encode_bits(le16_get_bits(phy_data->d4,
1344 IWL_RX_PHY_DATA4_HE_MU_EXT_SIGB_MCS_MASK),
1345 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS);
1346 he_mu->flags2 |=
1347 le16_encode_bits(le16_get_bits(phy_data->d4,
1348 IWL_RX_PHY_DATA4_HE_MU_EXT_PREAMBLE_PUNC_TYPE_MASK),
1349 IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW);
1350 iwl_mvm_decode_he_mu_ext(mvm, phy_data, rate_n_flags, he_mu);
1351
1352 case IWL_RX_PHY_INFO_TYPE_HE_MU:
1353 he_mu->flags2 |=
1354 le16_encode_bits(le32_get_bits(phy_data->d1,
1355 IWL_RX_PHY_DATA1_HE_MU_SIBG_SYM_OR_USER_NUM_MASK),
1356 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_SYMS_USERS);
1357 he_mu->flags2 |=
1358 le16_encode_bits(le32_get_bits(phy_data->d1,
1359 IWL_RX_PHY_DATA1_HE_MU_SIGB_COMPRESSION),
1360 IEEE80211_RADIOTAP_HE_MU_FLAGS2_SIG_B_COMP);
1361
1362 case IWL_RX_PHY_INFO_TYPE_HE_TB:
1363 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT:
1364 iwl_mvm_decode_he_phy_ru_alloc(phy_data, rate_n_flags,
1365 he, he_mu, rx_status);
1366 break;
1367 case IWL_RX_PHY_INFO_TYPE_HE_SU:
1368 he->data1 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BEAM_CHANGE_KNOWN);
1369 he->data3 |= le16_encode_bits(le32_get_bits(phy_data->d0,
1370 IWL_RX_PHY_DATA0_HE_BEAM_CHNG),
1371 IEEE80211_RADIOTAP_HE_DATA3_BEAM_CHANGE);
1372 break;
1373 default:
1374
1375 break;
1376 }
1377 }
1378
1379 static void iwl_mvm_rx_he(struct iwl_mvm *mvm, struct sk_buff *skb,
1380 struct iwl_mvm_rx_phy_data *phy_data,
1381 u32 rate_n_flags, u16 phy_info, int queue)
1382 {
1383 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
1384 struct ieee80211_radiotap_he *he = NULL;
1385 struct ieee80211_radiotap_he_mu *he_mu = NULL;
1386 u32 he_type = rate_n_flags & RATE_MCS_HE_TYPE_MSK;
1387 u8 stbc, ltf;
1388 static const struct ieee80211_radiotap_he known = {
1389 .data1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_DATA_MCS_KNOWN |
1390 IEEE80211_RADIOTAP_HE_DATA1_DATA_DCM_KNOWN |
1391 IEEE80211_RADIOTAP_HE_DATA1_STBC_KNOWN |
1392 IEEE80211_RADIOTAP_HE_DATA1_CODING_KNOWN),
1393 .data2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA2_GI_KNOWN |
1394 IEEE80211_RADIOTAP_HE_DATA2_TXBF_KNOWN),
1395 };
1396 static const struct ieee80211_radiotap_he_mu mu_known = {
1397 .flags1 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_MCS_KNOWN |
1398 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_DCM_KNOWN |
1399 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_SYMS_USERS_KNOWN |
1400 IEEE80211_RADIOTAP_HE_MU_FLAGS1_SIG_B_COMP_KNOWN),
1401 .flags2 = cpu_to_le16(IEEE80211_RADIOTAP_HE_MU_FLAGS2_PUNC_FROM_SIG_A_BW_KNOWN |
1402 IEEE80211_RADIOTAP_HE_MU_FLAGS2_BW_FROM_SIG_A_BW_KNOWN),
1403 };
1404
1405 he = skb_put_data(skb, &known, sizeof(known));
1406 rx_status->flag |= RX_FLAG_RADIOTAP_HE;
1407
1408 if (phy_data->info_type == IWL_RX_PHY_INFO_TYPE_HE_MU ||
1409 phy_data->info_type == IWL_RX_PHY_INFO_TYPE_HE_MU_EXT) {
1410 he_mu = skb_put_data(skb, &mu_known, sizeof(mu_known));
1411 rx_status->flag |= RX_FLAG_RADIOTAP_HE_MU;
1412 }
1413
1414
1415 if (!queue && !(phy_info & IWL_RX_MPDU_PHY_AMPDU)) {
1416 rx_status->flag |= RX_FLAG_AMPDU_DETAILS;
1417 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN;
1418 if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_HE_DELIM_EOF))
1419 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT;
1420 }
1421
1422 if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD)
1423 iwl_mvm_decode_he_phy_data(mvm, phy_data, he, he_mu, rx_status,
1424 rate_n_flags, queue);
1425
1426
1427 if (!queue && (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD) &&
1428 (phy_info & IWL_RX_MPDU_PHY_AMPDU)) {
1429 bool toggle_bit = phy_info & IWL_RX_MPDU_PHY_AMPDU_TOGGLE;
1430
1431
1432 if (toggle_bit != mvm->ampdu_toggle) {
1433 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT_KNOWN;
1434 if (phy_data->d0 & cpu_to_le32(IWL_RX_PHY_DATA0_HE_DELIM_EOF))
1435 rx_status->flag |= RX_FLAG_AMPDU_EOF_BIT;
1436 }
1437 }
1438
1439 if (he_type == RATE_MCS_HE_TYPE_EXT_SU &&
1440 rate_n_flags & RATE_MCS_HE_106T_MSK) {
1441 rx_status->bw = RATE_INFO_BW_HE_RU;
1442 rx_status->he_ru = NL80211_RATE_INFO_HE_RU_ALLOC_106;
1443 }
1444
1445
1446 if (he_type == RATE_MCS_HE_TYPE_SU ||
1447 he_type == RATE_MCS_HE_TYPE_EXT_SU)
1448 he->data1 |=
1449 cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA1_BW_RU_ALLOC_KNOWN);
1450
1451 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >> RATE_MCS_STBC_POS;
1452 rx_status->nss =
1453 ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >>
1454 RATE_VHT_MCS_NSS_POS) + 1;
1455 rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK;
1456 rx_status->encoding = RX_ENC_HE;
1457 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
1458 if (rate_n_flags & RATE_MCS_BF_MSK)
1459 rx_status->enc_flags |= RX_ENC_FLAG_BF;
1460
1461 rx_status->he_dcm =
1462 !!(rate_n_flags & RATE_HE_DUAL_CARRIER_MODE_MSK);
1463
1464 #define CHECK_TYPE(F) \
1465 BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA1_FORMAT_ ## F != \
1466 (RATE_MCS_HE_TYPE_ ## F >> RATE_MCS_HE_TYPE_POS))
1467
1468 CHECK_TYPE(SU);
1469 CHECK_TYPE(EXT_SU);
1470 CHECK_TYPE(MU);
1471 CHECK_TYPE(TRIG);
1472
1473 he->data1 |= cpu_to_le16(he_type >> RATE_MCS_HE_TYPE_POS);
1474
1475 if (rate_n_flags & RATE_MCS_BF_MSK)
1476 he->data5 |= cpu_to_le16(IEEE80211_RADIOTAP_HE_DATA5_TXBF);
1477
1478 switch ((rate_n_flags & RATE_MCS_HE_GI_LTF_MSK) >>
1479 RATE_MCS_HE_GI_LTF_POS) {
1480 case 0:
1481 if (he_type == RATE_MCS_HE_TYPE_TRIG)
1482 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
1483 else
1484 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
1485 if (he_type == RATE_MCS_HE_TYPE_MU)
1486 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
1487 else
1488 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_1X;
1489 break;
1490 case 1:
1491 if (he_type == RATE_MCS_HE_TYPE_TRIG)
1492 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
1493 else
1494 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
1495 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X;
1496 break;
1497 case 2:
1498 if (he_type == RATE_MCS_HE_TYPE_TRIG) {
1499 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
1500 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
1501 } else {
1502 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_1_6;
1503 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_2X;
1504 }
1505 break;
1506 case 3:
1507 if ((he_type == RATE_MCS_HE_TYPE_SU ||
1508 he_type == RATE_MCS_HE_TYPE_EXT_SU) &&
1509 rate_n_flags & RATE_MCS_SGI_MSK)
1510 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_0_8;
1511 else
1512 rx_status->he_gi = NL80211_RATE_INFO_HE_GI_3_2;
1513 ltf = IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE_4X;
1514 break;
1515 }
1516
1517 he->data5 |= le16_encode_bits(ltf,
1518 IEEE80211_RADIOTAP_HE_DATA5_LTF_SIZE);
1519 }
1520
1521 static void iwl_mvm_decode_lsig(struct sk_buff *skb,
1522 struct iwl_mvm_rx_phy_data *phy_data)
1523 {
1524 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
1525 struct ieee80211_radiotap_lsig *lsig;
1526
1527 switch (phy_data->info_type) {
1528 case IWL_RX_PHY_INFO_TYPE_HT:
1529 case IWL_RX_PHY_INFO_TYPE_VHT_SU:
1530 case IWL_RX_PHY_INFO_TYPE_VHT_MU:
1531 case IWL_RX_PHY_INFO_TYPE_HE_TB_EXT:
1532 case IWL_RX_PHY_INFO_TYPE_HE_SU:
1533 case IWL_RX_PHY_INFO_TYPE_HE_MU:
1534 case IWL_RX_PHY_INFO_TYPE_HE_MU_EXT:
1535 case IWL_RX_PHY_INFO_TYPE_HE_TB:
1536 lsig = skb_put(skb, sizeof(*lsig));
1537 lsig->data1 = cpu_to_le16(IEEE80211_RADIOTAP_LSIG_DATA1_LENGTH_KNOWN);
1538 lsig->data2 = le16_encode_bits(le32_get_bits(phy_data->d1,
1539 IWL_RX_PHY_DATA1_LSIG_LEN_MASK),
1540 IEEE80211_RADIOTAP_LSIG_DATA2_LENGTH);
1541 rx_status->flag |= RX_FLAG_RADIOTAP_LSIG;
1542 break;
1543 default:
1544 break;
1545 }
1546 }
1547
1548 void iwl_mvm_rx_mpdu_mq(struct iwl_mvm *mvm, struct napi_struct *napi,
1549 struct iwl_rx_cmd_buffer *rxb, int queue)
1550 {
1551 struct ieee80211_rx_status *rx_status;
1552 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1553 struct iwl_rx_mpdu_desc *desc = (void *)pkt->data;
1554 struct ieee80211_hdr *hdr;
1555 u32 len = le16_to_cpu(desc->mpdu_len);
1556 u32 rate_n_flags, gp2_on_air_rise;
1557 u16 phy_info = le16_to_cpu(desc->phy_info);
1558 struct ieee80211_sta *sta = NULL;
1559 struct sk_buff *skb;
1560 u8 crypt_len = 0, channel, energy_a, energy_b;
1561 size_t desc_size;
1562 struct iwl_mvm_rx_phy_data phy_data = {
1563 .d4 = desc->phy_data4,
1564 .info_type = IWL_RX_PHY_INFO_TYPE_NONE,
1565 };
1566 bool csi = false;
1567
1568 if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
1569 return;
1570
1571 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22560) {
1572 rate_n_flags = le32_to_cpu(desc->v3.rate_n_flags);
1573 channel = desc->v3.channel;
1574 gp2_on_air_rise = le32_to_cpu(desc->v3.gp2_on_air_rise);
1575 energy_a = desc->v3.energy_a;
1576 energy_b = desc->v3.energy_b;
1577 desc_size = sizeof(*desc);
1578
1579 phy_data.d0 = desc->v3.phy_data0;
1580 phy_data.d1 = desc->v3.phy_data1;
1581 phy_data.d2 = desc->v3.phy_data2;
1582 phy_data.d3 = desc->v3.phy_data3;
1583 } else {
1584 rate_n_flags = le32_to_cpu(desc->v1.rate_n_flags);
1585 channel = desc->v1.channel;
1586 gp2_on_air_rise = le32_to_cpu(desc->v1.gp2_on_air_rise);
1587 energy_a = desc->v1.energy_a;
1588 energy_b = desc->v1.energy_b;
1589 desc_size = IWL_RX_DESC_SIZE_V1;
1590
1591 phy_data.d0 = desc->v1.phy_data0;
1592 phy_data.d1 = desc->v1.phy_data1;
1593 phy_data.d2 = desc->v1.phy_data2;
1594 phy_data.d3 = desc->v1.phy_data3;
1595 }
1596
1597 if (phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD)
1598 phy_data.info_type =
1599 le32_get_bits(phy_data.d1,
1600 IWL_RX_PHY_DATA1_INFO_TYPE_MASK);
1601
1602 hdr = (void *)(pkt->data + desc_size);
1603
1604
1605
1606 skb = alloc_skb(128, GFP_ATOMIC);
1607 if (!skb) {
1608 IWL_ERR(mvm, "alloc_skb failed\n");
1609 return;
1610 }
1611
1612 if (desc->mac_flags2 & IWL_RX_MPDU_MFLG2_PAD) {
1613
1614
1615
1616
1617
1618
1619 skb_reserve(skb, 2);
1620 }
1621
1622 rx_status = IEEE80211_SKB_RXCB(skb);
1623
1624
1625 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
1626 case RATE_MCS_CHAN_WIDTH_20:
1627 break;
1628 case RATE_MCS_CHAN_WIDTH_40:
1629 rx_status->bw = RATE_INFO_BW_40;
1630 break;
1631 case RATE_MCS_CHAN_WIDTH_80:
1632 rx_status->bw = RATE_INFO_BW_80;
1633 break;
1634 case RATE_MCS_CHAN_WIDTH_160:
1635 rx_status->bw = RATE_INFO_BW_160;
1636 break;
1637 }
1638
1639 if (rate_n_flags & RATE_MCS_HE_MSK)
1640 iwl_mvm_rx_he(mvm, skb, &phy_data, rate_n_flags,
1641 phy_info, queue);
1642
1643 iwl_mvm_decode_lsig(skb, &phy_data);
1644
1645 rx_status = IEEE80211_SKB_RXCB(skb);
1646
1647 if (iwl_mvm_rx_crypto(mvm, hdr, rx_status, phy_info, desc,
1648 le32_to_cpu(pkt->len_n_flags), queue,
1649 &crypt_len)) {
1650 kfree_skb(skb);
1651 return;
1652 }
1653
1654
1655
1656
1657
1658 if (!(desc->status & cpu_to_le16(IWL_RX_MPDU_STATUS_CRC_OK)) ||
1659 !(desc->status & cpu_to_le16(IWL_RX_MPDU_STATUS_OVERRUN_OK))) {
1660 IWL_DEBUG_RX(mvm, "Bad CRC or FIFO: 0x%08X.\n",
1661 le16_to_cpu(desc->status));
1662 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
1663 }
1664
1665 if (rate_n_flags & RATE_MCS_CCK_MSK &&
1666 phy_info & IWL_RX_MPDU_PHY_SHORT_PREAMBLE)
1667 rx_status->enc_flags |= RX_ENC_FLAG_SHORTPRE;
1668
1669 if (likely(!(phy_info & IWL_RX_MPDU_PHY_TSF_OVERLOAD))) {
1670 u64 tsf_on_air_rise;
1671
1672 if (mvm->trans->trans_cfg->device_family >=
1673 IWL_DEVICE_FAMILY_22560)
1674 tsf_on_air_rise = le64_to_cpu(desc->v3.tsf_on_air_rise);
1675 else
1676 tsf_on_air_rise = le64_to_cpu(desc->v1.tsf_on_air_rise);
1677
1678 rx_status->mactime = tsf_on_air_rise;
1679
1680 rx_status->flag |= RX_FLAG_MACTIME_PLCP_START;
1681 }
1682
1683 rx_status->device_timestamp = gp2_on_air_rise;
1684 rx_status->band = channel > 14 ? NL80211_BAND_5GHZ :
1685 NL80211_BAND_2GHZ;
1686 rx_status->freq = ieee80211_channel_to_frequency(channel,
1687 rx_status->band);
1688 iwl_mvm_get_signal_strength(mvm, rx_status, rate_n_flags, energy_a,
1689 energy_b);
1690
1691
1692 if (!queue && (phy_info & IWL_RX_MPDU_PHY_AMPDU)) {
1693 bool toggle_bit = phy_info & IWL_RX_MPDU_PHY_AMPDU_TOGGLE;
1694
1695 rx_status->flag |= RX_FLAG_AMPDU_DETAILS;
1696
1697
1698
1699
1700
1701 if (toggle_bit != mvm->ampdu_toggle) {
1702 mvm->ampdu_ref++;
1703 if (mvm->ampdu_ref == 0)
1704 mvm->ampdu_ref++;
1705 mvm->ampdu_toggle = toggle_bit;
1706 }
1707 rx_status->ampdu_reference = mvm->ampdu_ref;
1708 }
1709
1710 if (unlikely(mvm->monitor_on))
1711 iwl_mvm_add_rtap_sniffer_config(mvm, skb);
1712
1713 rcu_read_lock();
1714
1715 if (desc->status & cpu_to_le16(IWL_RX_MPDU_STATUS_SRC_STA_FOUND)) {
1716 u8 id = desc->sta_id_flags & IWL_RX_MPDU_SIF_STA_ID_MASK;
1717
1718 if (!WARN_ON_ONCE(id >= ARRAY_SIZE(mvm->fw_id_to_mac_id))) {
1719 sta = rcu_dereference(mvm->fw_id_to_mac_id[id]);
1720 if (IS_ERR(sta))
1721 sta = NULL;
1722 }
1723 } else if (!is_multicast_ether_addr(hdr->addr2)) {
1724
1725
1726
1727
1728 sta = ieee80211_find_sta_by_ifaddr(mvm->hw, hdr->addr2, NULL);
1729 }
1730
1731 if (sta) {
1732 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1733 struct ieee80211_vif *tx_blocked_vif =
1734 rcu_dereference(mvm->csa_tx_blocked_vif);
1735 u8 baid = (u8)((le32_to_cpu(desc->reorder_data) &
1736 IWL_RX_MPDU_REORDER_BAID_MASK) >>
1737 IWL_RX_MPDU_REORDER_BAID_SHIFT);
1738 struct iwl_fw_dbg_trigger_tlv *trig;
1739 struct ieee80211_vif *vif = mvmsta->vif;
1740
1741 if (!mvm->tcm.paused && len >= sizeof(*hdr) &&
1742 !is_multicast_ether_addr(hdr->addr1) &&
1743 ieee80211_is_data(hdr->frame_control) &&
1744 time_after(jiffies, mvm->tcm.ts + MVM_TCM_PERIOD))
1745 schedule_delayed_work(&mvm->tcm.work, 0);
1746
1747
1748
1749
1750
1751
1752 if (unlikely(tx_blocked_vif) && tx_blocked_vif == vif) {
1753 struct iwl_mvm_vif *mvmvif =
1754 iwl_mvm_vif_from_mac80211(tx_blocked_vif);
1755
1756 if (mvmvif->csa_target_freq == rx_status->freq)
1757 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta,
1758 false);
1759 }
1760
1761 rs_update_last_rssi(mvm, mvmsta, rx_status);
1762
1763 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt,
1764 ieee80211_vif_to_wdev(vif),
1765 FW_DBG_TRIGGER_RSSI);
1766
1767 if (trig && ieee80211_is_beacon(hdr->frame_control)) {
1768 struct iwl_fw_dbg_trigger_low_rssi *rssi_trig;
1769 s32 rssi;
1770
1771 rssi_trig = (void *)trig->data;
1772 rssi = le32_to_cpu(rssi_trig->rssi);
1773
1774 if (rx_status->signal < rssi)
1775 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
1776 NULL);
1777 }
1778
1779 if (ieee80211_is_data(hdr->frame_control))
1780 iwl_mvm_rx_csum(sta, skb, desc);
1781
1782 if (iwl_mvm_is_dup(sta, queue, rx_status, hdr, desc)) {
1783 kfree_skb(skb);
1784 goto out;
1785 }
1786
1787
1788
1789
1790
1791
1792
1793 if ((desc->mac_flags2 & IWL_RX_MPDU_MFLG2_AMSDU) &&
1794 !WARN_ON(!ieee80211_is_data_qos(hdr->frame_control))) {
1795 u8 *qc = ieee80211_get_qos_ctl(hdr);
1796
1797 *qc &= ~IEEE80211_QOS_CTL_A_MSDU_PRESENT;
1798
1799 if (mvm->trans->trans_cfg->device_family ==
1800 IWL_DEVICE_FAMILY_9000) {
1801 iwl_mvm_flip_address(hdr->addr3);
1802
1803 if (ieee80211_has_a4(hdr->frame_control))
1804 iwl_mvm_flip_address(hdr->addr4);
1805 }
1806 }
1807 if (baid != IWL_RX_REORDER_DATA_INVALID_BAID) {
1808 u32 reorder_data = le32_to_cpu(desc->reorder_data);
1809
1810 iwl_mvm_agg_rx_received(mvm, reorder_data, baid);
1811 }
1812 }
1813
1814 if (!(rate_n_flags & RATE_MCS_CCK_MSK) &&
1815 rate_n_flags & RATE_MCS_SGI_MSK)
1816 rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
1817 if (rate_n_flags & RATE_HT_MCS_GF_MSK)
1818 rx_status->enc_flags |= RX_ENC_FLAG_HT_GF;
1819 if (rate_n_flags & RATE_MCS_LDPC_MSK)
1820 rx_status->enc_flags |= RX_ENC_FLAG_LDPC;
1821 if (rate_n_flags & RATE_MCS_HT_MSK) {
1822 u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
1823 RATE_MCS_STBC_POS;
1824 rx_status->encoding = RX_ENC_HT;
1825 rx_status->rate_idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK;
1826 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
1827 } else if (rate_n_flags & RATE_MCS_VHT_MSK) {
1828 u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
1829 RATE_MCS_STBC_POS;
1830 rx_status->nss =
1831 ((rate_n_flags & RATE_VHT_MCS_NSS_MSK) >>
1832 RATE_VHT_MCS_NSS_POS) + 1;
1833 rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK;
1834 rx_status->encoding = RX_ENC_VHT;
1835 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
1836 if (rate_n_flags & RATE_MCS_BF_MSK)
1837 rx_status->enc_flags |= RX_ENC_FLAG_BF;
1838 } else if (!(rate_n_flags & RATE_MCS_HE_MSK)) {
1839 int rate = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags,
1840 rx_status->band);
1841
1842 if (WARN(rate < 0 || rate > 0xFF,
1843 "Invalid rate flags 0x%x, band %d,\n",
1844 rate_n_flags, rx_status->band)) {
1845 kfree_skb(skb);
1846 goto out;
1847 }
1848 rx_status->rate_idx = rate;
1849 }
1850
1851
1852 if (!queue) {
1853 if (unlikely((ieee80211_is_beacon(hdr->frame_control) ||
1854 ieee80211_is_probe_resp(hdr->frame_control)) &&
1855 mvm->sched_scan_pass_all ==
1856 SCHED_SCAN_PASS_ALL_ENABLED))
1857 mvm->sched_scan_pass_all = SCHED_SCAN_PASS_ALL_FOUND;
1858
1859 if (unlikely(ieee80211_is_beacon(hdr->frame_control) ||
1860 ieee80211_is_probe_resp(hdr->frame_control)))
1861 rx_status->boottime_ns = ktime_get_boottime_ns();
1862 }
1863
1864 if (iwl_mvm_create_skb(mvm, skb, hdr, len, crypt_len, rxb)) {
1865 kfree_skb(skb);
1866 goto out;
1867 }
1868
1869 if (!iwl_mvm_reorder(mvm, napi, queue, sta, skb, desc))
1870 iwl_mvm_pass_packet_to_mac80211(mvm, napi, skb, queue,
1871 sta, csi);
1872 out:
1873 rcu_read_unlock();
1874 }
1875
1876 void iwl_mvm_rx_monitor_no_data(struct iwl_mvm *mvm, struct napi_struct *napi,
1877 struct iwl_rx_cmd_buffer *rxb, int queue)
1878 {
1879 struct ieee80211_rx_status *rx_status;
1880 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1881 struct iwl_rx_no_data *desc = (void *)pkt->data;
1882 u32 rate_n_flags = le32_to_cpu(desc->rate);
1883 u32 gp2_on_air_rise = le32_to_cpu(desc->on_air_rise_time);
1884 u32 rssi = le32_to_cpu(desc->rssi);
1885 u32 info_type = le32_to_cpu(desc->info) & RX_NO_DATA_INFO_TYPE_MSK;
1886 u16 phy_info = IWL_RX_MPDU_PHY_TSF_OVERLOAD;
1887 struct ieee80211_sta *sta = NULL;
1888 struct sk_buff *skb;
1889 u8 channel, energy_a, energy_b;
1890 struct iwl_mvm_rx_phy_data phy_data = {
1891 .d0 = desc->phy_info[0],
1892 .info_type = IWL_RX_PHY_INFO_TYPE_NONE,
1893 };
1894
1895 if (unlikely(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)))
1896 return;
1897
1898 energy_a = (rssi & RX_NO_DATA_CHAIN_A_MSK) >> RX_NO_DATA_CHAIN_A_POS;
1899 energy_b = (rssi & RX_NO_DATA_CHAIN_B_MSK) >> RX_NO_DATA_CHAIN_B_POS;
1900 channel = (rssi & RX_NO_DATA_CHANNEL_MSK) >> RX_NO_DATA_CHANNEL_POS;
1901
1902 phy_data.info_type =
1903 le32_get_bits(desc->phy_info[1],
1904 IWL_RX_PHY_DATA1_INFO_TYPE_MASK);
1905
1906
1907
1908
1909 skb = alloc_skb(128, GFP_ATOMIC);
1910 if (!skb) {
1911 IWL_ERR(mvm, "alloc_skb failed\n");
1912 return;
1913 }
1914
1915 rx_status = IEEE80211_SKB_RXCB(skb);
1916
1917
1918 rx_status->flag |= RX_FLAG_NO_PSDU;
1919
1920 switch (info_type) {
1921 case RX_NO_DATA_INFO_TYPE_NDP:
1922 rx_status->zero_length_psdu_type =
1923 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_SOUNDING;
1924 break;
1925 case RX_NO_DATA_INFO_TYPE_MU_UNMATCHED:
1926 case RX_NO_DATA_INFO_TYPE_HE_TB_UNMATCHED:
1927 rx_status->zero_length_psdu_type =
1928 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_NOT_CAPTURED;
1929 break;
1930 default:
1931 rx_status->zero_length_psdu_type =
1932 IEEE80211_RADIOTAP_ZERO_LEN_PSDU_VENDOR;
1933 break;
1934 }
1935
1936
1937 switch (rate_n_flags & RATE_MCS_CHAN_WIDTH_MSK) {
1938 case RATE_MCS_CHAN_WIDTH_20:
1939 break;
1940 case RATE_MCS_CHAN_WIDTH_40:
1941 rx_status->bw = RATE_INFO_BW_40;
1942 break;
1943 case RATE_MCS_CHAN_WIDTH_80:
1944 rx_status->bw = RATE_INFO_BW_80;
1945 break;
1946 case RATE_MCS_CHAN_WIDTH_160:
1947 rx_status->bw = RATE_INFO_BW_160;
1948 break;
1949 }
1950
1951 if (rate_n_flags & RATE_MCS_HE_MSK)
1952 iwl_mvm_rx_he(mvm, skb, &phy_data, rate_n_flags,
1953 phy_info, queue);
1954
1955 iwl_mvm_decode_lsig(skb, &phy_data);
1956
1957 rx_status->device_timestamp = gp2_on_air_rise;
1958 rx_status->band = channel > 14 ? NL80211_BAND_5GHZ :
1959 NL80211_BAND_2GHZ;
1960 rx_status->freq = ieee80211_channel_to_frequency(channel,
1961 rx_status->band);
1962 iwl_mvm_get_signal_strength(mvm, rx_status, rate_n_flags, energy_a,
1963 energy_b);
1964
1965 rcu_read_lock();
1966
1967 if (!(rate_n_flags & RATE_MCS_CCK_MSK) &&
1968 rate_n_flags & RATE_MCS_SGI_MSK)
1969 rx_status->enc_flags |= RX_ENC_FLAG_SHORT_GI;
1970 if (rate_n_flags & RATE_HT_MCS_GF_MSK)
1971 rx_status->enc_flags |= RX_ENC_FLAG_HT_GF;
1972 if (rate_n_flags & RATE_MCS_LDPC_MSK)
1973 rx_status->enc_flags |= RX_ENC_FLAG_LDPC;
1974 if (rate_n_flags & RATE_MCS_HT_MSK) {
1975 u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
1976 RATE_MCS_STBC_POS;
1977 rx_status->encoding = RX_ENC_HT;
1978 rx_status->rate_idx = rate_n_flags & RATE_HT_MCS_INDEX_MSK;
1979 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
1980 } else if (rate_n_flags & RATE_MCS_VHT_MSK) {
1981 u8 stbc = (rate_n_flags & RATE_MCS_STBC_MSK) >>
1982 RATE_MCS_STBC_POS;
1983 rx_status->rate_idx = rate_n_flags & RATE_VHT_MCS_RATE_CODE_MSK;
1984 rx_status->encoding = RX_ENC_VHT;
1985 rx_status->enc_flags |= stbc << RX_ENC_FLAG_STBC_SHIFT;
1986 if (rate_n_flags & RATE_MCS_BF_MSK)
1987 rx_status->enc_flags |= RX_ENC_FLAG_BF;
1988
1989
1990
1991
1992
1993 rx_status->nss =
1994 le32_get_bits(desc->rx_vec[0],
1995 RX_NO_DATA_RX_VEC0_VHT_NSTS_MSK) + 1;
1996 } else if (rate_n_flags & RATE_MCS_HE_MSK) {
1997 rx_status->nss =
1998 le32_get_bits(desc->rx_vec[0],
1999 RX_NO_DATA_RX_VEC0_HE_NSTS_MSK) + 1;
2000 } else {
2001 int rate = iwl_mvm_legacy_rate_to_mac80211_idx(rate_n_flags,
2002 rx_status->band);
2003
2004 if (WARN(rate < 0 || rate > 0xFF,
2005 "Invalid rate flags 0x%x, band %d,\n",
2006 rate_n_flags, rx_status->band)) {
2007 kfree_skb(skb);
2008 goto out;
2009 }
2010 rx_status->rate_idx = rate;
2011 }
2012
2013 ieee80211_rx_napi(mvm->hw, sta, skb, napi);
2014 out:
2015 rcu_read_unlock();
2016 }
2017
2018 void iwl_mvm_rx_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
2019 struct iwl_rx_cmd_buffer *rxb, int queue)
2020 {
2021 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2022 struct iwl_frame_release *release = (void *)pkt->data;
2023
2024 iwl_mvm_release_frames_from_notif(mvm, napi, release->baid,
2025 le16_to_cpu(release->nssn),
2026 queue, 0);
2027 }
2028
2029 void iwl_mvm_rx_bar_frame_release(struct iwl_mvm *mvm, struct napi_struct *napi,
2030 struct iwl_rx_cmd_buffer *rxb, int queue)
2031 {
2032 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2033 struct iwl_bar_frame_release *release = (void *)pkt->data;
2034 unsigned int baid = le32_get_bits(release->ba_info,
2035 IWL_BAR_FRAME_RELEASE_BAID_MASK);
2036 unsigned int nssn = le32_get_bits(release->ba_info,
2037 IWL_BAR_FRAME_RELEASE_NSSN_MASK);
2038 unsigned int sta_id = le32_get_bits(release->sta_tid,
2039 IWL_BAR_FRAME_RELEASE_STA_MASK);
2040 unsigned int tid = le32_get_bits(release->sta_tid,
2041 IWL_BAR_FRAME_RELEASE_TID_MASK);
2042 struct iwl_mvm_baid_data *baid_data;
2043
2044 if (WARN_ON_ONCE(baid == IWL_RX_REORDER_DATA_INVALID_BAID ||
2045 baid >= ARRAY_SIZE(mvm->baid_map)))
2046 return;
2047
2048 rcu_read_lock();
2049 baid_data = rcu_dereference(mvm->baid_map[baid]);
2050 if (!baid_data) {
2051 IWL_DEBUG_RX(mvm,
2052 "Got valid BAID %d but not allocated, invalid BAR release!\n",
2053 baid);
2054 goto out;
2055 }
2056
2057 if (WARN(tid != baid_data->tid || sta_id != baid_data->sta_id,
2058 "baid 0x%x is mapped to sta:%d tid:%d, but BAR release received for sta:%d tid:%d\n",
2059 baid, baid_data->sta_id, baid_data->tid, sta_id,
2060 tid))
2061 goto out;
2062
2063 iwl_mvm_release_frames_from_notif(mvm, napi, baid, nssn, queue, 0);
2064 out:
2065 rcu_read_unlock();
2066 }