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
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
34 * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *****************************************************************************/
65 #include <net/mac80211.h>
71 static int iwl_mvm_find_free_sta_id(struct iwl_mvm
*mvm
,
72 enum nl80211_iftype iftype
)
77 BUILD_BUG_ON(IWL_MVM_STATION_COUNT
> 32);
78 WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
));
80 lockdep_assert_held(&mvm
->mutex
);
82 /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */
83 if (iftype
!= NL80211_IFTYPE_STATION
)
84 reserved_ids
= BIT(0);
86 /* Don't take rcu_read_lock() since we are protected by mvm->mutex */
87 for (sta_id
= 0; sta_id
< IWL_MVM_STATION_COUNT
; sta_id
++) {
88 if (BIT(sta_id
) & reserved_ids
)
91 if (!rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
92 lockdep_is_held(&mvm
->mutex
)))
95 return IWL_MVM_STATION_COUNT
;
98 /* send station add/update command to firmware */
99 int iwl_mvm_sta_send_to_fw(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
102 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
103 struct iwl_mvm_add_sta_cmd add_sta_cmd
= {
104 .sta_id
= mvm_sta
->sta_id
,
105 .mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
),
106 .add_modify
= update
? 1 : 0,
107 .station_flags_msk
= cpu_to_le32(STA_FLG_FAT_EN_MSK
|
108 STA_FLG_MIMO_EN_MSK
),
112 u32 agg_size
= 0, mpdu_dens
= 0;
115 add_sta_cmd
.tfd_queue_msk
= cpu_to_le32(mvm_sta
->tfd_queue_msk
);
116 memcpy(&add_sta_cmd
.addr
, sta
->addr
, ETH_ALEN
);
119 switch (sta
->bandwidth
) {
120 case IEEE80211_STA_RX_BW_160
:
121 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_FAT_EN_160MHZ
);
123 case IEEE80211_STA_RX_BW_80
:
124 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_FAT_EN_80MHZ
);
126 case IEEE80211_STA_RX_BW_40
:
127 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_FAT_EN_40MHZ
);
129 case IEEE80211_STA_RX_BW_20
:
130 if (sta
->ht_cap
.ht_supported
)
131 add_sta_cmd
.station_flags
|=
132 cpu_to_le32(STA_FLG_FAT_EN_20MHZ
);
136 switch (sta
->rx_nss
) {
138 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_SISO
);
141 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2
);
144 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3
);
148 switch (sta
->smps_mode
) {
149 case IEEE80211_SMPS_AUTOMATIC
:
150 case IEEE80211_SMPS_NUM_MODES
:
153 case IEEE80211_SMPS_STATIC
:
155 add_sta_cmd
.station_flags
&= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK
);
156 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_MIMO_EN_SISO
);
158 case IEEE80211_SMPS_DYNAMIC
:
159 add_sta_cmd
.station_flags
|= cpu_to_le32(STA_FLG_RTS_MIMO_PROT
);
161 case IEEE80211_SMPS_OFF
:
166 if (sta
->ht_cap
.ht_supported
) {
167 add_sta_cmd
.station_flags_msk
|=
168 cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK
|
169 STA_FLG_AGG_MPDU_DENS_MSK
);
171 mpdu_dens
= sta
->ht_cap
.ampdu_density
;
174 if (sta
->vht_cap
.vht_supported
) {
175 agg_size
= sta
->vht_cap
.cap
&
176 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK
;
178 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT
;
179 } else if (sta
->ht_cap
.ht_supported
) {
180 agg_size
= sta
->ht_cap
.ampdu_factor
;
183 add_sta_cmd
.station_flags
|=
184 cpu_to_le32(agg_size
<< STA_FLG_MAX_AGG_SIZE_SHIFT
);
185 add_sta_cmd
.station_flags
|=
186 cpu_to_le32(mpdu_dens
<< STA_FLG_AGG_MPDU_DENS_SHIFT
);
188 status
= ADD_STA_SUCCESS
;
189 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(add_sta_cmd
),
190 &add_sta_cmd
, &status
);
195 case ADD_STA_SUCCESS
:
196 IWL_DEBUG_ASSOC(mvm
, "ADD_STA PASSED\n");
200 IWL_ERR(mvm
, "ADD_STA failed\n");
207 static int iwl_mvm_tdls_sta_init(struct iwl_mvm
*mvm
,
208 struct ieee80211_sta
*sta
)
210 unsigned long used_hw_queues
;
211 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
212 unsigned int wdg_timeout
=
213 iwl_mvm_get_wd_timeout(mvm
, NULL
, true, false);
216 lockdep_assert_held(&mvm
->mutex
);
218 used_hw_queues
= iwl_mvm_get_used_hw_queues(mvm
, NULL
);
220 /* Find available queues, and allocate them to the ACs */
221 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
222 u8 queue
= find_first_zero_bit(&used_hw_queues
,
223 mvm
->first_agg_queue
);
225 if (queue
>= mvm
->first_agg_queue
) {
226 IWL_ERR(mvm
, "Failed to allocate STA queue\n");
230 __set_bit(queue
, &used_hw_queues
);
231 mvmsta
->hw_queue
[ac
] = queue
;
234 /* Found a place for all queues - enable them */
235 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
236 iwl_mvm_enable_ac_txq(mvm
, mvmsta
->hw_queue
[ac
],
237 iwl_mvm_ac_to_tx_fifo
[ac
], wdg_timeout
);
238 mvmsta
->tfd_queue_msk
|= BIT(mvmsta
->hw_queue
[ac
]);
244 static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm
*mvm
,
245 struct ieee80211_sta
*sta
)
247 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
248 unsigned long sta_msk
;
251 lockdep_assert_held(&mvm
->mutex
);
253 /* disable the TDLS STA-specific queues */
254 sta_msk
= mvmsta
->tfd_queue_msk
;
255 for_each_set_bit(i
, &sta_msk
, sizeof(sta_msk
) * BITS_PER_BYTE
)
256 iwl_mvm_disable_txq(mvm
, i
, 0);
259 int iwl_mvm_add_sta(struct iwl_mvm
*mvm
,
260 struct ieee80211_vif
*vif
,
261 struct ieee80211_sta
*sta
)
263 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
264 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
267 lockdep_assert_held(&mvm
->mutex
);
269 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
270 sta_id
= iwl_mvm_find_free_sta_id(mvm
,
271 ieee80211_vif_type_p2p(vif
));
273 sta_id
= mvm_sta
->sta_id
;
275 if (sta_id
== IWL_MVM_STATION_COUNT
)
278 if (vif
->type
== NL80211_IFTYPE_AP
) {
279 mvmvif
->ap_assoc_sta_count
++;
280 iwl_mvm_mac_ctxt_cmd_ap(mvm
, vif
, FW_CTXT_ACTION_MODIFY
);
283 spin_lock_init(&mvm_sta
->lock
);
285 mvm_sta
->sta_id
= sta_id
;
286 mvm_sta
->mac_id_n_color
= FW_CMD_ID_AND_COLOR(mvmvif
->id
,
289 mvm_sta
->max_agg_bufsize
= LINK_QUAL_AGG_FRAME_LIMIT_DEF
;
290 mvm_sta
->tx_protection
= 0;
291 mvm_sta
->tt_tx_protection
= false;
293 /* HW restart, don't assume the memory has been zeroed */
294 atomic_set(&mvm
->pending_frames
[sta_id
], 0);
295 mvm_sta
->tid_disable_agg
= 0;
296 mvm_sta
->tfd_queue_msk
= 0;
298 /* allocate new queues for a TDLS station */
300 ret
= iwl_mvm_tdls_sta_init(mvm
, sta
);
304 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++)
305 if (vif
->hw_queue
[i
] != IEEE80211_INVAL_HW_QUEUE
)
306 mvm_sta
->tfd_queue_msk
|= BIT(vif
->hw_queue
[i
]);
309 /* for HW restart - reset everything but the sequence number */
310 for (i
= 0; i
< IWL_MAX_TID_COUNT
; i
++) {
311 u16 seq
= mvm_sta
->tid_data
[i
].seq_number
;
312 memset(&mvm_sta
->tid_data
[i
], 0, sizeof(mvm_sta
->tid_data
[i
]));
313 mvm_sta
->tid_data
[i
].seq_number
= seq
;
315 mvm_sta
->agg_tids
= 0;
317 ret
= iwl_mvm_sta_send_to_fw(mvm
, sta
, false);
321 if (vif
->type
== NL80211_IFTYPE_STATION
) {
323 WARN_ON(mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
);
324 mvmvif
->ap_sta_id
= sta_id
;
326 WARN_ON(mvmvif
->ap_sta_id
== IWL_MVM_STATION_COUNT
);
330 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta_id
], sta
);
335 iwl_mvm_tdls_sta_deinit(mvm
, sta
);
339 int iwl_mvm_update_sta(struct iwl_mvm
*mvm
,
340 struct ieee80211_vif
*vif
,
341 struct ieee80211_sta
*sta
)
343 return iwl_mvm_sta_send_to_fw(mvm
, sta
, true);
346 int iwl_mvm_drain_sta(struct iwl_mvm
*mvm
, struct iwl_mvm_sta
*mvmsta
,
349 struct iwl_mvm_add_sta_cmd cmd
= {};
353 lockdep_assert_held(&mvm
->mutex
);
355 cmd
.mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
);
356 cmd
.sta_id
= mvmsta
->sta_id
;
357 cmd
.add_modify
= STA_MODE_MODIFY
;
358 cmd
.station_flags
= drain
? cpu_to_le32(STA_FLG_DRAIN_FLOW
) : 0;
359 cmd
.station_flags_msk
= cpu_to_le32(STA_FLG_DRAIN_FLOW
);
361 status
= ADD_STA_SUCCESS
;
362 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(cmd
),
368 case ADD_STA_SUCCESS
:
369 IWL_DEBUG_INFO(mvm
, "Frames for staid %d will drained in fw\n",
374 IWL_ERR(mvm
, "Couldn't drain frames for staid %d\n",
383 * Remove a station from the FW table. Before sending the command to remove
384 * the station validate that the station is indeed known to the driver (sanity
387 static int iwl_mvm_rm_sta_common(struct iwl_mvm
*mvm
, u8 sta_id
)
389 struct ieee80211_sta
*sta
;
390 struct iwl_mvm_rm_sta_cmd rm_sta_cmd
= {
395 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
396 lockdep_is_held(&mvm
->mutex
));
398 /* Note: internal stations are marked as error values */
400 IWL_ERR(mvm
, "Invalid station id\n");
404 ret
= iwl_mvm_send_cmd_pdu(mvm
, REMOVE_STA
, 0,
405 sizeof(rm_sta_cmd
), &rm_sta_cmd
);
407 IWL_ERR(mvm
, "Failed to remove station. Id=%d\n", sta_id
);
414 void iwl_mvm_sta_drained_wk(struct work_struct
*wk
)
416 struct iwl_mvm
*mvm
= container_of(wk
, struct iwl_mvm
, sta_drained_wk
);
420 * The mutex is needed because of the SYNC cmd, but not only: if the
421 * work would run concurrently with iwl_mvm_rm_sta, it would run before
422 * iwl_mvm_rm_sta sets the station as busy, and exit. Then
423 * iwl_mvm_rm_sta would set the station as busy, and nobody will clean
426 mutex_lock(&mvm
->mutex
);
428 for_each_set_bit(sta_id
, mvm
->sta_drained
, IWL_MVM_STATION_COUNT
) {
430 struct ieee80211_sta
*sta
=
431 rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
432 lockdep_is_held(&mvm
->mutex
));
435 * This station is in use or RCU-removed; the latter happens in
436 * managed mode, where mac80211 removes the station before we
437 * can remove it from firmware (we can only do that after the
438 * MAC is marked unassociated), and possibly while the deauth
439 * frame to disconnect from the AP is still queued. Then, the
440 * station pointer is -ENOENT when the last skb is reclaimed.
442 if (!IS_ERR(sta
) || PTR_ERR(sta
) == -ENOENT
)
445 if (PTR_ERR(sta
) == -EINVAL
) {
446 IWL_ERR(mvm
, "Drained sta %d, but it is internal?\n",
452 IWL_ERR(mvm
, "Drained sta %d, but it was NULL?\n",
457 WARN_ON(PTR_ERR(sta
) != -EBUSY
);
458 /* This station was removed and we waited until it got drained,
459 * we can now proceed and remove it.
461 ret
= iwl_mvm_rm_sta_common(mvm
, sta_id
);
464 "Couldn't remove sta %d after it was drained\n",
468 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta_id
], NULL
);
469 clear_bit(sta_id
, mvm
->sta_drained
);
471 if (mvm
->tfd_drained
[sta_id
]) {
472 unsigned long i
, msk
= mvm
->tfd_drained
[sta_id
];
474 for_each_set_bit(i
, &msk
, sizeof(msk
) * BITS_PER_BYTE
)
475 iwl_mvm_disable_txq(mvm
, i
, 0);
477 mvm
->tfd_drained
[sta_id
] = 0;
478 IWL_DEBUG_TDLS(mvm
, "Drained sta %d, with queues %ld\n",
483 mutex_unlock(&mvm
->mutex
);
486 int iwl_mvm_rm_sta(struct iwl_mvm
*mvm
,
487 struct ieee80211_vif
*vif
,
488 struct ieee80211_sta
*sta
)
490 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
491 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
494 lockdep_assert_held(&mvm
->mutex
);
496 if (vif
->type
== NL80211_IFTYPE_STATION
&&
497 mvmvif
->ap_sta_id
== mvm_sta
->sta_id
) {
498 ret
= iwl_mvm_drain_sta(mvm
, mvm_sta
, true);
501 /* flush its queues here since we are freeing mvm_sta */
502 ret
= iwl_mvm_flush_tx_path(mvm
, mvm_sta
->tfd_queue_msk
, true);
505 ret
= iwl_trans_wait_tx_queue_empty(mvm
->trans
,
506 mvm_sta
->tfd_queue_msk
);
509 ret
= iwl_mvm_drain_sta(mvm
, mvm_sta
, false);
511 /* if we are associated - we can't remove the AP STA now */
512 if (vif
->bss_conf
.assoc
)
515 /* unassoc - go ahead - remove the AP STA now */
516 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
518 /* clear d0i3_ap_sta_id if no longer relevant */
519 if (mvm
->d0i3_ap_sta_id
== mvm_sta
->sta_id
)
520 mvm
->d0i3_ap_sta_id
= IWL_MVM_STATION_COUNT
;
524 * This shouldn't happen - the TDLS channel switch should be canceled
525 * before the STA is removed.
527 if (WARN_ON_ONCE(mvm
->tdls_cs
.peer
.sta_id
== mvm_sta
->sta_id
)) {
528 mvm
->tdls_cs
.peer
.sta_id
= IWL_MVM_STATION_COUNT
;
529 cancel_delayed_work(&mvm
->tdls_cs
.dwork
);
533 * Make sure that the tx response code sees the station as -EBUSY and
534 * calls the drain worker.
536 spin_lock_bh(&mvm_sta
->lock
);
538 * There are frames pending on the AC queues for this station.
539 * We need to wait until all the frames are drained...
541 if (atomic_read(&mvm
->pending_frames
[mvm_sta
->sta_id
])) {
542 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
],
544 spin_unlock_bh(&mvm_sta
->lock
);
546 /* disable TDLS sta queues on drain complete */
548 mvm
->tfd_drained
[mvm_sta
->sta_id
] =
549 mvm_sta
->tfd_queue_msk
;
550 IWL_DEBUG_TDLS(mvm
, "Draining TDLS sta %d\n",
554 ret
= iwl_mvm_drain_sta(mvm
, mvm_sta
, true);
556 spin_unlock_bh(&mvm_sta
->lock
);
559 iwl_mvm_tdls_sta_deinit(mvm
, sta
);
561 ret
= iwl_mvm_rm_sta_common(mvm
, mvm_sta
->sta_id
);
562 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
], NULL
);
568 int iwl_mvm_rm_sta_id(struct iwl_mvm
*mvm
,
569 struct ieee80211_vif
*vif
,
572 int ret
= iwl_mvm_rm_sta_common(mvm
, sta_id
);
574 lockdep_assert_held(&mvm
->mutex
);
576 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta_id
], NULL
);
580 static int iwl_mvm_allocate_int_sta(struct iwl_mvm
*mvm
,
581 struct iwl_mvm_int_sta
*sta
,
582 u32 qmask
, enum nl80211_iftype iftype
)
584 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
585 sta
->sta_id
= iwl_mvm_find_free_sta_id(mvm
, iftype
);
586 if (WARN_ON_ONCE(sta
->sta_id
== IWL_MVM_STATION_COUNT
))
590 sta
->tfd_queue_msk
= qmask
;
592 /* put a non-NULL value so iterating over the stations won't stop */
593 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta
->sta_id
], ERR_PTR(-EINVAL
));
597 static void iwl_mvm_dealloc_int_sta(struct iwl_mvm
*mvm
,
598 struct iwl_mvm_int_sta
*sta
)
600 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta
->sta_id
], NULL
);
601 memset(sta
, 0, sizeof(struct iwl_mvm_int_sta
));
602 sta
->sta_id
= IWL_MVM_STATION_COUNT
;
605 static int iwl_mvm_add_int_sta_common(struct iwl_mvm
*mvm
,
606 struct iwl_mvm_int_sta
*sta
,
608 u16 mac_id
, u16 color
)
610 struct iwl_mvm_add_sta_cmd cmd
;
614 lockdep_assert_held(&mvm
->mutex
);
616 memset(&cmd
, 0, sizeof(cmd
));
617 cmd
.sta_id
= sta
->sta_id
;
618 cmd
.mac_id_n_color
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id
,
621 cmd
.tfd_queue_msk
= cpu_to_le32(sta
->tfd_queue_msk
);
624 memcpy(cmd
.addr
, addr
, ETH_ALEN
);
626 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(cmd
),
632 case ADD_STA_SUCCESS
:
633 IWL_DEBUG_INFO(mvm
, "Internal station added.\n");
637 IWL_ERR(mvm
, "Add internal station failed, status=0x%x\n",
644 int iwl_mvm_add_aux_sta(struct iwl_mvm
*mvm
)
646 unsigned int wdg_timeout
= iwlmvm_mod_params
.tfd_q_hang_detect
?
647 mvm
->cfg
->base_params
->wd_timeout
:
648 IWL_WATCHDOG_DISABLED
;
651 lockdep_assert_held(&mvm
->mutex
);
653 /* Map Aux queue to fifo - needs to happen before adding Aux station */
654 iwl_mvm_enable_ac_txq(mvm
, mvm
->aux_queue
,
655 IWL_MVM_TX_FIFO_MCAST
, wdg_timeout
);
657 /* Allocate aux station and assign to it the aux queue */
658 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvm
->aux_sta
, BIT(mvm
->aux_queue
),
659 NL80211_IFTYPE_UNSPECIFIED
);
663 ret
= iwl_mvm_add_int_sta_common(mvm
, &mvm
->aux_sta
, NULL
,
667 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
671 void iwl_mvm_del_aux_sta(struct iwl_mvm
*mvm
)
673 lockdep_assert_held(&mvm
->mutex
);
675 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
679 * Send the add station command for the vif's broadcast station.
680 * Assumes that the station was already allocated.
682 * @mvm: the mvm component
683 * @vif: the interface to which the broadcast station is added
684 * @bsta: the broadcast station to add.
686 int iwl_mvm_send_add_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
688 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
689 struct iwl_mvm_int_sta
*bsta
= &mvmvif
->bcast_sta
;
690 static const u8 _baddr
[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
691 const u8
*baddr
= _baddr
;
693 lockdep_assert_held(&mvm
->mutex
);
695 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
696 baddr
= vif
->bss_conf
.bssid
;
698 if (WARN_ON_ONCE(bsta
->sta_id
== IWL_MVM_STATION_COUNT
))
701 return iwl_mvm_add_int_sta_common(mvm
, bsta
, baddr
,
702 mvmvif
->id
, mvmvif
->color
);
705 /* Send the FW a request to remove the station from it's internal data
706 * structures, but DO NOT remove the entry from the local data structures. */
707 int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
709 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
712 lockdep_assert_held(&mvm
->mutex
);
714 ret
= iwl_mvm_rm_sta_common(mvm
, mvmvif
->bcast_sta
.sta_id
);
716 IWL_WARN(mvm
, "Failed sending remove station\n");
720 int iwl_mvm_alloc_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
722 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
725 lockdep_assert_held(&mvm
->mutex
);
727 qmask
= iwl_mvm_mac_get_queues_mask(vif
);
730 * The firmware defines the TFD queue mask to only be relevant
731 * for *unicast* queues, so the multicast (CAB) queue shouldn't
734 if (vif
->type
== NL80211_IFTYPE_AP
)
735 qmask
&= ~BIT(vif
->cab_queue
);
737 return iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->bcast_sta
, qmask
,
738 ieee80211_vif_type_p2p(vif
));
741 /* Allocate a new station entry for the broadcast station to the given vif,
742 * and send it to the FW.
743 * Note that each P2P mac should have its own broadcast station.
745 * @mvm: the mvm component
746 * @vif: the interface to which the broadcast station is added
747 * @bsta: the broadcast station to add. */
748 int iwl_mvm_add_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
750 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
751 struct iwl_mvm_int_sta
*bsta
= &mvmvif
->bcast_sta
;
754 lockdep_assert_held(&mvm
->mutex
);
756 ret
= iwl_mvm_alloc_bcast_sta(mvm
, vif
);
760 ret
= iwl_mvm_send_add_bcast_sta(mvm
, vif
);
763 iwl_mvm_dealloc_int_sta(mvm
, bsta
);
768 void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
770 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
772 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->bcast_sta
);
776 * Send the FW a request to remove the station from it's internal data
777 * structures, and in addition remove it from the local data structure.
779 int iwl_mvm_rm_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
783 lockdep_assert_held(&mvm
->mutex
);
785 ret
= iwl_mvm_send_rm_bcast_sta(mvm
, vif
);
787 iwl_mvm_dealloc_bcast_sta(mvm
, vif
);
792 #define IWL_MAX_RX_BA_SESSIONS 16
794 int iwl_mvm_sta_rx_agg(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
795 int tid
, u16 ssn
, bool start
)
797 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
798 struct iwl_mvm_add_sta_cmd cmd
= {};
802 lockdep_assert_held(&mvm
->mutex
);
804 if (start
&& mvm
->rx_ba_sessions
>= IWL_MAX_RX_BA_SESSIONS
) {
805 IWL_WARN(mvm
, "Not enough RX BA SESSIONS\n");
809 cmd
.mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
);
810 cmd
.sta_id
= mvm_sta
->sta_id
;
811 cmd
.add_modify
= STA_MODE_MODIFY
;
813 cmd
.add_immediate_ba_tid
= (u8
) tid
;
814 cmd
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
816 cmd
.remove_immediate_ba_tid
= (u8
) tid
;
818 cmd
.modify_mask
= start
? STA_MODIFY_ADD_BA_TID
:
819 STA_MODIFY_REMOVE_BA_TID
;
821 status
= ADD_STA_SUCCESS
;
822 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(cmd
),
828 case ADD_STA_SUCCESS
:
829 IWL_DEBUG_INFO(mvm
, "RX BA Session %sed in fw\n",
830 start
? "start" : "stopp");
832 case ADD_STA_IMMEDIATE_BA_FAILURE
:
833 IWL_WARN(mvm
, "RX BA Session refused by fw\n");
838 IWL_ERR(mvm
, "RX BA Session failed %sing, status 0x%x\n",
839 start
? "start" : "stopp", status
);
845 mvm
->rx_ba_sessions
++;
846 else if (mvm
->rx_ba_sessions
> 0)
847 /* check that restart flow didn't zero the counter */
848 mvm
->rx_ba_sessions
--;
854 static int iwl_mvm_sta_tx_agg(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
855 int tid
, u8 queue
, bool start
)
857 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
858 struct iwl_mvm_add_sta_cmd cmd
= {};
862 lockdep_assert_held(&mvm
->mutex
);
865 mvm_sta
->tfd_queue_msk
|= BIT(queue
);
866 mvm_sta
->tid_disable_agg
&= ~BIT(tid
);
868 mvm_sta
->tfd_queue_msk
&= ~BIT(queue
);
869 mvm_sta
->tid_disable_agg
|= BIT(tid
);
872 cmd
.mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
);
873 cmd
.sta_id
= mvm_sta
->sta_id
;
874 cmd
.add_modify
= STA_MODE_MODIFY
;
875 cmd
.modify_mask
= STA_MODIFY_QUEUES
| STA_MODIFY_TID_DISABLE_TX
;
876 cmd
.tfd_queue_msk
= cpu_to_le32(mvm_sta
->tfd_queue_msk
);
877 cmd
.tid_disable_tx
= cpu_to_le16(mvm_sta
->tid_disable_agg
);
879 status
= ADD_STA_SUCCESS
;
880 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(cmd
),
886 case ADD_STA_SUCCESS
:
890 IWL_ERR(mvm
, "TX BA Session failed %sing, status 0x%x\n",
891 start
? "start" : "stopp", status
);
898 const u8 tid_to_mac80211_ac
[] = {
909 static const u8 tid_to_ucode_ac
[] = {
920 int iwl_mvm_sta_tx_agg_start(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
921 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
)
923 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
924 struct iwl_mvm_tid_data
*tid_data
;
927 if (WARN_ON_ONCE(tid
>= IWL_MAX_TID_COUNT
))
930 if (mvmsta
->tid_data
[tid
].state
!= IWL_AGG_OFF
) {
931 IWL_ERR(mvm
, "Start AGG when state is not IWL_AGG_OFF %d!\n",
932 mvmsta
->tid_data
[tid
].state
);
936 lockdep_assert_held(&mvm
->mutex
);
938 for (txq_id
= mvm
->first_agg_queue
;
939 txq_id
<= mvm
->last_agg_queue
; txq_id
++)
940 if (mvm
->queue_to_mac80211
[txq_id
] ==
941 IWL_INVALID_MAC80211_QUEUE
)
944 if (txq_id
> mvm
->last_agg_queue
) {
945 IWL_ERR(mvm
, "Failed to allocate agg queue\n");
949 spin_lock_bh(&mvmsta
->lock
);
951 /* possible race condition - we entered D0i3 while starting agg */
952 if (test_bit(IWL_MVM_STATUS_IN_D0I3
, &mvm
->status
)) {
953 spin_unlock_bh(&mvmsta
->lock
);
954 IWL_ERR(mvm
, "Entered D0i3 while starting Tx agg\n");
958 /* the new tx queue is still connected to the same mac80211 queue */
959 mvm
->queue_to_mac80211
[txq_id
] = vif
->hw_queue
[tid_to_mac80211_ac
[tid
]];
961 tid_data
= &mvmsta
->tid_data
[tid
];
962 tid_data
->ssn
= IEEE80211_SEQ_TO_SN(tid_data
->seq_number
);
963 tid_data
->txq_id
= txq_id
;
964 *ssn
= tid_data
->ssn
;
966 IWL_DEBUG_TX_QUEUES(mvm
,
967 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
968 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->ssn
,
969 tid_data
->next_reclaimed
);
971 if (tid_data
->ssn
== tid_data
->next_reclaimed
) {
972 tid_data
->state
= IWL_AGG_STARTING
;
973 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
975 tid_data
->state
= IWL_EMPTYING_HW_QUEUE_ADDBA
;
978 spin_unlock_bh(&mvmsta
->lock
);
983 int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
984 struct ieee80211_sta
*sta
, u16 tid
, u8 buf_size
)
986 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
987 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
988 unsigned int wdg_timeout
=
989 iwl_mvm_get_wd_timeout(mvm
, vif
, sta
->tdls
, false);
990 int queue
, fifo
, ret
;
993 BUILD_BUG_ON((sizeof(mvmsta
->agg_tids
) * BITS_PER_BYTE
)
994 != IWL_MAX_TID_COUNT
);
996 buf_size
= min_t(int, buf_size
, LINK_QUAL_AGG_FRAME_LIMIT_DEF
);
998 spin_lock_bh(&mvmsta
->lock
);
1000 queue
= tid_data
->txq_id
;
1001 tid_data
->state
= IWL_AGG_ON
;
1002 mvmsta
->agg_tids
|= BIT(tid
);
1003 tid_data
->ssn
= 0xffff;
1004 spin_unlock_bh(&mvmsta
->lock
);
1006 fifo
= iwl_mvm_ac_to_tx_fifo
[tid_to_mac80211_ac
[tid
]];
1008 iwl_mvm_enable_agg_txq(mvm
, queue
, fifo
, mvmsta
->sta_id
, tid
,
1009 buf_size
, ssn
, wdg_timeout
);
1011 ret
= iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, queue
, true);
1016 * Even though in theory the peer could have different
1017 * aggregation reorder buffer sizes for different sessions,
1018 * our ucode doesn't allow for that and has a global limit
1019 * for each station. Therefore, use the minimum of all the
1020 * aggregation sessions and our default value.
1022 mvmsta
->max_agg_bufsize
=
1023 min(mvmsta
->max_agg_bufsize
, buf_size
);
1024 mvmsta
->lq_sta
.lq
.agg_frame_cnt_limit
= mvmsta
->max_agg_bufsize
;
1026 IWL_DEBUG_HT(mvm
, "Tx aggregation enabled on ra = %pM tid = %d\n",
1029 return iwl_mvm_send_lq_cmd(mvm
, &mvmsta
->lq_sta
.lq
, false);
1032 int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1033 struct ieee80211_sta
*sta
, u16 tid
)
1035 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1036 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
1042 * If mac80211 is cleaning its state, then say that we finished since
1043 * our state has been cleared anyway.
1045 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
1046 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1050 spin_lock_bh(&mvmsta
->lock
);
1052 txq_id
= tid_data
->txq_id
;
1054 IWL_DEBUG_TX_QUEUES(mvm
, "Stop AGG: sta %d tid %d q %d state %d\n",
1055 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->state
);
1057 mvmsta
->agg_tids
&= ~BIT(tid
);
1059 switch (tid_data
->state
) {
1061 tid_data
->ssn
= IEEE80211_SEQ_TO_SN(tid_data
->seq_number
);
1063 IWL_DEBUG_TX_QUEUES(mvm
,
1064 "ssn = %d, next_recl = %d\n",
1065 tid_data
->ssn
, tid_data
->next_reclaimed
);
1067 /* There are still packets for this RA / TID in the HW */
1068 if (tid_data
->ssn
!= tid_data
->next_reclaimed
) {
1069 tid_data
->state
= IWL_EMPTYING_HW_QUEUE_DELBA
;
1074 tid_data
->ssn
= 0xffff;
1075 tid_data
->state
= IWL_AGG_OFF
;
1076 mvm
->queue_to_mac80211
[txq_id
] = IWL_INVALID_MAC80211_QUEUE
;
1077 spin_unlock_bh(&mvmsta
->lock
);
1079 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1081 iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, txq_id
, false);
1083 iwl_mvm_disable_txq(mvm
, txq_id
, 0);
1085 case IWL_AGG_STARTING
:
1086 case IWL_EMPTYING_HW_QUEUE_ADDBA
:
1088 * The agg session has been stopped before it was set up. This
1089 * can happen when the AddBA timer times out for example.
1092 /* No barriers since we are under mutex */
1093 lockdep_assert_held(&mvm
->mutex
);
1094 mvm
->queue_to_mac80211
[txq_id
] = IWL_INVALID_MAC80211_QUEUE
;
1096 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1097 tid_data
->state
= IWL_AGG_OFF
;
1102 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
1103 mvmsta
->sta_id
, tid
, tid_data
->state
);
1105 "\ttid_data->txq_id = %d\n", tid_data
->txq_id
);
1109 spin_unlock_bh(&mvmsta
->lock
);
1114 int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1115 struct ieee80211_sta
*sta
, u16 tid
)
1117 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1118 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
1120 enum iwl_mvm_agg_state old_state
;
1123 * First set the agg state to OFF to avoid calling
1124 * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
1126 spin_lock_bh(&mvmsta
->lock
);
1127 txq_id
= tid_data
->txq_id
;
1128 IWL_DEBUG_TX_QUEUES(mvm
, "Flush AGG: sta %d tid %d q %d state %d\n",
1129 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->state
);
1130 old_state
= tid_data
->state
;
1131 tid_data
->state
= IWL_AGG_OFF
;
1132 mvmsta
->agg_tids
&= ~BIT(tid
);
1133 spin_unlock_bh(&mvmsta
->lock
);
1135 if (old_state
>= IWL_AGG_ON
) {
1136 iwl_mvm_drain_sta(mvm
, mvmsta
, true);
1137 if (iwl_mvm_flush_tx_path(mvm
, BIT(txq_id
), true))
1138 IWL_ERR(mvm
, "Couldn't flush the AGG queue\n");
1139 iwl_trans_wait_tx_queue_empty(mvm
->trans
,
1140 mvmsta
->tfd_queue_msk
);
1141 iwl_mvm_drain_sta(mvm
, mvmsta
, false);
1143 iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, txq_id
, false);
1145 iwl_mvm_disable_txq(mvm
, tid_data
->txq_id
, 0);
1148 mvm
->queue_to_mac80211
[tid_data
->txq_id
] =
1149 IWL_INVALID_MAC80211_QUEUE
;
1154 static int iwl_mvm_set_fw_key_idx(struct iwl_mvm
*mvm
)
1156 int i
, max
= -1, max_offs
= -1;
1158 lockdep_assert_held(&mvm
->mutex
);
1160 /* Pick the unused key offset with the highest 'deleted'
1161 * counter. Every time a key is deleted, all the counters
1162 * are incremented and the one that was just deleted is
1163 * reset to zero. Thus, the highest counter is the one
1164 * that was deleted longest ago. Pick that one.
1166 for (i
= 0; i
< STA_KEY_MAX_NUM
; i
++) {
1167 if (test_bit(i
, mvm
->fw_key_table
))
1169 if (mvm
->fw_key_deleted
[i
] > max
) {
1170 max
= mvm
->fw_key_deleted
[i
];
1176 return STA_KEY_IDX_INVALID
;
1178 __set_bit(max_offs
, mvm
->fw_key_table
);
1183 static u8
iwl_mvm_get_key_sta_id(struct ieee80211_vif
*vif
,
1184 struct ieee80211_sta
*sta
)
1186 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1189 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1191 return mvm_sta
->sta_id
;
1195 * The device expects GTKs for station interfaces to be
1196 * installed as GTKs for the AP station. If we have no
1197 * station ID, then use AP's station ID.
1199 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1200 mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
)
1201 return mvmvif
->ap_sta_id
;
1203 return IWL_MVM_STATION_COUNT
;
1206 static int iwl_mvm_send_sta_key(struct iwl_mvm
*mvm
,
1207 struct iwl_mvm_sta
*mvm_sta
,
1208 struct ieee80211_key_conf
*keyconf
, bool mcast
,
1209 u32 tkip_iv32
, u16
*tkip_p1k
, u32 cmd_flags
)
1211 struct iwl_mvm_add_sta_key_cmd cmd
= {};
1217 u8 sta_id
= mvm_sta
->sta_id
;
1219 keyidx
= (keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
) &
1220 STA_KEY_FLG_KEYID_MSK
;
1221 key_flags
= cpu_to_le16(keyidx
);
1222 key_flags
|= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP
);
1224 switch (keyconf
->cipher
) {
1225 case WLAN_CIPHER_SUITE_TKIP
:
1226 key_flags
|= cpu_to_le16(STA_KEY_FLG_TKIP
);
1227 cmd
.tkip_rx_tsc_byte2
= tkip_iv32
;
1228 for (i
= 0; i
< 5; i
++)
1229 cmd
.tkip_rx_ttak
[i
] = cpu_to_le16(tkip_p1k
[i
]);
1230 memcpy(cmd
.key
, keyconf
->key
, keyconf
->keylen
);
1232 case WLAN_CIPHER_SUITE_CCMP
:
1233 key_flags
|= cpu_to_le16(STA_KEY_FLG_CCM
);
1234 memcpy(cmd
.key
, keyconf
->key
, keyconf
->keylen
);
1236 case WLAN_CIPHER_SUITE_WEP104
:
1237 key_flags
|= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES
);
1239 case WLAN_CIPHER_SUITE_WEP40
:
1240 key_flags
|= cpu_to_le16(STA_KEY_FLG_WEP
);
1241 memcpy(cmd
.key
+ 3, keyconf
->key
, keyconf
->keylen
);
1244 key_flags
|= cpu_to_le16(STA_KEY_FLG_EXT
);
1245 memcpy(cmd
.key
, keyconf
->key
, keyconf
->keylen
);
1249 key_flags
|= cpu_to_le16(STA_KEY_MULTICAST
);
1251 cmd
.key_offset
= keyconf
->hw_key_idx
;
1252 cmd
.key_flags
= key_flags
;
1253 cmd
.sta_id
= sta_id
;
1255 status
= ADD_STA_SUCCESS
;
1256 if (cmd_flags
& CMD_ASYNC
)
1257 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA_KEY
, CMD_ASYNC
,
1260 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA_KEY
, sizeof(cmd
),
1264 case ADD_STA_SUCCESS
:
1265 IWL_DEBUG_WEP(mvm
, "MODIFY_STA: set dynamic key passed\n");
1269 IWL_ERR(mvm
, "MODIFY_STA: set dynamic key failed\n");
1276 static int iwl_mvm_send_sta_igtk(struct iwl_mvm
*mvm
,
1277 struct ieee80211_key_conf
*keyconf
,
1278 u8 sta_id
, bool remove_key
)
1280 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd
= {};
1282 /* verify the key details match the required command's expectations */
1283 if (WARN_ON((keyconf
->cipher
!= WLAN_CIPHER_SUITE_AES_CMAC
) ||
1284 (keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
) ||
1285 (keyconf
->keyidx
!= 4 && keyconf
->keyidx
!= 5)))
1288 igtk_cmd
.key_id
= cpu_to_le32(keyconf
->keyidx
);
1289 igtk_cmd
.sta_id
= cpu_to_le32(sta_id
);
1292 igtk_cmd
.ctrl_flags
|= cpu_to_le32(STA_KEY_NOT_VALID
);
1294 struct ieee80211_key_seq seq
;
1297 memcpy(igtk_cmd
.IGTK
, keyconf
->key
, keyconf
->keylen
);
1298 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1299 pn
= seq
.aes_cmac
.pn
;
1300 igtk_cmd
.receive_seq_cnt
= cpu_to_le64(((u64
) pn
[5] << 0) |
1301 ((u64
) pn
[4] << 8) |
1302 ((u64
) pn
[3] << 16) |
1303 ((u64
) pn
[2] << 24) |
1304 ((u64
) pn
[1] << 32) |
1305 ((u64
) pn
[0] << 40));
1308 IWL_DEBUG_INFO(mvm
, "%s igtk for sta %u\n",
1309 remove_key
? "removing" : "installing",
1312 return iwl_mvm_send_cmd_pdu(mvm
, MGMT_MCAST_KEY
, 0,
1313 sizeof(igtk_cmd
), &igtk_cmd
);
1317 static inline u8
*iwl_mvm_get_mac_addr(struct iwl_mvm
*mvm
,
1318 struct ieee80211_vif
*vif
,
1319 struct ieee80211_sta
*sta
)
1321 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1326 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1327 mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
1328 u8 sta_id
= mvmvif
->ap_sta_id
;
1329 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1330 lockdep_is_held(&mvm
->mutex
));
1338 static int __iwl_mvm_set_sta_key(struct iwl_mvm
*mvm
,
1339 struct ieee80211_vif
*vif
,
1340 struct ieee80211_sta
*sta
,
1341 struct ieee80211_key_conf
*keyconf
,
1344 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1347 struct ieee80211_key_seq seq
;
1350 switch (keyconf
->cipher
) {
1351 case WLAN_CIPHER_SUITE_TKIP
:
1352 addr
= iwl_mvm_get_mac_addr(mvm
, vif
, sta
);
1353 /* get phase 1 key from mac80211 */
1354 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1355 ieee80211_get_tkip_rx_p1k(keyconf
, addr
, seq
.tkip
.iv32
, p1k
);
1356 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
1357 seq
.tkip
.iv32
, p1k
, 0);
1359 case WLAN_CIPHER_SUITE_CCMP
:
1360 case WLAN_CIPHER_SUITE_WEP40
:
1361 case WLAN_CIPHER_SUITE_WEP104
:
1362 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
1366 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
1373 static int __iwl_mvm_remove_sta_key(struct iwl_mvm
*mvm
, u8 sta_id
,
1374 struct ieee80211_key_conf
*keyconf
,
1377 struct iwl_mvm_add_sta_key_cmd cmd
= {};
1382 key_flags
= cpu_to_le16((keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
) &
1383 STA_KEY_FLG_KEYID_MSK
);
1384 key_flags
|= cpu_to_le16(STA_KEY_FLG_NO_ENC
| STA_KEY_FLG_WEP_KEY_MAP
);
1385 key_flags
|= cpu_to_le16(STA_KEY_NOT_VALID
);
1388 key_flags
|= cpu_to_le16(STA_KEY_MULTICAST
);
1390 cmd
.key_flags
= key_flags
;
1391 cmd
.key_offset
= keyconf
->hw_key_idx
;
1392 cmd
.sta_id
= sta_id
;
1394 status
= ADD_STA_SUCCESS
;
1395 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA_KEY
, sizeof(cmd
),
1399 case ADD_STA_SUCCESS
:
1400 IWL_DEBUG_WEP(mvm
, "MODIFY_STA: remove sta key passed\n");
1404 IWL_ERR(mvm
, "MODIFY_STA: remove sta key failed\n");
1411 int iwl_mvm_set_sta_key(struct iwl_mvm
*mvm
,
1412 struct ieee80211_vif
*vif
,
1413 struct ieee80211_sta
*sta
,
1414 struct ieee80211_key_conf
*keyconf
,
1415 bool have_key_offset
)
1417 bool mcast
= !(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
1420 static const u8 __maybe_unused zero_addr
[ETH_ALEN
] = {0};
1422 lockdep_assert_held(&mvm
->mutex
);
1424 /* Get the station id from the mvm local station table */
1425 sta_id
= iwl_mvm_get_key_sta_id(vif
, sta
);
1426 if (sta_id
== IWL_MVM_STATION_COUNT
) {
1427 IWL_ERR(mvm
, "Failed to find station id\n");
1431 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
) {
1432 ret
= iwl_mvm_send_sta_igtk(mvm
, keyconf
, sta_id
, false);
1437 * It is possible that the 'sta' parameter is NULL, and thus
1438 * there is a need to retrieve the sta from the local station table.
1441 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1442 lockdep_is_held(&mvm
->mutex
));
1443 if (IS_ERR_OR_NULL(sta
)) {
1444 IWL_ERR(mvm
, "Invalid station id\n");
1449 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta
)->vif
!= vif
))
1452 if (!have_key_offset
) {
1454 * The D3 firmware hardcodes the PTK offset to 0, so we have to
1455 * configure it there. As a result, this workaround exists to
1456 * let the caller set the key offset (hw_key_idx), see d3.c.
1458 keyconf
->hw_key_idx
= iwl_mvm_set_fw_key_idx(mvm
);
1459 if (keyconf
->hw_key_idx
== STA_KEY_IDX_INVALID
)
1463 ret
= __iwl_mvm_set_sta_key(mvm
, vif
, sta
, keyconf
, mcast
);
1465 __clear_bit(keyconf
->hw_key_idx
, mvm
->fw_key_table
);
1470 * For WEP, the same key is used for multicast and unicast. Upload it
1471 * again, using the same key offset, and now pointing the other one
1472 * to the same key slot (offset).
1473 * If this fails, remove the original as well.
1475 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
1476 keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP104
) {
1477 ret
= __iwl_mvm_set_sta_key(mvm
, vif
, sta
, keyconf
, !mcast
);
1479 __clear_bit(keyconf
->hw_key_idx
, mvm
->fw_key_table
);
1480 __iwl_mvm_remove_sta_key(mvm
, sta_id
, keyconf
, mcast
);
1485 IWL_DEBUG_WEP(mvm
, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
1486 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
1487 sta
? sta
->addr
: zero_addr
, ret
);
1491 int iwl_mvm_remove_sta_key(struct iwl_mvm
*mvm
,
1492 struct ieee80211_vif
*vif
,
1493 struct ieee80211_sta
*sta
,
1494 struct ieee80211_key_conf
*keyconf
)
1496 bool mcast
= !(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
1500 lockdep_assert_held(&mvm
->mutex
);
1502 /* Get the station id from the mvm local station table */
1503 sta_id
= iwl_mvm_get_key_sta_id(vif
, sta
);
1505 IWL_DEBUG_WEP(mvm
, "mvm remove dynamic key: idx=%d sta=%d\n",
1506 keyconf
->keyidx
, sta_id
);
1508 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
)
1509 return iwl_mvm_send_sta_igtk(mvm
, keyconf
, sta_id
, true);
1511 if (!__test_and_clear_bit(keyconf
->hw_key_idx
, mvm
->fw_key_table
)) {
1512 IWL_ERR(mvm
, "offset %d not used in fw key table.\n",
1513 keyconf
->hw_key_idx
);
1517 /* track which key was deleted last */
1518 for (i
= 0; i
< STA_KEY_MAX_NUM
; i
++) {
1519 if (mvm
->fw_key_deleted
[i
] < U8_MAX
)
1520 mvm
->fw_key_deleted
[i
]++;
1522 mvm
->fw_key_deleted
[keyconf
->hw_key_idx
] = 0;
1524 if (sta_id
== IWL_MVM_STATION_COUNT
) {
1525 IWL_DEBUG_WEP(mvm
, "station non-existent, early return.\n");
1530 * It is possible that the 'sta' parameter is NULL, and thus
1531 * there is a need to retrieve the sta from the local station table,
1532 * for example when a GTK is removed (where the sta_id will then be
1533 * the AP ID, and no station was passed by mac80211.)
1536 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1537 lockdep_is_held(&mvm
->mutex
));
1539 IWL_ERR(mvm
, "Invalid station id\n");
1544 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta
)->vif
!= vif
))
1547 ret
= __iwl_mvm_remove_sta_key(mvm
, sta_id
, keyconf
, mcast
);
1551 /* delete WEP key twice to get rid of (now useless) offset */
1552 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
1553 keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
1554 ret
= __iwl_mvm_remove_sta_key(mvm
, sta_id
, keyconf
, !mcast
);
1559 void iwl_mvm_update_tkip_key(struct iwl_mvm
*mvm
,
1560 struct ieee80211_vif
*vif
,
1561 struct ieee80211_key_conf
*keyconf
,
1562 struct ieee80211_sta
*sta
, u32 iv32
,
1565 struct iwl_mvm_sta
*mvm_sta
;
1566 u8 sta_id
= iwl_mvm_get_key_sta_id(vif
, sta
);
1567 bool mcast
= !(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
1569 if (WARN_ON_ONCE(sta_id
== IWL_MVM_STATION_COUNT
))
1575 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
1576 if (WARN_ON(IS_ERR_OR_NULL(sta
))) {
1582 mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1583 iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
1584 iv32
, phase1key
, CMD_ASYNC
);
1588 void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm
*mvm
,
1589 struct ieee80211_sta
*sta
)
1591 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1592 struct iwl_mvm_add_sta_cmd cmd
= {
1593 .add_modify
= STA_MODE_MODIFY
,
1594 .sta_id
= mvmsta
->sta_id
,
1595 .station_flags_msk
= cpu_to_le32(STA_FLG_PS
),
1596 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
1600 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, CMD_ASYNC
, sizeof(cmd
), &cmd
);
1602 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
1605 void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm
*mvm
,
1606 struct ieee80211_sta
*sta
,
1607 enum ieee80211_frame_release_type reason
,
1608 u16 cnt
, u16 tids
, bool more_data
,
1611 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1612 struct iwl_mvm_add_sta_cmd cmd
= {
1613 .add_modify
= STA_MODE_MODIFY
,
1614 .sta_id
= mvmsta
->sta_id
,
1615 .modify_mask
= STA_MODIFY_SLEEPING_STA_TX_COUNT
,
1616 .sleep_tx_count
= cpu_to_le16(cnt
),
1617 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
1620 unsigned long _tids
= tids
;
1622 /* convert TIDs to ACs - we don't support TSPEC so that's OK
1623 * Note that this field is reserved and unused by firmware not
1624 * supporting GO uAPSD, so it's safe to always do this.
1626 for_each_set_bit(tid
, &_tids
, IWL_MAX_TID_COUNT
)
1627 cmd
.awake_acs
|= BIT(tid_to_ucode_ac
[tid
]);
1629 /* If we're releasing frames from aggregation queues then check if the
1630 * all queues combined that we're releasing frames from have
1631 * - more frames than the service period, in which case more_data
1633 * - fewer than 'cnt' frames, in which case we need to adjust the
1634 * firmware command (but do that unconditionally)
1637 int remaining
= cnt
;
1639 spin_lock_bh(&mvmsta
->lock
);
1640 for_each_set_bit(tid
, &_tids
, IWL_MAX_TID_COUNT
) {
1641 struct iwl_mvm_tid_data
*tid_data
;
1644 tid_data
= &mvmsta
->tid_data
[tid
];
1645 if (WARN(tid_data
->state
!= IWL_AGG_ON
&&
1646 tid_data
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
,
1647 "TID %d state is %d\n",
1648 tid
, tid_data
->state
)) {
1649 spin_unlock_bh(&mvmsta
->lock
);
1650 ieee80211_sta_eosp(sta
);
1654 n_queued
= iwl_mvm_tid_queued(tid_data
);
1655 if (n_queued
> remaining
) {
1660 remaining
-= n_queued
;
1662 spin_unlock_bh(&mvmsta
->lock
);
1664 cmd
.sleep_tx_count
= cpu_to_le16(cnt
- remaining
);
1665 if (WARN_ON(cnt
- remaining
== 0)) {
1666 ieee80211_sta_eosp(sta
);
1671 /* Note: this is ignored by firmware not supporting GO uAPSD */
1673 cmd
.sleep_state_flags
|= cpu_to_le16(STA_SLEEP_STATE_MOREDATA
);
1675 if (reason
== IEEE80211_FRAME_RELEASE_PSPOLL
) {
1676 mvmsta
->next_status_eosp
= true;
1677 cmd
.sleep_state_flags
|= cpu_to_le16(STA_SLEEP_STATE_PS_POLL
);
1679 cmd
.sleep_state_flags
|= cpu_to_le16(STA_SLEEP_STATE_UAPSD
);
1682 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, CMD_ASYNC
, sizeof(cmd
), &cmd
);
1684 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
1687 void iwl_mvm_rx_eosp_notif(struct iwl_mvm
*mvm
,
1688 struct iwl_rx_cmd_buffer
*rxb
)
1690 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1691 struct iwl_mvm_eosp_notification
*notif
= (void *)pkt
->data
;
1692 struct ieee80211_sta
*sta
;
1693 u32 sta_id
= le32_to_cpu(notif
->sta_id
);
1695 if (WARN_ON_ONCE(sta_id
>= IWL_MVM_STATION_COUNT
))
1699 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
1700 if (!IS_ERR_OR_NULL(sta
))
1701 ieee80211_sta_eosp(sta
);
1705 void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm
*mvm
,
1706 struct iwl_mvm_sta
*mvmsta
, bool disable
)
1708 struct iwl_mvm_add_sta_cmd cmd
= {
1709 .add_modify
= STA_MODE_MODIFY
,
1710 .sta_id
= mvmsta
->sta_id
,
1711 .station_flags
= disable
? cpu_to_le32(STA_FLG_DISABLE_TX
) : 0,
1712 .station_flags_msk
= cpu_to_le32(STA_FLG_DISABLE_TX
),
1713 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
1717 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, CMD_ASYNC
, sizeof(cmd
), &cmd
);
1719 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
1722 void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm
*mvm
,
1723 struct ieee80211_sta
*sta
,
1726 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1728 spin_lock_bh(&mvm_sta
->lock
);
1730 if (mvm_sta
->disable_tx
== disable
) {
1731 spin_unlock_bh(&mvm_sta
->lock
);
1735 mvm_sta
->disable_tx
= disable
;
1738 * Tell mac80211 to start/stop queuing tx for this station,
1739 * but don't stop queuing if there are still pending frames
1742 if (disable
|| !atomic_read(&mvm
->pending_frames
[mvm_sta
->sta_id
]))
1743 ieee80211_sta_block_awake(mvm
->hw
, sta
, disable
);
1745 iwl_mvm_sta_modify_disable_tx(mvm
, mvm_sta
, disable
);
1747 spin_unlock_bh(&mvm_sta
->lock
);
1750 void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm
*mvm
,
1751 struct iwl_mvm_vif
*mvmvif
,
1754 struct ieee80211_sta
*sta
;
1755 struct iwl_mvm_sta
*mvm_sta
;
1758 lockdep_assert_held(&mvm
->mutex
);
1760 /* Block/unblock all the stations of the given mvmvif */
1761 for (i
= 0; i
< IWL_MVM_STATION_COUNT
; i
++) {
1762 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[i
],
1763 lockdep_is_held(&mvm
->mutex
));
1764 if (IS_ERR_OR_NULL(sta
))
1767 mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1768 if (mvm_sta
->mac_id_n_color
!=
1769 FW_CMD_ID_AND_COLOR(mvmvif
->id
, mvmvif
->color
))
1772 iwl_mvm_sta_modify_disable_tx_ap(mvm
, sta
, disable
);
1776 void iwl_mvm_csa_client_absent(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1778 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1779 struct iwl_mvm_sta
*mvmsta
;
1783 mvmsta
= iwl_mvm_sta_from_staid_rcu(mvm
, mvmvif
->ap_sta_id
);
1785 if (!WARN_ON(!mvmsta
))
1786 iwl_mvm_sta_modify_disable_tx(mvm
, mvmsta
, true);