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
64#include <net/mac80211.h>
65
66#include "mvm.h"
67#include "sta.h"
68#include "rs.h"
69
70
71
72
73
74
75static inline int iwl_mvm_add_sta_cmd_size(struct iwl_mvm *mvm)
76{
77 if (iwl_mvm_has_new_rx_api(mvm) ||
78 fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
79 return sizeof(struct iwl_mvm_add_sta_cmd);
80 else
81 return sizeof(struct iwl_mvm_add_sta_cmd_v7);
82}
83
84static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm,
85 enum nl80211_iftype iftype)
86{
87 int sta_id;
88 u32 reserved_ids = 0;
89
90 BUILD_BUG_ON(IWL_MVM_STATION_COUNT > 32);
91 WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status));
92
93 lockdep_assert_held(&mvm->mutex);
94
95
96 if (iftype != NL80211_IFTYPE_STATION)
97 reserved_ids = BIT(0);
98
99
100 for (sta_id = 0; sta_id < ARRAY_SIZE(mvm->fw_id_to_mac_id); sta_id++) {
101 if (BIT(sta_id) & reserved_ids)
102 continue;
103
104 if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
105 lockdep_is_held(&mvm->mutex)))
106 return sta_id;
107 }
108 return IWL_MVM_INVALID_STA;
109}
110
111
112int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
113 bool update, unsigned int flags)
114{
115 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
116 struct iwl_mvm_add_sta_cmd add_sta_cmd = {
117 .sta_id = mvm_sta->sta_id,
118 .mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color),
119 .add_modify = update ? 1 : 0,
120 .station_flags_msk = cpu_to_le32(STA_FLG_FAT_EN_MSK |
121 STA_FLG_MIMO_EN_MSK |
122 STA_FLG_RTS_MIMO_PROT),
123 .tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg),
124 };
125 int ret;
126 u32 status;
127 u32 agg_size = 0, mpdu_dens = 0;
128
129 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
130 add_sta_cmd.station_type = mvm_sta->sta_type;
131
132 if (!update || (flags & STA_MODIFY_QUEUES)) {
133 memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN);
134
135 if (!iwl_mvm_has_new_tx_api(mvm)) {
136 add_sta_cmd.tfd_queue_msk =
137 cpu_to_le32(mvm_sta->tfd_queue_msk);
138
139 if (flags & STA_MODIFY_QUEUES)
140 add_sta_cmd.modify_mask |= STA_MODIFY_QUEUES;
141 } else {
142 WARN_ON(flags & STA_MODIFY_QUEUES);
143 }
144 }
145
146 switch (sta->bandwidth) {
147 case IEEE80211_STA_RX_BW_160:
148 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_160MHZ);
149
150 case IEEE80211_STA_RX_BW_80:
151 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_80MHZ);
152
153 case IEEE80211_STA_RX_BW_40:
154 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_40MHZ);
155
156 case IEEE80211_STA_RX_BW_20:
157 if (sta->ht_cap.ht_supported)
158 add_sta_cmd.station_flags |=
159 cpu_to_le32(STA_FLG_FAT_EN_20MHZ);
160 break;
161 }
162
163 switch (sta->rx_nss) {
164 case 1:
165 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO);
166 break;
167 case 2:
168 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2);
169 break;
170 case 3 ... 8:
171 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3);
172 break;
173 }
174
175 switch (sta->smps_mode) {
176 case IEEE80211_SMPS_AUTOMATIC:
177 case IEEE80211_SMPS_NUM_MODES:
178 WARN_ON(1);
179 break;
180 case IEEE80211_SMPS_STATIC:
181
182 add_sta_cmd.station_flags &= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK);
183 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO);
184 break;
185 case IEEE80211_SMPS_DYNAMIC:
186 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_RTS_MIMO_PROT);
187 break;
188 case IEEE80211_SMPS_OFF:
189
190 break;
191 }
192
193 if (sta->ht_cap.ht_supported) {
194 add_sta_cmd.station_flags_msk |=
195 cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK |
196 STA_FLG_AGG_MPDU_DENS_MSK);
197
198 mpdu_dens = sta->ht_cap.ampdu_density;
199 }
200
201 if (sta->vht_cap.vht_supported) {
202 agg_size = sta->vht_cap.cap &
203 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
204 agg_size >>=
205 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
206 } else if (sta->ht_cap.ht_supported) {
207 agg_size = sta->ht_cap.ampdu_factor;
208 }
209
210 add_sta_cmd.station_flags |=
211 cpu_to_le32(agg_size << STA_FLG_MAX_AGG_SIZE_SHIFT);
212 add_sta_cmd.station_flags |=
213 cpu_to_le32(mpdu_dens << STA_FLG_AGG_MPDU_DENS_SHIFT);
214 if (mvm_sta->sta_state >= IEEE80211_STA_ASSOC)
215 add_sta_cmd.assoc_id = cpu_to_le16(sta->aid);
216
217 if (sta->wme) {
218 add_sta_cmd.modify_mask |= STA_MODIFY_UAPSD_ACS;
219
220 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
221 add_sta_cmd.uapsd_acs |= BIT(AC_BK);
222 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
223 add_sta_cmd.uapsd_acs |= BIT(AC_BE);
224 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
225 add_sta_cmd.uapsd_acs |= BIT(AC_VI);
226 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
227 add_sta_cmd.uapsd_acs |= BIT(AC_VO);
228 add_sta_cmd.uapsd_acs |= add_sta_cmd.uapsd_acs << 4;
229 add_sta_cmd.sp_length = sta->max_sp ? sta->max_sp * 2 : 128;
230 }
231
232 status = ADD_STA_SUCCESS;
233 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
234 iwl_mvm_add_sta_cmd_size(mvm),
235 &add_sta_cmd, &status);
236 if (ret)
237 return ret;
238
239 switch (status & IWL_ADD_STA_STATUS_MASK) {
240 case ADD_STA_SUCCESS:
241 IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n");
242 break;
243 default:
244 ret = -EIO;
245 IWL_ERR(mvm, "ADD_STA failed\n");
246 break;
247 }
248
249 return ret;
250}
251
252static void iwl_mvm_rx_agg_session_expired(struct timer_list *t)
253{
254 struct iwl_mvm_baid_data *data =
255 from_timer(data, t, session_timer);
256 struct iwl_mvm_baid_data __rcu **rcu_ptr = data->rcu_ptr;
257 struct iwl_mvm_baid_data *ba_data;
258 struct ieee80211_sta *sta;
259 struct iwl_mvm_sta *mvm_sta;
260 unsigned long timeout;
261
262 rcu_read_lock();
263
264 ba_data = rcu_dereference(*rcu_ptr);
265
266 if (WARN_ON(!ba_data))
267 goto unlock;
268
269 if (!ba_data->timeout)
270 goto unlock;
271
272 timeout = ba_data->last_rx + TU_TO_JIFFIES(ba_data->timeout * 2);
273 if (time_is_after_jiffies(timeout)) {
274 mod_timer(&ba_data->session_timer, timeout);
275 goto unlock;
276 }
277
278
279 sta = rcu_dereference(ba_data->mvm->fw_id_to_mac_id[ba_data->sta_id]);
280
281
282
283
284
285
286
287
288
289 if (!sta)
290 goto unlock;
291
292 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
293 ieee80211_rx_ba_timer_expired(mvm_sta->vif,
294 sta->addr, ba_data->tid);
295unlock:
296 rcu_read_unlock();
297}
298
299
300static int iwl_mvm_invalidate_sta_queue(struct iwl_mvm *mvm, int queue,
301 unsigned long disable_agg_tids,
302 bool remove_queue)
303{
304 struct iwl_mvm_add_sta_cmd cmd = {};
305 struct ieee80211_sta *sta;
306 struct iwl_mvm_sta *mvmsta;
307 u32 status;
308 u8 sta_id;
309
310 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
311 return -EINVAL;
312
313 sta_id = mvm->queue_info[queue].ra_sta_id;
314
315 rcu_read_lock();
316
317 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
318
319 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
320 rcu_read_unlock();
321 return -EINVAL;
322 }
323
324 mvmsta = iwl_mvm_sta_from_mac80211(sta);
325
326 mvmsta->tid_disable_agg |= disable_agg_tids;
327
328 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
329 cmd.sta_id = mvmsta->sta_id;
330 cmd.add_modify = STA_MODE_MODIFY;
331 cmd.modify_mask = STA_MODIFY_QUEUES;
332 if (disable_agg_tids)
333 cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX;
334 if (remove_queue)
335 cmd.modify_mask |= STA_MODIFY_QUEUE_REMOVAL;
336 cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk);
337 cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg);
338
339 rcu_read_unlock();
340
341
342 status = ADD_STA_SUCCESS;
343 return iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
344 iwl_mvm_add_sta_cmd_size(mvm),
345 &cmd, &status);
346}
347
348static int iwl_mvm_disable_txq(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
349 int queue, u8 tid, u8 flags)
350{
351 struct iwl_scd_txq_cfg_cmd cmd = {
352 .scd_queue = queue,
353 .action = SCD_CFG_DISABLE_QUEUE,
354 };
355 int ret;
356
357 if (iwl_mvm_has_new_tx_api(mvm)) {
358 iwl_trans_txq_free(mvm->trans, queue);
359
360 return 0;
361 }
362
363 if (WARN_ON(mvm->queue_info[queue].tid_bitmap == 0))
364 return 0;
365
366 mvm->queue_info[queue].tid_bitmap &= ~BIT(tid);
367
368 cmd.action = mvm->queue_info[queue].tid_bitmap ?
369 SCD_CFG_ENABLE_QUEUE : SCD_CFG_DISABLE_QUEUE;
370 if (cmd.action == SCD_CFG_DISABLE_QUEUE)
371 mvm->queue_info[queue].status = IWL_MVM_QUEUE_FREE;
372
373 IWL_DEBUG_TX_QUEUES(mvm,
374 "Disabling TXQ #%d tids=0x%x\n",
375 queue,
376 mvm->queue_info[queue].tid_bitmap);
377
378
379 if (cmd.action == SCD_CFG_ENABLE_QUEUE)
380 return 0;
381
382 cmd.sta_id = mvm->queue_info[queue].ra_sta_id;
383 cmd.tid = mvm->queue_info[queue].txq_tid;
384
385
386 WARN(mvm->queue_info[queue].tid_bitmap,
387 "TXQ #%d info out-of-sync - tids=0x%x\n",
388 queue, mvm->queue_info[queue].tid_bitmap);
389
390
391 mvm->queue_info[queue].tid_bitmap = 0;
392
393 if (sta) {
394 struct iwl_mvm_txq *mvmtxq =
395 iwl_mvm_txq_from_tid(sta, tid);
396
397 mvmtxq->txq_id = IWL_MVM_INVALID_QUEUE;
398 }
399
400
401 mvm->queue_info[queue].reserved = false;
402
403 iwl_trans_txq_disable(mvm->trans, queue, false);
404 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, flags,
405 sizeof(struct iwl_scd_txq_cfg_cmd), &cmd);
406
407 if (ret)
408 IWL_ERR(mvm, "Failed to disable queue %d (ret=%d)\n",
409 queue, ret);
410 return ret;
411}
412
413static int iwl_mvm_get_queue_agg_tids(struct iwl_mvm *mvm, int queue)
414{
415 struct ieee80211_sta *sta;
416 struct iwl_mvm_sta *mvmsta;
417 unsigned long tid_bitmap;
418 unsigned long agg_tids = 0;
419 u8 sta_id;
420 int tid;
421
422 lockdep_assert_held(&mvm->mutex);
423
424 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
425 return -EINVAL;
426
427 sta_id = mvm->queue_info[queue].ra_sta_id;
428 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
429
430 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
431 lockdep_is_held(&mvm->mutex));
432
433 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
434 return -EINVAL;
435
436 mvmsta = iwl_mvm_sta_from_mac80211(sta);
437
438 spin_lock_bh(&mvmsta->lock);
439 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
440 if (mvmsta->tid_data[tid].state == IWL_AGG_ON)
441 agg_tids |= BIT(tid);
442 }
443 spin_unlock_bh(&mvmsta->lock);
444
445 return agg_tids;
446}
447
448
449
450
451
452
453static int iwl_mvm_remove_sta_queue_marking(struct iwl_mvm *mvm, int queue)
454{
455 struct ieee80211_sta *sta;
456 struct iwl_mvm_sta *mvmsta;
457 unsigned long tid_bitmap;
458 unsigned long disable_agg_tids = 0;
459 u8 sta_id;
460 int tid;
461
462 lockdep_assert_held(&mvm->mutex);
463
464 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
465 return -EINVAL;
466
467 sta_id = mvm->queue_info[queue].ra_sta_id;
468 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
469
470 rcu_read_lock();
471
472 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
473
474 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
475 rcu_read_unlock();
476 return 0;
477 }
478
479 mvmsta = iwl_mvm_sta_from_mac80211(sta);
480
481 spin_lock_bh(&mvmsta->lock);
482
483 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
484 struct iwl_mvm_txq *mvmtxq =
485 iwl_mvm_txq_from_tid(sta, tid);
486
487 if (mvmsta->tid_data[tid].state == IWL_AGG_ON)
488 disable_agg_tids |= BIT(tid);
489 mvmsta->tid_data[tid].txq_id = IWL_MVM_INVALID_QUEUE;
490
491 mvmtxq->txq_id = IWL_MVM_INVALID_QUEUE;
492 }
493
494 mvmsta->tfd_queue_msk &= ~BIT(queue);
495 spin_unlock_bh(&mvmsta->lock);
496
497 rcu_read_unlock();
498
499
500
501
502
503
504
505
506
507 synchronize_net();
508
509 return disable_agg_tids;
510}
511
512static int iwl_mvm_free_inactive_queue(struct iwl_mvm *mvm, int queue,
513 struct ieee80211_sta *old_sta,
514 u8 new_sta_id)
515{
516 struct iwl_mvm_sta *mvmsta;
517 u8 sta_id, tid;
518 unsigned long disable_agg_tids = 0;
519 bool same_sta;
520 int ret;
521
522 lockdep_assert_held(&mvm->mutex);
523
524 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
525 return -EINVAL;
526
527 sta_id = mvm->queue_info[queue].ra_sta_id;
528 tid = mvm->queue_info[queue].txq_tid;
529
530 same_sta = sta_id == new_sta_id;
531
532 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
533 if (WARN_ON(!mvmsta))
534 return -EINVAL;
535
536 disable_agg_tids = iwl_mvm_remove_sta_queue_marking(mvm, queue);
537
538 if (disable_agg_tids)
539 iwl_mvm_invalidate_sta_queue(mvm, queue,
540 disable_agg_tids, false);
541
542 ret = iwl_mvm_disable_txq(mvm, old_sta, queue, tid, 0);
543 if (ret) {
544 IWL_ERR(mvm,
545 "Failed to free inactive queue %d (ret=%d)\n",
546 queue, ret);
547
548 return ret;
549 }
550
551
552 if (!same_sta)
553 iwl_mvm_invalidate_sta_queue(mvm, queue, 0, true);
554
555 return 0;
556}
557
558static int iwl_mvm_get_shared_queue(struct iwl_mvm *mvm,
559 unsigned long tfd_queue_mask, u8 ac)
560{
561 int queue = 0;
562 u8 ac_to_queue[IEEE80211_NUM_ACS];
563 int i;
564
565
566
567
568
569 lockdep_assert_held(&mvm->mutex);
570
571 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
572 return -EINVAL;
573
574 memset(&ac_to_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(ac_to_queue));
575
576
577 for_each_set_bit(i, &tfd_queue_mask, IWL_MVM_DQA_MAX_DATA_QUEUE) {
578
579 if (i < IWL_MVM_DQA_MIN_DATA_QUEUE &&
580 i != IWL_MVM_DQA_BSS_CLIENT_QUEUE)
581 continue;
582
583 ac_to_queue[mvm->queue_info[i].mac80211_ac] = i;
584 }
585
586
587
588
589
590
591
592
593
594
595
596 if (ac_to_queue[IEEE80211_AC_BE] != IEEE80211_INVAL_HW_QUEUE)
597 queue = ac_to_queue[IEEE80211_AC_BE];
598
599 else if (ac_to_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
600 queue = ac_to_queue[ac];
601
602 else if (ac == IEEE80211_AC_VO &&
603 ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE)
604 queue = ac_to_queue[IEEE80211_AC_VI];
605
606 else if (ac_to_queue[IEEE80211_AC_BK] != IEEE80211_INVAL_HW_QUEUE)
607 queue = ac_to_queue[IEEE80211_AC_BK];
608
609 else if (ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE)
610 queue = ac_to_queue[IEEE80211_AC_VI];
611
612 else if (ac_to_queue[IEEE80211_AC_VO] != IEEE80211_INVAL_HW_QUEUE)
613 queue = ac_to_queue[IEEE80211_AC_VO];
614
615
616 if (!iwl_mvm_is_dqa_data_queue(mvm, queue) &&
617 !iwl_mvm_is_dqa_mgmt_queue(mvm, queue) &&
618 (queue != IWL_MVM_DQA_BSS_CLIENT_QUEUE)) {
619 IWL_ERR(mvm, "No DATA queues available to share\n");
620 return -ENOSPC;
621 }
622
623 return queue;
624}
625
626
627
628
629
630
631
632static int iwl_mvm_redirect_queue(struct iwl_mvm *mvm, int queue, int tid,
633 int ac, int ssn, unsigned int wdg_timeout,
634 bool force, struct iwl_mvm_txq *txq)
635{
636 struct iwl_scd_txq_cfg_cmd cmd = {
637 .scd_queue = queue,
638 .action = SCD_CFG_DISABLE_QUEUE,
639 };
640 bool shared_queue;
641 int ret;
642
643 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
644 return -EINVAL;
645
646
647
648
649
650
651
652
653
654 if (ac <= mvm->queue_info[queue].mac80211_ac && !force) {
655 IWL_DEBUG_TX_QUEUES(mvm,
656 "No redirection needed on TXQ #%d\n",
657 queue);
658 return 0;
659 }
660
661 cmd.sta_id = mvm->queue_info[queue].ra_sta_id;
662 cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[mvm->queue_info[queue].mac80211_ac];
663 cmd.tid = mvm->queue_info[queue].txq_tid;
664 shared_queue = hweight16(mvm->queue_info[queue].tid_bitmap) > 1;
665
666 IWL_DEBUG_TX_QUEUES(mvm, "Redirecting TXQ #%d to FIFO #%d\n",
667 queue, iwl_mvm_ac_to_tx_fifo[ac]);
668
669
670 txq->stopped = true;
671
672 ret = iwl_trans_wait_tx_queues_empty(mvm->trans, BIT(queue));
673 if (ret) {
674 IWL_ERR(mvm, "Error draining queue %d before reconfig\n",
675 queue);
676 ret = -EIO;
677 goto out;
678 }
679
680
681 iwl_trans_txq_disable(mvm->trans, queue, false);
682 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd);
683 if (ret)
684 IWL_ERR(mvm, "Failed SCD disable TXQ %d (ret=%d)\n", queue,
685 ret);
686
687
688 iwl_trans_txq_enable_cfg(mvm->trans, queue, ssn, NULL, wdg_timeout);
689
690
691 mvm->queue_info[queue].txq_tid = tid;
692
693
694
695
696 iwl_mvm_reconfig_scd(mvm, queue, iwl_mvm_ac_to_tx_fifo[ac],
697 cmd.sta_id, tid, IWL_FRAME_LIMIT, ssn);
698
699
700 mvm->queue_info[queue].mac80211_ac = ac;
701
702
703
704
705
706
707
708 if (shared_queue)
709 iwl_trans_txq_set_shared_mode(mvm->trans, queue, true);
710
711out:
712
713 txq->stopped = false;
714
715 return ret;
716}
717
718static int iwl_mvm_find_free_queue(struct iwl_mvm *mvm, u8 sta_id,
719 u8 minq, u8 maxq)
720{
721 int i;
722
723 lockdep_assert_held(&mvm->mutex);
724
725
726 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
727 return -ENOSPC;
728
729
730 for (i = minq; i <= maxq; i++)
731 if (mvm->queue_info[i].tid_bitmap == 0 &&
732 mvm->queue_info[i].status == IWL_MVM_QUEUE_FREE)
733 return i;
734
735 return -ENOSPC;
736}
737
738static int iwl_mvm_tvqm_enable_txq(struct iwl_mvm *mvm,
739 u8 sta_id, u8 tid, unsigned int timeout)
740{
741 int queue, size = max_t(u32, IWL_DEFAULT_QUEUE_SIZE,
742 mvm->trans->cfg->min_256_ba_txq_size);
743
744 if (tid == IWL_MAX_TID_COUNT) {
745 tid = IWL_MGMT_TID;
746 size = max_t(u32, IWL_MGMT_QUEUE_SIZE,
747 mvm->trans->cfg->min_txq_size);
748 }
749 queue = iwl_trans_txq_alloc(mvm->trans,
750 cpu_to_le16(TX_QUEUE_CFG_ENABLE_QUEUE),
751 sta_id, tid, SCD_QUEUE_CFG, size, timeout);
752
753 if (queue < 0) {
754 IWL_DEBUG_TX_QUEUES(mvm,
755 "Failed allocating TXQ for sta %d tid %d, ret: %d\n",
756 sta_id, tid, queue);
757 return queue;
758 }
759
760 IWL_DEBUG_TX_QUEUES(mvm, "Enabling TXQ #%d for sta %d tid %d\n",
761 queue, sta_id, tid);
762
763 IWL_DEBUG_TX_QUEUES(mvm, "Enabling TXQ #%d\n", queue);
764
765 return queue;
766}
767
768static int iwl_mvm_sta_alloc_queue_tvqm(struct iwl_mvm *mvm,
769 struct ieee80211_sta *sta, u8 ac,
770 int tid)
771{
772 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
773 struct iwl_mvm_txq *mvmtxq =
774 iwl_mvm_txq_from_tid(sta, tid);
775 unsigned int wdg_timeout =
776 iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
777 int queue = -1;
778
779 lockdep_assert_held(&mvm->mutex);
780
781 IWL_DEBUG_TX_QUEUES(mvm,
782 "Allocating queue for sta %d on tid %d\n",
783 mvmsta->sta_id, tid);
784 queue = iwl_mvm_tvqm_enable_txq(mvm, mvmsta->sta_id, tid, wdg_timeout);
785 if (queue < 0)
786 return queue;
787
788 mvmtxq->txq_id = queue;
789 mvm->tvqm_info[queue].txq_tid = tid;
790 mvm->tvqm_info[queue].sta_id = mvmsta->sta_id;
791
792 IWL_DEBUG_TX_QUEUES(mvm, "Allocated queue is %d\n", queue);
793
794 spin_lock_bh(&mvmsta->lock);
795 mvmsta->tid_data[tid].txq_id = queue;
796 spin_unlock_bh(&mvmsta->lock);
797
798 return 0;
799}
800
801static bool iwl_mvm_update_txq_mapping(struct iwl_mvm *mvm,
802 struct ieee80211_sta *sta,
803 int queue, u8 sta_id, u8 tid)
804{
805 bool enable_queue = true;
806
807
808 if (mvm->queue_info[queue].tid_bitmap & BIT(tid)) {
809 IWL_ERR(mvm, "Trying to enable TXQ %d with existing TID %d\n",
810 queue, tid);
811 return false;
812 }
813
814
815 if (mvm->queue_info[queue].tid_bitmap)
816 enable_queue = false;
817
818 mvm->queue_info[queue].tid_bitmap |= BIT(tid);
819 mvm->queue_info[queue].ra_sta_id = sta_id;
820
821 if (enable_queue) {
822 if (tid != IWL_MAX_TID_COUNT)
823 mvm->queue_info[queue].mac80211_ac =
824 tid_to_mac80211_ac[tid];
825 else
826 mvm->queue_info[queue].mac80211_ac = IEEE80211_AC_VO;
827
828 mvm->queue_info[queue].txq_tid = tid;
829 }
830
831 if (sta) {
832 struct iwl_mvm_txq *mvmtxq =
833 iwl_mvm_txq_from_tid(sta, tid);
834
835 mvmtxq->txq_id = queue;
836 }
837
838 IWL_DEBUG_TX_QUEUES(mvm,
839 "Enabling TXQ #%d tids=0x%x\n",
840 queue, mvm->queue_info[queue].tid_bitmap);
841
842 return enable_queue;
843}
844
845static bool iwl_mvm_enable_txq(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
846 int queue, u16 ssn,
847 const struct iwl_trans_txq_scd_cfg *cfg,
848 unsigned int wdg_timeout)
849{
850 struct iwl_scd_txq_cfg_cmd cmd = {
851 .scd_queue = queue,
852 .action = SCD_CFG_ENABLE_QUEUE,
853 .window = cfg->frame_limit,
854 .sta_id = cfg->sta_id,
855 .ssn = cpu_to_le16(ssn),
856 .tx_fifo = cfg->fifo,
857 .aggregate = cfg->aggregate,
858 .tid = cfg->tid,
859 };
860 bool inc_ssn;
861
862 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
863 return false;
864
865
866 if (!iwl_mvm_update_txq_mapping(mvm, sta, queue, cfg->sta_id, cfg->tid))
867 return false;
868
869 inc_ssn = iwl_trans_txq_enable_cfg(mvm->trans, queue, ssn,
870 NULL, wdg_timeout);
871 if (inc_ssn)
872 le16_add_cpu(&cmd.ssn, 1);
873
874 WARN(iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd),
875 "Failed to configure queue %d on FIFO %d\n", queue, cfg->fifo);
876
877 return inc_ssn;
878}
879
880static void iwl_mvm_change_queue_tid(struct iwl_mvm *mvm, int queue)
881{
882 struct iwl_scd_txq_cfg_cmd cmd = {
883 .scd_queue = queue,
884 .action = SCD_CFG_UPDATE_QUEUE_TID,
885 };
886 int tid;
887 unsigned long tid_bitmap;
888 int ret;
889
890 lockdep_assert_held(&mvm->mutex);
891
892 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
893 return;
894
895 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
896
897 if (WARN(!tid_bitmap, "TXQ %d has no tids assigned to it\n", queue))
898 return;
899
900
901 tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1);
902 cmd.tid = tid;
903 cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
904
905 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd);
906 if (ret) {
907 IWL_ERR(mvm, "Failed to update owner of TXQ %d (ret=%d)\n",
908 queue, ret);
909 return;
910 }
911
912 mvm->queue_info[queue].txq_tid = tid;
913 IWL_DEBUG_TX_QUEUES(mvm, "Changed TXQ %d ownership to tid %d\n",
914 queue, tid);
915}
916
917static void iwl_mvm_unshare_queue(struct iwl_mvm *mvm, int queue)
918{
919 struct ieee80211_sta *sta;
920 struct iwl_mvm_sta *mvmsta;
921 u8 sta_id;
922 int tid = -1;
923 unsigned long tid_bitmap;
924 unsigned int wdg_timeout;
925 int ssn;
926 int ret = true;
927
928
929 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
930 return;
931
932 lockdep_assert_held(&mvm->mutex);
933
934 sta_id = mvm->queue_info[queue].ra_sta_id;
935 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
936
937
938 tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1);
939 if (tid_bitmap != BIT(tid)) {
940 IWL_ERR(mvm, "Failed to unshare q %d, active tids=0x%lx\n",
941 queue, tid_bitmap);
942 return;
943 }
944
945 IWL_DEBUG_TX_QUEUES(mvm, "Unsharing TXQ %d, keeping tid %d\n", queue,
946 tid);
947
948 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
949 lockdep_is_held(&mvm->mutex));
950
951 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
952 return;
953
954 mvmsta = iwl_mvm_sta_from_mac80211(sta);
955 wdg_timeout = iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
956
957 ssn = IEEE80211_SEQ_TO_SN(mvmsta->tid_data[tid].seq_number);
958
959 ret = iwl_mvm_redirect_queue(mvm, queue, tid,
960 tid_to_mac80211_ac[tid], ssn,
961 wdg_timeout, true,
962 iwl_mvm_txq_from_tid(sta, tid));
963 if (ret) {
964 IWL_ERR(mvm, "Failed to redirect TXQ %d\n", queue);
965 return;
966 }
967
968
969 if (mvmsta->tid_data[tid].state == IWL_AGG_ON) {
970 struct iwl_mvm_add_sta_cmd cmd = {0};
971
972 mvmsta->tid_disable_agg &= ~BIT(tid);
973
974 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
975 cmd.sta_id = mvmsta->sta_id;
976 cmd.add_modify = STA_MODE_MODIFY;
977 cmd.modify_mask = STA_MODIFY_TID_DISABLE_TX;
978 cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk);
979 cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg);
980
981 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
982 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
983 if (!ret) {
984 IWL_DEBUG_TX_QUEUES(mvm,
985 "TXQ #%d is now aggregated again\n",
986 queue);
987
988
989 iwl_trans_txq_set_shared_mode(mvm->trans, queue, false);
990 }
991 }
992
993 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
994}
995
996
997
998
999
1000
1001
1002
1003static bool iwl_mvm_remove_inactive_tids(struct iwl_mvm *mvm,
1004 struct iwl_mvm_sta *mvmsta, int queue,
1005 unsigned long tid_bitmap,
1006 unsigned long *unshare_queues,
1007 unsigned long *changetid_queues)
1008{
1009 int tid;
1010
1011 lockdep_assert_held(&mvmsta->lock);
1012 lockdep_assert_held(&mvm->mutex);
1013
1014 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
1015 return false;
1016
1017
1018 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
1019
1020 if (iwl_mvm_tid_queued(mvm, &mvmsta->tid_data[tid]))
1021 tid_bitmap &= ~BIT(tid);
1022
1023
1024 if (mvmsta->tid_data[tid].state != IWL_AGG_OFF)
1025 tid_bitmap &= ~BIT(tid);
1026 }
1027
1028
1029 if (tid_bitmap == mvm->queue_info[queue].tid_bitmap) {
1030 IWL_DEBUG_TX_QUEUES(mvm, "Queue %d is inactive\n", queue);
1031 return true;
1032 }
1033
1034
1035
1036
1037
1038 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
1039 u16 tid_bitmap;
1040
1041 mvmsta->tid_data[tid].txq_id = IWL_MVM_INVALID_QUEUE;
1042 mvm->queue_info[queue].tid_bitmap &= ~BIT(tid);
1043
1044 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057 if (!(tid_bitmap & BIT(mvm->queue_info[queue].txq_tid)))
1058 set_bit(queue, changetid_queues);
1059
1060 IWL_DEBUG_TX_QUEUES(mvm,
1061 "Removing inactive TID %d from shared Q:%d\n",
1062 tid, queue);
1063 }
1064
1065 IWL_DEBUG_TX_QUEUES(mvm,
1066 "TXQ #%d left with tid bitmap 0x%x\n", queue,
1067 mvm->queue_info[queue].tid_bitmap);
1068
1069
1070
1071
1072
1073 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
1074
1075
1076 if (hweight16(mvm->queue_info[queue].tid_bitmap) == 1 &&
1077 mvm->queue_info[queue].status == IWL_MVM_QUEUE_SHARED) {
1078 IWL_DEBUG_TX_QUEUES(mvm, "Marking Q:%d for reconfig\n",
1079 queue);
1080 set_bit(queue, unshare_queues);
1081 }
1082
1083 return false;
1084}
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095static int iwl_mvm_inactivity_check(struct iwl_mvm *mvm, u8 alloc_for_sta)
1096{
1097 unsigned long now = jiffies;
1098 unsigned long unshare_queues = 0;
1099 unsigned long changetid_queues = 0;
1100 int i, ret, free_queue = -ENOSPC;
1101 struct ieee80211_sta *queue_owner = NULL;
1102
1103 lockdep_assert_held(&mvm->mutex);
1104
1105 if (iwl_mvm_has_new_tx_api(mvm))
1106 return -ENOSPC;
1107
1108 rcu_read_lock();
1109
1110
1111 BUILD_BUG_ON(IWL_MVM_DQA_CMD_QUEUE != 0);
1112
1113 for (i = 1; i < IWL_MAX_HW_QUEUES; i++) {
1114 struct ieee80211_sta *sta;
1115 struct iwl_mvm_sta *mvmsta;
1116 u8 sta_id;
1117 int tid;
1118 unsigned long inactive_tid_bitmap = 0;
1119 unsigned long queue_tid_bitmap;
1120
1121 queue_tid_bitmap = mvm->queue_info[i].tid_bitmap;
1122 if (!queue_tid_bitmap)
1123 continue;
1124
1125
1126 if (mvm->queue_info[i].status != IWL_MVM_QUEUE_READY &&
1127 mvm->queue_info[i].status != IWL_MVM_QUEUE_SHARED)
1128 continue;
1129
1130
1131 for_each_set_bit(tid, &queue_tid_bitmap,
1132 IWL_MAX_TID_COUNT + 1) {
1133 if (time_after(mvm->queue_info[i].last_frame_time[tid] +
1134 IWL_MVM_DQA_QUEUE_TIMEOUT, now))
1135 continue;
1136
1137 inactive_tid_bitmap |= BIT(tid);
1138 }
1139
1140
1141 if (!inactive_tid_bitmap)
1142 continue;
1143
1144
1145
1146
1147
1148
1149 sta_id = mvm->queue_info[i].ra_sta_id;
1150 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1151
1152
1153
1154
1155
1156
1157 if (IS_ERR_OR_NULL(sta))
1158 continue;
1159
1160 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1161
1162 spin_lock_bh(&mvmsta->lock);
1163 ret = iwl_mvm_remove_inactive_tids(mvm, mvmsta, i,
1164 inactive_tid_bitmap,
1165 &unshare_queues,
1166 &changetid_queues);
1167 if (ret >= 0 && free_queue < 0) {
1168 queue_owner = sta;
1169 free_queue = ret;
1170 }
1171
1172 spin_unlock_bh(&mvmsta->lock);
1173 }
1174
1175
1176
1177 for_each_set_bit(i, &unshare_queues, IWL_MAX_HW_QUEUES)
1178 iwl_mvm_unshare_queue(mvm, i);
1179 for_each_set_bit(i, &changetid_queues, IWL_MAX_HW_QUEUES)
1180 iwl_mvm_change_queue_tid(mvm, i);
1181
1182 if (free_queue >= 0 && alloc_for_sta != IWL_MVM_INVALID_STA) {
1183 ret = iwl_mvm_free_inactive_queue(mvm, free_queue, queue_owner,
1184 alloc_for_sta);
1185 if (ret) {
1186 rcu_read_unlock();
1187 return ret;
1188 }
1189 }
1190
1191 rcu_read_unlock();
1192
1193 return free_queue;
1194}
1195
1196static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm,
1197 struct ieee80211_sta *sta, u8 ac, int tid)
1198{
1199 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1200 struct iwl_trans_txq_scd_cfg cfg = {
1201 .fifo = iwl_mvm_mac_ac_to_tx_fifo(mvm, ac),
1202 .sta_id = mvmsta->sta_id,
1203 .tid = tid,
1204 .frame_limit = IWL_FRAME_LIMIT,
1205 };
1206 unsigned int wdg_timeout =
1207 iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
1208 int queue = -1;
1209 unsigned long disable_agg_tids = 0;
1210 enum iwl_mvm_agg_state queue_state;
1211 bool shared_queue = false, inc_ssn;
1212 int ssn;
1213 unsigned long tfd_queue_mask;
1214 int ret;
1215
1216 lockdep_assert_held(&mvm->mutex);
1217
1218 if (iwl_mvm_has_new_tx_api(mvm))
1219 return iwl_mvm_sta_alloc_queue_tvqm(mvm, sta, ac, tid);
1220
1221 spin_lock_bh(&mvmsta->lock);
1222 tfd_queue_mask = mvmsta->tfd_queue_msk;
1223 ssn = IEEE80211_SEQ_TO_SN(mvmsta->tid_data[tid].seq_number);
1224 spin_unlock_bh(&mvmsta->lock);
1225
1226 if (tid == IWL_MAX_TID_COUNT) {
1227 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
1228 IWL_MVM_DQA_MIN_MGMT_QUEUE,
1229 IWL_MVM_DQA_MAX_MGMT_QUEUE);
1230 if (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE)
1231 IWL_DEBUG_TX_QUEUES(mvm, "Found free MGMT queue #%d\n",
1232 queue);
1233
1234
1235 }
1236
1237 if ((queue < 0 && mvmsta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) &&
1238 (mvm->queue_info[mvmsta->reserved_queue].status ==
1239 IWL_MVM_QUEUE_RESERVED)) {
1240 queue = mvmsta->reserved_queue;
1241 mvm->queue_info[queue].reserved = true;
1242 IWL_DEBUG_TX_QUEUES(mvm, "Using reserved queue #%d\n", queue);
1243 }
1244
1245 if (queue < 0)
1246 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
1247 IWL_MVM_DQA_MIN_DATA_QUEUE,
1248 IWL_MVM_DQA_MAX_DATA_QUEUE);
1249 if (queue < 0) {
1250
1251 queue = iwl_mvm_inactivity_check(mvm, mvmsta->sta_id);
1252 }
1253
1254
1255 if (queue <= 0) {
1256 queue = iwl_mvm_get_shared_queue(mvm, tfd_queue_mask, ac);
1257 if (queue > 0) {
1258 shared_queue = true;
1259 mvm->queue_info[queue].status = IWL_MVM_QUEUE_SHARED;
1260 }
1261 }
1262
1263
1264
1265
1266
1267
1268
1269 if (queue > 0 && !shared_queue)
1270 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
1271
1272
1273 if (WARN_ON(queue <= 0)) {
1274 IWL_ERR(mvm, "No available queues for tid %d on sta_id %d\n",
1275 tid, cfg.sta_id);
1276 return queue;
1277 }
1278
1279
1280
1281
1282
1283
1284
1285 cfg.aggregate = (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
1286 queue == IWL_MVM_DQA_BSS_CLIENT_QUEUE);
1287
1288 IWL_DEBUG_TX_QUEUES(mvm,
1289 "Allocating %squeue #%d to sta %d on tid %d\n",
1290 shared_queue ? "shared " : "", queue,
1291 mvmsta->sta_id, tid);
1292
1293 if (shared_queue) {
1294
1295 disable_agg_tids = iwl_mvm_get_queue_agg_tids(mvm, queue);
1296
1297 if (disable_agg_tids) {
1298 IWL_DEBUG_TX_QUEUES(mvm, "Disabling aggs on queue %d\n",
1299 queue);
1300 iwl_mvm_invalidate_sta_queue(mvm, queue,
1301 disable_agg_tids, false);
1302 }
1303 }
1304
1305 inc_ssn = iwl_mvm_enable_txq(mvm, sta, queue, ssn, &cfg, wdg_timeout);
1306
1307
1308
1309
1310
1311
1312
1313 if (shared_queue)
1314 iwl_trans_txq_set_shared_mode(mvm->trans, queue, true);
1315
1316 spin_lock_bh(&mvmsta->lock);
1317
1318
1319
1320
1321
1322 if (inc_ssn) {
1323 mvmsta->tid_data[tid].seq_number += 0x10;
1324 ssn = (ssn + 1) & IEEE80211_SCTL_SEQ;
1325 }
1326 mvmsta->tid_data[tid].txq_id = queue;
1327 mvmsta->tfd_queue_msk |= BIT(queue);
1328 queue_state = mvmsta->tid_data[tid].state;
1329
1330 if (mvmsta->reserved_queue == queue)
1331 mvmsta->reserved_queue = IEEE80211_INVAL_HW_QUEUE;
1332 spin_unlock_bh(&mvmsta->lock);
1333
1334 if (!shared_queue) {
1335 ret = iwl_mvm_sta_send_to_fw(mvm, sta, true, STA_MODIFY_QUEUES);
1336 if (ret)
1337 goto out_err;
1338
1339
1340 if (queue_state == IWL_AGG_ON) {
1341 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
1342 if (ret)
1343 goto out_err;
1344 }
1345 } else {
1346
1347 ret = iwl_mvm_redirect_queue(mvm, queue, tid, ac, ssn,
1348 wdg_timeout, false,
1349 iwl_mvm_txq_from_tid(sta, tid));
1350 if (ret)
1351 goto out_err;
1352 }
1353
1354 return 0;
1355
1356out_err:
1357 iwl_mvm_disable_txq(mvm, sta, queue, tid, 0);
1358
1359 return ret;
1360}
1361
1362static inline u8 iwl_mvm_tid_to_ac_queue(int tid)
1363{
1364 if (tid == IWL_MAX_TID_COUNT)
1365 return IEEE80211_AC_VO;
1366
1367 return tid_to_mac80211_ac[tid];
1368}
1369
1370void iwl_mvm_add_new_dqa_stream_wk(struct work_struct *wk)
1371{
1372 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm,
1373 add_stream_wk);
1374
1375 mutex_lock(&mvm->mutex);
1376
1377 iwl_mvm_inactivity_check(mvm, IWL_MVM_INVALID_STA);
1378
1379 while (!list_empty(&mvm->add_stream_txqs)) {
1380 struct iwl_mvm_txq *mvmtxq;
1381 struct ieee80211_txq *txq;
1382 u8 tid;
1383
1384 mvmtxq = list_first_entry(&mvm->add_stream_txqs,
1385 struct iwl_mvm_txq, list);
1386
1387 txq = container_of((void *)mvmtxq, struct ieee80211_txq,
1388 drv_priv);
1389 tid = txq->tid;
1390 if (tid == IEEE80211_NUM_TIDS)
1391 tid = IWL_MAX_TID_COUNT;
1392
1393 iwl_mvm_sta_alloc_queue(mvm, txq->sta, txq->ac, tid);
1394 list_del_init(&mvmtxq->list);
1395 local_bh_disable();
1396 iwl_mvm_mac_itxq_xmit(mvm->hw, txq);
1397 local_bh_enable();
1398 }
1399
1400 mutex_unlock(&mvm->mutex);
1401}
1402
1403static int iwl_mvm_reserve_sta_stream(struct iwl_mvm *mvm,
1404 struct ieee80211_sta *sta,
1405 enum nl80211_iftype vif_type)
1406{
1407 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1408 int queue;
1409
1410
1411 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
1412 return 0;
1413
1414
1415 iwl_mvm_inactivity_check(mvm, IWL_MVM_INVALID_STA);
1416
1417
1418 if (vif_type == NL80211_IFTYPE_STATION && !sta->tdls &&
1419 !mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].tid_bitmap &&
1420 (mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].status ==
1421 IWL_MVM_QUEUE_FREE))
1422 queue = IWL_MVM_DQA_BSS_CLIENT_QUEUE;
1423 else
1424 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
1425 IWL_MVM_DQA_MIN_DATA_QUEUE,
1426 IWL_MVM_DQA_MAX_DATA_QUEUE);
1427 if (queue < 0) {
1428
1429 queue = iwl_mvm_inactivity_check(mvm, mvmsta->sta_id);
1430 if (queue < 0) {
1431 IWL_ERR(mvm, "No available queues for new station\n");
1432 return -ENOSPC;
1433 }
1434 }
1435 mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED;
1436
1437 mvmsta->reserved_queue = queue;
1438
1439 IWL_DEBUG_TX_QUEUES(mvm, "Reserving data queue #%d for sta_id %d\n",
1440 queue, mvmsta->sta_id);
1441
1442 return 0;
1443}
1444
1445
1446
1447
1448
1449
1450
1451
1452static void iwl_mvm_realloc_queues_after_restart(struct iwl_mvm *mvm,
1453 struct ieee80211_sta *sta)
1454{
1455 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1456 unsigned int wdg =
1457 iwl_mvm_get_wd_timeout(mvm, mvm_sta->vif, false, false);
1458 int i;
1459 struct iwl_trans_txq_scd_cfg cfg = {
1460 .sta_id = mvm_sta->sta_id,
1461 .frame_limit = IWL_FRAME_LIMIT,
1462 };
1463
1464
1465 if (mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE)
1466 mvm->queue_info[mvm_sta->reserved_queue].status =
1467 IWL_MVM_QUEUE_RESERVED;
1468
1469 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
1470 struct iwl_mvm_tid_data *tid_data = &mvm_sta->tid_data[i];
1471 int txq_id = tid_data->txq_id;
1472 int ac;
1473
1474 if (txq_id == IWL_MVM_INVALID_QUEUE)
1475 continue;
1476
1477 ac = tid_to_mac80211_ac[i];
1478
1479 if (iwl_mvm_has_new_tx_api(mvm)) {
1480 IWL_DEBUG_TX_QUEUES(mvm,
1481 "Re-mapping sta %d tid %d\n",
1482 mvm_sta->sta_id, i);
1483 txq_id = iwl_mvm_tvqm_enable_txq(mvm, mvm_sta->sta_id,
1484 i, wdg);
1485
1486
1487
1488
1489
1490 if (txq_id < 0)
1491 txq_id = IWL_MVM_INVALID_QUEUE;
1492 tid_data->txq_id = txq_id;
1493
1494
1495
1496
1497
1498
1499
1500 tid_data->seq_number = 0;
1501 } else {
1502 u16 seq = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
1503
1504 cfg.tid = i;
1505 cfg.fifo = iwl_mvm_mac_ac_to_tx_fifo(mvm, ac);
1506 cfg.aggregate = (txq_id >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
1507 txq_id ==
1508 IWL_MVM_DQA_BSS_CLIENT_QUEUE);
1509
1510 IWL_DEBUG_TX_QUEUES(mvm,
1511 "Re-mapping sta %d tid %d to queue %d\n",
1512 mvm_sta->sta_id, i, txq_id);
1513
1514 iwl_mvm_enable_txq(mvm, sta, txq_id, seq, &cfg, wdg);
1515 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_READY;
1516 }
1517 }
1518}
1519
1520static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm,
1521 struct iwl_mvm_int_sta *sta,
1522 const u8 *addr,
1523 u16 mac_id, u16 color)
1524{
1525 struct iwl_mvm_add_sta_cmd cmd;
1526 int ret;
1527 u32 status = ADD_STA_SUCCESS;
1528
1529 lockdep_assert_held(&mvm->mutex);
1530
1531 memset(&cmd, 0, sizeof(cmd));
1532 cmd.sta_id = sta->sta_id;
1533 cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id,
1534 color));
1535 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
1536 cmd.station_type = sta->type;
1537
1538 if (!iwl_mvm_has_new_tx_api(mvm))
1539 cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk);
1540 cmd.tid_disable_tx = cpu_to_le16(0xffff);
1541
1542 if (addr)
1543 memcpy(cmd.addr, addr, ETH_ALEN);
1544
1545 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1546 iwl_mvm_add_sta_cmd_size(mvm),
1547 &cmd, &status);
1548 if (ret)
1549 return ret;
1550
1551 switch (status & IWL_ADD_STA_STATUS_MASK) {
1552 case ADD_STA_SUCCESS:
1553 IWL_DEBUG_INFO(mvm, "Internal station added.\n");
1554 return 0;
1555 default:
1556 ret = -EIO;
1557 IWL_ERR(mvm, "Add internal station failed, status=0x%x\n",
1558 status);
1559 break;
1560 }
1561 return ret;
1562}
1563
1564int iwl_mvm_add_sta(struct iwl_mvm *mvm,
1565 struct ieee80211_vif *vif,
1566 struct ieee80211_sta *sta)
1567{
1568 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1569 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1570 struct iwl_mvm_rxq_dup_data *dup_data;
1571 int i, ret, sta_id;
1572 bool sta_update = false;
1573 unsigned int sta_flags = 0;
1574
1575 lockdep_assert_held(&mvm->mutex);
1576
1577 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1578 sta_id = iwl_mvm_find_free_sta_id(mvm,
1579 ieee80211_vif_type_p2p(vif));
1580 else
1581 sta_id = mvm_sta->sta_id;
1582
1583 if (sta_id == IWL_MVM_INVALID_STA)
1584 return -ENOSPC;
1585
1586 spin_lock_init(&mvm_sta->lock);
1587
1588
1589 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1590 struct iwl_mvm_int_sta tmp_sta = {
1591 .sta_id = sta_id,
1592 .type = mvm_sta->sta_type,
1593 };
1594
1595
1596
1597
1598
1599 ret = iwl_mvm_add_int_sta_common(mvm, &tmp_sta, sta->addr,
1600 mvmvif->id, mvmvif->color);
1601 if (ret)
1602 goto err;
1603
1604 iwl_mvm_realloc_queues_after_restart(mvm, sta);
1605 sta_update = true;
1606 sta_flags = iwl_mvm_has_new_tx_api(mvm) ? 0 : STA_MODIFY_QUEUES;
1607 goto update_fw;
1608 }
1609
1610 mvm_sta->sta_id = sta_id;
1611 mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id,
1612 mvmvif->color);
1613 mvm_sta->vif = vif;
1614 if (!mvm->trans->trans_cfg->gen2)
1615 mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
1616 else
1617 mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_GEN2_DEF;
1618 mvm_sta->tx_protection = 0;
1619 mvm_sta->tt_tx_protection = false;
1620 mvm_sta->sta_type = sta->tdls ? IWL_STA_TDLS_LINK : IWL_STA_LINK;
1621
1622
1623 mvm_sta->tid_disable_agg = 0xffff;
1624 mvm_sta->tfd_queue_msk = 0;
1625
1626
1627 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
1628 u16 seq = mvm_sta->tid_data[i].seq_number;
1629 memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i]));
1630 mvm_sta->tid_data[i].seq_number = seq;
1631
1632
1633
1634
1635
1636 mvm_sta->tid_data[i].txq_id = IWL_MVM_INVALID_QUEUE;
1637 }
1638
1639 for (i = 0; i < ARRAY_SIZE(sta->txq); i++) {
1640 struct iwl_mvm_txq *mvmtxq =
1641 iwl_mvm_txq_from_mac80211(sta->txq[i]);
1642
1643 mvmtxq->txq_id = IWL_MVM_INVALID_QUEUE;
1644 INIT_LIST_HEAD(&mvmtxq->list);
1645 atomic_set(&mvmtxq->tx_request, 0);
1646 }
1647
1648 mvm_sta->agg_tids = 0;
1649
1650 if (iwl_mvm_has_new_rx_api(mvm) &&
1651 !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1652 int q;
1653
1654 dup_data = kcalloc(mvm->trans->num_rx_queues,
1655 sizeof(*dup_data), GFP_KERNEL);
1656 if (!dup_data)
1657 return -ENOMEM;
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667 for (q = 0; q < mvm->trans->num_rx_queues; q++)
1668 memset(dup_data[q].last_seq, 0xff,
1669 sizeof(dup_data[q].last_seq));
1670 mvm_sta->dup_data = dup_data;
1671 }
1672
1673 if (!iwl_mvm_has_new_tx_api(mvm)) {
1674 ret = iwl_mvm_reserve_sta_stream(mvm, sta,
1675 ieee80211_vif_type_p2p(vif));
1676 if (ret)
1677 goto err;
1678 }
1679
1680
1681
1682
1683
1684 if (iwl_mvm_has_tlc_offload(mvm))
1685 iwl_mvm_rs_add_sta(mvm, mvm_sta);
1686 else
1687 spin_lock_init(&mvm_sta->lq_sta.rs_drv.pers.lock);
1688
1689 iwl_mvm_toggle_tx_ant(mvm, &mvm_sta->tx_ant);
1690
1691update_fw:
1692 ret = iwl_mvm_sta_send_to_fw(mvm, sta, sta_update, sta_flags);
1693 if (ret)
1694 goto err;
1695
1696 if (vif->type == NL80211_IFTYPE_STATION) {
1697 if (!sta->tdls) {
1698 WARN_ON(mvmvif->ap_sta_id != IWL_MVM_INVALID_STA);
1699 mvmvif->ap_sta_id = sta_id;
1700 } else {
1701 WARN_ON(mvmvif->ap_sta_id == IWL_MVM_INVALID_STA);
1702 }
1703 }
1704
1705 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta);
1706
1707 return 0;
1708
1709err:
1710 return ret;
1711}
1712
1713int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
1714 bool drain)
1715{
1716 struct iwl_mvm_add_sta_cmd cmd = {};
1717 int ret;
1718 u32 status;
1719
1720 lockdep_assert_held(&mvm->mutex);
1721
1722 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
1723 cmd.sta_id = mvmsta->sta_id;
1724 cmd.add_modify = STA_MODE_MODIFY;
1725 cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0;
1726 cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW);
1727
1728 status = ADD_STA_SUCCESS;
1729 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1730 iwl_mvm_add_sta_cmd_size(mvm),
1731 &cmd, &status);
1732 if (ret)
1733 return ret;
1734
1735 switch (status & IWL_ADD_STA_STATUS_MASK) {
1736 case ADD_STA_SUCCESS:
1737 IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n",
1738 mvmsta->sta_id);
1739 break;
1740 default:
1741 ret = -EIO;
1742 IWL_ERR(mvm, "Couldn't drain frames for staid %d\n",
1743 mvmsta->sta_id);
1744 break;
1745 }
1746
1747 return ret;
1748}
1749
1750
1751
1752
1753
1754
1755static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id)
1756{
1757 struct ieee80211_sta *sta;
1758 struct iwl_mvm_rm_sta_cmd rm_sta_cmd = {
1759 .sta_id = sta_id,
1760 };
1761 int ret;
1762
1763 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1764 lockdep_is_held(&mvm->mutex));
1765
1766
1767 if (!sta) {
1768 IWL_ERR(mvm, "Invalid station id\n");
1769 return -EINVAL;
1770 }
1771
1772 ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0,
1773 sizeof(rm_sta_cmd), &rm_sta_cmd);
1774 if (ret) {
1775 IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id);
1776 return ret;
1777 }
1778
1779 return 0;
1780}
1781
1782static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm,
1783 struct ieee80211_vif *vif,
1784 struct ieee80211_sta *sta)
1785{
1786 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1787 int i;
1788
1789 lockdep_assert_held(&mvm->mutex);
1790
1791 for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) {
1792 if (mvm_sta->tid_data[i].txq_id == IWL_MVM_INVALID_QUEUE)
1793 continue;
1794
1795 iwl_mvm_disable_txq(mvm, sta, mvm_sta->tid_data[i].txq_id, i,
1796 0);
1797 mvm_sta->tid_data[i].txq_id = IWL_MVM_INVALID_QUEUE;
1798 }
1799
1800 for (i = 0; i < ARRAY_SIZE(sta->txq); i++) {
1801 struct iwl_mvm_txq *mvmtxq =
1802 iwl_mvm_txq_from_mac80211(sta->txq[i]);
1803
1804 mvmtxq->txq_id = IWL_MVM_INVALID_QUEUE;
1805 }
1806}
1807
1808int iwl_mvm_wait_sta_queues_empty(struct iwl_mvm *mvm,
1809 struct iwl_mvm_sta *mvm_sta)
1810{
1811 int i;
1812
1813 for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) {
1814 u16 txq_id;
1815 int ret;
1816
1817 spin_lock_bh(&mvm_sta->lock);
1818 txq_id = mvm_sta->tid_data[i].txq_id;
1819 spin_unlock_bh(&mvm_sta->lock);
1820
1821 if (txq_id == IWL_MVM_INVALID_QUEUE)
1822 continue;
1823
1824 ret = iwl_trans_wait_txq_empty(mvm->trans, txq_id);
1825 if (ret)
1826 return ret;
1827 }
1828
1829 return 0;
1830}
1831
1832int iwl_mvm_rm_sta(struct iwl_mvm *mvm,
1833 struct ieee80211_vif *vif,
1834 struct ieee80211_sta *sta)
1835{
1836 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1837 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1838 u8 sta_id = mvm_sta->sta_id;
1839 int ret;
1840
1841 lockdep_assert_held(&mvm->mutex);
1842
1843 if (iwl_mvm_has_new_rx_api(mvm))
1844 kfree(mvm_sta->dup_data);
1845
1846 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
1847 if (ret)
1848 return ret;
1849
1850
1851 ret = iwl_mvm_flush_sta(mvm, mvm_sta, false, 0);
1852 if (ret)
1853 return ret;
1854 if (iwl_mvm_has_new_tx_api(mvm)) {
1855 ret = iwl_mvm_wait_sta_queues_empty(mvm, mvm_sta);
1856 } else {
1857 u32 q_mask = mvm_sta->tfd_queue_msk;
1858
1859 ret = iwl_trans_wait_tx_queues_empty(mvm->trans,
1860 q_mask);
1861 }
1862 if (ret)
1863 return ret;
1864
1865 ret = iwl_mvm_drain_sta(mvm, mvm_sta, false);
1866
1867 iwl_mvm_disable_sta_queues(mvm, vif, sta);
1868
1869
1870 if (mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) {
1871 u8 reserved_txq = mvm_sta->reserved_queue;
1872 enum iwl_mvm_queue_status *status;
1873
1874
1875
1876
1877
1878
1879 status = &mvm->queue_info[reserved_txq].status;
1880 if (WARN((*status != IWL_MVM_QUEUE_RESERVED) &&
1881 (*status != IWL_MVM_QUEUE_FREE),
1882 "sta_id %d reserved txq %d status %d",
1883 sta_id, reserved_txq, *status))
1884 return -EINVAL;
1885
1886 *status = IWL_MVM_QUEUE_FREE;
1887 }
1888
1889 if (vif->type == NL80211_IFTYPE_STATION &&
1890 mvmvif->ap_sta_id == sta_id) {
1891
1892 if (vif->bss_conf.assoc)
1893 return ret;
1894
1895
1896 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1897 }
1898
1899
1900
1901
1902
1903 if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == sta_id)) {
1904 mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA;
1905 cancel_delayed_work(&mvm->tdls_cs.dwork);
1906 }
1907
1908
1909
1910
1911
1912 spin_lock_bh(&mvm_sta->lock);
1913 spin_unlock_bh(&mvm_sta->lock);
1914
1915 ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id);
1916 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL);
1917
1918 return ret;
1919}
1920
1921int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm,
1922 struct ieee80211_vif *vif,
1923 u8 sta_id)
1924{
1925 int ret = iwl_mvm_rm_sta_common(mvm, sta_id);
1926
1927 lockdep_assert_held(&mvm->mutex);
1928
1929 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
1930 return ret;
1931}
1932
1933int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm,
1934 struct iwl_mvm_int_sta *sta,
1935 u32 qmask, enum nl80211_iftype iftype,
1936 enum iwl_sta_type type)
1937{
1938 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
1939 sta->sta_id == IWL_MVM_INVALID_STA) {
1940 sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype);
1941 if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_INVALID_STA))
1942 return -ENOSPC;
1943 }
1944
1945 sta->tfd_queue_msk = qmask;
1946 sta->type = type;
1947
1948
1949 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL));
1950 return 0;
1951}
1952
1953void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm, struct iwl_mvm_int_sta *sta)
1954{
1955 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta->sta_id], NULL);
1956 memset(sta, 0, sizeof(struct iwl_mvm_int_sta));
1957 sta->sta_id = IWL_MVM_INVALID_STA;
1958}
1959
1960static void iwl_mvm_enable_aux_snif_queue(struct iwl_mvm *mvm, u16 queue,
1961 u8 sta_id, u8 fifo)
1962{
1963 unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ?
1964 mvm->trans->trans_cfg->base_params->wd_timeout :
1965 IWL_WATCHDOG_DISABLED;
1966 struct iwl_trans_txq_scd_cfg cfg = {
1967 .fifo = fifo,
1968 .sta_id = sta_id,
1969 .tid = IWL_MAX_TID_COUNT,
1970 .aggregate = false,
1971 .frame_limit = IWL_FRAME_LIMIT,
1972 };
1973
1974 WARN_ON(iwl_mvm_has_new_tx_api(mvm));
1975
1976 iwl_mvm_enable_txq(mvm, NULL, queue, 0, &cfg, wdg_timeout);
1977}
1978
1979static int iwl_mvm_enable_aux_snif_queue_tvqm(struct iwl_mvm *mvm, u8 sta_id)
1980{
1981 unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ?
1982 mvm->trans->trans_cfg->base_params->wd_timeout :
1983 IWL_WATCHDOG_DISABLED;
1984
1985 WARN_ON(!iwl_mvm_has_new_tx_api(mvm));
1986
1987 return iwl_mvm_tvqm_enable_txq(mvm, sta_id, IWL_MAX_TID_COUNT,
1988 wdg_timeout);
1989}
1990
1991static int iwl_mvm_add_int_sta_with_queue(struct iwl_mvm *mvm, int macidx,
1992 int maccolor,
1993 struct iwl_mvm_int_sta *sta,
1994 u16 *queue, int fifo)
1995{
1996 int ret;
1997
1998
1999 if (!iwl_mvm_has_new_tx_api(mvm))
2000 iwl_mvm_enable_aux_snif_queue(mvm, *queue, sta->sta_id, fifo);
2001
2002 ret = iwl_mvm_add_int_sta_common(mvm, sta, NULL, macidx, maccolor);
2003 if (ret) {
2004 if (!iwl_mvm_has_new_tx_api(mvm))
2005 iwl_mvm_disable_txq(mvm, NULL, *queue,
2006 IWL_MAX_TID_COUNT, 0);
2007 return ret;
2008 }
2009
2010
2011
2012
2013
2014 if (iwl_mvm_has_new_tx_api(mvm)) {
2015 int txq;
2016
2017 txq = iwl_mvm_enable_aux_snif_queue_tvqm(mvm, sta->sta_id);
2018 if (txq < 0) {
2019 iwl_mvm_rm_sta_common(mvm, sta->sta_id);
2020 return txq;
2021 }
2022
2023 *queue = txq;
2024 }
2025
2026 return 0;
2027}
2028
2029int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm)
2030{
2031 int ret;
2032
2033 lockdep_assert_held(&mvm->mutex);
2034
2035
2036 ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue),
2037 NL80211_IFTYPE_UNSPECIFIED,
2038 IWL_STA_AUX_ACTIVITY);
2039 if (ret)
2040 return ret;
2041
2042 ret = iwl_mvm_add_int_sta_with_queue(mvm, MAC_INDEX_AUX, 0,
2043 &mvm->aux_sta, &mvm->aux_queue,
2044 IWL_MVM_TX_FIFO_MCAST);
2045 if (ret) {
2046 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
2047 return ret;
2048 }
2049
2050 return 0;
2051}
2052
2053int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2054{
2055 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2056
2057 lockdep_assert_held(&mvm->mutex);
2058
2059 return iwl_mvm_add_int_sta_with_queue(mvm, mvmvif->id, mvmvif->color,
2060 &mvm->snif_sta, &mvm->snif_queue,
2061 IWL_MVM_TX_FIFO_BE);
2062}
2063
2064int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2065{
2066 int ret;
2067
2068 lockdep_assert_held(&mvm->mutex);
2069
2070 iwl_mvm_disable_txq(mvm, NULL, mvm->snif_queue, IWL_MAX_TID_COUNT, 0);
2071 ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id);
2072 if (ret)
2073 IWL_WARN(mvm, "Failed sending remove station\n");
2074
2075 return ret;
2076}
2077
2078void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm)
2079{
2080 iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta);
2081}
2082
2083void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm)
2084{
2085 lockdep_assert_held(&mvm->mutex);
2086
2087 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
2088}
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2099{
2100 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2101 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
2102 static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
2103 const u8 *baddr = _baddr;
2104 int queue;
2105 int ret;
2106 unsigned int wdg_timeout =
2107 iwl_mvm_get_wd_timeout(mvm, vif, false, false);
2108 struct iwl_trans_txq_scd_cfg cfg = {
2109 .fifo = IWL_MVM_TX_FIFO_VO,
2110 .sta_id = mvmvif->bcast_sta.sta_id,
2111 .tid = IWL_MAX_TID_COUNT,
2112 .aggregate = false,
2113 .frame_limit = IWL_FRAME_LIMIT,
2114 };
2115
2116 lockdep_assert_held(&mvm->mutex);
2117
2118 if (!iwl_mvm_has_new_tx_api(mvm)) {
2119 if (vif->type == NL80211_IFTYPE_AP ||
2120 vif->type == NL80211_IFTYPE_ADHOC) {
2121 queue = mvm->probe_queue;
2122 } else if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
2123 queue = mvm->p2p_dev_queue;
2124 } else {
2125 WARN(1, "Missing required TXQ for adding bcast STA\n");
2126 return -EINVAL;
2127 }
2128
2129 bsta->tfd_queue_msk |= BIT(queue);
2130
2131 iwl_mvm_enable_txq(mvm, NULL, queue, 0, &cfg, wdg_timeout);
2132 }
2133
2134 if (vif->type == NL80211_IFTYPE_ADHOC)
2135 baddr = vif->bss_conf.bssid;
2136
2137 if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_INVALID_STA))
2138 return -ENOSPC;
2139
2140 ret = iwl_mvm_add_int_sta_common(mvm, bsta, baddr,
2141 mvmvif->id, mvmvif->color);
2142 if (ret)
2143 return ret;
2144
2145
2146
2147
2148
2149 if (iwl_mvm_has_new_tx_api(mvm)) {
2150 queue = iwl_mvm_tvqm_enable_txq(mvm, bsta->sta_id,
2151 IWL_MAX_TID_COUNT,
2152 wdg_timeout);
2153 if (queue < 0) {
2154 iwl_mvm_rm_sta_common(mvm, bsta->sta_id);
2155 return queue;
2156 }
2157
2158 if (vif->type == NL80211_IFTYPE_AP ||
2159 vif->type == NL80211_IFTYPE_ADHOC)
2160 mvm->probe_queue = queue;
2161 else if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
2162 mvm->p2p_dev_queue = queue;
2163 }
2164
2165 return 0;
2166}
2167
2168static void iwl_mvm_free_bcast_sta_queues(struct iwl_mvm *mvm,
2169 struct ieee80211_vif *vif)
2170{
2171 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2172 int queue;
2173
2174 lockdep_assert_held(&mvm->mutex);
2175
2176 iwl_mvm_flush_sta(mvm, &mvmvif->bcast_sta, true, 0);
2177
2178 switch (vif->type) {
2179 case NL80211_IFTYPE_AP:
2180 case NL80211_IFTYPE_ADHOC:
2181 queue = mvm->probe_queue;
2182 break;
2183 case NL80211_IFTYPE_P2P_DEVICE:
2184 queue = mvm->p2p_dev_queue;
2185 break;
2186 default:
2187 WARN(1, "Can't free bcast queue on vif type %d\n",
2188 vif->type);
2189 return;
2190 }
2191
2192 iwl_mvm_disable_txq(mvm, NULL, queue, IWL_MAX_TID_COUNT, 0);
2193 if (iwl_mvm_has_new_tx_api(mvm))
2194 return;
2195
2196 WARN_ON(!(mvmvif->bcast_sta.tfd_queue_msk & BIT(queue)));
2197 mvmvif->bcast_sta.tfd_queue_msk &= ~BIT(queue);
2198}
2199
2200
2201
2202int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2203{
2204 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2205 int ret;
2206
2207 lockdep_assert_held(&mvm->mutex);
2208
2209 iwl_mvm_free_bcast_sta_queues(mvm, vif);
2210
2211 ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id);
2212 if (ret)
2213 IWL_WARN(mvm, "Failed sending remove station\n");
2214 return ret;
2215}
2216
2217int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2218{
2219 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2220
2221 lockdep_assert_held(&mvm->mutex);
2222
2223 return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, 0,
2224 ieee80211_vif_type_p2p(vif),
2225 IWL_STA_GENERAL_PURPOSE);
2226}
2227
2228
2229
2230
2231
2232
2233
2234
2235int iwl_mvm_add_p2p_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2236{
2237 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2238 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
2239 int ret;
2240
2241 lockdep_assert_held(&mvm->mutex);
2242
2243 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
2244 if (ret)
2245 return ret;
2246
2247 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
2248
2249 if (ret)
2250 iwl_mvm_dealloc_int_sta(mvm, bsta);
2251
2252 return ret;
2253}
2254
2255void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2256{
2257 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2258
2259 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
2260}
2261
2262
2263
2264
2265
2266int iwl_mvm_rm_p2p_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2267{
2268 int ret;
2269
2270 lockdep_assert_held(&mvm->mutex);
2271
2272 ret = iwl_mvm_send_rm_bcast_sta(mvm, vif);
2273
2274 iwl_mvm_dealloc_bcast_sta(mvm, vif);
2275
2276 return ret;
2277}
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287int iwl_mvm_add_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2288{
2289 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2290 struct iwl_mvm_int_sta *msta = &mvmvif->mcast_sta;
2291 static const u8 _maddr[] = {0x03, 0x00, 0x00, 0x00, 0x00, 0x00};
2292 const u8 *maddr = _maddr;
2293 struct iwl_trans_txq_scd_cfg cfg = {
2294 .fifo = vif->type == NL80211_IFTYPE_AP ?
2295 IWL_MVM_TX_FIFO_MCAST : IWL_MVM_TX_FIFO_BE,
2296 .sta_id = msta->sta_id,
2297 .tid = 0,
2298 .aggregate = false,
2299 .frame_limit = IWL_FRAME_LIMIT,
2300 };
2301 unsigned int timeout = iwl_mvm_get_wd_timeout(mvm, vif, false, false);
2302 int ret;
2303
2304 lockdep_assert_held(&mvm->mutex);
2305
2306 if (WARN_ON(vif->type != NL80211_IFTYPE_AP &&
2307 vif->type != NL80211_IFTYPE_ADHOC))
2308 return -ENOTSUPP;
2309
2310
2311
2312
2313
2314
2315
2316 if (vif->type == NL80211_IFTYPE_ADHOC)
2317 mvmvif->cab_queue = IWL_MVM_DQA_GCAST_QUEUE;
2318
2319
2320
2321
2322
2323 if (!iwl_mvm_has_new_tx_api(mvm) &&
2324 fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2325 iwl_mvm_enable_txq(mvm, NULL, mvmvif->cab_queue, 0, &cfg,
2326 timeout);
2327 msta->tfd_queue_msk |= BIT(mvmvif->cab_queue);
2328 }
2329 ret = iwl_mvm_add_int_sta_common(mvm, msta, maddr,
2330 mvmvif->id, mvmvif->color);
2331 if (ret)
2332 goto err;
2333
2334
2335
2336
2337
2338
2339
2340
2341 if (iwl_mvm_has_new_tx_api(mvm)) {
2342 int queue = iwl_mvm_tvqm_enable_txq(mvm, msta->sta_id,
2343 0,
2344 timeout);
2345 if (queue < 0) {
2346 ret = queue;
2347 goto err;
2348 }
2349 mvmvif->cab_queue = queue;
2350 } else if (!fw_has_api(&mvm->fw->ucode_capa,
2351 IWL_UCODE_TLV_API_STA_TYPE))
2352 iwl_mvm_enable_txq(mvm, NULL, mvmvif->cab_queue, 0, &cfg,
2353 timeout);
2354
2355 return 0;
2356err:
2357 iwl_mvm_dealloc_int_sta(mvm, msta);
2358 return ret;
2359}
2360
2361static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id,
2362 struct ieee80211_key_conf *keyconf,
2363 bool mcast)
2364{
2365 union {
2366 struct iwl_mvm_add_sta_key_cmd_v1 cmd_v1;
2367 struct iwl_mvm_add_sta_key_cmd cmd;
2368 } u = {};
2369 bool new_api = fw_has_api(&mvm->fw->ucode_capa,
2370 IWL_UCODE_TLV_API_TKIP_MIC_KEYS);
2371 __le16 key_flags;
2372 int ret, size;
2373 u32 status;
2374
2375
2376 if (sta_id == IWL_MVM_INVALID_STA)
2377 return 0;
2378
2379 key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
2380 STA_KEY_FLG_KEYID_MSK);
2381 key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP);
2382 key_flags |= cpu_to_le16(STA_KEY_NOT_VALID);
2383
2384 if (mcast)
2385 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
2386
2387
2388
2389
2390
2391 u.cmd.common.key_flags = key_flags;
2392 u.cmd.common.key_offset = keyconf->hw_key_idx;
2393 u.cmd.common.sta_id = sta_id;
2394
2395 size = new_api ? sizeof(u.cmd) : sizeof(u.cmd_v1);
2396
2397 status = ADD_STA_SUCCESS;
2398 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, size, &u.cmd,
2399 &status);
2400
2401 switch (status) {
2402 case ADD_STA_SUCCESS:
2403 IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n");
2404 break;
2405 default:
2406 ret = -EIO;
2407 IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n");
2408 break;
2409 }
2410
2411 return ret;
2412}
2413
2414
2415
2416
2417
2418int iwl_mvm_rm_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2419{
2420 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2421 int ret;
2422
2423 lockdep_assert_held(&mvm->mutex);
2424
2425 iwl_mvm_flush_sta(mvm, &mvmvif->mcast_sta, true, 0);
2426
2427 iwl_mvm_disable_txq(mvm, NULL, mvmvif->cab_queue, 0, 0);
2428
2429 ret = iwl_mvm_rm_sta_common(mvm, mvmvif->mcast_sta.sta_id);
2430 if (ret)
2431 IWL_WARN(mvm, "Failed sending remove station\n");
2432
2433 return ret;
2434}
2435
2436#define IWL_MAX_RX_BA_SESSIONS 16
2437
2438static void iwl_mvm_sync_rxq_del_ba(struct iwl_mvm *mvm, u8 baid)
2439{
2440 struct iwl_mvm_rss_sync_notif notif = {
2441 .metadata.type = IWL_MVM_RXQ_NOTIF_DEL_BA,
2442 .metadata.sync = 1,
2443 .delba.baid = baid,
2444 };
2445 iwl_mvm_sync_rx_queues_internal(mvm, (void *)¬if, sizeof(notif));
2446};
2447
2448static void iwl_mvm_free_reorder(struct iwl_mvm *mvm,
2449 struct iwl_mvm_baid_data *data)
2450{
2451 int i;
2452
2453 iwl_mvm_sync_rxq_del_ba(mvm, data->baid);
2454
2455 for (i = 0; i < mvm->trans->num_rx_queues; i++) {
2456 int j;
2457 struct iwl_mvm_reorder_buffer *reorder_buf =
2458 &data->reorder_buf[i];
2459 struct iwl_mvm_reorder_buf_entry *entries =
2460 &data->entries[i * data->entries_per_queue];
2461
2462 spin_lock_bh(&reorder_buf->lock);
2463 if (likely(!reorder_buf->num_stored)) {
2464 spin_unlock_bh(&reorder_buf->lock);
2465 continue;
2466 }
2467
2468
2469
2470
2471
2472
2473 WARN_ON(1);
2474
2475 for (j = 0; j < reorder_buf->buf_size; j++)
2476 __skb_queue_purge(&entries[j].e.frames);
2477
2478
2479
2480
2481
2482
2483
2484
2485 reorder_buf->removed = true;
2486 spin_unlock_bh(&reorder_buf->lock);
2487 del_timer_sync(&reorder_buf->reorder_timer);
2488 }
2489}
2490
2491static void iwl_mvm_init_reorder_buffer(struct iwl_mvm *mvm,
2492 struct iwl_mvm_baid_data *data,
2493 u16 ssn, u16 buf_size)
2494{
2495 int i;
2496
2497 for (i = 0; i < mvm->trans->num_rx_queues; i++) {
2498 struct iwl_mvm_reorder_buffer *reorder_buf =
2499 &data->reorder_buf[i];
2500 struct iwl_mvm_reorder_buf_entry *entries =
2501 &data->entries[i * data->entries_per_queue];
2502 int j;
2503
2504 reorder_buf->num_stored = 0;
2505 reorder_buf->head_sn = ssn;
2506 reorder_buf->buf_size = buf_size;
2507
2508 timer_setup(&reorder_buf->reorder_timer,
2509 iwl_mvm_reorder_timer_expired, 0);
2510 spin_lock_init(&reorder_buf->lock);
2511 reorder_buf->mvm = mvm;
2512 reorder_buf->queue = i;
2513 reorder_buf->valid = false;
2514 for (j = 0; j < reorder_buf->buf_size; j++)
2515 __skb_queue_head_init(&entries[j].e.frames);
2516 }
2517}
2518
2519int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
2520 int tid, u16 ssn, bool start, u16 buf_size, u16 timeout)
2521{
2522 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2523 struct iwl_mvm_add_sta_cmd cmd = {};
2524 struct iwl_mvm_baid_data *baid_data = NULL;
2525 int ret;
2526 u32 status;
2527
2528 lockdep_assert_held(&mvm->mutex);
2529
2530 if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) {
2531 IWL_WARN(mvm, "Not enough RX BA SESSIONS\n");
2532 return -ENOSPC;
2533 }
2534
2535 if (iwl_mvm_has_new_rx_api(mvm) && start) {
2536 u16 reorder_buf_size = buf_size * sizeof(baid_data->entries[0]);
2537
2538
2539#ifndef __CHECKER__
2540
2541
2542
2543
2544
2545
2546 BUILD_BUG_ON(SMP_CACHE_BYTES % sizeof(baid_data->entries[0]) &&
2547 sizeof(baid_data->entries[0]) % SMP_CACHE_BYTES);
2548#endif
2549
2550
2551
2552
2553
2554
2555 reorder_buf_size = ALIGN(reorder_buf_size, SMP_CACHE_BYTES);
2556
2557
2558
2559
2560
2561 baid_data = kzalloc(sizeof(*baid_data) +
2562 mvm->trans->num_rx_queues *
2563 reorder_buf_size,
2564 GFP_KERNEL);
2565 if (!baid_data)
2566 return -ENOMEM;
2567
2568
2569
2570
2571
2572 baid_data->entries_per_queue =
2573 reorder_buf_size / sizeof(baid_data->entries[0]);
2574 }
2575
2576 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
2577 cmd.sta_id = mvm_sta->sta_id;
2578 cmd.add_modify = STA_MODE_MODIFY;
2579 if (start) {
2580 cmd.add_immediate_ba_tid = (u8) tid;
2581 cmd.add_immediate_ba_ssn = cpu_to_le16(ssn);
2582 cmd.rx_ba_window = cpu_to_le16(buf_size);
2583 } else {
2584 cmd.remove_immediate_ba_tid = (u8) tid;
2585 }
2586 cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID :
2587 STA_MODIFY_REMOVE_BA_TID;
2588
2589 status = ADD_STA_SUCCESS;
2590 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
2591 iwl_mvm_add_sta_cmd_size(mvm),
2592 &cmd, &status);
2593 if (ret)
2594 goto out_free;
2595
2596 switch (status & IWL_ADD_STA_STATUS_MASK) {
2597 case ADD_STA_SUCCESS:
2598 IWL_DEBUG_HT(mvm, "RX BA Session %sed in fw\n",
2599 start ? "start" : "stopp");
2600 break;
2601 case ADD_STA_IMMEDIATE_BA_FAILURE:
2602 IWL_WARN(mvm, "RX BA Session refused by fw\n");
2603 ret = -ENOSPC;
2604 break;
2605 default:
2606 ret = -EIO;
2607 IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n",
2608 start ? "start" : "stopp", status);
2609 break;
2610 }
2611
2612 if (ret)
2613 goto out_free;
2614
2615 if (start) {
2616 u8 baid;
2617
2618 mvm->rx_ba_sessions++;
2619
2620 if (!iwl_mvm_has_new_rx_api(mvm))
2621 return 0;
2622
2623 if (WARN_ON(!(status & IWL_ADD_STA_BAID_VALID_MASK))) {
2624 ret = -EINVAL;
2625 goto out_free;
2626 }
2627 baid = (u8)((status & IWL_ADD_STA_BAID_MASK) >>
2628 IWL_ADD_STA_BAID_SHIFT);
2629 baid_data->baid = baid;
2630 baid_data->timeout = timeout;
2631 baid_data->last_rx = jiffies;
2632 baid_data->rcu_ptr = &mvm->baid_map[baid];
2633 timer_setup(&baid_data->session_timer,
2634 iwl_mvm_rx_agg_session_expired, 0);
2635 baid_data->mvm = mvm;
2636 baid_data->tid = tid;
2637 baid_data->sta_id = mvm_sta->sta_id;
2638
2639 mvm_sta->tid_to_baid[tid] = baid;
2640 if (timeout)
2641 mod_timer(&baid_data->session_timer,
2642 TU_TO_EXP_TIME(timeout * 2));
2643
2644 iwl_mvm_init_reorder_buffer(mvm, baid_data, ssn, buf_size);
2645
2646
2647
2648
2649
2650
2651 IWL_DEBUG_HT(mvm, "Sta %d(%d) is assigned to BAID %d\n",
2652 mvm_sta->sta_id, tid, baid);
2653 WARN_ON(rcu_access_pointer(mvm->baid_map[baid]));
2654 rcu_assign_pointer(mvm->baid_map[baid], baid_data);
2655 } else {
2656 u8 baid = mvm_sta->tid_to_baid[tid];
2657
2658 if (mvm->rx_ba_sessions > 0)
2659
2660 mvm->rx_ba_sessions--;
2661 if (!iwl_mvm_has_new_rx_api(mvm))
2662 return 0;
2663
2664 if (WARN_ON(baid == IWL_RX_REORDER_DATA_INVALID_BAID))
2665 return -EINVAL;
2666
2667 baid_data = rcu_access_pointer(mvm->baid_map[baid]);
2668 if (WARN_ON(!baid_data))
2669 return -EINVAL;
2670
2671
2672 iwl_mvm_free_reorder(mvm, baid_data);
2673 del_timer_sync(&baid_data->session_timer);
2674 RCU_INIT_POINTER(mvm->baid_map[baid], NULL);
2675 kfree_rcu(baid_data, rcu_head);
2676 IWL_DEBUG_HT(mvm, "BAID %d is free\n", baid);
2677 }
2678 return 0;
2679
2680out_free:
2681 kfree(baid_data);
2682 return ret;
2683}
2684
2685int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
2686 int tid, u8 queue, bool start)
2687{
2688 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2689 struct iwl_mvm_add_sta_cmd cmd = {};
2690 int ret;
2691 u32 status;
2692
2693 lockdep_assert_held(&mvm->mutex);
2694
2695 if (start) {
2696 mvm_sta->tfd_queue_msk |= BIT(queue);
2697 mvm_sta->tid_disable_agg &= ~BIT(tid);
2698 } else {
2699
2700 mvm_sta->tid_disable_agg |= BIT(tid);
2701 }
2702
2703 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
2704 cmd.sta_id = mvm_sta->sta_id;
2705 cmd.add_modify = STA_MODE_MODIFY;
2706 if (!iwl_mvm_has_new_tx_api(mvm))
2707 cmd.modify_mask = STA_MODIFY_QUEUES;
2708 cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX;
2709 cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk);
2710 cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg);
2711
2712 status = ADD_STA_SUCCESS;
2713 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
2714 iwl_mvm_add_sta_cmd_size(mvm),
2715 &cmd, &status);
2716 if (ret)
2717 return ret;
2718
2719 switch (status & IWL_ADD_STA_STATUS_MASK) {
2720 case ADD_STA_SUCCESS:
2721 break;
2722 default:
2723 ret = -EIO;
2724 IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n",
2725 start ? "start" : "stopp", status);
2726 break;
2727 }
2728
2729 return ret;
2730}
2731
2732const u8 tid_to_mac80211_ac[] = {
2733 IEEE80211_AC_BE,
2734 IEEE80211_AC_BK,
2735 IEEE80211_AC_BK,
2736 IEEE80211_AC_BE,
2737 IEEE80211_AC_VI,
2738 IEEE80211_AC_VI,
2739 IEEE80211_AC_VO,
2740 IEEE80211_AC_VO,
2741 IEEE80211_AC_VO,
2742};
2743
2744static const u8 tid_to_ucode_ac[] = {
2745 AC_BE,
2746 AC_BK,
2747 AC_BK,
2748 AC_BE,
2749 AC_VI,
2750 AC_VI,
2751 AC_VO,
2752 AC_VO,
2753};
2754
2755int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2756 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
2757{
2758 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2759 struct iwl_mvm_tid_data *tid_data;
2760 u16 normalized_ssn;
2761 u16 txq_id;
2762 int ret;
2763
2764 if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
2765 return -EINVAL;
2766
2767 if (mvmsta->tid_data[tid].state != IWL_AGG_QUEUED &&
2768 mvmsta->tid_data[tid].state != IWL_AGG_OFF) {
2769 IWL_ERR(mvm,
2770 "Start AGG when state is not IWL_AGG_QUEUED or IWL_AGG_OFF %d!\n",
2771 mvmsta->tid_data[tid].state);
2772 return -ENXIO;
2773 }
2774
2775 lockdep_assert_held(&mvm->mutex);
2776
2777 if (mvmsta->tid_data[tid].txq_id == IWL_MVM_INVALID_QUEUE &&
2778 iwl_mvm_has_new_tx_api(mvm)) {
2779 u8 ac = tid_to_mac80211_ac[tid];
2780
2781 ret = iwl_mvm_sta_alloc_queue_tvqm(mvm, sta, ac, tid);
2782 if (ret)
2783 return ret;
2784 }
2785
2786 spin_lock_bh(&mvmsta->lock);
2787
2788
2789
2790
2791
2792
2793
2794 txq_id = mvmsta->tid_data[tid].txq_id;
2795 if (txq_id == IWL_MVM_INVALID_QUEUE) {
2796 ret = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
2797 IWL_MVM_DQA_MIN_DATA_QUEUE,
2798 IWL_MVM_DQA_MAX_DATA_QUEUE);
2799 if (ret < 0) {
2800 IWL_ERR(mvm, "Failed to allocate agg queue\n");
2801 goto out;
2802 }
2803
2804 txq_id = ret;
2805
2806
2807 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_RESERVED;
2808 } else if (WARN_ON(txq_id >= IWL_MAX_HW_QUEUES)) {
2809 ret = -ENXIO;
2810 IWL_ERR(mvm, "tid_id %d out of range (0, %d)!\n",
2811 tid, IWL_MAX_HW_QUEUES - 1);
2812 goto out;
2813
2814 } else if (unlikely(mvm->queue_info[txq_id].status ==
2815 IWL_MVM_QUEUE_SHARED)) {
2816 ret = -ENXIO;
2817 IWL_DEBUG_TX_QUEUES(mvm,
2818 "Can't start tid %d agg on shared queue!\n",
2819 tid);
2820 goto out;
2821 }
2822
2823 IWL_DEBUG_TX_QUEUES(mvm,
2824 "AGG for tid %d will be on queue #%d\n",
2825 tid, txq_id);
2826
2827 tid_data = &mvmsta->tid_data[tid];
2828 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
2829 tid_data->txq_id = txq_id;
2830 *ssn = tid_data->ssn;
2831
2832 IWL_DEBUG_TX_QUEUES(mvm,
2833 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
2834 mvmsta->sta_id, tid, txq_id, tid_data->ssn,
2835 tid_data->next_reclaimed);
2836
2837
2838
2839
2840
2841 normalized_ssn = tid_data->ssn;
2842 if (mvm->trans->trans_cfg->gen2)
2843 normalized_ssn &= 0xff;
2844
2845 if (normalized_ssn == tid_data->next_reclaimed) {
2846 tid_data->state = IWL_AGG_STARTING;
2847 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2848 } else {
2849 tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA;
2850 }
2851
2852 ret = 0;
2853
2854out:
2855 spin_unlock_bh(&mvmsta->lock);
2856
2857 return ret;
2858}
2859
2860int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2861 struct ieee80211_sta *sta, u16 tid, u16 buf_size,
2862 bool amsdu)
2863{
2864 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2865 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2866 unsigned int wdg_timeout =
2867 iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false);
2868 int queue, ret;
2869 bool alloc_queue = true;
2870 enum iwl_mvm_queue_status queue_status;
2871 u16 ssn;
2872
2873 struct iwl_trans_txq_scd_cfg cfg = {
2874 .sta_id = mvmsta->sta_id,
2875 .tid = tid,
2876 .frame_limit = buf_size,
2877 .aggregate = true,
2878 };
2879
2880
2881
2882
2883
2884 if (WARN_ON_ONCE(iwl_mvm_has_tlc_offload(mvm)))
2885 return -EINVAL;
2886
2887 BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE)
2888 != IWL_MAX_TID_COUNT);
2889
2890 spin_lock_bh(&mvmsta->lock);
2891 ssn = tid_data->ssn;
2892 queue = tid_data->txq_id;
2893 tid_data->state = IWL_AGG_ON;
2894 mvmsta->agg_tids |= BIT(tid);
2895 tid_data->ssn = 0xffff;
2896 tid_data->amsdu_in_ampdu_allowed = amsdu;
2897 spin_unlock_bh(&mvmsta->lock);
2898
2899 if (iwl_mvm_has_new_tx_api(mvm)) {
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911 if (buf_size < IWL_FRAME_LIMIT)
2912 return -ENOTSUPP;
2913
2914 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
2915 if (ret)
2916 return -EIO;
2917 goto out;
2918 }
2919
2920 cfg.fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
2921
2922 queue_status = mvm->queue_info[queue].status;
2923
2924
2925 if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_READY)
2926 alloc_queue = false;
2927
2928
2929
2930
2931
2932 if (!alloc_queue && buf_size < IWL_FRAME_LIMIT) {
2933
2934
2935
2936
2937 ret = iwl_trans_wait_tx_queues_empty(mvm->trans,
2938 BIT(queue));
2939 if (ret) {
2940 IWL_ERR(mvm,
2941 "Error draining queue before reconfig\n");
2942 return ret;
2943 }
2944
2945 ret = iwl_mvm_reconfig_scd(mvm, queue, cfg.fifo,
2946 mvmsta->sta_id, tid,
2947 buf_size, ssn);
2948 if (ret) {
2949 IWL_ERR(mvm,
2950 "Error reconfiguring TXQ #%d\n", queue);
2951 return ret;
2952 }
2953 }
2954
2955 if (alloc_queue)
2956 iwl_mvm_enable_txq(mvm, sta, queue, ssn,
2957 &cfg, wdg_timeout);
2958
2959
2960 if (queue_status != IWL_MVM_QUEUE_SHARED) {
2961 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
2962 if (ret)
2963 return -EIO;
2964 }
2965
2966
2967 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
2968
2969out:
2970
2971
2972
2973
2974
2975
2976
2977 mvmsta->max_agg_bufsize =
2978 min(mvmsta->max_agg_bufsize, buf_size);
2979 mvmsta->lq_sta.rs_drv.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize;
2980
2981 IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n",
2982 sta->addr, tid);
2983
2984 return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.rs_drv.lq);
2985}
2986
2987static void iwl_mvm_unreserve_agg_queue(struct iwl_mvm *mvm,
2988 struct iwl_mvm_sta *mvmsta,
2989 struct iwl_mvm_tid_data *tid_data)
2990{
2991 u16 txq_id = tid_data->txq_id;
2992
2993 lockdep_assert_held(&mvm->mutex);
2994
2995 if (iwl_mvm_has_new_tx_api(mvm))
2996 return;
2997
2998
2999
3000
3001
3002
3003
3004
3005 if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED) {
3006 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE;
3007 tid_data->txq_id = IWL_MVM_INVALID_QUEUE;
3008 }
3009}
3010
3011int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
3012 struct ieee80211_sta *sta, u16 tid)
3013{
3014 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3015 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
3016 u16 txq_id;
3017 int err;
3018
3019
3020
3021
3022
3023 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
3024 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
3025 return 0;
3026 }
3027
3028 spin_lock_bh(&mvmsta->lock);
3029
3030 txq_id = tid_data->txq_id;
3031
3032 IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n",
3033 mvmsta->sta_id, tid, txq_id, tid_data->state);
3034
3035 mvmsta->agg_tids &= ~BIT(tid);
3036
3037 iwl_mvm_unreserve_agg_queue(mvm, mvmsta, tid_data);
3038
3039 switch (tid_data->state) {
3040 case IWL_AGG_ON:
3041 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
3042
3043 IWL_DEBUG_TX_QUEUES(mvm,
3044 "ssn = %d, next_recl = %d\n",
3045 tid_data->ssn, tid_data->next_reclaimed);
3046
3047 tid_data->ssn = 0xffff;
3048 tid_data->state = IWL_AGG_OFF;
3049 spin_unlock_bh(&mvmsta->lock);
3050
3051 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
3052
3053 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
3054 return 0;
3055 case IWL_AGG_STARTING:
3056 case IWL_EMPTYING_HW_QUEUE_ADDBA:
3057
3058
3059
3060
3061
3062
3063 lockdep_assert_held(&mvm->mutex);
3064
3065 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
3066 tid_data->state = IWL_AGG_OFF;
3067 err = 0;
3068 break;
3069 default:
3070 IWL_ERR(mvm,
3071 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
3072 mvmsta->sta_id, tid, tid_data->state);
3073 IWL_ERR(mvm,
3074 "\ttid_data->txq_id = %d\n", tid_data->txq_id);
3075 err = -EINVAL;
3076 }
3077
3078 spin_unlock_bh(&mvmsta->lock);
3079
3080 return err;
3081}
3082
3083int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
3084 struct ieee80211_sta *sta, u16 tid)
3085{
3086 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3087 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
3088 u16 txq_id;
3089 enum iwl_mvm_agg_state old_state;
3090
3091
3092
3093
3094
3095 spin_lock_bh(&mvmsta->lock);
3096 txq_id = tid_data->txq_id;
3097 IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n",
3098 mvmsta->sta_id, tid, txq_id, tid_data->state);
3099 old_state = tid_data->state;
3100 tid_data->state = IWL_AGG_OFF;
3101 mvmsta->agg_tids &= ~BIT(tid);
3102 spin_unlock_bh(&mvmsta->lock);
3103
3104 iwl_mvm_unreserve_agg_queue(mvm, mvmsta, tid_data);
3105
3106 if (old_state >= IWL_AGG_ON) {
3107 iwl_mvm_drain_sta(mvm, mvmsta, true);
3108
3109 if (iwl_mvm_has_new_tx_api(mvm)) {
3110 if (iwl_mvm_flush_sta_tids(mvm, mvmsta->sta_id,
3111 BIT(tid), 0))
3112 IWL_ERR(mvm, "Couldn't flush the AGG queue\n");
3113 iwl_trans_wait_txq_empty(mvm->trans, txq_id);
3114 } else {
3115 if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0))
3116 IWL_ERR(mvm, "Couldn't flush the AGG queue\n");
3117 iwl_trans_wait_tx_queues_empty(mvm->trans, BIT(txq_id));
3118 }
3119
3120 iwl_mvm_drain_sta(mvm, mvmsta, false);
3121
3122 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
3123 }
3124
3125 return 0;
3126}
3127
3128static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm)
3129{
3130 int i, max = -1, max_offs = -1;
3131
3132 lockdep_assert_held(&mvm->mutex);
3133
3134
3135
3136
3137
3138
3139
3140 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
3141 if (test_bit(i, mvm->fw_key_table))
3142 continue;
3143 if (mvm->fw_key_deleted[i] > max) {
3144 max = mvm->fw_key_deleted[i];
3145 max_offs = i;
3146 }
3147 }
3148
3149 if (max_offs < 0)
3150 return STA_KEY_IDX_INVALID;
3151
3152 return max_offs;
3153}
3154
3155static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm,
3156 struct ieee80211_vif *vif,
3157 struct ieee80211_sta *sta)
3158{
3159 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3160
3161 if (sta)
3162 return iwl_mvm_sta_from_mac80211(sta);
3163
3164
3165
3166
3167
3168
3169 if (vif->type == NL80211_IFTYPE_STATION &&
3170 mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
3171 u8 sta_id = mvmvif->ap_sta_id;
3172
3173 sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id],
3174 lockdep_is_held(&mvm->mutex));
3175
3176
3177
3178
3179
3180
3181 if (IS_ERR_OR_NULL(sta))
3182 return NULL;
3183
3184 return iwl_mvm_sta_from_mac80211(sta);
3185 }
3186
3187 return NULL;
3188}
3189
3190static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm,
3191 u32 sta_id,
3192 struct ieee80211_key_conf *key, bool mcast,
3193 u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags,
3194 u8 key_offset, bool mfp)
3195{
3196 union {
3197 struct iwl_mvm_add_sta_key_cmd_v1 cmd_v1;
3198 struct iwl_mvm_add_sta_key_cmd cmd;
3199 } u = {};
3200 __le16 key_flags;
3201 int ret;
3202 u32 status;
3203 u16 keyidx;
3204 u64 pn = 0;
3205 int i, size;
3206 bool new_api = fw_has_api(&mvm->fw->ucode_capa,
3207 IWL_UCODE_TLV_API_TKIP_MIC_KEYS);
3208
3209 if (sta_id == IWL_MVM_INVALID_STA)
3210 return -EINVAL;
3211
3212 keyidx = (key->keyidx << STA_KEY_FLG_KEYID_POS) &
3213 STA_KEY_FLG_KEYID_MSK;
3214 key_flags = cpu_to_le16(keyidx);
3215 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP);
3216
3217 switch (key->cipher) {
3218 case WLAN_CIPHER_SUITE_TKIP:
3219 key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP);
3220 if (new_api) {
3221 memcpy((void *)&u.cmd.tx_mic_key,
3222 &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
3223 IWL_MIC_KEY_SIZE);
3224
3225 memcpy((void *)&u.cmd.rx_mic_key,
3226 &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
3227 IWL_MIC_KEY_SIZE);
3228 pn = atomic64_read(&key->tx_pn);
3229
3230 } else {
3231 u.cmd_v1.tkip_rx_tsc_byte2 = tkip_iv32;
3232 for (i = 0; i < 5; i++)
3233 u.cmd_v1.tkip_rx_ttak[i] =
3234 cpu_to_le16(tkip_p1k[i]);
3235 }
3236 memcpy(u.cmd.common.key, key->key, key->keylen);
3237 break;
3238 case WLAN_CIPHER_SUITE_CCMP:
3239 key_flags |= cpu_to_le16(STA_KEY_FLG_CCM);
3240 memcpy(u.cmd.common.key, key->key, key->keylen);
3241 if (new_api)
3242 pn = atomic64_read(&key->tx_pn);
3243 break;
3244 case WLAN_CIPHER_SUITE_WEP104:
3245 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES);
3246
3247 case WLAN_CIPHER_SUITE_WEP40:
3248 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP);
3249 memcpy(u.cmd.common.key + 3, key->key, key->keylen);
3250 break;
3251 case WLAN_CIPHER_SUITE_GCMP_256:
3252 key_flags |= cpu_to_le16(STA_KEY_FLG_KEY_32BYTES);
3253
3254 case WLAN_CIPHER_SUITE_GCMP:
3255 key_flags |= cpu_to_le16(STA_KEY_FLG_GCMP);
3256 memcpy(u.cmd.common.key, key->key, key->keylen);
3257 if (new_api)
3258 pn = atomic64_read(&key->tx_pn);
3259 break;
3260 default:
3261 key_flags |= cpu_to_le16(STA_KEY_FLG_EXT);
3262 memcpy(u.cmd.common.key, key->key, key->keylen);
3263 }
3264
3265 if (mcast)
3266 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
3267 if (mfp)
3268 key_flags |= cpu_to_le16(STA_KEY_MFP);
3269
3270 u.cmd.common.key_offset = key_offset;
3271 u.cmd.common.key_flags = key_flags;
3272 u.cmd.common.sta_id = sta_id;
3273
3274 if (new_api) {
3275 u.cmd.transmit_seq_cnt = cpu_to_le64(pn);
3276 size = sizeof(u.cmd);
3277 } else {
3278 size = sizeof(u.cmd_v1);
3279 }
3280
3281 status = ADD_STA_SUCCESS;
3282 if (cmd_flags & CMD_ASYNC)
3283 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC, size,
3284 &u.cmd);
3285 else
3286 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, size,
3287 &u.cmd, &status);
3288
3289 switch (status) {
3290 case ADD_STA_SUCCESS:
3291 IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n");
3292 break;
3293 default:
3294 ret = -EIO;
3295 IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n");
3296 break;
3297 }
3298
3299 return ret;
3300}
3301
3302static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm,
3303 struct ieee80211_key_conf *keyconf,
3304 u8 sta_id, bool remove_key)
3305{
3306 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {};
3307
3308
3309 if (WARN_ON((keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) ||
3310 (keyconf->keyidx != 4 && keyconf->keyidx != 5) ||
3311 (keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC &&
3312 keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_128 &&
3313 keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_256)))
3314 return -EINVAL;
3315
3316 if (WARN_ON(!iwl_mvm_has_new_rx_api(mvm) &&
3317 keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC))
3318 return -EINVAL;
3319
3320 igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx);
3321 igtk_cmd.sta_id = cpu_to_le32(sta_id);
3322
3323 if (remove_key) {
3324 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID);
3325 } else {
3326 struct ieee80211_key_seq seq;
3327 const u8 *pn;
3328
3329 switch (keyconf->cipher) {
3330 case WLAN_CIPHER_SUITE_AES_CMAC:
3331 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_CCM);
3332 break;
3333 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
3334 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
3335 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_GCMP);
3336 break;
3337 default:
3338 return -EINVAL;
3339 }
3340
3341 memcpy(igtk_cmd.igtk, keyconf->key, keyconf->keylen);
3342 if (keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3343 igtk_cmd.ctrl_flags |=
3344 cpu_to_le32(STA_KEY_FLG_KEY_32BYTES);
3345 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
3346 pn = seq.aes_cmac.pn;
3347 igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) |
3348 ((u64) pn[4] << 8) |
3349 ((u64) pn[3] << 16) |
3350 ((u64) pn[2] << 24) |
3351 ((u64) pn[1] << 32) |
3352 ((u64) pn[0] << 40));
3353 }
3354
3355 IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n",
3356 remove_key ? "removing" : "installing",
3357 igtk_cmd.sta_id);
3358
3359 if (!iwl_mvm_has_new_rx_api(mvm)) {
3360 struct iwl_mvm_mgmt_mcast_key_cmd_v1 igtk_cmd_v1 = {
3361 .ctrl_flags = igtk_cmd.ctrl_flags,
3362 .key_id = igtk_cmd.key_id,
3363 .sta_id = igtk_cmd.sta_id,
3364 .receive_seq_cnt = igtk_cmd.receive_seq_cnt
3365 };
3366
3367 memcpy(igtk_cmd_v1.igtk, igtk_cmd.igtk,
3368 ARRAY_SIZE(igtk_cmd_v1.igtk));
3369 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
3370 sizeof(igtk_cmd_v1), &igtk_cmd_v1);
3371 }
3372 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
3373 sizeof(igtk_cmd), &igtk_cmd);
3374}
3375
3376
3377static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm,
3378 struct ieee80211_vif *vif,
3379 struct ieee80211_sta *sta)
3380{
3381 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3382
3383 if (sta)
3384 return sta->addr;
3385
3386 if (vif->type == NL80211_IFTYPE_STATION &&
3387 mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
3388 u8 sta_id = mvmvif->ap_sta_id;
3389 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
3390 lockdep_is_held(&mvm->mutex));
3391 return sta->addr;
3392 }
3393
3394
3395 return NULL;
3396}
3397
3398static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
3399 struct ieee80211_vif *vif,
3400 struct ieee80211_sta *sta,
3401 struct ieee80211_key_conf *keyconf,
3402 u8 key_offset,
3403 bool mcast)
3404{
3405 int ret;
3406 const u8 *addr;
3407 struct ieee80211_key_seq seq;
3408 u16 p1k[5];
3409 u32 sta_id;
3410 bool mfp = false;
3411
3412 if (sta) {
3413 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3414
3415 sta_id = mvm_sta->sta_id;
3416 mfp = sta->mfp;
3417 } else if (vif->type == NL80211_IFTYPE_AP &&
3418 !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
3419 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3420
3421 sta_id = mvmvif->mcast_sta.sta_id;
3422 } else {
3423 IWL_ERR(mvm, "Failed to find station id\n");
3424 return -EINVAL;
3425 }
3426
3427 switch (keyconf->cipher) {
3428 case WLAN_CIPHER_SUITE_TKIP:
3429 addr = iwl_mvm_get_mac_addr(mvm, vif, sta);
3430
3431 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
3432 ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k);
3433 ret = iwl_mvm_send_sta_key(mvm, sta_id, keyconf, mcast,
3434 seq.tkip.iv32, p1k, 0, key_offset,
3435 mfp);
3436 break;
3437 case WLAN_CIPHER_SUITE_CCMP:
3438 case WLAN_CIPHER_SUITE_WEP40:
3439 case WLAN_CIPHER_SUITE_WEP104:
3440 case WLAN_CIPHER_SUITE_GCMP:
3441 case WLAN_CIPHER_SUITE_GCMP_256:
3442 ret = iwl_mvm_send_sta_key(mvm, sta_id, keyconf, mcast,
3443 0, NULL, 0, key_offset, mfp);
3444 break;
3445 default:
3446 ret = iwl_mvm_send_sta_key(mvm, sta_id, keyconf, mcast,
3447 0, NULL, 0, key_offset, mfp);
3448 }
3449
3450 return ret;
3451}
3452
3453int iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
3454 struct ieee80211_vif *vif,
3455 struct ieee80211_sta *sta,
3456 struct ieee80211_key_conf *keyconf,
3457 u8 key_offset)
3458{
3459 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
3460 struct iwl_mvm_sta *mvm_sta;
3461 u8 sta_id = IWL_MVM_INVALID_STA;
3462 int ret;
3463 static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0};
3464
3465 lockdep_assert_held(&mvm->mutex);
3466
3467 if (vif->type != NL80211_IFTYPE_AP ||
3468 keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
3469
3470 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
3471 if (!mvm_sta) {
3472 IWL_ERR(mvm, "Failed to find station\n");
3473 return -EINVAL;
3474 }
3475 sta_id = mvm_sta->sta_id;
3476
3477
3478
3479
3480
3481
3482 if (!sta) {
3483 sta = rcu_dereference_protected(
3484 mvm->fw_id_to_mac_id[sta_id],
3485 lockdep_is_held(&mvm->mutex));
3486 if (IS_ERR_OR_NULL(sta)) {
3487 IWL_ERR(mvm, "Invalid station id\n");
3488 return -EINVAL;
3489 }
3490 }
3491
3492 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif))
3493 return -EINVAL;
3494 } else {
3495 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3496
3497 sta_id = mvmvif->mcast_sta.sta_id;
3498 }
3499
3500 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3501 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3502 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) {
3503 ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false);
3504 goto end;
3505 }
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518 if (key_offset == STA_KEY_IDX_INVALID) {
3519 key_offset = iwl_mvm_set_fw_key_idx(mvm);
3520 if (key_offset == STA_KEY_IDX_INVALID)
3521 return -ENOSPC;
3522 keyconf->hw_key_idx = key_offset;
3523 }
3524
3525 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, key_offset, mcast);
3526 if (ret)
3527 goto end;
3528
3529
3530
3531
3532
3533
3534
3535 if ((keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3536 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) &&
3537 sta) {
3538 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf,
3539 key_offset, !mcast);
3540 if (ret) {
3541 __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
3542 goto end;
3543 }
3544 }
3545
3546 __set_bit(key_offset, mvm->fw_key_table);
3547
3548end:
3549 IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
3550 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
3551 sta ? sta->addr : zero_addr, ret);
3552 return ret;
3553}
3554
3555int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm,
3556 struct ieee80211_vif *vif,
3557 struct ieee80211_sta *sta,
3558 struct ieee80211_key_conf *keyconf)
3559{
3560 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
3561 struct iwl_mvm_sta *mvm_sta;
3562 u8 sta_id = IWL_MVM_INVALID_STA;
3563 int ret, i;
3564
3565 lockdep_assert_held(&mvm->mutex);
3566
3567
3568 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
3569 if (mvm_sta)
3570 sta_id = mvm_sta->sta_id;
3571 else if (!sta && vif->type == NL80211_IFTYPE_AP && mcast)
3572 sta_id = iwl_mvm_vif_from_mac80211(vif)->mcast_sta.sta_id;
3573
3574
3575 IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n",
3576 keyconf->keyidx, sta_id);
3577
3578 if (mvm_sta && (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3579 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3580 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256))
3581 return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true);
3582
3583 if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) {
3584 IWL_ERR(mvm, "offset %d not used in fw key table.\n",
3585 keyconf->hw_key_idx);
3586 return -ENOENT;
3587 }
3588
3589
3590 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
3591 if (mvm->fw_key_deleted[i] < U8_MAX)
3592 mvm->fw_key_deleted[i]++;
3593 }
3594 mvm->fw_key_deleted[keyconf->hw_key_idx] = 0;
3595
3596 if (sta && !mvm_sta) {
3597 IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n");
3598 return 0;
3599 }
3600
3601 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
3602 if (ret)
3603 return ret;
3604
3605
3606 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3607 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104)
3608 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast);
3609
3610 return ret;
3611}
3612
3613void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm,
3614 struct ieee80211_vif *vif,
3615 struct ieee80211_key_conf *keyconf,
3616 struct ieee80211_sta *sta, u32 iv32,
3617 u16 *phase1key)
3618{
3619 struct iwl_mvm_sta *mvm_sta;
3620 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
3621 bool mfp = sta ? sta->mfp : false;
3622
3623 rcu_read_lock();
3624
3625 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
3626 if (WARN_ON_ONCE(!mvm_sta))
3627 goto unlock;
3628 iwl_mvm_send_sta_key(mvm, mvm_sta->sta_id, keyconf, mcast,
3629 iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx,
3630 mfp);
3631
3632 unlock:
3633 rcu_read_unlock();
3634}
3635
3636void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm,
3637 struct ieee80211_sta *sta)
3638{
3639 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3640 struct iwl_mvm_add_sta_cmd cmd = {
3641 .add_modify = STA_MODE_MODIFY,
3642 .sta_id = mvmsta->sta_id,
3643 .station_flags_msk = cpu_to_le32(STA_FLG_PS),
3644 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
3645 };
3646 int ret;
3647
3648 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
3649 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
3650 if (ret)
3651 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3652}
3653
3654void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm,
3655 struct ieee80211_sta *sta,
3656 enum ieee80211_frame_release_type reason,
3657 u16 cnt, u16 tids, bool more_data,
3658 bool single_sta_queue)
3659{
3660 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3661 struct iwl_mvm_add_sta_cmd cmd = {
3662 .add_modify = STA_MODE_MODIFY,
3663 .sta_id = mvmsta->sta_id,
3664 .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT,
3665 .sleep_tx_count = cpu_to_le16(cnt),
3666 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
3667 };
3668 int tid, ret;
3669 unsigned long _tids = tids;
3670
3671
3672
3673
3674
3675 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT)
3676 cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]);
3677
3678
3679
3680
3681
3682
3683
3684
3685 if (single_sta_queue) {
3686 int remaining = cnt;
3687 int sleep_tx_count;
3688
3689 spin_lock_bh(&mvmsta->lock);
3690 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) {
3691 struct iwl_mvm_tid_data *tid_data;
3692 u16 n_queued;
3693
3694 tid_data = &mvmsta->tid_data[tid];
3695
3696 n_queued = iwl_mvm_tid_queued(mvm, tid_data);
3697 if (n_queued > remaining) {
3698 more_data = true;
3699 remaining = 0;
3700 break;
3701 }
3702 remaining -= n_queued;
3703 }
3704 sleep_tx_count = cnt - remaining;
3705 if (reason == IEEE80211_FRAME_RELEASE_UAPSD)
3706 mvmsta->sleep_tx_count = sleep_tx_count;
3707 spin_unlock_bh(&mvmsta->lock);
3708
3709 cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count);
3710 if (WARN_ON(cnt - remaining == 0)) {
3711 ieee80211_sta_eosp(sta);
3712 return;
3713 }
3714 }
3715
3716
3717 if (more_data)
3718 cmd.sleep_state_flags |= STA_SLEEP_STATE_MOREDATA;
3719
3720 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) {
3721 mvmsta->next_status_eosp = true;
3722 cmd.sleep_state_flags |= STA_SLEEP_STATE_PS_POLL;
3723 } else {
3724 cmd.sleep_state_flags |= STA_SLEEP_STATE_UAPSD;
3725 }
3726
3727
3728 iwl_trans_block_txq_ptrs(mvm->trans, true);
3729
3730 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA,
3731 CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK,
3732 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
3733 if (ret)
3734 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3735}
3736
3737void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm,
3738 struct iwl_rx_cmd_buffer *rxb)
3739{
3740 struct iwl_rx_packet *pkt = rxb_addr(rxb);
3741 struct iwl_mvm_eosp_notification *notif = (void *)pkt->data;
3742 struct ieee80211_sta *sta;
3743 u32 sta_id = le32_to_cpu(notif->sta_id);
3744
3745 if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT))
3746 return;
3747
3748 rcu_read_lock();
3749 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
3750 if (!IS_ERR_OR_NULL(sta))
3751 ieee80211_sta_eosp(sta);
3752 rcu_read_unlock();
3753}
3754
3755void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm,
3756 struct iwl_mvm_sta *mvmsta, bool disable)
3757{
3758 struct iwl_mvm_add_sta_cmd cmd = {
3759 .add_modify = STA_MODE_MODIFY,
3760 .sta_id = mvmsta->sta_id,
3761 .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0,
3762 .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX),
3763 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
3764 };
3765 int ret;
3766
3767 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
3768 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
3769 if (ret)
3770 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3771}
3772
3773void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm,
3774 struct ieee80211_sta *sta,
3775 bool disable)
3776{
3777 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3778
3779 spin_lock_bh(&mvm_sta->lock);
3780
3781 if (mvm_sta->disable_tx == disable) {
3782 spin_unlock_bh(&mvm_sta->lock);
3783 return;
3784 }
3785
3786 mvm_sta->disable_tx = disable;
3787
3788
3789 ieee80211_sta_block_awake(mvm->hw, sta, disable);
3790
3791 iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable);
3792
3793 spin_unlock_bh(&mvm_sta->lock);
3794}
3795
3796static void iwl_mvm_int_sta_modify_disable_tx(struct iwl_mvm *mvm,
3797 struct iwl_mvm_vif *mvmvif,
3798 struct iwl_mvm_int_sta *sta,
3799 bool disable)
3800{
3801 u32 id = FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color);
3802 struct iwl_mvm_add_sta_cmd cmd = {
3803 .add_modify = STA_MODE_MODIFY,
3804 .sta_id = sta->sta_id,
3805 .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0,
3806 .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX),
3807 .mac_id_n_color = cpu_to_le32(id),
3808 };
3809 int ret;
3810
3811 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, 0,
3812 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
3813 if (ret)
3814 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3815}
3816
3817void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm,
3818 struct iwl_mvm_vif *mvmvif,
3819 bool disable)
3820{
3821 struct ieee80211_sta *sta;
3822 struct iwl_mvm_sta *mvm_sta;
3823 int i;
3824
3825 lockdep_assert_held(&mvm->mutex);
3826
3827
3828 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
3829 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3830 lockdep_is_held(&mvm->mutex));
3831 if (IS_ERR_OR_NULL(sta))
3832 continue;
3833
3834 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3835 if (mvm_sta->mac_id_n_color !=
3836 FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color))
3837 continue;
3838
3839 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable);
3840 }
3841
3842 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
3843 return;
3844
3845
3846 if (mvmvif->mcast_sta.sta_id != IWL_MVM_INVALID_STA)
3847 iwl_mvm_int_sta_modify_disable_tx(mvm, mvmvif,
3848 &mvmvif->mcast_sta, disable);
3849
3850
3851
3852
3853
3854 if (!disable && mvmvif->bcast_sta.sta_id != IWL_MVM_INVALID_STA)
3855 iwl_mvm_int_sta_modify_disable_tx(mvm, mvmvif,
3856 &mvmvif->bcast_sta, disable);
3857}
3858
3859void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
3860{
3861 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3862 struct iwl_mvm_sta *mvmsta;
3863
3864 rcu_read_lock();
3865
3866 mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id);
3867
3868 if (!WARN_ON(!mvmsta))
3869 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true);
3870
3871 rcu_read_unlock();
3872}
3873
3874u16 iwl_mvm_tid_queued(struct iwl_mvm *mvm, struct iwl_mvm_tid_data *tid_data)
3875{
3876 u16 sn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
3877
3878
3879
3880
3881
3882 if (mvm->trans->trans_cfg->gen2)
3883 sn &= 0xff;
3884
3885 return ieee80211_sn_sub(sn, tid_data->next_reclaimed);
3886}
3887