1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10 * Copyright(c) 2016 Intel Deutschland GmbH
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
26 * The full GNU General Public License is included in this distribution
27 * in the file called COPYING.
29 * Contact Information:
30 * Intel Linux Wireless <linuxwifi@intel.com>
31 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
35 * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved.
36 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
37 * Copyright(c) 2016 Intel Deutschland GmbH
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * * Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in
48 * the documentation and/or other materials provided with the
50 * * Neither the name Intel Corporation nor the names of its
51 * contributors may be used to endorse or promote products derived
52 * from this software without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 *****************************************************************************/
67 #include <net/mac80211.h>
74 * New version of ADD_STA_sta command added new fields at the end of the
75 * structure, so sending the size of the relevant API's structure is enough to
76 * support both API versions.
78 static inline int iwl_mvm_add_sta_cmd_size(struct iwl_mvm
*mvm
)
80 return iwl_mvm_has_new_rx_api(mvm
) ?
81 sizeof(struct iwl_mvm_add_sta_cmd
) :
82 sizeof(struct iwl_mvm_add_sta_cmd_v7
);
85 static int iwl_mvm_find_free_sta_id(struct iwl_mvm
*mvm
,
86 enum nl80211_iftype iftype
)
91 BUILD_BUG_ON(IWL_MVM_STATION_COUNT
> 32);
92 WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
));
94 lockdep_assert_held(&mvm
->mutex
);
96 /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */
97 if (iftype
!= NL80211_IFTYPE_STATION
)
98 reserved_ids
= BIT(0);
100 /* Don't take rcu_read_lock() since we are protected by mvm->mutex */
101 for (sta_id
= 0; sta_id
< IWL_MVM_STATION_COUNT
; sta_id
++) {
102 if (BIT(sta_id
) & reserved_ids
)
105 if (!rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
106 lockdep_is_held(&mvm
->mutex
)))
109 return IWL_MVM_STATION_COUNT
;
112 /* send station add/update command to firmware */
113 int iwl_mvm_sta_send_to_fw(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
114 bool update
, unsigned int flags
)
116 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
117 struct iwl_mvm_add_sta_cmd add_sta_cmd
= {
118 .sta_id
= mvm_sta
->sta_id
,
119 .mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
),
120 .add_modify
= update
? 1 : 0,
121 .station_flags_msk
= cpu_to_le32(STA_FLG_FAT_EN_MSK
|
122 STA_FLG_MIMO_EN_MSK
),
123 .tid_disable_tx
= cpu_to_le16(mvm_sta
->tid_disable_agg
),
127 u32 agg_size
= 0, mpdu_dens
= 0;
129 if (!update
|| (flags
& STA_MODIFY_QUEUES
)) {
130 add_sta_cmd
.tfd_queue_msk
= cpu_to_le32(mvm_sta
->tfd_queue_msk
);
131 memcpy(&add_sta_cmd
.addr
, sta
->addr
, ETH_ALEN
);
133 if (flags
& STA_MODIFY_QUEUES
)
134 add_sta_cmd
.modify_mask
|= STA_MODIFY_QUEUES
;
137 switch (sta
->bandwidth
) {
138 case IEEE80211_STA_RX_BW_160
:
139 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_FAT_EN_160MHZ
);
141 case IEEE80211_STA_RX_BW_80
:
142 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_FAT_EN_80MHZ
);
144 case IEEE80211_STA_RX_BW_40
:
145 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_FAT_EN_40MHZ
);
147 case IEEE80211_STA_RX_BW_20
:
148 if (sta
->ht_cap
.ht_supported
)
149 add_sta_cmd
.station_flags
|=
150 cpu_to_le32(STA_FLG_FAT_EN_20MHZ
);
154 switch (sta
->rx_nss
) {
156 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_SISO
);
159 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2
);
162 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3
);
166 switch (sta
->smps_mode
) {
167 case IEEE80211_SMPS_AUTOMATIC
:
168 case IEEE80211_SMPS_NUM_MODES
:
171 case IEEE80211_SMPS_STATIC
:
173 add_sta_cmd
.station_flags
&= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK
);
174 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_SISO
);
176 case IEEE80211_SMPS_DYNAMIC
:
177 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_RTS_MIMO_PROT
);
179 case IEEE80211_SMPS_OFF
:
184 if (sta
->ht_cap
.ht_supported
) {
185 add_sta_cmd
.station_flags_msk
|=
186 cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK
|
187 STA_FLG_AGG_MPDU_DENS_MSK
);
189 mpdu_dens
= sta
->ht_cap
.ampdu_density
;
192 if (sta
->vht_cap
.vht_supported
) {
193 agg_size
= sta
->vht_cap
.cap
&
194 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
;
196 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
197 } else if (sta
->ht_cap
.ht_supported
) {
198 agg_size
= sta
->ht_cap
.ampdu_factor
;
201 add_sta_cmd
.station_flags
|=
202 cpu_to_le32(agg_size
<< STA_FLG_MAX_AGG_SIZE_SHIFT
);
203 add_sta_cmd
.station_flags
|=
204 cpu_to_le32(mpdu_dens
<< STA_FLG_AGG_MPDU_DENS_SHIFT
);
206 status
= ADD_STA_SUCCESS
;
207 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
,
208 iwl_mvm_add_sta_cmd_size(mvm
),
209 &add_sta_cmd
, &status
);
213 switch (status
& IWL_ADD_STA_STATUS_MASK
) {
214 case ADD_STA_SUCCESS
:
215 IWL_DEBUG_ASSOC(mvm
, "ADD_STA PASSED\n");
219 IWL_ERR(mvm
, "ADD_STA failed\n");
226 static void iwl_mvm_rx_agg_session_expired(unsigned long data
)
228 struct iwl_mvm_baid_data __rcu
**rcu_ptr
= (void *)data
;
229 struct iwl_mvm_baid_data
*ba_data
;
230 struct ieee80211_sta
*sta
;
231 struct iwl_mvm_sta
*mvm_sta
;
232 unsigned long timeout
;
236 ba_data
= rcu_dereference(*rcu_ptr
);
238 if (WARN_ON(!ba_data
))
241 if (!ba_data
->timeout
)
244 timeout
= ba_data
->last_rx
+ TU_TO_JIFFIES(ba_data
->timeout
* 2);
245 if (time_is_after_jiffies(timeout
)) {
246 mod_timer(&ba_data
->session_timer
, timeout
);
251 sta
= rcu_dereference(ba_data
->mvm
->fw_id_to_mac_id
[ba_data
->sta_id
]);
252 mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
253 ieee80211_stop_rx_ba_session_offl(mvm_sta
->vif
,
254 sta
->addr
, ba_data
->tid
);
259 static int iwl_mvm_tdls_sta_init(struct iwl_mvm
*mvm
,
260 struct ieee80211_sta
*sta
)
262 unsigned long used_hw_queues
;
263 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
264 unsigned int wdg_timeout
=
265 iwl_mvm_get_wd_timeout(mvm
, NULL
, true, false);
268 lockdep_assert_held(&mvm
->mutex
);
270 used_hw_queues
= iwl_mvm_get_used_hw_queues(mvm
, NULL
);
272 /* Find available queues, and allocate them to the ACs */
273 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
274 u8 queue
= find_first_zero_bit(&used_hw_queues
,
275 mvm
->first_agg_queue
);
277 if (queue
>= mvm
->first_agg_queue
) {
278 IWL_ERR(mvm
, "Failed to allocate STA queue\n");
282 __set_bit(queue
, &used_hw_queues
);
283 mvmsta
->hw_queue
[ac
] = queue
;
286 /* Found a place for all queues - enable them */
287 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
288 iwl_mvm_enable_ac_txq(mvm
, mvmsta
->hw_queue
[ac
],
289 mvmsta
->hw_queue
[ac
],
290 iwl_mvm_ac_to_tx_fifo
[ac
], 0,
292 mvmsta
->tfd_queue_msk
|= BIT(mvmsta
->hw_queue
[ac
]);
298 static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm
*mvm
,
299 struct ieee80211_sta
*sta
)
301 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
302 unsigned long sta_msk
;
305 lockdep_assert_held(&mvm
->mutex
);
307 /* disable the TDLS STA-specific queues */
308 sta_msk
= mvmsta
->tfd_queue_msk
;
309 for_each_set_bit(i
, &sta_msk
, sizeof(sta_msk
) * BITS_PER_BYTE
)
310 iwl_mvm_disable_txq(mvm
, i
, i
, IWL_MAX_TID_COUNT
, 0);
313 static int iwl_mvm_sta_alloc_queue(struct iwl_mvm
*mvm
,
314 struct ieee80211_sta
*sta
, u8 ac
, int tid
,
315 struct ieee80211_hdr
*hdr
)
317 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
318 struct iwl_trans_txq_scd_cfg cfg
= {
319 .fifo
= iwl_mvm_ac_to_tx_fifo
[ac
],
320 .sta_id
= mvmsta
->sta_id
,
322 .frame_limit
= IWL_FRAME_LIMIT
,
324 unsigned int wdg_timeout
=
325 iwl_mvm_get_wd_timeout(mvm
, mvmsta
->vif
, false, false);
326 u8 mac_queue
= mvmsta
->vif
->hw_queue
[ac
];
330 lockdep_assert_held(&mvm
->mutex
);
332 spin_lock_bh(&mvm
->queue_info_lock
);
335 * Non-QoS, QoS NDP and MGMT frames should go to a MGMT queue, if one
338 if (!ieee80211_is_data_qos(hdr
->frame_control
) ||
339 ieee80211_is_qos_nullfunc(hdr
->frame_control
)) {
340 queue
= iwl_mvm_find_free_queue(mvm
, IWL_MVM_DQA_MIN_MGMT_QUEUE
,
341 IWL_MVM_DQA_MAX_MGMT_QUEUE
);
342 if (queue
>= IWL_MVM_DQA_MIN_MGMT_QUEUE
)
343 IWL_DEBUG_TX_QUEUES(mvm
, "Found free MGMT queue #%d\n",
346 /* If no such queue is found, we'll use a DATA queue instead */
349 if (queue
< 0 && mvmsta
->reserved_queue
!= IEEE80211_INVAL_HW_QUEUE
) {
350 queue
= mvmsta
->reserved_queue
;
351 IWL_DEBUG_TX_QUEUES(mvm
, "Using reserved queue #%d\n", queue
);
355 queue
= iwl_mvm_find_free_queue(mvm
, IWL_MVM_DQA_MIN_DATA_QUEUE
,
356 IWL_MVM_DQA_MAX_DATA_QUEUE
);
358 mvm
->queue_info
[queue
].setup_reserved
= false;
360 spin_unlock_bh(&mvm
->queue_info_lock
);
362 /* TODO: support shared queues for same RA */
367 * Actual en/disablement of aggregations is through the ADD_STA HCMD,
368 * but for configuring the SCD to send A-MPDUs we need to mark the queue
370 * Mark all DATA queues as allowing to be aggregated at some point
372 cfg
.aggregate
= (queue
>= IWL_MVM_DQA_MIN_DATA_QUEUE
||
373 queue
== IWL_MVM_DQA_BSS_CLIENT_QUEUE
);
375 IWL_DEBUG_TX_QUEUES(mvm
, "Allocating queue #%d to sta %d on tid %d\n",
376 queue
, mvmsta
->sta_id
, tid
);
378 ssn
= IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr
->seq_ctrl
));
379 iwl_mvm_enable_txq(mvm
, queue
, mac_queue
, ssn
, &cfg
,
382 spin_lock_bh(&mvmsta
->lock
);
383 mvmsta
->tid_data
[tid
].txq_id
= queue
;
384 mvmsta
->tfd_queue_msk
|= BIT(queue
);
386 if (mvmsta
->reserved_queue
== queue
)
387 mvmsta
->reserved_queue
= IEEE80211_INVAL_HW_QUEUE
;
388 spin_unlock_bh(&mvmsta
->lock
);
390 return iwl_mvm_sta_send_to_fw(mvm
, sta
, true, STA_MODIFY_QUEUES
);
393 static inline u8
iwl_mvm_tid_to_ac_queue(int tid
)
395 if (tid
== IWL_MAX_TID_COUNT
)
396 return IEEE80211_AC_VO
; /* MGMT */
398 return tid_to_mac80211_ac
[tid
];
401 static void iwl_mvm_tx_deferred_stream(struct iwl_mvm
*mvm
,
402 struct ieee80211_sta
*sta
, int tid
)
404 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
405 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
407 struct ieee80211_hdr
*hdr
;
408 struct sk_buff_head deferred_tx
;
410 bool no_queue
= false; /* Marks if there is a problem with the queue */
413 lockdep_assert_held(&mvm
->mutex
);
415 skb
= skb_peek(&tid_data
->deferred_tx_frames
);
418 hdr
= (void *)skb
->data
;
420 ac
= iwl_mvm_tid_to_ac_queue(tid
);
421 mac_queue
= IEEE80211_SKB_CB(skb
)->hw_queue
;
423 if (tid_data
->txq_id
== IEEE80211_INVAL_HW_QUEUE
&&
424 iwl_mvm_sta_alloc_queue(mvm
, sta
, ac
, tid
, hdr
)) {
426 "Can't alloc TXQ for sta %d tid %d - dropping frame\n",
427 mvmsta
->sta_id
, tid
);
430 * Mark queue as problematic so later the deferred traffic is
431 * freed, as we can do nothing with it
436 __skb_queue_head_init(&deferred_tx
);
438 /* Disable bottom-halves when entering TX path */
440 spin_lock(&mvmsta
->lock
);
441 skb_queue_splice_init(&tid_data
->deferred_tx_frames
, &deferred_tx
);
442 spin_unlock(&mvmsta
->lock
);
444 while ((skb
= __skb_dequeue(&deferred_tx
)))
445 if (no_queue
|| iwl_mvm_tx_skb(mvm
, skb
, sta
))
446 ieee80211_free_txskb(mvm
->hw
, skb
);
450 iwl_mvm_start_mac_queues(mvm
, BIT(mac_queue
));
453 void iwl_mvm_add_new_dqa_stream_wk(struct work_struct
*wk
)
455 struct iwl_mvm
*mvm
= container_of(wk
, struct iwl_mvm
,
457 struct ieee80211_sta
*sta
;
458 struct iwl_mvm_sta
*mvmsta
;
459 unsigned long deferred_tid_traffic
;
462 mutex_lock(&mvm
->mutex
);
464 /* Go over all stations with deferred traffic */
465 for_each_set_bit(sta_id
, mvm
->sta_deferred_frames
,
466 IWL_MVM_STATION_COUNT
) {
467 clear_bit(sta_id
, mvm
->sta_deferred_frames
);
468 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
469 lockdep_is_held(&mvm
->mutex
));
470 if (IS_ERR_OR_NULL(sta
))
473 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
474 deferred_tid_traffic
= mvmsta
->deferred_traffic_tid_map
;
476 for_each_set_bit(tid
, &deferred_tid_traffic
,
477 IWL_MAX_TID_COUNT
+ 1)
478 iwl_mvm_tx_deferred_stream(mvm
, sta
, tid
);
481 mutex_unlock(&mvm
->mutex
);
484 static int iwl_mvm_reserve_sta_stream(struct iwl_mvm
*mvm
,
485 struct ieee80211_sta
*sta
,
486 enum nl80211_iftype vif_type
)
488 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
491 spin_lock_bh(&mvm
->queue_info_lock
);
493 /* Make sure we have free resources for this STA */
494 if (vif_type
== NL80211_IFTYPE_STATION
&& !sta
->tdls
&&
495 !mvm
->queue_info
[IWL_MVM_DQA_BSS_CLIENT_QUEUE
].hw_queue_refcount
&&
496 !mvm
->queue_info
[IWL_MVM_DQA_BSS_CLIENT_QUEUE
].setup_reserved
)
497 queue
= IWL_MVM_DQA_BSS_CLIENT_QUEUE
;
499 queue
= iwl_mvm_find_free_queue(mvm
, IWL_MVM_DQA_MIN_DATA_QUEUE
,
500 IWL_MVM_DQA_MAX_DATA_QUEUE
);
502 spin_unlock_bh(&mvm
->queue_info_lock
);
503 IWL_ERR(mvm
, "No available queues for new station\n");
506 mvm
->queue_info
[queue
].setup_reserved
= true;
508 spin_unlock_bh(&mvm
->queue_info_lock
);
510 mvmsta
->reserved_queue
= queue
;
512 IWL_DEBUG_TX_QUEUES(mvm
, "Reserving data queue #%d for sta_id %d\n",
513 queue
, mvmsta
->sta_id
);
518 int iwl_mvm_add_sta(struct iwl_mvm
*mvm
,
519 struct ieee80211_vif
*vif
,
520 struct ieee80211_sta
*sta
)
522 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
523 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
524 struct iwl_mvm_rxq_dup_data
*dup_data
;
527 lockdep_assert_held(&mvm
->mutex
);
529 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
530 sta_id
= iwl_mvm_find_free_sta_id(mvm
,
531 ieee80211_vif_type_p2p(vif
));
533 sta_id
= mvm_sta
->sta_id
;
535 if (sta_id
== IWL_MVM_STATION_COUNT
)
538 spin_lock_init(&mvm_sta
->lock
);
540 mvm_sta
->sta_id
= sta_id
;
541 mvm_sta
->mac_id_n_color
= FW_CMD_ID_AND_COLOR(mvmvif
->id
,
544 mvm_sta
->max_agg_bufsize
= LINK_QUAL_AGG_FRAME_LIMIT_DEF
;
545 mvm_sta
->tx_protection
= 0;
546 mvm_sta
->tt_tx_protection
= false;
548 /* HW restart, don't assume the memory has been zeroed */
549 atomic_set(&mvm
->pending_frames
[sta_id
], 0);
550 mvm_sta
->tid_disable_agg
= 0xffff; /* No aggs at first */
551 mvm_sta
->tfd_queue_msk
= 0;
553 /* allocate new queues for a TDLS station */
555 ret
= iwl_mvm_tdls_sta_init(mvm
, sta
);
558 } else if (!iwl_mvm_is_dqa_supported(mvm
)) {
559 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++)
560 if (vif
->hw_queue
[i
] != IEEE80211_INVAL_HW_QUEUE
)
561 mvm_sta
->tfd_queue_msk
|= BIT(vif
->hw_queue
[i
]);
564 /* for HW restart - reset everything but the sequence number */
565 for (i
= 0; i
<= IWL_MAX_TID_COUNT
; i
++) {
566 u16 seq
= mvm_sta
->tid_data
[i
].seq_number
;
567 memset(&mvm_sta
->tid_data
[i
], 0, sizeof(mvm_sta
->tid_data
[i
]));
568 mvm_sta
->tid_data
[i
].seq_number
= seq
;
570 if (!iwl_mvm_is_dqa_supported(mvm
))
574 * Mark all queues for this STA as unallocated and defer TX
575 * frames until the queue is allocated
577 mvm_sta
->tid_data
[i
].txq_id
= IEEE80211_INVAL_HW_QUEUE
;
578 skb_queue_head_init(&mvm_sta
->tid_data
[i
].deferred_tx_frames
);
580 mvm_sta
->deferred_traffic_tid_map
= 0;
581 mvm_sta
->agg_tids
= 0;
583 if (iwl_mvm_has_new_rx_api(mvm
) &&
584 !test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
585 dup_data
= kcalloc(mvm
->trans
->num_rx_queues
,
590 mvm_sta
->dup_data
= dup_data
;
593 if (iwl_mvm_is_dqa_supported(mvm
)) {
594 ret
= iwl_mvm_reserve_sta_stream(mvm
, sta
,
595 ieee80211_vif_type_p2p(vif
));
600 ret
= iwl_mvm_sta_send_to_fw(mvm
, sta
, false, 0);
604 if (vif
->type
== NL80211_IFTYPE_STATION
) {
606 WARN_ON(mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
);
607 mvmvif
->ap_sta_id
= sta_id
;
609 WARN_ON(mvmvif
->ap_sta_id
== IWL_MVM_STATION_COUNT
);
613 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta_id
], sta
);
618 iwl_mvm_tdls_sta_deinit(mvm
, sta
);
622 int iwl_mvm_update_sta(struct iwl_mvm
*mvm
,
623 struct ieee80211_vif
*vif
,
624 struct ieee80211_sta
*sta
)
626 return iwl_mvm_sta_send_to_fw(mvm
, sta
, true, 0);
629 int iwl_mvm_drain_sta(struct iwl_mvm
*mvm
, struct iwl_mvm_sta
*mvmsta
,
632 struct iwl_mvm_add_sta_cmd cmd
= {};
636 lockdep_assert_held(&mvm
->mutex
);
638 cmd
.mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
);
639 cmd
.sta_id
= mvmsta
->sta_id
;
640 cmd
.add_modify
= STA_MODE_MODIFY
;
641 cmd
.station_flags
= drain
? cpu_to_le32(STA_FLG_DRAIN_FLOW
) : 0;
642 cmd
.station_flags_msk
= cpu_to_le32(STA_FLG_DRAIN_FLOW
);
644 status
= ADD_STA_SUCCESS
;
645 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
,
646 iwl_mvm_add_sta_cmd_size(mvm
),
651 switch (status
& IWL_ADD_STA_STATUS_MASK
) {
652 case ADD_STA_SUCCESS
:
653 IWL_DEBUG_INFO(mvm
, "Frames for staid %d will drained in fw\n",
658 IWL_ERR(mvm
, "Couldn't drain frames for staid %d\n",
667 * Remove a station from the FW table. Before sending the command to remove
668 * the station validate that the station is indeed known to the driver (sanity
671 static int iwl_mvm_rm_sta_common(struct iwl_mvm
*mvm
, u8 sta_id
)
673 struct ieee80211_sta
*sta
;
674 struct iwl_mvm_rm_sta_cmd rm_sta_cmd
= {
679 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
680 lockdep_is_held(&mvm
->mutex
));
682 /* Note: internal stations are marked as error values */
684 IWL_ERR(mvm
, "Invalid station id\n");
688 ret
= iwl_mvm_send_cmd_pdu(mvm
, REMOVE_STA
, 0,
689 sizeof(rm_sta_cmd
), &rm_sta_cmd
);
691 IWL_ERR(mvm
, "Failed to remove station. Id=%d\n", sta_id
);
698 void iwl_mvm_sta_drained_wk(struct work_struct
*wk
)
700 struct iwl_mvm
*mvm
= container_of(wk
, struct iwl_mvm
, sta_drained_wk
);
704 * The mutex is needed because of the SYNC cmd, but not only: if the
705 * work would run concurrently with iwl_mvm_rm_sta, it would run before
706 * iwl_mvm_rm_sta sets the station as busy, and exit. Then
707 * iwl_mvm_rm_sta would set the station as busy, and nobody will clean
710 mutex_lock(&mvm
->mutex
);
712 for_each_set_bit(sta_id
, mvm
->sta_drained
, IWL_MVM_STATION_COUNT
) {
714 struct ieee80211_sta
*sta
=
715 rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
716 lockdep_is_held(&mvm
->mutex
));
719 * This station is in use or RCU-removed; the latter happens in
720 * managed mode, where mac80211 removes the station before we
721 * can remove it from firmware (we can only do that after the
722 * MAC is marked unassociated), and possibly while the deauth
723 * frame to disconnect from the AP is still queued. Then, the
724 * station pointer is -ENOENT when the last skb is reclaimed.
726 if (!IS_ERR(sta
) || PTR_ERR(sta
) == -ENOENT
)
729 if (PTR_ERR(sta
) == -EINVAL
) {
730 IWL_ERR(mvm
, "Drained sta %d, but it is internal?\n",
736 IWL_ERR(mvm
, "Drained sta %d, but it was NULL?\n",
741 WARN_ON(PTR_ERR(sta
) != -EBUSY
);
742 /* This station was removed and we waited until it got drained,
743 * we can now proceed and remove it.
745 ret
= iwl_mvm_rm_sta_common(mvm
, sta_id
);
748 "Couldn't remove sta %d after it was drained\n",
752 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta_id
], NULL
);
753 clear_bit(sta_id
, mvm
->sta_drained
);
755 if (mvm
->tfd_drained
[sta_id
]) {
756 unsigned long i
, msk
= mvm
->tfd_drained
[sta_id
];
758 for_each_set_bit(i
, &msk
, sizeof(msk
) * BITS_PER_BYTE
)
759 iwl_mvm_disable_txq(mvm
, i
, i
,
760 IWL_MAX_TID_COUNT
, 0);
762 mvm
->tfd_drained
[sta_id
] = 0;
763 IWL_DEBUG_TDLS(mvm
, "Drained sta %d, with queues %ld\n",
768 mutex_unlock(&mvm
->mutex
);
771 static void iwl_mvm_disable_sta_queues(struct iwl_mvm
*mvm
,
772 struct ieee80211_vif
*vif
,
773 struct iwl_mvm_sta
*mvm_sta
)
778 lockdep_assert_held(&mvm
->mutex
);
780 for (i
= 0; i
< ARRAY_SIZE(mvm_sta
->tid_data
); i
++) {
781 if (mvm_sta
->tid_data
[i
].txq_id
== IEEE80211_INVAL_HW_QUEUE
)
784 ac
= iwl_mvm_tid_to_ac_queue(i
);
785 iwl_mvm_disable_txq(mvm
, mvm_sta
->tid_data
[i
].txq_id
,
786 vif
->hw_queue
[ac
], i
, 0);
787 mvm_sta
->tid_data
[i
].txq_id
= IEEE80211_INVAL_HW_QUEUE
;
791 int iwl_mvm_rm_sta(struct iwl_mvm
*mvm
,
792 struct ieee80211_vif
*vif
,
793 struct ieee80211_sta
*sta
)
795 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
796 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
799 lockdep_assert_held(&mvm
->mutex
);
801 if (iwl_mvm_has_new_rx_api(mvm
))
802 kfree(mvm_sta
->dup_data
);
804 if (vif
->type
== NL80211_IFTYPE_STATION
&&
805 mvmvif
->ap_sta_id
== mvm_sta
->sta_id
) {
806 ret
= iwl_mvm_drain_sta(mvm
, mvm_sta
, true);
809 /* flush its queues here since we are freeing mvm_sta */
810 ret
= iwl_mvm_flush_tx_path(mvm
, mvm_sta
->tfd_queue_msk
, 0);
813 ret
= iwl_trans_wait_tx_queue_empty(mvm
->trans
,
814 mvm_sta
->tfd_queue_msk
);
817 ret
= iwl_mvm_drain_sta(mvm
, mvm_sta
, false);
819 /* If DQA is supported - the queues can be disabled now */
820 if (iwl_mvm_is_dqa_supported(mvm
))
821 iwl_mvm_disable_sta_queues(mvm
, vif
, mvm_sta
);
823 /* if we are associated - we can't remove the AP STA now */
824 if (vif
->bss_conf
.assoc
)
827 /* unassoc - go ahead - remove the AP STA now */
828 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
830 /* clear d0i3_ap_sta_id if no longer relevant */
831 if (mvm
->d0i3_ap_sta_id
== mvm_sta
->sta_id
)
832 mvm
->d0i3_ap_sta_id
= IWL_MVM_STATION_COUNT
;
836 * This shouldn't happen - the TDLS channel switch should be canceled
837 * before the STA is removed.
839 if (WARN_ON_ONCE(mvm
->tdls_cs
.peer
.sta_id
== mvm_sta
->sta_id
)) {
840 mvm
->tdls_cs
.peer
.sta_id
= IWL_MVM_STATION_COUNT
;
841 cancel_delayed_work(&mvm
->tdls_cs
.dwork
);
845 * Make sure that the tx response code sees the station as -EBUSY and
846 * calls the drain worker.
848 spin_lock_bh(&mvm_sta
->lock
);
850 * There are frames pending on the AC queues for this station.
851 * We need to wait until all the frames are drained...
853 if (atomic_read(&mvm
->pending_frames
[mvm_sta
->sta_id
])) {
854 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
],
856 spin_unlock_bh(&mvm_sta
->lock
);
858 /* disable TDLS sta queues on drain complete */
860 mvm
->tfd_drained
[mvm_sta
->sta_id
] =
861 mvm_sta
->tfd_queue_msk
;
862 IWL_DEBUG_TDLS(mvm
, "Draining TDLS sta %d\n",
866 ret
= iwl_mvm_drain_sta(mvm
, mvm_sta
, true);
868 spin_unlock_bh(&mvm_sta
->lock
);
871 iwl_mvm_tdls_sta_deinit(mvm
, sta
);
873 ret
= iwl_mvm_rm_sta_common(mvm
, mvm_sta
->sta_id
);
874 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
], NULL
);
880 int iwl_mvm_rm_sta_id(struct iwl_mvm
*mvm
,
881 struct ieee80211_vif
*vif
,
884 int ret
= iwl_mvm_rm_sta_common(mvm
, sta_id
);
886 lockdep_assert_held(&mvm
->mutex
);
888 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta_id
], NULL
);
892 int iwl_mvm_allocate_int_sta(struct iwl_mvm
*mvm
,
893 struct iwl_mvm_int_sta
*sta
,
894 u32 qmask
, enum nl80211_iftype iftype
)
896 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
897 sta
->sta_id
= iwl_mvm_find_free_sta_id(mvm
, iftype
);
898 if (WARN_ON_ONCE(sta
->sta_id
== IWL_MVM_STATION_COUNT
))
902 sta
->tfd_queue_msk
= qmask
;
904 /* put a non-NULL value so iterating over the stations won't stop */
905 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta
->sta_id
], ERR_PTR(-EINVAL
));
909 static void iwl_mvm_dealloc_int_sta(struct iwl_mvm
*mvm
,
910 struct iwl_mvm_int_sta
*sta
)
912 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta
->sta_id
], NULL
);
913 memset(sta
, 0, sizeof(struct iwl_mvm_int_sta
));
914 sta
->sta_id
= IWL_MVM_STATION_COUNT
;
917 static int iwl_mvm_add_int_sta_common(struct iwl_mvm
*mvm
,
918 struct iwl_mvm_int_sta
*sta
,
920 u16 mac_id
, u16 color
)
922 struct iwl_mvm_add_sta_cmd cmd
;
926 lockdep_assert_held(&mvm
->mutex
);
928 memset(&cmd
, 0, sizeof(cmd
));
929 cmd
.sta_id
= sta
->sta_id
;
930 cmd
.mac_id_n_color
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id
,
933 cmd
.tfd_queue_msk
= cpu_to_le32(sta
->tfd_queue_msk
);
934 cmd
.tid_disable_tx
= cpu_to_le16(0xffff);
937 memcpy(cmd
.addr
, addr
, ETH_ALEN
);
939 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
,
940 iwl_mvm_add_sta_cmd_size(mvm
),
945 switch (status
& IWL_ADD_STA_STATUS_MASK
) {
946 case ADD_STA_SUCCESS
:
947 IWL_DEBUG_INFO(mvm
, "Internal station added.\n");
951 IWL_ERR(mvm
, "Add internal station failed, status=0x%x\n",
958 int iwl_mvm_add_aux_sta(struct iwl_mvm
*mvm
)
960 unsigned int wdg_timeout
= iwlmvm_mod_params
.tfd_q_hang_detect
?
961 mvm
->cfg
->base_params
->wd_timeout
:
962 IWL_WATCHDOG_DISABLED
;
965 lockdep_assert_held(&mvm
->mutex
);
967 /* Map Aux queue to fifo - needs to happen before adding Aux station */
968 iwl_mvm_enable_ac_txq(mvm
, mvm
->aux_queue
, mvm
->aux_queue
,
969 IWL_MVM_TX_FIFO_MCAST
, 0, wdg_timeout
);
971 /* Allocate aux station and assign to it the aux queue */
972 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvm
->aux_sta
, BIT(mvm
->aux_queue
),
973 NL80211_IFTYPE_UNSPECIFIED
);
977 ret
= iwl_mvm_add_int_sta_common(mvm
, &mvm
->aux_sta
, NULL
,
981 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
985 int iwl_mvm_add_snif_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
987 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
989 lockdep_assert_held(&mvm
->mutex
);
990 return iwl_mvm_add_int_sta_common(mvm
, &mvm
->snif_sta
, vif
->addr
,
994 int iwl_mvm_rm_snif_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
998 lockdep_assert_held(&mvm
->mutex
);
1000 ret
= iwl_mvm_rm_sta_common(mvm
, mvm
->snif_sta
.sta_id
);
1002 IWL_WARN(mvm
, "Failed sending remove station\n");
1007 void iwl_mvm_dealloc_snif_sta(struct iwl_mvm
*mvm
)
1009 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->snif_sta
);
1012 void iwl_mvm_del_aux_sta(struct iwl_mvm
*mvm
)
1014 lockdep_assert_held(&mvm
->mutex
);
1016 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
1020 * Send the add station command for the vif's broadcast station.
1021 * Assumes that the station was already allocated.
1023 * @mvm: the mvm component
1024 * @vif: the interface to which the broadcast station is added
1025 * @bsta: the broadcast station to add.
1027 int iwl_mvm_send_add_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1029 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1030 struct iwl_mvm_int_sta
*bsta
= &mvmvif
->bcast_sta
;
1031 static const u8 _baddr
[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
1032 const u8
*baddr
= _baddr
;
1034 lockdep_assert_held(&mvm
->mutex
);
1036 if (iwl_mvm_is_dqa_supported(mvm
)) {
1037 struct iwl_trans_txq_scd_cfg cfg
= {
1038 .fifo
= IWL_MVM_TX_FIFO_VO
,
1039 .sta_id
= mvmvif
->bcast_sta
.sta_id
,
1040 .tid
= IWL_MAX_TID_COUNT
,
1042 .frame_limit
= IWL_FRAME_LIMIT
,
1044 unsigned int wdg_timeout
=
1045 iwl_mvm_get_wd_timeout(mvm
, vif
, false, false);
1048 if ((vif
->type
== NL80211_IFTYPE_AP
) &&
1049 (mvmvif
->bcast_sta
.tfd_queue_msk
&
1050 BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE
)))
1051 queue
= IWL_MVM_DQA_AP_PROBE_RESP_QUEUE
;
1052 else if ((vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) &&
1053 (mvmvif
->bcast_sta
.tfd_queue_msk
&
1054 BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE
)))
1055 queue
= IWL_MVM_DQA_P2P_DEVICE_QUEUE
;
1056 else if (WARN(1, "Missed required TXQ for adding bcast STA\n"))
1059 iwl_mvm_enable_txq(mvm
, queue
, vif
->hw_queue
[0], 0, &cfg
,
1063 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
1064 baddr
= vif
->bss_conf
.bssid
;
1066 if (WARN_ON_ONCE(bsta
->sta_id
== IWL_MVM_STATION_COUNT
))
1069 return iwl_mvm_add_int_sta_common(mvm
, bsta
, baddr
,
1070 mvmvif
->id
, mvmvif
->color
);
1073 /* Send the FW a request to remove the station from it's internal data
1074 * structures, but DO NOT remove the entry from the local data structures. */
1075 int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1077 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1080 lockdep_assert_held(&mvm
->mutex
);
1082 ret
= iwl_mvm_rm_sta_common(mvm
, mvmvif
->bcast_sta
.sta_id
);
1084 IWL_WARN(mvm
, "Failed sending remove station\n");
1088 int iwl_mvm_alloc_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1090 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1093 lockdep_assert_held(&mvm
->mutex
);
1095 if (!iwl_mvm_is_dqa_supported(mvm
))
1096 qmask
= iwl_mvm_mac_get_queues_mask(vif
);
1098 if (vif
->type
== NL80211_IFTYPE_AP
) {
1100 * The firmware defines the TFD queue mask to only be relevant
1101 * for *unicast* queues, so the multicast (CAB) queue shouldn't
1104 qmask
&= ~BIT(vif
->cab_queue
);
1106 if (iwl_mvm_is_dqa_supported(mvm
))
1107 qmask
|= BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE
);
1108 } else if (iwl_mvm_is_dqa_supported(mvm
) &&
1109 vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1110 qmask
|= BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE
);
1113 return iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->bcast_sta
, qmask
,
1114 ieee80211_vif_type_p2p(vif
));
1117 /* Allocate a new station entry for the broadcast station to the given vif,
1118 * and send it to the FW.
1119 * Note that each P2P mac should have its own broadcast station.
1121 * @mvm: the mvm component
1122 * @vif: the interface to which the broadcast station is added
1123 * @bsta: the broadcast station to add. */
1124 int iwl_mvm_add_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1126 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1127 struct iwl_mvm_int_sta
*bsta
= &mvmvif
->bcast_sta
;
1130 lockdep_assert_held(&mvm
->mutex
);
1132 ret
= iwl_mvm_alloc_bcast_sta(mvm
, vif
);
1136 ret
= iwl_mvm_send_add_bcast_sta(mvm
, vif
);
1139 iwl_mvm_dealloc_int_sta(mvm
, bsta
);
1144 void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1146 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1148 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->bcast_sta
);
1152 * Send the FW a request to remove the station from it's internal data
1153 * structures, and in addition remove it from the local data structure.
1155 int iwl_mvm_rm_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1159 lockdep_assert_held(&mvm
->mutex
);
1161 ret
= iwl_mvm_send_rm_bcast_sta(mvm
, vif
);
1163 iwl_mvm_dealloc_bcast_sta(mvm
, vif
);
1168 #define IWL_MAX_RX_BA_SESSIONS 16
1170 static void iwl_mvm_sync_rxq_del_ba(struct iwl_mvm
*mvm
, u8 baid
)
1172 struct iwl_mvm_delba_notif notif
= {
1173 .metadata
.type
= IWL_MVM_RXQ_NOTIF_DEL_BA
,
1177 iwl_mvm_sync_rx_queues_internal(mvm
, (void *)¬if
, sizeof(notif
));
1180 static void iwl_mvm_free_reorder(struct iwl_mvm
*mvm
,
1181 struct iwl_mvm_baid_data
*data
)
1185 iwl_mvm_sync_rxq_del_ba(mvm
, data
->baid
);
1187 for (i
= 0; i
< mvm
->trans
->num_rx_queues
; i
++) {
1189 struct iwl_mvm_reorder_buffer
*reorder_buf
=
1190 &data
->reorder_buf
[i
];
1192 spin_lock_bh(&reorder_buf
->lock
);
1193 if (likely(!reorder_buf
->num_stored
)) {
1194 spin_unlock_bh(&reorder_buf
->lock
);
1199 * This shouldn't happen in regular DELBA since the internal
1200 * delBA notification should trigger a release of all frames in
1201 * the reorder buffer.
1205 for (j
= 0; j
< reorder_buf
->buf_size
; j
++)
1206 __skb_queue_purge(&reorder_buf
->entries
[j
]);
1208 * Prevent timer re-arm. This prevents a very far fetched case
1209 * where we timed out on the notification. There may be prior
1210 * RX frames pending in the RX queue before the notification
1211 * that might get processed between now and the actual deletion
1212 * and we would re-arm the timer although we are deleting the
1215 reorder_buf
->removed
= true;
1216 spin_unlock_bh(&reorder_buf
->lock
);
1217 del_timer_sync(&reorder_buf
->reorder_timer
);
1221 static void iwl_mvm_init_reorder_buffer(struct iwl_mvm
*mvm
,
1223 struct iwl_mvm_baid_data
*data
,
1224 u16 ssn
, u8 buf_size
)
1228 for (i
= 0; i
< mvm
->trans
->num_rx_queues
; i
++) {
1229 struct iwl_mvm_reorder_buffer
*reorder_buf
=
1230 &data
->reorder_buf
[i
];
1233 reorder_buf
->num_stored
= 0;
1234 reorder_buf
->head_sn
= ssn
;
1235 reorder_buf
->buf_size
= buf_size
;
1236 /* rx reorder timer */
1237 reorder_buf
->reorder_timer
.function
=
1238 iwl_mvm_reorder_timer_expired
;
1239 reorder_buf
->reorder_timer
.data
= (unsigned long)reorder_buf
;
1240 init_timer(&reorder_buf
->reorder_timer
);
1241 spin_lock_init(&reorder_buf
->lock
);
1242 reorder_buf
->mvm
= mvm
;
1243 reorder_buf
->queue
= i
;
1244 reorder_buf
->sta_id
= sta_id
;
1245 for (j
= 0; j
< reorder_buf
->buf_size
; j
++)
1246 __skb_queue_head_init(&reorder_buf
->entries
[j
]);
1250 int iwl_mvm_sta_rx_agg(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
1251 int tid
, u16 ssn
, bool start
, u8 buf_size
, u16 timeout
)
1253 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1254 struct iwl_mvm_add_sta_cmd cmd
= {};
1255 struct iwl_mvm_baid_data
*baid_data
= NULL
;
1259 lockdep_assert_held(&mvm
->mutex
);
1261 if (start
&& mvm
->rx_ba_sessions
>= IWL_MAX_RX_BA_SESSIONS
) {
1262 IWL_WARN(mvm
, "Not enough RX BA SESSIONS\n");
1266 if (iwl_mvm_has_new_rx_api(mvm
) && start
) {
1268 * Allocate here so if allocation fails we can bail out early
1269 * before starting the BA session in the firmware
1271 baid_data
= kzalloc(sizeof(*baid_data
) +
1272 mvm
->trans
->num_rx_queues
*
1273 sizeof(baid_data
->reorder_buf
[0]),
1279 cmd
.mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
);
1280 cmd
.sta_id
= mvm_sta
->sta_id
;
1281 cmd
.add_modify
= STA_MODE_MODIFY
;
1283 cmd
.add_immediate_ba_tid
= (u8
) tid
;
1284 cmd
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
1285 cmd
.rx_ba_window
= cpu_to_le16((u16
)buf_size
);
1287 cmd
.remove_immediate_ba_tid
= (u8
) tid
;
1289 cmd
.modify_mask
= start
? STA_MODIFY_ADD_BA_TID
:
1290 STA_MODIFY_REMOVE_BA_TID
;
1292 status
= ADD_STA_SUCCESS
;
1293 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
,
1294 iwl_mvm_add_sta_cmd_size(mvm
),
1299 switch (status
& IWL_ADD_STA_STATUS_MASK
) {
1300 case ADD_STA_SUCCESS
:
1301 IWL_DEBUG_INFO(mvm
, "RX BA Session %sed in fw\n",
1302 start
? "start" : "stopp");
1304 case ADD_STA_IMMEDIATE_BA_FAILURE
:
1305 IWL_WARN(mvm
, "RX BA Session refused by fw\n");
1310 IWL_ERR(mvm
, "RX BA Session failed %sing, status 0x%x\n",
1311 start
? "start" : "stopp", status
);
1321 mvm
->rx_ba_sessions
++;
1323 if (!iwl_mvm_has_new_rx_api(mvm
))
1326 if (WARN_ON(!(status
& IWL_ADD_STA_BAID_VALID_MASK
))) {
1330 baid
= (u8
)((status
& IWL_ADD_STA_BAID_MASK
) >>
1331 IWL_ADD_STA_BAID_SHIFT
);
1332 baid_data
->baid
= baid
;
1333 baid_data
->timeout
= timeout
;
1334 baid_data
->last_rx
= jiffies
;
1335 init_timer(&baid_data
->session_timer
);
1336 baid_data
->session_timer
.function
=
1337 iwl_mvm_rx_agg_session_expired
;
1338 baid_data
->session_timer
.data
=
1339 (unsigned long)&mvm
->baid_map
[baid
];
1340 baid_data
->mvm
= mvm
;
1341 baid_data
->tid
= tid
;
1342 baid_data
->sta_id
= mvm_sta
->sta_id
;
1344 mvm_sta
->tid_to_baid
[tid
] = baid
;
1346 mod_timer(&baid_data
->session_timer
,
1347 TU_TO_EXP_TIME(timeout
* 2));
1349 iwl_mvm_init_reorder_buffer(mvm
, mvm_sta
->sta_id
,
1350 baid_data
, ssn
, buf_size
);
1352 * protect the BA data with RCU to cover a case where our
1353 * internal RX sync mechanism will timeout (not that it's
1354 * supposed to happen) and we will free the session data while
1355 * RX is being processed in parallel
1357 WARN_ON(rcu_access_pointer(mvm
->baid_map
[baid
]));
1358 rcu_assign_pointer(mvm
->baid_map
[baid
], baid_data
);
1359 } else if (mvm
->rx_ba_sessions
> 0) {
1360 u8 baid
= mvm_sta
->tid_to_baid
[tid
];
1362 /* check that restart flow didn't zero the counter */
1363 mvm
->rx_ba_sessions
--;
1364 if (!iwl_mvm_has_new_rx_api(mvm
))
1367 if (WARN_ON(baid
== IWL_RX_REORDER_DATA_INVALID_BAID
))
1370 baid_data
= rcu_access_pointer(mvm
->baid_map
[baid
]);
1371 if (WARN_ON(!baid_data
))
1374 /* synchronize all rx queues so we can safely delete */
1375 iwl_mvm_free_reorder(mvm
, baid_data
);
1376 del_timer_sync(&baid_data
->session_timer
);
1377 RCU_INIT_POINTER(mvm
->baid_map
[baid
], NULL
);
1378 kfree_rcu(baid_data
, rcu_head
);
1387 static int iwl_mvm_sta_tx_agg(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
1388 int tid
, u8 queue
, bool start
)
1390 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1391 struct iwl_mvm_add_sta_cmd cmd
= {};
1395 lockdep_assert_held(&mvm
->mutex
);
1398 mvm_sta
->tfd_queue_msk
|= BIT(queue
);
1399 mvm_sta
->tid_disable_agg
&= ~BIT(tid
);
1401 mvm_sta
->tfd_queue_msk
&= ~BIT(queue
);
1402 mvm_sta
->tid_disable_agg
|= BIT(tid
);
1405 cmd
.mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
);
1406 cmd
.sta_id
= mvm_sta
->sta_id
;
1407 cmd
.add_modify
= STA_MODE_MODIFY
;
1408 cmd
.modify_mask
= STA_MODIFY_QUEUES
| STA_MODIFY_TID_DISABLE_TX
;
1409 cmd
.tfd_queue_msk
= cpu_to_le32(mvm_sta
->tfd_queue_msk
);
1410 cmd
.tid_disable_tx
= cpu_to_le16(mvm_sta
->tid_disable_agg
);
1412 status
= ADD_STA_SUCCESS
;
1413 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
,
1414 iwl_mvm_add_sta_cmd_size(mvm
),
1419 switch (status
& IWL_ADD_STA_STATUS_MASK
) {
1420 case ADD_STA_SUCCESS
:
1424 IWL_ERR(mvm
, "TX BA Session failed %sing, status 0x%x\n",
1425 start
? "start" : "stopp", status
);
1432 const u8 tid_to_mac80211_ac
[] = {
1443 static const u8 tid_to_ucode_ac
[] = {
1454 int iwl_mvm_sta_tx_agg_start(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1455 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
)
1457 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1458 struct iwl_mvm_tid_data
*tid_data
;
1462 if (WARN_ON_ONCE(tid
>= IWL_MAX_TID_COUNT
))
1465 if (mvmsta
->tid_data
[tid
].state
!= IWL_AGG_OFF
) {
1466 IWL_ERR(mvm
, "Start AGG when state is not IWL_AGG_OFF %d!\n",
1467 mvmsta
->tid_data
[tid
].state
);
1471 lockdep_assert_held(&mvm
->mutex
);
1473 spin_lock_bh(&mvmsta
->lock
);
1475 /* possible race condition - we entered D0i3 while starting agg */
1476 if (test_bit(IWL_MVM_STATUS_IN_D0I3
, &mvm
->status
)) {
1477 spin_unlock_bh(&mvmsta
->lock
);
1478 IWL_ERR(mvm
, "Entered D0i3 while starting Tx agg\n");
1482 spin_lock_bh(&mvm
->queue_info_lock
);
1484 txq_id
= iwl_mvm_find_free_queue(mvm
, mvm
->first_agg_queue
,
1485 mvm
->last_agg_queue
);
1488 spin_unlock_bh(&mvm
->queue_info_lock
);
1489 IWL_ERR(mvm
, "Failed to allocate agg queue\n");
1492 mvm
->queue_info
[txq_id
].setup_reserved
= true;
1493 spin_unlock_bh(&mvm
->queue_info_lock
);
1495 tid_data
= &mvmsta
->tid_data
[tid
];
1496 tid_data
->ssn
= IEEE80211_SEQ_TO_SN(tid_data
->seq_number
);
1497 tid_data
->txq_id
= txq_id
;
1498 *ssn
= tid_data
->ssn
;
1500 IWL_DEBUG_TX_QUEUES(mvm
,
1501 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
1502 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->ssn
,
1503 tid_data
->next_reclaimed
);
1505 if (tid_data
->ssn
== tid_data
->next_reclaimed
) {
1506 tid_data
->state
= IWL_AGG_STARTING
;
1507 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1509 tid_data
->state
= IWL_EMPTYING_HW_QUEUE_ADDBA
;
1515 spin_unlock_bh(&mvmsta
->lock
);
1520 int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1521 struct ieee80211_sta
*sta
, u16 tid
, u8 buf_size
,
1524 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1525 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
1526 unsigned int wdg_timeout
=
1527 iwl_mvm_get_wd_timeout(mvm
, vif
, sta
->tdls
, false);
1531 struct iwl_trans_txq_scd_cfg cfg
= {
1532 .sta_id
= mvmsta
->sta_id
,
1534 .frame_limit
= buf_size
,
1538 BUILD_BUG_ON((sizeof(mvmsta
->agg_tids
) * BITS_PER_BYTE
)
1539 != IWL_MAX_TID_COUNT
);
1541 buf_size
= min_t(int, buf_size
, LINK_QUAL_AGG_FRAME_LIMIT_DEF
);
1543 spin_lock_bh(&mvmsta
->lock
);
1544 ssn
= tid_data
->ssn
;
1545 queue
= tid_data
->txq_id
;
1546 tid_data
->state
= IWL_AGG_ON
;
1547 mvmsta
->agg_tids
|= BIT(tid
);
1548 tid_data
->ssn
= 0xffff;
1549 tid_data
->amsdu_in_ampdu_allowed
= amsdu
;
1550 spin_unlock_bh(&mvmsta
->lock
);
1552 cfg
.fifo
= iwl_mvm_ac_to_tx_fifo
[tid_to_mac80211_ac
[tid
]];
1554 iwl_mvm_enable_txq(mvm
, queue
, vif
->hw_queue
[tid_to_mac80211_ac
[tid
]],
1555 ssn
, &cfg
, wdg_timeout
);
1557 ret
= iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, queue
, true);
1561 /* No need to mark as reserved */
1562 spin_lock_bh(&mvm
->queue_info_lock
);
1563 mvm
->queue_info
[queue
].setup_reserved
= false;
1564 spin_unlock_bh(&mvm
->queue_info_lock
);
1567 * Even though in theory the peer could have different
1568 * aggregation reorder buffer sizes for different sessions,
1569 * our ucode doesn't allow for that and has a global limit
1570 * for each station. Therefore, use the minimum of all the
1571 * aggregation sessions and our default value.
1573 mvmsta
->max_agg_bufsize
=
1574 min(mvmsta
->max_agg_bufsize
, buf_size
);
1575 mvmsta
->lq_sta
.lq
.agg_frame_cnt_limit
= mvmsta
->max_agg_bufsize
;
1577 IWL_DEBUG_HT(mvm
, "Tx aggregation enabled on ra = %pM tid = %d\n",
1580 return iwl_mvm_send_lq_cmd(mvm
, &mvmsta
->lq_sta
.lq
, false);
1583 int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1584 struct ieee80211_sta
*sta
, u16 tid
)
1586 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1587 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
1593 * If mac80211 is cleaning its state, then say that we finished since
1594 * our state has been cleared anyway.
1596 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
1597 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1601 spin_lock_bh(&mvmsta
->lock
);
1603 txq_id
= tid_data
->txq_id
;
1605 IWL_DEBUG_TX_QUEUES(mvm
, "Stop AGG: sta %d tid %d q %d state %d\n",
1606 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->state
);
1608 mvmsta
->agg_tids
&= ~BIT(tid
);
1610 /* No need to mark as reserved anymore */
1611 spin_lock_bh(&mvm
->queue_info_lock
);
1612 mvm
->queue_info
[txq_id
].setup_reserved
= false;
1613 spin_unlock_bh(&mvm
->queue_info_lock
);
1615 switch (tid_data
->state
) {
1617 tid_data
->ssn
= IEEE80211_SEQ_TO_SN(tid_data
->seq_number
);
1619 IWL_DEBUG_TX_QUEUES(mvm
,
1620 "ssn = %d, next_recl = %d\n",
1621 tid_data
->ssn
, tid_data
->next_reclaimed
);
1623 /* There are still packets for this RA / TID in the HW */
1624 if (tid_data
->ssn
!= tid_data
->next_reclaimed
) {
1625 tid_data
->state
= IWL_EMPTYING_HW_QUEUE_DELBA
;
1630 tid_data
->ssn
= 0xffff;
1631 tid_data
->state
= IWL_AGG_OFF
;
1632 spin_unlock_bh(&mvmsta
->lock
);
1634 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1636 iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, txq_id
, false);
1638 iwl_mvm_disable_txq(mvm
, txq_id
,
1639 vif
->hw_queue
[tid_to_mac80211_ac
[tid
]], tid
,
1642 case IWL_AGG_STARTING
:
1643 case IWL_EMPTYING_HW_QUEUE_ADDBA
:
1645 * The agg session has been stopped before it was set up. This
1646 * can happen when the AddBA timer times out for example.
1649 /* No barriers since we are under mutex */
1650 lockdep_assert_held(&mvm
->mutex
);
1652 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1653 tid_data
->state
= IWL_AGG_OFF
;
1658 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
1659 mvmsta
->sta_id
, tid
, tid_data
->state
);
1661 "\ttid_data->txq_id = %d\n", tid_data
->txq_id
);
1665 spin_unlock_bh(&mvmsta
->lock
);
1670 int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1671 struct ieee80211_sta
*sta
, u16 tid
)
1673 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1674 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
1676 enum iwl_mvm_agg_state old_state
;
1679 * First set the agg state to OFF to avoid calling
1680 * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
1682 spin_lock_bh(&mvmsta
->lock
);
1683 txq_id
= tid_data
->txq_id
;
1684 IWL_DEBUG_TX_QUEUES(mvm
, "Flush AGG: sta %d tid %d q %d state %d\n",
1685 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->state
);
1686 old_state
= tid_data
->state
;
1687 tid_data
->state
= IWL_AGG_OFF
;
1688 mvmsta
->agg_tids
&= ~BIT(tid
);
1689 spin_unlock_bh(&mvmsta
->lock
);
1691 /* No need to mark as reserved */
1692 spin_lock_bh(&mvm
->queue_info_lock
);
1693 mvm
->queue_info
[txq_id
].setup_reserved
= false;
1694 spin_unlock_bh(&mvm
->queue_info_lock
);
1696 if (old_state
>= IWL_AGG_ON
) {
1697 iwl_mvm_drain_sta(mvm
, mvmsta
, true);
1698 if (iwl_mvm_flush_tx_path(mvm
, BIT(txq_id
), 0))
1699 IWL_ERR(mvm
, "Couldn't flush the AGG queue\n");
1700 iwl_trans_wait_tx_queue_empty(mvm
->trans
,
1701 mvmsta
->tfd_queue_msk
);
1702 iwl_mvm_drain_sta(mvm
, mvmsta
, false);
1704 iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, txq_id
, false);
1706 iwl_mvm_disable_txq(mvm
, tid_data
->txq_id
,
1707 vif
->hw_queue
[tid_to_mac80211_ac
[tid
]], tid
,
1714 static int iwl_mvm_set_fw_key_idx(struct iwl_mvm
*mvm
)
1716 int i
, max
= -1, max_offs
= -1;
1718 lockdep_assert_held(&mvm
->mutex
);
1720 /* Pick the unused key offset with the highest 'deleted'
1721 * counter. Every time a key is deleted, all the counters
1722 * are incremented and the one that was just deleted is
1723 * reset to zero. Thus, the highest counter is the one
1724 * that was deleted longest ago. Pick that one.
1726 for (i
= 0; i
< STA_KEY_MAX_NUM
; i
++) {
1727 if (test_bit(i
, mvm
->fw_key_table
))
1729 if (mvm
->fw_key_deleted
[i
] > max
) {
1730 max
= mvm
->fw_key_deleted
[i
];
1736 return STA_KEY_IDX_INVALID
;
1741 static struct iwl_mvm_sta
*iwl_mvm_get_key_sta(struct iwl_mvm
*mvm
,
1742 struct ieee80211_vif
*vif
,
1743 struct ieee80211_sta
*sta
)
1745 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1748 return iwl_mvm_sta_from_mac80211(sta
);
1751 * The device expects GTKs for station interfaces to be
1752 * installed as GTKs for the AP station. If we have no
1753 * station ID, then use AP's station ID.
1755 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1756 mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
1757 u8 sta_id
= mvmvif
->ap_sta_id
;
1760 * It is possible that the 'sta' parameter is NULL,
1761 * for example when a GTK is removed - the sta_id will then
1762 * be the AP ID, and no station was passed by mac80211.
1764 return iwl_mvm_sta_from_staid_protected(mvm
, sta_id
);
1770 static int iwl_mvm_send_sta_key(struct iwl_mvm
*mvm
,
1771 struct iwl_mvm_sta
*mvm_sta
,
1772 struct ieee80211_key_conf
*keyconf
, bool mcast
,
1773 u32 tkip_iv32
, u16
*tkip_p1k
, u32 cmd_flags
,
1776 struct iwl_mvm_add_sta_key_cmd cmd
= {};
1782 u8 sta_id
= mvm_sta
->sta_id
;
1784 keyidx
= (keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
) &
1785 STA_KEY_FLG_KEYID_MSK
;
1786 key_flags
= cpu_to_le16(keyidx
);
1787 key_flags
|= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP
);
1789 switch (keyconf
->cipher
) {
1790 case WLAN_CIPHER_SUITE_TKIP
:
1791 key_flags
|= cpu_to_le16(STA_KEY_FLG_TKIP
);
1792 cmd
.tkip_rx_tsc_byte2
= tkip_iv32
;
1793 for (i
= 0; i
< 5; i
++)
1794 cmd
.tkip_rx_ttak
[i
] = cpu_to_le16(tkip_p1k
[i
]);
1795 memcpy(cmd
.key
, keyconf
->key
, keyconf
->keylen
);
1797 case WLAN_CIPHER_SUITE_CCMP
:
1798 key_flags
|= cpu_to_le16(STA_KEY_FLG_CCM
);
1799 memcpy(cmd
.key
, keyconf
->key
, keyconf
->keylen
);
1801 case WLAN_CIPHER_SUITE_WEP104
:
1802 key_flags
|= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES
);
1804 case WLAN_CIPHER_SUITE_WEP40
:
1805 key_flags
|= cpu_to_le16(STA_KEY_FLG_WEP
);
1806 memcpy(cmd
.key
+ 3, keyconf
->key
, keyconf
->keylen
);
1809 key_flags
|= cpu_to_le16(STA_KEY_FLG_EXT
);
1810 memcpy(cmd
.key
, keyconf
->key
, keyconf
->keylen
);
1814 key_flags
|= cpu_to_le16(STA_KEY_MULTICAST
);
1816 cmd
.key_offset
= key_offset
;
1817 cmd
.key_flags
= key_flags
;
1818 cmd
.sta_id
= sta_id
;
1820 status
= ADD_STA_SUCCESS
;
1821 if (cmd_flags
& CMD_ASYNC
)
1822 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA_KEY
, CMD_ASYNC
,
1825 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA_KEY
, sizeof(cmd
),
1829 case ADD_STA_SUCCESS
:
1830 IWL_DEBUG_WEP(mvm
, "MODIFY_STA: set dynamic key passed\n");
1834 IWL_ERR(mvm
, "MODIFY_STA: set dynamic key failed\n");
1841 static int iwl_mvm_send_sta_igtk(struct iwl_mvm
*mvm
,
1842 struct ieee80211_key_conf
*keyconf
,
1843 u8 sta_id
, bool remove_key
)
1845 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd
= {};
1847 /* verify the key details match the required command's expectations */
1848 if (WARN_ON((keyconf
->cipher
!= WLAN_CIPHER_SUITE_AES_CMAC
) ||
1849 (keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
) ||
1850 (keyconf
->keyidx
!= 4 && keyconf
->keyidx
!= 5)))
1853 igtk_cmd
.key_id
= cpu_to_le32(keyconf
->keyidx
);
1854 igtk_cmd
.sta_id
= cpu_to_le32(sta_id
);
1857 igtk_cmd
.ctrl_flags
|= cpu_to_le32(STA_KEY_NOT_VALID
);
1859 struct ieee80211_key_seq seq
;
1862 memcpy(igtk_cmd
.IGTK
, keyconf
->key
, keyconf
->keylen
);
1863 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1864 pn
= seq
.aes_cmac
.pn
;
1865 igtk_cmd
.receive_seq_cnt
= cpu_to_le64(((u64
) pn
[5] << 0) |
1866 ((u64
) pn
[4] << 8) |
1867 ((u64
) pn
[3] << 16) |
1868 ((u64
) pn
[2] << 24) |
1869 ((u64
) pn
[1] << 32) |
1870 ((u64
) pn
[0] << 40));
1873 IWL_DEBUG_INFO(mvm
, "%s igtk for sta %u\n",
1874 remove_key
? "removing" : "installing",
1877 return iwl_mvm_send_cmd_pdu(mvm
, MGMT_MCAST_KEY
, 0,
1878 sizeof(igtk_cmd
), &igtk_cmd
);
1882 static inline u8
*iwl_mvm_get_mac_addr(struct iwl_mvm
*mvm
,
1883 struct ieee80211_vif
*vif
,
1884 struct ieee80211_sta
*sta
)
1886 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1891 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1892 mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
1893 u8 sta_id
= mvmvif
->ap_sta_id
;
1894 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1895 lockdep_is_held(&mvm
->mutex
));
1903 static int __iwl_mvm_set_sta_key(struct iwl_mvm
*mvm
,
1904 struct ieee80211_vif
*vif
,
1905 struct ieee80211_sta
*sta
,
1906 struct ieee80211_key_conf
*keyconf
,
1910 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1913 struct ieee80211_key_seq seq
;
1916 switch (keyconf
->cipher
) {
1917 case WLAN_CIPHER_SUITE_TKIP
:
1918 addr
= iwl_mvm_get_mac_addr(mvm
, vif
, sta
);
1919 /* get phase 1 key from mac80211 */
1920 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1921 ieee80211_get_tkip_rx_p1k(keyconf
, addr
, seq
.tkip
.iv32
, p1k
);
1922 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
1923 seq
.tkip
.iv32
, p1k
, 0, key_offset
);
1925 case WLAN_CIPHER_SUITE_CCMP
:
1926 case WLAN_CIPHER_SUITE_WEP40
:
1927 case WLAN_CIPHER_SUITE_WEP104
:
1928 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
1929 0, NULL
, 0, key_offset
);
1932 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
1933 0, NULL
, 0, key_offset
);
1939 static int __iwl_mvm_remove_sta_key(struct iwl_mvm
*mvm
, u8 sta_id
,
1940 struct ieee80211_key_conf
*keyconf
,
1943 struct iwl_mvm_add_sta_key_cmd cmd
= {};
1948 key_flags
= cpu_to_le16((keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
) &
1949 STA_KEY_FLG_KEYID_MSK
);
1950 key_flags
|= cpu_to_le16(STA_KEY_FLG_NO_ENC
| STA_KEY_FLG_WEP_KEY_MAP
);
1951 key_flags
|= cpu_to_le16(STA_KEY_NOT_VALID
);
1954 key_flags
|= cpu_to_le16(STA_KEY_MULTICAST
);
1956 cmd
.key_flags
= key_flags
;
1957 cmd
.key_offset
= keyconf
->hw_key_idx
;
1958 cmd
.sta_id
= sta_id
;
1960 status
= ADD_STA_SUCCESS
;
1961 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA_KEY
, sizeof(cmd
),
1965 case ADD_STA_SUCCESS
:
1966 IWL_DEBUG_WEP(mvm
, "MODIFY_STA: remove sta key passed\n");
1970 IWL_ERR(mvm
, "MODIFY_STA: remove sta key failed\n");
1977 int iwl_mvm_set_sta_key(struct iwl_mvm
*mvm
,
1978 struct ieee80211_vif
*vif
,
1979 struct ieee80211_sta
*sta
,
1980 struct ieee80211_key_conf
*keyconf
,
1983 bool mcast
= !(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
1984 struct iwl_mvm_sta
*mvm_sta
;
1987 static const u8 __maybe_unused zero_addr
[ETH_ALEN
] = {0};
1989 lockdep_assert_held(&mvm
->mutex
);
1991 /* Get the station id from the mvm local station table */
1992 mvm_sta
= iwl_mvm_get_key_sta(mvm
, vif
, sta
);
1994 IWL_ERR(mvm
, "Failed to find station\n");
1997 sta_id
= mvm_sta
->sta_id
;
1999 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
) {
2000 ret
= iwl_mvm_send_sta_igtk(mvm
, keyconf
, sta_id
, false);
2005 * It is possible that the 'sta' parameter is NULL, and thus
2006 * there is a need to retrieve the sta from the local station table.
2009 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
2010 lockdep_is_held(&mvm
->mutex
));
2011 if (IS_ERR_OR_NULL(sta
)) {
2012 IWL_ERR(mvm
, "Invalid station id\n");
2017 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta
)->vif
!= vif
))
2020 /* If the key_offset is not pre-assigned, we need to find a
2021 * new offset to use. In normal cases, the offset is not
2022 * pre-assigned, but during HW_RESTART we want to reuse the
2023 * same indices, so we pass them when this function is called.
2025 * In D3 entry, we need to hardcoded the indices (because the
2026 * firmware hardcodes the PTK offset to 0). In this case, we
2027 * need to make sure we don't overwrite the hw_key_idx in the
2028 * keyconf structure, because otherwise we cannot configure
2029 * the original ones back when resuming.
2031 if (key_offset
== STA_KEY_IDX_INVALID
) {
2032 key_offset
= iwl_mvm_set_fw_key_idx(mvm
);
2033 if (key_offset
== STA_KEY_IDX_INVALID
)
2035 keyconf
->hw_key_idx
= key_offset
;
2038 ret
= __iwl_mvm_set_sta_key(mvm
, vif
, sta
, keyconf
, key_offset
, mcast
);
2043 * For WEP, the same key is used for multicast and unicast. Upload it
2044 * again, using the same key offset, and now pointing the other one
2045 * to the same key slot (offset).
2046 * If this fails, remove the original as well.
2048 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
2049 keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP104
) {
2050 ret
= __iwl_mvm_set_sta_key(mvm
, vif
, sta
, keyconf
,
2051 key_offset
, !mcast
);
2053 __iwl_mvm_remove_sta_key(mvm
, sta_id
, keyconf
, mcast
);
2058 __set_bit(key_offset
, mvm
->fw_key_table
);
2061 IWL_DEBUG_WEP(mvm
, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
2062 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
2063 sta
? sta
->addr
: zero_addr
, ret
);
2067 int iwl_mvm_remove_sta_key(struct iwl_mvm
*mvm
,
2068 struct ieee80211_vif
*vif
,
2069 struct ieee80211_sta
*sta
,
2070 struct ieee80211_key_conf
*keyconf
)
2072 bool mcast
= !(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
2073 struct iwl_mvm_sta
*mvm_sta
;
2074 u8 sta_id
= IWL_MVM_STATION_COUNT
;
2077 lockdep_assert_held(&mvm
->mutex
);
2079 /* Get the station from the mvm local station table */
2080 mvm_sta
= iwl_mvm_get_key_sta(mvm
, vif
, sta
);
2082 IWL_DEBUG_WEP(mvm
, "mvm remove dynamic key: idx=%d sta=%d\n",
2083 keyconf
->keyidx
, sta_id
);
2085 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
)
2086 return iwl_mvm_send_sta_igtk(mvm
, keyconf
, sta_id
, true);
2088 if (!__test_and_clear_bit(keyconf
->hw_key_idx
, mvm
->fw_key_table
)) {
2089 IWL_ERR(mvm
, "offset %d not used in fw key table.\n",
2090 keyconf
->hw_key_idx
);
2094 /* track which key was deleted last */
2095 for (i
= 0; i
< STA_KEY_MAX_NUM
; i
++) {
2096 if (mvm
->fw_key_deleted
[i
] < U8_MAX
)
2097 mvm
->fw_key_deleted
[i
]++;
2099 mvm
->fw_key_deleted
[keyconf
->hw_key_idx
] = 0;
2102 IWL_DEBUG_WEP(mvm
, "station non-existent, early return.\n");
2106 sta_id
= mvm_sta
->sta_id
;
2108 ret
= __iwl_mvm_remove_sta_key(mvm
, sta_id
, keyconf
, mcast
);
2112 /* delete WEP key twice to get rid of (now useless) offset */
2113 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
2114 keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
2115 ret
= __iwl_mvm_remove_sta_key(mvm
, sta_id
, keyconf
, !mcast
);
2120 void iwl_mvm_update_tkip_key(struct iwl_mvm
*mvm
,
2121 struct ieee80211_vif
*vif
,
2122 struct ieee80211_key_conf
*keyconf
,
2123 struct ieee80211_sta
*sta
, u32 iv32
,
2126 struct iwl_mvm_sta
*mvm_sta
;
2127 bool mcast
= !(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
2131 mvm_sta
= iwl_mvm_get_key_sta(mvm
, vif
, sta
);
2132 if (WARN_ON_ONCE(!mvm_sta
))
2134 iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
2135 iv32
, phase1key
, CMD_ASYNC
, keyconf
->hw_key_idx
);
2141 void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm
*mvm
,
2142 struct ieee80211_sta
*sta
)
2144 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
2145 struct iwl_mvm_add_sta_cmd cmd
= {
2146 .add_modify
= STA_MODE_MODIFY
,
2147 .sta_id
= mvmsta
->sta_id
,
2148 .station_flags_msk
= cpu_to_le32(STA_FLG_PS
),
2149 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
2153 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, CMD_ASYNC
,
2154 iwl_mvm_add_sta_cmd_size(mvm
), &cmd
);
2156 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
2159 void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm
*mvm
,
2160 struct ieee80211_sta
*sta
,
2161 enum ieee80211_frame_release_type reason
,
2162 u16 cnt
, u16 tids
, bool more_data
,
2165 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
2166 struct iwl_mvm_add_sta_cmd cmd
= {
2167 .add_modify
= STA_MODE_MODIFY
,
2168 .sta_id
= mvmsta
->sta_id
,
2169 .modify_mask
= STA_MODIFY_SLEEPING_STA_TX_COUNT
,
2170 .sleep_tx_count
= cpu_to_le16(cnt
),
2171 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
2174 unsigned long _tids
= tids
;
2176 /* convert TIDs to ACs - we don't support TSPEC so that's OK
2177 * Note that this field is reserved and unused by firmware not
2178 * supporting GO uAPSD, so it's safe to always do this.
2180 for_each_set_bit(tid
, &_tids
, IWL_MAX_TID_COUNT
)
2181 cmd
.awake_acs
|= BIT(tid_to_ucode_ac
[tid
]);
2183 /* If we're releasing frames from aggregation queues then check if the
2184 * all queues combined that we're releasing frames from have
2185 * - more frames than the service period, in which case more_data
2187 * - fewer than 'cnt' frames, in which case we need to adjust the
2188 * firmware command (but do that unconditionally)
2191 int remaining
= cnt
;
2194 spin_lock_bh(&mvmsta
->lock
);
2195 for_each_set_bit(tid
, &_tids
, IWL_MAX_TID_COUNT
) {
2196 struct iwl_mvm_tid_data
*tid_data
;
2199 tid_data
= &mvmsta
->tid_data
[tid
];
2200 if (WARN(tid_data
->state
!= IWL_AGG_ON
&&
2201 tid_data
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
,
2202 "TID %d state is %d\n",
2203 tid
, tid_data
->state
)) {
2204 spin_unlock_bh(&mvmsta
->lock
);
2205 ieee80211_sta_eosp(sta
);
2209 n_queued
= iwl_mvm_tid_queued(tid_data
);
2210 if (n_queued
> remaining
) {
2215 remaining
-= n_queued
;
2217 sleep_tx_count
= cnt
- remaining
;
2218 if (reason
== IEEE80211_FRAME_RELEASE_UAPSD
)
2219 mvmsta
->sleep_tx_count
= sleep_tx_count
;
2220 spin_unlock_bh(&mvmsta
->lock
);
2222 cmd
.sleep_tx_count
= cpu_to_le16(sleep_tx_count
);
2223 if (WARN_ON(cnt
- remaining
== 0)) {
2224 ieee80211_sta_eosp(sta
);
2229 /* Note: this is ignored by firmware not supporting GO uAPSD */
2231 cmd
.sleep_state_flags
|= cpu_to_le16(STA_SLEEP_STATE_MOREDATA
);
2233 if (reason
== IEEE80211_FRAME_RELEASE_PSPOLL
) {
2234 mvmsta
->next_status_eosp
= true;
2235 cmd
.sleep_state_flags
|= cpu_to_le16(STA_SLEEP_STATE_PS_POLL
);
2237 cmd
.sleep_state_flags
|= cpu_to_le16(STA_SLEEP_STATE_UAPSD
);
2240 /* block the Tx queues until the FW updated the sleep Tx count */
2241 iwl_trans_block_txq_ptrs(mvm
->trans
, true);
2243 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
,
2244 CMD_ASYNC
| CMD_WANT_ASYNC_CALLBACK
,
2245 iwl_mvm_add_sta_cmd_size(mvm
), &cmd
);
2247 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
2250 void iwl_mvm_rx_eosp_notif(struct iwl_mvm
*mvm
,
2251 struct iwl_rx_cmd_buffer
*rxb
)
2253 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
2254 struct iwl_mvm_eosp_notification
*notif
= (void *)pkt
->data
;
2255 struct ieee80211_sta
*sta
;
2256 u32 sta_id
= le32_to_cpu(notif
->sta_id
);
2258 if (WARN_ON_ONCE(sta_id
>= IWL_MVM_STATION_COUNT
))
2262 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
2263 if (!IS_ERR_OR_NULL(sta
))
2264 ieee80211_sta_eosp(sta
);
2268 void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm
*mvm
,
2269 struct iwl_mvm_sta
*mvmsta
, bool disable
)
2271 struct iwl_mvm_add_sta_cmd cmd
= {
2272 .add_modify
= STA_MODE_MODIFY
,
2273 .sta_id
= mvmsta
->sta_id
,
2274 .station_flags
= disable
? cpu_to_le32(STA_FLG_DISABLE_TX
) : 0,
2275 .station_flags_msk
= cpu_to_le32(STA_FLG_DISABLE_TX
),
2276 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
2280 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, CMD_ASYNC
,
2281 iwl_mvm_add_sta_cmd_size(mvm
), &cmd
);
2283 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
2286 void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm
*mvm
,
2287 struct ieee80211_sta
*sta
,
2290 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
2292 spin_lock_bh(&mvm_sta
->lock
);
2294 if (mvm_sta
->disable_tx
== disable
) {
2295 spin_unlock_bh(&mvm_sta
->lock
);
2299 mvm_sta
->disable_tx
= disable
;
2302 * Tell mac80211 to start/stop queuing tx for this station,
2303 * but don't stop queuing if there are still pending frames
2306 if (disable
|| !atomic_read(&mvm
->pending_frames
[mvm_sta
->sta_id
]))
2307 ieee80211_sta_block_awake(mvm
->hw
, sta
, disable
);
2309 iwl_mvm_sta_modify_disable_tx(mvm
, mvm_sta
, disable
);
2311 spin_unlock_bh(&mvm_sta
->lock
);
2314 void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm
*mvm
,
2315 struct iwl_mvm_vif
*mvmvif
,
2318 struct ieee80211_sta
*sta
;
2319 struct iwl_mvm_sta
*mvm_sta
;
2322 lockdep_assert_held(&mvm
->mutex
);
2324 /* Block/unblock all the stations of the given mvmvif */
2325 for (i
= 0; i
< IWL_MVM_STATION_COUNT
; i
++) {
2326 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[i
],
2327 lockdep_is_held(&mvm
->mutex
));
2328 if (IS_ERR_OR_NULL(sta
))
2331 mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
2332 if (mvm_sta
->mac_id_n_color
!=
2333 FW_CMD_ID_AND_COLOR(mvmvif
->id
, mvmvif
->color
))
2336 iwl_mvm_sta_modify_disable_tx_ap(mvm
, sta
, disable
);
2340 void iwl_mvm_csa_client_absent(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
2342 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2343 struct iwl_mvm_sta
*mvmsta
;
2347 mvmsta
= iwl_mvm_sta_from_staid_rcu(mvm
, mvmvif
->ap_sta_id
);
2349 if (!WARN_ON(!mvmsta
))
2350 iwl_mvm_sta_modify_disable_tx(mvm
, mvmsta
, true);