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 (or allocated) */
1168 mvm->queue_info[mvm_sta->reserved_queue].status =
1169 IWL_MVM_QUEUE_RESERVED;
1171 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
1172 struct iwl_mvm_tid_data *tid_data = &mvm_sta->tid_data[i];
1173 int txq_id = tid_data->txq_id;
1177 if (txq_id == IEEE80211_INVAL_HW_QUEUE)
1180 skb_queue_head_init(&tid_data->deferred_tx_frames);
1182 ac = tid_to_mac80211_ac[i];
1183 mac_queue = mvm_sta->vif->hw_queue[ac];
1186 cfg.fifo = iwl_mvm_ac_to_tx_fifo[ac];
1187 cfg.aggregate = (txq_id >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
1188 txq_id == IWL_MVM_DQA_BSS_CLIENT_QUEUE);
1190 IWL_DEBUG_TX_QUEUES(mvm,
1191 "Re-mapping sta %d tid %d to queue %d\n",
1192 mvm_sta->sta_id, i, txq_id);
1194 iwl_mvm_enable_txq(mvm, txq_id, mac_queue,
1195 IEEE80211_SEQ_TO_SN(tid_data->seq_number),
1198 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_READY;
1201 atomic_set(&mvm->pending_frames[mvm_sta->sta_id], 0);
1204 int iwl_mvm_add_sta(struct iwl_mvm *mvm,
1205 struct ieee80211_vif *vif,
1206 struct ieee80211_sta *sta)
1208 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1209 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1210 struct iwl_mvm_rxq_dup_data *dup_data;
1213 lockdep_assert_held(&mvm->mutex);
1215 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1216 sta_id = iwl_mvm_find_free_sta_id(mvm,
1217 ieee80211_vif_type_p2p(vif));
1219 sta_id = mvm_sta->sta_id;
1221 if (sta_id == IWL_MVM_STATION_COUNT)
1224 spin_lock_init(&mvm_sta->lock);
1226 /* In DQA mode, if this is a HW restart, re-alloc existing queues */
1227 if (iwl_mvm_is_dqa_supported(mvm) &&
1228 test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1229 iwl_mvm_realloc_queues_after_restart(mvm, mvm_sta);
1233 mvm_sta->sta_id = sta_id;
1234 mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id,
1237 mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
1238 mvm_sta->tx_protection = 0;
1239 mvm_sta->tt_tx_protection = false;
1241 /* HW restart, don't assume the memory has been zeroed */
1242 atomic_set(&mvm->pending_frames[sta_id], 0);
1243 mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */
1244 mvm_sta->tfd_queue_msk = 0;
1247 * Allocate new queues for a TDLS station, unless we're in DQA mode,
1248 * and then they'll be allocated dynamically
1250 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) {
1251 ret = iwl_mvm_tdls_sta_init(mvm, sta);
1254 } else if (!iwl_mvm_is_dqa_supported(mvm)) {
1255 for (i = 0; i < IEEE80211_NUM_ACS; i++)
1256 if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE)
1257 mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]);
1260 /* for HW restart - reset everything but the sequence number */
1261 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
1262 u16 seq = mvm_sta->tid_data[i].seq_number;
1263 memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i]));
1264 mvm_sta->tid_data[i].seq_number = seq;
1266 if (!iwl_mvm_is_dqa_supported(mvm))
1270 * Mark all queues for this STA as unallocated and defer TX
1271 * frames until the queue is allocated
1273 mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE;
1274 skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames);
1276 mvm_sta->deferred_traffic_tid_map = 0;
1277 mvm_sta->agg_tids = 0;
1279 if (iwl_mvm_has_new_rx_api(mvm) &&
1280 !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1281 dup_data = kcalloc(mvm->trans->num_rx_queues,
1286 mvm_sta->dup_data = dup_data;
1289 if (iwl_mvm_is_dqa_supported(mvm)) {
1290 ret = iwl_mvm_reserve_sta_stream(mvm, sta,
1291 ieee80211_vif_type_p2p(vif));
1297 ret = iwl_mvm_sta_send_to_fw(mvm, sta, false, 0);
1301 if (vif->type == NL80211_IFTYPE_STATION) {
1303 WARN_ON(mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT);
1304 mvmvif->ap_sta_id = sta_id;
1306 WARN_ON(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT);
1310 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta);
1315 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls)
1316 iwl_mvm_tdls_sta_deinit(mvm, sta);
1320 int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
1323 struct iwl_mvm_add_sta_cmd cmd = {};
1327 lockdep_assert_held(&mvm->mutex);
1329 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
1330 cmd.sta_id = mvmsta->sta_id;
1331 cmd.add_modify = STA_MODE_MODIFY;
1332 cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0;
1333 cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW);
1335 status = ADD_STA_SUCCESS;
1336 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1337 iwl_mvm_add_sta_cmd_size(mvm),
1342 switch (status & IWL_ADD_STA_STATUS_MASK) {
1343 case ADD_STA_SUCCESS:
1344 IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n",
1349 IWL_ERR(mvm, "Couldn't drain frames for staid %d\n",
1358 * Remove a station from the FW table. Before sending the command to remove
1359 * the station validate that the station is indeed known to the driver (sanity
1362 static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id)
1364 struct ieee80211_sta *sta;
1365 struct iwl_mvm_rm_sta_cmd rm_sta_cmd = {
1370 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1371 lockdep_is_held(&mvm->mutex));
1373 /* Note: internal stations are marked as error values */
1375 IWL_ERR(mvm, "Invalid station id\n");
1379 ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0,
1380 sizeof(rm_sta_cmd), &rm_sta_cmd);
1382 IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id);
1389 void iwl_mvm_sta_drained_wk(struct work_struct *wk)
1391 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk);
1395 * The mutex is needed because of the SYNC cmd, but not only: if the
1396 * work would run concurrently with iwl_mvm_rm_sta, it would run before
1397 * iwl_mvm_rm_sta sets the station as busy, and exit. Then
1398 * iwl_mvm_rm_sta would set the station as busy, and nobody will clean
1401 mutex_lock(&mvm->mutex);
1403 for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) {
1405 struct ieee80211_sta *sta =
1406 rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1407 lockdep_is_held(&mvm->mutex));
1410 * This station is in use or RCU-removed; the latter happens in
1411 * managed mode, where mac80211 removes the station before we
1412 * can remove it from firmware (we can only do that after the
1413 * MAC is marked unassociated), and possibly while the deauth
1414 * frame to disconnect from the AP is still queued. Then, the
1415 * station pointer is -ENOENT when the last skb is reclaimed.
1417 if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT)
1420 if (PTR_ERR(sta) == -EINVAL) {
1421 IWL_ERR(mvm, "Drained sta %d, but it is internal?\n",
1427 IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n",
1432 WARN_ON(PTR_ERR(sta) != -EBUSY);
1433 /* This station was removed and we waited until it got drained,
1434 * we can now proceed and remove it.
1436 ret = iwl_mvm_rm_sta_common(mvm, sta_id);
1439 "Couldn't remove sta %d after it was drained\n",
1443 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
1444 clear_bit(sta_id, mvm->sta_drained);
1446 if (mvm->tfd_drained[sta_id]) {
1447 unsigned long i, msk = mvm->tfd_drained[sta_id];
1449 for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE)
1450 iwl_mvm_disable_txq(mvm, i, i,
1451 IWL_MAX_TID_COUNT, 0);
1453 mvm->tfd_drained[sta_id] = 0;
1454 IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n",
1459 mutex_unlock(&mvm->mutex);
1462 static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm,
1463 struct ieee80211_vif *vif,
1464 struct iwl_mvm_sta *mvm_sta)
1469 lockdep_assert_held(&mvm->mutex);
1471 for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) {
1472 if (mvm_sta->tid_data[i].txq_id == IEEE80211_INVAL_HW_QUEUE)
1475 ac = iwl_mvm_tid_to_ac_queue(i);
1476 iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id,
1477 vif->hw_queue[ac], i, 0);
1478 mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE;
1482 int iwl_mvm_rm_sta(struct iwl_mvm *mvm,
1483 struct ieee80211_vif *vif,
1484 struct ieee80211_sta *sta)
1486 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1487 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1490 lockdep_assert_held(&mvm->mutex);
1492 if (iwl_mvm_has_new_rx_api(mvm))
1493 kfree(mvm_sta->dup_data);
1495 if ((vif->type == NL80211_IFTYPE_STATION &&
1496 mvmvif->ap_sta_id == mvm_sta->sta_id) ||
1497 iwl_mvm_is_dqa_supported(mvm)){
1498 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
1501 /* flush its queues here since we are freeing mvm_sta */
1502 ret = iwl_mvm_flush_tx_path(mvm, mvm_sta->tfd_queue_msk, 0);
1505 ret = iwl_trans_wait_tx_queue_empty(mvm->trans,
1506 mvm_sta->tfd_queue_msk);
1509 ret = iwl_mvm_drain_sta(mvm, mvm_sta, false);
1511 /* If DQA is supported - the queues can be disabled now */
1512 if (iwl_mvm_is_dqa_supported(mvm))
1513 iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta);
1515 /* If there is a TXQ still marked as reserved - free it */
1516 if (iwl_mvm_is_dqa_supported(mvm) &&
1517 mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) {
1518 u8 reserved_txq = mvm_sta->reserved_queue;
1519 enum iwl_mvm_queue_status *status;
1522 * If no traffic has gone through the reserved TXQ - it
1523 * is still marked as IWL_MVM_QUEUE_RESERVED, and
1524 * should be manually marked as free again
1526 spin_lock_bh(&mvm->queue_info_lock);
1527 status = &mvm->queue_info[reserved_txq].status;
1528 if (WARN((*status != IWL_MVM_QUEUE_RESERVED) &&
1529 (*status != IWL_MVM_QUEUE_FREE),
1530 "sta_id %d reserved txq %d status %d",
1531 mvm_sta->sta_id, reserved_txq, *status)) {
1532 spin_unlock_bh(&mvm->queue_info_lock);
1536 *status = IWL_MVM_QUEUE_FREE;
1537 spin_unlock_bh(&mvm->queue_info_lock);
1540 if (vif->type == NL80211_IFTYPE_STATION &&
1541 mvmvif->ap_sta_id == mvm_sta->sta_id) {
1542 /* if associated - we can't remove the AP STA now */
1543 if (vif->bss_conf.assoc)
1546 /* unassoc - go ahead - remove the AP STA now */
1547 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1549 /* clear d0i3_ap_sta_id if no longer relevant */
1550 if (mvm->d0i3_ap_sta_id == mvm_sta->sta_id)
1551 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
1556 * This shouldn't happen - the TDLS channel switch should be canceled
1557 * before the STA is removed.
1559 if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == mvm_sta->sta_id)) {
1560 mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT;
1561 cancel_delayed_work(&mvm->tdls_cs.dwork);
1565 * Make sure that the tx response code sees the station as -EBUSY and
1566 * calls the drain worker.
1568 spin_lock_bh(&mvm_sta->lock);
1570 * There are frames pending on the AC queues for this station.
1571 * We need to wait until all the frames are drained...
1573 if (atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) {
1574 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1576 spin_unlock_bh(&mvm_sta->lock);
1578 /* disable TDLS sta queues on drain complete */
1580 mvm->tfd_drained[mvm_sta->sta_id] =
1581 mvm_sta->tfd_queue_msk;
1582 IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n",
1586 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
1588 spin_unlock_bh(&mvm_sta->lock);
1590 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls)
1591 iwl_mvm_tdls_sta_deinit(mvm, sta);
1593 ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id);
1594 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL);
1600 int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm,
1601 struct ieee80211_vif *vif,
1604 int ret = iwl_mvm_rm_sta_common(mvm, sta_id);
1606 lockdep_assert_held(&mvm->mutex);
1608 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
1612 int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm,
1613 struct iwl_mvm_int_sta *sta,
1614 u32 qmask, enum nl80211_iftype iftype)
1616 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1617 sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype);
1618 if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_STATION_COUNT))
1622 sta->tfd_queue_msk = qmask;
1624 /* put a non-NULL value so iterating over the stations won't stop */
1625 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL));
1629 static void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm,
1630 struct iwl_mvm_int_sta *sta)
1632 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta->sta_id], NULL);
1633 memset(sta, 0, sizeof(struct iwl_mvm_int_sta));
1634 sta->sta_id = IWL_MVM_STATION_COUNT;
1637 static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm,
1638 struct iwl_mvm_int_sta *sta,
1640 u16 mac_id, u16 color)
1642 struct iwl_mvm_add_sta_cmd cmd;
1646 lockdep_assert_held(&mvm->mutex);
1648 memset(&cmd, 0, sizeof(cmd));
1649 cmd.sta_id = sta->sta_id;
1650 cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id,
1653 cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk);
1654 cmd.tid_disable_tx = cpu_to_le16(0xffff);
1657 memcpy(cmd.addr, addr, ETH_ALEN);
1659 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1660 iwl_mvm_add_sta_cmd_size(mvm),
1665 switch (status & IWL_ADD_STA_STATUS_MASK) {
1666 case ADD_STA_SUCCESS:
1667 IWL_DEBUG_INFO(mvm, "Internal station added.\n");
1671 IWL_ERR(mvm, "Add internal station failed, status=0x%x\n",
1678 int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm)
1680 unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ?
1681 mvm->cfg->base_params->wd_timeout :
1682 IWL_WATCHDOG_DISABLED;
1685 lockdep_assert_held(&mvm->mutex);
1687 /* Map Aux queue to fifo - needs to happen before adding Aux station */
1688 if (!iwl_mvm_is_dqa_supported(mvm))
1689 iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue,
1690 IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout);
1692 /* Allocate aux station and assign to it the aux queue */
1693 ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue),
1694 NL80211_IFTYPE_UNSPECIFIED);
1698 if (iwl_mvm_is_dqa_supported(mvm)) {
1699 struct iwl_trans_txq_scd_cfg cfg = {
1700 .fifo = IWL_MVM_TX_FIFO_MCAST,
1701 .sta_id = mvm->aux_sta.sta_id,
1702 .tid = IWL_MAX_TID_COUNT,
1704 .frame_limit = IWL_FRAME_LIMIT,
1707 iwl_mvm_enable_txq(mvm, mvm->aux_queue, mvm->aux_queue, 0, &cfg,
1711 ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL,
1715 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
1719 int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1721 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1723 lockdep_assert_held(&mvm->mutex);
1724 return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr,
1728 int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1732 lockdep_assert_held(&mvm->mutex);
1734 ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id);
1736 IWL_WARN(mvm, "Failed sending remove station\n");
1741 void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm)
1743 iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta);
1746 void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm)
1748 lockdep_assert_held(&mvm->mutex);
1750 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
1754 * Send the add station command for the vif's broadcast station.
1755 * Assumes that the station was already allocated.
1757 * @mvm: the mvm component
1758 * @vif: the interface to which the broadcast station is added
1759 * @bsta: the broadcast station to add.
1761 int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1763 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1764 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
1765 static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
1766 const u8 *baddr = _baddr;
1768 lockdep_assert_held(&mvm->mutex);
1770 if (iwl_mvm_is_dqa_supported(mvm)) {
1771 struct iwl_trans_txq_scd_cfg cfg = {
1772 .fifo = IWL_MVM_TX_FIFO_VO,
1773 .sta_id = mvmvif->bcast_sta.sta_id,
1774 .tid = IWL_MAX_TID_COUNT,
1776 .frame_limit = IWL_FRAME_LIMIT,
1778 unsigned int wdg_timeout =
1779 iwl_mvm_get_wd_timeout(mvm, vif, false, false);
1782 if ((vif->type == NL80211_IFTYPE_AP) &&
1783 (mvmvif->bcast_sta.tfd_queue_msk &
1784 BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE)))
1785 queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE;
1786 else if ((vif->type == NL80211_IFTYPE_P2P_DEVICE) &&
1787 (mvmvif->bcast_sta.tfd_queue_msk &
1788 BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE)))
1789 queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE;
1790 else if (WARN(1, "Missed required TXQ for adding bcast STA\n"))
1793 iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[0], 0, &cfg,
1797 if (vif->type == NL80211_IFTYPE_ADHOC)
1798 baddr = vif->bss_conf.bssid;
1800 if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_STATION_COUNT))
1803 return iwl_mvm_add_int_sta_common(mvm, bsta, baddr,
1804 mvmvif->id, mvmvif->color);
1807 /* Send the FW a request to remove the station from it's internal data
1808 * structures, but DO NOT remove the entry from the local data structures. */
1809 int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1811 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1814 lockdep_assert_held(&mvm->mutex);
1816 ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id);
1818 IWL_WARN(mvm, "Failed sending remove station\n");
1822 int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1824 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1827 lockdep_assert_held(&mvm->mutex);
1829 if (!iwl_mvm_is_dqa_supported(mvm))
1830 qmask = iwl_mvm_mac_get_queues_mask(vif);
1832 if (vif->type == NL80211_IFTYPE_AP) {
1834 * The firmware defines the TFD queue mask to only be relevant
1835 * for *unicast* queues, so the multicast (CAB) queue shouldn't
1838 qmask &= ~BIT(vif->cab_queue);
1840 if (iwl_mvm_is_dqa_supported(mvm))
1841 qmask |= BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE);
1842 } else if (iwl_mvm_is_dqa_supported(mvm) &&
1843 vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1844 qmask |= BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE);
1847 return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask,
1848 ieee80211_vif_type_p2p(vif));
1851 /* Allocate a new station entry for the broadcast station to the given vif,
1852 * and send it to the FW.
1853 * Note that each P2P mac should have its own broadcast station.
1855 * @mvm: the mvm component
1856 * @vif: the interface to which the broadcast station is added
1857 * @bsta: the broadcast station to add. */
1858 int iwl_mvm_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1860 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1861 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
1864 lockdep_assert_held(&mvm->mutex);
1866 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1870 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
1873 iwl_mvm_dealloc_int_sta(mvm, bsta);
1878 void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1880 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1882 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
1886 * Send the FW a request to remove the station from it's internal data
1887 * structures, and in addition remove it from the local data structure.
1889 int iwl_mvm_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1893 lockdep_assert_held(&mvm->mutex);
1895 ret = iwl_mvm_send_rm_bcast_sta(mvm, vif);
1897 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1902 #define IWL_MAX_RX_BA_SESSIONS 16
1904 static void iwl_mvm_sync_rxq_del_ba(struct iwl_mvm *mvm, u8 baid)
1906 struct iwl_mvm_delba_notif notif = {
1907 .metadata.type = IWL_MVM_RXQ_NOTIF_DEL_BA,
1911 iwl_mvm_sync_rx_queues_internal(mvm, (void *)¬if, sizeof(notif));
1914 static void iwl_mvm_free_reorder(struct iwl_mvm *mvm,
1915 struct iwl_mvm_baid_data *data)
1919 iwl_mvm_sync_rxq_del_ba(mvm, data->baid);
1921 for (i = 0; i < mvm->trans->num_rx_queues; i++) {
1923 struct iwl_mvm_reorder_buffer *reorder_buf =
1924 &data->reorder_buf[i];
1926 spin_lock_bh(&reorder_buf->lock);
1927 if (likely(!reorder_buf->num_stored)) {
1928 spin_unlock_bh(&reorder_buf->lock);
1933 * This shouldn't happen in regular DELBA since the internal
1934 * delBA notification should trigger a release of all frames in
1935 * the reorder buffer.
1939 for (j = 0; j < reorder_buf->buf_size; j++)
1940 __skb_queue_purge(&reorder_buf->entries[j]);
1942 * Prevent timer re-arm. This prevents a very far fetched case
1943 * where we timed out on the notification. There may be prior
1944 * RX frames pending in the RX queue before the notification
1945 * that might get processed between now and the actual deletion
1946 * and we would re-arm the timer although we are deleting the
1949 reorder_buf->removed = true;
1950 spin_unlock_bh(&reorder_buf->lock);
1951 del_timer_sync(&reorder_buf->reorder_timer);
1955 static void iwl_mvm_init_reorder_buffer(struct iwl_mvm *mvm,
1957 struct iwl_mvm_baid_data *data,
1958 u16 ssn, u8 buf_size)
1962 for (i = 0; i < mvm->trans->num_rx_queues; i++) {
1963 struct iwl_mvm_reorder_buffer *reorder_buf =
1964 &data->reorder_buf[i];
1967 reorder_buf->num_stored = 0;
1968 reorder_buf->head_sn = ssn;
1969 reorder_buf->buf_size = buf_size;
1970 /* rx reorder timer */
1971 reorder_buf->reorder_timer.function =
1972 iwl_mvm_reorder_timer_expired;
1973 reorder_buf->reorder_timer.data = (unsigned long)reorder_buf;
1974 init_timer(&reorder_buf->reorder_timer);
1975 spin_lock_init(&reorder_buf->lock);
1976 reorder_buf->mvm = mvm;
1977 reorder_buf->queue = i;
1978 reorder_buf->sta_id = sta_id;
1979 for (j = 0; j < reorder_buf->buf_size; j++)
1980 __skb_queue_head_init(&reorder_buf->entries[j]);
1984 int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
1985 int tid, u16 ssn, bool start, u8 buf_size, u16 timeout)
1987 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1988 struct iwl_mvm_add_sta_cmd cmd = {};
1989 struct iwl_mvm_baid_data *baid_data = NULL;
1993 lockdep_assert_held(&mvm->mutex);
1995 if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) {
1996 IWL_WARN(mvm, "Not enough RX BA SESSIONS\n");
2000 if (iwl_mvm_has_new_rx_api(mvm) && start) {
2002 * Allocate here so if allocation fails we can bail out early
2003 * before starting the BA session in the firmware
2005 baid_data = kzalloc(sizeof(*baid_data) +
2006 mvm->trans->num_rx_queues *
2007 sizeof(baid_data->reorder_buf[0]),
2013 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
2014 cmd.sta_id = mvm_sta->sta_id;
2015 cmd.add_modify = STA_MODE_MODIFY;
2017 cmd.add_immediate_ba_tid = (u8) tid;
2018 cmd.add_immediate_ba_ssn = cpu_to_le16(ssn);
2019 cmd.rx_ba_window = cpu_to_le16((u16)buf_size);
2021 cmd.remove_immediate_ba_tid = (u8) tid;
2023 cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID :
2024 STA_MODIFY_REMOVE_BA_TID;
2026 status = ADD_STA_SUCCESS;
2027 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
2028 iwl_mvm_add_sta_cmd_size(mvm),
2033 switch (status & IWL_ADD_STA_STATUS_MASK) {
2034 case ADD_STA_SUCCESS:
2035 IWL_DEBUG_HT(mvm, "RX BA Session %sed in fw\n",
2036 start ? "start" : "stopp");
2038 case ADD_STA_IMMEDIATE_BA_FAILURE:
2039 IWL_WARN(mvm, "RX BA Session refused by fw\n");
2044 IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n",
2045 start ? "start" : "stopp", status);
2055 mvm->rx_ba_sessions++;
2057 if (!iwl_mvm_has_new_rx_api(mvm))
2060 if (WARN_ON(!(status & IWL_ADD_STA_BAID_VALID_MASK))) {
2064 baid = (u8)((status & IWL_ADD_STA_BAID_MASK) >>
2065 IWL_ADD_STA_BAID_SHIFT);
2066 baid_data->baid = baid;
2067 baid_data->timeout = timeout;
2068 baid_data->last_rx = jiffies;
2069 setup_timer(&baid_data->session_timer,
2070 iwl_mvm_rx_agg_session_expired,
2071 (unsigned long)&mvm->baid_map[baid]);
2072 baid_data->mvm = mvm;
2073 baid_data->tid = tid;
2074 baid_data->sta_id = mvm_sta->sta_id;
2076 mvm_sta->tid_to_baid[tid] = baid;
2078 mod_timer(&baid_data->session_timer,
2079 TU_TO_EXP_TIME(timeout * 2));
2081 iwl_mvm_init_reorder_buffer(mvm, mvm_sta->sta_id,
2082 baid_data, ssn, buf_size);
2084 * protect the BA data with RCU to cover a case where our
2085 * internal RX sync mechanism will timeout (not that it's
2086 * supposed to happen) and we will free the session data while
2087 * RX is being processed in parallel
2089 IWL_DEBUG_HT(mvm, "Sta %d(%d) is assigned to BAID %d\n",
2090 mvm_sta->sta_id, tid, baid);
2091 WARN_ON(rcu_access_pointer(mvm->baid_map[baid]));
2092 rcu_assign_pointer(mvm->baid_map[baid], baid_data);
2094 u8 baid = mvm_sta->tid_to_baid[tid];
2096 if (mvm->rx_ba_sessions > 0)
2097 /* check that restart flow didn't zero the counter */
2098 mvm->rx_ba_sessions--;
2099 if (!iwl_mvm_has_new_rx_api(mvm))
2102 if (WARN_ON(baid == IWL_RX_REORDER_DATA_INVALID_BAID))
2105 baid_data = rcu_access_pointer(mvm->baid_map[baid]);
2106 if (WARN_ON(!baid_data))
2109 /* synchronize all rx queues so we can safely delete */
2110 iwl_mvm_free_reorder(mvm, baid_data);
2111 del_timer_sync(&baid_data->session_timer);
2112 RCU_INIT_POINTER(mvm->baid_map[baid], NULL);
2113 kfree_rcu(baid_data, rcu_head);
2114 IWL_DEBUG_HT(mvm, "BAID %d is free\n", baid);
2123 int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
2124 int tid, u8 queue, bool start)
2126 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2127 struct iwl_mvm_add_sta_cmd cmd = {};
2131 lockdep_assert_held(&mvm->mutex);
2134 mvm_sta->tfd_queue_msk |= BIT(queue);
2135 mvm_sta->tid_disable_agg &= ~BIT(tid);
2137 /* In DQA-mode the queue isn't removed on agg termination */
2138 if (!iwl_mvm_is_dqa_supported(mvm))
2139 mvm_sta->tfd_queue_msk &= ~BIT(queue);
2140 mvm_sta->tid_disable_agg |= BIT(tid);
2143 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
2144 cmd.sta_id = mvm_sta->sta_id;
2145 cmd.add_modify = STA_MODE_MODIFY;
2146 cmd.modify_mask = STA_MODIFY_QUEUES | STA_MODIFY_TID_DISABLE_TX;
2147 cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk);
2148 cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg);
2150 status = ADD_STA_SUCCESS;
2151 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
2152 iwl_mvm_add_sta_cmd_size(mvm),
2157 switch (status & IWL_ADD_STA_STATUS_MASK) {
2158 case ADD_STA_SUCCESS:
2162 IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n",
2163 start ? "start" : "stopp", status);
2170 const u8 tid_to_mac80211_ac[] = {
2179 IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */
2182 static const u8 tid_to_ucode_ac[] = {
2193 int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2194 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
2196 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2197 struct iwl_mvm_tid_data *tid_data;
2201 if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
2204 if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) {
2205 IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n",
2206 mvmsta->tid_data[tid].state);
2210 lockdep_assert_held(&mvm->mutex);
2212 spin_lock_bh(&mvmsta->lock);
2214 /* possible race condition - we entered D0i3 while starting agg */
2215 if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) {
2216 spin_unlock_bh(&mvmsta->lock);
2217 IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n");
2221 spin_lock(&mvm->queue_info_lock);
2224 * Note the possible cases:
2225 * 1. In DQA mode with an enabled TXQ - TXQ needs to become agg'ed
2226 * 2. Non-DQA mode: the TXQ hasn't yet been enabled, so find a free
2227 * one and mark it as reserved
2228 * 3. In DQA mode, but no traffic yet on this TID: same treatment as in
2229 * non-DQA mode, since the TXQ hasn't yet been allocated
2231 txq_id = mvmsta->tid_data[tid].txq_id;
2232 if (iwl_mvm_is_dqa_supported(mvm) &&
2233 unlikely(mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_SHARED)) {
2235 IWL_DEBUG_TX_QUEUES(mvm,
2236 "Can't start tid %d agg on shared queue!\n",
2239 } else if (!iwl_mvm_is_dqa_supported(mvm) ||
2240 mvm->queue_info[txq_id].status != IWL_MVM_QUEUE_READY) {
2241 txq_id = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
2242 mvm->first_agg_queue,
2243 mvm->last_agg_queue);
2246 IWL_ERR(mvm, "Failed to allocate agg queue\n");
2250 /* TXQ hasn't yet been enabled, so mark it only as reserved */
2251 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_RESERVED;
2254 spin_unlock(&mvm->queue_info_lock);
2256 IWL_DEBUG_TX_QUEUES(mvm,
2257 "AGG for tid %d will be on queue #%d\n",
2260 tid_data = &mvmsta->tid_data[tid];
2261 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
2262 tid_data->txq_id = txq_id;
2263 *ssn = tid_data->ssn;
2265 IWL_DEBUG_TX_QUEUES(mvm,
2266 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
2267 mvmsta->sta_id, tid, txq_id, tid_data->ssn,
2268 tid_data->next_reclaimed);
2270 if (tid_data->ssn == tid_data->next_reclaimed) {
2271 tid_data->state = IWL_AGG_STARTING;
2272 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2274 tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA;
2281 spin_unlock(&mvm->queue_info_lock);
2283 spin_unlock_bh(&mvmsta->lock);
2288 int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2289 struct ieee80211_sta *sta, u16 tid, u8 buf_size,
2292 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2293 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2294 unsigned int wdg_timeout =
2295 iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false);
2297 bool alloc_queue = true;
2298 enum iwl_mvm_queue_status queue_status;
2301 struct iwl_trans_txq_scd_cfg cfg = {
2302 .sta_id = mvmsta->sta_id,
2304 .frame_limit = buf_size,
2308 BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE)
2309 != IWL_MAX_TID_COUNT);
2311 buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
2313 spin_lock_bh(&mvmsta->lock);
2314 ssn = tid_data->ssn;
2315 queue = tid_data->txq_id;
2316 tid_data->state = IWL_AGG_ON;
2317 mvmsta->agg_tids |= BIT(tid);
2318 tid_data->ssn = 0xffff;
2319 tid_data->amsdu_in_ampdu_allowed = amsdu;
2320 spin_unlock_bh(&mvmsta->lock);
2322 cfg.fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
2324 spin_lock_bh(&mvm->queue_info_lock);
2325 queue_status = mvm->queue_info[queue].status;
2326 spin_unlock_bh(&mvm->queue_info_lock);
2328 /* In DQA mode, the existing queue might need to be reconfigured */
2329 if (iwl_mvm_is_dqa_supported(mvm)) {
2330 /* Maybe there is no need to even alloc a queue... */
2331 if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_READY)
2332 alloc_queue = false;
2335 * Only reconfig the SCD for the queue if the window size has
2336 * changed from current (become smaller)
2338 if (!alloc_queue && buf_size < mvmsta->max_agg_bufsize) {
2340 * If reconfiguring an existing queue, it first must be
2343 ret = iwl_trans_wait_tx_queue_empty(mvm->trans,
2347 "Error draining queue before reconfig\n");
2351 ret = iwl_mvm_reconfig_scd(mvm, queue, cfg.fifo,
2352 mvmsta->sta_id, tid,
2356 "Error reconfiguring TXQ #%d\n", queue);
2363 iwl_mvm_enable_txq(mvm, queue,
2364 vif->hw_queue[tid_to_mac80211_ac[tid]], ssn,
2367 /* Send ADD_STA command to enable aggs only if the queue isn't shared */
2368 if (queue_status != IWL_MVM_QUEUE_SHARED) {
2369 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
2374 /* No need to mark as reserved */
2375 spin_lock_bh(&mvm->queue_info_lock);
2376 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
2377 spin_unlock_bh(&mvm->queue_info_lock);
2380 * Even though in theory the peer could have different
2381 * aggregation reorder buffer sizes for different sessions,
2382 * our ucode doesn't allow for that and has a global limit
2383 * for each station. Therefore, use the minimum of all the
2384 * aggregation sessions and our default value.
2386 mvmsta->max_agg_bufsize =
2387 min(mvmsta->max_agg_bufsize, buf_size);
2388 mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize;
2390 IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n",
2393 return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false);
2396 int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2397 struct ieee80211_sta *sta, u16 tid)
2399 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2400 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2405 * If mac80211 is cleaning its state, then say that we finished since
2406 * our state has been cleared anyway.
2408 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2409 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2413 spin_lock_bh(&mvmsta->lock);
2415 txq_id = tid_data->txq_id;
2417 IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n",
2418 mvmsta->sta_id, tid, txq_id, tid_data->state);
2420 mvmsta->agg_tids &= ~BIT(tid);
2422 spin_lock_bh(&mvm->queue_info_lock);
2424 * The TXQ is marked as reserved only if no traffic came through yet
2425 * This means no traffic has been sent on this TID (agg'd or not), so
2426 * we no longer have use for the queue. Since it hasn't even been
2427 * allocated through iwl_mvm_enable_txq, so we can just mark it back as
2430 if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED)
2431 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE;
2433 spin_unlock_bh(&mvm->queue_info_lock);
2435 switch (tid_data->state) {
2437 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
2439 IWL_DEBUG_TX_QUEUES(mvm,
2440 "ssn = %d, next_recl = %d\n",
2441 tid_data->ssn, tid_data->next_reclaimed);
2443 /* There are still packets for this RA / TID in the HW */
2444 if (tid_data->ssn != tid_data->next_reclaimed) {
2445 tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA;
2450 tid_data->ssn = 0xffff;
2451 tid_data->state = IWL_AGG_OFF;
2452 spin_unlock_bh(&mvmsta->lock);
2454 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2456 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
2458 if (!iwl_mvm_is_dqa_supported(mvm)) {
2459 int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]];
2461 iwl_mvm_disable_txq(mvm, txq_id, mac_queue, tid, 0);
2464 case IWL_AGG_STARTING:
2465 case IWL_EMPTYING_HW_QUEUE_ADDBA:
2467 * The agg session has been stopped before it was set up. This
2468 * can happen when the AddBA timer times out for example.
2471 /* No barriers since we are under mutex */
2472 lockdep_assert_held(&mvm->mutex);
2474 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2475 tid_data->state = IWL_AGG_OFF;
2480 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
2481 mvmsta->sta_id, tid, tid_data->state);
2483 "\ttid_data->txq_id = %d\n", tid_data->txq_id);
2487 spin_unlock_bh(&mvmsta->lock);
2492 int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2493 struct ieee80211_sta *sta, u16 tid)
2495 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2496 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2498 enum iwl_mvm_agg_state old_state;
2501 * First set the agg state to OFF to avoid calling
2502 * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
2504 spin_lock_bh(&mvmsta->lock);
2505 txq_id = tid_data->txq_id;
2506 IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n",
2507 mvmsta->sta_id, tid, txq_id, tid_data->state);
2508 old_state = tid_data->state;
2509 tid_data->state = IWL_AGG_OFF;
2510 mvmsta->agg_tids &= ~BIT(tid);
2511 spin_unlock_bh(&mvmsta->lock);
2513 spin_lock_bh(&mvm->queue_info_lock);
2515 * The TXQ is marked as reserved only if no traffic came through yet
2516 * This means no traffic has been sent on this TID (agg'd or not), so
2517 * we no longer have use for the queue. Since it hasn't even been
2518 * allocated through iwl_mvm_enable_txq, so we can just mark it back as
2521 if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED)
2522 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE;
2523 spin_unlock_bh(&mvm->queue_info_lock);
2525 if (old_state >= IWL_AGG_ON) {
2526 iwl_mvm_drain_sta(mvm, mvmsta, true);
2527 if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0))
2528 IWL_ERR(mvm, "Couldn't flush the AGG queue\n");
2529 iwl_trans_wait_tx_queue_empty(mvm->trans,
2530 mvmsta->tfd_queue_msk);
2531 iwl_mvm_drain_sta(mvm, mvmsta, false);
2533 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
2535 if (!iwl_mvm_is_dqa_supported(mvm)) {
2536 int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]];
2538 iwl_mvm_disable_txq(mvm, tid_data->txq_id, mac_queue,
2546 static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm)
2548 int i, max = -1, max_offs = -1;
2550 lockdep_assert_held(&mvm->mutex);
2552 /* Pick the unused key offset with the highest 'deleted'
2553 * counter. Every time a key is deleted, all the counters
2554 * are incremented and the one that was just deleted is
2555 * reset to zero. Thus, the highest counter is the one
2556 * that was deleted longest ago. Pick that one.
2558 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
2559 if (test_bit(i, mvm->fw_key_table))
2561 if (mvm->fw_key_deleted[i] > max) {
2562 max = mvm->fw_key_deleted[i];
2568 return STA_KEY_IDX_INVALID;
2573 static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm,
2574 struct ieee80211_vif *vif,
2575 struct ieee80211_sta *sta)
2577 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2580 return iwl_mvm_sta_from_mac80211(sta);
2583 * The device expects GTKs for station interfaces to be
2584 * installed as GTKs for the AP station. If we have no
2585 * station ID, then use AP's station ID.
2587 if (vif->type == NL80211_IFTYPE_STATION &&
2588 mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
2589 u8 sta_id = mvmvif->ap_sta_id;
2591 sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id],
2592 lockdep_is_held(&mvm->mutex));
2595 * It is possible that the 'sta' parameter is NULL,
2596 * for example when a GTK is removed - the sta_id will then
2597 * be the AP ID, and no station was passed by mac80211.
2599 if (IS_ERR_OR_NULL(sta))
2602 return iwl_mvm_sta_from_mac80211(sta);
2608 static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm,
2609 struct iwl_mvm_sta *mvm_sta,
2610 struct ieee80211_key_conf *keyconf, bool mcast,
2611 u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags,
2614 struct iwl_mvm_add_sta_key_cmd cmd = {};
2620 u8 sta_id = mvm_sta->sta_id;
2622 keyidx = (keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
2623 STA_KEY_FLG_KEYID_MSK;
2624 key_flags = cpu_to_le16(keyidx);
2625 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP);
2627 switch (keyconf->cipher) {
2628 case WLAN_CIPHER_SUITE_TKIP:
2629 key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP);
2630 cmd.tkip_rx_tsc_byte2 = tkip_iv32;
2631 for (i = 0; i < 5; i++)
2632 cmd.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]);
2633 memcpy(cmd.key, keyconf->key, keyconf->keylen);
2635 case WLAN_CIPHER_SUITE_CCMP:
2636 key_flags |= cpu_to_le16(STA_KEY_FLG_CCM);
2637 memcpy(cmd.key, keyconf->key, keyconf->keylen);
2639 case WLAN_CIPHER_SUITE_WEP104:
2640 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES);
2642 case WLAN_CIPHER_SUITE_WEP40:
2643 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP);
2644 memcpy(cmd.key + 3, keyconf->key, keyconf->keylen);
2646 case WLAN_CIPHER_SUITE_GCMP_256:
2647 key_flags |= cpu_to_le16(STA_KEY_FLG_KEY_32BYTES);
2649 case WLAN_CIPHER_SUITE_GCMP:
2650 key_flags |= cpu_to_le16(STA_KEY_FLG_GCMP);
2651 memcpy(cmd.key, keyconf->key, keyconf->keylen);
2654 key_flags |= cpu_to_le16(STA_KEY_FLG_EXT);
2655 memcpy(cmd.key, keyconf->key, keyconf->keylen);
2659 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
2661 cmd.key_offset = key_offset;
2662 cmd.key_flags = key_flags;
2663 cmd.sta_id = sta_id;
2665 status = ADD_STA_SUCCESS;
2666 if (cmd_flags & CMD_ASYNC)
2667 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC,
2670 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd),
2674 case ADD_STA_SUCCESS:
2675 IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n");
2679 IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n");
2686 static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm,
2687 struct ieee80211_key_conf *keyconf,
2688 u8 sta_id, bool remove_key)
2690 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {};
2692 /* verify the key details match the required command's expectations */
2693 if (WARN_ON((keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) ||
2694 (keyconf->keyidx != 4 && keyconf->keyidx != 5) ||
2695 (keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC &&
2696 keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_128 &&
2697 keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_256)))
2700 if (WARN_ON(!iwl_mvm_has_new_rx_api(mvm) &&
2701 keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC))
2704 igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx);
2705 igtk_cmd.sta_id = cpu_to_le32(sta_id);
2708 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID);
2710 struct ieee80211_key_seq seq;
2713 switch (keyconf->cipher) {
2714 case WLAN_CIPHER_SUITE_AES_CMAC:
2715 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_CCM);
2717 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2718 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2719 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_GCMP);
2725 memcpy(igtk_cmd.igtk, keyconf->key, keyconf->keylen);
2726 if (keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
2727 igtk_cmd.ctrl_flags |=
2728 cpu_to_le32(STA_KEY_FLG_KEY_32BYTES);
2729 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
2730 pn = seq.aes_cmac.pn;
2731 igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) |
2732 ((u64) pn[4] << 8) |
2733 ((u64) pn[3] << 16) |
2734 ((u64) pn[2] << 24) |
2735 ((u64) pn[1] << 32) |
2736 ((u64) pn[0] << 40));
2739 IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n",
2740 remove_key ? "removing" : "installing",
2743 if (!iwl_mvm_has_new_rx_api(mvm)) {
2744 struct iwl_mvm_mgmt_mcast_key_cmd_v1 igtk_cmd_v1 = {
2745 .ctrl_flags = igtk_cmd.ctrl_flags,
2746 .key_id = igtk_cmd.key_id,
2747 .sta_id = igtk_cmd.sta_id,
2748 .receive_seq_cnt = igtk_cmd.receive_seq_cnt
2751 memcpy(igtk_cmd_v1.igtk, igtk_cmd.igtk,
2752 ARRAY_SIZE(igtk_cmd_v1.igtk));
2753 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
2754 sizeof(igtk_cmd_v1), &igtk_cmd_v1);
2756 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
2757 sizeof(igtk_cmd), &igtk_cmd);
2761 static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm,
2762 struct ieee80211_vif *vif,
2763 struct ieee80211_sta *sta)
2765 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2770 if (vif->type == NL80211_IFTYPE_STATION &&
2771 mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
2772 u8 sta_id = mvmvif->ap_sta_id;
2773 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
2774 lockdep_is_held(&mvm->mutex));
2782 static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
2783 struct ieee80211_vif *vif,
2784 struct ieee80211_sta *sta,
2785 struct ieee80211_key_conf *keyconf,
2789 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2792 struct ieee80211_key_seq seq;
2795 switch (keyconf->cipher) {
2796 case WLAN_CIPHER_SUITE_TKIP:
2797 addr = iwl_mvm_get_mac_addr(mvm, vif, sta);
2798 /* get phase 1 key from mac80211 */
2799 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
2800 ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k);
2801 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
2802 seq.tkip.iv32, p1k, 0, key_offset);
2804 case WLAN_CIPHER_SUITE_CCMP:
2805 case WLAN_CIPHER_SUITE_WEP40:
2806 case WLAN_CIPHER_SUITE_WEP104:
2807 case WLAN_CIPHER_SUITE_GCMP:
2808 case WLAN_CIPHER_SUITE_GCMP_256:
2809 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
2810 0, NULL, 0, key_offset);
2813 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
2814 0, NULL, 0, key_offset);
2820 static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id,
2821 struct ieee80211_key_conf *keyconf,
2824 struct iwl_mvm_add_sta_key_cmd cmd = {};
2829 key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
2830 STA_KEY_FLG_KEYID_MSK);
2831 key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP);
2832 key_flags |= cpu_to_le16(STA_KEY_NOT_VALID);
2835 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
2837 cmd.key_flags = key_flags;
2838 cmd.key_offset = keyconf->hw_key_idx;
2839 cmd.sta_id = sta_id;
2841 status = ADD_STA_SUCCESS;
2842 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd),
2846 case ADD_STA_SUCCESS:
2847 IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n");
2851 IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n");
2858 int iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
2859 struct ieee80211_vif *vif,
2860 struct ieee80211_sta *sta,
2861 struct ieee80211_key_conf *keyconf,
2864 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
2865 struct iwl_mvm_sta *mvm_sta;
2868 static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0};
2870 lockdep_assert_held(&mvm->mutex);
2872 /* Get the station id from the mvm local station table */
2873 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
2875 IWL_ERR(mvm, "Failed to find station\n");
2878 sta_id = mvm_sta->sta_id;
2880 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
2881 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
2882 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) {
2883 ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false);
2888 * It is possible that the 'sta' parameter is NULL, and thus
2889 * there is a need to retrieve the sta from the local station table.
2892 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
2893 lockdep_is_held(&mvm->mutex));
2894 if (IS_ERR_OR_NULL(sta)) {
2895 IWL_ERR(mvm, "Invalid station id\n");
2900 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif))
2903 /* If the key_offset is not pre-assigned, we need to find a
2904 * new offset to use. In normal cases, the offset is not
2905 * pre-assigned, but during HW_RESTART we want to reuse the
2906 * same indices, so we pass them when this function is called.
2908 * In D3 entry, we need to hardcoded the indices (because the
2909 * firmware hardcodes the PTK offset to 0). In this case, we
2910 * need to make sure we don't overwrite the hw_key_idx in the
2911 * keyconf structure, because otherwise we cannot configure
2912 * the original ones back when resuming.
2914 if (key_offset == STA_KEY_IDX_INVALID) {
2915 key_offset = iwl_mvm_set_fw_key_idx(mvm);
2916 if (key_offset == STA_KEY_IDX_INVALID)
2918 keyconf->hw_key_idx = key_offset;
2921 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, key_offset, mcast);
2926 * For WEP, the same key is used for multicast and unicast. Upload it
2927 * again, using the same key offset, and now pointing the other one
2928 * to the same key slot (offset).
2929 * If this fails, remove the original as well.
2931 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2932 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) {
2933 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf,
2934 key_offset, !mcast);
2936 __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
2941 __set_bit(key_offset, mvm->fw_key_table);
2944 IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
2945 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
2946 sta ? sta->addr : zero_addr, ret);
2950 int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm,
2951 struct ieee80211_vif *vif,
2952 struct ieee80211_sta *sta,
2953 struct ieee80211_key_conf *keyconf)
2955 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
2956 struct iwl_mvm_sta *mvm_sta;
2957 u8 sta_id = IWL_MVM_STATION_COUNT;
2960 lockdep_assert_held(&mvm->mutex);
2962 /* Get the station from the mvm local station table */
2963 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
2965 IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n",
2966 keyconf->keyidx, sta_id);
2968 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
2969 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
2970 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
2971 return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true);
2973 if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) {
2974 IWL_ERR(mvm, "offset %d not used in fw key table.\n",
2975 keyconf->hw_key_idx);
2979 /* track which key was deleted last */
2980 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
2981 if (mvm->fw_key_deleted[i] < U8_MAX)
2982 mvm->fw_key_deleted[i]++;
2984 mvm->fw_key_deleted[keyconf->hw_key_idx] = 0;
2987 IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n");
2991 sta_id = mvm_sta->sta_id;
2993 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
2997 /* delete WEP key twice to get rid of (now useless) offset */
2998 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2999 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104)
3000 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast);
3005 void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm,
3006 struct ieee80211_vif *vif,
3007 struct ieee80211_key_conf *keyconf,
3008 struct ieee80211_sta *sta, u32 iv32,
3011 struct iwl_mvm_sta *mvm_sta;
3012 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
3016 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
3017 if (WARN_ON_ONCE(!mvm_sta))
3019 iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
3020 iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx);
3026 void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm,
3027 struct ieee80211_sta *sta)
3029 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3030 struct iwl_mvm_add_sta_cmd cmd = {
3031 .add_modify = STA_MODE_MODIFY,
3032 .sta_id = mvmsta->sta_id,
3033 .station_flags_msk = cpu_to_le32(STA_FLG_PS),
3034 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
3038 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
3039 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
3041 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3044 void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm,
3045 struct ieee80211_sta *sta,
3046 enum ieee80211_frame_release_type reason,
3047 u16 cnt, u16 tids, bool more_data,
3050 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3051 struct iwl_mvm_add_sta_cmd cmd = {
3052 .add_modify = STA_MODE_MODIFY,
3053 .sta_id = mvmsta->sta_id,
3054 .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT,
3055 .sleep_tx_count = cpu_to_le16(cnt),
3056 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
3059 unsigned long _tids = tids;
3061 /* convert TIDs to ACs - we don't support TSPEC so that's OK
3062 * Note that this field is reserved and unused by firmware not
3063 * supporting GO uAPSD, so it's safe to always do this.
3065 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT)
3066 cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]);
3068 /* If we're releasing frames from aggregation queues then check if the
3069 * all queues combined that we're releasing frames from have
3070 * - more frames than the service period, in which case more_data
3072 * - fewer than 'cnt' frames, in which case we need to adjust the
3073 * firmware command (but do that unconditionally)
3076 int remaining = cnt;
3079 spin_lock_bh(&mvmsta->lock);
3080 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) {
3081 struct iwl_mvm_tid_data *tid_data;
3084 tid_data = &mvmsta->tid_data[tid];
3085 if (WARN(tid_data->state != IWL_AGG_ON &&
3086 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA,
3087 "TID %d state is %d\n",
3088 tid, tid_data->state)) {
3089 spin_unlock_bh(&mvmsta->lock);
3090 ieee80211_sta_eosp(sta);
3094 n_queued = iwl_mvm_tid_queued(tid_data);
3095 if (n_queued > remaining) {
3100 remaining -= n_queued;
3102 sleep_tx_count = cnt - remaining;
3103 if (reason == IEEE80211_FRAME_RELEASE_UAPSD)
3104 mvmsta->sleep_tx_count = sleep_tx_count;
3105 spin_unlock_bh(&mvmsta->lock);
3107 cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count);
3108 if (WARN_ON(cnt - remaining == 0)) {
3109 ieee80211_sta_eosp(sta);
3114 /* Note: this is ignored by firmware not supporting GO uAPSD */
3116 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA);
3118 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) {
3119 mvmsta->next_status_eosp = true;
3120 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL);
3122 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD);
3125 /* block the Tx queues until the FW updated the sleep Tx count */
3126 iwl_trans_block_txq_ptrs(mvm->trans, true);
3128 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA,
3129 CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK,
3130 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
3132 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3135 void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm,
3136 struct iwl_rx_cmd_buffer *rxb)
3138 struct iwl_rx_packet *pkt = rxb_addr(rxb);
3139 struct iwl_mvm_eosp_notification *notif = (void *)pkt->data;
3140 struct ieee80211_sta *sta;
3141 u32 sta_id = le32_to_cpu(notif->sta_id);
3143 if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT))
3147 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
3148 if (!IS_ERR_OR_NULL(sta))
3149 ieee80211_sta_eosp(sta);
3153 void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm,
3154 struct iwl_mvm_sta *mvmsta, bool disable)
3156 struct iwl_mvm_add_sta_cmd cmd = {
3157 .add_modify = STA_MODE_MODIFY,
3158 .sta_id = mvmsta->sta_id,
3159 .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0,
3160 .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX),
3161 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
3165 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
3166 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
3168 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3171 void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm,
3172 struct ieee80211_sta *sta,
3175 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3177 spin_lock_bh(&mvm_sta->lock);
3179 if (mvm_sta->disable_tx == disable) {
3180 spin_unlock_bh(&mvm_sta->lock);
3184 mvm_sta->disable_tx = disable;
3187 * Tell mac80211 to start/stop queuing tx for this station,
3188 * but don't stop queuing if there are still pending frames
3191 if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id]))
3192 ieee80211_sta_block_awake(mvm->hw, sta, disable);
3194 iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable);
3196 spin_unlock_bh(&mvm_sta->lock);
3199 void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm,
3200 struct iwl_mvm_vif *mvmvif,
3203 struct ieee80211_sta *sta;
3204 struct iwl_mvm_sta *mvm_sta;
3207 lockdep_assert_held(&mvm->mutex);
3209 /* Block/unblock all the stations of the given mvmvif */
3210 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
3211 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3212 lockdep_is_held(&mvm->mutex));
3213 if (IS_ERR_OR_NULL(sta))
3216 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3217 if (mvm_sta->mac_id_n_color !=
3218 FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color))
3221 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable);
3225 void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
3227 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3228 struct iwl_mvm_sta *mvmsta;
3232 mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id);
3234 if (!WARN_ON(!mvmsta))
3235 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true);