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 if (mvm_sta->associated)
206 add_sta_cmd.assoc_id = cpu_to_le16(sta->aid);
209 add_sta_cmd.modify_mask |= STA_MODIFY_UAPSD_ACS;
211 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
212 add_sta_cmd.uapsd_trigger_acs |= BIT(AC_BK);
213 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
214 add_sta_cmd.uapsd_trigger_acs |= BIT(AC_BE);
215 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
216 add_sta_cmd.uapsd_trigger_acs |= BIT(AC_VI);
217 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
218 add_sta_cmd.uapsd_trigger_acs |= BIT(AC_VO);
221 status = ADD_STA_SUCCESS;
222 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
223 iwl_mvm_add_sta_cmd_size(mvm),
224 &add_sta_cmd, &status);
228 switch (status & IWL_ADD_STA_STATUS_MASK) {
229 case ADD_STA_SUCCESS:
230 IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n");
234 IWL_ERR(mvm, "ADD_STA failed\n");
241 static void iwl_mvm_rx_agg_session_expired(unsigned long data)
243 struct iwl_mvm_baid_data __rcu **rcu_ptr = (void *)data;
244 struct iwl_mvm_baid_data *ba_data;
245 struct ieee80211_sta *sta;
246 struct iwl_mvm_sta *mvm_sta;
247 unsigned long timeout;
251 ba_data = rcu_dereference(*rcu_ptr);
253 if (WARN_ON(!ba_data))
256 if (!ba_data->timeout)
259 timeout = ba_data->last_rx + TU_TO_JIFFIES(ba_data->timeout * 2);
260 if (time_is_after_jiffies(timeout)) {
261 mod_timer(&ba_data->session_timer, timeout);
266 sta = rcu_dereference(ba_data->mvm->fw_id_to_mac_id[ba_data->sta_id]);
267 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
268 ieee80211_stop_rx_ba_session_offl(mvm_sta->vif,
269 sta->addr, ba_data->tid);
274 static int iwl_mvm_tdls_sta_init(struct iwl_mvm *mvm,
275 struct ieee80211_sta *sta)
277 unsigned long used_hw_queues;
278 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
279 unsigned int wdg_timeout =
280 iwl_mvm_get_wd_timeout(mvm, NULL, true, false);
283 lockdep_assert_held(&mvm->mutex);
285 used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, NULL);
287 /* Find available queues, and allocate them to the ACs */
288 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
289 u8 queue = find_first_zero_bit(&used_hw_queues,
290 mvm->first_agg_queue);
292 if (queue >= mvm->first_agg_queue) {
293 IWL_ERR(mvm, "Failed to allocate STA queue\n");
297 __set_bit(queue, &used_hw_queues);
298 mvmsta->hw_queue[ac] = queue;
301 /* Found a place for all queues - enable them */
302 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
303 iwl_mvm_enable_ac_txq(mvm, mvmsta->hw_queue[ac],
304 mvmsta->hw_queue[ac],
305 iwl_mvm_ac_to_tx_fifo[ac], 0,
307 mvmsta->tfd_queue_msk |= BIT(mvmsta->hw_queue[ac]);
313 static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm *mvm,
314 struct ieee80211_sta *sta)
316 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
317 unsigned long sta_msk;
320 lockdep_assert_held(&mvm->mutex);
322 /* disable the TDLS STA-specific queues */
323 sta_msk = mvmsta->tfd_queue_msk;
324 for_each_set_bit(i, &sta_msk, sizeof(sta_msk) * BITS_PER_BYTE)
325 iwl_mvm_disable_txq(mvm, i, i, IWL_MAX_TID_COUNT, 0);
328 /* Disable aggregations for a bitmap of TIDs for a given station */
329 static int iwl_mvm_invalidate_sta_queue(struct iwl_mvm *mvm, int queue,
330 unsigned long disable_agg_tids,
333 struct iwl_mvm_add_sta_cmd cmd = {};
334 struct ieee80211_sta *sta;
335 struct iwl_mvm_sta *mvmsta;
340 spin_lock_bh(&mvm->queue_info_lock);
341 sta_id = mvm->queue_info[queue].ra_sta_id;
342 spin_unlock_bh(&mvm->queue_info_lock);
346 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
348 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
353 mvmsta = iwl_mvm_sta_from_mac80211(sta);
355 mvmsta->tid_disable_agg |= disable_agg_tids;
357 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
358 cmd.sta_id = mvmsta->sta_id;
359 cmd.add_modify = STA_MODE_MODIFY;
360 cmd.modify_mask = STA_MODIFY_QUEUES;
361 if (disable_agg_tids)
362 cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX;
364 cmd.modify_mask |= STA_MODIFY_QUEUE_REMOVAL;
365 cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk);
366 cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg);
370 /* Notify FW of queue removal from the STA queues */
371 status = ADD_STA_SUCCESS;
372 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
373 iwl_mvm_add_sta_cmd_size(mvm),
379 static int iwl_mvm_get_queue_agg_tids(struct iwl_mvm *mvm, int queue)
381 struct ieee80211_sta *sta;
382 struct iwl_mvm_sta *mvmsta;
383 unsigned long tid_bitmap;
384 unsigned long agg_tids = 0;
388 lockdep_assert_held(&mvm->mutex);
390 spin_lock_bh(&mvm->queue_info_lock);
391 sta_id = mvm->queue_info[queue].ra_sta_id;
392 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
393 spin_unlock_bh(&mvm->queue_info_lock);
395 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
396 lockdep_is_held(&mvm->mutex));
398 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
401 mvmsta = iwl_mvm_sta_from_mac80211(sta);
403 spin_lock_bh(&mvmsta->lock);
404 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
405 if (mvmsta->tid_data[tid].state == IWL_AGG_ON)
406 agg_tids |= BIT(tid);
408 spin_unlock_bh(&mvmsta->lock);
414 * Remove a queue from a station's resources.
415 * Note that this only marks as free. It DOESN'T delete a BA agreement, and
416 * doesn't disable the queue
418 static int iwl_mvm_remove_sta_queue_marking(struct iwl_mvm *mvm, int queue)
420 struct ieee80211_sta *sta;
421 struct iwl_mvm_sta *mvmsta;
422 unsigned long tid_bitmap;
423 unsigned long disable_agg_tids = 0;
427 lockdep_assert_held(&mvm->mutex);
429 spin_lock_bh(&mvm->queue_info_lock);
430 sta_id = mvm->queue_info[queue].ra_sta_id;
431 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
432 spin_unlock_bh(&mvm->queue_info_lock);
436 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
438 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
443 mvmsta = iwl_mvm_sta_from_mac80211(sta);
445 spin_lock_bh(&mvmsta->lock);
446 /* Unmap MAC queues and TIDs from this queue */
447 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
448 if (mvmsta->tid_data[tid].state == IWL_AGG_ON)
449 disable_agg_tids |= BIT(tid);
450 mvmsta->tid_data[tid].txq_id = IEEE80211_INVAL_HW_QUEUE;
453 mvmsta->tfd_queue_msk &= ~BIT(queue); /* Don't use this queue anymore */
454 spin_unlock_bh(&mvmsta->lock);
458 return disable_agg_tids;
461 static int iwl_mvm_free_inactive_queue(struct iwl_mvm *mvm, int queue,
464 struct iwl_mvm_sta *mvmsta;
465 u8 txq_curr_ac, sta_id, tid;
466 unsigned long disable_agg_tids = 0;
469 lockdep_assert_held(&mvm->mutex);
471 spin_lock_bh(&mvm->queue_info_lock);
472 txq_curr_ac = mvm->queue_info[queue].mac80211_ac;
473 sta_id = mvm->queue_info[queue].ra_sta_id;
474 tid = mvm->queue_info[queue].txq_tid;
475 spin_unlock_bh(&mvm->queue_info_lock);
477 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
479 disable_agg_tids = iwl_mvm_remove_sta_queue_marking(mvm, queue);
480 /* Disable the queue */
481 if (disable_agg_tids)
482 iwl_mvm_invalidate_sta_queue(mvm, queue,
483 disable_agg_tids, false);
485 ret = iwl_mvm_disable_txq(mvm, queue,
486 mvmsta->vif->hw_queue[txq_curr_ac],
489 /* Re-mark the inactive queue as inactive */
490 spin_lock_bh(&mvm->queue_info_lock);
491 mvm->queue_info[queue].status = IWL_MVM_QUEUE_INACTIVE;
492 spin_unlock_bh(&mvm->queue_info_lock);
494 "Failed to free inactive queue %d (ret=%d)\n",
500 /* If TXQ is allocated to another STA, update removal in FW */
502 iwl_mvm_invalidate_sta_queue(mvm, queue, 0, true);
507 static int iwl_mvm_get_shared_queue(struct iwl_mvm *mvm,
508 unsigned long tfd_queue_mask, u8 ac)
511 u8 ac_to_queue[IEEE80211_NUM_ACS];
514 lockdep_assert_held(&mvm->queue_info_lock);
516 memset(&ac_to_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(ac_to_queue));
518 /* See what ACs the existing queues for this STA have */
519 for_each_set_bit(i, &tfd_queue_mask, IWL_MVM_DQA_MAX_DATA_QUEUE) {
520 /* Only DATA queues can be shared */
521 if (i < IWL_MVM_DQA_MIN_DATA_QUEUE &&
522 i != IWL_MVM_DQA_BSS_CLIENT_QUEUE)
525 /* Don't try and take queues being reconfigured */
526 if (mvm->queue_info[queue].status ==
527 IWL_MVM_QUEUE_RECONFIGURING)
530 ac_to_queue[mvm->queue_info[i].mac80211_ac] = i;
534 * The queue to share is chosen only from DATA queues as follows (in
535 * descending priority):
538 * 3. Highest AC queue that is lower than new AC
539 * 4. Any existing AC (there always is at least 1 DATA queue)
542 /* Priority 1: An AC_BE queue */
543 if (ac_to_queue[IEEE80211_AC_BE] != IEEE80211_INVAL_HW_QUEUE)
544 queue = ac_to_queue[IEEE80211_AC_BE];
545 /* Priority 2: Same AC queue */
546 else if (ac_to_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
547 queue = ac_to_queue[ac];
548 /* Priority 3a: If new AC is VO and VI exists - use VI */
549 else if (ac == IEEE80211_AC_VO &&
550 ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE)
551 queue = ac_to_queue[IEEE80211_AC_VI];
552 /* Priority 3b: No BE so only AC less than the new one is BK */
553 else if (ac_to_queue[IEEE80211_AC_BK] != IEEE80211_INVAL_HW_QUEUE)
554 queue = ac_to_queue[IEEE80211_AC_BK];
555 /* Priority 4a: No BE nor BK - use VI if exists */
556 else if (ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE)
557 queue = ac_to_queue[IEEE80211_AC_VI];
558 /* Priority 4b: No BE, BK nor VI - use VO if exists */
559 else if (ac_to_queue[IEEE80211_AC_VO] != IEEE80211_INVAL_HW_QUEUE)
560 queue = ac_to_queue[IEEE80211_AC_VO];
562 /* Make sure queue found (or not) is legal */
563 if (!iwl_mvm_is_dqa_data_queue(mvm, queue) &&
564 !iwl_mvm_is_dqa_mgmt_queue(mvm, queue) &&
565 (queue != IWL_MVM_DQA_BSS_CLIENT_QUEUE)) {
566 IWL_ERR(mvm, "No DATA queues available to share\n");
570 /* Make sure the queue isn't in the middle of being reconfigured */
571 if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_RECONFIGURING) {
573 "TXQ %d is in the middle of re-config - try again\n",
582 * If a given queue has a higher AC than the TID stream that is being compared
583 * to, the queue needs to be redirected to the lower AC. This function does that
584 * in such a case, otherwise - if no redirection required - it does nothing,
585 * unless the %force param is true.
587 int iwl_mvm_scd_queue_redirect(struct iwl_mvm *mvm, int queue, int tid,
588 int ac, int ssn, unsigned int wdg_timeout,
591 struct iwl_scd_txq_cfg_cmd cmd = {
593 .action = SCD_CFG_DISABLE_QUEUE,
600 * If the AC is lower than current one - FIFO needs to be redirected to
601 * the lowest one of the streams in the queue. Check if this is needed
603 * Notice that the enum ieee80211_ac_numbers is "flipped", so BK is with
604 * value 3 and VO with value 0, so to check if ac X is lower than ac Y
605 * we need to check if the numerical value of X is LARGER than of Y.
607 spin_lock_bh(&mvm->queue_info_lock);
608 if (ac <= mvm->queue_info[queue].mac80211_ac && !force) {
609 spin_unlock_bh(&mvm->queue_info_lock);
611 IWL_DEBUG_TX_QUEUES(mvm,
612 "No redirection needed on TXQ #%d\n",
617 cmd.sta_id = mvm->queue_info[queue].ra_sta_id;
618 cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[mvm->queue_info[queue].mac80211_ac];
619 cmd.tid = mvm->queue_info[queue].txq_tid;
620 mq = mvm->queue_info[queue].hw_queue_to_mac80211;
621 shared_queue = (mvm->queue_info[queue].hw_queue_refcount > 1);
622 spin_unlock_bh(&mvm->queue_info_lock);
624 IWL_DEBUG_TX_QUEUES(mvm, "Redirecting TXQ #%d to FIFO #%d\n",
625 queue, iwl_mvm_ac_to_tx_fifo[ac]);
627 /* Stop MAC queues and wait for this queue to empty */
628 iwl_mvm_stop_mac_queues(mvm, mq);
629 ret = iwl_trans_wait_tx_queue_empty(mvm->trans, BIT(queue));
631 IWL_ERR(mvm, "Error draining queue %d before reconfig\n",
637 /* Before redirecting the queue we need to de-activate it */
638 iwl_trans_txq_disable(mvm->trans, queue, false);
639 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd);
641 IWL_ERR(mvm, "Failed SCD disable TXQ %d (ret=%d)\n", queue,
644 /* Make sure the SCD wrptr is correctly set before reconfiguring */
645 iwl_trans_txq_enable_cfg(mvm->trans, queue, ssn, NULL, wdg_timeout);
647 /* Update the TID "owner" of the queue */
648 spin_lock_bh(&mvm->queue_info_lock);
649 mvm->queue_info[queue].txq_tid = tid;
650 spin_unlock_bh(&mvm->queue_info_lock);
652 /* TODO: Work-around SCD bug when moving back by multiples of 0x40 */
654 /* Redirect to lower AC */
655 iwl_mvm_reconfig_scd(mvm, queue, iwl_mvm_ac_to_tx_fifo[ac],
656 cmd.sta_id, tid, LINK_QUAL_AGG_FRAME_LIMIT_DEF,
659 /* Update AC marking of the queue */
660 spin_lock_bh(&mvm->queue_info_lock);
661 mvm->queue_info[queue].mac80211_ac = ac;
662 spin_unlock_bh(&mvm->queue_info_lock);
665 * Mark queue as shared in transport if shared
666 * Note this has to be done after queue enablement because enablement
667 * can also set this value, and there is no indication there to shared
671 iwl_trans_txq_set_shared_mode(mvm->trans, queue, true);
674 /* Continue using the MAC queues */
675 iwl_mvm_start_mac_queues(mvm, mq);
680 static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm,
681 struct ieee80211_sta *sta, u8 ac, int tid,
682 struct ieee80211_hdr *hdr)
684 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
685 struct iwl_trans_txq_scd_cfg cfg = {
686 .fifo = iwl_mvm_ac_to_tx_fifo[ac],
687 .sta_id = mvmsta->sta_id,
689 .frame_limit = IWL_FRAME_LIMIT,
691 unsigned int wdg_timeout =
692 iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
693 u8 mac_queue = mvmsta->vif->hw_queue[ac];
695 bool using_inactive_queue = false, same_sta = false;
696 unsigned long disable_agg_tids = 0;
697 enum iwl_mvm_agg_state queue_state;
698 bool shared_queue = false;
700 unsigned long tfd_queue_mask;
703 lockdep_assert_held(&mvm->mutex);
705 spin_lock_bh(&mvmsta->lock);
706 tfd_queue_mask = mvmsta->tfd_queue_msk;
707 spin_unlock_bh(&mvmsta->lock);
709 spin_lock_bh(&mvm->queue_info_lock);
712 * Non-QoS, QoS NDP and MGMT frames should go to a MGMT queue, if one
715 if (!ieee80211_is_data_qos(hdr->frame_control) ||
716 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
717 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
718 IWL_MVM_DQA_MIN_MGMT_QUEUE,
719 IWL_MVM_DQA_MAX_MGMT_QUEUE);
720 if (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE)
721 IWL_DEBUG_TX_QUEUES(mvm, "Found free MGMT queue #%d\n",
724 /* If no such queue is found, we'll use a DATA queue instead */
727 if ((queue < 0 && mvmsta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) &&
728 (mvm->queue_info[mvmsta->reserved_queue].status ==
729 IWL_MVM_QUEUE_RESERVED ||
730 mvm->queue_info[mvmsta->reserved_queue].status ==
731 IWL_MVM_QUEUE_INACTIVE)) {
732 queue = mvmsta->reserved_queue;
733 mvm->queue_info[queue].reserved = true;
734 IWL_DEBUG_TX_QUEUES(mvm, "Using reserved queue #%d\n", queue);
738 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
739 IWL_MVM_DQA_MIN_DATA_QUEUE,
740 IWL_MVM_DQA_MAX_DATA_QUEUE);
743 * Check if this queue is already allocated but inactive.
744 * In such a case, we'll need to first free this queue before enabling
745 * it again, so we'll mark it as reserved to make sure no new traffic
749 mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) {
750 mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED;
751 using_inactive_queue = true;
752 same_sta = mvm->queue_info[queue].ra_sta_id == mvmsta->sta_id;
753 IWL_DEBUG_TX_QUEUES(mvm,
754 "Re-assigning TXQ %d: sta_id=%d, tid=%d\n",
755 queue, mvmsta->sta_id, tid);
758 /* No free queue - we'll have to share */
760 queue = iwl_mvm_get_shared_queue(mvm, tfd_queue_mask, ac);
763 mvm->queue_info[queue].status = IWL_MVM_QUEUE_SHARED;
768 * Mark TXQ as ready, even though it hasn't been fully configured yet,
769 * to make sure no one else takes it.
770 * This will allow avoiding re-acquiring the lock at the end of the
771 * configuration. On error we'll mark it back as free.
773 if ((queue > 0) && !shared_queue)
774 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
776 spin_unlock_bh(&mvm->queue_info_lock);
778 /* This shouldn't happen - out of queues */
779 if (WARN_ON(queue <= 0)) {
780 IWL_ERR(mvm, "No available queues for tid %d on sta_id %d\n",
786 * Actual en/disablement of aggregations is through the ADD_STA HCMD,
787 * but for configuring the SCD to send A-MPDUs we need to mark the queue
789 * Mark all DATA queues as allowing to be aggregated at some point
791 cfg.aggregate = (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
792 queue == IWL_MVM_DQA_BSS_CLIENT_QUEUE);
795 * If this queue was previously inactive (idle) - we need to free it
798 if (using_inactive_queue) {
799 ret = iwl_mvm_free_inactive_queue(mvm, queue, same_sta);
804 IWL_DEBUG_TX_QUEUES(mvm,
805 "Allocating %squeue #%d to sta %d on tid %d\n",
806 shared_queue ? "shared " : "", queue,
807 mvmsta->sta_id, tid);
810 /* Disable any open aggs on this queue */
811 disable_agg_tids = iwl_mvm_get_queue_agg_tids(mvm, queue);
813 if (disable_agg_tids) {
814 IWL_DEBUG_TX_QUEUES(mvm, "Disabling aggs on queue %d\n",
816 iwl_mvm_invalidate_sta_queue(mvm, queue,
817 disable_agg_tids, false);
821 ssn = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
822 iwl_mvm_enable_txq(mvm, queue, mac_queue, ssn, &cfg,
826 * Mark queue as shared in transport if shared
827 * Note this has to be done after queue enablement because enablement
828 * can also set this value, and there is no indication there to shared
832 iwl_trans_txq_set_shared_mode(mvm->trans, queue, true);
834 spin_lock_bh(&mvmsta->lock);
835 mvmsta->tid_data[tid].txq_id = queue;
836 mvmsta->tid_data[tid].is_tid_active = true;
837 mvmsta->tfd_queue_msk |= BIT(queue);
838 queue_state = mvmsta->tid_data[tid].state;
840 if (mvmsta->reserved_queue == queue)
841 mvmsta->reserved_queue = IEEE80211_INVAL_HW_QUEUE;
842 spin_unlock_bh(&mvmsta->lock);
845 ret = iwl_mvm_sta_send_to_fw(mvm, sta, true, STA_MODIFY_QUEUES);
849 /* If we need to re-enable aggregations... */
850 if (queue_state == IWL_AGG_ON) {
851 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
856 /* Redirect queue, if needed */
857 ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid, ac, ssn,
866 iwl_mvm_disable_txq(mvm, queue, mac_queue, tid, 0);
871 static void iwl_mvm_change_queue_owner(struct iwl_mvm *mvm, int queue)
873 struct iwl_scd_txq_cfg_cmd cmd = {
875 .action = SCD_CFG_UPDATE_QUEUE_TID,
878 unsigned long tid_bitmap;
881 lockdep_assert_held(&mvm->mutex);
883 spin_lock_bh(&mvm->queue_info_lock);
884 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
885 spin_unlock_bh(&mvm->queue_info_lock);
887 if (WARN(!tid_bitmap, "TXQ %d has no tids assigned to it\n", queue))
890 /* Find any TID for queue */
891 tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1);
893 cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
895 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd);
897 IWL_ERR(mvm, "Failed to update owner of TXQ %d (ret=%d)\n",
902 spin_lock_bh(&mvm->queue_info_lock);
903 mvm->queue_info[queue].txq_tid = tid;
904 spin_unlock_bh(&mvm->queue_info_lock);
905 IWL_DEBUG_TX_QUEUES(mvm, "Changed TXQ %d ownership to tid %d\n",
909 static void iwl_mvm_unshare_queue(struct iwl_mvm *mvm, int queue)
911 struct ieee80211_sta *sta;
912 struct iwl_mvm_sta *mvmsta;
915 unsigned long tid_bitmap;
916 unsigned int wdg_timeout;
920 lockdep_assert_held(&mvm->mutex);
922 spin_lock_bh(&mvm->queue_info_lock);
923 sta_id = mvm->queue_info[queue].ra_sta_id;
924 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
925 spin_unlock_bh(&mvm->queue_info_lock);
927 /* Find TID for queue, and make sure it is the only one on the queue */
928 tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1);
929 if (tid_bitmap != BIT(tid)) {
930 IWL_ERR(mvm, "Failed to unshare q %d, active tids=0x%lx\n",
935 IWL_DEBUG_TX_QUEUES(mvm, "Unsharing TXQ %d, keeping tid %d\n", queue,
938 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
939 lockdep_is_held(&mvm->mutex));
941 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
944 mvmsta = iwl_mvm_sta_from_mac80211(sta);
945 wdg_timeout = iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
947 ssn = IEEE80211_SEQ_TO_SN(mvmsta->tid_data[tid].seq_number);
949 ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid,
950 tid_to_mac80211_ac[tid], ssn,
953 IWL_ERR(mvm, "Failed to redirect TXQ %d\n", queue);
957 /* If aggs should be turned back on - do it */
958 if (mvmsta->tid_data[tid].state == IWL_AGG_ON) {
959 struct iwl_mvm_add_sta_cmd cmd = {0};
961 mvmsta->tid_disable_agg &= ~BIT(tid);
963 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
964 cmd.sta_id = mvmsta->sta_id;
965 cmd.add_modify = STA_MODE_MODIFY;
966 cmd.modify_mask = STA_MODIFY_TID_DISABLE_TX;
967 cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk);
968 cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg);
970 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
971 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
973 IWL_DEBUG_TX_QUEUES(mvm,
974 "TXQ #%d is now aggregated again\n",
977 /* Mark queue intenally as aggregating again */
978 iwl_trans_txq_set_shared_mode(mvm->trans, queue, false);
982 spin_lock_bh(&mvm->queue_info_lock);
983 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
984 spin_unlock_bh(&mvm->queue_info_lock);
987 static inline u8 iwl_mvm_tid_to_ac_queue(int tid)
989 if (tid == IWL_MAX_TID_COUNT)
990 return IEEE80211_AC_VO; /* MGMT */
992 return tid_to_mac80211_ac[tid];
995 static void iwl_mvm_tx_deferred_stream(struct iwl_mvm *mvm,
996 struct ieee80211_sta *sta, int tid)
998 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
999 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
1000 struct sk_buff *skb;
1001 struct ieee80211_hdr *hdr;
1002 struct sk_buff_head deferred_tx;
1004 bool no_queue = false; /* Marks if there is a problem with the queue */
1007 lockdep_assert_held(&mvm->mutex);
1009 skb = skb_peek(&tid_data->deferred_tx_frames);
1012 hdr = (void *)skb->data;
1014 ac = iwl_mvm_tid_to_ac_queue(tid);
1015 mac_queue = IEEE80211_SKB_CB(skb)->hw_queue;
1017 if (tid_data->txq_id == IEEE80211_INVAL_HW_QUEUE &&
1018 iwl_mvm_sta_alloc_queue(mvm, sta, ac, tid, hdr)) {
1020 "Can't alloc TXQ for sta %d tid %d - dropping frame\n",
1021 mvmsta->sta_id, tid);
1024 * Mark queue as problematic so later the deferred traffic is
1025 * freed, as we can do nothing with it
1030 __skb_queue_head_init(&deferred_tx);
1032 /* Disable bottom-halves when entering TX path */
1034 spin_lock(&mvmsta->lock);
1035 skb_queue_splice_init(&tid_data->deferred_tx_frames, &deferred_tx);
1036 mvmsta->deferred_traffic_tid_map &= ~BIT(tid);
1037 spin_unlock(&mvmsta->lock);
1039 while ((skb = __skb_dequeue(&deferred_tx)))
1040 if (no_queue || iwl_mvm_tx_skb(mvm, skb, sta))
1041 ieee80211_free_txskb(mvm->hw, skb);
1045 iwl_mvm_start_mac_queues(mvm, BIT(mac_queue));
1048 void iwl_mvm_add_new_dqa_stream_wk(struct work_struct *wk)
1050 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm,
1052 struct ieee80211_sta *sta;
1053 struct iwl_mvm_sta *mvmsta;
1054 unsigned long deferred_tid_traffic;
1055 int queue, sta_id, tid;
1057 /* Check inactivity of queues */
1058 iwl_mvm_inactivity_check(mvm);
1060 mutex_lock(&mvm->mutex);
1062 /* Reconfigure queues requiring reconfiguation */
1063 for (queue = 0; queue < IWL_MAX_HW_QUEUES; queue++) {
1067 spin_lock_bh(&mvm->queue_info_lock);
1068 reconfig = (mvm->queue_info[queue].status ==
1069 IWL_MVM_QUEUE_RECONFIGURING);
1072 * We need to take into account a situation in which a TXQ was
1073 * allocated to TID x, and then turned shared by adding TIDs y
1074 * and z. If TID x becomes inactive and is removed from the TXQ,
1075 * ownership must be given to one of the remaining TIDs.
1076 * This is mainly because if TID x continues - a new queue can't
1077 * be allocated for it as long as it is an owner of another TXQ.
1079 change_owner = !(mvm->queue_info[queue].tid_bitmap &
1080 BIT(mvm->queue_info[queue].txq_tid)) &&
1081 (mvm->queue_info[queue].status ==
1082 IWL_MVM_QUEUE_SHARED);
1083 spin_unlock_bh(&mvm->queue_info_lock);
1086 iwl_mvm_unshare_queue(mvm, queue);
1087 else if (change_owner)
1088 iwl_mvm_change_queue_owner(mvm, queue);
1091 /* Go over all stations with deferred traffic */
1092 for_each_set_bit(sta_id, mvm->sta_deferred_frames,
1093 IWL_MVM_STATION_COUNT) {
1094 clear_bit(sta_id, mvm->sta_deferred_frames);
1095 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1096 lockdep_is_held(&mvm->mutex));
1097 if (IS_ERR_OR_NULL(sta))
1100 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1101 deferred_tid_traffic = mvmsta->deferred_traffic_tid_map;
1103 for_each_set_bit(tid, &deferred_tid_traffic,
1104 IWL_MAX_TID_COUNT + 1)
1105 iwl_mvm_tx_deferred_stream(mvm, sta, tid);
1108 mutex_unlock(&mvm->mutex);
1111 static int iwl_mvm_reserve_sta_stream(struct iwl_mvm *mvm,
1112 struct ieee80211_sta *sta,
1113 enum nl80211_iftype vif_type)
1115 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1117 bool using_inactive_queue = false, same_sta = false;
1120 * Check for inactive queues, so we don't reach a situation where we
1121 * can't add a STA due to a shortage in queues that doesn't really exist
1123 iwl_mvm_inactivity_check(mvm);
1125 spin_lock_bh(&mvm->queue_info_lock);
1127 /* Make sure we have free resources for this STA */
1128 if (vif_type == NL80211_IFTYPE_STATION && !sta->tdls &&
1129 !mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].hw_queue_refcount &&
1130 (mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].status ==
1131 IWL_MVM_QUEUE_FREE))
1132 queue = IWL_MVM_DQA_BSS_CLIENT_QUEUE;
1134 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
1135 IWL_MVM_DQA_MIN_DATA_QUEUE,
1136 IWL_MVM_DQA_MAX_DATA_QUEUE);
1138 spin_unlock_bh(&mvm->queue_info_lock);
1139 IWL_ERR(mvm, "No available queues for new station\n");
1141 } else if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) {
1143 * If this queue is already allocated but inactive we'll need to
1144 * first free this queue before enabling it again, we'll mark
1145 * it as reserved to make sure no new traffic arrives on it
1147 using_inactive_queue = true;
1148 same_sta = mvm->queue_info[queue].ra_sta_id == mvmsta->sta_id;
1150 mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED;
1152 spin_unlock_bh(&mvm->queue_info_lock);
1154 mvmsta->reserved_queue = queue;
1156 if (using_inactive_queue)
1157 iwl_mvm_free_inactive_queue(mvm, queue, same_sta);
1159 IWL_DEBUG_TX_QUEUES(mvm, "Reserving data queue #%d for sta_id %d\n",
1160 queue, mvmsta->sta_id);
1166 * In DQA mode, after a HW restart the queues should be allocated as before, in
1167 * order to avoid race conditions when there are shared queues. This function
1168 * does the re-mapping and queue allocation.
1170 * Note that re-enabling aggregations isn't done in this function.
1172 static void iwl_mvm_realloc_queues_after_restart(struct iwl_mvm *mvm,
1173 struct iwl_mvm_sta *mvm_sta)
1175 unsigned int wdg_timeout =
1176 iwl_mvm_get_wd_timeout(mvm, mvm_sta->vif, false, false);
1178 struct iwl_trans_txq_scd_cfg cfg = {
1179 .sta_id = mvm_sta->sta_id,
1180 .frame_limit = IWL_FRAME_LIMIT,
1183 /* Make sure reserved queue is still marked as such (if allocated) */
1184 if (mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE)
1185 mvm->queue_info[mvm_sta->reserved_queue].status =
1186 IWL_MVM_QUEUE_RESERVED;
1188 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
1189 struct iwl_mvm_tid_data *tid_data = &mvm_sta->tid_data[i];
1190 int txq_id = tid_data->txq_id;
1194 if (txq_id == IEEE80211_INVAL_HW_QUEUE)
1197 skb_queue_head_init(&tid_data->deferred_tx_frames);
1199 ac = tid_to_mac80211_ac[i];
1200 mac_queue = mvm_sta->vif->hw_queue[ac];
1203 cfg.fifo = iwl_mvm_ac_to_tx_fifo[ac];
1204 cfg.aggregate = (txq_id >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
1205 txq_id == IWL_MVM_DQA_BSS_CLIENT_QUEUE);
1207 IWL_DEBUG_TX_QUEUES(mvm,
1208 "Re-mapping sta %d tid %d to queue %d\n",
1209 mvm_sta->sta_id, i, txq_id);
1211 iwl_mvm_enable_txq(mvm, txq_id, mac_queue,
1212 IEEE80211_SEQ_TO_SN(tid_data->seq_number),
1215 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_READY;
1218 atomic_set(&mvm->pending_frames[mvm_sta->sta_id], 0);
1221 int iwl_mvm_add_sta(struct iwl_mvm *mvm,
1222 struct ieee80211_vif *vif,
1223 struct ieee80211_sta *sta)
1225 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1226 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1227 struct iwl_mvm_rxq_dup_data *dup_data;
1230 lockdep_assert_held(&mvm->mutex);
1232 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1233 sta_id = iwl_mvm_find_free_sta_id(mvm,
1234 ieee80211_vif_type_p2p(vif));
1236 sta_id = mvm_sta->sta_id;
1238 if (sta_id == IWL_MVM_STATION_COUNT)
1241 spin_lock_init(&mvm_sta->lock);
1243 /* In DQA mode, if this is a HW restart, re-alloc existing queues */
1244 if (iwl_mvm_is_dqa_supported(mvm) &&
1245 test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1246 iwl_mvm_realloc_queues_after_restart(mvm, mvm_sta);
1250 mvm_sta->sta_id = sta_id;
1251 mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id,
1254 mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
1255 mvm_sta->tx_protection = 0;
1256 mvm_sta->tt_tx_protection = false;
1258 /* HW restart, don't assume the memory has been zeroed */
1259 atomic_set(&mvm->pending_frames[sta_id], 0);
1260 mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */
1261 mvm_sta->tfd_queue_msk = 0;
1264 * Allocate new queues for a TDLS station, unless we're in DQA mode,
1265 * and then they'll be allocated dynamically
1267 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) {
1268 ret = iwl_mvm_tdls_sta_init(mvm, sta);
1271 } else if (!iwl_mvm_is_dqa_supported(mvm)) {
1272 for (i = 0; i < IEEE80211_NUM_ACS; i++)
1273 if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE)
1274 mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]);
1277 /* for HW restart - reset everything but the sequence number */
1278 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
1279 u16 seq = mvm_sta->tid_data[i].seq_number;
1280 memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i]));
1281 mvm_sta->tid_data[i].seq_number = seq;
1283 if (!iwl_mvm_is_dqa_supported(mvm))
1287 * Mark all queues for this STA as unallocated and defer TX
1288 * frames until the queue is allocated
1290 mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE;
1291 skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames);
1293 mvm_sta->deferred_traffic_tid_map = 0;
1294 mvm_sta->agg_tids = 0;
1296 if (iwl_mvm_has_new_rx_api(mvm) &&
1297 !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1298 dup_data = kcalloc(mvm->trans->num_rx_queues,
1303 mvm_sta->dup_data = dup_data;
1306 if (iwl_mvm_is_dqa_supported(mvm)) {
1307 ret = iwl_mvm_reserve_sta_stream(mvm, sta,
1308 ieee80211_vif_type_p2p(vif));
1314 ret = iwl_mvm_sta_send_to_fw(mvm, sta, false, 0);
1318 if (vif->type == NL80211_IFTYPE_STATION) {
1320 WARN_ON(mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT);
1321 mvmvif->ap_sta_id = sta_id;
1323 WARN_ON(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT);
1327 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta);
1332 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls)
1333 iwl_mvm_tdls_sta_deinit(mvm, sta);
1337 int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
1340 struct iwl_mvm_add_sta_cmd cmd = {};
1344 lockdep_assert_held(&mvm->mutex);
1346 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
1347 cmd.sta_id = mvmsta->sta_id;
1348 cmd.add_modify = STA_MODE_MODIFY;
1349 cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0;
1350 cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW);
1352 status = ADD_STA_SUCCESS;
1353 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1354 iwl_mvm_add_sta_cmd_size(mvm),
1359 switch (status & IWL_ADD_STA_STATUS_MASK) {
1360 case ADD_STA_SUCCESS:
1361 IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n",
1366 IWL_ERR(mvm, "Couldn't drain frames for staid %d\n",
1375 * Remove a station from the FW table. Before sending the command to remove
1376 * the station validate that the station is indeed known to the driver (sanity
1379 static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id)
1381 struct ieee80211_sta *sta;
1382 struct iwl_mvm_rm_sta_cmd rm_sta_cmd = {
1387 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1388 lockdep_is_held(&mvm->mutex));
1390 /* Note: internal stations are marked as error values */
1392 IWL_ERR(mvm, "Invalid station id\n");
1396 ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0,
1397 sizeof(rm_sta_cmd), &rm_sta_cmd);
1399 IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id);
1406 void iwl_mvm_sta_drained_wk(struct work_struct *wk)
1408 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk);
1412 * The mutex is needed because of the SYNC cmd, but not only: if the
1413 * work would run concurrently with iwl_mvm_rm_sta, it would run before
1414 * iwl_mvm_rm_sta sets the station as busy, and exit. Then
1415 * iwl_mvm_rm_sta would set the station as busy, and nobody will clean
1418 mutex_lock(&mvm->mutex);
1420 for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) {
1422 struct ieee80211_sta *sta =
1423 rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1424 lockdep_is_held(&mvm->mutex));
1427 * This station is in use or RCU-removed; the latter happens in
1428 * managed mode, where mac80211 removes the station before we
1429 * can remove it from firmware (we can only do that after the
1430 * MAC is marked unassociated), and possibly while the deauth
1431 * frame to disconnect from the AP is still queued. Then, the
1432 * station pointer is -ENOENT when the last skb is reclaimed.
1434 if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT)
1437 if (PTR_ERR(sta) == -EINVAL) {
1438 IWL_ERR(mvm, "Drained sta %d, but it is internal?\n",
1444 IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n",
1449 WARN_ON(PTR_ERR(sta) != -EBUSY);
1450 /* This station was removed and we waited until it got drained,
1451 * we can now proceed and remove it.
1453 ret = iwl_mvm_rm_sta_common(mvm, sta_id);
1456 "Couldn't remove sta %d after it was drained\n",
1460 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
1461 clear_bit(sta_id, mvm->sta_drained);
1463 if (mvm->tfd_drained[sta_id]) {
1464 unsigned long i, msk = mvm->tfd_drained[sta_id];
1466 for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE)
1467 iwl_mvm_disable_txq(mvm, i, i,
1468 IWL_MAX_TID_COUNT, 0);
1470 mvm->tfd_drained[sta_id] = 0;
1471 IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n",
1476 mutex_unlock(&mvm->mutex);
1479 static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm,
1480 struct ieee80211_vif *vif,
1481 struct iwl_mvm_sta *mvm_sta)
1486 lockdep_assert_held(&mvm->mutex);
1488 for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) {
1489 if (mvm_sta->tid_data[i].txq_id == IEEE80211_INVAL_HW_QUEUE)
1492 ac = iwl_mvm_tid_to_ac_queue(i);
1493 iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id,
1494 vif->hw_queue[ac], i, 0);
1495 mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE;
1499 int iwl_mvm_rm_sta(struct iwl_mvm *mvm,
1500 struct ieee80211_vif *vif,
1501 struct ieee80211_sta *sta)
1503 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1504 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1505 u8 sta_id = mvm_sta->sta_id;
1508 lockdep_assert_held(&mvm->mutex);
1510 if (iwl_mvm_has_new_rx_api(mvm))
1511 kfree(mvm_sta->dup_data);
1513 if ((vif->type == NL80211_IFTYPE_STATION &&
1514 mvmvif->ap_sta_id == sta_id) ||
1515 iwl_mvm_is_dqa_supported(mvm)){
1516 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
1519 /* flush its queues here since we are freeing mvm_sta */
1520 ret = iwl_mvm_flush_tx_path(mvm, mvm_sta->tfd_queue_msk, 0);
1523 ret = iwl_trans_wait_tx_queue_empty(mvm->trans,
1524 mvm_sta->tfd_queue_msk);
1527 ret = iwl_mvm_drain_sta(mvm, mvm_sta, false);
1529 /* If DQA is supported - the queues can be disabled now */
1530 if (iwl_mvm_is_dqa_supported(mvm)) {
1531 iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta);
1533 * If pending_frames is set at this point - it must be
1534 * driver internal logic error, since queues are empty
1535 * and removed successuly.
1536 * warn on it but set it to 0 anyway to avoid station
1537 * not being removed later in the function
1539 WARN_ON(atomic_xchg(&mvm->pending_frames[sta_id], 0));
1542 /* If there is a TXQ still marked as reserved - free it */
1543 if (iwl_mvm_is_dqa_supported(mvm) &&
1544 mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) {
1545 u8 reserved_txq = mvm_sta->reserved_queue;
1546 enum iwl_mvm_queue_status *status;
1549 * If no traffic has gone through the reserved TXQ - it
1550 * is still marked as IWL_MVM_QUEUE_RESERVED, and
1551 * should be manually marked as free again
1553 spin_lock_bh(&mvm->queue_info_lock);
1554 status = &mvm->queue_info[reserved_txq].status;
1555 if (WARN((*status != IWL_MVM_QUEUE_RESERVED) &&
1556 (*status != IWL_MVM_QUEUE_FREE),
1557 "sta_id %d reserved txq %d status %d",
1558 sta_id, reserved_txq, *status)) {
1559 spin_unlock_bh(&mvm->queue_info_lock);
1563 *status = IWL_MVM_QUEUE_FREE;
1564 spin_unlock_bh(&mvm->queue_info_lock);
1567 if (vif->type == NL80211_IFTYPE_STATION &&
1568 mvmvif->ap_sta_id == sta_id) {
1569 /* if associated - we can't remove the AP STA now */
1570 if (vif->bss_conf.assoc)
1573 /* unassoc - go ahead - remove the AP STA now */
1574 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
1576 /* clear d0i3_ap_sta_id if no longer relevant */
1577 if (mvm->d0i3_ap_sta_id == sta_id)
1578 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
1583 * This shouldn't happen - the TDLS channel switch should be canceled
1584 * before the STA is removed.
1586 if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == sta_id)) {
1587 mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT;
1588 cancel_delayed_work(&mvm->tdls_cs.dwork);
1592 * Make sure that the tx response code sees the station as -EBUSY and
1593 * calls the drain worker.
1595 spin_lock_bh(&mvm_sta->lock);
1598 * There are frames pending on the AC queues for this station.
1599 * We need to wait until all the frames are drained...
1601 if (atomic_read(&mvm->pending_frames[sta_id])) {
1602 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id],
1604 spin_unlock_bh(&mvm_sta->lock);
1606 /* disable TDLS sta queues on drain complete */
1608 mvm->tfd_drained[sta_id] = mvm_sta->tfd_queue_msk;
1609 IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n", sta_id);
1612 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
1614 spin_unlock_bh(&mvm_sta->lock);
1616 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls)
1617 iwl_mvm_tdls_sta_deinit(mvm, sta);
1619 ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id);
1620 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL);
1626 int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm,
1627 struct ieee80211_vif *vif,
1630 int ret = iwl_mvm_rm_sta_common(mvm, sta_id);
1632 lockdep_assert_held(&mvm->mutex);
1634 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
1638 int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm,
1639 struct iwl_mvm_int_sta *sta,
1640 u32 qmask, enum nl80211_iftype iftype)
1642 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1643 sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype);
1644 if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_STATION_COUNT))
1648 sta->tfd_queue_msk = qmask;
1650 /* put a non-NULL value so iterating over the stations won't stop */
1651 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL));
1655 static void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm,
1656 struct iwl_mvm_int_sta *sta)
1658 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta->sta_id], NULL);
1659 memset(sta, 0, sizeof(struct iwl_mvm_int_sta));
1660 sta->sta_id = IWL_MVM_STATION_COUNT;
1663 static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm,
1664 struct iwl_mvm_int_sta *sta,
1666 u16 mac_id, u16 color)
1668 struct iwl_mvm_add_sta_cmd cmd;
1672 lockdep_assert_held(&mvm->mutex);
1674 memset(&cmd, 0, sizeof(cmd));
1675 cmd.sta_id = sta->sta_id;
1676 cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id,
1679 cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk);
1680 cmd.tid_disable_tx = cpu_to_le16(0xffff);
1683 memcpy(cmd.addr, addr, ETH_ALEN);
1685 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1686 iwl_mvm_add_sta_cmd_size(mvm),
1691 switch (status & IWL_ADD_STA_STATUS_MASK) {
1692 case ADD_STA_SUCCESS:
1693 IWL_DEBUG_INFO(mvm, "Internal station added.\n");
1697 IWL_ERR(mvm, "Add internal station failed, status=0x%x\n",
1704 int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm)
1706 unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ?
1707 mvm->cfg->base_params->wd_timeout :
1708 IWL_WATCHDOG_DISABLED;
1711 lockdep_assert_held(&mvm->mutex);
1713 /* Map Aux queue to fifo - needs to happen before adding Aux station */
1714 if (!iwl_mvm_is_dqa_supported(mvm))
1715 iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue,
1716 IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout);
1718 /* Allocate aux station and assign to it the aux queue */
1719 ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue),
1720 NL80211_IFTYPE_UNSPECIFIED);
1724 if (iwl_mvm_is_dqa_supported(mvm)) {
1725 struct iwl_trans_txq_scd_cfg cfg = {
1726 .fifo = IWL_MVM_TX_FIFO_MCAST,
1727 .sta_id = mvm->aux_sta.sta_id,
1728 .tid = IWL_MAX_TID_COUNT,
1730 .frame_limit = IWL_FRAME_LIMIT,
1733 iwl_mvm_enable_txq(mvm, mvm->aux_queue, mvm->aux_queue, 0, &cfg,
1737 ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL,
1741 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
1745 int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1747 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1749 lockdep_assert_held(&mvm->mutex);
1750 return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr,
1754 int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1758 lockdep_assert_held(&mvm->mutex);
1760 ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id);
1762 IWL_WARN(mvm, "Failed sending remove station\n");
1767 void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm)
1769 iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta);
1772 void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm)
1774 lockdep_assert_held(&mvm->mutex);
1776 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
1780 * Send the add station command for the vif's broadcast station.
1781 * Assumes that the station was already allocated.
1783 * @mvm: the mvm component
1784 * @vif: the interface to which the broadcast station is added
1785 * @bsta: the broadcast station to add.
1787 int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1789 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1790 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
1791 static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
1792 const u8 *baddr = _baddr;
1795 lockdep_assert_held(&mvm->mutex);
1797 if (iwl_mvm_is_dqa_supported(mvm)) {
1798 struct iwl_trans_txq_scd_cfg cfg = {
1799 .fifo = IWL_MVM_TX_FIFO_VO,
1800 .sta_id = mvmvif->bcast_sta.sta_id,
1801 .tid = IWL_MAX_TID_COUNT,
1803 .frame_limit = IWL_FRAME_LIMIT,
1805 unsigned int wdg_timeout =
1806 iwl_mvm_get_wd_timeout(mvm, vif, false, false);
1809 if (vif->type == NL80211_IFTYPE_AP)
1810 queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE;
1811 else if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
1812 queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE;
1813 else if (WARN(1, "Missing required TXQ for adding bcast STA\n"))
1816 iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[0], 0, &cfg,
1818 bsta->tfd_queue_msk |= BIT(queue);
1821 if (vif->type == NL80211_IFTYPE_ADHOC)
1822 baddr = vif->bss_conf.bssid;
1824 if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_STATION_COUNT))
1827 ret = iwl_mvm_add_int_sta_common(mvm, bsta, baddr,
1828 mvmvif->id, mvmvif->color);
1833 * In AP vif type, we also need to enable the cab_queue. However, we
1834 * have to enable it after the ADD_STA command is sent, otherwise the
1835 * FW will throw an assert once we send the ADD_STA command (it'll
1836 * detect a mismatch in the tfd_queue_msk, as we can't add the
1837 * enabled-cab_queue to the mask)
1839 if (iwl_mvm_is_dqa_supported(mvm) &&
1840 vif->type == NL80211_IFTYPE_AP) {
1841 struct iwl_trans_txq_scd_cfg cfg = {
1842 .fifo = IWL_MVM_TX_FIFO_MCAST,
1843 .sta_id = mvmvif->bcast_sta.sta_id,
1844 .tid = IWL_MAX_TID_COUNT,
1846 .frame_limit = IWL_FRAME_LIMIT,
1848 unsigned int wdg_timeout =
1849 iwl_mvm_get_wd_timeout(mvm, vif, false, false);
1851 iwl_mvm_enable_txq(mvm, vif->cab_queue, vif->cab_queue,
1852 0, &cfg, wdg_timeout);
1858 static void iwl_mvm_free_bcast_sta_queues(struct iwl_mvm *mvm,
1859 struct ieee80211_vif *vif)
1861 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1863 lockdep_assert_held(&mvm->mutex);
1865 if (vif->type == NL80211_IFTYPE_AP)
1866 iwl_mvm_disable_txq(mvm, vif->cab_queue, vif->cab_queue,
1867 IWL_MAX_TID_COUNT, 0);
1869 if (mvmvif->bcast_sta.tfd_queue_msk &
1870 BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE)) {
1871 iwl_mvm_disable_txq(mvm,
1872 IWL_MVM_DQA_AP_PROBE_RESP_QUEUE,
1873 vif->hw_queue[0], IWL_MAX_TID_COUNT,
1875 mvmvif->bcast_sta.tfd_queue_msk &=
1876 ~BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE);
1879 if (mvmvif->bcast_sta.tfd_queue_msk &
1880 BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE)) {
1881 iwl_mvm_disable_txq(mvm,
1882 IWL_MVM_DQA_P2P_DEVICE_QUEUE,
1883 vif->hw_queue[0], IWL_MAX_TID_COUNT,
1885 mvmvif->bcast_sta.tfd_queue_msk &=
1886 ~BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE);
1890 /* Send the FW a request to remove the station from it's internal data
1891 * structures, but DO NOT remove the entry from the local data structures. */
1892 int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1894 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1897 lockdep_assert_held(&mvm->mutex);
1899 if (iwl_mvm_is_dqa_supported(mvm))
1900 iwl_mvm_free_bcast_sta_queues(mvm, vif);
1902 ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id);
1904 IWL_WARN(mvm, "Failed sending remove station\n");
1908 int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1910 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1913 lockdep_assert_held(&mvm->mutex);
1915 if (!iwl_mvm_is_dqa_supported(mvm)) {
1916 qmask = iwl_mvm_mac_get_queues_mask(vif);
1919 * The firmware defines the TFD queue mask to only be relevant
1920 * for *unicast* queues, so the multicast (CAB) queue shouldn't
1921 * be included. This only happens in NL80211_IFTYPE_AP vif type,
1922 * so the next line will only have an effect there.
1924 qmask &= ~BIT(vif->cab_queue);
1927 return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask,
1928 ieee80211_vif_type_p2p(vif));
1931 /* Allocate a new station entry for the broadcast station to the given vif,
1932 * and send it to the FW.
1933 * Note that each P2P mac should have its own broadcast station.
1935 * @mvm: the mvm component
1936 * @vif: the interface to which the broadcast station is added
1937 * @bsta: the broadcast station to add. */
1938 int iwl_mvm_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1940 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1941 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
1944 lockdep_assert_held(&mvm->mutex);
1946 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
1950 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
1953 iwl_mvm_dealloc_int_sta(mvm, bsta);
1958 void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1960 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1962 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
1966 * Send the FW a request to remove the station from it's internal data
1967 * structures, and in addition remove it from the local data structure.
1969 int iwl_mvm_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1973 lockdep_assert_held(&mvm->mutex);
1975 ret = iwl_mvm_send_rm_bcast_sta(mvm, vif);
1977 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1982 #define IWL_MAX_RX_BA_SESSIONS 16
1984 static void iwl_mvm_sync_rxq_del_ba(struct iwl_mvm *mvm, u8 baid)
1986 struct iwl_mvm_delba_notif notif = {
1987 .metadata.type = IWL_MVM_RXQ_NOTIF_DEL_BA,
1991 iwl_mvm_sync_rx_queues_internal(mvm, (void *)¬if, sizeof(notif));
1994 static void iwl_mvm_free_reorder(struct iwl_mvm *mvm,
1995 struct iwl_mvm_baid_data *data)
1999 iwl_mvm_sync_rxq_del_ba(mvm, data->baid);
2001 for (i = 0; i < mvm->trans->num_rx_queues; i++) {
2003 struct iwl_mvm_reorder_buffer *reorder_buf =
2004 &data->reorder_buf[i];
2006 spin_lock_bh(&reorder_buf->lock);
2007 if (likely(!reorder_buf->num_stored)) {
2008 spin_unlock_bh(&reorder_buf->lock);
2013 * This shouldn't happen in regular DELBA since the internal
2014 * delBA notification should trigger a release of all frames in
2015 * the reorder buffer.
2019 for (j = 0; j < reorder_buf->buf_size; j++)
2020 __skb_queue_purge(&reorder_buf->entries[j]);
2022 * Prevent timer re-arm. This prevents a very far fetched case
2023 * where we timed out on the notification. There may be prior
2024 * RX frames pending in the RX queue before the notification
2025 * that might get processed between now and the actual deletion
2026 * and we would re-arm the timer although we are deleting the
2029 reorder_buf->removed = true;
2030 spin_unlock_bh(&reorder_buf->lock);
2031 del_timer_sync(&reorder_buf->reorder_timer);
2035 static void iwl_mvm_init_reorder_buffer(struct iwl_mvm *mvm,
2037 struct iwl_mvm_baid_data *data,
2038 u16 ssn, u8 buf_size)
2042 for (i = 0; i < mvm->trans->num_rx_queues; i++) {
2043 struct iwl_mvm_reorder_buffer *reorder_buf =
2044 &data->reorder_buf[i];
2047 reorder_buf->num_stored = 0;
2048 reorder_buf->head_sn = ssn;
2049 reorder_buf->buf_size = buf_size;
2050 /* rx reorder timer */
2051 reorder_buf->reorder_timer.function =
2052 iwl_mvm_reorder_timer_expired;
2053 reorder_buf->reorder_timer.data = (unsigned long)reorder_buf;
2054 init_timer(&reorder_buf->reorder_timer);
2055 spin_lock_init(&reorder_buf->lock);
2056 reorder_buf->mvm = mvm;
2057 reorder_buf->queue = i;
2058 reorder_buf->sta_id = sta_id;
2059 for (j = 0; j < reorder_buf->buf_size; j++)
2060 __skb_queue_head_init(&reorder_buf->entries[j]);
2064 int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
2065 int tid, u16 ssn, bool start, u8 buf_size, u16 timeout)
2067 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2068 struct iwl_mvm_add_sta_cmd cmd = {};
2069 struct iwl_mvm_baid_data *baid_data = NULL;
2073 lockdep_assert_held(&mvm->mutex);
2075 if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) {
2076 IWL_WARN(mvm, "Not enough RX BA SESSIONS\n");
2080 if (iwl_mvm_has_new_rx_api(mvm) && start) {
2082 * Allocate here so if allocation fails we can bail out early
2083 * before starting the BA session in the firmware
2085 baid_data = kzalloc(sizeof(*baid_data) +
2086 mvm->trans->num_rx_queues *
2087 sizeof(baid_data->reorder_buf[0]),
2093 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
2094 cmd.sta_id = mvm_sta->sta_id;
2095 cmd.add_modify = STA_MODE_MODIFY;
2097 cmd.add_immediate_ba_tid = (u8) tid;
2098 cmd.add_immediate_ba_ssn = cpu_to_le16(ssn);
2099 cmd.rx_ba_window = cpu_to_le16((u16)buf_size);
2101 cmd.remove_immediate_ba_tid = (u8) tid;
2103 cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID :
2104 STA_MODIFY_REMOVE_BA_TID;
2106 status = ADD_STA_SUCCESS;
2107 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
2108 iwl_mvm_add_sta_cmd_size(mvm),
2113 switch (status & IWL_ADD_STA_STATUS_MASK) {
2114 case ADD_STA_SUCCESS:
2115 IWL_DEBUG_HT(mvm, "RX BA Session %sed in fw\n",
2116 start ? "start" : "stopp");
2118 case ADD_STA_IMMEDIATE_BA_FAILURE:
2119 IWL_WARN(mvm, "RX BA Session refused by fw\n");
2124 IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n",
2125 start ? "start" : "stopp", status);
2135 mvm->rx_ba_sessions++;
2137 if (!iwl_mvm_has_new_rx_api(mvm))
2140 if (WARN_ON(!(status & IWL_ADD_STA_BAID_VALID_MASK))) {
2144 baid = (u8)((status & IWL_ADD_STA_BAID_MASK) >>
2145 IWL_ADD_STA_BAID_SHIFT);
2146 baid_data->baid = baid;
2147 baid_data->timeout = timeout;
2148 baid_data->last_rx = jiffies;
2149 setup_timer(&baid_data->session_timer,
2150 iwl_mvm_rx_agg_session_expired,
2151 (unsigned long)&mvm->baid_map[baid]);
2152 baid_data->mvm = mvm;
2153 baid_data->tid = tid;
2154 baid_data->sta_id = mvm_sta->sta_id;
2156 mvm_sta->tid_to_baid[tid] = baid;
2158 mod_timer(&baid_data->session_timer,
2159 TU_TO_EXP_TIME(timeout * 2));
2161 iwl_mvm_init_reorder_buffer(mvm, mvm_sta->sta_id,
2162 baid_data, ssn, buf_size);
2164 * protect the BA data with RCU to cover a case where our
2165 * internal RX sync mechanism will timeout (not that it's
2166 * supposed to happen) and we will free the session data while
2167 * RX is being processed in parallel
2169 IWL_DEBUG_HT(mvm, "Sta %d(%d) is assigned to BAID %d\n",
2170 mvm_sta->sta_id, tid, baid);
2171 WARN_ON(rcu_access_pointer(mvm->baid_map[baid]));
2172 rcu_assign_pointer(mvm->baid_map[baid], baid_data);
2174 u8 baid = mvm_sta->tid_to_baid[tid];
2176 if (mvm->rx_ba_sessions > 0)
2177 /* check that restart flow didn't zero the counter */
2178 mvm->rx_ba_sessions--;
2179 if (!iwl_mvm_has_new_rx_api(mvm))
2182 if (WARN_ON(baid == IWL_RX_REORDER_DATA_INVALID_BAID))
2185 baid_data = rcu_access_pointer(mvm->baid_map[baid]);
2186 if (WARN_ON(!baid_data))
2189 /* synchronize all rx queues so we can safely delete */
2190 iwl_mvm_free_reorder(mvm, baid_data);
2191 del_timer_sync(&baid_data->session_timer);
2192 RCU_INIT_POINTER(mvm->baid_map[baid], NULL);
2193 kfree_rcu(baid_data, rcu_head);
2194 IWL_DEBUG_HT(mvm, "BAID %d is free\n", baid);
2203 int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
2204 int tid, u8 queue, bool start)
2206 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2207 struct iwl_mvm_add_sta_cmd cmd = {};
2211 lockdep_assert_held(&mvm->mutex);
2214 mvm_sta->tfd_queue_msk |= BIT(queue);
2215 mvm_sta->tid_disable_agg &= ~BIT(tid);
2217 /* In DQA-mode the queue isn't removed on agg termination */
2218 if (!iwl_mvm_is_dqa_supported(mvm))
2219 mvm_sta->tfd_queue_msk &= ~BIT(queue);
2220 mvm_sta->tid_disable_agg |= BIT(tid);
2223 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
2224 cmd.sta_id = mvm_sta->sta_id;
2225 cmd.add_modify = STA_MODE_MODIFY;
2226 cmd.modify_mask = STA_MODIFY_QUEUES | STA_MODIFY_TID_DISABLE_TX;
2227 cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk);
2228 cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg);
2230 status = ADD_STA_SUCCESS;
2231 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
2232 iwl_mvm_add_sta_cmd_size(mvm),
2237 switch (status & IWL_ADD_STA_STATUS_MASK) {
2238 case ADD_STA_SUCCESS:
2242 IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n",
2243 start ? "start" : "stopp", status);
2250 const u8 tid_to_mac80211_ac[] = {
2259 IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */
2262 static const u8 tid_to_ucode_ac[] = {
2273 int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2274 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
2276 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2277 struct iwl_mvm_tid_data *tid_data;
2281 if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
2284 if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) {
2285 IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n",
2286 mvmsta->tid_data[tid].state);
2290 lockdep_assert_held(&mvm->mutex);
2292 spin_lock_bh(&mvmsta->lock);
2294 /* possible race condition - we entered D0i3 while starting agg */
2295 if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) {
2296 spin_unlock_bh(&mvmsta->lock);
2297 IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n");
2301 spin_lock(&mvm->queue_info_lock);
2304 * Note the possible cases:
2305 * 1. In DQA mode with an enabled TXQ - TXQ needs to become agg'ed
2306 * 2. Non-DQA mode: the TXQ hasn't yet been enabled, so find a free
2307 * one and mark it as reserved
2308 * 3. In DQA mode, but no traffic yet on this TID: same treatment as in
2309 * non-DQA mode, since the TXQ hasn't yet been allocated
2311 txq_id = mvmsta->tid_data[tid].txq_id;
2312 if (iwl_mvm_is_dqa_supported(mvm) &&
2313 unlikely(mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_SHARED)) {
2315 IWL_DEBUG_TX_QUEUES(mvm,
2316 "Can't start tid %d agg on shared queue!\n",
2319 } else if (!iwl_mvm_is_dqa_supported(mvm) ||
2320 mvm->queue_info[txq_id].status != IWL_MVM_QUEUE_READY) {
2321 txq_id = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
2322 mvm->first_agg_queue,
2323 mvm->last_agg_queue);
2326 IWL_ERR(mvm, "Failed to allocate agg queue\n");
2330 * TXQ shouldn't be in inactive mode for non-DQA, so getting
2331 * an inactive queue from iwl_mvm_find_free_queue() is
2334 WARN_ON(mvm->queue_info[txq_id].status ==
2335 IWL_MVM_QUEUE_INACTIVE);
2337 /* TXQ hasn't yet been enabled, so mark it only as reserved */
2338 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_RESERVED;
2341 spin_unlock(&mvm->queue_info_lock);
2343 IWL_DEBUG_TX_QUEUES(mvm,
2344 "AGG for tid %d will be on queue #%d\n",
2347 tid_data = &mvmsta->tid_data[tid];
2348 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
2349 tid_data->txq_id = txq_id;
2350 *ssn = tid_data->ssn;
2352 IWL_DEBUG_TX_QUEUES(mvm,
2353 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
2354 mvmsta->sta_id, tid, txq_id, tid_data->ssn,
2355 tid_data->next_reclaimed);
2357 if (tid_data->ssn == tid_data->next_reclaimed) {
2358 tid_data->state = IWL_AGG_STARTING;
2359 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2361 tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA;
2368 spin_unlock(&mvm->queue_info_lock);
2370 spin_unlock_bh(&mvmsta->lock);
2375 int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2376 struct ieee80211_sta *sta, u16 tid, u8 buf_size,
2379 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2380 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2381 unsigned int wdg_timeout =
2382 iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false);
2384 bool alloc_queue = true;
2385 enum iwl_mvm_queue_status queue_status;
2388 struct iwl_trans_txq_scd_cfg cfg = {
2389 .sta_id = mvmsta->sta_id,
2391 .frame_limit = buf_size,
2395 BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE)
2396 != IWL_MAX_TID_COUNT);
2398 buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
2400 spin_lock_bh(&mvmsta->lock);
2401 ssn = tid_data->ssn;
2402 queue = tid_data->txq_id;
2403 tid_data->state = IWL_AGG_ON;
2404 mvmsta->agg_tids |= BIT(tid);
2405 tid_data->ssn = 0xffff;
2406 tid_data->amsdu_in_ampdu_allowed = amsdu;
2407 spin_unlock_bh(&mvmsta->lock);
2409 cfg.fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
2411 spin_lock_bh(&mvm->queue_info_lock);
2412 queue_status = mvm->queue_info[queue].status;
2413 spin_unlock_bh(&mvm->queue_info_lock);
2415 /* In DQA mode, the existing queue might need to be reconfigured */
2416 if (iwl_mvm_is_dqa_supported(mvm)) {
2417 /* Maybe there is no need to even alloc a queue... */
2418 if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_READY)
2419 alloc_queue = false;
2422 * Only reconfig the SCD for the queue if the window size has
2423 * changed from current (become smaller)
2425 if (!alloc_queue && buf_size < mvmsta->max_agg_bufsize) {
2427 * If reconfiguring an existing queue, it first must be
2430 ret = iwl_trans_wait_tx_queue_empty(mvm->trans,
2434 "Error draining queue before reconfig\n");
2438 ret = iwl_mvm_reconfig_scd(mvm, queue, cfg.fifo,
2439 mvmsta->sta_id, tid,
2443 "Error reconfiguring TXQ #%d\n", queue);
2450 iwl_mvm_enable_txq(mvm, queue,
2451 vif->hw_queue[tid_to_mac80211_ac[tid]], ssn,
2454 /* Send ADD_STA command to enable aggs only if the queue isn't shared */
2455 if (queue_status != IWL_MVM_QUEUE_SHARED) {
2456 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
2461 /* No need to mark as reserved */
2462 spin_lock_bh(&mvm->queue_info_lock);
2463 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
2464 spin_unlock_bh(&mvm->queue_info_lock);
2467 * Even though in theory the peer could have different
2468 * aggregation reorder buffer sizes for different sessions,
2469 * our ucode doesn't allow for that and has a global limit
2470 * for each station. Therefore, use the minimum of all the
2471 * aggregation sessions and our default value.
2473 mvmsta->max_agg_bufsize =
2474 min(mvmsta->max_agg_bufsize, buf_size);
2475 mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize;
2477 IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n",
2480 return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false);
2483 int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2484 struct ieee80211_sta *sta, u16 tid)
2486 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2487 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2492 * If mac80211 is cleaning its state, then say that we finished since
2493 * our state has been cleared anyway.
2495 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2496 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2500 spin_lock_bh(&mvmsta->lock);
2502 txq_id = tid_data->txq_id;
2504 IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n",
2505 mvmsta->sta_id, tid, txq_id, tid_data->state);
2507 mvmsta->agg_tids &= ~BIT(tid);
2509 spin_lock_bh(&mvm->queue_info_lock);
2511 * The TXQ is marked as reserved only if no traffic came through yet
2512 * This means no traffic has been sent on this TID (agg'd or not), so
2513 * we no longer have use for the queue. Since it hasn't even been
2514 * allocated through iwl_mvm_enable_txq, so we can just mark it back as
2517 if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED)
2518 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE;
2520 spin_unlock_bh(&mvm->queue_info_lock);
2522 switch (tid_data->state) {
2524 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
2526 IWL_DEBUG_TX_QUEUES(mvm,
2527 "ssn = %d, next_recl = %d\n",
2528 tid_data->ssn, tid_data->next_reclaimed);
2530 /* There are still packets for this RA / TID in the HW */
2531 if (tid_data->ssn != tid_data->next_reclaimed) {
2532 tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA;
2537 tid_data->ssn = 0xffff;
2538 tid_data->state = IWL_AGG_OFF;
2539 spin_unlock_bh(&mvmsta->lock);
2541 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2543 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
2545 if (!iwl_mvm_is_dqa_supported(mvm)) {
2546 int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]];
2548 iwl_mvm_disable_txq(mvm, txq_id, mac_queue, tid, 0);
2551 case IWL_AGG_STARTING:
2552 case IWL_EMPTYING_HW_QUEUE_ADDBA:
2554 * The agg session has been stopped before it was set up. This
2555 * can happen when the AddBA timer times out for example.
2558 /* No barriers since we are under mutex */
2559 lockdep_assert_held(&mvm->mutex);
2561 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2562 tid_data->state = IWL_AGG_OFF;
2567 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
2568 mvmsta->sta_id, tid, tid_data->state);
2570 "\ttid_data->txq_id = %d\n", tid_data->txq_id);
2574 spin_unlock_bh(&mvmsta->lock);
2579 int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2580 struct ieee80211_sta *sta, u16 tid)
2582 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
2583 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2585 enum iwl_mvm_agg_state old_state;
2588 * First set the agg state to OFF to avoid calling
2589 * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
2591 spin_lock_bh(&mvmsta->lock);
2592 txq_id = tid_data->txq_id;
2593 IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n",
2594 mvmsta->sta_id, tid, txq_id, tid_data->state);
2595 old_state = tid_data->state;
2596 tid_data->state = IWL_AGG_OFF;
2597 mvmsta->agg_tids &= ~BIT(tid);
2598 spin_unlock_bh(&mvmsta->lock);
2600 spin_lock_bh(&mvm->queue_info_lock);
2602 * The TXQ is marked as reserved only if no traffic came through yet
2603 * This means no traffic has been sent on this TID (agg'd or not), so
2604 * we no longer have use for the queue. Since it hasn't even been
2605 * allocated through iwl_mvm_enable_txq, so we can just mark it back as
2608 if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED)
2609 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE;
2610 spin_unlock_bh(&mvm->queue_info_lock);
2612 if (old_state >= IWL_AGG_ON) {
2613 iwl_mvm_drain_sta(mvm, mvmsta, true);
2614 if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0))
2615 IWL_ERR(mvm, "Couldn't flush the AGG queue\n");
2616 iwl_trans_wait_tx_queue_empty(mvm->trans,
2617 mvmsta->tfd_queue_msk);
2618 iwl_mvm_drain_sta(mvm, mvmsta, false);
2620 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
2622 if (!iwl_mvm_is_dqa_supported(mvm)) {
2623 int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]];
2625 iwl_mvm_disable_txq(mvm, tid_data->txq_id, mac_queue,
2633 static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm)
2635 int i, max = -1, max_offs = -1;
2637 lockdep_assert_held(&mvm->mutex);
2639 /* Pick the unused key offset with the highest 'deleted'
2640 * counter. Every time a key is deleted, all the counters
2641 * are incremented and the one that was just deleted is
2642 * reset to zero. Thus, the highest counter is the one
2643 * that was deleted longest ago. Pick that one.
2645 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
2646 if (test_bit(i, mvm->fw_key_table))
2648 if (mvm->fw_key_deleted[i] > max) {
2649 max = mvm->fw_key_deleted[i];
2655 return STA_KEY_IDX_INVALID;
2660 static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm,
2661 struct ieee80211_vif *vif,
2662 struct ieee80211_sta *sta)
2664 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2667 return iwl_mvm_sta_from_mac80211(sta);
2670 * The device expects GTKs for station interfaces to be
2671 * installed as GTKs for the AP station. If we have no
2672 * station ID, then use AP's station ID.
2674 if (vif->type == NL80211_IFTYPE_STATION &&
2675 mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
2676 u8 sta_id = mvmvif->ap_sta_id;
2678 sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id],
2679 lockdep_is_held(&mvm->mutex));
2682 * It is possible that the 'sta' parameter is NULL,
2683 * for example when a GTK is removed - the sta_id will then
2684 * be the AP ID, and no station was passed by mac80211.
2686 if (IS_ERR_OR_NULL(sta))
2689 return iwl_mvm_sta_from_mac80211(sta);
2695 static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm,
2696 struct iwl_mvm_sta *mvm_sta,
2697 struct ieee80211_key_conf *keyconf, bool mcast,
2698 u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags,
2701 struct iwl_mvm_add_sta_key_cmd cmd = {};
2707 u8 sta_id = mvm_sta->sta_id;
2709 keyidx = (keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
2710 STA_KEY_FLG_KEYID_MSK;
2711 key_flags = cpu_to_le16(keyidx);
2712 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP);
2714 switch (keyconf->cipher) {
2715 case WLAN_CIPHER_SUITE_TKIP:
2716 key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP);
2717 cmd.tkip_rx_tsc_byte2 = tkip_iv32;
2718 for (i = 0; i < 5; i++)
2719 cmd.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]);
2720 memcpy(cmd.key, keyconf->key, keyconf->keylen);
2722 case WLAN_CIPHER_SUITE_CCMP:
2723 key_flags |= cpu_to_le16(STA_KEY_FLG_CCM);
2724 memcpy(cmd.key, keyconf->key, keyconf->keylen);
2726 case WLAN_CIPHER_SUITE_WEP104:
2727 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES);
2729 case WLAN_CIPHER_SUITE_WEP40:
2730 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP);
2731 memcpy(cmd.key + 3, keyconf->key, keyconf->keylen);
2733 case WLAN_CIPHER_SUITE_GCMP_256:
2734 key_flags |= cpu_to_le16(STA_KEY_FLG_KEY_32BYTES);
2736 case WLAN_CIPHER_SUITE_GCMP:
2737 key_flags |= cpu_to_le16(STA_KEY_FLG_GCMP);
2738 memcpy(cmd.key, keyconf->key, keyconf->keylen);
2741 key_flags |= cpu_to_le16(STA_KEY_FLG_EXT);
2742 memcpy(cmd.key, keyconf->key, keyconf->keylen);
2746 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
2748 cmd.key_offset = key_offset;
2749 cmd.key_flags = key_flags;
2750 cmd.sta_id = sta_id;
2752 status = ADD_STA_SUCCESS;
2753 if (cmd_flags & CMD_ASYNC)
2754 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC,
2757 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd),
2761 case ADD_STA_SUCCESS:
2762 IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n");
2766 IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n");
2773 static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm,
2774 struct ieee80211_key_conf *keyconf,
2775 u8 sta_id, bool remove_key)
2777 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {};
2779 /* verify the key details match the required command's expectations */
2780 if (WARN_ON((keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) ||
2781 (keyconf->keyidx != 4 && keyconf->keyidx != 5) ||
2782 (keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC &&
2783 keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_128 &&
2784 keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_256)))
2787 if (WARN_ON(!iwl_mvm_has_new_rx_api(mvm) &&
2788 keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC))
2791 igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx);
2792 igtk_cmd.sta_id = cpu_to_le32(sta_id);
2795 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID);
2797 struct ieee80211_key_seq seq;
2800 switch (keyconf->cipher) {
2801 case WLAN_CIPHER_SUITE_AES_CMAC:
2802 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_CCM);
2804 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2805 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2806 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_GCMP);
2812 memcpy(igtk_cmd.igtk, keyconf->key, keyconf->keylen);
2813 if (keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
2814 igtk_cmd.ctrl_flags |=
2815 cpu_to_le32(STA_KEY_FLG_KEY_32BYTES);
2816 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
2817 pn = seq.aes_cmac.pn;
2818 igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) |
2819 ((u64) pn[4] << 8) |
2820 ((u64) pn[3] << 16) |
2821 ((u64) pn[2] << 24) |
2822 ((u64) pn[1] << 32) |
2823 ((u64) pn[0] << 40));
2826 IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n",
2827 remove_key ? "removing" : "installing",
2830 if (!iwl_mvm_has_new_rx_api(mvm)) {
2831 struct iwl_mvm_mgmt_mcast_key_cmd_v1 igtk_cmd_v1 = {
2832 .ctrl_flags = igtk_cmd.ctrl_flags,
2833 .key_id = igtk_cmd.key_id,
2834 .sta_id = igtk_cmd.sta_id,
2835 .receive_seq_cnt = igtk_cmd.receive_seq_cnt
2838 memcpy(igtk_cmd_v1.igtk, igtk_cmd.igtk,
2839 ARRAY_SIZE(igtk_cmd_v1.igtk));
2840 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
2841 sizeof(igtk_cmd_v1), &igtk_cmd_v1);
2843 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
2844 sizeof(igtk_cmd), &igtk_cmd);
2848 static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm,
2849 struct ieee80211_vif *vif,
2850 struct ieee80211_sta *sta)
2852 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2857 if (vif->type == NL80211_IFTYPE_STATION &&
2858 mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
2859 u8 sta_id = mvmvif->ap_sta_id;
2860 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
2861 lockdep_is_held(&mvm->mutex));
2869 static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
2870 struct ieee80211_vif *vif,
2871 struct ieee80211_sta *sta,
2872 struct ieee80211_key_conf *keyconf,
2876 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2879 struct ieee80211_key_seq seq;
2882 switch (keyconf->cipher) {
2883 case WLAN_CIPHER_SUITE_TKIP:
2884 addr = iwl_mvm_get_mac_addr(mvm, vif, sta);
2885 /* get phase 1 key from mac80211 */
2886 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
2887 ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k);
2888 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
2889 seq.tkip.iv32, p1k, 0, key_offset);
2891 case WLAN_CIPHER_SUITE_CCMP:
2892 case WLAN_CIPHER_SUITE_WEP40:
2893 case WLAN_CIPHER_SUITE_WEP104:
2894 case WLAN_CIPHER_SUITE_GCMP:
2895 case WLAN_CIPHER_SUITE_GCMP_256:
2896 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
2897 0, NULL, 0, key_offset);
2900 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
2901 0, NULL, 0, key_offset);
2907 static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id,
2908 struct ieee80211_key_conf *keyconf,
2911 struct iwl_mvm_add_sta_key_cmd cmd = {};
2916 key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
2917 STA_KEY_FLG_KEYID_MSK);
2918 key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP);
2919 key_flags |= cpu_to_le16(STA_KEY_NOT_VALID);
2922 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
2924 cmd.key_flags = key_flags;
2925 cmd.key_offset = keyconf->hw_key_idx;
2926 cmd.sta_id = sta_id;
2928 status = ADD_STA_SUCCESS;
2929 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd),
2933 case ADD_STA_SUCCESS:
2934 IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n");
2938 IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n");
2945 int iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
2946 struct ieee80211_vif *vif,
2947 struct ieee80211_sta *sta,
2948 struct ieee80211_key_conf *keyconf,
2951 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
2952 struct iwl_mvm_sta *mvm_sta;
2955 static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0};
2957 lockdep_assert_held(&mvm->mutex);
2959 /* Get the station id from the mvm local station table */
2960 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
2962 IWL_ERR(mvm, "Failed to find station\n");
2965 sta_id = mvm_sta->sta_id;
2967 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
2968 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
2969 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) {
2970 ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false);
2975 * It is possible that the 'sta' parameter is NULL, and thus
2976 * there is a need to retrieve the sta from the local station table.
2979 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
2980 lockdep_is_held(&mvm->mutex));
2981 if (IS_ERR_OR_NULL(sta)) {
2982 IWL_ERR(mvm, "Invalid station id\n");
2987 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif))
2990 /* If the key_offset is not pre-assigned, we need to find a
2991 * new offset to use. In normal cases, the offset is not
2992 * pre-assigned, but during HW_RESTART we want to reuse the
2993 * same indices, so we pass them when this function is called.
2995 * In D3 entry, we need to hardcoded the indices (because the
2996 * firmware hardcodes the PTK offset to 0). In this case, we
2997 * need to make sure we don't overwrite the hw_key_idx in the
2998 * keyconf structure, because otherwise we cannot configure
2999 * the original ones back when resuming.
3001 if (key_offset == STA_KEY_IDX_INVALID) {
3002 key_offset = iwl_mvm_set_fw_key_idx(mvm);
3003 if (key_offset == STA_KEY_IDX_INVALID)
3005 keyconf->hw_key_idx = key_offset;
3008 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, key_offset, mcast);
3013 * For WEP, the same key is used for multicast and unicast. Upload it
3014 * again, using the same key offset, and now pointing the other one
3015 * to the same key slot (offset).
3016 * If this fails, remove the original as well.
3018 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3019 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) {
3020 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf,
3021 key_offset, !mcast);
3023 __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
3028 __set_bit(key_offset, mvm->fw_key_table);
3031 IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
3032 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
3033 sta ? sta->addr : zero_addr, ret);
3037 int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm,
3038 struct ieee80211_vif *vif,
3039 struct ieee80211_sta *sta,
3040 struct ieee80211_key_conf *keyconf)
3042 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
3043 struct iwl_mvm_sta *mvm_sta;
3044 u8 sta_id = IWL_MVM_STATION_COUNT;
3047 lockdep_assert_held(&mvm->mutex);
3049 /* Get the station from the mvm local station table */
3050 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
3052 IWL_ERR(mvm, "Failed to find station\n");
3055 sta_id = mvm_sta->sta_id;
3057 IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n",
3058 keyconf->keyidx, sta_id);
3060 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3061 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3062 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3063 return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true);
3065 if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) {
3066 IWL_ERR(mvm, "offset %d not used in fw key table.\n",
3067 keyconf->hw_key_idx);
3071 /* track which key was deleted last */
3072 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
3073 if (mvm->fw_key_deleted[i] < U8_MAX)
3074 mvm->fw_key_deleted[i]++;
3076 mvm->fw_key_deleted[keyconf->hw_key_idx] = 0;
3079 IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n");
3083 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
3087 /* delete WEP key twice to get rid of (now useless) offset */
3088 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3089 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104)
3090 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast);
3095 void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm,
3096 struct ieee80211_vif *vif,
3097 struct ieee80211_key_conf *keyconf,
3098 struct ieee80211_sta *sta, u32 iv32,
3101 struct iwl_mvm_sta *mvm_sta;
3102 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
3106 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
3107 if (WARN_ON_ONCE(!mvm_sta))
3109 iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
3110 iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx);
3116 void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm,
3117 struct ieee80211_sta *sta)
3119 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3120 struct iwl_mvm_add_sta_cmd cmd = {
3121 .add_modify = STA_MODE_MODIFY,
3122 .sta_id = mvmsta->sta_id,
3123 .station_flags_msk = cpu_to_le32(STA_FLG_PS),
3124 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
3128 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
3129 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
3131 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3134 void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm,
3135 struct ieee80211_sta *sta,
3136 enum ieee80211_frame_release_type reason,
3137 u16 cnt, u16 tids, bool more_data,
3140 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
3141 struct iwl_mvm_add_sta_cmd cmd = {
3142 .add_modify = STA_MODE_MODIFY,
3143 .sta_id = mvmsta->sta_id,
3144 .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT,
3145 .sleep_tx_count = cpu_to_le16(cnt),
3146 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
3149 unsigned long _tids = tids;
3151 /* convert TIDs to ACs - we don't support TSPEC so that's OK
3152 * Note that this field is reserved and unused by firmware not
3153 * supporting GO uAPSD, so it's safe to always do this.
3155 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT)
3156 cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]);
3158 /* If we're releasing frames from aggregation queues then check if the
3159 * all queues combined that we're releasing frames from have
3160 * - more frames than the service period, in which case more_data
3162 * - fewer than 'cnt' frames, in which case we need to adjust the
3163 * firmware command (but do that unconditionally)
3166 int remaining = cnt;
3169 spin_lock_bh(&mvmsta->lock);
3170 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) {
3171 struct iwl_mvm_tid_data *tid_data;
3174 tid_data = &mvmsta->tid_data[tid];
3175 if (WARN(tid_data->state != IWL_AGG_ON &&
3176 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA,
3177 "TID %d state is %d\n",
3178 tid, tid_data->state)) {
3179 spin_unlock_bh(&mvmsta->lock);
3180 ieee80211_sta_eosp(sta);
3184 n_queued = iwl_mvm_tid_queued(tid_data);
3185 if (n_queued > remaining) {
3190 remaining -= n_queued;
3192 sleep_tx_count = cnt - remaining;
3193 if (reason == IEEE80211_FRAME_RELEASE_UAPSD)
3194 mvmsta->sleep_tx_count = sleep_tx_count;
3195 spin_unlock_bh(&mvmsta->lock);
3197 cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count);
3198 if (WARN_ON(cnt - remaining == 0)) {
3199 ieee80211_sta_eosp(sta);
3204 /* Note: this is ignored by firmware not supporting GO uAPSD */
3206 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA);
3208 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) {
3209 mvmsta->next_status_eosp = true;
3210 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL);
3212 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD);
3215 /* block the Tx queues until the FW updated the sleep Tx count */
3216 iwl_trans_block_txq_ptrs(mvm->trans, true);
3218 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA,
3219 CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK,
3220 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
3222 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3225 void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm,
3226 struct iwl_rx_cmd_buffer *rxb)
3228 struct iwl_rx_packet *pkt = rxb_addr(rxb);
3229 struct iwl_mvm_eosp_notification *notif = (void *)pkt->data;
3230 struct ieee80211_sta *sta;
3231 u32 sta_id = le32_to_cpu(notif->sta_id);
3233 if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT))
3237 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
3238 if (!IS_ERR_OR_NULL(sta))
3239 ieee80211_sta_eosp(sta);
3243 void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm,
3244 struct iwl_mvm_sta *mvmsta, bool disable)
3246 struct iwl_mvm_add_sta_cmd cmd = {
3247 .add_modify = STA_MODE_MODIFY,
3248 .sta_id = mvmsta->sta_id,
3249 .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0,
3250 .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX),
3251 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
3255 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
3256 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
3258 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3261 void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm,
3262 struct ieee80211_sta *sta,
3265 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3267 spin_lock_bh(&mvm_sta->lock);
3269 if (mvm_sta->disable_tx == disable) {
3270 spin_unlock_bh(&mvm_sta->lock);
3274 mvm_sta->disable_tx = disable;
3277 * Tell mac80211 to start/stop queuing tx for this station,
3278 * but don't stop queuing if there are still pending frames
3281 if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id]))
3282 ieee80211_sta_block_awake(mvm->hw, sta, disable);
3284 iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable);
3286 spin_unlock_bh(&mvm_sta->lock);
3289 void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm,
3290 struct iwl_mvm_vif *mvmvif,
3293 struct ieee80211_sta *sta;
3294 struct iwl_mvm_sta *mvm_sta;
3297 lockdep_assert_held(&mvm->mutex);
3299 /* Block/unblock all the stations of the given mvmvif */
3300 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
3301 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3302 lockdep_is_held(&mvm->mutex));
3303 if (IS_ERR_OR_NULL(sta))
3306 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3307 if (mvm_sta->mac_id_n_color !=
3308 FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color))
3311 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable);
3315 void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
3317 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3318 struct iwl_mvm_sta *mvmsta;
3322 mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id);
3324 if (!WARN_ON(!mvmsta))
3325 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true);