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 - 2017 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 - 2017 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 if (iwl_mvm_has_new_rx_api(mvm
) ||
81 fw_has_api(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_API_STA_TYPE
))
82 return sizeof(struct iwl_mvm_add_sta_cmd
);
84 return sizeof(struct iwl_mvm_add_sta_cmd_v7
);
87 static int iwl_mvm_find_free_sta_id(struct iwl_mvm
*mvm
,
88 enum nl80211_iftype iftype
)
93 BUILD_BUG_ON(IWL_MVM_STATION_COUNT
> 32);
94 WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
));
96 lockdep_assert_held(&mvm
->mutex
);
98 /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */
99 if (iftype
!= NL80211_IFTYPE_STATION
)
100 reserved_ids
= BIT(0);
102 /* Don't take rcu_read_lock() since we are protected by mvm->mutex */
103 for (sta_id
= 0; sta_id
< ARRAY_SIZE(mvm
->fw_id_to_mac_id
); sta_id
++) {
104 if (BIT(sta_id
) & reserved_ids
)
107 if (!rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
108 lockdep_is_held(&mvm
->mutex
)))
111 return IWL_MVM_INVALID_STA
;
114 /* send station add/update command to firmware */
115 int iwl_mvm_sta_send_to_fw(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
116 bool update
, unsigned int flags
)
118 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
119 struct iwl_mvm_add_sta_cmd add_sta_cmd
= {
120 .sta_id
= mvm_sta
->sta_id
,
121 .mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
),
122 .add_modify
= update
? 1 : 0,
123 .station_flags_msk
= cpu_to_le32(STA_FLG_FAT_EN_MSK
|
124 STA_FLG_MIMO_EN_MSK
),
125 .tid_disable_tx
= cpu_to_le16(mvm_sta
->tid_disable_agg
),
129 u32 agg_size
= 0, mpdu_dens
= 0;
131 if (fw_has_api(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_API_STA_TYPE
))
132 add_sta_cmd
.station_type
= mvm_sta
->sta_type
;
134 if (!update
|| (flags
& STA_MODIFY_QUEUES
)) {
135 memcpy(&add_sta_cmd
.addr
, sta
->addr
, ETH_ALEN
);
137 if (!iwl_mvm_has_new_tx_api(mvm
)) {
138 add_sta_cmd
.tfd_queue_msk
=
139 cpu_to_le32(mvm_sta
->tfd_queue_msk
);
141 if (flags
& STA_MODIFY_QUEUES
)
142 add_sta_cmd
.modify_mask
|= STA_MODIFY_QUEUES
;
144 WARN_ON(flags
& STA_MODIFY_QUEUES
);
148 switch (sta
->bandwidth
) {
149 case IEEE80211_STA_RX_BW_160
:
150 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_FAT_EN_160MHZ
);
152 case IEEE80211_STA_RX_BW_80
:
153 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_FAT_EN_80MHZ
);
155 case IEEE80211_STA_RX_BW_40
:
156 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_FAT_EN_40MHZ
);
158 case IEEE80211_STA_RX_BW_20
:
159 if (sta
->ht_cap
.ht_supported
)
160 add_sta_cmd
.station_flags
|=
161 cpu_to_le32(STA_FLG_FAT_EN_20MHZ
);
165 switch (sta
->rx_nss
) {
167 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_SISO
);
170 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2
);
173 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3
);
177 switch (sta
->smps_mode
) {
178 case IEEE80211_SMPS_AUTOMATIC
:
179 case IEEE80211_SMPS_NUM_MODES
:
182 case IEEE80211_SMPS_STATIC
:
184 add_sta_cmd
.station_flags
&= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK
);
185 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_SISO
);
187 case IEEE80211_SMPS_DYNAMIC
:
188 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_RTS_MIMO_PROT
);
190 case IEEE80211_SMPS_OFF
:
195 if (sta
->ht_cap
.ht_supported
) {
196 add_sta_cmd
.station_flags_msk
|=
197 cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK
|
198 STA_FLG_AGG_MPDU_DENS_MSK
);
200 mpdu_dens
= sta
->ht_cap
.ampdu_density
;
203 if (sta
->vht_cap
.vht_supported
) {
204 agg_size
= sta
->vht_cap
.cap
&
205 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
;
207 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
208 } else if (sta
->ht_cap
.ht_supported
) {
209 agg_size
= sta
->ht_cap
.ampdu_factor
;
212 add_sta_cmd
.station_flags
|=
213 cpu_to_le32(agg_size
<< STA_FLG_MAX_AGG_SIZE_SHIFT
);
214 add_sta_cmd
.station_flags
|=
215 cpu_to_le32(mpdu_dens
<< STA_FLG_AGG_MPDU_DENS_SHIFT
);
216 if (mvm_sta
->associated
)
217 add_sta_cmd
.assoc_id
= cpu_to_le16(sta
->aid
);
220 add_sta_cmd
.modify_mask
|= STA_MODIFY_UAPSD_ACS
;
222 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BK
)
223 add_sta_cmd
.uapsd_acs
|= BIT(AC_BK
);
224 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_BE
)
225 add_sta_cmd
.uapsd_acs
|= BIT(AC_BE
);
226 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VI
)
227 add_sta_cmd
.uapsd_acs
|= BIT(AC_VI
);
228 if (sta
->uapsd_queues
& IEEE80211_WMM_IE_STA_QOSINFO_AC_VO
)
229 add_sta_cmd
.uapsd_acs
|= BIT(AC_VO
);
230 add_sta_cmd
.uapsd_acs
|= add_sta_cmd
.uapsd_acs
<< 4;
231 add_sta_cmd
.sp_length
= sta
->max_sp
? sta
->max_sp
* 2 : 128;
234 status
= ADD_STA_SUCCESS
;
235 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
,
236 iwl_mvm_add_sta_cmd_size(mvm
),
237 &add_sta_cmd
, &status
);
241 switch (status
& IWL_ADD_STA_STATUS_MASK
) {
242 case ADD_STA_SUCCESS
:
243 IWL_DEBUG_ASSOC(mvm
, "ADD_STA PASSED\n");
247 IWL_ERR(mvm
, "ADD_STA failed\n");
254 static void iwl_mvm_rx_agg_session_expired(unsigned long data
)
256 struct iwl_mvm_baid_data __rcu
**rcu_ptr
= (void *)data
;
257 struct iwl_mvm_baid_data
*ba_data
;
258 struct ieee80211_sta
*sta
;
259 struct iwl_mvm_sta
*mvm_sta
;
260 unsigned long timeout
;
264 ba_data
= rcu_dereference(*rcu_ptr
);
266 if (WARN_ON(!ba_data
))
269 if (!ba_data
->timeout
)
272 timeout
= ba_data
->last_rx
+ TU_TO_JIFFIES(ba_data
->timeout
* 2);
273 if (time_is_after_jiffies(timeout
)) {
274 mod_timer(&ba_data
->session_timer
, timeout
);
279 sta
= rcu_dereference(ba_data
->mvm
->fw_id_to_mac_id
[ba_data
->sta_id
]);
280 mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
281 ieee80211_stop_rx_ba_session_offl(mvm_sta
->vif
,
282 sta
->addr
, ba_data
->tid
);
287 static int iwl_mvm_tdls_sta_init(struct iwl_mvm
*mvm
,
288 struct ieee80211_sta
*sta
)
290 unsigned long used_hw_queues
;
291 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
292 unsigned int wdg_timeout
=
293 iwl_mvm_get_wd_timeout(mvm
, NULL
, true, false);
296 lockdep_assert_held(&mvm
->mutex
);
298 used_hw_queues
= iwl_mvm_get_used_hw_queues(mvm
, NULL
);
300 /* Find available queues, and allocate them to the ACs */
301 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
302 u8 queue
= find_first_zero_bit(&used_hw_queues
,
303 mvm
->first_agg_queue
);
305 if (queue
>= mvm
->first_agg_queue
) {
306 IWL_ERR(mvm
, "Failed to allocate STA queue\n");
310 __set_bit(queue
, &used_hw_queues
);
311 mvmsta
->hw_queue
[ac
] = queue
;
314 /* Found a place for all queues - enable them */
315 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
316 iwl_mvm_enable_ac_txq(mvm
, mvmsta
->hw_queue
[ac
],
317 mvmsta
->hw_queue
[ac
],
318 iwl_mvm_ac_to_tx_fifo
[ac
], 0,
320 mvmsta
->tfd_queue_msk
|= BIT(mvmsta
->hw_queue
[ac
]);
326 static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm
*mvm
,
327 struct ieee80211_sta
*sta
)
329 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
330 unsigned long sta_msk
;
333 lockdep_assert_held(&mvm
->mutex
);
335 /* disable the TDLS STA-specific queues */
336 sta_msk
= mvmsta
->tfd_queue_msk
;
337 for_each_set_bit(i
, &sta_msk
, sizeof(sta_msk
) * BITS_PER_BYTE
)
338 iwl_mvm_disable_txq(mvm
, i
, i
, IWL_MAX_TID_COUNT
, 0);
341 /* Disable aggregations for a bitmap of TIDs for a given station */
342 static int iwl_mvm_invalidate_sta_queue(struct iwl_mvm
*mvm
, int queue
,
343 unsigned long disable_agg_tids
,
346 struct iwl_mvm_add_sta_cmd cmd
= {};
347 struct ieee80211_sta
*sta
;
348 struct iwl_mvm_sta
*mvmsta
;
353 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm
)))
356 spin_lock_bh(&mvm
->queue_info_lock
);
357 sta_id
= mvm
->queue_info
[queue
].ra_sta_id
;
358 spin_unlock_bh(&mvm
->queue_info_lock
);
362 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
364 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta
))) {
369 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
371 mvmsta
->tid_disable_agg
|= disable_agg_tids
;
373 cmd
.mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
);
374 cmd
.sta_id
= mvmsta
->sta_id
;
375 cmd
.add_modify
= STA_MODE_MODIFY
;
376 cmd
.modify_mask
= STA_MODIFY_QUEUES
;
377 if (disable_agg_tids
)
378 cmd
.modify_mask
|= STA_MODIFY_TID_DISABLE_TX
;
380 cmd
.modify_mask
|= STA_MODIFY_QUEUE_REMOVAL
;
381 cmd
.tfd_queue_msk
= cpu_to_le32(mvmsta
->tfd_queue_msk
);
382 cmd
.tid_disable_tx
= cpu_to_le16(mvmsta
->tid_disable_agg
);
386 /* Notify FW of queue removal from the STA queues */
387 status
= ADD_STA_SUCCESS
;
388 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
,
389 iwl_mvm_add_sta_cmd_size(mvm
),
395 static int iwl_mvm_get_queue_agg_tids(struct iwl_mvm
*mvm
, int queue
)
397 struct ieee80211_sta
*sta
;
398 struct iwl_mvm_sta
*mvmsta
;
399 unsigned long tid_bitmap
;
400 unsigned long agg_tids
= 0;
404 lockdep_assert_held(&mvm
->mutex
);
406 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm
)))
409 spin_lock_bh(&mvm
->queue_info_lock
);
410 sta_id
= mvm
->queue_info
[queue
].ra_sta_id
;
411 tid_bitmap
= mvm
->queue_info
[queue
].tid_bitmap
;
412 spin_unlock_bh(&mvm
->queue_info_lock
);
414 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
415 lockdep_is_held(&mvm
->mutex
));
417 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta
)))
420 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
422 spin_lock_bh(&mvmsta
->lock
);
423 for_each_set_bit(tid
, &tid_bitmap
, IWL_MAX_TID_COUNT
+ 1) {
424 if (mvmsta
->tid_data
[tid
].state
== IWL_AGG_ON
)
425 agg_tids
|= BIT(tid
);
427 spin_unlock_bh(&mvmsta
->lock
);
433 * Remove a queue from a station's resources.
434 * Note that this only marks as free. It DOESN'T delete a BA agreement, and
435 * doesn't disable the queue
437 static int iwl_mvm_remove_sta_queue_marking(struct iwl_mvm
*mvm
, int queue
)
439 struct ieee80211_sta
*sta
;
440 struct iwl_mvm_sta
*mvmsta
;
441 unsigned long tid_bitmap
;
442 unsigned long disable_agg_tids
= 0;
446 lockdep_assert_held(&mvm
->mutex
);
448 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm
)))
451 spin_lock_bh(&mvm
->queue_info_lock
);
452 sta_id
= mvm
->queue_info
[queue
].ra_sta_id
;
453 tid_bitmap
= mvm
->queue_info
[queue
].tid_bitmap
;
454 spin_unlock_bh(&mvm
->queue_info_lock
);
458 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
460 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta
))) {
465 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
467 spin_lock_bh(&mvmsta
->lock
);
468 /* Unmap MAC queues and TIDs from this queue */
469 for_each_set_bit(tid
, &tid_bitmap
, IWL_MAX_TID_COUNT
+ 1) {
470 if (mvmsta
->tid_data
[tid
].state
== IWL_AGG_ON
)
471 disable_agg_tids
|= BIT(tid
);
472 mvmsta
->tid_data
[tid
].txq_id
= IWL_MVM_INVALID_QUEUE
;
475 mvmsta
->tfd_queue_msk
&= ~BIT(queue
); /* Don't use this queue anymore */
476 spin_unlock_bh(&mvmsta
->lock
);
480 return disable_agg_tids
;
483 static int iwl_mvm_free_inactive_queue(struct iwl_mvm
*mvm
, int queue
,
486 struct iwl_mvm_sta
*mvmsta
;
487 u8 txq_curr_ac
, sta_id
, tid
;
488 unsigned long disable_agg_tids
= 0;
491 lockdep_assert_held(&mvm
->mutex
);
493 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm
)))
496 spin_lock_bh(&mvm
->queue_info_lock
);
497 txq_curr_ac
= mvm
->queue_info
[queue
].mac80211_ac
;
498 sta_id
= mvm
->queue_info
[queue
].ra_sta_id
;
499 tid
= mvm
->queue_info
[queue
].txq_tid
;
500 spin_unlock_bh(&mvm
->queue_info_lock
);
502 mvmsta
= iwl_mvm_sta_from_staid_protected(mvm
, sta_id
);
503 if (WARN_ON(!mvmsta
))
506 disable_agg_tids
= iwl_mvm_remove_sta_queue_marking(mvm
, queue
);
507 /* Disable the queue */
508 if (disable_agg_tids
)
509 iwl_mvm_invalidate_sta_queue(mvm
, queue
,
510 disable_agg_tids
, false);
512 ret
= iwl_mvm_disable_txq(mvm
, queue
,
513 mvmsta
->vif
->hw_queue
[txq_curr_ac
],
516 /* Re-mark the inactive queue as inactive */
517 spin_lock_bh(&mvm
->queue_info_lock
);
518 mvm
->queue_info
[queue
].status
= IWL_MVM_QUEUE_INACTIVE
;
519 spin_unlock_bh(&mvm
->queue_info_lock
);
521 "Failed to free inactive queue %d (ret=%d)\n",
527 /* If TXQ is allocated to another STA, update removal in FW */
529 iwl_mvm_invalidate_sta_queue(mvm
, queue
, 0, true);
534 static int iwl_mvm_get_shared_queue(struct iwl_mvm
*mvm
,
535 unsigned long tfd_queue_mask
, u8 ac
)
538 u8 ac_to_queue
[IEEE80211_NUM_ACS
];
541 lockdep_assert_held(&mvm
->queue_info_lock
);
542 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm
)))
545 memset(&ac_to_queue
, IEEE80211_INVAL_HW_QUEUE
, sizeof(ac_to_queue
));
547 /* See what ACs the existing queues for this STA have */
548 for_each_set_bit(i
, &tfd_queue_mask
, IWL_MVM_DQA_MAX_DATA_QUEUE
) {
549 /* Only DATA queues can be shared */
550 if (i
< IWL_MVM_DQA_MIN_DATA_QUEUE
&&
551 i
!= IWL_MVM_DQA_BSS_CLIENT_QUEUE
)
554 /* Don't try and take queues being reconfigured */
555 if (mvm
->queue_info
[queue
].status
==
556 IWL_MVM_QUEUE_RECONFIGURING
)
559 ac_to_queue
[mvm
->queue_info
[i
].mac80211_ac
] = i
;
563 * The queue to share is chosen only from DATA queues as follows (in
564 * descending priority):
567 * 3. Highest AC queue that is lower than new AC
568 * 4. Any existing AC (there always is at least 1 DATA queue)
571 /* Priority 1: An AC_BE queue */
572 if (ac_to_queue
[IEEE80211_AC_BE
] != IEEE80211_INVAL_HW_QUEUE
)
573 queue
= ac_to_queue
[IEEE80211_AC_BE
];
574 /* Priority 2: Same AC queue */
575 else if (ac_to_queue
[ac
] != IEEE80211_INVAL_HW_QUEUE
)
576 queue
= ac_to_queue
[ac
];
577 /* Priority 3a: If new AC is VO and VI exists - use VI */
578 else if (ac
== IEEE80211_AC_VO
&&
579 ac_to_queue
[IEEE80211_AC_VI
] != IEEE80211_INVAL_HW_QUEUE
)
580 queue
= ac_to_queue
[IEEE80211_AC_VI
];
581 /* Priority 3b: No BE so only AC less than the new one is BK */
582 else if (ac_to_queue
[IEEE80211_AC_BK
] != IEEE80211_INVAL_HW_QUEUE
)
583 queue
= ac_to_queue
[IEEE80211_AC_BK
];
584 /* Priority 4a: No BE nor BK - use VI if exists */
585 else if (ac_to_queue
[IEEE80211_AC_VI
] != IEEE80211_INVAL_HW_QUEUE
)
586 queue
= ac_to_queue
[IEEE80211_AC_VI
];
587 /* Priority 4b: No BE, BK nor VI - use VO if exists */
588 else if (ac_to_queue
[IEEE80211_AC_VO
] != IEEE80211_INVAL_HW_QUEUE
)
589 queue
= ac_to_queue
[IEEE80211_AC_VO
];
591 /* Make sure queue found (or not) is legal */
592 if (!iwl_mvm_is_dqa_data_queue(mvm
, queue
) &&
593 !iwl_mvm_is_dqa_mgmt_queue(mvm
, queue
) &&
594 (queue
!= IWL_MVM_DQA_BSS_CLIENT_QUEUE
)) {
595 IWL_ERR(mvm
, "No DATA queues available to share\n");
599 /* Make sure the queue isn't in the middle of being reconfigured */
600 if (mvm
->queue_info
[queue
].status
== IWL_MVM_QUEUE_RECONFIGURING
) {
602 "TXQ %d is in the middle of re-config - try again\n",
611 * If a given queue has a higher AC than the TID stream that is being compared
612 * to, the queue needs to be redirected to the lower AC. This function does that
613 * in such a case, otherwise - if no redirection required - it does nothing,
614 * unless the %force param is true.
616 int iwl_mvm_scd_queue_redirect(struct iwl_mvm
*mvm
, int queue
, int tid
,
617 int ac
, int ssn
, unsigned int wdg_timeout
,
620 struct iwl_scd_txq_cfg_cmd cmd
= {
622 .action
= SCD_CFG_DISABLE_QUEUE
,
628 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm
)))
632 * If the AC is lower than current one - FIFO needs to be redirected to
633 * the lowest one of the streams in the queue. Check if this is needed
635 * Notice that the enum ieee80211_ac_numbers is "flipped", so BK is with
636 * value 3 and VO with value 0, so to check if ac X is lower than ac Y
637 * we need to check if the numerical value of X is LARGER than of Y.
639 spin_lock_bh(&mvm
->queue_info_lock
);
640 if (ac
<= mvm
->queue_info
[queue
].mac80211_ac
&& !force
) {
641 spin_unlock_bh(&mvm
->queue_info_lock
);
643 IWL_DEBUG_TX_QUEUES(mvm
,
644 "No redirection needed on TXQ #%d\n",
649 cmd
.sta_id
= mvm
->queue_info
[queue
].ra_sta_id
;
650 cmd
.tx_fifo
= iwl_mvm_ac_to_tx_fifo
[mvm
->queue_info
[queue
].mac80211_ac
];
651 cmd
.tid
= mvm
->queue_info
[queue
].txq_tid
;
652 mq
= mvm
->hw_queue_to_mac80211
[queue
];
653 shared_queue
= (mvm
->queue_info
[queue
].hw_queue_refcount
> 1);
654 spin_unlock_bh(&mvm
->queue_info_lock
);
656 IWL_DEBUG_TX_QUEUES(mvm
, "Redirecting TXQ #%d to FIFO #%d\n",
657 queue
, iwl_mvm_ac_to_tx_fifo
[ac
]);
659 /* Stop MAC queues and wait for this queue to empty */
660 iwl_mvm_stop_mac_queues(mvm
, mq
);
661 ret
= iwl_trans_wait_tx_queues_empty(mvm
->trans
, BIT(queue
));
663 IWL_ERR(mvm
, "Error draining queue %d before reconfig\n",
669 /* Before redirecting the queue we need to de-activate it */
670 iwl_trans_txq_disable(mvm
->trans
, queue
, false);
671 ret
= iwl_mvm_send_cmd_pdu(mvm
, SCD_QUEUE_CFG
, 0, sizeof(cmd
), &cmd
);
673 IWL_ERR(mvm
, "Failed SCD disable TXQ %d (ret=%d)\n", queue
,
676 /* Make sure the SCD wrptr is correctly set before reconfiguring */
677 iwl_trans_txq_enable_cfg(mvm
->trans
, queue
, ssn
, NULL
, wdg_timeout
);
679 /* Update the TID "owner" of the queue */
680 spin_lock_bh(&mvm
->queue_info_lock
);
681 mvm
->queue_info
[queue
].txq_tid
= tid
;
682 spin_unlock_bh(&mvm
->queue_info_lock
);
684 /* TODO: Work-around SCD bug when moving back by multiples of 0x40 */
686 /* Redirect to lower AC */
687 iwl_mvm_reconfig_scd(mvm
, queue
, iwl_mvm_ac_to_tx_fifo
[ac
],
688 cmd
.sta_id
, tid
, LINK_QUAL_AGG_FRAME_LIMIT_DEF
,
691 /* Update AC marking of the queue */
692 spin_lock_bh(&mvm
->queue_info_lock
);
693 mvm
->queue_info
[queue
].mac80211_ac
= ac
;
694 spin_unlock_bh(&mvm
->queue_info_lock
);
697 * Mark queue as shared in transport if shared
698 * Note this has to be done after queue enablement because enablement
699 * can also set this value, and there is no indication there to shared
703 iwl_trans_txq_set_shared_mode(mvm
->trans
, queue
, true);
706 /* Continue using the MAC queues */
707 iwl_mvm_start_mac_queues(mvm
, mq
);
712 static int iwl_mvm_sta_alloc_queue_tvqm(struct iwl_mvm
*mvm
,
713 struct ieee80211_sta
*sta
, u8 ac
,
716 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
717 unsigned int wdg_timeout
=
718 iwl_mvm_get_wd_timeout(mvm
, mvmsta
->vif
, false, false);
719 u8 mac_queue
= mvmsta
->vif
->hw_queue
[ac
];
722 lockdep_assert_held(&mvm
->mutex
);
724 IWL_DEBUG_TX_QUEUES(mvm
,
725 "Allocating queue for sta %d on tid %d\n",
726 mvmsta
->sta_id
, tid
);
727 queue
= iwl_mvm_tvqm_enable_txq(mvm
, mac_queue
, mvmsta
->sta_id
, tid
,
732 IWL_DEBUG_TX_QUEUES(mvm
, "Allocated queue is %d\n", queue
);
734 spin_lock_bh(&mvmsta
->lock
);
735 mvmsta
->tid_data
[tid
].txq_id
= queue
;
736 mvmsta
->tid_data
[tid
].is_tid_active
= true;
737 mvmsta
->tfd_queue_msk
|= BIT(queue
);
738 spin_unlock_bh(&mvmsta
->lock
);
743 static int iwl_mvm_sta_alloc_queue(struct iwl_mvm
*mvm
,
744 struct ieee80211_sta
*sta
, u8 ac
, int tid
,
745 struct ieee80211_hdr
*hdr
)
747 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
748 struct iwl_trans_txq_scd_cfg cfg
= {
749 .fifo
= iwl_mvm_ac_to_tx_fifo
[ac
],
750 .sta_id
= mvmsta
->sta_id
,
752 .frame_limit
= IWL_FRAME_LIMIT
,
754 unsigned int wdg_timeout
=
755 iwl_mvm_get_wd_timeout(mvm
, mvmsta
->vif
, false, false);
756 u8 mac_queue
= mvmsta
->vif
->hw_queue
[ac
];
758 bool using_inactive_queue
= false, same_sta
= false;
759 unsigned long disable_agg_tids
= 0;
760 enum iwl_mvm_agg_state queue_state
;
761 bool shared_queue
= false;
763 unsigned long tfd_queue_mask
;
766 lockdep_assert_held(&mvm
->mutex
);
768 if (iwl_mvm_has_new_tx_api(mvm
))
769 return iwl_mvm_sta_alloc_queue_tvqm(mvm
, sta
, ac
, tid
);
771 spin_lock_bh(&mvmsta
->lock
);
772 tfd_queue_mask
= mvmsta
->tfd_queue_msk
;
773 spin_unlock_bh(&mvmsta
->lock
);
775 spin_lock_bh(&mvm
->queue_info_lock
);
778 * Non-QoS, QoS NDP and MGMT frames should go to a MGMT queue, if one
781 if (!ieee80211_is_data_qos(hdr
->frame_control
) ||
782 ieee80211_is_qos_nullfunc(hdr
->frame_control
)) {
783 queue
= iwl_mvm_find_free_queue(mvm
, mvmsta
->sta_id
,
784 IWL_MVM_DQA_MIN_MGMT_QUEUE
,
785 IWL_MVM_DQA_MAX_MGMT_QUEUE
);
786 if (queue
>= IWL_MVM_DQA_MIN_MGMT_QUEUE
)
787 IWL_DEBUG_TX_QUEUES(mvm
, "Found free MGMT queue #%d\n",
790 /* If no such queue is found, we'll use a DATA queue instead */
793 if ((queue
< 0 && mvmsta
->reserved_queue
!= IEEE80211_INVAL_HW_QUEUE
) &&
794 (mvm
->queue_info
[mvmsta
->reserved_queue
].status
==
795 IWL_MVM_QUEUE_RESERVED
||
796 mvm
->queue_info
[mvmsta
->reserved_queue
].status
==
797 IWL_MVM_QUEUE_INACTIVE
)) {
798 queue
= mvmsta
->reserved_queue
;
799 mvm
->queue_info
[queue
].reserved
= true;
800 IWL_DEBUG_TX_QUEUES(mvm
, "Using reserved queue #%d\n", queue
);
804 queue
= iwl_mvm_find_free_queue(mvm
, mvmsta
->sta_id
,
805 IWL_MVM_DQA_MIN_DATA_QUEUE
,
806 IWL_MVM_DQA_MAX_DATA_QUEUE
);
809 * Check if this queue is already allocated but inactive.
810 * In such a case, we'll need to first free this queue before enabling
811 * it again, so we'll mark it as reserved to make sure no new traffic
815 mvm
->queue_info
[queue
].status
== IWL_MVM_QUEUE_INACTIVE
) {
816 mvm
->queue_info
[queue
].status
= IWL_MVM_QUEUE_RESERVED
;
817 using_inactive_queue
= true;
818 same_sta
= mvm
->queue_info
[queue
].ra_sta_id
== mvmsta
->sta_id
;
819 IWL_DEBUG_TX_QUEUES(mvm
,
820 "Re-assigning TXQ %d: sta_id=%d, tid=%d\n",
821 queue
, mvmsta
->sta_id
, tid
);
824 /* No free queue - we'll have to share */
826 queue
= iwl_mvm_get_shared_queue(mvm
, tfd_queue_mask
, ac
);
829 mvm
->queue_info
[queue
].status
= IWL_MVM_QUEUE_SHARED
;
834 * Mark TXQ as ready, even though it hasn't been fully configured yet,
835 * to make sure no one else takes it.
836 * This will allow avoiding re-acquiring the lock at the end of the
837 * configuration. On error we'll mark it back as free.
839 if ((queue
> 0) && !shared_queue
)
840 mvm
->queue_info
[queue
].status
= IWL_MVM_QUEUE_READY
;
842 spin_unlock_bh(&mvm
->queue_info_lock
);
844 /* This shouldn't happen - out of queues */
845 if (WARN_ON(queue
<= 0)) {
846 IWL_ERR(mvm
, "No available queues for tid %d on sta_id %d\n",
852 * Actual en/disablement of aggregations is through the ADD_STA HCMD,
853 * but for configuring the SCD to send A-MPDUs we need to mark the queue
855 * Mark all DATA queues as allowing to be aggregated at some point
857 cfg
.aggregate
= (queue
>= IWL_MVM_DQA_MIN_DATA_QUEUE
||
858 queue
== IWL_MVM_DQA_BSS_CLIENT_QUEUE
);
861 * If this queue was previously inactive (idle) - we need to free it
864 if (using_inactive_queue
) {
865 ret
= iwl_mvm_free_inactive_queue(mvm
, queue
, same_sta
);
870 IWL_DEBUG_TX_QUEUES(mvm
,
871 "Allocating %squeue #%d to sta %d on tid %d\n",
872 shared_queue
? "shared " : "", queue
,
873 mvmsta
->sta_id
, tid
);
876 /* Disable any open aggs on this queue */
877 disable_agg_tids
= iwl_mvm_get_queue_agg_tids(mvm
, queue
);
879 if (disable_agg_tids
) {
880 IWL_DEBUG_TX_QUEUES(mvm
, "Disabling aggs on queue %d\n",
882 iwl_mvm_invalidate_sta_queue(mvm
, queue
,
883 disable_agg_tids
, false);
887 ssn
= IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr
->seq_ctrl
));
888 iwl_mvm_enable_txq(mvm
, queue
, mac_queue
, ssn
, &cfg
,
892 * Mark queue as shared in transport if shared
893 * Note this has to be done after queue enablement because enablement
894 * can also set this value, and there is no indication there to shared
898 iwl_trans_txq_set_shared_mode(mvm
->trans
, queue
, true);
900 spin_lock_bh(&mvmsta
->lock
);
901 mvmsta
->tid_data
[tid
].txq_id
= queue
;
902 mvmsta
->tid_data
[tid
].is_tid_active
= true;
903 mvmsta
->tfd_queue_msk
|= BIT(queue
);
904 queue_state
= mvmsta
->tid_data
[tid
].state
;
906 if (mvmsta
->reserved_queue
== queue
)
907 mvmsta
->reserved_queue
= IEEE80211_INVAL_HW_QUEUE
;
908 spin_unlock_bh(&mvmsta
->lock
);
911 ret
= iwl_mvm_sta_send_to_fw(mvm
, sta
, true, STA_MODIFY_QUEUES
);
915 /* If we need to re-enable aggregations... */
916 if (queue_state
== IWL_AGG_ON
) {
917 ret
= iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, queue
, true);
922 /* Redirect queue, if needed */
923 ret
= iwl_mvm_scd_queue_redirect(mvm
, queue
, tid
, ac
, ssn
,
932 iwl_mvm_disable_txq(mvm
, queue
, mac_queue
, tid
, 0);
937 static void iwl_mvm_change_queue_owner(struct iwl_mvm
*mvm
, int queue
)
939 struct iwl_scd_txq_cfg_cmd cmd
= {
941 .action
= SCD_CFG_UPDATE_QUEUE_TID
,
944 unsigned long tid_bitmap
;
947 lockdep_assert_held(&mvm
->mutex
);
949 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm
)))
952 spin_lock_bh(&mvm
->queue_info_lock
);
953 tid_bitmap
= mvm
->queue_info
[queue
].tid_bitmap
;
954 spin_unlock_bh(&mvm
->queue_info_lock
);
956 if (WARN(!tid_bitmap
, "TXQ %d has no tids assigned to it\n", queue
))
959 /* Find any TID for queue */
960 tid
= find_first_bit(&tid_bitmap
, IWL_MAX_TID_COUNT
+ 1);
962 cmd
.tx_fifo
= iwl_mvm_ac_to_tx_fifo
[tid_to_mac80211_ac
[tid
]];
964 ret
= iwl_mvm_send_cmd_pdu(mvm
, SCD_QUEUE_CFG
, 0, sizeof(cmd
), &cmd
);
966 IWL_ERR(mvm
, "Failed to update owner of TXQ %d (ret=%d)\n",
971 spin_lock_bh(&mvm
->queue_info_lock
);
972 mvm
->queue_info
[queue
].txq_tid
= tid
;
973 spin_unlock_bh(&mvm
->queue_info_lock
);
974 IWL_DEBUG_TX_QUEUES(mvm
, "Changed TXQ %d ownership to tid %d\n",
978 static void iwl_mvm_unshare_queue(struct iwl_mvm
*mvm
, int queue
)
980 struct ieee80211_sta
*sta
;
981 struct iwl_mvm_sta
*mvmsta
;
984 unsigned long tid_bitmap
;
985 unsigned int wdg_timeout
;
989 /* queue sharing is disabled on new TX path */
990 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm
)))
993 lockdep_assert_held(&mvm
->mutex
);
995 spin_lock_bh(&mvm
->queue_info_lock
);
996 sta_id
= mvm
->queue_info
[queue
].ra_sta_id
;
997 tid_bitmap
= mvm
->queue_info
[queue
].tid_bitmap
;
998 spin_unlock_bh(&mvm
->queue_info_lock
);
1000 /* Find TID for queue, and make sure it is the only one on the queue */
1001 tid
= find_first_bit(&tid_bitmap
, IWL_MAX_TID_COUNT
+ 1);
1002 if (tid_bitmap
!= BIT(tid
)) {
1003 IWL_ERR(mvm
, "Failed to unshare q %d, active tids=0x%lx\n",
1008 IWL_DEBUG_TX_QUEUES(mvm
, "Unsharing TXQ %d, keeping tid %d\n", queue
,
1011 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1012 lockdep_is_held(&mvm
->mutex
));
1014 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta
)))
1017 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1018 wdg_timeout
= iwl_mvm_get_wd_timeout(mvm
, mvmsta
->vif
, false, false);
1020 ssn
= IEEE80211_SEQ_TO_SN(mvmsta
->tid_data
[tid
].seq_number
);
1022 ret
= iwl_mvm_scd_queue_redirect(mvm
, queue
, tid
,
1023 tid_to_mac80211_ac
[tid
], ssn
,
1026 IWL_ERR(mvm
, "Failed to redirect TXQ %d\n", queue
);
1030 /* If aggs should be turned back on - do it */
1031 if (mvmsta
->tid_data
[tid
].state
== IWL_AGG_ON
) {
1032 struct iwl_mvm_add_sta_cmd cmd
= {0};
1034 mvmsta
->tid_disable_agg
&= ~BIT(tid
);
1036 cmd
.mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
);
1037 cmd
.sta_id
= mvmsta
->sta_id
;
1038 cmd
.add_modify
= STA_MODE_MODIFY
;
1039 cmd
.modify_mask
= STA_MODIFY_TID_DISABLE_TX
;
1040 cmd
.tfd_queue_msk
= cpu_to_le32(mvmsta
->tfd_queue_msk
);
1041 cmd
.tid_disable_tx
= cpu_to_le16(mvmsta
->tid_disable_agg
);
1043 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, CMD_ASYNC
,
1044 iwl_mvm_add_sta_cmd_size(mvm
), &cmd
);
1046 IWL_DEBUG_TX_QUEUES(mvm
,
1047 "TXQ #%d is now aggregated again\n",
1050 /* Mark queue intenally as aggregating again */
1051 iwl_trans_txq_set_shared_mode(mvm
->trans
, queue
, false);
1055 spin_lock_bh(&mvm
->queue_info_lock
);
1056 mvm
->queue_info
[queue
].status
= IWL_MVM_QUEUE_READY
;
1057 spin_unlock_bh(&mvm
->queue_info_lock
);
1060 static inline u8
iwl_mvm_tid_to_ac_queue(int tid
)
1062 if (tid
== IWL_MAX_TID_COUNT
)
1063 return IEEE80211_AC_VO
; /* MGMT */
1065 return tid_to_mac80211_ac
[tid
];
1068 static void iwl_mvm_tx_deferred_stream(struct iwl_mvm
*mvm
,
1069 struct ieee80211_sta
*sta
, int tid
)
1071 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1072 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
1073 struct sk_buff
*skb
;
1074 struct ieee80211_hdr
*hdr
;
1075 struct sk_buff_head deferred_tx
;
1077 bool no_queue
= false; /* Marks if there is a problem with the queue */
1080 lockdep_assert_held(&mvm
->mutex
);
1082 skb
= skb_peek(&tid_data
->deferred_tx_frames
);
1085 hdr
= (void *)skb
->data
;
1087 ac
= iwl_mvm_tid_to_ac_queue(tid
);
1088 mac_queue
= IEEE80211_SKB_CB(skb
)->hw_queue
;
1090 if (tid_data
->txq_id
== IWL_MVM_INVALID_QUEUE
&&
1091 iwl_mvm_sta_alloc_queue(mvm
, sta
, ac
, tid
, hdr
)) {
1093 "Can't alloc TXQ for sta %d tid %d - dropping frame\n",
1094 mvmsta
->sta_id
, tid
);
1097 * Mark queue as problematic so later the deferred traffic is
1098 * freed, as we can do nothing with it
1103 __skb_queue_head_init(&deferred_tx
);
1105 /* Disable bottom-halves when entering TX path */
1107 spin_lock(&mvmsta
->lock
);
1108 skb_queue_splice_init(&tid_data
->deferred_tx_frames
, &deferred_tx
);
1109 mvmsta
->deferred_traffic_tid_map
&= ~BIT(tid
);
1110 spin_unlock(&mvmsta
->lock
);
1112 while ((skb
= __skb_dequeue(&deferred_tx
)))
1113 if (no_queue
|| iwl_mvm_tx_skb(mvm
, skb
, sta
))
1114 ieee80211_free_txskb(mvm
->hw
, skb
);
1118 iwl_mvm_start_mac_queues(mvm
, BIT(mac_queue
));
1121 void iwl_mvm_add_new_dqa_stream_wk(struct work_struct
*wk
)
1123 struct iwl_mvm
*mvm
= container_of(wk
, struct iwl_mvm
,
1125 struct ieee80211_sta
*sta
;
1126 struct iwl_mvm_sta
*mvmsta
;
1127 unsigned long deferred_tid_traffic
;
1128 int queue
, sta_id
, tid
;
1130 /* Check inactivity of queues */
1131 iwl_mvm_inactivity_check(mvm
);
1133 mutex_lock(&mvm
->mutex
);
1135 /* No queue reconfiguration in TVQM mode */
1136 if (iwl_mvm_has_new_tx_api(mvm
))
1139 /* Reconfigure queues requiring reconfiguation */
1140 for (queue
= 0; queue
< ARRAY_SIZE(mvm
->queue_info
); queue
++) {
1144 spin_lock_bh(&mvm
->queue_info_lock
);
1145 reconfig
= (mvm
->queue_info
[queue
].status
==
1146 IWL_MVM_QUEUE_RECONFIGURING
);
1149 * We need to take into account a situation in which a TXQ was
1150 * allocated to TID x, and then turned shared by adding TIDs y
1151 * and z. If TID x becomes inactive and is removed from the TXQ,
1152 * ownership must be given to one of the remaining TIDs.
1153 * This is mainly because if TID x continues - a new queue can't
1154 * be allocated for it as long as it is an owner of another TXQ.
1156 change_owner
= !(mvm
->queue_info
[queue
].tid_bitmap
&
1157 BIT(mvm
->queue_info
[queue
].txq_tid
)) &&
1158 (mvm
->queue_info
[queue
].status
==
1159 IWL_MVM_QUEUE_SHARED
);
1160 spin_unlock_bh(&mvm
->queue_info_lock
);
1163 iwl_mvm_unshare_queue(mvm
, queue
);
1164 else if (change_owner
)
1165 iwl_mvm_change_queue_owner(mvm
, queue
);
1169 /* Go over all stations with deferred traffic */
1170 for_each_set_bit(sta_id
, mvm
->sta_deferred_frames
,
1171 IWL_MVM_STATION_COUNT
) {
1172 clear_bit(sta_id
, mvm
->sta_deferred_frames
);
1173 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1174 lockdep_is_held(&mvm
->mutex
));
1175 if (IS_ERR_OR_NULL(sta
))
1178 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1179 deferred_tid_traffic
= mvmsta
->deferred_traffic_tid_map
;
1181 for_each_set_bit(tid
, &deferred_tid_traffic
,
1182 IWL_MAX_TID_COUNT
+ 1)
1183 iwl_mvm_tx_deferred_stream(mvm
, sta
, tid
);
1186 mutex_unlock(&mvm
->mutex
);
1189 static int iwl_mvm_reserve_sta_stream(struct iwl_mvm
*mvm
,
1190 struct ieee80211_sta
*sta
,
1191 enum nl80211_iftype vif_type
)
1193 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1195 bool using_inactive_queue
= false, same_sta
= false;
1197 /* queue reserving is disabled on new TX path */
1198 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm
)))
1202 * Check for inactive queues, so we don't reach a situation where we
1203 * can't add a STA due to a shortage in queues that doesn't really exist
1205 iwl_mvm_inactivity_check(mvm
);
1207 spin_lock_bh(&mvm
->queue_info_lock
);
1209 /* Make sure we have free resources for this STA */
1210 if (vif_type
== NL80211_IFTYPE_STATION
&& !sta
->tdls
&&
1211 !mvm
->queue_info
[IWL_MVM_DQA_BSS_CLIENT_QUEUE
].hw_queue_refcount
&&
1212 (mvm
->queue_info
[IWL_MVM_DQA_BSS_CLIENT_QUEUE
].status
==
1213 IWL_MVM_QUEUE_FREE
))
1214 queue
= IWL_MVM_DQA_BSS_CLIENT_QUEUE
;
1216 queue
= iwl_mvm_find_free_queue(mvm
, mvmsta
->sta_id
,
1217 IWL_MVM_DQA_MIN_DATA_QUEUE
,
1218 IWL_MVM_DQA_MAX_DATA_QUEUE
);
1220 spin_unlock_bh(&mvm
->queue_info_lock
);
1221 IWL_ERR(mvm
, "No available queues for new station\n");
1223 } else if (mvm
->queue_info
[queue
].status
== IWL_MVM_QUEUE_INACTIVE
) {
1225 * If this queue is already allocated but inactive we'll need to
1226 * first free this queue before enabling it again, we'll mark
1227 * it as reserved to make sure no new traffic arrives on it
1229 using_inactive_queue
= true;
1230 same_sta
= mvm
->queue_info
[queue
].ra_sta_id
== mvmsta
->sta_id
;
1232 mvm
->queue_info
[queue
].status
= IWL_MVM_QUEUE_RESERVED
;
1234 spin_unlock_bh(&mvm
->queue_info_lock
);
1236 mvmsta
->reserved_queue
= queue
;
1238 if (using_inactive_queue
)
1239 iwl_mvm_free_inactive_queue(mvm
, queue
, same_sta
);
1241 IWL_DEBUG_TX_QUEUES(mvm
, "Reserving data queue #%d for sta_id %d\n",
1242 queue
, mvmsta
->sta_id
);
1248 * In DQA mode, after a HW restart the queues should be allocated as before, in
1249 * order to avoid race conditions when there are shared queues. This function
1250 * does the re-mapping and queue allocation.
1252 * Note that re-enabling aggregations isn't done in this function.
1254 static void iwl_mvm_realloc_queues_after_restart(struct iwl_mvm
*mvm
,
1255 struct iwl_mvm_sta
*mvm_sta
)
1257 unsigned int wdg_timeout
=
1258 iwl_mvm_get_wd_timeout(mvm
, mvm_sta
->vif
, false, false);
1260 struct iwl_trans_txq_scd_cfg cfg
= {
1261 .sta_id
= mvm_sta
->sta_id
,
1262 .frame_limit
= IWL_FRAME_LIMIT
,
1265 /* Make sure reserved queue is still marked as such (if allocated) */
1266 if (mvm_sta
->reserved_queue
!= IEEE80211_INVAL_HW_QUEUE
)
1267 mvm
->queue_info
[mvm_sta
->reserved_queue
].status
=
1268 IWL_MVM_QUEUE_RESERVED
;
1270 for (i
= 0; i
<= IWL_MAX_TID_COUNT
; i
++) {
1271 struct iwl_mvm_tid_data
*tid_data
= &mvm_sta
->tid_data
[i
];
1272 int txq_id
= tid_data
->txq_id
;
1276 if (txq_id
== IWL_MVM_INVALID_QUEUE
)
1279 skb_queue_head_init(&tid_data
->deferred_tx_frames
);
1281 ac
= tid_to_mac80211_ac
[i
];
1282 mac_queue
= mvm_sta
->vif
->hw_queue
[ac
];
1284 if (iwl_mvm_has_new_tx_api(mvm
)) {
1285 IWL_DEBUG_TX_QUEUES(mvm
,
1286 "Re-mapping sta %d tid %d\n",
1287 mvm_sta
->sta_id
, i
);
1288 txq_id
= iwl_mvm_tvqm_enable_txq(mvm
, mac_queue
,
1291 tid_data
->txq_id
= txq_id
;
1293 u16 seq
= IEEE80211_SEQ_TO_SN(tid_data
->seq_number
);
1296 cfg
.fifo
= iwl_mvm_ac_to_tx_fifo
[ac
];
1297 cfg
.aggregate
= (txq_id
>= IWL_MVM_DQA_MIN_DATA_QUEUE
||
1299 IWL_MVM_DQA_BSS_CLIENT_QUEUE
);
1301 IWL_DEBUG_TX_QUEUES(mvm
,
1302 "Re-mapping sta %d tid %d to queue %d\n",
1303 mvm_sta
->sta_id
, i
, txq_id
);
1305 iwl_mvm_enable_txq(mvm
, txq_id
, mac_queue
, seq
, &cfg
,
1307 mvm
->queue_info
[txq_id
].status
= IWL_MVM_QUEUE_READY
;
1311 atomic_set(&mvm
->pending_frames
[mvm_sta
->sta_id
], 0);
1314 int iwl_mvm_add_sta(struct iwl_mvm
*mvm
,
1315 struct ieee80211_vif
*vif
,
1316 struct ieee80211_sta
*sta
)
1318 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1319 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1320 struct iwl_mvm_rxq_dup_data
*dup_data
;
1323 lockdep_assert_held(&mvm
->mutex
);
1325 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
1326 sta_id
= iwl_mvm_find_free_sta_id(mvm
,
1327 ieee80211_vif_type_p2p(vif
));
1329 sta_id
= mvm_sta
->sta_id
;
1331 if (sta_id
== IWL_MVM_INVALID_STA
)
1334 spin_lock_init(&mvm_sta
->lock
);
1336 /* In DQA mode, if this is a HW restart, re-alloc existing queues */
1337 if (iwl_mvm_is_dqa_supported(mvm
) &&
1338 test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
1339 iwl_mvm_realloc_queues_after_restart(mvm
, mvm_sta
);
1343 mvm_sta
->sta_id
= sta_id
;
1344 mvm_sta
->mac_id_n_color
= FW_CMD_ID_AND_COLOR(mvmvif
->id
,
1347 mvm_sta
->max_agg_bufsize
= LINK_QUAL_AGG_FRAME_LIMIT_DEF
;
1348 mvm_sta
->tx_protection
= 0;
1349 mvm_sta
->tt_tx_protection
= false;
1350 mvm_sta
->sta_type
= sta
->tdls
? IWL_STA_TDLS_LINK
: IWL_STA_LINK
;
1352 /* HW restart, don't assume the memory has been zeroed */
1353 atomic_set(&mvm
->pending_frames
[sta_id
], 0);
1354 mvm_sta
->tid_disable_agg
= 0xffff; /* No aggs at first */
1355 mvm_sta
->tfd_queue_msk
= 0;
1358 * Allocate new queues for a TDLS station, unless we're in DQA mode,
1359 * and then they'll be allocated dynamically
1361 if (!iwl_mvm_is_dqa_supported(mvm
) && sta
->tdls
) {
1362 ret
= iwl_mvm_tdls_sta_init(mvm
, sta
);
1365 } else if (!iwl_mvm_is_dqa_supported(mvm
)) {
1366 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++)
1367 if (vif
->hw_queue
[i
] != IEEE80211_INVAL_HW_QUEUE
)
1368 mvm_sta
->tfd_queue_msk
|= BIT(vif
->hw_queue
[i
]);
1371 /* for HW restart - reset everything but the sequence number */
1372 for (i
= 0; i
<= IWL_MAX_TID_COUNT
; i
++) {
1373 u16 seq
= mvm_sta
->tid_data
[i
].seq_number
;
1374 memset(&mvm_sta
->tid_data
[i
], 0, sizeof(mvm_sta
->tid_data
[i
]));
1375 mvm_sta
->tid_data
[i
].seq_number
= seq
;
1377 if (!iwl_mvm_is_dqa_supported(mvm
))
1381 * Mark all queues for this STA as unallocated and defer TX
1382 * frames until the queue is allocated
1384 mvm_sta
->tid_data
[i
].txq_id
= IWL_MVM_INVALID_QUEUE
;
1385 skb_queue_head_init(&mvm_sta
->tid_data
[i
].deferred_tx_frames
);
1387 mvm_sta
->deferred_traffic_tid_map
= 0;
1388 mvm_sta
->agg_tids
= 0;
1390 if (iwl_mvm_has_new_rx_api(mvm
) &&
1391 !test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
1392 dup_data
= kcalloc(mvm
->trans
->num_rx_queues
,
1397 mvm_sta
->dup_data
= dup_data
;
1400 if (iwl_mvm_is_dqa_supported(mvm
) && !iwl_mvm_has_new_tx_api(mvm
)) {
1401 ret
= iwl_mvm_reserve_sta_stream(mvm
, sta
,
1402 ieee80211_vif_type_p2p(vif
));
1408 ret
= iwl_mvm_sta_send_to_fw(mvm
, sta
, false, 0);
1412 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1414 WARN_ON(mvmvif
->ap_sta_id
!= IWL_MVM_INVALID_STA
);
1415 mvmvif
->ap_sta_id
= sta_id
;
1417 WARN_ON(mvmvif
->ap_sta_id
== IWL_MVM_INVALID_STA
);
1421 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta_id
], sta
);
1426 if (!iwl_mvm_is_dqa_supported(mvm
) && sta
->tdls
)
1427 iwl_mvm_tdls_sta_deinit(mvm
, sta
);
1431 int iwl_mvm_drain_sta(struct iwl_mvm
*mvm
, struct iwl_mvm_sta
*mvmsta
,
1434 struct iwl_mvm_add_sta_cmd cmd
= {};
1438 lockdep_assert_held(&mvm
->mutex
);
1440 cmd
.mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
);
1441 cmd
.sta_id
= mvmsta
->sta_id
;
1442 cmd
.add_modify
= STA_MODE_MODIFY
;
1443 cmd
.station_flags
= drain
? cpu_to_le32(STA_FLG_DRAIN_FLOW
) : 0;
1444 cmd
.station_flags_msk
= cpu_to_le32(STA_FLG_DRAIN_FLOW
);
1446 status
= ADD_STA_SUCCESS
;
1447 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
,
1448 iwl_mvm_add_sta_cmd_size(mvm
),
1453 switch (status
& IWL_ADD_STA_STATUS_MASK
) {
1454 case ADD_STA_SUCCESS
:
1455 IWL_DEBUG_INFO(mvm
, "Frames for staid %d will drained in fw\n",
1460 IWL_ERR(mvm
, "Couldn't drain frames for staid %d\n",
1469 * Remove a station from the FW table. Before sending the command to remove
1470 * the station validate that the station is indeed known to the driver (sanity
1473 static int iwl_mvm_rm_sta_common(struct iwl_mvm
*mvm
, u8 sta_id
)
1475 struct ieee80211_sta
*sta
;
1476 struct iwl_mvm_rm_sta_cmd rm_sta_cmd
= {
1481 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1482 lockdep_is_held(&mvm
->mutex
));
1484 /* Note: internal stations are marked as error values */
1486 IWL_ERR(mvm
, "Invalid station id\n");
1490 ret
= iwl_mvm_send_cmd_pdu(mvm
, REMOVE_STA
, 0,
1491 sizeof(rm_sta_cmd
), &rm_sta_cmd
);
1493 IWL_ERR(mvm
, "Failed to remove station. Id=%d\n", sta_id
);
1500 void iwl_mvm_sta_drained_wk(struct work_struct
*wk
)
1502 struct iwl_mvm
*mvm
= container_of(wk
, struct iwl_mvm
, sta_drained_wk
);
1506 * The mutex is needed because of the SYNC cmd, but not only: if the
1507 * work would run concurrently with iwl_mvm_rm_sta, it would run before
1508 * iwl_mvm_rm_sta sets the station as busy, and exit. Then
1509 * iwl_mvm_rm_sta would set the station as busy, and nobody will clean
1512 mutex_lock(&mvm
->mutex
);
1514 for_each_set_bit(sta_id
, mvm
->sta_drained
, IWL_MVM_STATION_COUNT
) {
1516 struct ieee80211_sta
*sta
=
1517 rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1518 lockdep_is_held(&mvm
->mutex
));
1521 * This station is in use or RCU-removed; the latter happens in
1522 * managed mode, where mac80211 removes the station before we
1523 * can remove it from firmware (we can only do that after the
1524 * MAC is marked unassociated), and possibly while the deauth
1525 * frame to disconnect from the AP is still queued. Then, the
1526 * station pointer is -ENOENT when the last skb is reclaimed.
1528 if (!IS_ERR(sta
) || PTR_ERR(sta
) == -ENOENT
)
1531 if (PTR_ERR(sta
) == -EINVAL
) {
1532 IWL_ERR(mvm
, "Drained sta %d, but it is internal?\n",
1538 IWL_ERR(mvm
, "Drained sta %d, but it was NULL?\n",
1543 WARN_ON(PTR_ERR(sta
) != -EBUSY
);
1544 /* This station was removed and we waited until it got drained,
1545 * we can now proceed and remove it.
1547 ret
= iwl_mvm_rm_sta_common(mvm
, sta_id
);
1550 "Couldn't remove sta %d after it was drained\n",
1554 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta_id
], NULL
);
1555 clear_bit(sta_id
, mvm
->sta_drained
);
1557 if (mvm
->tfd_drained
[sta_id
]) {
1558 unsigned long i
, msk
= mvm
->tfd_drained
[sta_id
];
1560 for_each_set_bit(i
, &msk
, sizeof(msk
) * BITS_PER_BYTE
)
1561 iwl_mvm_disable_txq(mvm
, i
, i
,
1562 IWL_MAX_TID_COUNT
, 0);
1564 mvm
->tfd_drained
[sta_id
] = 0;
1565 IWL_DEBUG_TDLS(mvm
, "Drained sta %d, with queues %ld\n",
1570 mutex_unlock(&mvm
->mutex
);
1573 static void iwl_mvm_disable_sta_queues(struct iwl_mvm
*mvm
,
1574 struct ieee80211_vif
*vif
,
1575 struct iwl_mvm_sta
*mvm_sta
)
1580 lockdep_assert_held(&mvm
->mutex
);
1582 for (i
= 0; i
< ARRAY_SIZE(mvm_sta
->tid_data
); i
++) {
1583 if (mvm_sta
->tid_data
[i
].txq_id
== IWL_MVM_INVALID_QUEUE
)
1586 ac
= iwl_mvm_tid_to_ac_queue(i
);
1587 iwl_mvm_disable_txq(mvm
, mvm_sta
->tid_data
[i
].txq_id
,
1588 vif
->hw_queue
[ac
], i
, 0);
1589 mvm_sta
->tid_data
[i
].txq_id
= IWL_MVM_INVALID_QUEUE
;
1593 int iwl_mvm_rm_sta(struct iwl_mvm
*mvm
,
1594 struct ieee80211_vif
*vif
,
1595 struct ieee80211_sta
*sta
)
1597 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1598 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1599 u8 sta_id
= mvm_sta
->sta_id
;
1602 lockdep_assert_held(&mvm
->mutex
);
1604 if (iwl_mvm_has_new_rx_api(mvm
))
1605 kfree(mvm_sta
->dup_data
);
1607 if ((vif
->type
== NL80211_IFTYPE_STATION
&&
1608 mvmvif
->ap_sta_id
== sta_id
) ||
1609 iwl_mvm_is_dqa_supported(mvm
)){
1610 ret
= iwl_mvm_drain_sta(mvm
, mvm_sta
, true);
1613 /* flush its queues here since we are freeing mvm_sta */
1614 ret
= iwl_mvm_flush_tx_path(mvm
, mvm_sta
->tfd_queue_msk
, 0);
1617 ret
= iwl_trans_wait_tx_queues_empty(mvm
->trans
,
1618 mvm_sta
->tfd_queue_msk
);
1621 ret
= iwl_mvm_drain_sta(mvm
, mvm_sta
, false);
1623 /* If DQA is supported - the queues can be disabled now */
1624 if (iwl_mvm_is_dqa_supported(mvm
)) {
1625 iwl_mvm_disable_sta_queues(mvm
, vif
, mvm_sta
);
1627 * If pending_frames is set at this point - it must be
1628 * driver internal logic error, since queues are empty
1629 * and removed successuly.
1630 * warn on it but set it to 0 anyway to avoid station
1631 * not being removed later in the function
1633 WARN_ON(atomic_xchg(&mvm
->pending_frames
[sta_id
], 0));
1636 /* If there is a TXQ still marked as reserved - free it */
1637 if (iwl_mvm_is_dqa_supported(mvm
) &&
1638 mvm_sta
->reserved_queue
!= IEEE80211_INVAL_HW_QUEUE
) {
1639 u8 reserved_txq
= mvm_sta
->reserved_queue
;
1640 enum iwl_mvm_queue_status
*status
;
1643 * If no traffic has gone through the reserved TXQ - it
1644 * is still marked as IWL_MVM_QUEUE_RESERVED, and
1645 * should be manually marked as free again
1647 spin_lock_bh(&mvm
->queue_info_lock
);
1648 status
= &mvm
->queue_info
[reserved_txq
].status
;
1649 if (WARN((*status
!= IWL_MVM_QUEUE_RESERVED
) &&
1650 (*status
!= IWL_MVM_QUEUE_FREE
),
1651 "sta_id %d reserved txq %d status %d",
1652 sta_id
, reserved_txq
, *status
)) {
1653 spin_unlock_bh(&mvm
->queue_info_lock
);
1657 *status
= IWL_MVM_QUEUE_FREE
;
1658 spin_unlock_bh(&mvm
->queue_info_lock
);
1661 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1662 mvmvif
->ap_sta_id
== sta_id
) {
1663 /* if associated - we can't remove the AP STA now */
1664 if (vif
->bss_conf
.assoc
)
1667 /* unassoc - go ahead - remove the AP STA now */
1668 mvmvif
->ap_sta_id
= IWL_MVM_INVALID_STA
;
1670 /* clear d0i3_ap_sta_id if no longer relevant */
1671 if (mvm
->d0i3_ap_sta_id
== sta_id
)
1672 mvm
->d0i3_ap_sta_id
= IWL_MVM_INVALID_STA
;
1677 * This shouldn't happen - the TDLS channel switch should be canceled
1678 * before the STA is removed.
1680 if (WARN_ON_ONCE(mvm
->tdls_cs
.peer
.sta_id
== sta_id
)) {
1681 mvm
->tdls_cs
.peer
.sta_id
= IWL_MVM_INVALID_STA
;
1682 cancel_delayed_work(&mvm
->tdls_cs
.dwork
);
1686 * Make sure that the tx response code sees the station as -EBUSY and
1687 * calls the drain worker.
1689 spin_lock_bh(&mvm_sta
->lock
);
1692 * There are frames pending on the AC queues for this station.
1693 * We need to wait until all the frames are drained...
1695 if (atomic_read(&mvm
->pending_frames
[sta_id
])) {
1696 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta_id
],
1698 spin_unlock_bh(&mvm_sta
->lock
);
1700 /* disable TDLS sta queues on drain complete */
1702 mvm
->tfd_drained
[sta_id
] = mvm_sta
->tfd_queue_msk
;
1703 IWL_DEBUG_TDLS(mvm
, "Draining TDLS sta %d\n", sta_id
);
1706 ret
= iwl_mvm_drain_sta(mvm
, mvm_sta
, true);
1708 spin_unlock_bh(&mvm_sta
->lock
);
1710 if (!iwl_mvm_is_dqa_supported(mvm
) && sta
->tdls
)
1711 iwl_mvm_tdls_sta_deinit(mvm
, sta
);
1713 ret
= iwl_mvm_rm_sta_common(mvm
, mvm_sta
->sta_id
);
1714 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
], NULL
);
1720 int iwl_mvm_rm_sta_id(struct iwl_mvm
*mvm
,
1721 struct ieee80211_vif
*vif
,
1724 int ret
= iwl_mvm_rm_sta_common(mvm
, sta_id
);
1726 lockdep_assert_held(&mvm
->mutex
);
1728 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta_id
], NULL
);
1732 int iwl_mvm_allocate_int_sta(struct iwl_mvm
*mvm
,
1733 struct iwl_mvm_int_sta
*sta
,
1734 u32 qmask
, enum nl80211_iftype iftype
,
1735 enum iwl_sta_type type
)
1737 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
1738 sta
->sta_id
= iwl_mvm_find_free_sta_id(mvm
, iftype
);
1739 if (WARN_ON_ONCE(sta
->sta_id
== IWL_MVM_INVALID_STA
))
1743 sta
->tfd_queue_msk
= qmask
;
1746 /* put a non-NULL value so iterating over the stations won't stop */
1747 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta
->sta_id
], ERR_PTR(-EINVAL
));
1751 void iwl_mvm_dealloc_int_sta(struct iwl_mvm
*mvm
, struct iwl_mvm_int_sta
*sta
)
1753 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta
->sta_id
], NULL
);
1754 memset(sta
, 0, sizeof(struct iwl_mvm_int_sta
));
1755 sta
->sta_id
= IWL_MVM_INVALID_STA
;
1758 static int iwl_mvm_add_int_sta_common(struct iwl_mvm
*mvm
,
1759 struct iwl_mvm_int_sta
*sta
,
1761 u16 mac_id
, u16 color
)
1763 struct iwl_mvm_add_sta_cmd cmd
;
1767 lockdep_assert_held(&mvm
->mutex
);
1769 memset(&cmd
, 0, sizeof(cmd
));
1770 cmd
.sta_id
= sta
->sta_id
;
1771 cmd
.mac_id_n_color
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id
,
1773 if (fw_has_api(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_API_STA_TYPE
))
1774 cmd
.station_type
= sta
->type
;
1776 if (!iwl_mvm_has_new_tx_api(mvm
))
1777 cmd
.tfd_queue_msk
= cpu_to_le32(sta
->tfd_queue_msk
);
1778 cmd
.tid_disable_tx
= cpu_to_le16(0xffff);
1781 memcpy(cmd
.addr
, addr
, ETH_ALEN
);
1783 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
,
1784 iwl_mvm_add_sta_cmd_size(mvm
),
1789 switch (status
& IWL_ADD_STA_STATUS_MASK
) {
1790 case ADD_STA_SUCCESS
:
1791 IWL_DEBUG_INFO(mvm
, "Internal station added.\n");
1795 IWL_ERR(mvm
, "Add internal station failed, status=0x%x\n",
1802 static void iwl_mvm_enable_aux_queue(struct iwl_mvm
*mvm
)
1804 unsigned int wdg_timeout
= iwlmvm_mod_params
.tfd_q_hang_detect
?
1805 mvm
->cfg
->base_params
->wd_timeout
:
1806 IWL_WATCHDOG_DISABLED
;
1808 if (iwl_mvm_has_new_tx_api(mvm
)) {
1809 int queue
= iwl_mvm_tvqm_enable_txq(mvm
, mvm
->aux_queue
,
1810 mvm
->aux_sta
.sta_id
,
1813 mvm
->aux_queue
= queue
;
1814 } else if (iwl_mvm_is_dqa_supported(mvm
)) {
1815 struct iwl_trans_txq_scd_cfg cfg
= {
1816 .fifo
= IWL_MVM_TX_FIFO_MCAST
,
1817 .sta_id
= mvm
->aux_sta
.sta_id
,
1818 .tid
= IWL_MAX_TID_COUNT
,
1820 .frame_limit
= IWL_FRAME_LIMIT
,
1823 iwl_mvm_enable_txq(mvm
, mvm
->aux_queue
, mvm
->aux_queue
, 0, &cfg
,
1826 iwl_mvm_enable_ac_txq(mvm
, mvm
->aux_queue
, mvm
->aux_queue
,
1827 IWL_MVM_TX_FIFO_MCAST
, 0, wdg_timeout
);
1831 int iwl_mvm_add_aux_sta(struct iwl_mvm
*mvm
)
1835 lockdep_assert_held(&mvm
->mutex
);
1837 /* Allocate aux station and assign to it the aux queue */
1838 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvm
->aux_sta
, BIT(mvm
->aux_queue
),
1839 NL80211_IFTYPE_UNSPECIFIED
,
1840 IWL_STA_AUX_ACTIVITY
);
1844 /* Map Aux queue to fifo - needs to happen before adding Aux station */
1845 if (!iwl_mvm_has_new_tx_api(mvm
))
1846 iwl_mvm_enable_aux_queue(mvm
);
1848 ret
= iwl_mvm_add_int_sta_common(mvm
, &mvm
->aux_sta
, NULL
,
1851 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
1856 * For a000 firmware and on we cannot add queue to a station unknown
1857 * to firmware so enable queue here - after the station was added
1859 if (iwl_mvm_has_new_tx_api(mvm
))
1860 iwl_mvm_enable_aux_queue(mvm
);
1865 int iwl_mvm_add_snif_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1867 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1869 lockdep_assert_held(&mvm
->mutex
);
1870 return iwl_mvm_add_int_sta_common(mvm
, &mvm
->snif_sta
, vif
->addr
,
1874 int iwl_mvm_rm_snif_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1878 lockdep_assert_held(&mvm
->mutex
);
1880 ret
= iwl_mvm_rm_sta_common(mvm
, mvm
->snif_sta
.sta_id
);
1882 IWL_WARN(mvm
, "Failed sending remove station\n");
1887 void iwl_mvm_dealloc_snif_sta(struct iwl_mvm
*mvm
)
1889 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->snif_sta
);
1892 void iwl_mvm_del_aux_sta(struct iwl_mvm
*mvm
)
1894 lockdep_assert_held(&mvm
->mutex
);
1896 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
1900 * Send the add station command for the vif's broadcast station.
1901 * Assumes that the station was already allocated.
1903 * @mvm: the mvm component
1904 * @vif: the interface to which the broadcast station is added
1905 * @bsta: the broadcast station to add.
1907 int iwl_mvm_send_add_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1909 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1910 struct iwl_mvm_int_sta
*bsta
= &mvmvif
->bcast_sta
;
1911 static const u8 _baddr
[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
1912 const u8
*baddr
= _baddr
;
1915 unsigned int wdg_timeout
=
1916 iwl_mvm_get_wd_timeout(mvm
, vif
, false, false);
1917 struct iwl_trans_txq_scd_cfg cfg
= {
1918 .fifo
= IWL_MVM_TX_FIFO_VO
,
1919 .sta_id
= mvmvif
->bcast_sta
.sta_id
,
1920 .tid
= IWL_MAX_TID_COUNT
,
1922 .frame_limit
= IWL_FRAME_LIMIT
,
1925 lockdep_assert_held(&mvm
->mutex
);
1927 if (iwl_mvm_is_dqa_supported(mvm
) && !iwl_mvm_has_new_tx_api(mvm
)) {
1928 if (vif
->type
== NL80211_IFTYPE_AP
||
1929 vif
->type
== NL80211_IFTYPE_ADHOC
)
1930 queue
= mvm
->probe_queue
;
1931 else if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
)
1932 queue
= mvm
->p2p_dev_queue
;
1933 else if (WARN(1, "Missing required TXQ for adding bcast STA\n"))
1936 bsta
->tfd_queue_msk
|= BIT(queue
);
1938 iwl_mvm_enable_txq(mvm
, queue
, vif
->hw_queue
[0], 0,
1942 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
1943 baddr
= vif
->bss_conf
.bssid
;
1945 if (WARN_ON_ONCE(bsta
->sta_id
== IWL_MVM_INVALID_STA
))
1948 ret
= iwl_mvm_add_int_sta_common(mvm
, bsta
, baddr
,
1949 mvmvif
->id
, mvmvif
->color
);
1954 * For a000 firmware and on we cannot add queue to a station unknown
1955 * to firmware so enable queue here - after the station was added
1957 if (iwl_mvm_has_new_tx_api(mvm
)) {
1958 queue
= iwl_mvm_tvqm_enable_txq(mvm
, vif
->hw_queue
[0],
1963 if (vif
->type
== NL80211_IFTYPE_AP
)
1964 mvm
->probe_queue
= queue
;
1965 else if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
)
1966 mvm
->p2p_dev_queue
= queue
;
1968 bsta
->tfd_queue_msk
|= BIT(queue
);
1974 static void iwl_mvm_free_bcast_sta_queues(struct iwl_mvm
*mvm
,
1975 struct ieee80211_vif
*vif
)
1977 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1979 lockdep_assert_held(&mvm
->mutex
);
1981 if (vif
->type
== NL80211_IFTYPE_AP
||
1982 vif
->type
== NL80211_IFTYPE_ADHOC
)
1983 iwl_mvm_disable_txq(mvm
, vif
->cab_queue
, vif
->cab_queue
,
1984 IWL_MAX_TID_COUNT
, 0);
1986 if (mvmvif
->bcast_sta
.tfd_queue_msk
& BIT(mvm
->probe_queue
)) {
1987 iwl_mvm_disable_txq(mvm
, mvm
->probe_queue
,
1988 vif
->hw_queue
[0], IWL_MAX_TID_COUNT
,
1990 mvmvif
->bcast_sta
.tfd_queue_msk
&= ~BIT(mvm
->probe_queue
);
1993 if (mvmvif
->bcast_sta
.tfd_queue_msk
& BIT(mvm
->p2p_dev_queue
)) {
1994 iwl_mvm_disable_txq(mvm
, mvm
->p2p_dev_queue
,
1995 vif
->hw_queue
[0], IWL_MAX_TID_COUNT
,
1997 mvmvif
->bcast_sta
.tfd_queue_msk
&= ~BIT(mvm
->p2p_dev_queue
);
2001 /* Send the FW a request to remove the station from it's internal data
2002 * structures, but DO NOT remove the entry from the local data structures. */
2003 int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
2005 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2008 lockdep_assert_held(&mvm
->mutex
);
2010 if (iwl_mvm_is_dqa_supported(mvm
))
2011 iwl_mvm_free_bcast_sta_queues(mvm
, vif
);
2013 ret
= iwl_mvm_rm_sta_common(mvm
, mvmvif
->bcast_sta
.sta_id
);
2015 IWL_WARN(mvm
, "Failed sending remove station\n");
2019 int iwl_mvm_alloc_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
2021 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2024 lockdep_assert_held(&mvm
->mutex
);
2026 if (!iwl_mvm_is_dqa_supported(mvm
)) {
2027 qmask
= iwl_mvm_mac_get_queues_mask(vif
);
2030 * The firmware defines the TFD queue mask to only be relevant
2031 * for *unicast* queues, so the multicast (CAB) queue shouldn't
2032 * be included. This only happens in NL80211_IFTYPE_AP vif type,
2033 * so the next line will only have an effect there.
2035 qmask
&= ~BIT(vif
->cab_queue
);
2038 return iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->bcast_sta
, qmask
,
2039 ieee80211_vif_type_p2p(vif
),
2040 IWL_STA_GENERAL_PURPOSE
);
2043 /* Allocate a new station entry for the broadcast station to the given vif,
2044 * and send it to the FW.
2045 * Note that each P2P mac should have its own broadcast station.
2047 * @mvm: the mvm component
2048 * @vif: the interface to which the broadcast station is added
2049 * @bsta: the broadcast station to add. */
2050 int iwl_mvm_add_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
2052 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2053 struct iwl_mvm_int_sta
*bsta
= &mvmvif
->bcast_sta
;
2056 lockdep_assert_held(&mvm
->mutex
);
2058 ret
= iwl_mvm_alloc_bcast_sta(mvm
, vif
);
2062 ret
= iwl_mvm_send_add_bcast_sta(mvm
, vif
);
2065 iwl_mvm_dealloc_int_sta(mvm
, bsta
);
2070 void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
2072 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2074 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->bcast_sta
);
2078 * Send the FW a request to remove the station from it's internal data
2079 * structures, and in addition remove it from the local data structure.
2081 int iwl_mvm_rm_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
2085 lockdep_assert_held(&mvm
->mutex
);
2087 ret
= iwl_mvm_send_rm_bcast_sta(mvm
, vif
);
2089 iwl_mvm_dealloc_bcast_sta(mvm
, vif
);
2095 * Allocate a new station entry for the multicast station to the given vif,
2096 * and send it to the FW.
2097 * Note that each AP/GO mac should have its own multicast station.
2099 * @mvm: the mvm component
2100 * @vif: the interface to which the multicast station is added
2102 int iwl_mvm_add_mcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
2104 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2105 struct iwl_mvm_int_sta
*msta
= &mvmvif
->mcast_sta
;
2106 static const u8 _maddr
[] = {0x03, 0x00, 0x00, 0x00, 0x00, 0x00};
2107 const u8
*maddr
= _maddr
;
2108 struct iwl_trans_txq_scd_cfg cfg
= {
2109 .fifo
= IWL_MVM_TX_FIFO_MCAST
,
2110 .sta_id
= msta
->sta_id
,
2111 .tid
= IWL_MAX_TID_COUNT
,
2113 .frame_limit
= IWL_FRAME_LIMIT
,
2115 unsigned int timeout
= iwl_mvm_get_wd_timeout(mvm
, vif
, false, false);
2118 lockdep_assert_held(&mvm
->mutex
);
2120 if (!iwl_mvm_is_dqa_supported(mvm
))
2123 if (WARN_ON(vif
->type
!= NL80211_IFTYPE_AP
&&
2124 vif
->type
!= NL80211_IFTYPE_ADHOC
))
2128 * While in previous FWs we had to exclude cab queue from TFD queue
2129 * mask, now it is needed as any other queue.
2131 if (!iwl_mvm_has_new_tx_api(mvm
) &&
2132 fw_has_api(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_API_STA_TYPE
)) {
2133 iwl_mvm_enable_txq(mvm
, vif
->cab_queue
, vif
->cab_queue
, 0,
2135 msta
->tfd_queue_msk
|= BIT(vif
->cab_queue
);
2137 ret
= iwl_mvm_add_int_sta_common(mvm
, msta
, maddr
,
2138 mvmvif
->id
, mvmvif
->color
);
2140 iwl_mvm_dealloc_int_sta(mvm
, msta
);
2145 * Enable cab queue after the ADD_STA command is sent.
2146 * This is needed for a000 firmware which won't accept SCD_QUEUE_CFG
2147 * command with unknown station id, and for FW that doesn't support
2148 * station API since the cab queue is not included in the
2151 if (iwl_mvm_has_new_tx_api(mvm
)) {
2152 int queue
= iwl_mvm_tvqm_enable_txq(mvm
, vif
->cab_queue
,
2156 mvmvif
->cab_queue
= queue
;
2157 } else if (!fw_has_api(&mvm
->fw
->ucode_capa
,
2158 IWL_UCODE_TLV_API_STA_TYPE
)) {
2160 * In IBSS, ieee80211_check_queues() sets the cab_queue to be
2161 * invalid, so make sure we use the queue we want.
2162 * Note that this is done here as we want to avoid making DQA
2163 * changes in mac80211 layer.
2165 if (vif
->type
== NL80211_IFTYPE_ADHOC
) {
2166 vif
->cab_queue
= IWL_MVM_DQA_GCAST_QUEUE
;
2167 mvmvif
->cab_queue
= vif
->cab_queue
;
2169 iwl_mvm_enable_txq(mvm
, vif
->cab_queue
, vif
->cab_queue
, 0,
2177 * Send the FW a request to remove the station from it's internal data
2178 * structures, and in addition remove it from the local data structure.
2180 int iwl_mvm_rm_mcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
2182 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2185 lockdep_assert_held(&mvm
->mutex
);
2187 if (!iwl_mvm_is_dqa_supported(mvm
))
2190 iwl_mvm_disable_txq(mvm
, mvmvif
->cab_queue
, vif
->cab_queue
,
2191 IWL_MAX_TID_COUNT
, 0);
2193 ret
= iwl_mvm_rm_sta_common(mvm
, mvmvif
->mcast_sta
.sta_id
);
2195 IWL_WARN(mvm
, "Failed sending remove station\n");
2200 #define IWL_MAX_RX_BA_SESSIONS 16
2202 static void iwl_mvm_sync_rxq_del_ba(struct iwl_mvm
*mvm
, u8 baid
)
2204 struct iwl_mvm_delba_notif notif
= {
2205 .metadata
.type
= IWL_MVM_RXQ_NOTIF_DEL_BA
,
2209 iwl_mvm_sync_rx_queues_internal(mvm
, (void *)¬if
, sizeof(notif
));
2212 static void iwl_mvm_free_reorder(struct iwl_mvm
*mvm
,
2213 struct iwl_mvm_baid_data
*data
)
2217 iwl_mvm_sync_rxq_del_ba(mvm
, data
->baid
);
2219 for (i
= 0; i
< mvm
->trans
->num_rx_queues
; i
++) {
2221 struct iwl_mvm_reorder_buffer
*reorder_buf
=
2222 &data
->reorder_buf
[i
];
2224 spin_lock_bh(&reorder_buf
->lock
);
2225 if (likely(!reorder_buf
->num_stored
)) {
2226 spin_unlock_bh(&reorder_buf
->lock
);
2231 * This shouldn't happen in regular DELBA since the internal
2232 * delBA notification should trigger a release of all frames in
2233 * the reorder buffer.
2237 for (j
= 0; j
< reorder_buf
->buf_size
; j
++)
2238 __skb_queue_purge(&reorder_buf
->entries
[j
]);
2240 * Prevent timer re-arm. This prevents a very far fetched case
2241 * where we timed out on the notification. There may be prior
2242 * RX frames pending in the RX queue before the notification
2243 * that might get processed between now and the actual deletion
2244 * and we would re-arm the timer although we are deleting the
2247 reorder_buf
->removed
= true;
2248 spin_unlock_bh(&reorder_buf
->lock
);
2249 del_timer_sync(&reorder_buf
->reorder_timer
);
2253 static void iwl_mvm_init_reorder_buffer(struct iwl_mvm
*mvm
,
2255 struct iwl_mvm_baid_data
*data
,
2256 u16 ssn
, u8 buf_size
)
2260 for (i
= 0; i
< mvm
->trans
->num_rx_queues
; i
++) {
2261 struct iwl_mvm_reorder_buffer
*reorder_buf
=
2262 &data
->reorder_buf
[i
];
2265 reorder_buf
->num_stored
= 0;
2266 reorder_buf
->head_sn
= ssn
;
2267 reorder_buf
->buf_size
= buf_size
;
2268 /* rx reorder timer */
2269 reorder_buf
->reorder_timer
.function
=
2270 iwl_mvm_reorder_timer_expired
;
2271 reorder_buf
->reorder_timer
.data
= (unsigned long)reorder_buf
;
2272 init_timer(&reorder_buf
->reorder_timer
);
2273 spin_lock_init(&reorder_buf
->lock
);
2274 reorder_buf
->mvm
= mvm
;
2275 reorder_buf
->queue
= i
;
2276 reorder_buf
->sta_id
= sta_id
;
2277 reorder_buf
->valid
= false;
2278 for (j
= 0; j
< reorder_buf
->buf_size
; j
++)
2279 __skb_queue_head_init(&reorder_buf
->entries
[j
]);
2283 int iwl_mvm_sta_rx_agg(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
2284 int tid
, u16 ssn
, bool start
, u8 buf_size
, u16 timeout
)
2286 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
2287 struct iwl_mvm_add_sta_cmd cmd
= {};
2288 struct iwl_mvm_baid_data
*baid_data
= NULL
;
2292 lockdep_assert_held(&mvm
->mutex
);
2294 if (start
&& mvm
->rx_ba_sessions
>= IWL_MAX_RX_BA_SESSIONS
) {
2295 IWL_WARN(mvm
, "Not enough RX BA SESSIONS\n");
2299 if (iwl_mvm_has_new_rx_api(mvm
) && start
) {
2301 * Allocate here so if allocation fails we can bail out early
2302 * before starting the BA session in the firmware
2304 baid_data
= kzalloc(sizeof(*baid_data
) +
2305 mvm
->trans
->num_rx_queues
*
2306 sizeof(baid_data
->reorder_buf
[0]),
2312 cmd
.mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
);
2313 cmd
.sta_id
= mvm_sta
->sta_id
;
2314 cmd
.add_modify
= STA_MODE_MODIFY
;
2316 cmd
.add_immediate_ba_tid
= (u8
) tid
;
2317 cmd
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
2318 cmd
.rx_ba_window
= cpu_to_le16((u16
)buf_size
);
2320 cmd
.remove_immediate_ba_tid
= (u8
) tid
;
2322 cmd
.modify_mask
= start
? STA_MODIFY_ADD_BA_TID
:
2323 STA_MODIFY_REMOVE_BA_TID
;
2325 status
= ADD_STA_SUCCESS
;
2326 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
,
2327 iwl_mvm_add_sta_cmd_size(mvm
),
2332 switch (status
& IWL_ADD_STA_STATUS_MASK
) {
2333 case ADD_STA_SUCCESS
:
2334 IWL_DEBUG_HT(mvm
, "RX BA Session %sed in fw\n",
2335 start
? "start" : "stopp");
2337 case ADD_STA_IMMEDIATE_BA_FAILURE
:
2338 IWL_WARN(mvm
, "RX BA Session refused by fw\n");
2343 IWL_ERR(mvm
, "RX BA Session failed %sing, status 0x%x\n",
2344 start
? "start" : "stopp", status
);
2354 mvm
->rx_ba_sessions
++;
2356 if (!iwl_mvm_has_new_rx_api(mvm
))
2359 if (WARN_ON(!(status
& IWL_ADD_STA_BAID_VALID_MASK
))) {
2363 baid
= (u8
)((status
& IWL_ADD_STA_BAID_MASK
) >>
2364 IWL_ADD_STA_BAID_SHIFT
);
2365 baid_data
->baid
= baid
;
2366 baid_data
->timeout
= timeout
;
2367 baid_data
->last_rx
= jiffies
;
2368 setup_timer(&baid_data
->session_timer
,
2369 iwl_mvm_rx_agg_session_expired
,
2370 (unsigned long)&mvm
->baid_map
[baid
]);
2371 baid_data
->mvm
= mvm
;
2372 baid_data
->tid
= tid
;
2373 baid_data
->sta_id
= mvm_sta
->sta_id
;
2375 mvm_sta
->tid_to_baid
[tid
] = baid
;
2377 mod_timer(&baid_data
->session_timer
,
2378 TU_TO_EXP_TIME(timeout
* 2));
2380 iwl_mvm_init_reorder_buffer(mvm
, mvm_sta
->sta_id
,
2381 baid_data
, ssn
, buf_size
);
2383 * protect the BA data with RCU to cover a case where our
2384 * internal RX sync mechanism will timeout (not that it's
2385 * supposed to happen) and we will free the session data while
2386 * RX is being processed in parallel
2388 IWL_DEBUG_HT(mvm
, "Sta %d(%d) is assigned to BAID %d\n",
2389 mvm_sta
->sta_id
, tid
, baid
);
2390 WARN_ON(rcu_access_pointer(mvm
->baid_map
[baid
]));
2391 rcu_assign_pointer(mvm
->baid_map
[baid
], baid_data
);
2393 u8 baid
= mvm_sta
->tid_to_baid
[tid
];
2395 if (mvm
->rx_ba_sessions
> 0)
2396 /* check that restart flow didn't zero the counter */
2397 mvm
->rx_ba_sessions
--;
2398 if (!iwl_mvm_has_new_rx_api(mvm
))
2401 if (WARN_ON(baid
== IWL_RX_REORDER_DATA_INVALID_BAID
))
2404 baid_data
= rcu_access_pointer(mvm
->baid_map
[baid
]);
2405 if (WARN_ON(!baid_data
))
2408 /* synchronize all rx queues so we can safely delete */
2409 iwl_mvm_free_reorder(mvm
, baid_data
);
2410 del_timer_sync(&baid_data
->session_timer
);
2411 RCU_INIT_POINTER(mvm
->baid_map
[baid
], NULL
);
2412 kfree_rcu(baid_data
, rcu_head
);
2413 IWL_DEBUG_HT(mvm
, "BAID %d is free\n", baid
);
2422 int iwl_mvm_sta_tx_agg(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
2423 int tid
, u8 queue
, bool start
)
2425 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
2426 struct iwl_mvm_add_sta_cmd cmd
= {};
2430 lockdep_assert_held(&mvm
->mutex
);
2433 mvm_sta
->tfd_queue_msk
|= BIT(queue
);
2434 mvm_sta
->tid_disable_agg
&= ~BIT(tid
);
2436 /* In DQA-mode the queue isn't removed on agg termination */
2437 if (!iwl_mvm_is_dqa_supported(mvm
))
2438 mvm_sta
->tfd_queue_msk
&= ~BIT(queue
);
2439 mvm_sta
->tid_disable_agg
|= BIT(tid
);
2442 cmd
.mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
);
2443 cmd
.sta_id
= mvm_sta
->sta_id
;
2444 cmd
.add_modify
= STA_MODE_MODIFY
;
2445 if (!iwl_mvm_has_new_tx_api(mvm
))
2446 cmd
.modify_mask
= STA_MODIFY_QUEUES
;
2447 cmd
.modify_mask
|= STA_MODIFY_TID_DISABLE_TX
;
2448 cmd
.tfd_queue_msk
= cpu_to_le32(mvm_sta
->tfd_queue_msk
);
2449 cmd
.tid_disable_tx
= cpu_to_le16(mvm_sta
->tid_disable_agg
);
2451 status
= ADD_STA_SUCCESS
;
2452 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
,
2453 iwl_mvm_add_sta_cmd_size(mvm
),
2458 switch (status
& IWL_ADD_STA_STATUS_MASK
) {
2459 case ADD_STA_SUCCESS
:
2463 IWL_ERR(mvm
, "TX BA Session failed %sing, status 0x%x\n",
2464 start
? "start" : "stopp", status
);
2471 const u8 tid_to_mac80211_ac
[] = {
2480 IEEE80211_AC_VO
, /* We treat MGMT as TID 8, which is set as AC_VO */
2483 static const u8 tid_to_ucode_ac
[] = {
2494 int iwl_mvm_sta_tx_agg_start(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
2495 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
)
2497 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
2498 struct iwl_mvm_tid_data
*tid_data
;
2502 if (WARN_ON_ONCE(tid
>= IWL_MAX_TID_COUNT
))
2505 if (mvmsta
->tid_data
[tid
].state
!= IWL_AGG_OFF
) {
2506 IWL_ERR(mvm
, "Start AGG when state is not IWL_AGG_OFF %d!\n",
2507 mvmsta
->tid_data
[tid
].state
);
2511 lockdep_assert_held(&mvm
->mutex
);
2513 spin_lock_bh(&mvmsta
->lock
);
2515 /* possible race condition - we entered D0i3 while starting agg */
2516 if (test_bit(IWL_MVM_STATUS_IN_D0I3
, &mvm
->status
)) {
2517 spin_unlock_bh(&mvmsta
->lock
);
2518 IWL_ERR(mvm
, "Entered D0i3 while starting Tx agg\n");
2522 spin_lock(&mvm
->queue_info_lock
);
2525 * Note the possible cases:
2526 * 1. In DQA mode with an enabled TXQ - TXQ needs to become agg'ed
2527 * 2. Non-DQA mode: the TXQ hasn't yet been enabled, so find a free
2528 * one and mark it as reserved
2529 * 3. In DQA mode, but no traffic yet on this TID: same treatment as in
2530 * non-DQA mode, since the TXQ hasn't yet been allocated
2531 * Don't support case 3 for new TX path as it is not expected to happen
2532 * and aggregation will be offloaded soon anyway
2534 txq_id
= mvmsta
->tid_data
[tid
].txq_id
;
2535 if (iwl_mvm_has_new_tx_api(mvm
)) {
2536 if (txq_id
== IWL_MVM_INVALID_QUEUE
) {
2540 } else if (iwl_mvm_is_dqa_supported(mvm
) &&
2541 unlikely(mvm
->queue_info
[txq_id
].status
==
2542 IWL_MVM_QUEUE_SHARED
)) {
2544 IWL_DEBUG_TX_QUEUES(mvm
,
2545 "Can't start tid %d agg on shared queue!\n",
2548 } else if (!iwl_mvm_is_dqa_supported(mvm
) ||
2549 mvm
->queue_info
[txq_id
].status
!= IWL_MVM_QUEUE_READY
) {
2550 txq_id
= iwl_mvm_find_free_queue(mvm
, mvmsta
->sta_id
,
2551 mvm
->first_agg_queue
,
2552 mvm
->last_agg_queue
);
2555 IWL_ERR(mvm
, "Failed to allocate agg queue\n");
2559 * TXQ shouldn't be in inactive mode for non-DQA, so getting
2560 * an inactive queue from iwl_mvm_find_free_queue() is
2563 WARN_ON(mvm
->queue_info
[txq_id
].status
==
2564 IWL_MVM_QUEUE_INACTIVE
);
2566 /* TXQ hasn't yet been enabled, so mark it only as reserved */
2567 mvm
->queue_info
[txq_id
].status
= IWL_MVM_QUEUE_RESERVED
;
2570 spin_unlock(&mvm
->queue_info_lock
);
2572 IWL_DEBUG_TX_QUEUES(mvm
,
2573 "AGG for tid %d will be on queue #%d\n",
2576 tid_data
= &mvmsta
->tid_data
[tid
];
2577 tid_data
->ssn
= IEEE80211_SEQ_TO_SN(tid_data
->seq_number
);
2578 tid_data
->txq_id
= txq_id
;
2579 *ssn
= tid_data
->ssn
;
2581 IWL_DEBUG_TX_QUEUES(mvm
,
2582 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
2583 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->ssn
,
2584 tid_data
->next_reclaimed
);
2586 if (tid_data
->ssn
== tid_data
->next_reclaimed
) {
2587 tid_data
->state
= IWL_AGG_STARTING
;
2588 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
2590 tid_data
->state
= IWL_EMPTYING_HW_QUEUE_ADDBA
;
2597 spin_unlock(&mvm
->queue_info_lock
);
2599 spin_unlock_bh(&mvmsta
->lock
);
2604 int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
2605 struct ieee80211_sta
*sta
, u16 tid
, u8 buf_size
,
2608 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
2609 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
2610 unsigned int wdg_timeout
=
2611 iwl_mvm_get_wd_timeout(mvm
, vif
, sta
->tdls
, false);
2613 bool alloc_queue
= true;
2614 enum iwl_mvm_queue_status queue_status
;
2617 struct iwl_trans_txq_scd_cfg cfg
= {
2618 .sta_id
= mvmsta
->sta_id
,
2620 .frame_limit
= buf_size
,
2624 BUILD_BUG_ON((sizeof(mvmsta
->agg_tids
) * BITS_PER_BYTE
)
2625 != IWL_MAX_TID_COUNT
);
2627 buf_size
= min_t(int, buf_size
, LINK_QUAL_AGG_FRAME_LIMIT_DEF
);
2629 spin_lock_bh(&mvmsta
->lock
);
2630 ssn
= tid_data
->ssn
;
2631 queue
= tid_data
->txq_id
;
2632 tid_data
->state
= IWL_AGG_ON
;
2633 mvmsta
->agg_tids
|= BIT(tid
);
2634 tid_data
->ssn
= 0xffff;
2635 tid_data
->amsdu_in_ampdu_allowed
= amsdu
;
2636 spin_unlock_bh(&mvmsta
->lock
);
2638 if (iwl_mvm_has_new_tx_api(mvm
)) {
2640 * If no queue iwl_mvm_sta_tx_agg_start() would have failed so
2641 * no need to check queue's status
2643 if (buf_size
< mvmsta
->max_agg_bufsize
)
2646 ret
= iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, queue
, true);
2652 cfg
.fifo
= iwl_mvm_ac_to_tx_fifo
[tid_to_mac80211_ac
[tid
]];
2654 spin_lock_bh(&mvm
->queue_info_lock
);
2655 queue_status
= mvm
->queue_info
[queue
].status
;
2656 spin_unlock_bh(&mvm
->queue_info_lock
);
2658 /* In DQA mode, the existing queue might need to be reconfigured */
2659 if (iwl_mvm_is_dqa_supported(mvm
)) {
2660 /* Maybe there is no need to even alloc a queue... */
2661 if (mvm
->queue_info
[queue
].status
== IWL_MVM_QUEUE_READY
)
2662 alloc_queue
= false;
2665 * Only reconfig the SCD for the queue if the window size has
2666 * changed from current (become smaller)
2668 if (!alloc_queue
&& buf_size
< mvmsta
->max_agg_bufsize
) {
2670 * If reconfiguring an existing queue, it first must be
2673 ret
= iwl_trans_wait_tx_queues_empty(mvm
->trans
,
2677 "Error draining queue before reconfig\n");
2681 ret
= iwl_mvm_reconfig_scd(mvm
, queue
, cfg
.fifo
,
2682 mvmsta
->sta_id
, tid
,
2686 "Error reconfiguring TXQ #%d\n", queue
);
2693 iwl_mvm_enable_txq(mvm
, queue
,
2694 vif
->hw_queue
[tid_to_mac80211_ac
[tid
]], ssn
,
2697 /* Send ADD_STA command to enable aggs only if the queue isn't shared */
2698 if (queue_status
!= IWL_MVM_QUEUE_SHARED
) {
2699 ret
= iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, queue
, true);
2704 /* No need to mark as reserved */
2705 spin_lock_bh(&mvm
->queue_info_lock
);
2706 mvm
->queue_info
[queue
].status
= IWL_MVM_QUEUE_READY
;
2707 spin_unlock_bh(&mvm
->queue_info_lock
);
2711 * Even though in theory the peer could have different
2712 * aggregation reorder buffer sizes for different sessions,
2713 * our ucode doesn't allow for that and has a global limit
2714 * for each station. Therefore, use the minimum of all the
2715 * aggregation sessions and our default value.
2717 mvmsta
->max_agg_bufsize
=
2718 min(mvmsta
->max_agg_bufsize
, buf_size
);
2719 mvmsta
->lq_sta
.lq
.agg_frame_cnt_limit
= mvmsta
->max_agg_bufsize
;
2721 IWL_DEBUG_HT(mvm
, "Tx aggregation enabled on ra = %pM tid = %d\n",
2724 return iwl_mvm_send_lq_cmd(mvm
, &mvmsta
->lq_sta
.lq
, false);
2727 static void iwl_mvm_unreserve_agg_queue(struct iwl_mvm
*mvm
,
2728 struct iwl_mvm_sta
*mvmsta
,
2731 if (iwl_mvm_has_new_tx_api(mvm
))
2734 spin_lock_bh(&mvm
->queue_info_lock
);
2736 * The TXQ is marked as reserved only if no traffic came through yet
2737 * This means no traffic has been sent on this TID (agg'd or not), so
2738 * we no longer have use for the queue. Since it hasn't even been
2739 * allocated through iwl_mvm_enable_txq, so we can just mark it back as
2742 if (mvm
->queue_info
[txq_id
].status
== IWL_MVM_QUEUE_RESERVED
)
2743 mvm
->queue_info
[txq_id
].status
= IWL_MVM_QUEUE_FREE
;
2745 spin_unlock_bh(&mvm
->queue_info_lock
);
2748 int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
2749 struct ieee80211_sta
*sta
, u16 tid
)
2751 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
2752 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
2757 * If mac80211 is cleaning its state, then say that we finished since
2758 * our state has been cleared anyway.
2760 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
2761 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
2765 spin_lock_bh(&mvmsta
->lock
);
2767 txq_id
= tid_data
->txq_id
;
2769 IWL_DEBUG_TX_QUEUES(mvm
, "Stop AGG: sta %d tid %d q %d state %d\n",
2770 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->state
);
2772 mvmsta
->agg_tids
&= ~BIT(tid
);
2774 iwl_mvm_unreserve_agg_queue(mvm
, mvmsta
, txq_id
);
2776 switch (tid_data
->state
) {
2778 tid_data
->ssn
= IEEE80211_SEQ_TO_SN(tid_data
->seq_number
);
2780 IWL_DEBUG_TX_QUEUES(mvm
,
2781 "ssn = %d, next_recl = %d\n",
2782 tid_data
->ssn
, tid_data
->next_reclaimed
);
2784 /* There are still packets for this RA / TID in the HW */
2785 if (tid_data
->ssn
!= tid_data
->next_reclaimed
) {
2786 tid_data
->state
= IWL_EMPTYING_HW_QUEUE_DELBA
;
2791 tid_data
->ssn
= 0xffff;
2792 tid_data
->state
= IWL_AGG_OFF
;
2793 spin_unlock_bh(&mvmsta
->lock
);
2795 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
2797 iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, txq_id
, false);
2799 if (!iwl_mvm_is_dqa_supported(mvm
)) {
2800 int mac_queue
= vif
->hw_queue
[tid_to_mac80211_ac
[tid
]];
2802 iwl_mvm_disable_txq(mvm
, txq_id
, mac_queue
, tid
, 0);
2805 case IWL_AGG_STARTING
:
2806 case IWL_EMPTYING_HW_QUEUE_ADDBA
:
2808 * The agg session has been stopped before it was set up. This
2809 * can happen when the AddBA timer times out for example.
2812 /* No barriers since we are under mutex */
2813 lockdep_assert_held(&mvm
->mutex
);
2815 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
2816 tid_data
->state
= IWL_AGG_OFF
;
2821 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
2822 mvmsta
->sta_id
, tid
, tid_data
->state
);
2824 "\ttid_data->txq_id = %d\n", tid_data
->txq_id
);
2828 spin_unlock_bh(&mvmsta
->lock
);
2833 int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
2834 struct ieee80211_sta
*sta
, u16 tid
)
2836 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
2837 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
2839 enum iwl_mvm_agg_state old_state
;
2842 * First set the agg state to OFF to avoid calling
2843 * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
2845 spin_lock_bh(&mvmsta
->lock
);
2846 txq_id
= tid_data
->txq_id
;
2847 IWL_DEBUG_TX_QUEUES(mvm
, "Flush AGG: sta %d tid %d q %d state %d\n",
2848 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->state
);
2849 old_state
= tid_data
->state
;
2850 tid_data
->state
= IWL_AGG_OFF
;
2851 mvmsta
->agg_tids
&= ~BIT(tid
);
2852 spin_unlock_bh(&mvmsta
->lock
);
2854 iwl_mvm_unreserve_agg_queue(mvm
, mvmsta
, txq_id
);
2856 if (old_state
>= IWL_AGG_ON
) {
2857 iwl_mvm_drain_sta(mvm
, mvmsta
, true);
2858 if (iwl_mvm_flush_tx_path(mvm
, BIT(txq_id
), 0))
2859 IWL_ERR(mvm
, "Couldn't flush the AGG queue\n");
2860 iwl_trans_wait_tx_queues_empty(mvm
->trans
,
2861 mvmsta
->tfd_queue_msk
);
2862 iwl_mvm_drain_sta(mvm
, mvmsta
, false);
2864 iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, txq_id
, false);
2866 if (!iwl_mvm_is_dqa_supported(mvm
)) {
2867 int mac_queue
= vif
->hw_queue
[tid_to_mac80211_ac
[tid
]];
2869 iwl_mvm_disable_txq(mvm
, tid_data
->txq_id
, mac_queue
,
2877 static int iwl_mvm_set_fw_key_idx(struct iwl_mvm
*mvm
)
2879 int i
, max
= -1, max_offs
= -1;
2881 lockdep_assert_held(&mvm
->mutex
);
2883 /* Pick the unused key offset with the highest 'deleted'
2884 * counter. Every time a key is deleted, all the counters
2885 * are incremented and the one that was just deleted is
2886 * reset to zero. Thus, the highest counter is the one
2887 * that was deleted longest ago. Pick that one.
2889 for (i
= 0; i
< STA_KEY_MAX_NUM
; i
++) {
2890 if (test_bit(i
, mvm
->fw_key_table
))
2892 if (mvm
->fw_key_deleted
[i
] > max
) {
2893 max
= mvm
->fw_key_deleted
[i
];
2899 return STA_KEY_IDX_INVALID
;
2904 static struct iwl_mvm_sta
*iwl_mvm_get_key_sta(struct iwl_mvm
*mvm
,
2905 struct ieee80211_vif
*vif
,
2906 struct ieee80211_sta
*sta
)
2908 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2911 return iwl_mvm_sta_from_mac80211(sta
);
2914 * The device expects GTKs for station interfaces to be
2915 * installed as GTKs for the AP station. If we have no
2916 * station ID, then use AP's station ID.
2918 if (vif
->type
== NL80211_IFTYPE_STATION
&&
2919 mvmvif
->ap_sta_id
!= IWL_MVM_INVALID_STA
) {
2920 u8 sta_id
= mvmvif
->ap_sta_id
;
2922 sta
= rcu_dereference_check(mvm
->fw_id_to_mac_id
[sta_id
],
2923 lockdep_is_held(&mvm
->mutex
));
2926 * It is possible that the 'sta' parameter is NULL,
2927 * for example when a GTK is removed - the sta_id will then
2928 * be the AP ID, and no station was passed by mac80211.
2930 if (IS_ERR_OR_NULL(sta
))
2933 return iwl_mvm_sta_from_mac80211(sta
);
2939 static int iwl_mvm_send_sta_key(struct iwl_mvm
*mvm
,
2940 struct iwl_mvm_sta
*mvm_sta
,
2941 struct ieee80211_key_conf
*key
, bool mcast
,
2942 u32 tkip_iv32
, u16
*tkip_p1k
, u32 cmd_flags
,
2946 struct iwl_mvm_add_sta_key_cmd_v1 cmd_v1
;
2947 struct iwl_mvm_add_sta_key_cmd cmd
;
2955 bool new_api
= fw_has_api(&mvm
->fw
->ucode_capa
,
2956 IWL_UCODE_TLV_API_TKIP_MIC_KEYS
);
2958 keyidx
= (key
->keyidx
<< STA_KEY_FLG_KEYID_POS
) &
2959 STA_KEY_FLG_KEYID_MSK
;
2960 key_flags
= cpu_to_le16(keyidx
);
2961 key_flags
|= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP
);
2963 switch (key
->cipher
) {
2964 case WLAN_CIPHER_SUITE_TKIP
:
2965 key_flags
|= cpu_to_le16(STA_KEY_FLG_TKIP
);
2967 memcpy((void *)&u
.cmd
.tx_mic_key
,
2968 &key
->key
[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY
],
2971 memcpy((void *)&u
.cmd
.rx_mic_key
,
2972 &key
->key
[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY
],
2974 pn
= atomic64_read(&key
->tx_pn
);
2977 u
.cmd_v1
.tkip_rx_tsc_byte2
= tkip_iv32
;
2978 for (i
= 0; i
< 5; i
++)
2979 u
.cmd_v1
.tkip_rx_ttak
[i
] =
2980 cpu_to_le16(tkip_p1k
[i
]);
2982 memcpy(u
.cmd
.common
.key
, key
->key
, key
->keylen
);
2984 case WLAN_CIPHER_SUITE_CCMP
:
2985 key_flags
|= cpu_to_le16(STA_KEY_FLG_CCM
);
2986 memcpy(u
.cmd
.common
.key
, key
->key
, key
->keylen
);
2988 pn
= atomic64_read(&key
->tx_pn
);
2990 case WLAN_CIPHER_SUITE_WEP104
:
2991 key_flags
|= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES
);
2993 case WLAN_CIPHER_SUITE_WEP40
:
2994 key_flags
|= cpu_to_le16(STA_KEY_FLG_WEP
);
2995 memcpy(u
.cmd
.common
.key
+ 3, key
->key
, key
->keylen
);
2997 case WLAN_CIPHER_SUITE_GCMP_256
:
2998 key_flags
|= cpu_to_le16(STA_KEY_FLG_KEY_32BYTES
);
3000 case WLAN_CIPHER_SUITE_GCMP
:
3001 key_flags
|= cpu_to_le16(STA_KEY_FLG_GCMP
);
3002 memcpy(u
.cmd
.common
.key
, key
->key
, key
->keylen
);
3004 pn
= atomic64_read(&key
->tx_pn
);
3007 key_flags
|= cpu_to_le16(STA_KEY_FLG_EXT
);
3008 memcpy(u
.cmd
.common
.key
, key
->key
, key
->keylen
);
3012 key_flags
|= cpu_to_le16(STA_KEY_MULTICAST
);
3014 u
.cmd
.common
.key_offset
= key_offset
;
3015 u
.cmd
.common
.key_flags
= key_flags
;
3016 u
.cmd
.common
.sta_id
= mvm_sta
->sta_id
;
3019 u
.cmd
.transmit_seq_cnt
= cpu_to_le64(pn
);
3020 size
= sizeof(u
.cmd
);
3022 size
= sizeof(u
.cmd_v1
);
3025 status
= ADD_STA_SUCCESS
;
3026 if (cmd_flags
& CMD_ASYNC
)
3027 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA_KEY
, CMD_ASYNC
, size
,
3030 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA_KEY
, size
,
3034 case ADD_STA_SUCCESS
:
3035 IWL_DEBUG_WEP(mvm
, "MODIFY_STA: set dynamic key passed\n");
3039 IWL_ERR(mvm
, "MODIFY_STA: set dynamic key failed\n");
3046 static int iwl_mvm_send_sta_igtk(struct iwl_mvm
*mvm
,
3047 struct ieee80211_key_conf
*keyconf
,
3048 u8 sta_id
, bool remove_key
)
3050 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd
= {};
3052 /* verify the key details match the required command's expectations */
3053 if (WARN_ON((keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
) ||
3054 (keyconf
->keyidx
!= 4 && keyconf
->keyidx
!= 5) ||
3055 (keyconf
->cipher
!= WLAN_CIPHER_SUITE_AES_CMAC
&&
3056 keyconf
->cipher
!= WLAN_CIPHER_SUITE_BIP_GMAC_128
&&
3057 keyconf
->cipher
!= WLAN_CIPHER_SUITE_BIP_GMAC_256
)))
3060 if (WARN_ON(!iwl_mvm_has_new_rx_api(mvm
) &&
3061 keyconf
->cipher
!= WLAN_CIPHER_SUITE_AES_CMAC
))
3064 igtk_cmd
.key_id
= cpu_to_le32(keyconf
->keyidx
);
3065 igtk_cmd
.sta_id
= cpu_to_le32(sta_id
);
3068 igtk_cmd
.ctrl_flags
|= cpu_to_le32(STA_KEY_NOT_VALID
);
3070 struct ieee80211_key_seq seq
;
3073 switch (keyconf
->cipher
) {
3074 case WLAN_CIPHER_SUITE_AES_CMAC
:
3075 igtk_cmd
.ctrl_flags
|= cpu_to_le32(STA_KEY_FLG_CCM
);
3077 case WLAN_CIPHER_SUITE_BIP_GMAC_128
:
3078 case WLAN_CIPHER_SUITE_BIP_GMAC_256
:
3079 igtk_cmd
.ctrl_flags
|= cpu_to_le32(STA_KEY_FLG_GCMP
);
3085 memcpy(igtk_cmd
.igtk
, keyconf
->key
, keyconf
->keylen
);
3086 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_256
)
3087 igtk_cmd
.ctrl_flags
|=
3088 cpu_to_le32(STA_KEY_FLG_KEY_32BYTES
);
3089 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
3090 pn
= seq
.aes_cmac
.pn
;
3091 igtk_cmd
.receive_seq_cnt
= cpu_to_le64(((u64
) pn
[5] << 0) |
3092 ((u64
) pn
[4] << 8) |
3093 ((u64
) pn
[3] << 16) |
3094 ((u64
) pn
[2] << 24) |
3095 ((u64
) pn
[1] << 32) |
3096 ((u64
) pn
[0] << 40));
3099 IWL_DEBUG_INFO(mvm
, "%s igtk for sta %u\n",
3100 remove_key
? "removing" : "installing",
3103 if (!iwl_mvm_has_new_rx_api(mvm
)) {
3104 struct iwl_mvm_mgmt_mcast_key_cmd_v1 igtk_cmd_v1
= {
3105 .ctrl_flags
= igtk_cmd
.ctrl_flags
,
3106 .key_id
= igtk_cmd
.key_id
,
3107 .sta_id
= igtk_cmd
.sta_id
,
3108 .receive_seq_cnt
= igtk_cmd
.receive_seq_cnt
3111 memcpy(igtk_cmd_v1
.igtk
, igtk_cmd
.igtk
,
3112 ARRAY_SIZE(igtk_cmd_v1
.igtk
));
3113 return iwl_mvm_send_cmd_pdu(mvm
, MGMT_MCAST_KEY
, 0,
3114 sizeof(igtk_cmd_v1
), &igtk_cmd_v1
);
3116 return iwl_mvm_send_cmd_pdu(mvm
, MGMT_MCAST_KEY
, 0,
3117 sizeof(igtk_cmd
), &igtk_cmd
);
3121 static inline u8
*iwl_mvm_get_mac_addr(struct iwl_mvm
*mvm
,
3122 struct ieee80211_vif
*vif
,
3123 struct ieee80211_sta
*sta
)
3125 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3130 if (vif
->type
== NL80211_IFTYPE_STATION
&&
3131 mvmvif
->ap_sta_id
!= IWL_MVM_INVALID_STA
) {
3132 u8 sta_id
= mvmvif
->ap_sta_id
;
3133 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
3134 lockdep_is_held(&mvm
->mutex
));
3142 static int __iwl_mvm_set_sta_key(struct iwl_mvm
*mvm
,
3143 struct ieee80211_vif
*vif
,
3144 struct ieee80211_sta
*sta
,
3145 struct ieee80211_key_conf
*keyconf
,
3149 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
3152 struct ieee80211_key_seq seq
;
3155 switch (keyconf
->cipher
) {
3156 case WLAN_CIPHER_SUITE_TKIP
:
3157 addr
= iwl_mvm_get_mac_addr(mvm
, vif
, sta
);
3158 /* get phase 1 key from mac80211 */
3159 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
3160 ieee80211_get_tkip_rx_p1k(keyconf
, addr
, seq
.tkip
.iv32
, p1k
);
3161 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
3162 seq
.tkip
.iv32
, p1k
, 0, key_offset
);
3164 case WLAN_CIPHER_SUITE_CCMP
:
3165 case WLAN_CIPHER_SUITE_WEP40
:
3166 case WLAN_CIPHER_SUITE_WEP104
:
3167 case WLAN_CIPHER_SUITE_GCMP
:
3168 case WLAN_CIPHER_SUITE_GCMP_256
:
3169 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
3170 0, NULL
, 0, key_offset
);
3173 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
3174 0, NULL
, 0, key_offset
);
3180 static int __iwl_mvm_remove_sta_key(struct iwl_mvm
*mvm
, u8 sta_id
,
3181 struct ieee80211_key_conf
*keyconf
,
3185 struct iwl_mvm_add_sta_key_cmd_v1 cmd_v1
;
3186 struct iwl_mvm_add_sta_key_cmd cmd
;
3188 bool new_api
= fw_has_api(&mvm
->fw
->ucode_capa
,
3189 IWL_UCODE_TLV_API_TKIP_MIC_KEYS
);
3194 key_flags
= cpu_to_le16((keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
) &
3195 STA_KEY_FLG_KEYID_MSK
);
3196 key_flags
|= cpu_to_le16(STA_KEY_FLG_NO_ENC
| STA_KEY_FLG_WEP_KEY_MAP
);
3197 key_flags
|= cpu_to_le16(STA_KEY_NOT_VALID
);
3200 key_flags
|= cpu_to_le16(STA_KEY_MULTICAST
);
3203 * The fields assigned here are in the same location at the start
3204 * of the command, so we can do this union trick.
3206 u
.cmd
.common
.key_flags
= key_flags
;
3207 u
.cmd
.common
.key_offset
= keyconf
->hw_key_idx
;
3208 u
.cmd
.common
.sta_id
= sta_id
;
3210 size
= new_api
? sizeof(u
.cmd
) : sizeof(u
.cmd_v1
);
3212 status
= ADD_STA_SUCCESS
;
3213 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA_KEY
, size
, &u
.cmd
,
3217 case ADD_STA_SUCCESS
:
3218 IWL_DEBUG_WEP(mvm
, "MODIFY_STA: remove sta key passed\n");
3222 IWL_ERR(mvm
, "MODIFY_STA: remove sta key failed\n");
3229 int iwl_mvm_set_sta_key(struct iwl_mvm
*mvm
,
3230 struct ieee80211_vif
*vif
,
3231 struct ieee80211_sta
*sta
,
3232 struct ieee80211_key_conf
*keyconf
,
3235 bool mcast
= !(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
3236 struct iwl_mvm_sta
*mvm_sta
;
3239 static const u8 __maybe_unused zero_addr
[ETH_ALEN
] = {0};
3241 lockdep_assert_held(&mvm
->mutex
);
3243 /* Get the station id from the mvm local station table */
3244 mvm_sta
= iwl_mvm_get_key_sta(mvm
, vif
, sta
);
3246 IWL_ERR(mvm
, "Failed to find station\n");
3249 sta_id
= mvm_sta
->sta_id
;
3251 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
||
3252 keyconf
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_128
||
3253 keyconf
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_256
) {
3254 ret
= iwl_mvm_send_sta_igtk(mvm
, keyconf
, sta_id
, false);
3259 * It is possible that the 'sta' parameter is NULL, and thus
3260 * there is a need to retrieve the sta from the local station table.
3263 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
3264 lockdep_is_held(&mvm
->mutex
));
3265 if (IS_ERR_OR_NULL(sta
)) {
3266 IWL_ERR(mvm
, "Invalid station id\n");
3271 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta
)->vif
!= vif
))
3274 /* If the key_offset is not pre-assigned, we need to find a
3275 * new offset to use. In normal cases, the offset is not
3276 * pre-assigned, but during HW_RESTART we want to reuse the
3277 * same indices, so we pass them when this function is called.
3279 * In D3 entry, we need to hardcoded the indices (because the
3280 * firmware hardcodes the PTK offset to 0). In this case, we
3281 * need to make sure we don't overwrite the hw_key_idx in the
3282 * keyconf structure, because otherwise we cannot configure
3283 * the original ones back when resuming.
3285 if (key_offset
== STA_KEY_IDX_INVALID
) {
3286 key_offset
= iwl_mvm_set_fw_key_idx(mvm
);
3287 if (key_offset
== STA_KEY_IDX_INVALID
)
3289 keyconf
->hw_key_idx
= key_offset
;
3292 ret
= __iwl_mvm_set_sta_key(mvm
, vif
, sta
, keyconf
, key_offset
, mcast
);
3297 * For WEP, the same key is used for multicast and unicast. Upload it
3298 * again, using the same key offset, and now pointing the other one
3299 * to the same key slot (offset).
3300 * If this fails, remove the original as well.
3302 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
3303 keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP104
) {
3304 ret
= __iwl_mvm_set_sta_key(mvm
, vif
, sta
, keyconf
,
3305 key_offset
, !mcast
);
3307 __iwl_mvm_remove_sta_key(mvm
, sta_id
, keyconf
, mcast
);
3312 __set_bit(key_offset
, mvm
->fw_key_table
);
3315 IWL_DEBUG_WEP(mvm
, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
3316 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
3317 sta
? sta
->addr
: zero_addr
, ret
);
3321 int iwl_mvm_remove_sta_key(struct iwl_mvm
*mvm
,
3322 struct ieee80211_vif
*vif
,
3323 struct ieee80211_sta
*sta
,
3324 struct ieee80211_key_conf
*keyconf
)
3326 bool mcast
= !(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
3327 struct iwl_mvm_sta
*mvm_sta
;
3328 u8 sta_id
= IWL_MVM_INVALID_STA
;
3331 lockdep_assert_held(&mvm
->mutex
);
3333 /* Get the station from the mvm local station table */
3334 mvm_sta
= iwl_mvm_get_key_sta(mvm
, vif
, sta
);
3336 sta_id
= mvm_sta
->sta_id
;
3338 IWL_DEBUG_WEP(mvm
, "mvm remove dynamic key: idx=%d sta=%d\n",
3339 keyconf
->keyidx
, sta_id
);
3341 if (mvm_sta
&& (keyconf
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
||
3342 keyconf
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_128
||
3343 keyconf
->cipher
== WLAN_CIPHER_SUITE_BIP_GMAC_256
))
3344 return iwl_mvm_send_sta_igtk(mvm
, keyconf
, sta_id
, true);
3346 if (!__test_and_clear_bit(keyconf
->hw_key_idx
, mvm
->fw_key_table
)) {
3347 IWL_ERR(mvm
, "offset %d not used in fw key table.\n",
3348 keyconf
->hw_key_idx
);
3352 /* track which key was deleted last */
3353 for (i
= 0; i
< STA_KEY_MAX_NUM
; i
++) {
3354 if (mvm
->fw_key_deleted
[i
] < U8_MAX
)
3355 mvm
->fw_key_deleted
[i
]++;
3357 mvm
->fw_key_deleted
[keyconf
->hw_key_idx
] = 0;
3360 IWL_DEBUG_WEP(mvm
, "station non-existent, early return.\n");
3364 ret
= __iwl_mvm_remove_sta_key(mvm
, sta_id
, keyconf
, mcast
);
3368 /* delete WEP key twice to get rid of (now useless) offset */
3369 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
3370 keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
3371 ret
= __iwl_mvm_remove_sta_key(mvm
, sta_id
, keyconf
, !mcast
);
3376 void iwl_mvm_update_tkip_key(struct iwl_mvm
*mvm
,
3377 struct ieee80211_vif
*vif
,
3378 struct ieee80211_key_conf
*keyconf
,
3379 struct ieee80211_sta
*sta
, u32 iv32
,
3382 struct iwl_mvm_sta
*mvm_sta
;
3383 bool mcast
= !(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
3387 mvm_sta
= iwl_mvm_get_key_sta(mvm
, vif
, sta
);
3388 if (WARN_ON_ONCE(!mvm_sta
))
3390 iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
3391 iv32
, phase1key
, CMD_ASYNC
, keyconf
->hw_key_idx
);
3397 void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm
*mvm
,
3398 struct ieee80211_sta
*sta
)
3400 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
3401 struct iwl_mvm_add_sta_cmd cmd
= {
3402 .add_modify
= STA_MODE_MODIFY
,
3403 .sta_id
= mvmsta
->sta_id
,
3404 .station_flags_msk
= cpu_to_le32(STA_FLG_PS
),
3405 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
3409 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, CMD_ASYNC
,
3410 iwl_mvm_add_sta_cmd_size(mvm
), &cmd
);
3412 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
3415 void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm
*mvm
,
3416 struct ieee80211_sta
*sta
,
3417 enum ieee80211_frame_release_type reason
,
3418 u16 cnt
, u16 tids
, bool more_data
,
3419 bool single_sta_queue
)
3421 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
3422 struct iwl_mvm_add_sta_cmd cmd
= {
3423 .add_modify
= STA_MODE_MODIFY
,
3424 .sta_id
= mvmsta
->sta_id
,
3425 .modify_mask
= STA_MODIFY_SLEEPING_STA_TX_COUNT
,
3426 .sleep_tx_count
= cpu_to_le16(cnt
),
3427 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
3430 unsigned long _tids
= tids
;
3432 /* convert TIDs to ACs - we don't support TSPEC so that's OK
3433 * Note that this field is reserved and unused by firmware not
3434 * supporting GO uAPSD, so it's safe to always do this.
3436 for_each_set_bit(tid
, &_tids
, IWL_MAX_TID_COUNT
)
3437 cmd
.awake_acs
|= BIT(tid_to_ucode_ac
[tid
]);
3439 /* If we're releasing frames from aggregation or dqa queues then check
3440 * if all the queues that we're releasing frames from, combined, have:
3441 * - more frames than the service period, in which case more_data
3443 * - fewer than 'cnt' frames, in which case we need to adjust the
3444 * firmware command (but do that unconditionally)
3446 if (single_sta_queue
) {
3447 int remaining
= cnt
;
3450 spin_lock_bh(&mvmsta
->lock
);
3451 for_each_set_bit(tid
, &_tids
, IWL_MAX_TID_COUNT
) {
3452 struct iwl_mvm_tid_data
*tid_data
;
3455 tid_data
= &mvmsta
->tid_data
[tid
];
3456 if (WARN(!iwl_mvm_is_dqa_supported(mvm
) &&
3457 tid_data
->state
!= IWL_AGG_ON
&&
3458 tid_data
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
,
3459 "TID %d state is %d\n",
3460 tid
, tid_data
->state
)) {
3461 spin_unlock_bh(&mvmsta
->lock
);
3462 ieee80211_sta_eosp(sta
);
3466 n_queued
= iwl_mvm_tid_queued(tid_data
);
3467 if (n_queued
> remaining
) {
3472 remaining
-= n_queued
;
3474 sleep_tx_count
= cnt
- remaining
;
3475 if (reason
== IEEE80211_FRAME_RELEASE_UAPSD
)
3476 mvmsta
->sleep_tx_count
= sleep_tx_count
;
3477 spin_unlock_bh(&mvmsta
->lock
);
3479 cmd
.sleep_tx_count
= cpu_to_le16(sleep_tx_count
);
3480 if (WARN_ON(cnt
- remaining
== 0)) {
3481 ieee80211_sta_eosp(sta
);
3486 /* Note: this is ignored by firmware not supporting GO uAPSD */
3488 cmd
.sleep_state_flags
|= STA_SLEEP_STATE_MOREDATA
;
3490 if (reason
== IEEE80211_FRAME_RELEASE_PSPOLL
) {
3491 mvmsta
->next_status_eosp
= true;
3492 cmd
.sleep_state_flags
|= STA_SLEEP_STATE_PS_POLL
;
3494 cmd
.sleep_state_flags
|= STA_SLEEP_STATE_UAPSD
;
3497 /* block the Tx queues until the FW updated the sleep Tx count */
3498 iwl_trans_block_txq_ptrs(mvm
->trans
, true);
3500 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
,
3501 CMD_ASYNC
| CMD_WANT_ASYNC_CALLBACK
,
3502 iwl_mvm_add_sta_cmd_size(mvm
), &cmd
);
3504 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
3507 void iwl_mvm_rx_eosp_notif(struct iwl_mvm
*mvm
,
3508 struct iwl_rx_cmd_buffer
*rxb
)
3510 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
3511 struct iwl_mvm_eosp_notification
*notif
= (void *)pkt
->data
;
3512 struct ieee80211_sta
*sta
;
3513 u32 sta_id
= le32_to_cpu(notif
->sta_id
);
3515 if (WARN_ON_ONCE(sta_id
>= IWL_MVM_STATION_COUNT
))
3519 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
3520 if (!IS_ERR_OR_NULL(sta
))
3521 ieee80211_sta_eosp(sta
);
3525 void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm
*mvm
,
3526 struct iwl_mvm_sta
*mvmsta
, bool disable
)
3528 struct iwl_mvm_add_sta_cmd cmd
= {
3529 .add_modify
= STA_MODE_MODIFY
,
3530 .sta_id
= mvmsta
->sta_id
,
3531 .station_flags
= disable
? cpu_to_le32(STA_FLG_DISABLE_TX
) : 0,
3532 .station_flags_msk
= cpu_to_le32(STA_FLG_DISABLE_TX
),
3533 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
3537 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, CMD_ASYNC
,
3538 iwl_mvm_add_sta_cmd_size(mvm
), &cmd
);
3540 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
3543 void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm
*mvm
,
3544 struct ieee80211_sta
*sta
,
3547 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
3549 spin_lock_bh(&mvm_sta
->lock
);
3551 if (mvm_sta
->disable_tx
== disable
) {
3552 spin_unlock_bh(&mvm_sta
->lock
);
3556 mvm_sta
->disable_tx
= disable
;
3559 * Tell mac80211 to start/stop queuing tx for this station,
3560 * but don't stop queuing if there are still pending frames
3563 if (disable
|| !atomic_read(&mvm
->pending_frames
[mvm_sta
->sta_id
]))
3564 ieee80211_sta_block_awake(mvm
->hw
, sta
, disable
);
3566 iwl_mvm_sta_modify_disable_tx(mvm
, mvm_sta
, disable
);
3568 spin_unlock_bh(&mvm_sta
->lock
);
3571 static void iwl_mvm_int_sta_modify_disable_tx(struct iwl_mvm
*mvm
,
3572 struct iwl_mvm_vif
*mvmvif
,
3573 struct iwl_mvm_int_sta
*sta
,
3576 u32 id
= FW_CMD_ID_AND_COLOR(mvmvif
->id
, mvmvif
->color
);
3577 struct iwl_mvm_add_sta_cmd cmd
= {
3578 .add_modify
= STA_MODE_MODIFY
,
3579 .sta_id
= sta
->sta_id
,
3580 .station_flags
= disable
? cpu_to_le32(STA_FLG_DISABLE_TX
) : 0,
3581 .station_flags_msk
= cpu_to_le32(STA_FLG_DISABLE_TX
),
3582 .mac_id_n_color
= cpu_to_le32(id
),
3586 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, 0,
3587 iwl_mvm_add_sta_cmd_size(mvm
), &cmd
);
3589 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
3592 void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm
*mvm
,
3593 struct iwl_mvm_vif
*mvmvif
,
3596 struct ieee80211_sta
*sta
;
3597 struct iwl_mvm_sta
*mvm_sta
;
3600 lockdep_assert_held(&mvm
->mutex
);
3602 /* Block/unblock all the stations of the given mvmvif */
3603 for (i
= 0; i
< ARRAY_SIZE(mvm
->fw_id_to_mac_id
); i
++) {
3604 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[i
],
3605 lockdep_is_held(&mvm
->mutex
));
3606 if (IS_ERR_OR_NULL(sta
))
3609 mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
3610 if (mvm_sta
->mac_id_n_color
!=
3611 FW_CMD_ID_AND_COLOR(mvmvif
->id
, mvmvif
->color
))
3614 iwl_mvm_sta_modify_disable_tx_ap(mvm
, sta
, disable
);
3617 if (!fw_has_api(&mvm
->fw
->ucode_capa
, IWL_UCODE_TLV_API_STA_TYPE
))
3620 /* Need to block/unblock also multicast station */
3621 if (mvmvif
->mcast_sta
.sta_id
!= IWL_MVM_INVALID_STA
)
3622 iwl_mvm_int_sta_modify_disable_tx(mvm
, mvmvif
,
3623 &mvmvif
->mcast_sta
, disable
);
3626 * Only unblock the broadcast station (FW blocks it for immediate
3627 * quiet, not the driver)
3629 if (!disable
&& mvmvif
->bcast_sta
.sta_id
!= IWL_MVM_INVALID_STA
)
3630 iwl_mvm_int_sta_modify_disable_tx(mvm
, mvmvif
,
3631 &mvmvif
->bcast_sta
, disable
);
3634 void iwl_mvm_csa_client_absent(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
3636 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
3637 struct iwl_mvm_sta
*mvmsta
;
3641 mvmsta
= iwl_mvm_sta_from_staid_rcu(mvm
, mvmvif
->ap_sta_id
);
3643 if (!WARN_ON(!mvmsta
))
3644 iwl_mvm_sta_modify_disable_tx(mvm
, mvmsta
, true);