]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - drivers/net/wireless/intel/iwlwifi/mvm/sta.c
iwlwifi: mvm: support new TX response for TVQM
[mirror_ubuntu-focal-kernel.git] / drivers / net / wireless / intel / iwlwifi / mvm / sta.c
CommitLineData
8ca151b5
JB
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
fa7878e7
AO
8 * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
26d6c16b 10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
8ca151b5
JB
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * USA
25 *
26 * The full GNU General Public License is included in this distribution
410dc5aa 27 * in the file called COPYING.
8ca151b5
JB
28 *
29 * Contact Information:
cb2f8277 30 * Intel Linux Wireless <linuxwifi@intel.com>
8ca151b5
JB
31 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
fa7878e7
AO
35 * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved.
36 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
26d6c16b 37 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
8ca151b5
JB
38 * All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 *
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * * Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in
48 * the documentation and/or other materials provided with the
49 * distribution.
50 * * Neither the name Intel Corporation nor the names of its
51 * contributors may be used to endorse or promote products derived
52 * from this software without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 *
66 *****************************************************************************/
67#include <net/mac80211.h>
68
69#include "mvm.h"
70#include "sta.h"
9ee718aa 71#include "rs.h"
8ca151b5 72
854c5705
SS
73/*
74 * New version of ADD_STA_sta command added new fields at the end of the
75 * structure, so sending the size of the relevant API's structure is enough to
76 * support both API versions.
77 */
78static inline int iwl_mvm_add_sta_cmd_size(struct iwl_mvm *mvm)
79{
80 return iwl_mvm_has_new_rx_api(mvm) ?
81 sizeof(struct iwl_mvm_add_sta_cmd) :
82 sizeof(struct iwl_mvm_add_sta_cmd_v7);
83}
84
b92e661b
EP
85static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm,
86 enum nl80211_iftype iftype)
8ca151b5
JB
87{
88 int sta_id;
b92e661b 89 u32 reserved_ids = 0;
8ca151b5 90
b92e661b 91 BUILD_BUG_ON(IWL_MVM_STATION_COUNT > 32);
8ca151b5
JB
92 WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status));
93
94 lockdep_assert_held(&mvm->mutex);
95
b92e661b
EP
96 /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */
97 if (iftype != NL80211_IFTYPE_STATION)
98 reserved_ids = BIT(0);
99
8ca151b5 100 /* Don't take rcu_read_lock() since we are protected by mvm->mutex */
0ae98812 101 for (sta_id = 0; sta_id < ARRAY_SIZE(mvm->fw_id_to_mac_id); sta_id++) {
b92e661b
EP
102 if (BIT(sta_id) & reserved_ids)
103 continue;
104
8ca151b5
JB
105 if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
106 lockdep_is_held(&mvm->mutex)))
107 return sta_id;
b92e661b 108 }
0ae98812 109 return IWL_MVM_INVALID_STA;
8ca151b5
JB
110}
111
7a453973
JB
112/* send station add/update command to firmware */
113int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
24afba76 114 bool update, unsigned int flags)
8ca151b5 115{
9d8ce6af 116 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
4b8265ab
EG
117 struct iwl_mvm_add_sta_cmd add_sta_cmd = {
118 .sta_id = mvm_sta->sta_id,
119 .mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color),
120 .add_modify = update ? 1 : 0,
121 .station_flags_msk = cpu_to_le32(STA_FLG_FAT_EN_MSK |
122 STA_FLG_MIMO_EN_MSK),
cf0cda19 123 .tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg),
4b8265ab 124 };
8ca151b5
JB
125 int ret;
126 u32 status;
127 u32 agg_size = 0, mpdu_dens = 0;
128
24afba76 129 if (!update || (flags & STA_MODIFY_QUEUES)) {
7a453973 130 memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN);
24afba76 131
bb49701b
SS
132 if (!iwl_mvm_has_new_tx_api(mvm)) {
133 add_sta_cmd.tfd_queue_msk =
134 cpu_to_le32(mvm_sta->tfd_queue_msk);
135
136 if (flags & STA_MODIFY_QUEUES)
137 add_sta_cmd.modify_mask |= STA_MODIFY_QUEUES;
138 } else {
139 WARN_ON(flags & STA_MODIFY_QUEUES);
140 }
7a453973 141 }
5bc5aaad
JB
142
143 switch (sta->bandwidth) {
144 case IEEE80211_STA_RX_BW_160:
145 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_160MHZ);
146 /* fall through */
147 case IEEE80211_STA_RX_BW_80:
148 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_80MHZ);
149 /* fall through */
150 case IEEE80211_STA_RX_BW_40:
151 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_40MHZ);
152 /* fall through */
153 case IEEE80211_STA_RX_BW_20:
154 if (sta->ht_cap.ht_supported)
155 add_sta_cmd.station_flags |=
156 cpu_to_le32(STA_FLG_FAT_EN_20MHZ);
157 break;
158 }
159
160 switch (sta->rx_nss) {
161 case 1:
162 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO);
163 break;
164 case 2:
165 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2);
166 break;
167 case 3 ... 8:
168 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3);
169 break;
170 }
171
172 switch (sta->smps_mode) {
173 case IEEE80211_SMPS_AUTOMATIC:
174 case IEEE80211_SMPS_NUM_MODES:
175 WARN_ON(1);
176 break;
177 case IEEE80211_SMPS_STATIC:
178 /* override NSS */
179 add_sta_cmd.station_flags &= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK);
180 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO);
181 break;
182 case IEEE80211_SMPS_DYNAMIC:
183 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_RTS_MIMO_PROT);
184 break;
185 case IEEE80211_SMPS_OFF:
186 /* nothing */
187 break;
188 }
8ca151b5
JB
189
190 if (sta->ht_cap.ht_supported) {
191 add_sta_cmd.station_flags_msk |=
192 cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK |
193 STA_FLG_AGG_MPDU_DENS_MSK);
194
195 mpdu_dens = sta->ht_cap.ampdu_density;
196 }
197
198 if (sta->vht_cap.vht_supported) {
199 agg_size = sta->vht_cap.cap &
200 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
201 agg_size >>=
202 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
203 } else if (sta->ht_cap.ht_supported) {
204 agg_size = sta->ht_cap.ampdu_factor;
205 }
206
207 add_sta_cmd.station_flags |=
208 cpu_to_le32(agg_size << STA_FLG_MAX_AGG_SIZE_SHIFT);
209 add_sta_cmd.station_flags |=
210 cpu_to_le32(mpdu_dens << STA_FLG_AGG_MPDU_DENS_SHIFT);
6ea29ce5
JB
211 if (mvm_sta->associated)
212 add_sta_cmd.assoc_id = cpu_to_le16(sta->aid);
8ca151b5 213
65e25482
JB
214 if (sta->wme) {
215 add_sta_cmd.modify_mask |= STA_MODIFY_UAPSD_ACS;
216
217 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
c80eb570 218 add_sta_cmd.uapsd_acs |= BIT(AC_BK);
65e25482 219 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
c80eb570 220 add_sta_cmd.uapsd_acs |= BIT(AC_BE);
65e25482 221 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
c80eb570 222 add_sta_cmd.uapsd_acs |= BIT(AC_VI);
65e25482 223 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
c80eb570
EG
224 add_sta_cmd.uapsd_acs |= BIT(AC_VO);
225 add_sta_cmd.uapsd_acs |= add_sta_cmd.uapsd_acs << 4;
226 add_sta_cmd.sp_length = sta->max_sp;
65e25482
JB
227 }
228
8ca151b5 229 status = ADD_STA_SUCCESS;
854c5705
SS
230 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
231 iwl_mvm_add_sta_cmd_size(mvm),
f9dc0004 232 &add_sta_cmd, &status);
8ca151b5
JB
233 if (ret)
234 return ret;
235
837c4da9 236 switch (status & IWL_ADD_STA_STATUS_MASK) {
8ca151b5
JB
237 case ADD_STA_SUCCESS:
238 IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n");
239 break;
240 default:
241 ret = -EIO;
242 IWL_ERR(mvm, "ADD_STA failed\n");
243 break;
244 }
245
246 return ret;
247}
248
10b2b201
SS
249static void iwl_mvm_rx_agg_session_expired(unsigned long data)
250{
251 struct iwl_mvm_baid_data __rcu **rcu_ptr = (void *)data;
252 struct iwl_mvm_baid_data *ba_data;
253 struct ieee80211_sta *sta;
254 struct iwl_mvm_sta *mvm_sta;
255 unsigned long timeout;
256
257 rcu_read_lock();
258
259 ba_data = rcu_dereference(*rcu_ptr);
260
261 if (WARN_ON(!ba_data))
262 goto unlock;
263
264 if (!ba_data->timeout)
265 goto unlock;
266
267 timeout = ba_data->last_rx + TU_TO_JIFFIES(ba_data->timeout * 2);
268 if (time_is_after_jiffies(timeout)) {
269 mod_timer(&ba_data->session_timer, timeout);
270 goto unlock;
271 }
272
273 /* Timer expired */
274 sta = rcu_dereference(ba_data->mvm->fw_id_to_mac_id[ba_data->sta_id]);
275 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
276 ieee80211_stop_rx_ba_session_offl(mvm_sta->vif,
277 sta->addr, ba_data->tid);
278unlock:
279 rcu_read_unlock();
280}
281
a0f6bf2a
AN
282static int iwl_mvm_tdls_sta_init(struct iwl_mvm *mvm,
283 struct ieee80211_sta *sta)
284{
285 unsigned long used_hw_queues;
286 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
5d42e7b2
EG
287 unsigned int wdg_timeout =
288 iwl_mvm_get_wd_timeout(mvm, NULL, true, false);
a0f6bf2a
AN
289 u32 ac;
290
291 lockdep_assert_held(&mvm->mutex);
292
293 used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, NULL);
294
295 /* Find available queues, and allocate them to the ACs */
296 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
297 u8 queue = find_first_zero_bit(&used_hw_queues,
298 mvm->first_agg_queue);
299
300 if (queue >= mvm->first_agg_queue) {
301 IWL_ERR(mvm, "Failed to allocate STA queue\n");
302 return -EBUSY;
303 }
304
305 __set_bit(queue, &used_hw_queues);
306 mvmsta->hw_queue[ac] = queue;
307 }
308
309 /* Found a place for all queues - enable them */
310 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
311 iwl_mvm_enable_ac_txq(mvm, mvmsta->hw_queue[ac],
4ecafae9 312 mvmsta->hw_queue[ac],
5c1156ef
LK
313 iwl_mvm_ac_to_tx_fifo[ac], 0,
314 wdg_timeout);
a0f6bf2a
AN
315 mvmsta->tfd_queue_msk |= BIT(mvmsta->hw_queue[ac]);
316 }
317
318 return 0;
319}
320
321static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm *mvm,
322 struct ieee80211_sta *sta)
323{
324 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
325 unsigned long sta_msk;
326 int i;
327
328 lockdep_assert_held(&mvm->mutex);
329
330 /* disable the TDLS STA-specific queues */
331 sta_msk = mvmsta->tfd_queue_msk;
a4ca3ed4 332 for_each_set_bit(i, &sta_msk, sizeof(sta_msk) * BITS_PER_BYTE)
06ecdba3 333 iwl_mvm_disable_txq(mvm, i, i, IWL_MAX_TID_COUNT, 0);
a0f6bf2a
AN
334}
335
9794c64f
LK
336/* Disable aggregations for a bitmap of TIDs for a given station */
337static int iwl_mvm_invalidate_sta_queue(struct iwl_mvm *mvm, int queue,
338 unsigned long disable_agg_tids,
339 bool remove_queue)
340{
341 struct iwl_mvm_add_sta_cmd cmd = {};
342 struct ieee80211_sta *sta;
343 struct iwl_mvm_sta *mvmsta;
344 u32 status;
345 u8 sta_id;
346 int ret;
347
bb49701b
SS
348 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
349 return -EINVAL;
350
9794c64f
LK
351 spin_lock_bh(&mvm->queue_info_lock);
352 sta_id = mvm->queue_info[queue].ra_sta_id;
353 spin_unlock_bh(&mvm->queue_info_lock);
354
355 rcu_read_lock();
356
357 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
358
359 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
360 rcu_read_unlock();
361 return -EINVAL;
362 }
363
364 mvmsta = iwl_mvm_sta_from_mac80211(sta);
365
366 mvmsta->tid_disable_agg |= disable_agg_tids;
367
368 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
369 cmd.sta_id = mvmsta->sta_id;
370 cmd.add_modify = STA_MODE_MODIFY;
371 cmd.modify_mask = STA_MODIFY_QUEUES;
372 if (disable_agg_tids)
373 cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX;
374 if (remove_queue)
375 cmd.modify_mask |= STA_MODIFY_QUEUE_REMOVAL;
376 cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk);
377 cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg);
378
379 rcu_read_unlock();
380
381 /* Notify FW of queue removal from the STA queues */
382 status = ADD_STA_SUCCESS;
383 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
384 iwl_mvm_add_sta_cmd_size(mvm),
385 &cmd, &status);
386
387 return ret;
388}
389
42db09c1
LK
390static int iwl_mvm_get_queue_agg_tids(struct iwl_mvm *mvm, int queue)
391{
392 struct ieee80211_sta *sta;
393 struct iwl_mvm_sta *mvmsta;
394 unsigned long tid_bitmap;
395 unsigned long agg_tids = 0;
396 s8 sta_id;
397 int tid;
398
399 lockdep_assert_held(&mvm->mutex);
400
bb49701b
SS
401 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
402 return -EINVAL;
403
42db09c1
LK
404 spin_lock_bh(&mvm->queue_info_lock);
405 sta_id = mvm->queue_info[queue].ra_sta_id;
406 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
407 spin_unlock_bh(&mvm->queue_info_lock);
408
409 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
410 lockdep_is_held(&mvm->mutex));
411
412 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
413 return -EINVAL;
414
415 mvmsta = iwl_mvm_sta_from_mac80211(sta);
416
417 spin_lock_bh(&mvmsta->lock);
418 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
419 if (mvmsta->tid_data[tid].state == IWL_AGG_ON)
420 agg_tids |= BIT(tid);
421 }
422 spin_unlock_bh(&mvmsta->lock);
423
424 return agg_tids;
425}
426
9794c64f
LK
427/*
428 * Remove a queue from a station's resources.
429 * Note that this only marks as free. It DOESN'T delete a BA agreement, and
430 * doesn't disable the queue
431 */
432static int iwl_mvm_remove_sta_queue_marking(struct iwl_mvm *mvm, int queue)
433{
434 struct ieee80211_sta *sta;
435 struct iwl_mvm_sta *mvmsta;
436 unsigned long tid_bitmap;
437 unsigned long disable_agg_tids = 0;
438 u8 sta_id;
439 int tid;
440
441 lockdep_assert_held(&mvm->mutex);
442
bb49701b
SS
443 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
444 return -EINVAL;
445
9794c64f
LK
446 spin_lock_bh(&mvm->queue_info_lock);
447 sta_id = mvm->queue_info[queue].ra_sta_id;
448 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
449 spin_unlock_bh(&mvm->queue_info_lock);
450
451 rcu_read_lock();
452
453 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
454
455 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
456 rcu_read_unlock();
457 return 0;
458 }
459
460 mvmsta = iwl_mvm_sta_from_mac80211(sta);
461
462 spin_lock_bh(&mvmsta->lock);
42db09c1 463 /* Unmap MAC queues and TIDs from this queue */
9794c64f 464 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
9794c64f
LK
465 if (mvmsta->tid_data[tid].state == IWL_AGG_ON)
466 disable_agg_tids |= BIT(tid);
42db09c1 467 mvmsta->tid_data[tid].txq_id = IEEE80211_INVAL_HW_QUEUE;
9794c64f 468 }
9794c64f 469
42db09c1 470 mvmsta->tfd_queue_msk &= ~BIT(queue); /* Don't use this queue anymore */
9794c64f
LK
471 spin_unlock_bh(&mvmsta->lock);
472
473 rcu_read_unlock();
474
9794c64f
LK
475 return disable_agg_tids;
476}
477
01796ff2
SS
478static int iwl_mvm_free_inactive_queue(struct iwl_mvm *mvm, int queue,
479 bool same_sta)
480{
481 struct iwl_mvm_sta *mvmsta;
482 u8 txq_curr_ac, sta_id, tid;
483 unsigned long disable_agg_tids = 0;
484 int ret;
485
486 lockdep_assert_held(&mvm->mutex);
487
bb49701b
SS
488 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
489 return -EINVAL;
490
01796ff2
SS
491 spin_lock_bh(&mvm->queue_info_lock);
492 txq_curr_ac = mvm->queue_info[queue].mac80211_ac;
493 sta_id = mvm->queue_info[queue].ra_sta_id;
494 tid = mvm->queue_info[queue].txq_tid;
495 spin_unlock_bh(&mvm->queue_info_lock);
496
497 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
498
499 disable_agg_tids = iwl_mvm_remove_sta_queue_marking(mvm, queue);
500 /* Disable the queue */
501 if (disable_agg_tids)
502 iwl_mvm_invalidate_sta_queue(mvm, queue,
503 disable_agg_tids, false);
504
505 ret = iwl_mvm_disable_txq(mvm, queue,
506 mvmsta->vif->hw_queue[txq_curr_ac],
507 tid, 0);
508 if (ret) {
509 /* Re-mark the inactive queue as inactive */
510 spin_lock_bh(&mvm->queue_info_lock);
511 mvm->queue_info[queue].status = IWL_MVM_QUEUE_INACTIVE;
512 spin_unlock_bh(&mvm->queue_info_lock);
513 IWL_ERR(mvm,
514 "Failed to free inactive queue %d (ret=%d)\n",
515 queue, ret);
516
517 return ret;
518 }
519
520 /* If TXQ is allocated to another STA, update removal in FW */
521 if (!same_sta)
522 iwl_mvm_invalidate_sta_queue(mvm, queue, 0, true);
523
524 return 0;
525}
526
42db09c1
LK
527static int iwl_mvm_get_shared_queue(struct iwl_mvm *mvm,
528 unsigned long tfd_queue_mask, u8 ac)
529{
530 int queue = 0;
531 u8 ac_to_queue[IEEE80211_NUM_ACS];
532 int i;
533
534 lockdep_assert_held(&mvm->queue_info_lock);
bb49701b
SS
535 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
536 return -EINVAL;
42db09c1
LK
537
538 memset(&ac_to_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(ac_to_queue));
539
540 /* See what ACs the existing queues for this STA have */
541 for_each_set_bit(i, &tfd_queue_mask, IWL_MVM_DQA_MAX_DATA_QUEUE) {
542 /* Only DATA queues can be shared */
543 if (i < IWL_MVM_DQA_MIN_DATA_QUEUE &&
544 i != IWL_MVM_DQA_BSS_CLIENT_QUEUE)
545 continue;
546
9f9af3d7
LK
547 /* Don't try and take queues being reconfigured */
548 if (mvm->queue_info[queue].status ==
549 IWL_MVM_QUEUE_RECONFIGURING)
550 continue;
551
42db09c1
LK
552 ac_to_queue[mvm->queue_info[i].mac80211_ac] = i;
553 }
554
555 /*
556 * The queue to share is chosen only from DATA queues as follows (in
557 * descending priority):
558 * 1. An AC_BE queue
559 * 2. Same AC queue
560 * 3. Highest AC queue that is lower than new AC
561 * 4. Any existing AC (there always is at least 1 DATA queue)
562 */
563
564 /* Priority 1: An AC_BE queue */
565 if (ac_to_queue[IEEE80211_AC_BE] != IEEE80211_INVAL_HW_QUEUE)
566 queue = ac_to_queue[IEEE80211_AC_BE];
567 /* Priority 2: Same AC queue */
568 else if (ac_to_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
569 queue = ac_to_queue[ac];
570 /* Priority 3a: If new AC is VO and VI exists - use VI */
571 else if (ac == IEEE80211_AC_VO &&
572 ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE)
573 queue = ac_to_queue[IEEE80211_AC_VI];
574 /* Priority 3b: No BE so only AC less than the new one is BK */
575 else if (ac_to_queue[IEEE80211_AC_BK] != IEEE80211_INVAL_HW_QUEUE)
576 queue = ac_to_queue[IEEE80211_AC_BK];
577 /* Priority 4a: No BE nor BK - use VI if exists */
578 else if (ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE)
579 queue = ac_to_queue[IEEE80211_AC_VI];
580 /* Priority 4b: No BE, BK nor VI - use VO if exists */
581 else if (ac_to_queue[IEEE80211_AC_VO] != IEEE80211_INVAL_HW_QUEUE)
582 queue = ac_to_queue[IEEE80211_AC_VO];
583
584 /* Make sure queue found (or not) is legal */
9f9af3d7
LK
585 if (!iwl_mvm_is_dqa_data_queue(mvm, queue) &&
586 !iwl_mvm_is_dqa_mgmt_queue(mvm, queue) &&
587 (queue != IWL_MVM_DQA_BSS_CLIENT_QUEUE)) {
42db09c1 588 IWL_ERR(mvm, "No DATA queues available to share\n");
9f9af3d7
LK
589 return -ENOSPC;
590 }
591
592 /* Make sure the queue isn't in the middle of being reconfigured */
593 if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_RECONFIGURING) {
594 IWL_ERR(mvm,
595 "TXQ %d is in the middle of re-config - try again\n",
596 queue);
597 return -EBUSY;
42db09c1
LK
598 }
599
600 return queue;
601}
602
58f2cc57 603/*
9f9af3d7
LK
604 * If a given queue has a higher AC than the TID stream that is being compared
605 * to, the queue needs to be redirected to the lower AC. This function does that
58f2cc57
LK
606 * in such a case, otherwise - if no redirection required - it does nothing,
607 * unless the %force param is true.
608 */
9f9af3d7
LK
609int iwl_mvm_scd_queue_redirect(struct iwl_mvm *mvm, int queue, int tid,
610 int ac, int ssn, unsigned int wdg_timeout,
611 bool force)
58f2cc57
LK
612{
613 struct iwl_scd_txq_cfg_cmd cmd = {
614 .scd_queue = queue,
f7c692de 615 .action = SCD_CFG_DISABLE_QUEUE,
58f2cc57
LK
616 };
617 bool shared_queue;
618 unsigned long mq;
619 int ret;
620
bb49701b
SS
621 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
622 return -EINVAL;
623
58f2cc57
LK
624 /*
625 * If the AC is lower than current one - FIFO needs to be redirected to
626 * the lowest one of the streams in the queue. Check if this is needed
627 * here.
628 * Notice that the enum ieee80211_ac_numbers is "flipped", so BK is with
629 * value 3 and VO with value 0, so to check if ac X is lower than ac Y
630 * we need to check if the numerical value of X is LARGER than of Y.
631 */
632 spin_lock_bh(&mvm->queue_info_lock);
633 if (ac <= mvm->queue_info[queue].mac80211_ac && !force) {
634 spin_unlock_bh(&mvm->queue_info_lock);
635
636 IWL_DEBUG_TX_QUEUES(mvm,
637 "No redirection needed on TXQ #%d\n",
638 queue);
639 return 0;
640 }
641
642 cmd.sta_id = mvm->queue_info[queue].ra_sta_id;
643 cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[mvm->queue_info[queue].mac80211_ac];
edbe961c 644 cmd.tid = mvm->queue_info[queue].txq_tid;
58f2cc57
LK
645 mq = mvm->queue_info[queue].hw_queue_to_mac80211;
646 shared_queue = (mvm->queue_info[queue].hw_queue_refcount > 1);
647 spin_unlock_bh(&mvm->queue_info_lock);
648
9f9af3d7 649 IWL_DEBUG_TX_QUEUES(mvm, "Redirecting TXQ #%d to FIFO #%d\n",
58f2cc57
LK
650 queue, iwl_mvm_ac_to_tx_fifo[ac]);
651
652 /* Stop MAC queues and wait for this queue to empty */
653 iwl_mvm_stop_mac_queues(mvm, mq);
654 ret = iwl_trans_wait_tx_queue_empty(mvm->trans, BIT(queue));
655 if (ret) {
656 IWL_ERR(mvm, "Error draining queue %d before reconfig\n",
657 queue);
658 ret = -EIO;
659 goto out;
660 }
661
662 /* Before redirecting the queue we need to de-activate it */
663 iwl_trans_txq_disable(mvm->trans, queue, false);
664 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd);
665 if (ret)
666 IWL_ERR(mvm, "Failed SCD disable TXQ %d (ret=%d)\n", queue,
667 ret);
668
669 /* Make sure the SCD wrptr is correctly set before reconfiguring */
ca3b9c6b 670 iwl_trans_txq_enable_cfg(mvm->trans, queue, ssn, NULL, wdg_timeout);
58f2cc57 671
edbe961c
LK
672 /* Update the TID "owner" of the queue */
673 spin_lock_bh(&mvm->queue_info_lock);
674 mvm->queue_info[queue].txq_tid = tid;
675 spin_unlock_bh(&mvm->queue_info_lock);
676
58f2cc57
LK
677 /* TODO: Work-around SCD bug when moving back by multiples of 0x40 */
678
679 /* Redirect to lower AC */
680 iwl_mvm_reconfig_scd(mvm, queue, iwl_mvm_ac_to_tx_fifo[ac],
681 cmd.sta_id, tid, LINK_QUAL_AGG_FRAME_LIMIT_DEF,
682 ssn);
683
684 /* Update AC marking of the queue */
685 spin_lock_bh(&mvm->queue_info_lock);
686 mvm->queue_info[queue].mac80211_ac = ac;
687 spin_unlock_bh(&mvm->queue_info_lock);
688
689 /*
690 * Mark queue as shared in transport if shared
691 * Note this has to be done after queue enablement because enablement
692 * can also set this value, and there is no indication there to shared
693 * queues
694 */
695 if (shared_queue)
696 iwl_trans_txq_set_shared_mode(mvm->trans, queue, true);
697
698out:
699 /* Continue using the MAC queues */
700 iwl_mvm_start_mac_queues(mvm, mq);
701
702 return ret;
703}
704
24afba76
LK
705static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm,
706 struct ieee80211_sta *sta, u8 ac, int tid,
707 struct ieee80211_hdr *hdr)
708{
709 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
710 struct iwl_trans_txq_scd_cfg cfg = {
711 .fifo = iwl_mvm_ac_to_tx_fifo[ac],
712 .sta_id = mvmsta->sta_id,
713 .tid = tid,
714 .frame_limit = IWL_FRAME_LIMIT,
715 };
716 unsigned int wdg_timeout =
717 iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
718 u8 mac_queue = mvmsta->vif->hw_queue[ac];
719 int queue = -1;
01796ff2 720 bool using_inactive_queue = false, same_sta = false;
9794c64f
LK
721 unsigned long disable_agg_tids = 0;
722 enum iwl_mvm_agg_state queue_state;
42db09c1 723 bool shared_queue = false;
24afba76 724 int ssn;
42db09c1 725 unsigned long tfd_queue_mask;
cf961e16 726 int ret;
24afba76
LK
727
728 lockdep_assert_held(&mvm->mutex);
729
42db09c1
LK
730 spin_lock_bh(&mvmsta->lock);
731 tfd_queue_mask = mvmsta->tfd_queue_msk;
732 spin_unlock_bh(&mvmsta->lock);
733
d2515a99 734 spin_lock_bh(&mvm->queue_info_lock);
24afba76
LK
735
736 /*
737 * Non-QoS, QoS NDP and MGMT frames should go to a MGMT queue, if one
738 * exists
739 */
740 if (!ieee80211_is_data_qos(hdr->frame_control) ||
741 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
9794c64f
LK
742 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
743 IWL_MVM_DQA_MIN_MGMT_QUEUE,
24afba76
LK
744 IWL_MVM_DQA_MAX_MGMT_QUEUE);
745 if (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE)
746 IWL_DEBUG_TX_QUEUES(mvm, "Found free MGMT queue #%d\n",
747 queue);
748
749 /* If no such queue is found, we'll use a DATA queue instead */
750 }
751
9794c64f
LK
752 if ((queue < 0 && mvmsta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) &&
753 (mvm->queue_info[mvmsta->reserved_queue].status ==
754 IWL_MVM_QUEUE_RESERVED ||
755 mvm->queue_info[mvmsta->reserved_queue].status ==
756 IWL_MVM_QUEUE_INACTIVE)) {
24afba76 757 queue = mvmsta->reserved_queue;
9794c64f 758 mvm->queue_info[queue].reserved = true;
24afba76
LK
759 IWL_DEBUG_TX_QUEUES(mvm, "Using reserved queue #%d\n", queue);
760 }
761
762 if (queue < 0)
9794c64f
LK
763 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
764 IWL_MVM_DQA_MIN_DATA_QUEUE,
24afba76 765 IWL_MVM_DQA_MAX_DATA_QUEUE);
cf961e16 766
9794c64f
LK
767 /*
768 * Check if this queue is already allocated but inactive.
769 * In such a case, we'll need to first free this queue before enabling
770 * it again, so we'll mark it as reserved to make sure no new traffic
771 * arrives on it
772 */
773 if (queue > 0 &&
774 mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) {
775 mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED;
776 using_inactive_queue = true;
01796ff2 777 same_sta = mvm->queue_info[queue].ra_sta_id == mvmsta->sta_id;
9794c64f
LK
778 IWL_DEBUG_TX_QUEUES(mvm,
779 "Re-assigning TXQ %d: sta_id=%d, tid=%d\n",
780 queue, mvmsta->sta_id, tid);
781 }
782
42db09c1
LK
783 /* No free queue - we'll have to share */
784 if (queue <= 0) {
bb49701b
SS
785 /* This shouldn't happen in new HW - we have 512 queues */
786 if (WARN(iwl_mvm_has_new_tx_api(mvm),
787 "No available queues for tid %d on sta_id %d\n",
788 tid, cfg.sta_id)) {
789 spin_unlock_bh(&mvm->queue_info_lock);
790
791 return queue;
792 }
793
42db09c1
LK
794 queue = iwl_mvm_get_shared_queue(mvm, tfd_queue_mask, ac);
795 if (queue > 0) {
796 shared_queue = true;
797 mvm->queue_info[queue].status = IWL_MVM_QUEUE_SHARED;
798 }
799 }
800
cf961e16
LK
801 /*
802 * Mark TXQ as ready, even though it hasn't been fully configured yet,
803 * to make sure no one else takes it.
804 * This will allow avoiding re-acquiring the lock at the end of the
805 * configuration. On error we'll mark it back as free.
806 */
42db09c1 807 if ((queue > 0) && !shared_queue)
cf961e16 808 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
24afba76 809
d2515a99 810 spin_unlock_bh(&mvm->queue_info_lock);
24afba76 811
42db09c1
LK
812 /* This shouldn't happen - out of queues */
813 if (WARN_ON(queue <= 0)) {
814 IWL_ERR(mvm, "No available queues for tid %d on sta_id %d\n",
815 tid, cfg.sta_id);
9f9af3d7 816 return queue;
42db09c1 817 }
24afba76
LK
818
819 /*
820 * Actual en/disablement of aggregations is through the ADD_STA HCMD,
821 * but for configuring the SCD to send A-MPDUs we need to mark the queue
822 * as aggregatable.
823 * Mark all DATA queues as allowing to be aggregated at some point
824 */
d5216a28
LK
825 cfg.aggregate = (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
826 queue == IWL_MVM_DQA_BSS_CLIENT_QUEUE);
24afba76 827
9794c64f
LK
828 /*
829 * If this queue was previously inactive (idle) - we need to free it
830 * first
831 */
832 if (using_inactive_queue) {
01796ff2
SS
833 ret = iwl_mvm_free_inactive_queue(mvm, queue, same_sta);
834 if (ret)
9794c64f 835 return ret;
9794c64f
LK
836 }
837
42db09c1
LK
838 IWL_DEBUG_TX_QUEUES(mvm,
839 "Allocating %squeue #%d to sta %d on tid %d\n",
840 shared_queue ? "shared " : "", queue,
841 mvmsta->sta_id, tid);
842
843 if (shared_queue) {
844 /* Disable any open aggs on this queue */
845 disable_agg_tids = iwl_mvm_get_queue_agg_tids(mvm, queue);
846
847 if (disable_agg_tids) {
848 IWL_DEBUG_TX_QUEUES(mvm, "Disabling aggs on queue %d\n",
849 queue);
850 iwl_mvm_invalidate_sta_queue(mvm, queue,
851 disable_agg_tids, false);
852 }
42db09c1 853 }
24afba76
LK
854
855 ssn = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
856 iwl_mvm_enable_txq(mvm, queue, mac_queue, ssn, &cfg,
857 wdg_timeout);
858
58f2cc57
LK
859 /*
860 * Mark queue as shared in transport if shared
861 * Note this has to be done after queue enablement because enablement
862 * can also set this value, and there is no indication there to shared
863 * queues
864 */
865 if (shared_queue)
866 iwl_trans_txq_set_shared_mode(mvm->trans, queue, true);
867
24afba76
LK
868 spin_lock_bh(&mvmsta->lock);
869 mvmsta->tid_data[tid].txq_id = queue;
9794c64f 870 mvmsta->tid_data[tid].is_tid_active = true;
24afba76 871 mvmsta->tfd_queue_msk |= BIT(queue);
9794c64f 872 queue_state = mvmsta->tid_data[tid].state;
24afba76
LK
873
874 if (mvmsta->reserved_queue == queue)
875 mvmsta->reserved_queue = IEEE80211_INVAL_HW_QUEUE;
876 spin_unlock_bh(&mvmsta->lock);
877
bb49701b
SS
878 if (iwl_mvm_has_new_tx_api(mvm))
879 return 0;
880
42db09c1
LK
881 if (!shared_queue) {
882 ret = iwl_mvm_sta_send_to_fw(mvm, sta, true, STA_MODIFY_QUEUES);
883 if (ret)
884 goto out_err;
cf961e16 885
42db09c1
LK
886 /* If we need to re-enable aggregations... */
887 if (queue_state == IWL_AGG_ON) {
888 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
889 if (ret)
890 goto out_err;
891 }
58f2cc57
LK
892 } else {
893 /* Redirect queue, if needed */
894 ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid, ac, ssn,
895 wdg_timeout, false);
896 if (ret)
897 goto out_err;
42db09c1 898 }
9794c64f 899
42db09c1 900 return 0;
cf961e16
LK
901
902out_err:
903 iwl_mvm_disable_txq(mvm, queue, mac_queue, tid, 0);
904
905 return ret;
24afba76
LK
906}
907
19aefa45
LK
908static void iwl_mvm_change_queue_owner(struct iwl_mvm *mvm, int queue)
909{
910 struct iwl_scd_txq_cfg_cmd cmd = {
911 .scd_queue = queue,
912 .action = SCD_CFG_UPDATE_QUEUE_TID,
913 };
19aefa45
LK
914 int tid;
915 unsigned long tid_bitmap;
916 int ret;
917
918 lockdep_assert_held(&mvm->mutex);
919
bb49701b
SS
920 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
921 return;
922
19aefa45 923 spin_lock_bh(&mvm->queue_info_lock);
19aefa45
LK
924 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
925 spin_unlock_bh(&mvm->queue_info_lock);
926
927 if (WARN(!tid_bitmap, "TXQ %d has no tids assigned to it\n", queue))
928 return;
929
930 /* Find any TID for queue */
931 tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1);
932 cmd.tid = tid;
933 cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
934
935 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd);
341ca402 936 if (ret) {
19aefa45
LK
937 IWL_ERR(mvm, "Failed to update owner of TXQ %d (ret=%d)\n",
938 queue, ret);
341ca402
LK
939 return;
940 }
941
942 spin_lock_bh(&mvm->queue_info_lock);
943 mvm->queue_info[queue].txq_tid = tid;
944 spin_unlock_bh(&mvm->queue_info_lock);
945 IWL_DEBUG_TX_QUEUES(mvm, "Changed TXQ %d ownership to tid %d\n",
946 queue, tid);
19aefa45
LK
947}
948
9f9af3d7
LK
949static void iwl_mvm_unshare_queue(struct iwl_mvm *mvm, int queue)
950{
951 struct ieee80211_sta *sta;
952 struct iwl_mvm_sta *mvmsta;
953 s8 sta_id;
954 int tid = -1;
955 unsigned long tid_bitmap;
956 unsigned int wdg_timeout;
957 int ssn;
958 int ret = true;
959
bb49701b
SS
960 /* queue sharing is disabled on new TX path */
961 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
962 return;
963
9f9af3d7
LK
964 lockdep_assert_held(&mvm->mutex);
965
966 spin_lock_bh(&mvm->queue_info_lock);
967 sta_id = mvm->queue_info[queue].ra_sta_id;
968 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
969 spin_unlock_bh(&mvm->queue_info_lock);
970
971 /* Find TID for queue, and make sure it is the only one on the queue */
972 tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1);
973 if (tid_bitmap != BIT(tid)) {
974 IWL_ERR(mvm, "Failed to unshare q %d, active tids=0x%lx\n",
975 queue, tid_bitmap);
976 return;
977 }
978
979 IWL_DEBUG_TX_QUEUES(mvm, "Unsharing TXQ %d, keeping tid %d\n", queue,
980 tid);
981
982 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
983 lockdep_is_held(&mvm->mutex));
984
985 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
986 return;
987
988 mvmsta = iwl_mvm_sta_from_mac80211(sta);
989 wdg_timeout = iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
990
991 ssn = IEEE80211_SEQ_TO_SN(mvmsta->tid_data[tid].seq_number);
992
993 ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid,
994 tid_to_mac80211_ac[tid], ssn,
995 wdg_timeout, true);
996 if (ret) {
997 IWL_ERR(mvm, "Failed to redirect TXQ %d\n", queue);
998 return;
999 }
1000
1001 /* If aggs should be turned back on - do it */
1002 if (mvmsta->tid_data[tid].state == IWL_AGG_ON) {
9cd70e80 1003 struct iwl_mvm_add_sta_cmd cmd = {0};
9f9af3d7
LK
1004
1005 mvmsta->tid_disable_agg &= ~BIT(tid);
1006
1007 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
1008 cmd.sta_id = mvmsta->sta_id;
1009 cmd.add_modify = STA_MODE_MODIFY;
1010 cmd.modify_mask = STA_MODIFY_TID_DISABLE_TX;
1011 cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk);
1012 cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg);
1013
1014 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
1015 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
1016 if (!ret) {
1017 IWL_DEBUG_TX_QUEUES(mvm,
1018 "TXQ #%d is now aggregated again\n",
1019 queue);
1020
1021 /* Mark queue intenally as aggregating again */
1022 iwl_trans_txq_set_shared_mode(mvm->trans, queue, false);
1023 }
1024 }
1025
1026 spin_lock_bh(&mvm->queue_info_lock);
1027 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
1028 spin_unlock_bh(&mvm->queue_info_lock);
1029}
1030
24afba76
LK
1031static inline u8 iwl_mvm_tid_to_ac_queue(int tid)
1032{
1033 if (tid == IWL_MAX_TID_COUNT)
1034 return IEEE80211_AC_VO; /* MGMT */
1035
1036 return tid_to_mac80211_ac[tid];
1037}
1038
1039static void iwl_mvm_tx_deferred_stream(struct iwl_mvm *mvm,
1040 struct ieee80211_sta *sta, int tid)
1041{
1042 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1043 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
1044 struct sk_buff *skb;
1045 struct ieee80211_hdr *hdr;
1046 struct sk_buff_head deferred_tx;
1047 u8 mac_queue;
1048 bool no_queue = false; /* Marks if there is a problem with the queue */
1049 u8 ac;
1050
1051 lockdep_assert_held(&mvm->mutex);
1052
1053 skb = skb_peek(&tid_data->deferred_tx_frames);
1054 if (!skb)
1055 return;
1056 hdr = (void *)skb->data;
1057
1058 ac = iwl_mvm_tid_to_ac_queue(tid);
1059 mac_queue = IEEE80211_SKB_CB(skb)->hw_queue;
1060
1061 if (tid_data->txq_id == IEEE80211_INVAL_HW_QUEUE &&
1062 iwl_mvm_sta_alloc_queue(mvm, sta, ac, tid, hdr)) {
1063 IWL_ERR(mvm,
1064 "Can't alloc TXQ for sta %d tid %d - dropping frame\n",
1065 mvmsta->sta_id, tid);
1066
1067 /*
1068 * Mark queue as problematic so later the deferred traffic is
1069 * freed, as we can do nothing with it
1070 */
1071 no_queue = true;
1072 }
1073
1074 __skb_queue_head_init(&deferred_tx);
1075
d2515a99
LK
1076 /* Disable bottom-halves when entering TX path */
1077 local_bh_disable();
24afba76
LK
1078 spin_lock(&mvmsta->lock);
1079 skb_queue_splice_init(&tid_data->deferred_tx_frames, &deferred_tx);
ad5de737 1080 mvmsta->deferred_traffic_tid_map &= ~BIT(tid);
24afba76
LK
1081 spin_unlock(&mvmsta->lock);
1082
24afba76
LK
1083 while ((skb = __skb_dequeue(&deferred_tx)))
1084 if (no_queue || iwl_mvm_tx_skb(mvm, skb, sta))
1085 ieee80211_free_txskb(mvm->hw, skb);
1086 local_bh_enable();
1087
1088 /* Wake queue */
1089 iwl_mvm_start_mac_queues(mvm, BIT(mac_queue));
1090}
1091
1092void iwl_mvm_add_new_dqa_stream_wk(struct work_struct *wk)
1093{
1094 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm,
1095 add_stream_wk);
1096 struct ieee80211_sta *sta;
1097 struct iwl_mvm_sta *mvmsta;
1098 unsigned long deferred_tid_traffic;
9f9af3d7 1099 int queue, sta_id, tid;
24afba76 1100
9794c64f
LK
1101 /* Check inactivity of queues */
1102 iwl_mvm_inactivity_check(mvm);
1103
24afba76
LK
1104 mutex_lock(&mvm->mutex);
1105
9f9af3d7
LK
1106 /* Reconfigure queues requiring reconfiguation */
1107 for (queue = 0; queue < IWL_MAX_HW_QUEUES; queue++) {
1108 bool reconfig;
19aefa45 1109 bool change_owner;
9f9af3d7
LK
1110
1111 spin_lock_bh(&mvm->queue_info_lock);
1112 reconfig = (mvm->queue_info[queue].status ==
1113 IWL_MVM_QUEUE_RECONFIGURING);
19aefa45
LK
1114
1115 /*
1116 * We need to take into account a situation in which a TXQ was
1117 * allocated to TID x, and then turned shared by adding TIDs y
1118 * and z. If TID x becomes inactive and is removed from the TXQ,
1119 * ownership must be given to one of the remaining TIDs.
1120 * This is mainly because if TID x continues - a new queue can't
1121 * be allocated for it as long as it is an owner of another TXQ.
1122 */
1123 change_owner = !(mvm->queue_info[queue].tid_bitmap &
1124 BIT(mvm->queue_info[queue].txq_tid)) &&
1125 (mvm->queue_info[queue].status ==
1126 IWL_MVM_QUEUE_SHARED);
9f9af3d7
LK
1127 spin_unlock_bh(&mvm->queue_info_lock);
1128
1129 if (reconfig)
1130 iwl_mvm_unshare_queue(mvm, queue);
19aefa45
LK
1131 else if (change_owner)
1132 iwl_mvm_change_queue_owner(mvm, queue);
9f9af3d7
LK
1133 }
1134
24afba76
LK
1135 /* Go over all stations with deferred traffic */
1136 for_each_set_bit(sta_id, mvm->sta_deferred_frames,
1137 IWL_MVM_STATION_COUNT) {
1138 clear_bit(sta_id, mvm->sta_deferred_frames);
1139 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1140 lockdep_is_held(&mvm->mutex));
1141 if (IS_ERR_OR_NULL(sta))
1142 continue;
1143
1144 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1145 deferred_tid_traffic = mvmsta->deferred_traffic_tid_map;
1146
1147 for_each_set_bit(tid, &deferred_tid_traffic,
1148 IWL_MAX_TID_COUNT + 1)
1149 iwl_mvm_tx_deferred_stream(mvm, sta, tid);
1150 }
1151
1152 mutex_unlock(&mvm->mutex);
1153}
1154
1155static int iwl_mvm_reserve_sta_stream(struct iwl_mvm *mvm,
d5216a28
LK
1156 struct ieee80211_sta *sta,
1157 enum nl80211_iftype vif_type)
24afba76
LK
1158{
1159 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1160 int queue;
01796ff2 1161 bool using_inactive_queue = false, same_sta = false;
24afba76 1162
9794c64f
LK
1163 /*
1164 * Check for inactive queues, so we don't reach a situation where we
1165 * can't add a STA due to a shortage in queues that doesn't really exist
1166 */
1167 iwl_mvm_inactivity_check(mvm);
1168
24afba76
LK
1169 spin_lock_bh(&mvm->queue_info_lock);
1170
1171 /* Make sure we have free resources for this STA */
d5216a28
LK
1172 if (vif_type == NL80211_IFTYPE_STATION && !sta->tdls &&
1173 !mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].hw_queue_refcount &&
cf961e16
LK
1174 (mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].status ==
1175 IWL_MVM_QUEUE_FREE))
d5216a28
LK
1176 queue = IWL_MVM_DQA_BSS_CLIENT_QUEUE;
1177 else
9794c64f
LK
1178 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
1179 IWL_MVM_DQA_MIN_DATA_QUEUE,
d5216a28 1180 IWL_MVM_DQA_MAX_DATA_QUEUE);
24afba76
LK
1181 if (queue < 0) {
1182 spin_unlock_bh(&mvm->queue_info_lock);
1183 IWL_ERR(mvm, "No available queues for new station\n");
1184 return -ENOSPC;
01796ff2
SS
1185 } else if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) {
1186 /*
1187 * If this queue is already allocated but inactive we'll need to
1188 * first free this queue before enabling it again, we'll mark
1189 * it as reserved to make sure no new traffic arrives on it
1190 */
1191 using_inactive_queue = true;
1192 same_sta = mvm->queue_info[queue].ra_sta_id == mvmsta->sta_id;
24afba76 1193 }
cf961e16 1194 mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED;
24afba76
LK
1195
1196 spin_unlock_bh(&mvm->queue_info_lock);
1197
1198 mvmsta->reserved_queue = queue;
1199
01796ff2
SS
1200 if (using_inactive_queue)
1201 iwl_mvm_free_inactive_queue(mvm, queue, same_sta);
1202
24afba76
LK
1203 IWL_DEBUG_TX_QUEUES(mvm, "Reserving data queue #%d for sta_id %d\n",
1204 queue, mvmsta->sta_id);
1205
1206 return 0;
1207}
1208
8d98ae6e
LK
1209/*
1210 * In DQA mode, after a HW restart the queues should be allocated as before, in
1211 * order to avoid race conditions when there are shared queues. This function
1212 * does the re-mapping and queue allocation.
1213 *
1214 * Note that re-enabling aggregations isn't done in this function.
1215 */
1216static void iwl_mvm_realloc_queues_after_restart(struct iwl_mvm *mvm,
1217 struct iwl_mvm_sta *mvm_sta)
1218{
1219 unsigned int wdg_timeout =
1220 iwl_mvm_get_wd_timeout(mvm, mvm_sta->vif, false, false);
1221 int i;
1222 struct iwl_trans_txq_scd_cfg cfg = {
1223 .sta_id = mvm_sta->sta_id,
1224 .frame_limit = IWL_FRAME_LIMIT,
1225 };
1226
03c902bf
JB
1227 /* Make sure reserved queue is still marked as such (if allocated) */
1228 if (mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE)
1229 mvm->queue_info[mvm_sta->reserved_queue].status =
1230 IWL_MVM_QUEUE_RESERVED;
8d98ae6e
LK
1231
1232 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
1233 struct iwl_mvm_tid_data *tid_data = &mvm_sta->tid_data[i];
1234 int txq_id = tid_data->txq_id;
1235 int ac;
1236 u8 mac_queue;
1237
1238 if (txq_id == IEEE80211_INVAL_HW_QUEUE)
1239 continue;
1240
1241 skb_queue_head_init(&tid_data->deferred_tx_frames);
1242
1243 ac = tid_to_mac80211_ac[i];
1244 mac_queue = mvm_sta->vif->hw_queue[ac];
1245
1246 cfg.tid = i;
1247 cfg.fifo = iwl_mvm_ac_to_tx_fifo[ac];
1248 cfg.aggregate = (txq_id >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
1249 txq_id == IWL_MVM_DQA_BSS_CLIENT_QUEUE);
1250
1251 IWL_DEBUG_TX_QUEUES(mvm,
1252 "Re-mapping sta %d tid %d to queue %d\n",
1253 mvm_sta->sta_id, i, txq_id);
1254
1255 iwl_mvm_enable_txq(mvm, txq_id, mac_queue,
1256 IEEE80211_SEQ_TO_SN(tid_data->seq_number),
1257 &cfg, wdg_timeout);
1258
1259 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_READY;
1260 }
1261
1262 atomic_set(&mvm->pending_frames[mvm_sta->sta_id], 0);
1263}
1264
8ca151b5
JB
1265int iwl_mvm_add_sta(struct iwl_mvm *mvm,
1266 struct ieee80211_vif *vif,
1267 struct ieee80211_sta *sta)
1268{
1269 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
9d8ce6af 1270 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
a571f5f6 1271 struct iwl_mvm_rxq_dup_data *dup_data;
8ca151b5
JB
1272 int i, ret, sta_id;
1273
1274 lockdep_assert_held(&mvm->mutex);
1275
1276 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
b92e661b
EP
1277 sta_id = iwl_mvm_find_free_sta_id(mvm,
1278 ieee80211_vif_type_p2p(vif));
8ca151b5
JB
1279 else
1280 sta_id = mvm_sta->sta_id;
1281
0ae98812 1282 if (sta_id == IWL_MVM_INVALID_STA)
8ca151b5
JB
1283 return -ENOSPC;
1284
1285 spin_lock_init(&mvm_sta->lock);
1286
8d98ae6e
LK
1287 /* In DQA mode, if this is a HW restart, re-alloc existing queues */
1288 if (iwl_mvm_is_dqa_supported(mvm) &&
1289 test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1290 iwl_mvm_realloc_queues_after_restart(mvm, mvm_sta);
1291 goto update_fw;
1292 }
1293
8ca151b5
JB
1294 mvm_sta->sta_id = sta_id;
1295 mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id,
1296 mvmvif->color);
1297 mvm_sta->vif = vif;
1298 mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
9ee718aa
EL
1299 mvm_sta->tx_protection = 0;
1300 mvm_sta->tt_tx_protection = false;
8ca151b5
JB
1301
1302 /* HW restart, don't assume the memory has been zeroed */
e3d4bc8c 1303 atomic_set(&mvm->pending_frames[sta_id], 0);
69191afe 1304 mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */
8ca151b5 1305 mvm_sta->tfd_queue_msk = 0;
a0f6bf2a 1306
e3118ad7
LK
1307 /*
1308 * Allocate new queues for a TDLS station, unless we're in DQA mode,
1309 * and then they'll be allocated dynamically
1310 */
1311 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) {
a0f6bf2a
AN
1312 ret = iwl_mvm_tdls_sta_init(mvm, sta);
1313 if (ret)
1314 return ret;
24afba76 1315 } else if (!iwl_mvm_is_dqa_supported(mvm)) {
a0f6bf2a
AN
1316 for (i = 0; i < IEEE80211_NUM_ACS; i++)
1317 if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE)
1318 mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]);
1319 }
8ca151b5 1320
6d9d32b8 1321 /* for HW restart - reset everything but the sequence number */
24afba76 1322 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
6d9d32b8
JB
1323 u16 seq = mvm_sta->tid_data[i].seq_number;
1324 memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i]));
1325 mvm_sta->tid_data[i].seq_number = seq;
24afba76
LK
1326
1327 if (!iwl_mvm_is_dqa_supported(mvm))
1328 continue;
1329
1330 /*
1331 * Mark all queues for this STA as unallocated and defer TX
1332 * frames until the queue is allocated
1333 */
1334 mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE;
1335 skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames);
6d9d32b8 1336 }
24afba76 1337 mvm_sta->deferred_traffic_tid_map = 0;
efed6640 1338 mvm_sta->agg_tids = 0;
8ca151b5 1339
a571f5f6
SS
1340 if (iwl_mvm_has_new_rx_api(mvm) &&
1341 !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1342 dup_data = kcalloc(mvm->trans->num_rx_queues,
1343 sizeof(*dup_data),
1344 GFP_KERNEL);
1345 if (!dup_data)
1346 return -ENOMEM;
1347 mvm_sta->dup_data = dup_data;
1348 }
1349
24afba76 1350 if (iwl_mvm_is_dqa_supported(mvm)) {
d5216a28
LK
1351 ret = iwl_mvm_reserve_sta_stream(mvm, sta,
1352 ieee80211_vif_type_p2p(vif));
24afba76
LK
1353 if (ret)
1354 goto err;
1355 }
1356
8d98ae6e 1357update_fw:
24afba76 1358 ret = iwl_mvm_sta_send_to_fw(mvm, sta, false, 0);
8ca151b5 1359 if (ret)
a0f6bf2a 1360 goto err;
8ca151b5 1361
9e848010
JB
1362 if (vif->type == NL80211_IFTYPE_STATION) {
1363 if (!sta->tdls) {
0ae98812 1364 WARN_ON(mvmvif->ap_sta_id != IWL_MVM_INVALID_STA);
9e848010
JB
1365 mvmvif->ap_sta_id = sta_id;
1366 } else {
0ae98812 1367 WARN_ON(mvmvif->ap_sta_id == IWL_MVM_INVALID_STA);
9e848010
JB
1368 }
1369 }
8ca151b5
JB
1370
1371 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta);
1372
1373 return 0;
a0f6bf2a
AN
1374
1375err:
e3118ad7
LK
1376 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls)
1377 iwl_mvm_tdls_sta_deinit(mvm, sta);
a0f6bf2a 1378 return ret;
8ca151b5
JB
1379}
1380
1381int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
1382 bool drain)
1383{
f9dc0004 1384 struct iwl_mvm_add_sta_cmd cmd = {};
8ca151b5
JB
1385 int ret;
1386 u32 status;
1387
1388 lockdep_assert_held(&mvm->mutex);
1389
1390 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
1391 cmd.sta_id = mvmsta->sta_id;
1392 cmd.add_modify = STA_MODE_MODIFY;
1393 cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0;
1394 cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW);
1395
1396 status = ADD_STA_SUCCESS;
854c5705
SS
1397 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1398 iwl_mvm_add_sta_cmd_size(mvm),
f9dc0004 1399 &cmd, &status);
8ca151b5
JB
1400 if (ret)
1401 return ret;
1402
837c4da9 1403 switch (status & IWL_ADD_STA_STATUS_MASK) {
8ca151b5
JB
1404 case ADD_STA_SUCCESS:
1405 IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n",
1406 mvmsta->sta_id);
1407 break;
1408 default:
1409 ret = -EIO;
1410 IWL_ERR(mvm, "Couldn't drain frames for staid %d\n",
1411 mvmsta->sta_id);
1412 break;
1413 }
1414
1415 return ret;
1416}
1417
1418/*
1419 * Remove a station from the FW table. Before sending the command to remove
1420 * the station validate that the station is indeed known to the driver (sanity
1421 * only).
1422 */
1423static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id)
1424{
1425 struct ieee80211_sta *sta;
1426 struct iwl_mvm_rm_sta_cmd rm_sta_cmd = {
1427 .sta_id = sta_id,
1428 };
1429 int ret;
1430
1431 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1432 lockdep_is_held(&mvm->mutex));
1433
1434 /* Note: internal stations are marked as error values */
1435 if (!sta) {
1436 IWL_ERR(mvm, "Invalid station id\n");
1437 return -EINVAL;
1438 }
1439
a1022927 1440 ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0,
8ca151b5
JB
1441 sizeof(rm_sta_cmd), &rm_sta_cmd);
1442 if (ret) {
1443 IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id);
1444 return ret;
1445 }
1446
1447 return 0;
1448}
1449
1450void iwl_mvm_sta_drained_wk(struct work_struct *wk)
1451{
1452 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk);
1453 u8 sta_id;
1454
1455 /*
1456 * The mutex is needed because of the SYNC cmd, but not only: if the
1457 * work would run concurrently with iwl_mvm_rm_sta, it would run before
1458 * iwl_mvm_rm_sta sets the station as busy, and exit. Then
1459 * iwl_mvm_rm_sta would set the station as busy, and nobody will clean
1460 * that later.
1461 */
1462 mutex_lock(&mvm->mutex);
1463
1464 for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) {
1465 int ret;
1466 struct ieee80211_sta *sta =
1467 rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1468 lockdep_is_held(&mvm->mutex));
1469
1ddbbb0c
JB
1470 /*
1471 * This station is in use or RCU-removed; the latter happens in
1472 * managed mode, where mac80211 removes the station before we
1473 * can remove it from firmware (we can only do that after the
1474 * MAC is marked unassociated), and possibly while the deauth
1475 * frame to disconnect from the AP is still queued. Then, the
1476 * station pointer is -ENOENT when the last skb is reclaimed.
1477 */
1478 if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT)
8ca151b5
JB
1479 continue;
1480
1481 if (PTR_ERR(sta) == -EINVAL) {
1482 IWL_ERR(mvm, "Drained sta %d, but it is internal?\n",
1483 sta_id);
1484 continue;
1485 }
1486
1487 if (!sta) {
1488 IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n",
1489 sta_id);
1490 continue;
1491 }
1492
1493 WARN_ON(PTR_ERR(sta) != -EBUSY);
1494 /* This station was removed and we waited until it got drained,
1495 * we can now proceed and remove it.
1496 */
1497 ret = iwl_mvm_rm_sta_common(mvm, sta_id);
1498 if (ret) {
1499 IWL_ERR(mvm,
1500 "Couldn't remove sta %d after it was drained\n",
1501 sta_id);
1502 continue;
1503 }
c531c771 1504 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
8ca151b5 1505 clear_bit(sta_id, mvm->sta_drained);
a0f6bf2a
AN
1506
1507 if (mvm->tfd_drained[sta_id]) {
1508 unsigned long i, msk = mvm->tfd_drained[sta_id];
1509
a4ca3ed4 1510 for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE)
06ecdba3
AN
1511 iwl_mvm_disable_txq(mvm, i, i,
1512 IWL_MAX_TID_COUNT, 0);
a0f6bf2a
AN
1513
1514 mvm->tfd_drained[sta_id] = 0;
1515 IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n",
1516 sta_id, msk);
1517 }
8ca151b5
JB
1518 }
1519
1520 mutex_unlock(&mvm->mutex);
1521}
1522
24afba76
LK
1523static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm,
1524 struct ieee80211_vif *vif,
1525 struct iwl_mvm_sta *mvm_sta)
1526{
1527 int ac;
1528 int i;
1529
1530 lockdep_assert_held(&mvm->mutex);
1531
1532 for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) {
1533 if (mvm_sta->tid_data[i].txq_id == IEEE80211_INVAL_HW_QUEUE)
1534 continue;
1535
1536 ac = iwl_mvm_tid_to_ac_queue(i);
1537 iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id,
1538 vif->hw_queue[ac], i, 0);
1539 mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE;
1540 }
1541}
1542
8ca151b5
JB
1543int iwl_mvm_rm_sta(struct iwl_mvm *mvm,
1544 struct ieee80211_vif *vif,
1545 struct ieee80211_sta *sta)
1546{
1547 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
9d8ce6af 1548 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
94c3e614 1549 u8 sta_id = mvm_sta->sta_id;
8ca151b5
JB
1550 int ret;
1551
1552 lockdep_assert_held(&mvm->mutex);
1553
a571f5f6
SS
1554 if (iwl_mvm_has_new_rx_api(mvm))
1555 kfree(mvm_sta->dup_data);
1556
a6f035a0 1557 if ((vif->type == NL80211_IFTYPE_STATION &&
94c3e614 1558 mvmvif->ap_sta_id == sta_id) ||
a6f035a0 1559 iwl_mvm_is_dqa_supported(mvm)){
fe92e32a
EG
1560 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
1561 if (ret)
1562 return ret;
80d85655 1563 /* flush its queues here since we are freeing mvm_sta */
5888a40c 1564 ret = iwl_mvm_flush_tx_path(mvm, mvm_sta->tfd_queue_msk, 0);
fe92e32a
EG
1565 if (ret)
1566 return ret;
1567 ret = iwl_trans_wait_tx_queue_empty(mvm->trans,
1568 mvm_sta->tfd_queue_msk);
1569 if (ret)
1570 return ret;
1571 ret = iwl_mvm_drain_sta(mvm, mvm_sta, false);
80d85655 1572
24afba76 1573 /* If DQA is supported - the queues can be disabled now */
94c3e614 1574 if (iwl_mvm_is_dqa_supported(mvm)) {
56214749 1575 iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta);
94c3e614
SS
1576 /*
1577 * If pending_frames is set at this point - it must be
1578 * driver internal logic error, since queues are empty
1579 * and removed successuly.
1580 * warn on it but set it to 0 anyway to avoid station
1581 * not being removed later in the function
1582 */
1583 WARN_ON(atomic_xchg(&mvm->pending_frames[sta_id], 0));
1584 }
56214749
LK
1585
1586 /* If there is a TXQ still marked as reserved - free it */
1587 if (iwl_mvm_is_dqa_supported(mvm) &&
1588 mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) {
a0315dea
LK
1589 u8 reserved_txq = mvm_sta->reserved_queue;
1590 enum iwl_mvm_queue_status *status;
1591
a0315dea
LK
1592 /*
1593 * If no traffic has gone through the reserved TXQ - it
1594 * is still marked as IWL_MVM_QUEUE_RESERVED, and
1595 * should be manually marked as free again
1596 */
1597 spin_lock_bh(&mvm->queue_info_lock);
1598 status = &mvm->queue_info[reserved_txq].status;
1599 if (WARN((*status != IWL_MVM_QUEUE_RESERVED) &&
1600 (*status != IWL_MVM_QUEUE_FREE),
1601 "sta_id %d reserved txq %d status %d",
94c3e614 1602 sta_id, reserved_txq, *status)) {
a0315dea
LK
1603 spin_unlock_bh(&mvm->queue_info_lock);
1604 return -EINVAL;
1605 }
1606
1607 *status = IWL_MVM_QUEUE_FREE;
1608 spin_unlock_bh(&mvm->queue_info_lock);
1609 }
1610
e3118ad7 1611 if (vif->type == NL80211_IFTYPE_STATION &&
94c3e614 1612 mvmvif->ap_sta_id == sta_id) {
e3118ad7
LK
1613 /* if associated - we can't remove the AP STA now */
1614 if (vif->bss_conf.assoc)
1615 return ret;
8ca151b5 1616
e3118ad7 1617 /* unassoc - go ahead - remove the AP STA now */
0ae98812 1618 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
37577fe2 1619
e3118ad7 1620 /* clear d0i3_ap_sta_id if no longer relevant */
94c3e614 1621 if (mvm->d0i3_ap_sta_id == sta_id)
0ae98812 1622 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
e3118ad7 1623 }
8ca151b5
JB
1624 }
1625
1d3c3f63
AN
1626 /*
1627 * This shouldn't happen - the TDLS channel switch should be canceled
1628 * before the STA is removed.
1629 */
94c3e614 1630 if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == sta_id)) {
0ae98812 1631 mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA;
1d3c3f63
AN
1632 cancel_delayed_work(&mvm->tdls_cs.dwork);
1633 }
1634
e3d4bc8c
EG
1635 /*
1636 * Make sure that the tx response code sees the station as -EBUSY and
1637 * calls the drain worker.
1638 */
1639 spin_lock_bh(&mvm_sta->lock);
94c3e614 1640
8ca151b5
JB
1641 /*
1642 * There are frames pending on the AC queues for this station.
1643 * We need to wait until all the frames are drained...
1644 */
94c3e614
SS
1645 if (atomic_read(&mvm->pending_frames[sta_id])) {
1646 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id],
8ca151b5 1647 ERR_PTR(-EBUSY));
e3d4bc8c 1648 spin_unlock_bh(&mvm_sta->lock);
a0f6bf2a
AN
1649
1650 /* disable TDLS sta queues on drain complete */
1651 if (sta->tdls) {
94c3e614
SS
1652 mvm->tfd_drained[sta_id] = mvm_sta->tfd_queue_msk;
1653 IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n", sta_id);
a0f6bf2a
AN
1654 }
1655
e3d4bc8c 1656 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
8ca151b5 1657 } else {
e3d4bc8c 1658 spin_unlock_bh(&mvm_sta->lock);
a0f6bf2a 1659
e3118ad7 1660 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls)
a0f6bf2a
AN
1661 iwl_mvm_tdls_sta_deinit(mvm, sta);
1662
8ca151b5 1663 ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id);
c531c771 1664 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL);
8ca151b5
JB
1665 }
1666
1667 return ret;
1668}
1669
1670int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm,
1671 struct ieee80211_vif *vif,
1672 u8 sta_id)
1673{
1674 int ret = iwl_mvm_rm_sta_common(mvm, sta_id);
1675
1676 lockdep_assert_held(&mvm->mutex);
1677
c531c771 1678 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
8ca151b5
JB
1679 return ret;
1680}
1681
0e39eb03
CRI
1682int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm,
1683 struct iwl_mvm_int_sta *sta,
1684 u32 qmask, enum nl80211_iftype iftype)
8ca151b5
JB
1685{
1686 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
b92e661b 1687 sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype);
0ae98812 1688 if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_INVALID_STA))
8ca151b5
JB
1689 return -ENOSPC;
1690 }
1691
1692 sta->tfd_queue_msk = qmask;
1693
1694 /* put a non-NULL value so iterating over the stations won't stop */
1695 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL));
1696 return 0;
1697}
1698
26d6c16b 1699void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm, struct iwl_mvm_int_sta *sta)
8ca151b5 1700{
c531c771 1701 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta->sta_id], NULL);
8ca151b5 1702 memset(sta, 0, sizeof(struct iwl_mvm_int_sta));
0ae98812 1703 sta->sta_id = IWL_MVM_INVALID_STA;
8ca151b5
JB
1704}
1705
1706static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm,
1707 struct iwl_mvm_int_sta *sta,
1708 const u8 *addr,
1709 u16 mac_id, u16 color)
1710{
f9dc0004 1711 struct iwl_mvm_add_sta_cmd cmd;
8ca151b5
JB
1712 int ret;
1713 u32 status;
1714
1715 lockdep_assert_held(&mvm->mutex);
1716
f9dc0004 1717 memset(&cmd, 0, sizeof(cmd));
8ca151b5
JB
1718 cmd.sta_id = sta->sta_id;
1719 cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id,
1720 color));
1721
bb49701b
SS
1722 if (!iwl_mvm_has_new_tx_api(mvm))
1723 cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk);
cf0cda19 1724 cmd.tid_disable_tx = cpu_to_le16(0xffff);
8ca151b5
JB
1725
1726 if (addr)
1727 memcpy(cmd.addr, addr, ETH_ALEN);
1728
854c5705
SS
1729 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1730 iwl_mvm_add_sta_cmd_size(mvm),
f9dc0004 1731 &cmd, &status);
8ca151b5
JB
1732 if (ret)
1733 return ret;
1734
837c4da9 1735 switch (status & IWL_ADD_STA_STATUS_MASK) {
8ca151b5
JB
1736 case ADD_STA_SUCCESS:
1737 IWL_DEBUG_INFO(mvm, "Internal station added.\n");
1738 return 0;
1739 default:
1740 ret = -EIO;
1741 IWL_ERR(mvm, "Add internal station failed, status=0x%x\n",
1742 status);
1743 break;
1744 }
1745 return ret;
1746}
1747
c5a719ee 1748static void iwl_mvm_enable_aux_queue(struct iwl_mvm *mvm)
8ca151b5 1749{
4cf677fd
EG
1750 unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ?
1751 mvm->cfg->base_params->wd_timeout :
1752 IWL_WATCHDOG_DISABLED;
8ca151b5 1753
28d0793e
LK
1754 if (iwl_mvm_is_dqa_supported(mvm)) {
1755 struct iwl_trans_txq_scd_cfg cfg = {
1756 .fifo = IWL_MVM_TX_FIFO_MCAST,
1757 .sta_id = mvm->aux_sta.sta_id,
1758 .tid = IWL_MAX_TID_COUNT,
1759 .aggregate = false,
1760 .frame_limit = IWL_FRAME_LIMIT,
1761 };
1762
1763 iwl_mvm_enable_txq(mvm, mvm->aux_queue, mvm->aux_queue, 0, &cfg,
1764 wdg_timeout);
c5a719ee
SS
1765 } else {
1766 iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue,
1767 IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout);
28d0793e 1768 }
c5a719ee 1769}
28d0793e 1770
c5a719ee
SS
1771int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm)
1772{
1773 int ret;
1774
1775 lockdep_assert_held(&mvm->mutex);
8ca151b5 1776
c5a719ee
SS
1777 /* Allocate aux station and assign to it the aux queue */
1778 ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue),
1779 NL80211_IFTYPE_UNSPECIFIED);
8ca151b5 1780 if (ret)
c5a719ee
SS
1781 return ret;
1782
1783 /* Map Aux queue to fifo - needs to happen before adding Aux station */
1784 if (!iwl_mvm_has_new_tx_api(mvm))
1785 iwl_mvm_enable_aux_queue(mvm);
1786
1787 ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL,
1788 MAC_INDEX_AUX, 0);
1789 if (ret) {
8ca151b5 1790 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
c5a719ee
SS
1791 return ret;
1792 }
1793
1794 /*
1795 * For a000 firmware and on we cannot add queue to a station unknown
1796 * to firmware so enable queue here - after the station was added
1797 */
1798 if (iwl_mvm_has_new_tx_api(mvm))
1799 iwl_mvm_enable_aux_queue(mvm);
1800
1801 return 0;
8ca151b5
JB
1802}
1803
0e39eb03
CRI
1804int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1805{
1806 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1807
1808 lockdep_assert_held(&mvm->mutex);
1809 return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr,
1810 mvmvif->id, 0);
1811}
1812
1813int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1814{
1815 int ret;
1816
1817 lockdep_assert_held(&mvm->mutex);
1818
1819 ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id);
1820 if (ret)
1821 IWL_WARN(mvm, "Failed sending remove station\n");
1822
1823 return ret;
1824}
1825
1826void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm)
1827{
1828 iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta);
1829}
1830
712b24ad
JB
1831void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm)
1832{
1833 lockdep_assert_held(&mvm->mutex);
1834
1835 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
1836}
1837
8ca151b5
JB
1838/*
1839 * Send the add station command for the vif's broadcast station.
1840 * Assumes that the station was already allocated.
1841 *
1842 * @mvm: the mvm component
1843 * @vif: the interface to which the broadcast station is added
1844 * @bsta: the broadcast station to add.
1845 */
013290aa 1846int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
8ca151b5
JB
1847{
1848 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
013290aa 1849 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
5023d966 1850 static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
a4243402 1851 const u8 *baddr = _baddr;
c5a719ee 1852 int queue = 0;
df88c08d 1853 int ret;
c5a719ee
SS
1854 unsigned int wdg_timeout =
1855 iwl_mvm_get_wd_timeout(mvm, vif, false, false);
1856 struct iwl_trans_txq_scd_cfg cfg = {
1857 .fifo = IWL_MVM_TX_FIFO_VO,
1858 .sta_id = mvmvif->bcast_sta.sta_id,
1859 .tid = IWL_MAX_TID_COUNT,
1860 .aggregate = false,
1861 .frame_limit = IWL_FRAME_LIMIT,
1862 };
8ca151b5
JB
1863
1864 lockdep_assert_held(&mvm->mutex);
1865
de24f638 1866 if (iwl_mvm_is_dqa_supported(mvm)) {
4d339989
LK
1867 if (vif->type == NL80211_IFTYPE_AP ||
1868 vif->type == NL80211_IFTYPE_ADHOC)
49f71713 1869 queue = mvm->probe_queue;
df88c08d 1870 else if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
49f71713 1871 queue = mvm->p2p_dev_queue;
df88c08d 1872 else if (WARN(1, "Missing required TXQ for adding bcast STA\n"))
de24f638
LK
1873 return -EINVAL;
1874
df88c08d 1875 bsta->tfd_queue_msk |= BIT(queue);
c5a719ee
SS
1876
1877 if (!iwl_mvm_has_new_tx_api(mvm))
1878 iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[0], 0,
1879 &cfg, wdg_timeout);
de24f638
LK
1880 }
1881
5023d966
JB
1882 if (vif->type == NL80211_IFTYPE_ADHOC)
1883 baddr = vif->bss_conf.bssid;
1884
0ae98812 1885 if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_INVALID_STA))
8ca151b5
JB
1886 return -ENOSPC;
1887
df88c08d
LK
1888 ret = iwl_mvm_add_int_sta_common(mvm, bsta, baddr,
1889 mvmvif->id, mvmvif->color);
1890 if (ret)
1891 return ret;
1892
1893 /*
c5a719ee
SS
1894 * For a000 firmware and on we cannot add queue to a station unknown
1895 * to firmware so enable queue here - after the station was added
df88c08d 1896 */
c5a719ee
SS
1897 if (iwl_mvm_has_new_tx_api(mvm))
1898 iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[0], 0, &cfg,
1899 wdg_timeout);
df88c08d
LK
1900
1901 return 0;
1902}
1903
1904static void iwl_mvm_free_bcast_sta_queues(struct iwl_mvm *mvm,
1905 struct ieee80211_vif *vif)
1906{
1907 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1908
1909 lockdep_assert_held(&mvm->mutex);
1910
4d339989
LK
1911 if (vif->type == NL80211_IFTYPE_AP ||
1912 vif->type == NL80211_IFTYPE_ADHOC)
df88c08d
LK
1913 iwl_mvm_disable_txq(mvm, vif->cab_queue, vif->cab_queue,
1914 IWL_MAX_TID_COUNT, 0);
1915
49f71713
SS
1916 if (mvmvif->bcast_sta.tfd_queue_msk & BIT(mvm->probe_queue)) {
1917 iwl_mvm_disable_txq(mvm, mvm->probe_queue,
df88c08d
LK
1918 vif->hw_queue[0], IWL_MAX_TID_COUNT,
1919 0);
49f71713 1920 mvmvif->bcast_sta.tfd_queue_msk &= ~BIT(mvm->probe_queue);
df88c08d
LK
1921 }
1922
49f71713
SS
1923 if (mvmvif->bcast_sta.tfd_queue_msk & BIT(mvm->p2p_dev_queue)) {
1924 iwl_mvm_disable_txq(mvm, mvm->p2p_dev_queue,
df88c08d
LK
1925 vif->hw_queue[0], IWL_MAX_TID_COUNT,
1926 0);
49f71713 1927 mvmvif->bcast_sta.tfd_queue_msk &= ~BIT(mvm->p2p_dev_queue);
df88c08d 1928 }
8ca151b5
JB
1929}
1930
1931/* Send the FW a request to remove the station from it's internal data
1932 * structures, but DO NOT remove the entry from the local data structures. */
013290aa 1933int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
8ca151b5 1934{
013290aa 1935 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8ca151b5
JB
1936 int ret;
1937
1938 lockdep_assert_held(&mvm->mutex);
1939
df88c08d
LK
1940 if (iwl_mvm_is_dqa_supported(mvm))
1941 iwl_mvm_free_bcast_sta_queues(mvm, vif);
1942
013290aa 1943 ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id);
8ca151b5
JB
1944 if (ret)
1945 IWL_WARN(mvm, "Failed sending remove station\n");
1946 return ret;
1947}
1948
013290aa
JB
1949int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1950{
1951 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
de24f638 1952 u32 qmask = 0;
013290aa
JB
1953
1954 lockdep_assert_held(&mvm->mutex);
1955
df88c08d 1956 if (!iwl_mvm_is_dqa_supported(mvm)) {
de24f638 1957 qmask = iwl_mvm_mac_get_queues_mask(vif);
013290aa 1958
de24f638
LK
1959 /*
1960 * The firmware defines the TFD queue mask to only be relevant
1961 * for *unicast* queues, so the multicast (CAB) queue shouldn't
df88c08d
LK
1962 * be included. This only happens in NL80211_IFTYPE_AP vif type,
1963 * so the next line will only have an effect there.
de24f638 1964 */
013290aa 1965 qmask &= ~BIT(vif->cab_queue);
de24f638
LK
1966 }
1967
013290aa
JB
1968 return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask,
1969 ieee80211_vif_type_p2p(vif));
1970}
1971
8ca151b5
JB
1972/* Allocate a new station entry for the broadcast station to the given vif,
1973 * and send it to the FW.
1974 * Note that each P2P mac should have its own broadcast station.
1975 *
1976 * @mvm: the mvm component
1977 * @vif: the interface to which the broadcast station is added
1978 * @bsta: the broadcast station to add. */
013290aa 1979int iwl_mvm_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
8ca151b5
JB
1980{
1981 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
013290aa 1982 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
8ca151b5
JB
1983 int ret;
1984
1985 lockdep_assert_held(&mvm->mutex);
1986
013290aa 1987 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
8ca151b5
JB
1988 if (ret)
1989 return ret;
1990
013290aa 1991 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
8ca151b5
JB
1992
1993 if (ret)
1994 iwl_mvm_dealloc_int_sta(mvm, bsta);
013290aa 1995
8ca151b5
JB
1996 return ret;
1997}
1998
013290aa
JB
1999void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2000{
2001 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2002
2003 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
2004}
2005
8ca151b5
JB
2006/*
2007 * Send the FW a request to remove the station from it's internal data
2008 * structures, and in addition remove it from the local data structure.
2009 */
013290aa 2010int iwl_mvm_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
8ca151b5
JB
2011{
2012 int ret;
2013
2014 lockdep_assert_held(&mvm->mutex);
2015
013290aa
JB
2016 ret = iwl_mvm_send_rm_bcast_sta(mvm, vif);
2017
2018 iwl_mvm_dealloc_bcast_sta(mvm, vif);
8ca151b5 2019
8ca151b5
JB
2020 return ret;
2021}
2022
26d6c16b
SS
2023/*
2024 * Allocate a new station entry for the multicast station to the given vif,
2025 * and send it to the FW.
2026 * Note that each AP/GO mac should have its own multicast station.
2027 *
2028 * @mvm: the mvm component
2029 * @vif: the interface to which the multicast station is added
2030 */
2031int iwl_mvm_add_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2032{
2033 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2034 struct iwl_mvm_int_sta *msta = &mvmvif->mcast_sta;
2035 static const u8 _maddr[] = {0x03, 0x00, 0x00, 0x00, 0x00, 0x00};
2036 const u8 *maddr = _maddr;
2037 struct iwl_trans_txq_scd_cfg cfg = {
2038 .fifo = IWL_MVM_TX_FIFO_MCAST,
2039 .sta_id = msta->sta_id,
2040 .tid = IWL_MAX_TID_COUNT,
2041 .aggregate = false,
2042 .frame_limit = IWL_FRAME_LIMIT,
2043 };
2044 unsigned int timeout = iwl_mvm_get_wd_timeout(mvm, vif, false, false);
2045 int ret;
2046
2047 lockdep_assert_held(&mvm->mutex);
2048
2049 if (!iwl_mvm_is_dqa_supported(mvm))
2050 return 0;
2051
2052 if (WARN_ON(vif->type != NL80211_IFTYPE_AP))
2053 return -ENOTSUPP;
2054
2055 ret = iwl_mvm_add_int_sta_common(mvm, msta, maddr,
2056 mvmvif->id, mvmvif->color);
2057 if (ret) {
2058 iwl_mvm_dealloc_int_sta(mvm, msta);
2059 return ret;
2060 }
2061
2062 /*
2063 * Enable cab queue after the ADD_STA command is sent.
2064 * This is needed for a000 firmware which won't accept SCD_QUEUE_CFG
2065 * command with unknown station id.
2066 */
2067 iwl_mvm_enable_txq(mvm, vif->cab_queue, vif->cab_queue, 0, &cfg,
2068 timeout);
2069
2070 return 0;
2071}
2072
2073/*
2074 * Send the FW a request to remove the station from it's internal data
2075 * structures, and in addition remove it from the local data structure.
2076 */
2077int iwl_mvm_rm_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2078{
2079 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2080 int ret;
2081
2082 lockdep_assert_held(&mvm->mutex);
2083
2084 if (!iwl_mvm_is_dqa_supported(mvm))
2085 return 0;
2086
2087 iwl_mvm_disable_txq(mvm, vif->cab_queue, vif->cab_queue,
2088 IWL_MAX_TID_COUNT, 0);
2089
2090 ret = iwl_mvm_rm_sta_common(mvm, mvmvif->mcast_sta.sta_id);
2091 if (ret)
2092 IWL_WARN(mvm, "Failed sending remove station\n");
2093
2094 return ret;
2095}
2096
113a0447
EG
2097#define IWL_MAX_RX_BA_SESSIONS 16
2098
b915c101 2099static void iwl_mvm_sync_rxq_del_ba(struct iwl_mvm *mvm, u8 baid)
10b2b201 2100{
b915c101
SS
2101 struct iwl_mvm_delba_notif notif = {
2102 .metadata.type = IWL_MVM_RXQ_NOTIF_DEL_BA,
2103 .metadata.sync = 1,
2104 .delba.baid = baid,
10b2b201 2105 };
b915c101
SS
2106 iwl_mvm_sync_rx_queues_internal(mvm, (void *)&notif, sizeof(notif));
2107};
10b2b201 2108
b915c101
SS
2109static void iwl_mvm_free_reorder(struct iwl_mvm *mvm,
2110 struct iwl_mvm_baid_data *data)
2111{
2112 int i;
2113
2114 iwl_mvm_sync_rxq_del_ba(mvm, data->baid);
2115
2116 for (i = 0; i < mvm->trans->num_rx_queues; i++) {
2117 int j;
2118 struct iwl_mvm_reorder_buffer *reorder_buf =
2119 &data->reorder_buf[i];
2120
0690405f
SS
2121 spin_lock_bh(&reorder_buf->lock);
2122 if (likely(!reorder_buf->num_stored)) {
2123 spin_unlock_bh(&reorder_buf->lock);
b915c101 2124 continue;
0690405f 2125 }
b915c101
SS
2126
2127 /*
2128 * This shouldn't happen in regular DELBA since the internal
2129 * delBA notification should trigger a release of all frames in
2130 * the reorder buffer.
2131 */
2132 WARN_ON(1);
2133
2134 for (j = 0; j < reorder_buf->buf_size; j++)
2135 __skb_queue_purge(&reorder_buf->entries[j]);
0690405f
SS
2136 /*
2137 * Prevent timer re-arm. This prevents a very far fetched case
2138 * where we timed out on the notification. There may be prior
2139 * RX frames pending in the RX queue before the notification
2140 * that might get processed between now and the actual deletion
2141 * and we would re-arm the timer although we are deleting the
2142 * reorder buffer.
2143 */
2144 reorder_buf->removed = true;
2145 spin_unlock_bh(&reorder_buf->lock);
2146 del_timer_sync(&reorder_buf->reorder_timer);
b915c101
SS
2147 }
2148}
2149
2150static void iwl_mvm_init_reorder_buffer(struct iwl_mvm *mvm,
2151 u32 sta_id,
2152 struct iwl_mvm_baid_data *data,
2153 u16 ssn, u8 buf_size)
2154{
2155 int i;
2156
2157 for (i = 0; i < mvm->trans->num_rx_queues; i++) {
2158 struct iwl_mvm_reorder_buffer *reorder_buf =
2159 &data->reorder_buf[i];
2160 int j;
2161
2162 reorder_buf->num_stored = 0;
2163 reorder_buf->head_sn = ssn;
2164 reorder_buf->buf_size = buf_size;
0690405f
SS
2165 /* rx reorder timer */
2166 reorder_buf->reorder_timer.function =
2167 iwl_mvm_reorder_timer_expired;
2168 reorder_buf->reorder_timer.data = (unsigned long)reorder_buf;
2169 init_timer(&reorder_buf->reorder_timer);
2170 spin_lock_init(&reorder_buf->lock);
2171 reorder_buf->mvm = mvm;
b915c101
SS
2172 reorder_buf->queue = i;
2173 reorder_buf->sta_id = sta_id;
2174 for (j = 0; j < reorder_buf->buf_size; j++)
2175 __skb_queue_head_init(&reorder_buf->entries[j]);
2176 }
10b2b201
SS
2177}
2178
8ca151b5 2179int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
10b2b201 2180 int tid, u16 ssn, bool start, u8 buf_size, u16 timeout)
8ca151b5 2181{
9d8ce6af 2182 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
f9dc0004 2183 struct iwl_mvm_add_sta_cmd cmd = {};
10b2b201 2184 struct iwl_mvm_baid_data *baid_data = NULL;
8ca151b5
JB
2185 int ret;
2186 u32 status;
2187
2188 lockdep_assert_held(&mvm->mutex);
2189
113a0447
EG
2190 if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) {
2191 IWL_WARN(mvm, "Not enough RX BA SESSIONS\n");
2192 return -ENOSPC;
2193 }
2194
10b2b201
SS
2195 if (iwl_mvm_has_new_rx_api(mvm) && start) {
2196 /*
2197 * Allocate here so if allocation fails we can bail out early
2198 * before starting the BA session in the firmware
2199 */
b915c101
SS
2200 baid_data = kzalloc(sizeof(*baid_data) +
2201 mvm->trans->num_rx_queues *
2202 sizeof(baid_data->reorder_buf[0]),
2203 GFP_KERNEL);
10b2b201
SS
2204 if (!baid_data)
2205 return -ENOMEM;
2206 }
2207
8ca151b5
JB
2208 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
2209 cmd.sta_id = mvm_sta->sta_id;
2210 cmd.add_modify = STA_MODE_MODIFY;
93a42667
EG
2211 if (start) {
2212 cmd.add_immediate_ba_tid = (u8) tid;
2213 cmd.add_immediate_ba_ssn = cpu_to_le16(ssn);
854c5705 2214 cmd.rx_ba_window = cpu_to_le16((u16)buf_size);
93a42667
EG
2215 } else {
2216 cmd.remove_immediate_ba_tid = (u8) tid;
2217 }
8ca151b5
JB
2218 cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID :
2219 STA_MODIFY_REMOVE_BA_TID;
2220
2221 status = ADD_STA_SUCCESS;
854c5705
SS
2222 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
2223 iwl_mvm_add_sta_cmd_size(mvm),
f9dc0004 2224 &cmd, &status);
8ca151b5 2225 if (ret)
10b2b201 2226 goto out_free;
8ca151b5 2227
837c4da9 2228 switch (status & IWL_ADD_STA_STATUS_MASK) {
8ca151b5 2229 case ADD_STA_SUCCESS:
35263a03
SS
2230 IWL_DEBUG_HT(mvm, "RX BA Session %sed in fw\n",
2231 start ? "start" : "stopp");
8ca151b5
JB
2232 break;
2233 case ADD_STA_IMMEDIATE_BA_FAILURE:
2234 IWL_WARN(mvm, "RX BA Session refused by fw\n");
2235 ret = -ENOSPC;
2236 break;
2237 default:
2238 ret = -EIO;
2239 IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n",
2240 start ? "start" : "stopp", status);
2241 break;
2242 }
2243
10b2b201
SS
2244 if (ret)
2245 goto out_free;
2246
2247 if (start) {
2248 u8 baid;
2249
2250 mvm->rx_ba_sessions++;
2251
2252 if (!iwl_mvm_has_new_rx_api(mvm))
2253 return 0;
2254
2255 if (WARN_ON(!(status & IWL_ADD_STA_BAID_VALID_MASK))) {
2256 ret = -EINVAL;
2257 goto out_free;
2258 }
2259 baid = (u8)((status & IWL_ADD_STA_BAID_MASK) >>
2260 IWL_ADD_STA_BAID_SHIFT);
2261 baid_data->baid = baid;
2262 baid_data->timeout = timeout;
2263 baid_data->last_rx = jiffies;
72c240fe
WY
2264 setup_timer(&baid_data->session_timer,
2265 iwl_mvm_rx_agg_session_expired,
2266 (unsigned long)&mvm->baid_map[baid]);
10b2b201
SS
2267 baid_data->mvm = mvm;
2268 baid_data->tid = tid;
2269 baid_data->sta_id = mvm_sta->sta_id;
2270
2271 mvm_sta->tid_to_baid[tid] = baid;
2272 if (timeout)
2273 mod_timer(&baid_data->session_timer,
2274 TU_TO_EXP_TIME(timeout * 2));
2275
b915c101
SS
2276 iwl_mvm_init_reorder_buffer(mvm, mvm_sta->sta_id,
2277 baid_data, ssn, buf_size);
10b2b201
SS
2278 /*
2279 * protect the BA data with RCU to cover a case where our
2280 * internal RX sync mechanism will timeout (not that it's
2281 * supposed to happen) and we will free the session data while
2282 * RX is being processed in parallel
2283 */
35263a03
SS
2284 IWL_DEBUG_HT(mvm, "Sta %d(%d) is assigned to BAID %d\n",
2285 mvm_sta->sta_id, tid, baid);
10b2b201
SS
2286 WARN_ON(rcu_access_pointer(mvm->baid_map[baid]));
2287 rcu_assign_pointer(mvm->baid_map[baid], baid_data);
60dec523 2288 } else {
10b2b201
SS
2289 u8 baid = mvm_sta->tid_to_baid[tid];
2290
60dec523
SS
2291 if (mvm->rx_ba_sessions > 0)
2292 /* check that restart flow didn't zero the counter */
2293 mvm->rx_ba_sessions--;
10b2b201
SS
2294 if (!iwl_mvm_has_new_rx_api(mvm))
2295 return 0;
2296
2297 if (WARN_ON(baid == IWL_RX_REORDER_DATA_INVALID_BAID))
2298 return -EINVAL;
2299
2300 baid_data = rcu_access_pointer(mvm->baid_map[baid]);
2301 if (WARN_ON(!baid_data))
2302 return -EINVAL;
2303
2304 /* synchronize all rx queues so we can safely delete */
b915c101 2305 iwl_mvm_free_reorder(mvm, baid_data);
10b2b201 2306 del_timer_sync(&baid_data->session_timer);
10b2b201
SS
2307 RCU_INIT_POINTER(mvm->baid_map[baid], NULL);
2308 kfree_rcu(baid_data, rcu_head);
35263a03 2309 IWL_DEBUG_HT(mvm, "BAID %d is free\n", baid);
113a0447 2310 }
10b2b201 2311 return 0;
113a0447 2312
10b2b201
SS
2313out_free:
2314 kfree(baid_data);
8ca151b5
JB
2315 return ret;
2316}
2317
9794c64f
LK
2318int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
2319 int tid, u8 queue, bool start)
8ca151b5 2320{
9d8ce6af 2321 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
f9dc0004 2322 struct iwl_mvm_add_sta_cmd cmd = {};
8ca151b5
JB
2323 int ret;
2324 u32 status;
2325
2326 lockdep_assert_held(&mvm->mutex);
2327
2328 if (start) {
2329 mvm_sta->tfd_queue_msk |= BIT(queue);
2330 mvm_sta->tid_disable_agg &= ~BIT(tid);
2331 } else {
cf961e16
LK
2332 /* In DQA-mode the queue isn't removed on agg termination */
2333 if (!iwl_mvm_is_dqa_supported(mvm))
2334 mvm_sta->tfd_queue_msk &= ~BIT(queue);
8ca151b5
JB
2335 mvm_sta->tid_disable_agg |= BIT(tid);
2336 }
2337
2338 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
2339 cmd.sta_id = mvm_sta->sta_id;
2340 cmd.add_modify = STA_MODE_MODIFY;
bb49701b
SS
2341 if (!iwl_mvm_has_new_tx_api(mvm))
2342 cmd.modify_mask = STA_MODIFY_QUEUES;
2343 cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX;
8ca151b5
JB
2344 cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk);
2345 cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg);
2346
2347 status = ADD_STA_SUCCESS;
854c5705
SS
2348 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
2349 iwl_mvm_add_sta_cmd_size(mvm),
f9dc0004 2350 &cmd, &status);
8ca151b5
JB
2351 if (ret)
2352 return ret;
2353
837c4da9 2354 switch (status & IWL_ADD_STA_STATUS_MASK) {
8ca151b5
JB
2355 case ADD_STA_SUCCESS:
2356 break;
2357 default:
2358 ret = -EIO;
2359 IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n",
2360 start ? "start" : "stopp", status);
2361 break;
2362 }
2363
2364 return ret;
2365}
2366
b797e3fb 2367const u8 tid_to_mac80211_ac[] = {
8ca151b5
JB
2368 IEEE80211_AC_BE,
2369 IEEE80211_AC_BK,
2370 IEEE80211_AC_BK,
2371 IEEE80211_AC_BE,
2372 IEEE80211_AC_VI,
2373 IEEE80211_AC_VI,
2374 IEEE80211_AC_VO,
2375 IEEE80211_AC_VO,
9794c64f 2376 IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */
8ca151b5
JB
2377};
2378
3e56eadf
JB
2379static const u8 tid_to_ucode_ac[] = {
2380 AC_BE,
2381 AC_BK,
2382 AC_BK,
2383 AC_BE,
2384 AC_VI,
2385 AC_VI,
2386 AC_VO,
2387 AC_VO,
2388};
2389
8ca151b5
JB
2390int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2391 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
2392{
5b577a90 2393 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
8ca151b5
JB
2394 struct iwl_mvm_tid_data *tid_data;
2395 int txq_id;
4ecafae9 2396 int ret;
8ca151b5
JB
2397
2398 if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
2399 return -EINVAL;
2400
2401 if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) {
2402 IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n",
2403 mvmsta->tid_data[tid].state);
2404 return -ENXIO;
2405 }
2406
2407 lockdep_assert_held(&mvm->mutex);
2408
b2492501
AN
2409 spin_lock_bh(&mvmsta->lock);
2410
2411 /* possible race condition - we entered D0i3 while starting agg */
2412 if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) {
2413 spin_unlock_bh(&mvmsta->lock);
2414 IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n");
2415 return -EIO;
2416 }
2417
9f9af3d7 2418 spin_lock(&mvm->queue_info_lock);
4ecafae9 2419
cf961e16
LK
2420 /*
2421 * Note the possible cases:
2422 * 1. In DQA mode with an enabled TXQ - TXQ needs to become agg'ed
2423 * 2. Non-DQA mode: the TXQ hasn't yet been enabled, so find a free
2424 * one and mark it as reserved
2425 * 3. In DQA mode, but no traffic yet on this TID: same treatment as in
2426 * non-DQA mode, since the TXQ hasn't yet been allocated
2427 */
2428 txq_id = mvmsta->tid_data[tid].txq_id;
9f9af3d7
LK
2429 if (iwl_mvm_is_dqa_supported(mvm) &&
2430 unlikely(mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_SHARED)) {
2431 ret = -ENXIO;
2432 IWL_DEBUG_TX_QUEUES(mvm,
2433 "Can't start tid %d agg on shared queue!\n",
2434 tid);
2435 goto release_locks;
2436 } else if (!iwl_mvm_is_dqa_supported(mvm) ||
cf961e16 2437 mvm->queue_info[txq_id].status != IWL_MVM_QUEUE_READY) {
9794c64f
LK
2438 txq_id = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
2439 mvm->first_agg_queue,
cf961e16
LK
2440 mvm->last_agg_queue);
2441 if (txq_id < 0) {
2442 ret = txq_id;
cf961e16
LK
2443 IWL_ERR(mvm, "Failed to allocate agg queue\n");
2444 goto release_locks;
2445 }
01796ff2
SS
2446 /*
2447 * TXQ shouldn't be in inactive mode for non-DQA, so getting
2448 * an inactive queue from iwl_mvm_find_free_queue() is
2449 * certainly a bug
2450 */
2451 WARN_ON(mvm->queue_info[txq_id].status ==
2452 IWL_MVM_QUEUE_INACTIVE);
cf961e16
LK
2453
2454 /* TXQ hasn't yet been enabled, so mark it only as reserved */
2455 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_RESERVED;
4ecafae9 2456 }
9f9af3d7
LK
2457
2458 spin_unlock(&mvm->queue_info_lock);
8ca151b5 2459
cf961e16
LK
2460 IWL_DEBUG_TX_QUEUES(mvm,
2461 "AGG for tid %d will be on queue #%d\n",
2462 tid, txq_id);
2463
8ca151b5 2464 tid_data = &mvmsta->tid_data[tid];
9a886586 2465 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
8ca151b5
JB
2466 tid_data->txq_id = txq_id;
2467 *ssn = tid_data->ssn;
2468
2469 IWL_DEBUG_TX_QUEUES(mvm,
2470 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
2471 mvmsta->sta_id, tid, txq_id, tid_data->ssn,
2472 tid_data->next_reclaimed);
2473
2474 if (tid_data->ssn == tid_data->next_reclaimed) {
2475 tid_data->state = IWL_AGG_STARTING;
2476 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2477 } else {
2478 tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA;
2479 }
2480
4ecafae9 2481 ret = 0;
9f9af3d7 2482 goto out;
4ecafae9
LK
2483
2484release_locks:
9f9af3d7
LK
2485 spin_unlock(&mvm->queue_info_lock);
2486out:
8ca151b5
JB
2487 spin_unlock_bh(&mvmsta->lock);
2488
4ecafae9 2489 return ret;
8ca151b5
JB
2490}
2491
2492int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
bb81bb68
EG
2493 struct ieee80211_sta *sta, u16 tid, u8 buf_size,
2494 bool amsdu)
8ca151b5 2495{
5b577a90 2496 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
8ca151b5 2497 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
5d42e7b2
EG
2498 unsigned int wdg_timeout =
2499 iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false);
eea76c36 2500 int queue, ret;
cf961e16 2501 bool alloc_queue = true;
9f9af3d7 2502 enum iwl_mvm_queue_status queue_status;
8ca151b5
JB
2503 u16 ssn;
2504
eea76c36
EG
2505 struct iwl_trans_txq_scd_cfg cfg = {
2506 .sta_id = mvmsta->sta_id,
2507 .tid = tid,
2508 .frame_limit = buf_size,
2509 .aggregate = true,
2510 };
2511
efed6640
ES
2512 BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE)
2513 != IWL_MAX_TID_COUNT);
2514
8ca151b5
JB
2515 buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
2516
2517 spin_lock_bh(&mvmsta->lock);
2518 ssn = tid_data->ssn;
2519 queue = tid_data->txq_id;
2520 tid_data->state = IWL_AGG_ON;
efed6640 2521 mvmsta->agg_tids |= BIT(tid);
8ca151b5 2522 tid_data->ssn = 0xffff;
bb81bb68 2523 tid_data->amsdu_in_ampdu_allowed = amsdu;
8ca151b5
JB
2524 spin_unlock_bh(&mvmsta->lock);
2525
eea76c36 2526 cfg.fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
8ca151b5 2527
9f9af3d7
LK
2528 spin_lock_bh(&mvm->queue_info_lock);
2529 queue_status = mvm->queue_info[queue].status;
2530 spin_unlock_bh(&mvm->queue_info_lock);
2531
cf961e16
LK
2532 /* In DQA mode, the existing queue might need to be reconfigured */
2533 if (iwl_mvm_is_dqa_supported(mvm)) {
cf961e16
LK
2534 /* Maybe there is no need to even alloc a queue... */
2535 if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_READY)
2536 alloc_queue = false;
cf961e16
LK
2537
2538 /*
2539 * Only reconfig the SCD for the queue if the window size has
2540 * changed from current (become smaller)
2541 */
2542 if (!alloc_queue && buf_size < mvmsta->max_agg_bufsize) {
bb49701b
SS
2543 /*
2544 * On new TX API rs and BA manager are offloaded.
2545 * For now though, just don't support being reconfigured
2546 */
2547 if (iwl_mvm_has_new_tx_api(mvm))
2548 return -ENOTSUPP;
2549
cf961e16
LK
2550 /*
2551 * If reconfiguring an existing queue, it first must be
2552 * drained
2553 */
2554 ret = iwl_trans_wait_tx_queue_empty(mvm->trans,
2555 BIT(queue));
2556 if (ret) {
2557 IWL_ERR(mvm,
2558 "Error draining queue before reconfig\n");
2559 return ret;
2560 }
2561
2562 ret = iwl_mvm_reconfig_scd(mvm, queue, cfg.fifo,
2563 mvmsta->sta_id, tid,
2564 buf_size, ssn);
2565 if (ret) {
2566 IWL_ERR(mvm,
2567 "Error reconfiguring TXQ #%d\n", queue);
2568 return ret;
2569 }
2570 }
2571 }
2572
2573 if (alloc_queue)
2574 iwl_mvm_enable_txq(mvm, queue,
2575 vif->hw_queue[tid_to_mac80211_ac[tid]], ssn,
2576 &cfg, wdg_timeout);
fa7878e7 2577
9f9af3d7
LK
2578 /* Send ADD_STA command to enable aggs only if the queue isn't shared */
2579 if (queue_status != IWL_MVM_QUEUE_SHARED) {
2580 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
2581 if (ret)
2582 return -EIO;
2583 }
8ca151b5 2584
4ecafae9
LK
2585 /* No need to mark as reserved */
2586 spin_lock_bh(&mvm->queue_info_lock);
cf961e16 2587 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
4ecafae9
LK
2588 spin_unlock_bh(&mvm->queue_info_lock);
2589
8ca151b5
JB
2590 /*
2591 * Even though in theory the peer could have different
2592 * aggregation reorder buffer sizes for different sessions,
2593 * our ucode doesn't allow for that and has a global limit
2594 * for each station. Therefore, use the minimum of all the
2595 * aggregation sessions and our default value.
2596 */
2597 mvmsta->max_agg_bufsize =
2598 min(mvmsta->max_agg_bufsize, buf_size);
2599 mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize;
2600
9ee718aa
EL
2601 IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n",
2602 sta->addr, tid);
2603
9e680946 2604 return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false);
8ca151b5
JB
2605}
2606
2607int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2608 struct ieee80211_sta *sta, u16 tid)
2609{
5b577a90 2610 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
8ca151b5
JB
2611 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2612 u16 txq_id;
2613 int err;
2614
f9aa8dd3
EG
2615 /*
2616 * If mac80211 is cleaning its state, then say that we finished since
2617 * our state has been cleared anyway.
2618 */
2619 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2620 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2621 return 0;
2622 }
2623
8ca151b5
JB
2624 spin_lock_bh(&mvmsta->lock);
2625
2626 txq_id = tid_data->txq_id;
2627
2628 IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n",
2629 mvmsta->sta_id, tid, txq_id, tid_data->state);
2630
efed6640
ES
2631 mvmsta->agg_tids &= ~BIT(tid);
2632
4ecafae9 2633 spin_lock_bh(&mvm->queue_info_lock);
cf961e16
LK
2634 /*
2635 * The TXQ is marked as reserved only if no traffic came through yet
2636 * This means no traffic has been sent on this TID (agg'd or not), so
2637 * we no longer have use for the queue. Since it hasn't even been
2638 * allocated through iwl_mvm_enable_txq, so we can just mark it back as
2639 * free.
2640 */
2641 if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED)
2642 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE;
9f9af3d7 2643
4ecafae9
LK
2644 spin_unlock_bh(&mvm->queue_info_lock);
2645
8ca151b5
JB
2646 switch (tid_data->state) {
2647 case IWL_AGG_ON:
9a886586 2648 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
8ca151b5
JB
2649
2650 IWL_DEBUG_TX_QUEUES(mvm,
2651 "ssn = %d, next_recl = %d\n",
2652 tid_data->ssn, tid_data->next_reclaimed);
2653
2654 /* There are still packets for this RA / TID in the HW */
2655 if (tid_data->ssn != tid_data->next_reclaimed) {
2656 tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA;
2657 err = 0;
2658 break;
2659 }
2660
2661 tid_data->ssn = 0xffff;
f7f89e7b 2662 tid_data->state = IWL_AGG_OFF;
f7f89e7b
JB
2663 spin_unlock_bh(&mvmsta->lock);
2664
2665 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2666
2667 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
2668
cf961e16
LK
2669 if (!iwl_mvm_is_dqa_supported(mvm)) {
2670 int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]];
2671
2672 iwl_mvm_disable_txq(mvm, txq_id, mac_queue, tid, 0);
2673 }
f7f89e7b 2674 return 0;
8ca151b5
JB
2675 case IWL_AGG_STARTING:
2676 case IWL_EMPTYING_HW_QUEUE_ADDBA:
2677 /*
2678 * The agg session has been stopped before it was set up. This
2679 * can happen when the AddBA timer times out for example.
2680 */
2681
2682 /* No barriers since we are under mutex */
2683 lockdep_assert_held(&mvm->mutex);
8ca151b5
JB
2684
2685 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2686 tid_data->state = IWL_AGG_OFF;
2687 err = 0;
2688 break;
2689 default:
2690 IWL_ERR(mvm,
2691 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
2692 mvmsta->sta_id, tid, tid_data->state);
2693 IWL_ERR(mvm,
2694 "\ttid_data->txq_id = %d\n", tid_data->txq_id);
2695 err = -EINVAL;
2696 }
2697
2698 spin_unlock_bh(&mvmsta->lock);
2699
2700 return err;
2701}
2702
e3d9e7ce
EG
2703int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2704 struct ieee80211_sta *sta, u16 tid)
2705{
5b577a90 2706 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
e3d9e7ce
EG
2707 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2708 u16 txq_id;
b6658ff8 2709 enum iwl_mvm_agg_state old_state;
e3d9e7ce
EG
2710
2711 /*
2712 * First set the agg state to OFF to avoid calling
2713 * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
2714 */
2715 spin_lock_bh(&mvmsta->lock);
2716 txq_id = tid_data->txq_id;
2717 IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n",
2718 mvmsta->sta_id, tid, txq_id, tid_data->state);
b6658ff8 2719 old_state = tid_data->state;
e3d9e7ce 2720 tid_data->state = IWL_AGG_OFF;
efed6640 2721 mvmsta->agg_tids &= ~BIT(tid);
e3d9e7ce
EG
2722 spin_unlock_bh(&mvmsta->lock);
2723
4ecafae9 2724 spin_lock_bh(&mvm->queue_info_lock);
cf961e16
LK
2725 /*
2726 * The TXQ is marked as reserved only if no traffic came through yet
2727 * This means no traffic has been sent on this TID (agg'd or not), so
2728 * we no longer have use for the queue. Since it hasn't even been
2729 * allocated through iwl_mvm_enable_txq, so we can just mark it back as
2730 * free.
2731 */
2732 if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED)
2733 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE;
4ecafae9
LK
2734 spin_unlock_bh(&mvm->queue_info_lock);
2735
b6658ff8 2736 if (old_state >= IWL_AGG_ON) {
fe92e32a 2737 iwl_mvm_drain_sta(mvm, mvmsta, true);
5888a40c 2738 if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0))
b6658ff8 2739 IWL_ERR(mvm, "Couldn't flush the AGG queue\n");
fe92e32a
EG
2740 iwl_trans_wait_tx_queue_empty(mvm->trans,
2741 mvmsta->tfd_queue_msk);
2742 iwl_mvm_drain_sta(mvm, mvmsta, false);
b6658ff8 2743
f7f89e7b
JB
2744 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
2745
cf961e16
LK
2746 if (!iwl_mvm_is_dqa_supported(mvm)) {
2747 int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]];
2748
2749 iwl_mvm_disable_txq(mvm, tid_data->txq_id, mac_queue,
2750 tid, 0);
2751 }
b6658ff8 2752 }
e3d9e7ce 2753
e3d9e7ce
EG
2754 return 0;
2755}
2756
8ca151b5
JB
2757static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm)
2758{
2dc2a15e 2759 int i, max = -1, max_offs = -1;
8ca151b5
JB
2760
2761 lockdep_assert_held(&mvm->mutex);
2762
2dc2a15e
JB
2763 /* Pick the unused key offset with the highest 'deleted'
2764 * counter. Every time a key is deleted, all the counters
2765 * are incremented and the one that was just deleted is
2766 * reset to zero. Thus, the highest counter is the one
2767 * that was deleted longest ago. Pick that one.
2768 */
2769 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
2770 if (test_bit(i, mvm->fw_key_table))
2771 continue;
2772 if (mvm->fw_key_deleted[i] > max) {
2773 max = mvm->fw_key_deleted[i];
2774 max_offs = i;
2775 }
2776 }
8ca151b5 2777
2dc2a15e 2778 if (max_offs < 0)
8ca151b5
JB
2779 return STA_KEY_IDX_INVALID;
2780
2dc2a15e 2781 return max_offs;
8ca151b5
JB
2782}
2783
5f7a1847
JB
2784static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm,
2785 struct ieee80211_vif *vif,
2786 struct ieee80211_sta *sta)
8ca151b5 2787{
5b530e95 2788 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8ca151b5 2789
5f7a1847
JB
2790 if (sta)
2791 return iwl_mvm_sta_from_mac80211(sta);
8ca151b5
JB
2792
2793 /*
2794 * The device expects GTKs for station interfaces to be
2795 * installed as GTKs for the AP station. If we have no
2796 * station ID, then use AP's station ID.
2797 */
2798 if (vif->type == NL80211_IFTYPE_STATION &&
0ae98812 2799 mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
9513c5e1
AA
2800 u8 sta_id = mvmvif->ap_sta_id;
2801
7d6a1ab6
EG
2802 sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id],
2803 lockdep_is_held(&mvm->mutex));
2804
9513c5e1
AA
2805 /*
2806 * It is possible that the 'sta' parameter is NULL,
2807 * for example when a GTK is removed - the sta_id will then
2808 * be the AP ID, and no station was passed by mac80211.
2809 */
7d6a1ab6
EG
2810 if (IS_ERR_OR_NULL(sta))
2811 return NULL;
2812
2813 return iwl_mvm_sta_from_mac80211(sta);
9513c5e1 2814 }
8ca151b5 2815
5f7a1847 2816 return NULL;
8ca151b5
JB
2817}
2818
2819static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm,
2820 struct iwl_mvm_sta *mvm_sta,
45c458b4 2821 struct ieee80211_key_conf *key, bool mcast,
d6ee54a9
LC
2822 u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags,
2823 u8 key_offset)
8ca151b5 2824{
45c458b4
SS
2825 union {
2826 struct iwl_mvm_add_sta_key_cmd_v1 cmd_v1;
2827 struct iwl_mvm_add_sta_key_cmd cmd;
2828 } u = {};
f9dc0004 2829 __le16 key_flags;
79920749
JB
2830 int ret;
2831 u32 status;
8ca151b5 2832 u16 keyidx;
45c458b4
SS
2833 u64 pn = 0;
2834 int i, size;
2835 bool new_api = fw_has_api(&mvm->fw->ucode_capa,
2836 IWL_UCODE_TLV_API_TKIP_MIC_KEYS);
8ca151b5 2837
45c458b4 2838 keyidx = (key->keyidx << STA_KEY_FLG_KEYID_POS) &
8ca151b5
JB
2839 STA_KEY_FLG_KEYID_MSK;
2840 key_flags = cpu_to_le16(keyidx);
2841 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP);
2842
45c458b4 2843 switch (key->cipher) {
8ca151b5
JB
2844 case WLAN_CIPHER_SUITE_TKIP:
2845 key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP);
45c458b4
SS
2846 if (new_api) {
2847 memcpy((void *)&u.cmd.tx_mic_key,
2848 &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
2849 IWL_MIC_KEY_SIZE);
2850
2851 memcpy((void *)&u.cmd.rx_mic_key,
2852 &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
2853 IWL_MIC_KEY_SIZE);
2854 pn = atomic64_read(&key->tx_pn);
2855
2856 } else {
2857 u.cmd_v1.tkip_rx_tsc_byte2 = tkip_iv32;
2858 for (i = 0; i < 5; i++)
2859 u.cmd_v1.tkip_rx_ttak[i] =
2860 cpu_to_le16(tkip_p1k[i]);
2861 }
2862 memcpy(u.cmd.common.key, key->key, key->keylen);
8ca151b5
JB
2863 break;
2864 case WLAN_CIPHER_SUITE_CCMP:
2865 key_flags |= cpu_to_le16(STA_KEY_FLG_CCM);
45c458b4
SS
2866 memcpy(u.cmd.common.key, key->key, key->keylen);
2867 if (new_api)
2868 pn = atomic64_read(&key->tx_pn);
8ca151b5 2869 break;
ba3943b0
JB
2870 case WLAN_CIPHER_SUITE_WEP104:
2871 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES);
aa0cb08b 2872 /* fall through */
ba3943b0
JB
2873 case WLAN_CIPHER_SUITE_WEP40:
2874 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP);
45c458b4 2875 memcpy(u.cmd.common.key + 3, key->key, key->keylen);
ba3943b0 2876 break;
2a53d166
AB
2877 case WLAN_CIPHER_SUITE_GCMP_256:
2878 key_flags |= cpu_to_le16(STA_KEY_FLG_KEY_32BYTES);
2879 /* fall through */
2880 case WLAN_CIPHER_SUITE_GCMP:
2881 key_flags |= cpu_to_le16(STA_KEY_FLG_GCMP);
45c458b4
SS
2882 memcpy(u.cmd.common.key, key->key, key->keylen);
2883 if (new_api)
2884 pn = atomic64_read(&key->tx_pn);
2a53d166 2885 break;
8ca151b5 2886 default:
e36e5433 2887 key_flags |= cpu_to_le16(STA_KEY_FLG_EXT);
45c458b4 2888 memcpy(u.cmd.common.key, key->key, key->keylen);
8ca151b5
JB
2889 }
2890
ba3943b0 2891 if (mcast)
8ca151b5
JB
2892 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
2893
45c458b4
SS
2894 u.cmd.common.key_offset = key_offset;
2895 u.cmd.common.key_flags = key_flags;
2896 u.cmd.common.sta_id = mvm_sta->sta_id;
2897
2898 if (new_api) {
2899 u.cmd.transmit_seq_cnt = cpu_to_le64(pn);
2900 size = sizeof(u.cmd);
2901 } else {
2902 size = sizeof(u.cmd_v1);
2903 }
8ca151b5
JB
2904
2905 status = ADD_STA_SUCCESS;
a1022927 2906 if (cmd_flags & CMD_ASYNC)
45c458b4
SS
2907 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC, size,
2908 &u.cmd);
a1022927 2909 else
45c458b4
SS
2910 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, size,
2911 &u.cmd, &status);
8ca151b5
JB
2912
2913 switch (status) {
2914 case ADD_STA_SUCCESS:
2915 IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n");
2916 break;
2917 default:
2918 ret = -EIO;
2919 IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n");
2920 break;
2921 }
2922
2923 return ret;
2924}
2925
2926static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm,
2927 struct ieee80211_key_conf *keyconf,
2928 u8 sta_id, bool remove_key)
2929{
2930 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {};
2931
2932 /* verify the key details match the required command's expectations */
8e160ab8
AB
2933 if (WARN_ON((keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) ||
2934 (keyconf->keyidx != 4 && keyconf->keyidx != 5) ||
2935 (keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC &&
2936 keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_128 &&
2937 keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_256)))
2938 return -EINVAL;
2939
2940 if (WARN_ON(!iwl_mvm_has_new_rx_api(mvm) &&
2941 keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC))
8ca151b5
JB
2942 return -EINVAL;
2943
2944 igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx);
2945 igtk_cmd.sta_id = cpu_to_le32(sta_id);
2946
2947 if (remove_key) {
2948 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID);
2949 } else {
2950 struct ieee80211_key_seq seq;
2951 const u8 *pn;
2952
aa950524
AB
2953 switch (keyconf->cipher) {
2954 case WLAN_CIPHER_SUITE_AES_CMAC:
2955 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_CCM);
2956 break;
8e160ab8
AB
2957 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2958 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2959 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_GCMP);
2960 break;
aa950524
AB
2961 default:
2962 return -EINVAL;
2963 }
2964
8e160ab8
AB
2965 memcpy(igtk_cmd.igtk, keyconf->key, keyconf->keylen);
2966 if (keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
2967 igtk_cmd.ctrl_flags |=
2968 cpu_to_le32(STA_KEY_FLG_KEY_32BYTES);
8ca151b5
JB
2969 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
2970 pn = seq.aes_cmac.pn;
2971 igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) |
2972 ((u64) pn[4] << 8) |
2973 ((u64) pn[3] << 16) |
2974 ((u64) pn[2] << 24) |
2975 ((u64) pn[1] << 32) |
2976 ((u64) pn[0] << 40));
2977 }
2978
2979 IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n",
2980 remove_key ? "removing" : "installing",
2981 igtk_cmd.sta_id);
2982
8e160ab8
AB
2983 if (!iwl_mvm_has_new_rx_api(mvm)) {
2984 struct iwl_mvm_mgmt_mcast_key_cmd_v1 igtk_cmd_v1 = {
2985 .ctrl_flags = igtk_cmd.ctrl_flags,
2986 .key_id = igtk_cmd.key_id,
2987 .sta_id = igtk_cmd.sta_id,
2988 .receive_seq_cnt = igtk_cmd.receive_seq_cnt
2989 };
2990
2991 memcpy(igtk_cmd_v1.igtk, igtk_cmd.igtk,
2992 ARRAY_SIZE(igtk_cmd_v1.igtk));
2993 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
2994 sizeof(igtk_cmd_v1), &igtk_cmd_v1);
2995 }
a1022927 2996 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
8ca151b5
JB
2997 sizeof(igtk_cmd), &igtk_cmd);
2998}
2999
3000
3001static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm,
3002 struct ieee80211_vif *vif,
3003 struct ieee80211_sta *sta)
3004{
5b530e95 3005 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
8ca151b5
JB
3006
3007 if (sta)
3008 return sta->addr;
3009
3010 if (vif->type == NL80211_IFTYPE_STATION &&
0ae98812 3011 mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
8ca151b5
JB
3012 u8 sta_id = mvmvif->ap_sta_id;
3013 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
3014 lockdep_is_held(&mvm->mutex));
3015 return sta->addr;
3016 }
3017
3018
3019 return NULL;
3020}
3021
2f6319d1
JB
3022static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
3023 struct ieee80211_vif *vif,
3024 struct ieee80211_sta *sta,
ba3943b0 3025 struct ieee80211_key_conf *keyconf,
d6ee54a9 3026 u8 key_offset,
ba3943b0 3027 bool mcast)
2f6319d1
JB
3028{
3029 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3030 int ret;
3031 const u8 *addr;
3032 struct ieee80211_key_seq seq;
3033 u16 p1k[5];
3034
3035 switch (keyconf->cipher) {
3036 case WLAN_CIPHER_SUITE_TKIP:
3037 addr = iwl_mvm_get_mac_addr(mvm, vif, sta);
3038 /* get phase 1 key from mac80211 */
3039 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
3040 ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k);
ba3943b0 3041 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
d6ee54a9 3042 seq.tkip.iv32, p1k, 0, key_offset);
2f6319d1
JB
3043 break;
3044 case WLAN_CIPHER_SUITE_CCMP:
ba3943b0
JB
3045 case WLAN_CIPHER_SUITE_WEP40:
3046 case WLAN_CIPHER_SUITE_WEP104:
2a53d166
AB
3047 case WLAN_CIPHER_SUITE_GCMP:
3048 case WLAN_CIPHER_SUITE_GCMP_256:
ba3943b0 3049 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
d6ee54a9 3050 0, NULL, 0, key_offset);
2f6319d1
JB
3051 break;
3052 default:
ba3943b0 3053 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
d6ee54a9 3054 0, NULL, 0, key_offset);
2f6319d1
JB
3055 }
3056
3057 return ret;
3058}
3059
3060static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id,
ba3943b0
JB
3061 struct ieee80211_key_conf *keyconf,
3062 bool mcast)
2f6319d1 3063{
45c458b4
SS
3064 union {
3065 struct iwl_mvm_add_sta_key_cmd_v1 cmd_v1;
3066 struct iwl_mvm_add_sta_key_cmd cmd;
3067 } u = {};
3068 bool new_api = fw_has_api(&mvm->fw->ucode_capa,
3069 IWL_UCODE_TLV_API_TKIP_MIC_KEYS);
2f6319d1 3070 __le16 key_flags;
45c458b4 3071 int ret, size;
2f6319d1
JB
3072 u32 status;
3073
3074 key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
3075 STA_KEY_FLG_KEYID_MSK);
3076 key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP);
3077 key_flags |= cpu_to_le16(STA_KEY_NOT_VALID);
3078
ba3943b0 3079 if (mcast)
2f6319d1
JB
3080 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
3081
45c458b4
SS
3082 /*
3083 * The fields assigned here are in the same location at the start
3084 * of the command, so we can do this union trick.
3085 */
3086 u.cmd.common.key_flags = key_flags;
3087 u.cmd.common.key_offset = keyconf->hw_key_idx;
3088 u.cmd.common.sta_id = sta_id;
3089
3090 size = new_api ? sizeof(u.cmd) : sizeof(u.cmd_v1);
2f6319d1
JB
3091
3092 status = ADD_STA_SUCCESS;
45c458b4
SS
3093 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, size, &u.cmd,
3094 &status);
2f6319d1
JB
3095
3096 switch (status) {
3097 case ADD_STA_SUCCESS:
3098 IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n");
3099 break;
3100 default:
3101 ret = -EIO;
3102 IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n");
3103 break;
3104 }
3105
3106 return ret;
3107}
3108
8ca151b5
JB
3109int iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
3110 struct ieee80211_vif *vif,
3111 struct ieee80211_sta *sta,
3112 struct ieee80211_key_conf *keyconf,
d6ee54a9 3113 u8 key_offset)
8ca151b5 3114{
ba3943b0 3115 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
5f7a1847 3116 struct iwl_mvm_sta *mvm_sta;
2f6319d1 3117 u8 sta_id;
8ca151b5 3118 int ret;
11828dbc 3119 static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0};
8ca151b5
JB
3120
3121 lockdep_assert_held(&mvm->mutex);
3122
3123 /* Get the station id from the mvm local station table */
5f7a1847
JB
3124 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
3125 if (!mvm_sta) {
3126 IWL_ERR(mvm, "Failed to find station\n");
8ca151b5
JB
3127 return -EINVAL;
3128 }
5f7a1847 3129 sta_id = mvm_sta->sta_id;
8ca151b5 3130
8e160ab8
AB
3131 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3132 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3133 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) {
8ca151b5
JB
3134 ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false);
3135 goto end;
3136 }
3137
3138 /*
3139 * It is possible that the 'sta' parameter is NULL, and thus
3140 * there is a need to retrieve the sta from the local station table.
3141 */
3142 if (!sta) {
3143 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
3144 lockdep_is_held(&mvm->mutex));
3145 if (IS_ERR_OR_NULL(sta)) {
3146 IWL_ERR(mvm, "Invalid station id\n");
3147 return -EINVAL;
3148 }
3149 }
3150
2f6319d1 3151 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif))
8ca151b5
JB
3152 return -EINVAL;
3153
d6ee54a9
LC
3154 /* If the key_offset is not pre-assigned, we need to find a
3155 * new offset to use. In normal cases, the offset is not
3156 * pre-assigned, but during HW_RESTART we want to reuse the
3157 * same indices, so we pass them when this function is called.
3158 *
3159 * In D3 entry, we need to hardcoded the indices (because the
3160 * firmware hardcodes the PTK offset to 0). In this case, we
3161 * need to make sure we don't overwrite the hw_key_idx in the
3162 * keyconf structure, because otherwise we cannot configure
3163 * the original ones back when resuming.
3164 */
3165 if (key_offset == STA_KEY_IDX_INVALID) {
3166 key_offset = iwl_mvm_set_fw_key_idx(mvm);
3167 if (key_offset == STA_KEY_IDX_INVALID)
8ca151b5 3168 return -ENOSPC;
d6ee54a9 3169 keyconf->hw_key_idx = key_offset;
8ca151b5
JB
3170 }
3171
d6ee54a9 3172 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, key_offset, mcast);
9c3deeb5 3173 if (ret)
ba3943b0 3174 goto end;
ba3943b0
JB
3175
3176 /*
3177 * For WEP, the same key is used for multicast and unicast. Upload it
3178 * again, using the same key offset, and now pointing the other one
3179 * to the same key slot (offset).
3180 * If this fails, remove the original as well.
3181 */
3182 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3183 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) {
d6ee54a9
LC
3184 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf,
3185 key_offset, !mcast);
ba3943b0 3186 if (ret) {
ba3943b0 3187 __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
9c3deeb5 3188 goto end;
ba3943b0
JB
3189 }
3190 }
8ca151b5 3191
9c3deeb5
LC
3192 __set_bit(key_offset, mvm->fw_key_table);
3193
8ca151b5
JB
3194end:
3195 IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
3196 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
11828dbc 3197 sta ? sta->addr : zero_addr, ret);
8ca151b5
JB
3198 return ret;
3199}
3200
3201int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm,
3202 struct ieee80211_vif *vif,
3203 struct ieee80211_sta *sta,
3204 struct ieee80211_key_conf *keyconf)
3205{
ba3943b0 3206 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
5f7a1847 3207 struct iwl_mvm_sta *mvm_sta;
0ae98812 3208 u8 sta_id = IWL_MVM_INVALID_STA;
2dc2a15e 3209 int ret, i;
8ca151b5
JB
3210
3211 lockdep_assert_held(&mvm->mutex);
3212
5f7a1847
JB
3213 /* Get the station from the mvm local station table */
3214 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
cd4d23c1
IP
3215 if (!mvm_sta) {
3216 IWL_ERR(mvm, "Failed to find station\n");
3217 return -EINVAL;
3218 }
3219 sta_id = mvm_sta->sta_id;
8ca151b5
JB
3220
3221 IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n",
3222 keyconf->keyidx, sta_id);
3223
8e160ab8
AB
3224 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3225 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3226 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
8ca151b5
JB
3227 return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true);
3228
2f6319d1 3229 if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) {
8ca151b5
JB
3230 IWL_ERR(mvm, "offset %d not used in fw key table.\n",
3231 keyconf->hw_key_idx);
3232 return -ENOENT;
3233 }
3234
2dc2a15e
JB
3235 /* track which key was deleted last */
3236 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
3237 if (mvm->fw_key_deleted[i] < U8_MAX)
3238 mvm->fw_key_deleted[i]++;
3239 }
3240 mvm->fw_key_deleted[keyconf->hw_key_idx] = 0;
3241
5f7a1847 3242 if (!mvm_sta) {
8ca151b5
JB
3243 IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n");
3244 return 0;
3245 }
3246
ba3943b0
JB
3247 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
3248 if (ret)
3249 return ret;
3250
3251 /* delete WEP key twice to get rid of (now useless) offset */
3252 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3253 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104)
3254 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast);
3255
3256 return ret;
8ca151b5
JB
3257}
3258
3259void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm,
3260 struct ieee80211_vif *vif,
3261 struct ieee80211_key_conf *keyconf,
3262 struct ieee80211_sta *sta, u32 iv32,
3263 u16 *phase1key)
3264{
c3eb536a 3265 struct iwl_mvm_sta *mvm_sta;
ba3943b0 3266 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
8ca151b5 3267
c3eb536a
BL
3268 rcu_read_lock();
3269
5f7a1847
JB
3270 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
3271 if (WARN_ON_ONCE(!mvm_sta))
45854360 3272 goto unlock;
ba3943b0 3273 iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
d6ee54a9 3274 iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx);
45854360
JB
3275
3276 unlock:
c3eb536a 3277 rcu_read_unlock();
8ca151b5
JB
3278}
3279
9cc40712
JB
3280void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm,
3281 struct ieee80211_sta *sta)
8ca151b5 3282{
5b577a90 3283 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
f9dc0004 3284 struct iwl_mvm_add_sta_cmd cmd = {
8ca151b5 3285 .add_modify = STA_MODE_MODIFY,
9cc40712 3286 .sta_id = mvmsta->sta_id,
5af01772 3287 .station_flags_msk = cpu_to_le32(STA_FLG_PS),
9cc40712 3288 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
8ca151b5
JB
3289 };
3290 int ret;
3291
854c5705
SS
3292 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
3293 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
8ca151b5
JB
3294 if (ret)
3295 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3296}
3297
9cc40712
JB
3298void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm,
3299 struct ieee80211_sta *sta,
8ca151b5 3300 enum ieee80211_frame_release_type reason,
3e56eadf 3301 u16 cnt, u16 tids, bool more_data,
9a3fcf91 3302 bool single_sta_queue)
8ca151b5 3303{
5b577a90 3304 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
f9dc0004 3305 struct iwl_mvm_add_sta_cmd cmd = {
8ca151b5 3306 .add_modify = STA_MODE_MODIFY,
9cc40712 3307 .sta_id = mvmsta->sta_id,
8ca151b5
JB
3308 .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT,
3309 .sleep_tx_count = cpu_to_le16(cnt),
9cc40712 3310 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
8ca151b5 3311 };
3e56eadf
JB
3312 int tid, ret;
3313 unsigned long _tids = tids;
3314
3315 /* convert TIDs to ACs - we don't support TSPEC so that's OK
3316 * Note that this field is reserved and unused by firmware not
3317 * supporting GO uAPSD, so it's safe to always do this.
3318 */
3319 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT)
3320 cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]);
3321
9a3fcf91
SS
3322 /* If we're releasing frames from aggregation or dqa queues then check
3323 * if all the queues that we're releasing frames from, combined, have:
3e56eadf
JB
3324 * - more frames than the service period, in which case more_data
3325 * needs to be set
3326 * - fewer than 'cnt' frames, in which case we need to adjust the
3327 * firmware command (but do that unconditionally)
3328 */
9a3fcf91 3329 if (single_sta_queue) {
3e56eadf 3330 int remaining = cnt;
36be0eb6 3331 int sleep_tx_count;
3e56eadf
JB
3332
3333 spin_lock_bh(&mvmsta->lock);
3334 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) {
3335 struct iwl_mvm_tid_data *tid_data;
3336 u16 n_queued;
3337
3338 tid_data = &mvmsta->tid_data[tid];
9a3fcf91
SS
3339 if (WARN(!iwl_mvm_is_dqa_supported(mvm) &&
3340 tid_data->state != IWL_AGG_ON &&
3e56eadf
JB
3341 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA,
3342 "TID %d state is %d\n",
3343 tid, tid_data->state)) {
3344 spin_unlock_bh(&mvmsta->lock);
3345 ieee80211_sta_eosp(sta);
3346 return;
3347 }
3348
3349 n_queued = iwl_mvm_tid_queued(tid_data);
3350 if (n_queued > remaining) {
3351 more_data = true;
3352 remaining = 0;
3353 break;
3354 }
3355 remaining -= n_queued;
3356 }
36be0eb6
EG
3357 sleep_tx_count = cnt - remaining;
3358 if (reason == IEEE80211_FRAME_RELEASE_UAPSD)
3359 mvmsta->sleep_tx_count = sleep_tx_count;
3e56eadf
JB
3360 spin_unlock_bh(&mvmsta->lock);
3361
36be0eb6 3362 cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count);
3e56eadf
JB
3363 if (WARN_ON(cnt - remaining == 0)) {
3364 ieee80211_sta_eosp(sta);
3365 return;
3366 }
3367 }
3368
3369 /* Note: this is ignored by firmware not supporting GO uAPSD */
3370 if (more_data)
3371 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA);
3372
3373 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) {
3374 mvmsta->next_status_eosp = true;
3375 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL);
3376 } else {
3377 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD);
3378 }
8ca151b5 3379
156f92f2
EG
3380 /* block the Tx queues until the FW updated the sleep Tx count */
3381 iwl_trans_block_txq_ptrs(mvm->trans, true);
3382
3383 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA,
3384 CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK,
854c5705 3385 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
8ca151b5
JB
3386 if (ret)
3387 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3388}
3e56eadf 3389
0416841d
JB
3390void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm,
3391 struct iwl_rx_cmd_buffer *rxb)
3e56eadf
JB
3392{
3393 struct iwl_rx_packet *pkt = rxb_addr(rxb);
3394 struct iwl_mvm_eosp_notification *notif = (void *)pkt->data;
3395 struct ieee80211_sta *sta;
3396 u32 sta_id = le32_to_cpu(notif->sta_id);
3397
3398 if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT))
0416841d 3399 return;
3e56eadf
JB
3400
3401 rcu_read_lock();
3402 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
3403 if (!IS_ERR_OR_NULL(sta))
3404 ieee80211_sta_eosp(sta);
3405 rcu_read_unlock();
3e56eadf 3406}
09b0ce1a
AO
3407
3408void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm,
3409 struct iwl_mvm_sta *mvmsta, bool disable)
3410{
3411 struct iwl_mvm_add_sta_cmd cmd = {
3412 .add_modify = STA_MODE_MODIFY,
3413 .sta_id = mvmsta->sta_id,
3414 .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0,
3415 .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX),
3416 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
3417 };
3418 int ret;
3419
854c5705
SS
3420 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
3421 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
09b0ce1a
AO
3422 if (ret)
3423 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3424}
003e5236
AO
3425
3426void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm,
3427 struct ieee80211_sta *sta,
3428 bool disable)
3429{
3430 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3431
3432 spin_lock_bh(&mvm_sta->lock);
3433
3434 if (mvm_sta->disable_tx == disable) {
3435 spin_unlock_bh(&mvm_sta->lock);
3436 return;
3437 }
3438
3439 mvm_sta->disable_tx = disable;
3440
3441 /*
0d365ae5
SS
3442 * Tell mac80211 to start/stop queuing tx for this station,
3443 * but don't stop queuing if there are still pending frames
003e5236
AO
3444 * for this station.
3445 */
3446 if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id]))
3447 ieee80211_sta_block_awake(mvm->hw, sta, disable);
3448
3449 iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable);
3450
3451 spin_unlock_bh(&mvm_sta->lock);
3452}
3453
3454void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm,
3455 struct iwl_mvm_vif *mvmvif,
3456 bool disable)
3457{
3458 struct ieee80211_sta *sta;
3459 struct iwl_mvm_sta *mvm_sta;
3460 int i;
3461
3462 lockdep_assert_held(&mvm->mutex);
3463
3464 /* Block/unblock all the stations of the given mvmvif */
0ae98812 3465 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
003e5236
AO
3466 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3467 lockdep_is_held(&mvm->mutex));
3468 if (IS_ERR_OR_NULL(sta))
3469 continue;
3470
3471 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3472 if (mvm_sta->mac_id_n_color !=
3473 FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color))
3474 continue;
3475
3476 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable);
3477 }
3478}
dc88b4ba
LC
3479
3480void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
3481{
3482 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3483 struct iwl_mvm_sta *mvmsta;
3484
3485 rcu_read_lock();
3486
3487 mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id);
3488
3489 if (!WARN_ON(!mvmsta))
3490 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true);
3491
3492 rcu_read_unlock();
3493}