1 /******************************************************************************
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.
8 * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 Intel Deutschland GmbH
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.
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.
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,
26 * The full GNU General Public License is included in this distribution
27 * in the file called COPYING.
29 * Contact Information:
30 * Intel Linux Wireless <linuxwifi@intel.com>
31 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
35 * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved.
36 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
37 * Copyright(c) 2016 Intel Deutschland GmbH
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
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
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.
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.
66 *****************************************************************************/
67 #include <net/mac80211.h>
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.
78 static inline int iwl_mvm_add_sta_cmd_size(struct iwl_mvm *mvm)
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);
85 static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm,
86 enum nl80211_iftype iftype)
91 BUILD_BUG_ON(IWL_MVM_STATION_COUNT > 32);
92 WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status));
94 lockdep_assert_held(&mvm->mutex);
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);
100 /* Don't take rcu_read_lock() since we are protected by mvm->mutex */
101 for (sta_id = 0; sta_id < IWL_MVM_STATION_COUNT; sta_id++) {
102 if (BIT(sta_id) & reserved_ids)
105 if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
106 lockdep_is_held(&mvm->mutex)))
109 return IWL_MVM_STATION_COUNT;
112 /* send station add/update command to firmware */
113 int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
114 bool update, unsigned int flags)
116 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
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),
123 .tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg),
127 u32 agg_size = 0, mpdu_dens = 0;
129 if (!update || (flags & STA_MODIFY_QUEUES)) {
130 add_sta_cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk);
131 memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN);
133 if (flags & STA_MODIFY_QUEUES)
134 add_sta_cmd.modify_mask |= STA_MODIFY_QUEUES;
137 switch (sta->bandwidth) {
138 case IEEE80211_STA_RX_BW_160:
139 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_160MHZ);
141 case IEEE80211_STA_RX_BW_80:
142 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_80MHZ);
144 case IEEE80211_STA_RX_BW_40:
145 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_40MHZ);
147 case IEEE80211_STA_RX_BW_20:
148 if (sta->ht_cap.ht_supported)
149 add_sta_cmd.station_flags |=
150 cpu_to_le32(STA_FLG_FAT_EN_20MHZ);
154 switch (sta->rx_nss) {
156 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO);
159 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2);
162 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3);
166 switch (sta->smps_mode) {
167 case IEEE80211_SMPS_AUTOMATIC:
168 case IEEE80211_SMPS_NUM_MODES:
171 case IEEE80211_SMPS_STATIC:
173 add_sta_cmd.station_flags &= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK);
174 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO);
176 case IEEE80211_SMPS_DYNAMIC:
177 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_RTS_MIMO_PROT);
179 case IEEE80211_SMPS_OFF:
184 if (sta->ht_cap.ht_supported) {
185 add_sta_cmd.station_flags_msk |=
186 cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK |
187 STA_FLG_AGG_MPDU_DENS_MSK);
189 mpdu_dens = sta->ht_cap.ampdu_density;
192 if (sta->vht_cap.vht_supported) {
193 agg_size = sta->vht_cap.cap &
194 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
196 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
197 } else if (sta->ht_cap.ht_supported) {
198 agg_size = sta->ht_cap.ampdu_factor;
201 add_sta_cmd.station_flags |=
202 cpu_to_le32(agg_size << STA_FLG_MAX_AGG_SIZE_SHIFT);
203 add_sta_cmd.station_flags |=
204 cpu_to_le32(mpdu_dens << STA_FLG_AGG_MPDU_DENS_SHIFT);
205 add_sta_cmd.assoc_id = cpu_to_le16(sta->aid);
208 add_sta_cmd.modify_mask |= STA_MODIFY_UAPSD_ACS;
210 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
211 add_sta_cmd.uapsd_trigger_acs |= BIT(AC_BK);
212 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
213 add_sta_cmd.uapsd_trigger_acs |= BIT(AC_BE);
214 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
215 add_sta_cmd.uapsd_trigger_acs |= BIT(AC_VI);
216 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
217 add_sta_cmd.uapsd_trigger_acs |= BIT(AC_VO);
220 status = ADD_STA_SUCCESS;
221 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
222 iwl_mvm_add_sta_cmd_size(mvm),
223 &add_sta_cmd, &status);
227 switch (status & IWL_ADD_STA_STATUS_MASK) {
228 case ADD_STA_SUCCESS:
229 IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n");
233 IWL_ERR(mvm, "ADD_STA failed\n");
240 static void iwl_mvm_rx_agg_session_expired(unsigned long data)
242 struct iwl_mvm_baid_data __rcu **rcu_ptr = (void *)data;
243 struct iwl_mvm_baid_data *ba_data;
244 struct ieee80211_sta *sta;
245 struct iwl_mvm_sta *mvm_sta;
246 unsigned long timeout;
250 ba_data = rcu_dereference(*rcu_ptr);
252 if (WARN_ON(!ba_data))
255 if (!ba_data->timeout)
258 timeout = ba_data->last_rx + TU_TO_JIFFIES(ba_data->timeout * 2);
259 if (time_is_after_jiffies(timeout)) {
260 mod_timer(&ba_data->session_timer, timeout);
265 sta = rcu_dereference(ba_data->mvm->fw_id_to_mac_id[ba_data->sta_id]);
266 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
267 ieee80211_stop_rx_ba_session_offl(mvm_sta->vif,
268 sta->addr, ba_data->tid);
273 static int iwl_mvm_tdls_sta_init(struct iwl_mvm *mvm,
274 struct ieee80211_sta *sta)
276 unsigned long used_hw_queues;
277 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
278 unsigned int wdg_timeout =
279 iwl_mvm_get_wd_timeout(mvm, NULL, true, false);
282 lockdep_assert_held(&mvm->mutex);
284 used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, NULL);
286 /* Find available queues, and allocate them to the ACs */
287 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
288 u8 queue = find_first_zero_bit(&used_hw_queues,
289 mvm->first_agg_queue);
291 if (queue >= mvm->first_agg_queue) {
292 IWL_ERR(mvm, "Failed to allocate STA queue\n");
296 __set_bit(queue, &used_hw_queues);
297 mvmsta->hw_queue[ac] = queue;
300 /* Found a place for all queues - enable them */
301 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
302 iwl_mvm_enable_ac_txq(mvm, mvmsta->hw_queue[ac],
303 mvmsta->hw_queue[ac],
304 iwl_mvm_ac_to_tx_fifo[ac], 0,
306 mvmsta->tfd_queue_msk |= BIT(mvmsta->hw_queue[ac]);
312 static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm *mvm,
313 struct ieee80211_sta *sta)
315 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
316 unsigned long sta_msk;
319 lockdep_assert_held(&mvm->mutex);
321 /* disable the TDLS STA-specific queues */
322 sta_msk = mvmsta->tfd_queue_msk;
323 for_each_set_bit(i, &sta_msk, sizeof(sta_msk) * BITS_PER_BYTE)
324 iwl_mvm_disable_txq(mvm, i, i, IWL_MAX_TID_COUNT, 0);
327 /* Disable aggregations for a bitmap of TIDs for a given station */
328 static int iwl_mvm_invalidate_sta_queue(struct iwl_mvm *mvm, int queue,
329 unsigned long disable_agg_tids,
332 struct iwl_mvm_add_sta_cmd cmd = {};
333 struct ieee80211_sta *sta;
334 struct iwl_mvm_sta *mvmsta;
339 spin_lock_bh(&mvm->queue_info_lock);
340 sta_id = mvm->queue_info[queue].ra_sta_id;
341 spin_unlock_bh(&mvm->queue_info_lock);
345 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
347 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
352 mvmsta = iwl_mvm_sta_from_mac80211(sta);
354 mvmsta->tid_disable_agg |= disable_agg_tids;
356 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
357 cmd.sta_id = mvmsta->sta_id;
358 cmd.add_modify = STA_MODE_MODIFY;
359 cmd.modify_mask = STA_MODIFY_QUEUES;
360 if (disable_agg_tids)
361 cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX;
363 cmd.modify_mask |= STA_MODIFY_QUEUE_REMOVAL;
364 cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk);
365 cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg);
369 /* Notify FW of queue removal from the STA queues */
370 status = ADD_STA_SUCCESS;
371 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
372 iwl_mvm_add_sta_cmd_size(mvm),
378 static int iwl_mvm_get_queue_agg_tids(struct iwl_mvm *mvm, int queue)
380 struct ieee80211_sta *sta;
381 struct iwl_mvm_sta *mvmsta;
382 unsigned long tid_bitmap;
383 unsigned long agg_tids = 0;
387 lockdep_assert_held(&mvm->mutex);
389 spin_lock_bh(&mvm->queue_info_lock);
390 sta_id = mvm->queue_info[queue].ra_sta_id;
391 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
392 spin_unlock_bh(&mvm->queue_info_lock);
394 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
395 lockdep_is_held(&mvm->mutex));
397 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
400 mvmsta = iwl_mvm_sta_from_mac80211(sta);
402 spin_lock_bh(&mvmsta->lock);
403 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
404 if (mvmsta->tid_data[tid].state == IWL_AGG_ON)
405 agg_tids |= BIT(tid);
407 spin_unlock_bh(&mvmsta->lock);
413 * Remove a queue from a station's resources.
414 * Note that this only marks as free. It DOESN'T delete a BA agreement, and
415 * doesn't disable the queue
417 static int iwl_mvm_remove_sta_queue_marking(struct iwl_mvm *mvm, int queue)
419 struct ieee80211_sta *sta;
420 struct iwl_mvm_sta *mvmsta;
421 unsigned long tid_bitmap;
422 unsigned long disable_agg_tids = 0;
426 lockdep_assert_held(&mvm->mutex);
428 spin_lock_bh(&mvm->queue_info_lock);
429 sta_id = mvm->queue_info[queue].ra_sta_id;
430 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
431 spin_unlock_bh(&mvm->queue_info_lock);
435 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
437 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
442 mvmsta = iwl_mvm_sta_from_mac80211(sta);
444 spin_lock_bh(&mvmsta->lock);
445 /* Unmap MAC queues and TIDs from this queue */
446 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
447 if (mvmsta->tid_data[tid].state == IWL_AGG_ON)
448 disable_agg_tids |= BIT(tid);
449 mvmsta->tid_data[tid].txq_id = IEEE80211_INVAL_HW_QUEUE;
452 mvmsta->tfd_queue_msk &= ~BIT(queue); /* Don't use this queue anymore */
453 spin_unlock_bh(&mvmsta->lock);
457 spin_lock_bh(&mvm->queue_info_lock);
458 /* Unmap MAC queues and TIDs from this queue */
459 mvm->queue_info[queue].hw_queue_to_mac80211 = 0;
460 mvm->queue_info[queue].hw_queue_refcount = 0;
461 mvm->queue_info[queue].tid_bitmap = 0;
462 spin_unlock_bh(&mvm->queue_info_lock);
464 return disable_agg_tids;
467 static int iwl_mvm_get_shared_queue(struct iwl_mvm *mvm,
468 unsigned long tfd_queue_mask, u8 ac)
471 u8 ac_to_queue[IEEE80211_NUM_ACS];
474 lockdep_assert_held(&mvm->queue_info_lock);
476 memset(&ac_to_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(ac_to_queue));
478 /* See what ACs the existing queues for this STA have */
479 for_each_set_bit(i, &tfd_queue_mask, IWL_MVM_DQA_MAX_DATA_QUEUE) {
480 /* Only DATA queues can be shared */
481 if (i < IWL_MVM_DQA_MIN_DATA_QUEUE &&
482 i != IWL_MVM_DQA_BSS_CLIENT_QUEUE)
485 /* Don't try and take queues being reconfigured */
486 if (mvm->queue_info[queue].status ==
487 IWL_MVM_QUEUE_RECONFIGURING)
490 ac_to_queue[mvm->queue_info[i].mac80211_ac] = i;
494 * The queue to share is chosen only from DATA queues as follows (in
495 * descending priority):
498 * 3. Highest AC queue that is lower than new AC
499 * 4. Any existing AC (there always is at least 1 DATA queue)
502 /* Priority 1: An AC_BE queue */
503 if (ac_to_queue[IEEE80211_AC_BE] != IEEE80211_INVAL_HW_QUEUE)
504 queue = ac_to_queue[IEEE80211_AC_BE];
505 /* Priority 2: Same AC queue */
506 else if (ac_to_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
507 queue = ac_to_queue[ac];
508 /* Priority 3a: If new AC is VO and VI exists - use VI */
509 else if (ac == IEEE80211_AC_VO &&
510 ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE)
511 queue = ac_to_queue[IEEE80211_AC_VI];
512 /* Priority 3b: No BE so only AC less than the new one is BK */
513 else if (ac_to_queue[IEEE80211_AC_BK] != IEEE80211_INVAL_HW_QUEUE)
514 queue = ac_to_queue[IEEE80211_AC_BK];
515 /* Priority 4a: No BE nor BK - use VI if exists */
516 else if (ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE)
517 queue = ac_to_queue[IEEE80211_AC_VI];
518 /* Priority 4b: No BE, BK nor VI - use VO if exists */
519 else if (ac_to_queue[IEEE80211_AC_VO] != IEEE80211_INVAL_HW_QUEUE)
520 queue = ac_to_queue[IEEE80211_AC_VO];
522 /* Make sure queue found (or not) is legal */
523 if (!iwl_mvm_is_dqa_data_queue(mvm, queue) &&
524 !iwl_mvm_is_dqa_mgmt_queue(mvm, queue) &&
525 (queue != IWL_MVM_DQA_BSS_CLIENT_QUEUE)) {
526 IWL_ERR(mvm, "No DATA queues available to share\n");
530 /* Make sure the queue isn't in the middle of being reconfigured */
531 if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_RECONFIGURING) {
533 "TXQ %d is in the middle of re-config - try again\n",
542 * If a given queue has a higher AC than the TID stream that is being compared
543 * to, the queue needs to be redirected to the lower AC. This function does that
544 * in such a case, otherwise - if no redirection required - it does nothing,
545 * unless the %force param is true.
547 int iwl_mvm_scd_queue_redirect(struct iwl_mvm *mvm, int queue, int tid,
548 int ac, int ssn, unsigned int wdg_timeout,
551 struct iwl_scd_txq_cfg_cmd cmd = {
553 .action = SCD_CFG_DISABLE_QUEUE,
560 * If the AC is lower than current one - FIFO needs to be redirected to
561 * the lowest one of the streams in the queue. Check if this is needed
563 * Notice that the enum ieee80211_ac_numbers is "flipped", so BK is with
564 * value 3 and VO with value 0, so to check if ac X is lower than ac Y
565 * we need to check if the numerical value of X is LARGER than of Y.
567 spin_lock_bh(&mvm->queue_info_lock);
568 if (ac <= mvm->queue_info[queue].mac80211_ac && !force) {
569 spin_unlock_bh(&mvm->queue_info_lock);
571 IWL_DEBUG_TX_QUEUES(mvm,
572 "No redirection needed on TXQ #%d\n",
577 cmd.sta_id = mvm->queue_info[queue].ra_sta_id;
578 cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[mvm->queue_info[queue].mac80211_ac];
579 cmd.tid = mvm->queue_info[queue].txq_tid;
580 mq = mvm->queue_info[queue].hw_queue_to_mac80211;
581 shared_queue = (mvm->queue_info[queue].hw_queue_refcount > 1);
582 spin_unlock_bh(&mvm->queue_info_lock);
584 IWL_DEBUG_TX_QUEUES(mvm, "Redirecting TXQ #%d to FIFO #%d\n",
585 queue, iwl_mvm_ac_to_tx_fifo[ac]);
587 /* Stop MAC queues and wait for this queue to empty */
588 iwl_mvm_stop_mac_queues(mvm, mq);
589 ret = iwl_trans_wait_tx_queue_empty(mvm->trans, BIT(queue));
591 IWL_ERR(mvm, "Error draining queue %d before reconfig\n",
597 /* Before redirecting the queue we need to de-activate it */
598 iwl_trans_txq_disable(mvm->trans, queue, false);
599 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd);
601 IWL_ERR(mvm, "Failed SCD disable TXQ %d (ret=%d)\n", queue,
604 /* Make sure the SCD wrptr is correctly set before reconfiguring */
605 iwl_trans_txq_enable_cfg(mvm->trans, queue, ssn, NULL, wdg_timeout);
607 /* Update the TID "owner" of the queue */
608 spin_lock_bh(&mvm->queue_info_lock);
609 mvm->queue_info[queue].txq_tid = tid;
610 spin_unlock_bh(&mvm->queue_info_lock);
612 /* TODO: Work-around SCD bug when moving back by multiples of 0x40 */
614 /* Redirect to lower AC */
615 iwl_mvm_reconfig_scd(mvm, queue, iwl_mvm_ac_to_tx_fifo[ac],
616 cmd.sta_id, tid, LINK_QUAL_AGG_FRAME_LIMIT_DEF,
619 /* Update AC marking of the queue */
620 spin_lock_bh(&mvm->queue_info_lock);
621 mvm->queue_info[queue].mac80211_ac = ac;
622 spin_unlock_bh(&mvm->queue_info_lock);
625 * Mark queue as shared in transport if shared
626 * Note this has to be done after queue enablement because enablement
627 * can also set this value, and there is no indication there to shared
631 iwl_trans_txq_set_shared_mode(mvm->trans, queue, true);
634 /* Continue using the MAC queues */
635 iwl_mvm_start_mac_queues(mvm, mq);
640 static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm,
641 struct ieee80211_sta *sta, u8 ac, int tid,
642 struct ieee80211_hdr *hdr)
644 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
645 struct iwl_trans_txq_scd_cfg cfg = {
646 .fifo = iwl_mvm_ac_to_tx_fifo[ac],
647 .sta_id = mvmsta->sta_id,
649 .frame_limit = IWL_FRAME_LIMIT,
651 unsigned int wdg_timeout =
652 iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
653 u8 mac_queue = mvmsta->vif->hw_queue[ac];
655 bool using_inactive_queue = false;
656 unsigned long disable_agg_tids = 0;
657 enum iwl_mvm_agg_state queue_state;
658 bool shared_queue = false;
660 unsigned long tfd_queue_mask;
663 lockdep_assert_held(&mvm->mutex);
665 spin_lock_bh(&mvmsta->lock);
666 tfd_queue_mask = mvmsta->tfd_queue_msk;
667 spin_unlock_bh(&mvmsta->lock);
669 spin_lock_bh(&mvm->queue_info_lock);
672 * Non-QoS, QoS NDP and MGMT frames should go to a MGMT queue, if one
675 if (!ieee80211_is_data_qos(hdr->frame_control) ||
676 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
677 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
678 IWL_MVM_DQA_MIN_MGMT_QUEUE,
679 IWL_MVM_DQA_MAX_MGMT_QUEUE);
680 if (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE)
681 IWL_DEBUG_TX_QUEUES(mvm, "Found free MGMT queue #%d\n",
684 /* If no such queue is found, we'll use a DATA queue instead */
687 if ((queue < 0 && mvmsta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) &&
688 (mvm->queue_info[mvmsta->reserved_queue].status ==
689 IWL_MVM_QUEUE_RESERVED ||
690 mvm->queue_info[mvmsta->reserved_queue].status ==
691 IWL_MVM_QUEUE_INACTIVE)) {
692 queue = mvmsta->reserved_queue;
693 mvm->queue_info[queue].reserved = true;
694 IWL_DEBUG_TX_QUEUES(mvm, "Using reserved queue #%d\n", queue);
698 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
699 IWL_MVM_DQA_MIN_DATA_QUEUE,
700 IWL_MVM_DQA_MAX_DATA_QUEUE);
703 * Check if this queue is already allocated but inactive.
704 * In such a case, we'll need to first free this queue before enabling
705 * it again, so we'll mark it as reserved to make sure no new traffic
709 mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) {
710 mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED;
711 using_inactive_queue = true;
712 IWL_DEBUG_TX_QUEUES(mvm,
713 "Re-assigning TXQ %d: sta_id=%d, tid=%d\n",
714 queue, mvmsta->sta_id, tid);
717 /* No free queue - we'll have to share */
719 queue = iwl_mvm_get_shared_queue(mvm, tfd_queue_mask, ac);
722 mvm->queue_info[queue].status = IWL_MVM_QUEUE_SHARED;
727 * Mark TXQ as ready, even though it hasn't been fully configured yet,
728 * to make sure no one else takes it.
729 * This will allow avoiding re-acquiring the lock at the end of the
730 * configuration. On error we'll mark it back as free.
732 if ((queue > 0) && !shared_queue)
733 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
735 spin_unlock_bh(&mvm->queue_info_lock);
737 /* This shouldn't happen - out of queues */
738 if (WARN_ON(queue <= 0)) {
739 IWL_ERR(mvm, "No available queues for tid %d on sta_id %d\n",
745 * Actual en/disablement of aggregations is through the ADD_STA HCMD,
746 * but for configuring the SCD to send A-MPDUs we need to mark the queue
748 * Mark all DATA queues as allowing to be aggregated at some point
750 cfg.aggregate = (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
751 queue == IWL_MVM_DQA_BSS_CLIENT_QUEUE);
754 * If this queue was previously inactive (idle) - we need to free it
757 if (using_inactive_queue) {
758 struct iwl_scd_txq_cfg_cmd cmd = {
760 .action = SCD_CFG_DISABLE_QUEUE,
764 disable_agg_tids = iwl_mvm_remove_sta_queue_marking(mvm, queue);
766 spin_lock_bh(&mvm->queue_info_lock);
767 txq_curr_ac = mvm->queue_info[queue].mac80211_ac;
768 cmd.sta_id = mvm->queue_info[queue].ra_sta_id;
769 cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[txq_curr_ac];
770 cmd.tid = mvm->queue_info[queue].txq_tid;
771 spin_unlock_bh(&mvm->queue_info_lock);
773 /* Disable the queue */
774 if (disable_agg_tids)
775 iwl_mvm_invalidate_sta_queue(mvm, queue,
776 disable_agg_tids, false);
777 iwl_trans_txq_disable(mvm->trans, queue, false);
778 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd),
782 "Failed to free inactive queue %d (ret=%d)\n",
785 /* Re-mark the inactive queue as inactive */
786 spin_lock_bh(&mvm->queue_info_lock);
787 mvm->queue_info[queue].status = IWL_MVM_QUEUE_INACTIVE;
788 spin_unlock_bh(&mvm->queue_info_lock);
793 /* If TXQ is allocated to another STA, update removal in FW */
794 if (cmd.sta_id != mvmsta->sta_id)
795 iwl_mvm_invalidate_sta_queue(mvm, queue, 0, true);
798 IWL_DEBUG_TX_QUEUES(mvm,
799 "Allocating %squeue #%d to sta %d on tid %d\n",
800 shared_queue ? "shared " : "", queue,
801 mvmsta->sta_id, tid);
804 /* Disable any open aggs on this queue */
805 disable_agg_tids = iwl_mvm_get_queue_agg_tids(mvm, queue);
807 if (disable_agg_tids) {
808 IWL_DEBUG_TX_QUEUES(mvm, "Disabling aggs on queue %d\n",
810 iwl_mvm_invalidate_sta_queue(mvm, queue,
811 disable_agg_tids, false);
815 ssn = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
816 iwl_mvm_enable_txq(mvm, queue, mac_queue, ssn, &cfg,
820 * Mark queue as shared in transport if shared
821 * Note this has to be done after queue enablement because enablement
822 * can also set this value, and there is no indication there to shared
826 iwl_trans_txq_set_shared_mode(mvm->trans, queue, true);
828 spin_lock_bh(&mvmsta->lock);
829 mvmsta->tid_data[tid].txq_id = queue;
830 mvmsta->tid_data[tid].is_tid_active = true;
831 mvmsta->tfd_queue_msk |= BIT(queue);
832 queue_state = mvmsta->tid_data[tid].state;
834 if (mvmsta->reserved_queue == queue)
835 mvmsta->reserved_queue = IEEE80211_INVAL_HW_QUEUE;
836 spin_unlock_bh(&mvmsta->lock);
839 ret = iwl_mvm_sta_send_to_fw(mvm, sta, true, STA_MODIFY_QUEUES);
843 /* If we need to re-enable aggregations... */
844 if (queue_state == IWL_AGG_ON) {
845 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
850 /* Redirect queue, if needed */
851 ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid, ac, ssn,
860 iwl_mvm_disable_txq(mvm, queue, mac_queue, tid, 0);
865 static void iwl_mvm_change_queue_owner(struct iwl_mvm *mvm, int queue)
867 struct iwl_scd_txq_cfg_cmd cmd = {
869 .action = SCD_CFG_UPDATE_QUEUE_TID,
873 unsigned long tid_bitmap;
876 lockdep_assert_held(&mvm->mutex);
878 spin_lock_bh(&mvm->queue_info_lock);
879 sta_id = mvm->queue_info[queue].ra_sta_id;
880 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
881 spin_unlock_bh(&mvm->queue_info_lock);
883 if (WARN(!tid_bitmap, "TXQ %d has no tids assigned to it\n", queue))
886 /* Find any TID for queue */
887 tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1);
889 cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
891 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd);
893 IWL_ERR(mvm, "Failed to update owner of TXQ %d (ret=%d)\n",
898 spin_lock_bh(&mvm->queue_info_lock);
899 mvm->queue_info[queue].txq_tid = tid;
900 spin_unlock_bh(&mvm->queue_info_lock);
901 IWL_DEBUG_TX_QUEUES(mvm, "Changed TXQ %d ownership to tid %d\n",
905 static void iwl_mvm_unshare_queue(struct iwl_mvm *mvm, int queue)
907 struct ieee80211_sta *sta;
908 struct iwl_mvm_sta *mvmsta;
911 unsigned long tid_bitmap;
912 unsigned int wdg_timeout;
916 lockdep_assert_held(&mvm->mutex);
918 spin_lock_bh(&mvm->queue_info_lock);
919 sta_id = mvm->queue_info[queue].ra_sta_id;
920 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
921 spin_unlock_bh(&mvm->queue_info_lock);
923 /* Find TID for queue, and make sure it is the only one on the queue */
924 tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1);
925 if (tid_bitmap != BIT(tid)) {
926 IWL_ERR(mvm, "Failed to unshare q %d, active tids=0x%lx\n",
931 IWL_DEBUG_TX_QUEUES(mvm, "Unsharing TXQ %d, keeping tid %d\n", queue,
934 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
935 lockdep_is_held(&mvm->mutex));
937 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
940 mvmsta = iwl_mvm_sta_from_mac80211(sta);
941 wdg_timeout = iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
943 ssn = IEEE80211_SEQ_TO_SN(mvmsta->tid_data[tid].seq_number);
945 ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid,
946 tid_to_mac80211_ac[tid], ssn,
949 IWL_ERR(mvm, "Failed to redirect TXQ %d\n", queue);
953 /* If aggs should be turned back on - do it */
954 if (mvmsta->tid_data[tid].state == IWL_AGG_ON) {
955 struct iwl_mvm_add_sta_cmd cmd = {0};
957 mvmsta->tid_disable_agg &= ~BIT(tid);
959 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
960 cmd.sta_id = mvmsta->sta_id;
961 cmd.add_modify = STA_MODE_MODIFY;
962 cmd.modify_mask = STA_MODIFY_TID_DISABLE_TX;
963 cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk);
964 cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg);
966 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
967 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
969 IWL_DEBUG_TX_QUEUES(mvm,
970 "TXQ #%d is now aggregated again\n",
973 /* Mark queue intenally as aggregating again */
974 iwl_trans_txq_set_shared_mode(mvm->trans, queue, false);
978 spin_lock_bh(&mvm->queue_info_lock);
979 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
980 spin_unlock_bh(&mvm->queue_info_lock);
983 static inline u8 iwl_mvm_tid_to_ac_queue(int tid)
985 if (tid == IWL_MAX_TID_COUNT)
986 return IEEE80211_AC_VO; /* MGMT */
988 return tid_to_mac80211_ac[tid];
991 static void iwl_mvm_tx_deferred_stream(struct iwl_mvm *mvm,
992 struct ieee80211_sta *sta, int tid)
994 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
995 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
997 struct ieee80211_hdr *hdr;
998 struct sk_buff_head deferred_tx;
1000 bool no_queue = false; /* Marks if there is a problem with the queue */
1003 lockdep_assert_held(&mvm->mutex);
1005 skb = skb_peek(&tid_data->deferred_tx_frames);
1008 hdr = (void *)skb->data;
1010 ac = iwl_mvm_tid_to_ac_queue(tid);
1011 mac_queue = IEEE80211_SKB_CB(skb)->hw_queue;
1013 if (tid_data->txq_id == IEEE80211_INVAL_HW_QUEUE &&
1014 iwl_mvm_sta_alloc_queue(mvm, sta, ac, tid, hdr)) {
1016 "Can't alloc TXQ for sta %d tid %d - dropping frame\n",
1017 mvmsta->sta_id, tid);
1020 * Mark queue as problematic so later the deferred traffic is
1021 * freed, as we can do nothing with it
1026 __skb_queue_head_init(&deferred_tx);
1028 /* Disable bottom-halves when entering TX path */
1030 spin_lock(&mvmsta->lock);
1031 skb_queue_splice_init(&tid_data->deferred_tx_frames, &deferred_tx);
1032 mvmsta->deferred_traffic_tid_map &= ~BIT(tid);
1033 spin_unlock(&mvmsta->lock);
1035 while ((skb = __skb_dequeue(&deferred_tx)))
1036 if (no_queue || iwl_mvm_tx_skb(mvm, skb, sta))
1037 ieee80211_free_txskb(mvm->hw, skb);
1041 iwl_mvm_start_mac_queues(mvm, BIT(mac_queue));
1044 void iwl_mvm_add_new_dqa_stream_wk(struct work_struct *wk)
1046 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm,
1048 struct ieee80211_sta *sta;
1049 struct iwl_mvm_sta *mvmsta;
1050 unsigned long deferred_tid_traffic;
1051 int queue, sta_id, tid;
1053 /* Check inactivity of queues */
1054 iwl_mvm_inactivity_check(mvm);
1056 mutex_lock(&mvm->mutex);
1058 /* Reconfigure queues requiring reconfiguation */
1059 for (queue = 0; queue < IWL_MAX_HW_QUEUES; queue++) {
1063 spin_lock_bh(&mvm->queue_info_lock);
1064 reconfig = (mvm->queue_info[queue].status ==
1065 IWL_MVM_QUEUE_RECONFIGURING);
1068 * We need to take into account a situation in which a TXQ was
1069 * allocated to TID x, and then turned shared by adding TIDs y
1070 * and z. If TID x becomes inactive and is removed from the TXQ,
1071 * ownership must be given to one of the remaining TIDs.
1072 * This is mainly because if TID x continues - a new queue can't
1073 * be allocated for it as long as it is an owner of another TXQ.
1075 change_owner = !(mvm->queue_info[queue].tid_bitmap &
1076 BIT(mvm->queue_info[queue].txq_tid)) &&
1077 (mvm->queue_info[queue].status ==
1078 IWL_MVM_QUEUE_SHARED);
1079 spin_unlock_bh(&mvm->queue_info_lock);
1082 iwl_mvm_unshare_queue(mvm, queue);
1083 else if (change_owner)
1084 iwl_mvm_change_queue_owner(mvm, queue);
1087 /* Go over all stations with deferred traffic */
1088 for_each_set_bit(sta_id, mvm->sta_deferred_frames,
1089 IWL_MVM_STATION_COUNT) {
1090 clear_bit(sta_id, mvm->sta_deferred_frames);
1091 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1092 lockdep_is_held(&mvm->mutex));
1093 if (IS_ERR_OR_NULL(sta))
1096 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1097 deferred_tid_traffic = mvmsta->deferred_traffic_tid_map;
1099 for_each_set_bit(tid, &deferred_tid_traffic,
1100 IWL_MAX_TID_COUNT + 1)
1101 iwl_mvm_tx_deferred_stream(mvm, sta, tid);
1104 mutex_unlock(&mvm->mutex);
1107 static int iwl_mvm_reserve_sta_stream(struct iwl_mvm *mvm,
1108 struct ieee80211_sta *sta,
1109 enum nl80211_iftype vif_type)
1111 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1115 * Check for inactive queues, so we don't reach a situation where we
1116 * can't add a STA due to a shortage in queues that doesn't really exist
1118 iwl_mvm_inactivity_check(mvm);
1120 spin_lock_bh(&mvm->queue_info_lock);
1122 /* Make sure we have free resources for this STA */
1123 if (vif_type == NL80211_IFTYPE_STATION && !sta->tdls &&
1124 !mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].hw_queue_refcount &&
1125 (mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].status ==
1126 IWL_MVM_QUEUE_FREE))
1127 queue = IWL_MVM_DQA_BSS_CLIENT_QUEUE;
1129 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
1130 IWL_MVM_DQA_MIN_DATA_QUEUE,
1131 IWL_MVM_DQA_MAX_DATA_QUEUE);
1133 spin_unlock_bh(&mvm->queue_info_lock);
1134 IWL_ERR(mvm, "No available queues for new station\n");
1137 mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED;
1139 spin_unlock_bh(&mvm->queue_info_lock);
1141 mvmsta->reserved_queue = queue;
1143 IWL_DEBUG_TX_QUEUES(mvm, "Reserving data queue #%d for sta_id %d\n",
1144 queue, mvmsta->sta_id);
1150 * In DQA mode, after a HW restart the queues should be allocated as before, in
1151 * order to avoid race conditions when there are shared queues. This function
1152 * does the re-mapping and queue allocation.
1154 * Note that re-enabling aggregations isn't done in this function.
1156 static void iwl_mvm_realloc_queues_after_restart(struct iwl_mvm *mvm,
1157 struct iwl_mvm_sta *mvm_sta)
1159 unsigned int wdg_timeout =
1160 iwl_mvm_get_wd_timeout(mvm, mvm_sta->vif, false, false);
1162 struct iwl_trans_txq_scd_cfg cfg = {
1163 .sta_id = mvm_sta->sta_id,
1164 .frame_limit = IWL_FRAME_LIMIT,
1167 /* Make sure reserved queue is still marked as such (if allocated) */
1168 if (mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE)
1169 mvm->queue_info[mvm_sta->reserved_queue].status =
1170 IWL_MVM_QUEUE_RESERVED;
1172 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
1173 struct iwl_mvm_tid_data *tid_data = &mvm_sta->tid_data[i];
1174 int txq_id = tid_data->txq_id;
1178 if (txq_id == IEEE80211_INVAL_HW_QUEUE)
1181 skb_queue_head_init(&tid_data->deferred_tx_frames);
1183 ac = tid_to_mac80211_ac[i];
1184 mac_queue = mvm_sta->vif->hw_queue[ac];
1187 cfg.fifo = iwl_mvm_ac_to_tx_fifo[ac];
1188 cfg.aggregate = (txq_id >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
1189 txq_id == IWL_MVM_DQA_BSS_CLIENT_QUEUE);
1191 IWL_DEBUG_TX_QUEUES(mvm,
1192 "Re-mapping sta %d tid %d to queue %d\n",
1193 mvm_sta->sta_id, i, txq_id);
1195 iwl_mvm_enable_txq(mvm, txq_id, mac_queue,
1196 IEEE80211_SEQ_TO_SN(tid_data->seq_number),
1199 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_READY;
1202 atomic_set(&mvm->pending_frames[mvm_sta->sta_id], 0);
1205 int iwl_mvm_add_sta(struct iwl_mvm *mvm,
1206 struct ieee80211_vif *vif,
1207 struct ieee80211_sta *sta)
1209 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1210 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1211 struct iwl_mvm_rxq_dup_data *dup_data;
1214 lockdep_assert_held(&mvm->mutex);
1216 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1217 sta_id = iwl_mvm_find_free_sta_id(mvm,
1218 ieee80211_vif_type_p2p(vif));
1220 sta_id = mvm_sta->sta_id;
1222 if (sta_id == IWL_MVM_STATION_COUNT)
1225 spin_lock_init(&mvm_sta->lock);
1227 /* In DQA mode, if this is a HW restart, re-alloc existing queues */
1228 if (iwl_mvm_is_dqa_supported(mvm) &&
1229 test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1230 iwl_mvm_realloc_queues_after_restart(mvm, mvm_sta);
1234 mvm_sta->sta_id = sta_id;
1235 mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id,
1238 mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
1239 mvm_sta->tx_protection = 0;
1240 mvm_sta->tt_tx_protection = false;
1242 /* HW restart, don't assume the memory has been zeroed */
1243 atomic_set(&mvm->pending_frames[sta_id], 0);
1244 mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */
1245 mvm_sta->tfd_queue_msk = 0;
1248 * Allocate new queues for a TDLS station, unless we're in DQA mode,
1249 * and then they'll be allocated dynamically
1251 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) {
1252 ret = iwl_mvm_tdls_sta_init(mvm, sta);
1255 } else if (!iwl_mvm_is_dqa_supported(mvm)) {
1256 for (i = 0; i < IEEE80211_NUM_ACS; i++)
1257 if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE)
1258 mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]);
1261 /* for HW restart - reset everything but the sequence number */
1262 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
1263 u16 seq = mvm_sta->tid_data[i].seq_number;
1264 memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i]));
1265 mvm_sta->tid_data[i].seq_number = seq;
1267 if (!iwl_mvm_is_dqa_supported(mvm))
1271 * Mark all queues for this STA as unallocated and defer TX
1272 * frames until the queue is allocated
1274 mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE;
1275 skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames);
1277 mvm_sta->deferred_traffic_tid_map = 0;
1278 mvm_sta->agg_tids = 0;
1280 if (iwl_mvm_has_new_rx_api(mvm) &&
1281 !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1282 dup_data = kcalloc(mvm->trans->num_rx_queues,
1287 mvm_sta->dup_data = dup_data;
1290 if (iwl_mvm_is_dqa_supported(mvm)) {
1291 ret = iwl_mvm_reserve_sta_stream(mvm, sta,
1292 ieee80211_vif_type_p2p(vif));
1298 ret = iwl_mvm_sta_send_to_fw(mvm, sta, false, 0);
1302 if (vif->type == NL80211_IFTYPE_STATION) {
1304 WARN_ON(mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT);
1305 mvmvif->ap_sta_id = sta_id;
1307 WARN_ON(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT);
1311 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta);
1316 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls)
1317 iwl_mvm_tdls_sta_deinit(mvm, sta);
1321 int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
1324 struct iwl_mvm_add_sta_cmd cmd = {};
1328 lockdep_assert_held(&mvm->mutex);
1330 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
1331 cmd.sta_id = mvmsta->sta_id;
1332 cmd.add_modify = STA_MODE_MODIFY;
1333 cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0;
1334 cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW);
1336 status = ADD_STA_SUCCESS;
1337 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1338 iwl_mvm_add_sta_cmd_size(mvm),
1343 switch (status & IWL_ADD_STA_STATUS_MASK) {
1344 case ADD_STA_SUCCESS:
1345 IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n",
1350 IWL_ERR(mvm, "Couldn't drain frames for staid %d\n",
1359 * Remove a station from the FW table. Before sending the command to remove
1360 * the station validate that the station is indeed known to the driver (sanity
1363 static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id)
1365 struct ieee80211_sta *sta;
1366 struct iwl_mvm_rm_sta_cmd rm_sta_cmd = {
1371 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1372 lockdep_is_held(&mvm->mutex));
1374 /* Note: internal stations are marked as error values */
1376 IWL_ERR(mvm, "Invalid station id\n");
1380 ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0,
1381 sizeof(rm_sta_cmd), &rm_sta_cmd);
1383 IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id);
1390 void iwl_mvm_sta_drained_wk(struct work_struct *wk)
1392 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk);
1396 * The mutex is needed because of the SYNC cmd, but not only: if the
1397 * work would run concurrently with iwl_mvm_rm_sta, it would run before
1398 * iwl_mvm_rm_sta sets the station as busy, and exit. Then
1399 * iwl_mvm_rm_sta would set the station as busy, and nobody will clean
1402 mutex_lock(&mvm->mutex);
1404 for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) {
1406 struct ieee80211_sta *sta =
1407 rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1408 lockdep_is_held(&mvm->mutex));
1411 * This station is in use or RCU-removed; the latter happens in
1412 * managed mode, where mac80211 removes the station before we
1413 * can remove it from firmware (we can only do that after the
1414 * MAC is marked unassociated), and possibly while the deauth
1415 * frame to disconnect from the AP is still queued. Then, the
1416 * station pointer is -ENOENT when the last skb is reclaimed.
1418 if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT)
1421 if (PTR_ERR(sta) == -EINVAL) {
1422 IWL_ERR(mvm, "Drained sta %d, but it is internal?\n",
1428 IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n",
1433 WARN_ON(PTR_ERR(sta) != -EBUSY);
1434 /* This station was removed and we waited until it got drained,
1435 * we can now proceed and remove it.
1437 ret = iwl_mvm_rm_sta_common(mvm, sta_id);
1440 "Couldn't remove sta %d after it was drained\n",
1444 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
1445 clear_bit(sta_id, mvm->sta_drained);
1447 if (mvm->tfd_drained[sta_id]) {
1448 unsigned long i, msk = mvm->tfd_drained[sta_id];
1450 for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE)
1451 iwl_mvm_disable_txq(mvm, i, i,
1452 IWL_MAX_TID_COUNT, 0);
1454 mvm->tfd_drained[sta_id] = 0;
1455 IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n",
1460 mutex_unlock(&mvm->mutex);
1463 static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm,
1464 struct ieee80211_vif *vif,
1465 struct iwl_mvm_sta *mvm_sta)
1470 lockdep_assert_held(&mvm->mutex);
1472 for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) {
1473 if (mvm_sta->tid_data[i].txq_id == IEEE80211_INVAL_HW_QUEUE)
1476 ac = iwl_mvm_tid_to_ac_queue(i);
1477 iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id,
1478 vif->hw_queue[ac], i, 0);
1479 mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE;
1483 int iwl_mvm_rm_sta(struct iwl_mvm *mvm,
1484 struct ieee80211_vif *vif,
1485 struct ieee80211_sta *sta)
1487 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1488 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1491 lockdep_assert_held(&mvm->mutex);
1493 if (iwl_mvm_has_new_rx_api(mvm))
1494 kfree(mvm_sta->dup_data);
1496 if ((vif->type == NL80211_IFTYPE_STATION &&
1497 mvmvif->ap_sta_id == mvm_sta->sta_id) ||
1498 iwl_mvm_is_dqa_supported(mvm)){
1499 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
1502 /* flush its queues here since we are freeing mvm_sta */
1503 ret = iwl_mvm_flush_tx_path(mvm, mvm_sta->tfd_queue_msk, 0);
1506 ret = iwl_trans_wait_tx_queue_empty(mvm->trans,
1507 mvm_sta->tfd_queue_msk);
1510 ret = iwl_mvm_drain_sta(mvm, mvm_sta, false);
1512 /* If DQA is supported - the queues can be disabled now */
1513 if (iwl_mvm_is_dqa_supported(mvm))
1514 iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta);
1516 /* If there is a TXQ still marked as reserved - free it */
1517 if (iwl_mvm_is_dqa_supported(mvm) &&
1518 mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) {
1519 u8 reserved_txq = mvm_sta->reserved_queue;
1520 enum iwl_mvm_queue_status *status;
1523 * If no traffic has gone through the reserved TXQ - it
1524 * is still marked as IWL_MVM_QUEUE_RESERVED, and
1525 * should be manually marked as free again
1527 spin_lock_bh(&mvm->queue_info_lock);
1528 status = &mvm->queue_info[reserved_txq].status;
1529 if (WARN((*status != IWL_MVM_QUEUE_RESERVED) &&
1530 (*status != IWL_MVM_QUEUE_FREE),
1531 "sta_id %d reserved txq %d status %d",
1532 mvm_sta->sta_id, reserved_txq, *status)) {
1533 spin_unlock_bh(&mvm->queue_info_lock);
1537 *status = IWL_MVM_QUEUE_FREE;
1538 spin_unlock_bh(&mvm->queue_info_lock);
1541 if (vif->type == NL80211_IFTYPE_STATION &&
1542 mvmvif->ap_sta_id == mvm_sta->sta_id) {
1543 /* if associated - we can't remove the AP STA now */
1544 if (vif->bss_conf.assoc)
1547 /* unassoc - go ahead - remove the AP STA now */
1548 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1550 /* clear d0i3_ap_sta_id if no longer relevant */
1551 if (mvm->d0i3_ap_sta_id == mvm_sta->sta_id)
1552 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
1557 * This shouldn't happen - the TDLS channel switch should be canceled
1558 * before the STA is removed.
1560 if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == mvm_sta->sta_id)) {
1561 mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT;
1562 cancel_delayed_work(&mvm->tdls_cs.dwork);
1566 * Make sure that the tx response code sees the station as -EBUSY and
1567 * calls the drain worker.
1569 spin_lock_bh(&mvm_sta->lock);
1571 * There are frames pending on the AC queues for this station.
1572 * We need to wait until all the frames are drained...
1574 if (atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) {
1575 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1577 spin_unlock_bh(&mvm_sta->lock);
1579 /* disable TDLS sta queues on drain complete */
1581 mvm->tfd_drained[mvm_sta->sta_id] =
1582 mvm_sta->tfd_queue_msk;
1583 IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n",
1587 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
1589 spin_unlock_bh(&mvm_sta->lock);
1591 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls)
1592 iwl_mvm_tdls_sta_deinit(mvm, sta);
1594 ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id);
1595 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL);
1601 int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm,
1602 struct ieee80211_vif *vif,
1605 int ret = iwl_mvm_rm_sta_common(mvm, sta_id);
1607 lockdep_assert_held(&mvm->mutex);
1609 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
1613 int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm,
1614 struct iwl_mvm_int_sta *sta,
1615 u32 qmask, enum nl80211_iftype iftype)
1617 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1618 sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype);
1619 if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_STATION_COUNT))
1623 sta->tfd_queue_msk = qmask;
1625 /* put a non-NULL value so iterating over the stations won't stop */
1626 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL));
1630 static void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm,
1631 struct iwl_mvm_int_sta *sta)
1633 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta->sta_id], NULL);
1634 memset(sta, 0, sizeof(struct iwl_mvm_int_sta));
1635 sta->sta_id = IWL_MVM_STATION_COUNT;
1638 static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm,
1639 struct iwl_mvm_int_sta *sta,
1641 u16 mac_id, u16 color)
1643 struct iwl_mvm_add_sta_cmd cmd;
1647 lockdep_assert_held(&mvm->mutex);
1649 memset(&cmd, 0, sizeof(cmd));
1650 cmd.sta_id = sta->sta_id;
1651 cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id,
1654 cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk);
1655 cmd.tid_disable_tx = cpu_to_le16(0xffff);
1658 memcpy(cmd.addr, addr, ETH_ALEN);
1660 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1661 iwl_mvm_add_sta_cmd_size(mvm),
1666 switch (status & IWL_ADD_STA_STATUS_MASK) {
1667 case ADD_STA_SUCCESS:
1668 IWL_DEBUG_INFO(mvm, "Internal station added.\n");
1672 IWL_ERR(mvm, "Add internal station failed, status=0x%x\n",
1679 int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm)
1681 unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ?
1682 mvm->cfg->base_params->wd_timeout :
1683 IWL_WATCHDOG_DISABLED;
1686 lockdep_assert_held(&mvm->mutex);
1688 /* Map Aux queue to fifo - needs to happen before adding Aux station */
1689 if (!iwl_mvm_is_dqa_supported(mvm))
1690 iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue,
1691 IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout);
1693 /* Allocate aux station and assign to it the aux queue */
1694 ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue),
1695 NL80211_IFTYPE_UNSPECIFIED);
1699 if (iwl_mvm_is_dqa_supported(mvm)) {
1700 struct iwl_trans_txq_scd_cfg cfg = {
1701 .fifo = IWL_MVM_TX_FIFO_MCAST,
1702 .sta_id = mvm->aux_sta.sta_id,
1703 .tid = IWL_MAX_TID_COUNT,
1705 .frame_limit = IWL_FRAME_LIMIT,
1708 iwl_mvm_enable_txq(mvm, mvm->aux_queue, mvm->aux_queue, 0, &cfg,
1712 ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL,
1716 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
1720 int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1722 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1724 lockdep_assert_held(&mvm->mutex);
1725 return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr,
1729 int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1733 lockdep_assert_held(&mvm->mutex);
1735 ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id);
1737 IWL_WARN(mvm, "Failed sending remove station\n");
1742 void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm)
1744 iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta);
1747 void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm)
1749 lockdep_assert_held(&mvm->mutex);
1751 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
1755 * Send the add station command for the vif's broadcast station.
1756 * Assumes that the station was already allocated.
1758 * @mvm: the mvm component
1759 * @vif: the interface to which the broadcast station is added
1760 * @bsta: the broadcast station to add.
1762 int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1764 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1765 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
1766 static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
1767 const u8 *baddr = _baddr;
1769 lockdep_assert_held(&mvm->mutex);
1771 if (iwl_mvm_is_dqa_supported(mvm)) {
1772 struct iwl_trans_txq_scd_cfg cfg = {
1773 .fifo = IWL_MVM_TX_FIFO_VO,
1774 .sta_id = mvmvif->bcast_sta.sta_id,
1775 .tid = IWL_MAX_TID_COUNT,
1777 .frame_limit = IWL_FRAME_LIMIT,
1779 unsigned int wdg_timeout =
1780 iwl_mvm_get_wd_timeout(mvm, vif, false, false);
1783 if ((vif->type == NL80211_IFTYPE_AP) &&
1784 (mvmvif->bcast_sta.tfd_queue_msk &
1785 BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE)))
1786 queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE;
1787 else if ((vif->type == NL80211_IFTYPE_P2P_DEVICE) &&
1788 (mvmvif->bcast_sta.tfd_queue_msk &
1789 BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE)))
1790 queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE;
1791 else if (WARN(1, "Missed required TXQ for adding bcast STA\n"))
1794 iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[0], 0, &cfg,
1798 if (vif->type == NL80211_IFTYPE_ADHOC)
1799 baddr = vif->bss_conf.bssid;
1801 if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_STATION_COUNT))
1804 return iwl_mvm_add_int_sta_common(mvm, bsta, baddr,
1805 mvmvif->id, mvmvif->color);
1808 /* Send the FW a request to remove the station from it's internal data
1809 * structures, but DO NOT remove the entry from the local data structures. */
1810 int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1812 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1815 lockdep_assert_held(&mvm->mutex);
1817 ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id);
1819 IWL_WARN(mvm, "Failed sending remove station\n");
1823 int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1825 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1828 lockdep_assert_held(&mvm->mutex);
1830 if (!iwl_mvm_is_dqa_supported(mvm))
1831 qmask = iwl_mvm_mac_get_queues_mask(vif);
1833 if (vif->type == NL80211_IFTYPE_AP) {
1835 * The firmware defines the TFD queue mask to only be relevant
1836 * for *unicast* queues, so the multicast (CAB) queue shouldn't
1839 qmask &= ~BIT(vif->cab_queue);
1841 if (iwl_mvm_is_dqa_supported(mvm))
1842 qmask |= BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE);
1843 } else if (iwl_mvm_is_dqa_supported(mvm) &&
1844 vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1845 qmask |= BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE);
1848 return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask,
1849 ieee80211_vif_type_p2p(vif));
1852 /* Allocate a new station entry for the broadcast station to the given vif,
1853 * and send it to the FW.
1854 * Note that each P2P mac should have its own broadcast station.
1856 * @mvm: the mvm component
1857 * @vif: the interface to which the broadcast station is added
1858 * @bsta: the broadcast station to add. */
1859 int iwl_mvm_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1861 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1862 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
1865 lockdep_assert_held(&mvm->mutex);
1867 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1871 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
1874 iwl_mvm_dealloc_int_sta(mvm, bsta);
1879 void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1881 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1883 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
1887 * Send the FW a request to remove the station from it's internal data
1888 * structures, and in addition remove it from the local data structure.
1890 int iwl_mvm_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1894 lockdep_assert_held(&mvm->mutex);
1896 ret = iwl_mvm_send_rm_bcast_sta(mvm, vif);
1898 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1903 #define IWL_MAX_RX_BA_SESSIONS 16
1905 static void iwl_mvm_sync_rxq_del_ba(struct iwl_mvm *mvm, u8 baid)
1907 struct iwl_mvm_delba_notif notif = {
1908 .metadata.type = IWL_MVM_RXQ_NOTIF_DEL_BA,
1912 iwl_mvm_sync_rx_queues_internal(mvm, (void *)¬if, sizeof(notif));
1915 static void iwl_mvm_free_reorder(struct iwl_mvm *mvm,
1916 struct iwl_mvm_baid_data *data)
1920 iwl_mvm_sync_rxq_del_ba(mvm, data->baid);
1922 for (i = 0; i < mvm->trans->num_rx_queues; i++) {
1924 struct iwl_mvm_reorder_buffer *reorder_buf =
1925 &data->reorder_buf[i];
1927 spin_lock_bh(&reorder_buf->lock);
1928 if (likely(!reorder_buf->num_stored)) {
1929 spin_unlock_bh(&reorder_buf->lock);
1934 * This shouldn't happen in regular DELBA since the internal
1935 * delBA notification should trigger a release of all frames in
1936 * the reorder buffer.
1940 for (j = 0; j < reorder_buf->buf_size; j++)
1941 __skb_queue_purge(&reorder_buf->entries[j]);
1943 * Prevent timer re-arm. This prevents a very far fetched case
1944 * where we timed out on the notification. There may be prior
1945 * RX frames pending in the RX queue before the notification
1946 * that might get processed between now and the actual deletion
1947 * and we would re-arm the timer although we are deleting the
1950 reorder_buf->removed = true;
1951 spin_unlock_bh(&reorder_buf->lock);
1952 del_timer_sync(&reorder_buf->reorder_timer);
1956 static void iwl_mvm_init_reorder_buffer(struct iwl_mvm *mvm,
1958 struct iwl_mvm_baid_data *data,
1959 u16 ssn, u8 buf_size)
1963 for (i = 0; i < mvm->trans->num_rx_queues; i++) {
1964 struct iwl_mvm_reorder_buffer *reorder_buf =
1965 &data->reorder_buf[i];
1968 reorder_buf->num_stored = 0;
1969 reorder_buf->head_sn = ssn;
1970 reorder_buf->buf_size = buf_size;
1971 /* rx reorder timer */
1972 reorder_buf->reorder_timer.function =
1973 iwl_mvm_reorder_timer_expired;
1974 reorder_buf->reorder_timer.data = (unsigned long)reorder_buf;
1975 init_timer(&reorder_buf->reorder_timer);
1976 spin_lock_init(&reorder_buf->lock);
1977 reorder_buf->mvm = mvm;
1978 reorder_buf->queue = i;
1979 reorder_buf->sta_id = sta_id;
1980 for (j = 0; j < reorder_buf->buf_size; j++)
1981 __skb_queue_head_init(&reorder_buf->entries[j]);
1985 int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
1986 int tid, u16 ssn, bool start, u8 buf_size, u16 timeout)
1988 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1989 struct iwl_mvm_add_sta_cmd cmd = {};
1990 struct iwl_mvm_baid_data *baid_data = NULL;
1994 lockdep_assert_held(&mvm->mutex);
1996 if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) {
1997 IWL_WARN(mvm, "Not enough RX BA SESSIONS\n");
2001 if (iwl_mvm_has_new_rx_api(mvm) && start) {
2003 * Allocate here so if allocation fails we can bail out early
2004 * before starting the BA session in the firmware
2006 baid_data = kzalloc(sizeof(*baid_data) +
2007 mvm->trans->num_rx_queues *
2008 sizeof(baid_data->reorder_buf[0]),
2014 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
2015 cmd.sta_id = mvm_sta->sta_id;
2016 cmd.add_modify = STA_MODE_MODIFY;
2018 cmd.add_immediate_ba_tid = (u8) tid;
2019 cmd.add_immediate_ba_ssn = cpu_to_le16(ssn);
2020 cmd.rx_ba_window = cpu_to_le16((u16)buf_size);
2022 cmd.remove_immediate_ba_tid = (u8) tid;
2024 cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID :
2025 STA_MODIFY_REMOVE_BA_TID;
2027 status = ADD_STA_SUCCESS;
2028 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
2029 iwl_mvm_add_sta_cmd_size(mvm),
2034 switch (status & IWL_ADD_STA_STATUS_MASK) {
2035 case ADD_STA_SUCCESS:
2036 IWL_DEBUG_HT(mvm, "RX BA Session %sed in fw\n",
2037 start ? "start" : "stopp");
2039 case ADD_STA_IMMEDIATE_BA_FAILURE:
2040 IWL_WARN(mvm, "RX BA Session refused by fw\n");
2045 IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n",
2046 start ? "start" : "stopp", status);
2056 mvm->rx_ba_sessions++;
2058 if (!iwl_mvm_has_new_rx_api(mvm))
2061 if (WARN_ON(!(status & IWL_ADD_STA_BAID_VALID_MASK))) {
2065 baid = (u8)((status & IWL_ADD_STA_BAID_MASK) >>
2066 IWL_ADD_STA_BAID_SHIFT);
2067 baid_data->baid = baid;
2068 baid_data->timeout = timeout;
2069 baid_data->last_rx = jiffies;
2070 setup_timer(&baid_data->session_timer,
2071 iwl_mvm_rx_agg_session_expired,
2072 (unsigned long)&mvm->baid_map[baid]);
2073 baid_data->mvm = mvm;
2074 baid_data->tid = tid;
2075 baid_data->sta_id = mvm_sta->sta_id;
2077 mvm_sta->tid_to_baid[tid] = baid;
2079 mod_timer(&baid_data->session_timer,
2080 TU_TO_EXP_TIME(timeout * 2));
2082 iwl_mvm_init_reorder_buffer(mvm, mvm_sta->sta_id,
2083 baid_data, ssn, buf_size);
2085 * protect the BA data with RCU to cover a case where our
2086 * internal RX sync mechanism will timeout (not that it's
2087 * supposed to happen) and we will free the session data while
2088 * RX is being processed in parallel
2090 IWL_DEBUG_HT(mvm, "Sta %d(%d) is assigned to BAID %d\n",
2091 mvm_sta->sta_id, tid, baid);
2092 WARN_ON(rcu_access_pointer(mvm->baid_map[baid]));
2093 rcu_assign_pointer(mvm->baid_map[baid], baid_data);
2095 u8 baid = mvm_sta->tid_to_baid[tid];
2097 if (mvm->rx_ba_sessions > 0)
2098 /* check that restart flow didn't zero the counter */
2099 mvm->rx_ba_sessions--;
2100 if (!iwl_mvm_has_new_rx_api(mvm))
2103 if (WARN_ON(baid == IWL_RX_REORDER_DATA_INVALID_BAID))
2106 baid_data = rcu_access_pointer(mvm->baid_map[baid]);
2107 if (WARN_ON(!baid_data))
2110 /* synchronize all rx queues so we can safely delete */
2111 iwl_mvm_free_reorder(mvm, baid_data);
2112 del_timer_sync(&baid_data->session_timer);
2113 RCU_INIT_POINTER(mvm->baid_map[baid], NULL);
2114 kfree_rcu(baid_data, rcu_head);
2115 IWL_DEBUG_HT(mvm, "BAID %d is free\n", baid);
2124 int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
2125 int tid, u8 queue, bool start)
2127 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2128 struct iwl_mvm_add_sta_cmd cmd = {};
2132 lockdep_assert_held(&mvm->mutex);
2135 mvm_sta->tfd_queue_msk |= BIT(queue);
2136 mvm_sta->tid_disable_agg &= ~BIT(tid);
2138 /* In DQA-mode the queue isn't removed on agg termination */
2139 if (!iwl_mvm_is_dqa_supported(mvm))
2140 mvm_sta->tfd_queue_msk &= ~BIT(queue);
2141 mvm_sta->tid_disable_agg |= BIT(tid);
2144 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
2145 cmd.sta_id = mvm_sta->sta_id;
2146 cmd.add_modify = STA_MODE_MODIFY;
2147 cmd.modify_mask = STA_MODIFY_QUEUES | STA_MODIFY_TID_DISABLE_TX;
2148 cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk);
2149 cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg);
2151 status = ADD_STA_SUCCESS;
2152 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
2153 iwl_mvm_add_sta_cmd_size(mvm),
2158 switch (status & IWL_ADD_STA_STATUS_MASK) {
2159 case ADD_STA_SUCCESS:
2163 IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n",
2164 start ? "start" : "stopp", status);
2171 const u8 tid_to_mac80211_ac[] = {
2180 IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */
2183 static const u8 tid_to_ucode_ac[] = {
2194 int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2195 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
2197 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2198 struct iwl_mvm_tid_data *tid_data;
2202 if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
2205 if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) {
2206 IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n",
2207 mvmsta->tid_data[tid].state);
2211 lockdep_assert_held(&mvm->mutex);
2213 spin_lock_bh(&mvmsta->lock);
2215 /* possible race condition - we entered D0i3 while starting agg */
2216 if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) {
2217 spin_unlock_bh(&mvmsta->lock);
2218 IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n");
2222 spin_lock(&mvm->queue_info_lock);
2225 * Note the possible cases:
2226 * 1. In DQA mode with an enabled TXQ - TXQ needs to become agg'ed
2227 * 2. Non-DQA mode: the TXQ hasn't yet been enabled, so find a free
2228 * one and mark it as reserved
2229 * 3. In DQA mode, but no traffic yet on this TID: same treatment as in
2230 * non-DQA mode, since the TXQ hasn't yet been allocated
2232 txq_id = mvmsta->tid_data[tid].txq_id;
2233 if (iwl_mvm_is_dqa_supported(mvm) &&
2234 unlikely(mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_SHARED)) {
2236 IWL_DEBUG_TX_QUEUES(mvm,
2237 "Can't start tid %d agg on shared queue!\n",
2240 } else if (!iwl_mvm_is_dqa_supported(mvm) ||
2241 mvm->queue_info[txq_id].status != IWL_MVM_QUEUE_READY) {
2242 txq_id = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
2243 mvm->first_agg_queue,
2244 mvm->last_agg_queue);
2247 IWL_ERR(mvm, "Failed to allocate agg queue\n");
2251 /* TXQ hasn't yet been enabled, so mark it only as reserved */
2252 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_RESERVED;
2255 spin_unlock(&mvm->queue_info_lock);
2257 IWL_DEBUG_TX_QUEUES(mvm,
2258 "AGG for tid %d will be on queue #%d\n",
2261 tid_data = &mvmsta->tid_data[tid];
2262 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
2263 tid_data->txq_id = txq_id;
2264 *ssn = tid_data->ssn;
2266 IWL_DEBUG_TX_QUEUES(mvm,
2267 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
2268 mvmsta->sta_id, tid, txq_id, tid_data->ssn,
2269 tid_data->next_reclaimed);
2271 if (tid_data->ssn == tid_data->next_reclaimed) {
2272 tid_data->state = IWL_AGG_STARTING;
2273 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2275 tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA;
2282 spin_unlock(&mvm->queue_info_lock);
2284 spin_unlock_bh(&mvmsta->lock);
2289 int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2290 struct ieee80211_sta *sta, u16 tid, u8 buf_size,
2293 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2294 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2295 unsigned int wdg_timeout =
2296 iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false);
2298 bool alloc_queue = true;
2299 enum iwl_mvm_queue_status queue_status;
2302 struct iwl_trans_txq_scd_cfg cfg = {
2303 .sta_id = mvmsta->sta_id,
2305 .frame_limit = buf_size,
2309 BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE)
2310 != IWL_MAX_TID_COUNT);
2312 buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
2314 spin_lock_bh(&mvmsta->lock);
2315 ssn = tid_data->ssn;
2316 queue = tid_data->txq_id;
2317 tid_data->state = IWL_AGG_ON;
2318 mvmsta->agg_tids |= BIT(tid);
2319 tid_data->ssn = 0xffff;
2320 tid_data->amsdu_in_ampdu_allowed = amsdu;
2321 spin_unlock_bh(&mvmsta->lock);
2323 cfg.fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
2325 spin_lock_bh(&mvm->queue_info_lock);
2326 queue_status = mvm->queue_info[queue].status;
2327 spin_unlock_bh(&mvm->queue_info_lock);
2329 /* In DQA mode, the existing queue might need to be reconfigured */
2330 if (iwl_mvm_is_dqa_supported(mvm)) {
2331 /* Maybe there is no need to even alloc a queue... */
2332 if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_READY)
2333 alloc_queue = false;
2336 * Only reconfig the SCD for the queue if the window size has
2337 * changed from current (become smaller)
2339 if (!alloc_queue && buf_size < mvmsta->max_agg_bufsize) {
2341 * If reconfiguring an existing queue, it first must be
2344 ret = iwl_trans_wait_tx_queue_empty(mvm->trans,
2348 "Error draining queue before reconfig\n");
2352 ret = iwl_mvm_reconfig_scd(mvm, queue, cfg.fifo,
2353 mvmsta->sta_id, tid,
2357 "Error reconfiguring TXQ #%d\n", queue);
2364 iwl_mvm_enable_txq(mvm, queue,
2365 vif->hw_queue[tid_to_mac80211_ac[tid]], ssn,
2368 /* Send ADD_STA command to enable aggs only if the queue isn't shared */
2369 if (queue_status != IWL_MVM_QUEUE_SHARED) {
2370 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
2375 /* No need to mark as reserved */
2376 spin_lock_bh(&mvm->queue_info_lock);
2377 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
2378 spin_unlock_bh(&mvm->queue_info_lock);
2381 * Even though in theory the peer could have different
2382 * aggregation reorder buffer sizes for different sessions,
2383 * our ucode doesn't allow for that and has a global limit
2384 * for each station. Therefore, use the minimum of all the
2385 * aggregation sessions and our default value.
2387 mvmsta->max_agg_bufsize =
2388 min(mvmsta->max_agg_bufsize, buf_size);
2389 mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize;
2391 IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n",
2394 return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false);
2397 int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2398 struct ieee80211_sta *sta, u16 tid)
2400 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2401 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2406 * If mac80211 is cleaning its state, then say that we finished since
2407 * our state has been cleared anyway.
2409 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2410 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2414 spin_lock_bh(&mvmsta->lock);
2416 txq_id = tid_data->txq_id;
2418 IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n",
2419 mvmsta->sta_id, tid, txq_id, tid_data->state);
2421 mvmsta->agg_tids &= ~BIT(tid);
2423 spin_lock_bh(&mvm->queue_info_lock);
2425 * The TXQ is marked as reserved only if no traffic came through yet
2426 * This means no traffic has been sent on this TID (agg'd or not), so
2427 * we no longer have use for the queue. Since it hasn't even been
2428 * allocated through iwl_mvm_enable_txq, so we can just mark it back as
2431 if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED)
2432 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE;
2434 spin_unlock_bh(&mvm->queue_info_lock);
2436 switch (tid_data->state) {
2438 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
2440 IWL_DEBUG_TX_QUEUES(mvm,
2441 "ssn = %d, next_recl = %d\n",
2442 tid_data->ssn, tid_data->next_reclaimed);
2444 /* There are still packets for this RA / TID in the HW */
2445 if (tid_data->ssn != tid_data->next_reclaimed) {
2446 tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA;
2451 tid_data->ssn = 0xffff;
2452 tid_data->state = IWL_AGG_OFF;
2453 spin_unlock_bh(&mvmsta->lock);
2455 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2457 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
2459 if (!iwl_mvm_is_dqa_supported(mvm)) {
2460 int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]];
2462 iwl_mvm_disable_txq(mvm, txq_id, mac_queue, tid, 0);
2465 case IWL_AGG_STARTING:
2466 case IWL_EMPTYING_HW_QUEUE_ADDBA:
2468 * The agg session has been stopped before it was set up. This
2469 * can happen when the AddBA timer times out for example.
2472 /* No barriers since we are under mutex */
2473 lockdep_assert_held(&mvm->mutex);
2475 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2476 tid_data->state = IWL_AGG_OFF;
2481 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
2482 mvmsta->sta_id, tid, tid_data->state);
2484 "\ttid_data->txq_id = %d\n", tid_data->txq_id);
2488 spin_unlock_bh(&mvmsta->lock);
2493 int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2494 struct ieee80211_sta *sta, u16 tid)
2496 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2497 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2499 enum iwl_mvm_agg_state old_state;
2502 * First set the agg state to OFF to avoid calling
2503 * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
2505 spin_lock_bh(&mvmsta->lock);
2506 txq_id = tid_data->txq_id;
2507 IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n",
2508 mvmsta->sta_id, tid, txq_id, tid_data->state);
2509 old_state = tid_data->state;
2510 tid_data->state = IWL_AGG_OFF;
2511 mvmsta->agg_tids &= ~BIT(tid);
2512 spin_unlock_bh(&mvmsta->lock);
2514 spin_lock_bh(&mvm->queue_info_lock);
2516 * The TXQ is marked as reserved only if no traffic came through yet
2517 * This means no traffic has been sent on this TID (agg'd or not), so
2518 * we no longer have use for the queue. Since it hasn't even been
2519 * allocated through iwl_mvm_enable_txq, so we can just mark it back as
2522 if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED)
2523 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE;
2524 spin_unlock_bh(&mvm->queue_info_lock);
2526 if (old_state >= IWL_AGG_ON) {
2527 iwl_mvm_drain_sta(mvm, mvmsta, true);
2528 if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0))
2529 IWL_ERR(mvm, "Couldn't flush the AGG queue\n");
2530 iwl_trans_wait_tx_queue_empty(mvm->trans,
2531 mvmsta->tfd_queue_msk);
2532 iwl_mvm_drain_sta(mvm, mvmsta, false);
2534 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
2536 if (!iwl_mvm_is_dqa_supported(mvm)) {
2537 int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]];
2539 iwl_mvm_disable_txq(mvm, tid_data->txq_id, mac_queue,
2547 static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm)
2549 int i, max = -1, max_offs = -1;
2551 lockdep_assert_held(&mvm->mutex);
2553 /* Pick the unused key offset with the highest 'deleted'
2554 * counter. Every time a key is deleted, all the counters
2555 * are incremented and the one that was just deleted is
2556 * reset to zero. Thus, the highest counter is the one
2557 * that was deleted longest ago. Pick that one.
2559 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
2560 if (test_bit(i, mvm->fw_key_table))
2562 if (mvm->fw_key_deleted[i] > max) {
2563 max = mvm->fw_key_deleted[i];
2569 return STA_KEY_IDX_INVALID;
2574 static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm,
2575 struct ieee80211_vif *vif,
2576 struct ieee80211_sta *sta)
2578 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2581 return iwl_mvm_sta_from_mac80211(sta);
2584 * The device expects GTKs for station interfaces to be
2585 * installed as GTKs for the AP station. If we have no
2586 * station ID, then use AP's station ID.
2588 if (vif->type == NL80211_IFTYPE_STATION &&
2589 mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
2590 u8 sta_id = mvmvif->ap_sta_id;
2592 sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id],
2593 lockdep_is_held(&mvm->mutex));
2596 * It is possible that the 'sta' parameter is NULL,
2597 * for example when a GTK is removed - the sta_id will then
2598 * be the AP ID, and no station was passed by mac80211.
2600 if (IS_ERR_OR_NULL(sta))
2603 return iwl_mvm_sta_from_mac80211(sta);
2609 static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm,
2610 struct iwl_mvm_sta *mvm_sta,
2611 struct ieee80211_key_conf *keyconf, bool mcast,
2612 u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags,
2615 struct iwl_mvm_add_sta_key_cmd cmd = {};
2621 u8 sta_id = mvm_sta->sta_id;
2623 keyidx = (keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
2624 STA_KEY_FLG_KEYID_MSK;
2625 key_flags = cpu_to_le16(keyidx);
2626 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP);
2628 switch (keyconf->cipher) {
2629 case WLAN_CIPHER_SUITE_TKIP:
2630 key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP);
2631 cmd.tkip_rx_tsc_byte2 = tkip_iv32;
2632 for (i = 0; i < 5; i++)
2633 cmd.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]);
2634 memcpy(cmd.key, keyconf->key, keyconf->keylen);
2636 case WLAN_CIPHER_SUITE_CCMP:
2637 key_flags |= cpu_to_le16(STA_KEY_FLG_CCM);
2638 memcpy(cmd.key, keyconf->key, keyconf->keylen);
2640 case WLAN_CIPHER_SUITE_WEP104:
2641 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES);
2643 case WLAN_CIPHER_SUITE_WEP40:
2644 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP);
2645 memcpy(cmd.key + 3, keyconf->key, keyconf->keylen);
2647 case WLAN_CIPHER_SUITE_GCMP_256:
2648 key_flags |= cpu_to_le16(STA_KEY_FLG_KEY_32BYTES);
2650 case WLAN_CIPHER_SUITE_GCMP:
2651 key_flags |= cpu_to_le16(STA_KEY_FLG_GCMP);
2652 memcpy(cmd.key, keyconf->key, keyconf->keylen);
2655 key_flags |= cpu_to_le16(STA_KEY_FLG_EXT);
2656 memcpy(cmd.key, keyconf->key, keyconf->keylen);
2660 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
2662 cmd.key_offset = key_offset;
2663 cmd.key_flags = key_flags;
2664 cmd.sta_id = sta_id;
2666 status = ADD_STA_SUCCESS;
2667 if (cmd_flags & CMD_ASYNC)
2668 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC,
2671 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd),
2675 case ADD_STA_SUCCESS:
2676 IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n");
2680 IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n");
2687 static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm,
2688 struct ieee80211_key_conf *keyconf,
2689 u8 sta_id, bool remove_key)
2691 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {};
2693 /* verify the key details match the required command's expectations */
2694 if (WARN_ON((keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) ||
2695 (keyconf->keyidx != 4 && keyconf->keyidx != 5) ||
2696 (keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC &&
2697 keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_128 &&
2698 keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_256)))
2701 if (WARN_ON(!iwl_mvm_has_new_rx_api(mvm) &&
2702 keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC))
2705 igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx);
2706 igtk_cmd.sta_id = cpu_to_le32(sta_id);
2709 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID);
2711 struct ieee80211_key_seq seq;
2714 switch (keyconf->cipher) {
2715 case WLAN_CIPHER_SUITE_AES_CMAC:
2716 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_CCM);
2718 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2719 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2720 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_GCMP);
2726 memcpy(igtk_cmd.igtk, keyconf->key, keyconf->keylen);
2727 if (keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
2728 igtk_cmd.ctrl_flags |=
2729 cpu_to_le32(STA_KEY_FLG_KEY_32BYTES);
2730 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
2731 pn = seq.aes_cmac.pn;
2732 igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) |
2733 ((u64) pn[4] << 8) |
2734 ((u64) pn[3] << 16) |
2735 ((u64) pn[2] << 24) |
2736 ((u64) pn[1] << 32) |
2737 ((u64) pn[0] << 40));
2740 IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n",
2741 remove_key ? "removing" : "installing",
2744 if (!iwl_mvm_has_new_rx_api(mvm)) {
2745 struct iwl_mvm_mgmt_mcast_key_cmd_v1 igtk_cmd_v1 = {
2746 .ctrl_flags = igtk_cmd.ctrl_flags,
2747 .key_id = igtk_cmd.key_id,
2748 .sta_id = igtk_cmd.sta_id,
2749 .receive_seq_cnt = igtk_cmd.receive_seq_cnt
2752 memcpy(igtk_cmd_v1.igtk, igtk_cmd.igtk,
2753 ARRAY_SIZE(igtk_cmd_v1.igtk));
2754 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
2755 sizeof(igtk_cmd_v1), &igtk_cmd_v1);
2757 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
2758 sizeof(igtk_cmd), &igtk_cmd);
2762 static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm,
2763 struct ieee80211_vif *vif,
2764 struct ieee80211_sta *sta)
2766 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2771 if (vif->type == NL80211_IFTYPE_STATION &&
2772 mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
2773 u8 sta_id = mvmvif->ap_sta_id;
2774 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
2775 lockdep_is_held(&mvm->mutex));
2783 static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
2784 struct ieee80211_vif *vif,
2785 struct ieee80211_sta *sta,
2786 struct ieee80211_key_conf *keyconf,
2790 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2793 struct ieee80211_key_seq seq;
2796 switch (keyconf->cipher) {
2797 case WLAN_CIPHER_SUITE_TKIP:
2798 addr = iwl_mvm_get_mac_addr(mvm, vif, sta);
2799 /* get phase 1 key from mac80211 */
2800 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
2801 ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k);
2802 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
2803 seq.tkip.iv32, p1k, 0, key_offset);
2805 case WLAN_CIPHER_SUITE_CCMP:
2806 case WLAN_CIPHER_SUITE_WEP40:
2807 case WLAN_CIPHER_SUITE_WEP104:
2808 case WLAN_CIPHER_SUITE_GCMP:
2809 case WLAN_CIPHER_SUITE_GCMP_256:
2810 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
2811 0, NULL, 0, key_offset);
2814 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
2815 0, NULL, 0, key_offset);
2821 static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id,
2822 struct ieee80211_key_conf *keyconf,
2825 struct iwl_mvm_add_sta_key_cmd cmd = {};
2830 key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
2831 STA_KEY_FLG_KEYID_MSK);
2832 key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP);
2833 key_flags |= cpu_to_le16(STA_KEY_NOT_VALID);
2836 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
2838 cmd.key_flags = key_flags;
2839 cmd.key_offset = keyconf->hw_key_idx;
2840 cmd.sta_id = sta_id;
2842 status = ADD_STA_SUCCESS;
2843 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd),
2847 case ADD_STA_SUCCESS:
2848 IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n");
2852 IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n");
2859 int iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
2860 struct ieee80211_vif *vif,
2861 struct ieee80211_sta *sta,
2862 struct ieee80211_key_conf *keyconf,
2865 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
2866 struct iwl_mvm_sta *mvm_sta;
2869 static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0};
2871 lockdep_assert_held(&mvm->mutex);
2873 /* Get the station id from the mvm local station table */
2874 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
2876 IWL_ERR(mvm, "Failed to find station\n");
2879 sta_id = mvm_sta->sta_id;
2881 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
2882 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
2883 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) {
2884 ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false);
2889 * It is possible that the 'sta' parameter is NULL, and thus
2890 * there is a need to retrieve the sta from the local station table.
2893 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
2894 lockdep_is_held(&mvm->mutex));
2895 if (IS_ERR_OR_NULL(sta)) {
2896 IWL_ERR(mvm, "Invalid station id\n");
2901 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif))
2904 /* If the key_offset is not pre-assigned, we need to find a
2905 * new offset to use. In normal cases, the offset is not
2906 * pre-assigned, but during HW_RESTART we want to reuse the
2907 * same indices, so we pass them when this function is called.
2909 * In D3 entry, we need to hardcoded the indices (because the
2910 * firmware hardcodes the PTK offset to 0). In this case, we
2911 * need to make sure we don't overwrite the hw_key_idx in the
2912 * keyconf structure, because otherwise we cannot configure
2913 * the original ones back when resuming.
2915 if (key_offset == STA_KEY_IDX_INVALID) {
2916 key_offset = iwl_mvm_set_fw_key_idx(mvm);
2917 if (key_offset == STA_KEY_IDX_INVALID)
2919 keyconf->hw_key_idx = key_offset;
2922 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, key_offset, mcast);
2927 * For WEP, the same key is used for multicast and unicast. Upload it
2928 * again, using the same key offset, and now pointing the other one
2929 * to the same key slot (offset).
2930 * If this fails, remove the original as well.
2932 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2933 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) {
2934 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf,
2935 key_offset, !mcast);
2937 __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
2942 __set_bit(key_offset, mvm->fw_key_table);
2945 IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
2946 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
2947 sta ? sta->addr : zero_addr, ret);
2951 int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm,
2952 struct ieee80211_vif *vif,
2953 struct ieee80211_sta *sta,
2954 struct ieee80211_key_conf *keyconf)
2956 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
2957 struct iwl_mvm_sta *mvm_sta;
2958 u8 sta_id = IWL_MVM_STATION_COUNT;
2961 lockdep_assert_held(&mvm->mutex);
2963 /* Get the station from the mvm local station table */
2964 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
2966 IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n",
2967 keyconf->keyidx, sta_id);
2969 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
2970 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
2971 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
2972 return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true);
2974 if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) {
2975 IWL_ERR(mvm, "offset %d not used in fw key table.\n",
2976 keyconf->hw_key_idx);
2980 /* track which key was deleted last */
2981 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
2982 if (mvm->fw_key_deleted[i] < U8_MAX)
2983 mvm->fw_key_deleted[i]++;
2985 mvm->fw_key_deleted[keyconf->hw_key_idx] = 0;
2988 IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n");
2992 sta_id = mvm_sta->sta_id;
2994 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
2998 /* delete WEP key twice to get rid of (now useless) offset */
2999 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3000 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104)
3001 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast);
3006 void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm,
3007 struct ieee80211_vif *vif,
3008 struct ieee80211_key_conf *keyconf,
3009 struct ieee80211_sta *sta, u32 iv32,
3012 struct iwl_mvm_sta *mvm_sta;
3013 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
3017 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
3018 if (WARN_ON_ONCE(!mvm_sta))
3020 iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
3021 iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx);
3027 void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm,
3028 struct ieee80211_sta *sta)
3030 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3031 struct iwl_mvm_add_sta_cmd cmd = {
3032 .add_modify = STA_MODE_MODIFY,
3033 .sta_id = mvmsta->sta_id,
3034 .station_flags_msk = cpu_to_le32(STA_FLG_PS),
3035 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
3039 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
3040 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
3042 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3045 void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm,
3046 struct ieee80211_sta *sta,
3047 enum ieee80211_frame_release_type reason,
3048 u16 cnt, u16 tids, bool more_data,
3051 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3052 struct iwl_mvm_add_sta_cmd cmd = {
3053 .add_modify = STA_MODE_MODIFY,
3054 .sta_id = mvmsta->sta_id,
3055 .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT,
3056 .sleep_tx_count = cpu_to_le16(cnt),
3057 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
3060 unsigned long _tids = tids;
3062 /* convert TIDs to ACs - we don't support TSPEC so that's OK
3063 * Note that this field is reserved and unused by firmware not
3064 * supporting GO uAPSD, so it's safe to always do this.
3066 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT)
3067 cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]);
3069 /* If we're releasing frames from aggregation queues then check if the
3070 * all queues combined that we're releasing frames from have
3071 * - more frames than the service period, in which case more_data
3073 * - fewer than 'cnt' frames, in which case we need to adjust the
3074 * firmware command (but do that unconditionally)
3077 int remaining = cnt;
3080 spin_lock_bh(&mvmsta->lock);
3081 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) {
3082 struct iwl_mvm_tid_data *tid_data;
3085 tid_data = &mvmsta->tid_data[tid];
3086 if (WARN(tid_data->state != IWL_AGG_ON &&
3087 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA,
3088 "TID %d state is %d\n",
3089 tid, tid_data->state)) {
3090 spin_unlock_bh(&mvmsta->lock);
3091 ieee80211_sta_eosp(sta);
3095 n_queued = iwl_mvm_tid_queued(tid_data);
3096 if (n_queued > remaining) {
3101 remaining -= n_queued;
3103 sleep_tx_count = cnt - remaining;
3104 if (reason == IEEE80211_FRAME_RELEASE_UAPSD)
3105 mvmsta->sleep_tx_count = sleep_tx_count;
3106 spin_unlock_bh(&mvmsta->lock);
3108 cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count);
3109 if (WARN_ON(cnt - remaining == 0)) {
3110 ieee80211_sta_eosp(sta);
3115 /* Note: this is ignored by firmware not supporting GO uAPSD */
3117 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA);
3119 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) {
3120 mvmsta->next_status_eosp = true;
3121 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL);
3123 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD);
3126 /* block the Tx queues until the FW updated the sleep Tx count */
3127 iwl_trans_block_txq_ptrs(mvm->trans, true);
3129 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA,
3130 CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK,
3131 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
3133 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3136 void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm,
3137 struct iwl_rx_cmd_buffer *rxb)
3139 struct iwl_rx_packet *pkt = rxb_addr(rxb);
3140 struct iwl_mvm_eosp_notification *notif = (void *)pkt->data;
3141 struct ieee80211_sta *sta;
3142 u32 sta_id = le32_to_cpu(notif->sta_id);
3144 if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT))
3148 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
3149 if (!IS_ERR_OR_NULL(sta))
3150 ieee80211_sta_eosp(sta);
3154 void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm,
3155 struct iwl_mvm_sta *mvmsta, bool disable)
3157 struct iwl_mvm_add_sta_cmd cmd = {
3158 .add_modify = STA_MODE_MODIFY,
3159 .sta_id = mvmsta->sta_id,
3160 .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0,
3161 .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX),
3162 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
3166 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
3167 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
3169 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3172 void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm,
3173 struct ieee80211_sta *sta,
3176 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3178 spin_lock_bh(&mvm_sta->lock);
3180 if (mvm_sta->disable_tx == disable) {
3181 spin_unlock_bh(&mvm_sta->lock);
3185 mvm_sta->disable_tx = disable;
3188 * Tell mac80211 to start/stop queuing tx for this station,
3189 * but don't stop queuing if there are still pending frames
3192 if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id]))
3193 ieee80211_sta_block_awake(mvm->hw, sta, disable);
3195 iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable);
3197 spin_unlock_bh(&mvm_sta->lock);
3200 void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm,
3201 struct iwl_mvm_vif *mvmvif,
3204 struct ieee80211_sta *sta;
3205 struct iwl_mvm_sta *mvm_sta;
3208 lockdep_assert_held(&mvm->mutex);
3210 /* Block/unblock all the stations of the given mvmvif */
3211 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
3212 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3213 lockdep_is_held(&mvm->mutex));
3214 if (IS_ERR_OR_NULL(sta))
3217 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3218 if (mvm_sta->mac_id_n_color !=
3219 FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color))
3222 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable);
3226 void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
3228 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3229 struct iwl_mvm_sta *mvmsta;
3233 mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id);
3235 if (!WARN_ON(!mvmsta))
3236 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true);