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 - 2014 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2014 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 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2014 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
);
214 lockdep_assert_held(&mvm
->mutex
);
216 used_hw_queues
= iwl_mvm_get_used_hw_queues(mvm
, NULL
);
218 /* Find available queues, and allocate them to the ACs */
219 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
220 u8 queue
= find_first_zero_bit(&used_hw_queues
,
221 mvm
->first_agg_queue
);
223 if (queue
>= mvm
->first_agg_queue
) {
224 IWL_ERR(mvm
, "Failed to allocate STA queue\n");
228 __set_bit(queue
, &used_hw_queues
);
229 mvmsta
->hw_queue
[ac
] = queue
;
232 /* Found a place for all queues - enable them */
233 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++) {
234 iwl_mvm_enable_ac_txq(mvm
, mvmsta
->hw_queue
[ac
],
235 iwl_mvm_ac_to_tx_fifo
[ac
]);
236 mvmsta
->tfd_queue_msk
|= BIT(mvmsta
->hw_queue
[ac
]);
242 static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm
*mvm
,
243 struct ieee80211_sta
*sta
)
245 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
246 unsigned long sta_msk
;
249 lockdep_assert_held(&mvm
->mutex
);
251 /* disable the TDLS STA-specific queues */
252 sta_msk
= mvmsta
->tfd_queue_msk
;
253 for_each_set_bit(i
, &sta_msk
, sizeof(sta_msk
))
254 iwl_mvm_disable_txq(mvm
, i
, 0);
257 int iwl_mvm_add_sta(struct iwl_mvm
*mvm
,
258 struct ieee80211_vif
*vif
,
259 struct ieee80211_sta
*sta
)
261 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
262 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
265 lockdep_assert_held(&mvm
->mutex
);
267 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
268 sta_id
= iwl_mvm_find_free_sta_id(mvm
,
269 ieee80211_vif_type_p2p(vif
));
271 sta_id
= mvm_sta
->sta_id
;
273 if (WARN_ON_ONCE(sta_id
== IWL_MVM_STATION_COUNT
))
276 spin_lock_init(&mvm_sta
->lock
);
278 mvm_sta
->sta_id
= sta_id
;
279 mvm_sta
->mac_id_n_color
= FW_CMD_ID_AND_COLOR(mvmvif
->id
,
282 mvm_sta
->max_agg_bufsize
= LINK_QUAL_AGG_FRAME_LIMIT_DEF
;
283 mvm_sta
->tx_protection
= 0;
284 mvm_sta
->tt_tx_protection
= false;
286 /* HW restart, don't assume the memory has been zeroed */
287 atomic_set(&mvm
->pending_frames
[sta_id
], 0);
288 mvm_sta
->tid_disable_agg
= 0;
289 mvm_sta
->tfd_queue_msk
= 0;
291 /* allocate new queues for a TDLS station */
293 ret
= iwl_mvm_tdls_sta_init(mvm
, sta
);
297 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++)
298 if (vif
->hw_queue
[i
] != IEEE80211_INVAL_HW_QUEUE
)
299 mvm_sta
->tfd_queue_msk
|= BIT(vif
->hw_queue
[i
]);
302 /* for HW restart - reset everything but the sequence number */
303 for (i
= 0; i
< IWL_MAX_TID_COUNT
; i
++) {
304 u16 seq
= mvm_sta
->tid_data
[i
].seq_number
;
305 memset(&mvm_sta
->tid_data
[i
], 0, sizeof(mvm_sta
->tid_data
[i
]));
306 mvm_sta
->tid_data
[i
].seq_number
= seq
;
308 mvm_sta
->agg_tids
= 0;
310 ret
= iwl_mvm_sta_send_to_fw(mvm
, sta
, false);
314 if (vif
->type
== NL80211_IFTYPE_STATION
) {
316 WARN_ON(mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
);
317 mvmvif
->ap_sta_id
= sta_id
;
319 WARN_ON(mvmvif
->ap_sta_id
== IWL_MVM_STATION_COUNT
);
323 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta_id
], sta
);
328 iwl_mvm_tdls_sta_deinit(mvm
, sta
);
332 int iwl_mvm_update_sta(struct iwl_mvm
*mvm
,
333 struct ieee80211_vif
*vif
,
334 struct ieee80211_sta
*sta
)
336 return iwl_mvm_sta_send_to_fw(mvm
, sta
, true);
339 int iwl_mvm_drain_sta(struct iwl_mvm
*mvm
, struct iwl_mvm_sta
*mvmsta
,
342 struct iwl_mvm_add_sta_cmd cmd
= {};
346 lockdep_assert_held(&mvm
->mutex
);
348 cmd
.mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
);
349 cmd
.sta_id
= mvmsta
->sta_id
;
350 cmd
.add_modify
= STA_MODE_MODIFY
;
351 cmd
.station_flags
= drain
? cpu_to_le32(STA_FLG_DRAIN_FLOW
) : 0;
352 cmd
.station_flags_msk
= cpu_to_le32(STA_FLG_DRAIN_FLOW
);
354 status
= ADD_STA_SUCCESS
;
355 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(cmd
),
361 case ADD_STA_SUCCESS
:
362 IWL_DEBUG_INFO(mvm
, "Frames for staid %d will drained in fw\n",
367 IWL_ERR(mvm
, "Couldn't drain frames for staid %d\n",
376 * Remove a station from the FW table. Before sending the command to remove
377 * the station validate that the station is indeed known to the driver (sanity
380 static int iwl_mvm_rm_sta_common(struct iwl_mvm
*mvm
, u8 sta_id
)
382 struct ieee80211_sta
*sta
;
383 struct iwl_mvm_rm_sta_cmd rm_sta_cmd
= {
388 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
389 lockdep_is_held(&mvm
->mutex
));
391 /* Note: internal stations are marked as error values */
393 IWL_ERR(mvm
, "Invalid station id\n");
397 ret
= iwl_mvm_send_cmd_pdu(mvm
, REMOVE_STA
, 0,
398 sizeof(rm_sta_cmd
), &rm_sta_cmd
);
400 IWL_ERR(mvm
, "Failed to remove station. Id=%d\n", sta_id
);
407 void iwl_mvm_sta_drained_wk(struct work_struct
*wk
)
409 struct iwl_mvm
*mvm
= container_of(wk
, struct iwl_mvm
, sta_drained_wk
);
413 * The mutex is needed because of the SYNC cmd, but not only: if the
414 * work would run concurrently with iwl_mvm_rm_sta, it would run before
415 * iwl_mvm_rm_sta sets the station as busy, and exit. Then
416 * iwl_mvm_rm_sta would set the station as busy, and nobody will clean
419 mutex_lock(&mvm
->mutex
);
421 for_each_set_bit(sta_id
, mvm
->sta_drained
, IWL_MVM_STATION_COUNT
) {
423 struct ieee80211_sta
*sta
=
424 rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
425 lockdep_is_held(&mvm
->mutex
));
428 * This station is in use or RCU-removed; the latter happens in
429 * managed mode, where mac80211 removes the station before we
430 * can remove it from firmware (we can only do that after the
431 * MAC is marked unassociated), and possibly while the deauth
432 * frame to disconnect from the AP is still queued. Then, the
433 * station pointer is -ENOENT when the last skb is reclaimed.
435 if (!IS_ERR(sta
) || PTR_ERR(sta
) == -ENOENT
)
438 if (PTR_ERR(sta
) == -EINVAL
) {
439 IWL_ERR(mvm
, "Drained sta %d, but it is internal?\n",
445 IWL_ERR(mvm
, "Drained sta %d, but it was NULL?\n",
450 WARN_ON(PTR_ERR(sta
) != -EBUSY
);
451 /* This station was removed and we waited until it got drained,
452 * we can now proceed and remove it.
454 ret
= iwl_mvm_rm_sta_common(mvm
, sta_id
);
457 "Couldn't remove sta %d after it was drained\n",
461 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta_id
], NULL
);
462 clear_bit(sta_id
, mvm
->sta_drained
);
464 if (mvm
->tfd_drained
[sta_id
]) {
465 unsigned long i
, msk
= mvm
->tfd_drained
[sta_id
];
467 for_each_set_bit(i
, &msk
, sizeof(msk
))
468 iwl_mvm_disable_txq(mvm
, i
, 0);
470 mvm
->tfd_drained
[sta_id
] = 0;
471 IWL_DEBUG_TDLS(mvm
, "Drained sta %d, with queues %ld\n",
476 mutex_unlock(&mvm
->mutex
);
479 int iwl_mvm_rm_sta(struct iwl_mvm
*mvm
,
480 struct ieee80211_vif
*vif
,
481 struct ieee80211_sta
*sta
)
483 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
484 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
487 lockdep_assert_held(&mvm
->mutex
);
489 if (vif
->type
== NL80211_IFTYPE_STATION
&&
490 mvmvif
->ap_sta_id
== mvm_sta
->sta_id
) {
491 /* flush its queues here since we are freeing mvm_sta */
492 ret
= iwl_mvm_flush_tx_path(mvm
, mvm_sta
->tfd_queue_msk
, true);
494 /* if we are associated - we can't remove the AP STA now */
495 if (vif
->bss_conf
.assoc
)
498 /* unassoc - go ahead - remove the AP STA now */
499 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
501 /* clear d0i3_ap_sta_id if no longer relevant */
502 if (mvm
->d0i3_ap_sta_id
== mvm_sta
->sta_id
)
503 mvm
->d0i3_ap_sta_id
= IWL_MVM_STATION_COUNT
;
507 * This shouldn't happen - the TDLS channel switch should be canceled
508 * before the STA is removed.
510 if (WARN_ON_ONCE(mvm
->tdls_cs
.peer
.sta_id
== mvm_sta
->sta_id
)) {
511 mvm
->tdls_cs
.peer
.sta_id
= IWL_MVM_STATION_COUNT
;
512 cancel_delayed_work(&mvm
->tdls_cs
.dwork
);
516 * Make sure that the tx response code sees the station as -EBUSY and
517 * calls the drain worker.
519 spin_lock_bh(&mvm_sta
->lock
);
521 * There are frames pending on the AC queues for this station.
522 * We need to wait until all the frames are drained...
524 if (atomic_read(&mvm
->pending_frames
[mvm_sta
->sta_id
])) {
525 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
],
527 spin_unlock_bh(&mvm_sta
->lock
);
529 /* disable TDLS sta queues on drain complete */
531 mvm
->tfd_drained
[mvm_sta
->sta_id
] =
532 mvm_sta
->tfd_queue_msk
;
533 IWL_DEBUG_TDLS(mvm
, "Draining TDLS sta %d\n",
537 ret
= iwl_mvm_drain_sta(mvm
, mvm_sta
, true);
539 spin_unlock_bh(&mvm_sta
->lock
);
542 iwl_mvm_tdls_sta_deinit(mvm
, sta
);
544 ret
= iwl_mvm_rm_sta_common(mvm
, mvm_sta
->sta_id
);
545 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
], NULL
);
551 int iwl_mvm_rm_sta_id(struct iwl_mvm
*mvm
,
552 struct ieee80211_vif
*vif
,
555 int ret
= iwl_mvm_rm_sta_common(mvm
, sta_id
);
557 lockdep_assert_held(&mvm
->mutex
);
559 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta_id
], NULL
);
563 static int iwl_mvm_allocate_int_sta(struct iwl_mvm
*mvm
,
564 struct iwl_mvm_int_sta
*sta
,
565 u32 qmask
, enum nl80211_iftype iftype
)
567 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
568 sta
->sta_id
= iwl_mvm_find_free_sta_id(mvm
, iftype
);
569 if (WARN_ON_ONCE(sta
->sta_id
== IWL_MVM_STATION_COUNT
))
573 sta
->tfd_queue_msk
= qmask
;
575 /* put a non-NULL value so iterating over the stations won't stop */
576 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta
->sta_id
], ERR_PTR(-EINVAL
));
580 static void iwl_mvm_dealloc_int_sta(struct iwl_mvm
*mvm
,
581 struct iwl_mvm_int_sta
*sta
)
583 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta
->sta_id
], NULL
);
584 memset(sta
, 0, sizeof(struct iwl_mvm_int_sta
));
585 sta
->sta_id
= IWL_MVM_STATION_COUNT
;
588 static int iwl_mvm_add_int_sta_common(struct iwl_mvm
*mvm
,
589 struct iwl_mvm_int_sta
*sta
,
591 u16 mac_id
, u16 color
)
593 struct iwl_mvm_add_sta_cmd cmd
;
597 lockdep_assert_held(&mvm
->mutex
);
599 memset(&cmd
, 0, sizeof(cmd
));
600 cmd
.sta_id
= sta
->sta_id
;
601 cmd
.mac_id_n_color
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id
,
604 cmd
.tfd_queue_msk
= cpu_to_le32(sta
->tfd_queue_msk
);
607 memcpy(cmd
.addr
, addr
, ETH_ALEN
);
609 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(cmd
),
615 case ADD_STA_SUCCESS
:
616 IWL_DEBUG_INFO(mvm
, "Internal station added.\n");
620 IWL_ERR(mvm
, "Add internal station failed, status=0x%x\n",
627 int iwl_mvm_add_aux_sta(struct iwl_mvm
*mvm
)
631 lockdep_assert_held(&mvm
->mutex
);
633 /* Map Aux queue to fifo - needs to happen before adding Aux station */
634 iwl_mvm_enable_ac_txq(mvm
, mvm
->aux_queue
,
635 IWL_MVM_TX_FIFO_MCAST
);
637 /* Allocate aux station and assign to it the aux queue */
638 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvm
->aux_sta
, BIT(mvm
->aux_queue
),
639 NL80211_IFTYPE_UNSPECIFIED
);
643 ret
= iwl_mvm_add_int_sta_common(mvm
, &mvm
->aux_sta
, NULL
,
647 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
651 void iwl_mvm_del_aux_sta(struct iwl_mvm
*mvm
)
653 lockdep_assert_held(&mvm
->mutex
);
655 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
659 * Send the add station command for the vif's broadcast station.
660 * Assumes that the station was already allocated.
662 * @mvm: the mvm component
663 * @vif: the interface to which the broadcast station is added
664 * @bsta: the broadcast station to add.
666 int iwl_mvm_send_add_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
668 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
669 struct iwl_mvm_int_sta
*bsta
= &mvmvif
->bcast_sta
;
670 static const u8 _baddr
[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
671 const u8
*baddr
= _baddr
;
673 lockdep_assert_held(&mvm
->mutex
);
675 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
676 baddr
= vif
->bss_conf
.bssid
;
678 if (WARN_ON_ONCE(bsta
->sta_id
== IWL_MVM_STATION_COUNT
))
681 return iwl_mvm_add_int_sta_common(mvm
, bsta
, baddr
,
682 mvmvif
->id
, mvmvif
->color
);
685 /* Send the FW a request to remove the station from it's internal data
686 * structures, but DO NOT remove the entry from the local data structures. */
687 int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
689 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
692 lockdep_assert_held(&mvm
->mutex
);
694 ret
= iwl_mvm_rm_sta_common(mvm
, mvmvif
->bcast_sta
.sta_id
);
696 IWL_WARN(mvm
, "Failed sending remove station\n");
700 int iwl_mvm_alloc_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
702 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
705 lockdep_assert_held(&mvm
->mutex
);
707 qmask
= iwl_mvm_mac_get_queues_mask(vif
);
710 * The firmware defines the TFD queue mask to only be relevant
711 * for *unicast* queues, so the multicast (CAB) queue shouldn't
714 if (vif
->type
== NL80211_IFTYPE_AP
)
715 qmask
&= ~BIT(vif
->cab_queue
);
717 return iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->bcast_sta
, qmask
,
718 ieee80211_vif_type_p2p(vif
));
721 /* Allocate a new station entry for the broadcast station to the given vif,
722 * and send it to the FW.
723 * Note that each P2P mac should have its own broadcast station.
725 * @mvm: the mvm component
726 * @vif: the interface to which the broadcast station is added
727 * @bsta: the broadcast station to add. */
728 int iwl_mvm_add_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
730 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
731 struct iwl_mvm_int_sta
*bsta
= &mvmvif
->bcast_sta
;
734 lockdep_assert_held(&mvm
->mutex
);
736 ret
= iwl_mvm_alloc_bcast_sta(mvm
, vif
);
740 ret
= iwl_mvm_send_add_bcast_sta(mvm
, vif
);
743 iwl_mvm_dealloc_int_sta(mvm
, bsta
);
748 void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
750 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
752 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->bcast_sta
);
756 * Send the FW a request to remove the station from it's internal data
757 * structures, and in addition remove it from the local data structure.
759 int iwl_mvm_rm_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
763 lockdep_assert_held(&mvm
->mutex
);
765 ret
= iwl_mvm_send_rm_bcast_sta(mvm
, vif
);
767 iwl_mvm_dealloc_bcast_sta(mvm
, vif
);
772 #define IWL_MAX_RX_BA_SESSIONS 16
774 int iwl_mvm_sta_rx_agg(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
775 int tid
, u16 ssn
, bool start
)
777 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
778 struct iwl_mvm_add_sta_cmd cmd
= {};
782 lockdep_assert_held(&mvm
->mutex
);
784 if (start
&& mvm
->rx_ba_sessions
>= IWL_MAX_RX_BA_SESSIONS
) {
785 IWL_WARN(mvm
, "Not enough RX BA SESSIONS\n");
789 cmd
.mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
);
790 cmd
.sta_id
= mvm_sta
->sta_id
;
791 cmd
.add_modify
= STA_MODE_MODIFY
;
793 cmd
.add_immediate_ba_tid
= (u8
) tid
;
794 cmd
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
796 cmd
.remove_immediate_ba_tid
= (u8
) tid
;
798 cmd
.modify_mask
= start
? STA_MODIFY_ADD_BA_TID
:
799 STA_MODIFY_REMOVE_BA_TID
;
801 status
= ADD_STA_SUCCESS
;
802 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(cmd
),
808 case ADD_STA_SUCCESS
:
809 IWL_DEBUG_INFO(mvm
, "RX BA Session %sed in fw\n",
810 start
? "start" : "stopp");
812 case ADD_STA_IMMEDIATE_BA_FAILURE
:
813 IWL_WARN(mvm
, "RX BA Session refused by fw\n");
818 IWL_ERR(mvm
, "RX BA Session failed %sing, status 0x%x\n",
819 start
? "start" : "stopp", status
);
825 mvm
->rx_ba_sessions
++;
826 else if (mvm
->rx_ba_sessions
> 0)
827 /* check that restart flow didn't zero the counter */
828 mvm
->rx_ba_sessions
--;
834 static int iwl_mvm_sta_tx_agg(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
835 int tid
, u8 queue
, bool start
)
837 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
838 struct iwl_mvm_add_sta_cmd cmd
= {};
842 lockdep_assert_held(&mvm
->mutex
);
845 mvm_sta
->tfd_queue_msk
|= BIT(queue
);
846 mvm_sta
->tid_disable_agg
&= ~BIT(tid
);
848 mvm_sta
->tfd_queue_msk
&= ~BIT(queue
);
849 mvm_sta
->tid_disable_agg
|= BIT(tid
);
852 cmd
.mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
);
853 cmd
.sta_id
= mvm_sta
->sta_id
;
854 cmd
.add_modify
= STA_MODE_MODIFY
;
855 cmd
.modify_mask
= STA_MODIFY_QUEUES
| STA_MODIFY_TID_DISABLE_TX
;
856 cmd
.tfd_queue_msk
= cpu_to_le32(mvm_sta
->tfd_queue_msk
);
857 cmd
.tid_disable_tx
= cpu_to_le16(mvm_sta
->tid_disable_agg
);
859 status
= ADD_STA_SUCCESS
;
860 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(cmd
),
866 case ADD_STA_SUCCESS
:
870 IWL_ERR(mvm
, "TX BA Session failed %sing, status 0x%x\n",
871 start
? "start" : "stopp", status
);
878 const u8 tid_to_mac80211_ac
[] = {
889 static const u8 tid_to_ucode_ac
[] = {
900 int iwl_mvm_sta_tx_agg_start(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
901 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
)
903 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
904 struct iwl_mvm_tid_data
*tid_data
;
907 if (WARN_ON_ONCE(tid
>= IWL_MAX_TID_COUNT
))
910 if (mvmsta
->tid_data
[tid
].state
!= IWL_AGG_OFF
) {
911 IWL_ERR(mvm
, "Start AGG when state is not IWL_AGG_OFF %d!\n",
912 mvmsta
->tid_data
[tid
].state
);
916 lockdep_assert_held(&mvm
->mutex
);
918 for (txq_id
= mvm
->first_agg_queue
;
919 txq_id
<= mvm
->last_agg_queue
; txq_id
++)
920 if (mvm
->queue_to_mac80211
[txq_id
] ==
921 IWL_INVALID_MAC80211_QUEUE
)
924 if (txq_id
> mvm
->last_agg_queue
) {
925 IWL_ERR(mvm
, "Failed to allocate agg queue\n");
929 spin_lock_bh(&mvmsta
->lock
);
931 /* possible race condition - we entered D0i3 while starting agg */
932 if (test_bit(IWL_MVM_STATUS_IN_D0I3
, &mvm
->status
)) {
933 spin_unlock_bh(&mvmsta
->lock
);
934 IWL_ERR(mvm
, "Entered D0i3 while starting Tx agg\n");
938 /* the new tx queue is still connected to the same mac80211 queue */
939 mvm
->queue_to_mac80211
[txq_id
] = vif
->hw_queue
[tid_to_mac80211_ac
[tid
]];
941 tid_data
= &mvmsta
->tid_data
[tid
];
942 tid_data
->ssn
= IEEE80211_SEQ_TO_SN(tid_data
->seq_number
);
943 tid_data
->txq_id
= txq_id
;
944 *ssn
= tid_data
->ssn
;
946 IWL_DEBUG_TX_QUEUES(mvm
,
947 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
948 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->ssn
,
949 tid_data
->next_reclaimed
);
951 if (tid_data
->ssn
== tid_data
->next_reclaimed
) {
952 tid_data
->state
= IWL_AGG_STARTING
;
953 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
955 tid_data
->state
= IWL_EMPTYING_HW_QUEUE_ADDBA
;
958 spin_unlock_bh(&mvmsta
->lock
);
963 int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
964 struct ieee80211_sta
*sta
, u16 tid
, u8 buf_size
)
966 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
967 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
968 int queue
, fifo
, ret
;
971 BUILD_BUG_ON((sizeof(mvmsta
->agg_tids
) * BITS_PER_BYTE
)
972 != IWL_MAX_TID_COUNT
);
974 buf_size
= min_t(int, buf_size
, LINK_QUAL_AGG_FRAME_LIMIT_DEF
);
976 spin_lock_bh(&mvmsta
->lock
);
978 queue
= tid_data
->txq_id
;
979 tid_data
->state
= IWL_AGG_ON
;
980 mvmsta
->agg_tids
|= BIT(tid
);
981 tid_data
->ssn
= 0xffff;
982 spin_unlock_bh(&mvmsta
->lock
);
984 fifo
= iwl_mvm_ac_to_tx_fifo
[tid_to_mac80211_ac
[tid
]];
986 ret
= iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, queue
, true);
990 iwl_mvm_enable_agg_txq(mvm
, queue
, fifo
, mvmsta
->sta_id
, tid
,
994 * Even though in theory the peer could have different
995 * aggregation reorder buffer sizes for different sessions,
996 * our ucode doesn't allow for that and has a global limit
997 * for each station. Therefore, use the minimum of all the
998 * aggregation sessions and our default value.
1000 mvmsta
->max_agg_bufsize
=
1001 min(mvmsta
->max_agg_bufsize
, buf_size
);
1002 mvmsta
->lq_sta
.lq
.agg_frame_cnt_limit
= mvmsta
->max_agg_bufsize
;
1004 IWL_DEBUG_HT(mvm
, "Tx aggregation enabled on ra = %pM tid = %d\n",
1007 return iwl_mvm_send_lq_cmd(mvm
, &mvmsta
->lq_sta
.lq
, false);
1010 int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1011 struct ieee80211_sta
*sta
, u16 tid
)
1013 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1014 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
1020 * If mac80211 is cleaning its state, then say that we finished since
1021 * our state has been cleared anyway.
1023 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
1024 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1028 spin_lock_bh(&mvmsta
->lock
);
1030 txq_id
= tid_data
->txq_id
;
1032 IWL_DEBUG_TX_QUEUES(mvm
, "Stop AGG: sta %d tid %d q %d state %d\n",
1033 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->state
);
1035 mvmsta
->agg_tids
&= ~BIT(tid
);
1037 switch (tid_data
->state
) {
1039 tid_data
->ssn
= IEEE80211_SEQ_TO_SN(tid_data
->seq_number
);
1041 IWL_DEBUG_TX_QUEUES(mvm
,
1042 "ssn = %d, next_recl = %d\n",
1043 tid_data
->ssn
, tid_data
->next_reclaimed
);
1045 /* There are still packets for this RA / TID in the HW */
1046 if (tid_data
->ssn
!= tid_data
->next_reclaimed
) {
1047 tid_data
->state
= IWL_EMPTYING_HW_QUEUE_DELBA
;
1052 tid_data
->ssn
= 0xffff;
1053 tid_data
->state
= IWL_AGG_OFF
;
1054 mvm
->queue_to_mac80211
[txq_id
] = IWL_INVALID_MAC80211_QUEUE
;
1055 spin_unlock_bh(&mvmsta
->lock
);
1057 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1059 iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, txq_id
, false);
1061 iwl_mvm_disable_txq(mvm
, txq_id
, 0);
1063 case IWL_AGG_STARTING
:
1064 case IWL_EMPTYING_HW_QUEUE_ADDBA
:
1066 * The agg session has been stopped before it was set up. This
1067 * can happen when the AddBA timer times out for example.
1070 /* No barriers since we are under mutex */
1071 lockdep_assert_held(&mvm
->mutex
);
1072 mvm
->queue_to_mac80211
[txq_id
] = IWL_INVALID_MAC80211_QUEUE
;
1074 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1075 tid_data
->state
= IWL_AGG_OFF
;
1080 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
1081 mvmsta
->sta_id
, tid
, tid_data
->state
);
1083 "\ttid_data->txq_id = %d\n", tid_data
->txq_id
);
1087 spin_unlock_bh(&mvmsta
->lock
);
1092 int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1093 struct ieee80211_sta
*sta
, u16 tid
)
1095 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1096 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
1098 enum iwl_mvm_agg_state old_state
;
1101 * First set the agg state to OFF to avoid calling
1102 * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
1104 spin_lock_bh(&mvmsta
->lock
);
1105 txq_id
= tid_data
->txq_id
;
1106 IWL_DEBUG_TX_QUEUES(mvm
, "Flush AGG: sta %d tid %d q %d state %d\n",
1107 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->state
);
1108 old_state
= tid_data
->state
;
1109 tid_data
->state
= IWL_AGG_OFF
;
1110 mvmsta
->agg_tids
&= ~BIT(tid
);
1111 spin_unlock_bh(&mvmsta
->lock
);
1113 if (old_state
>= IWL_AGG_ON
) {
1114 if (iwl_mvm_flush_tx_path(mvm
, BIT(txq_id
), true))
1115 IWL_ERR(mvm
, "Couldn't flush the AGG queue\n");
1117 iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, txq_id
, false);
1119 iwl_mvm_disable_txq(mvm
, tid_data
->txq_id
, 0);
1122 mvm
->queue_to_mac80211
[tid_data
->txq_id
] =
1123 IWL_INVALID_MAC80211_QUEUE
;
1128 static int iwl_mvm_set_fw_key_idx(struct iwl_mvm
*mvm
)
1132 lockdep_assert_held(&mvm
->mutex
);
1134 i
= find_first_zero_bit(mvm
->fw_key_table
, STA_KEY_MAX_NUM
);
1136 if (i
== STA_KEY_MAX_NUM
)
1137 return STA_KEY_IDX_INVALID
;
1139 __set_bit(i
, mvm
->fw_key_table
);
1144 static u8
iwl_mvm_get_key_sta_id(struct ieee80211_vif
*vif
,
1145 struct ieee80211_sta
*sta
)
1147 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1150 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1152 return mvm_sta
->sta_id
;
1156 * The device expects GTKs for station interfaces to be
1157 * installed as GTKs for the AP station. If we have no
1158 * station ID, then use AP's station ID.
1160 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1161 mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
)
1162 return mvmvif
->ap_sta_id
;
1164 return IWL_MVM_STATION_COUNT
;
1167 static int iwl_mvm_send_sta_key(struct iwl_mvm
*mvm
,
1168 struct iwl_mvm_sta
*mvm_sta
,
1169 struct ieee80211_key_conf
*keyconf
, bool mcast
,
1170 u32 tkip_iv32
, u16
*tkip_p1k
, u32 cmd_flags
)
1172 struct iwl_mvm_add_sta_key_cmd cmd
= {};
1178 u8 sta_id
= mvm_sta
->sta_id
;
1180 keyidx
= (keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
) &
1181 STA_KEY_FLG_KEYID_MSK
;
1182 key_flags
= cpu_to_le16(keyidx
);
1183 key_flags
|= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP
);
1185 switch (keyconf
->cipher
) {
1186 case WLAN_CIPHER_SUITE_TKIP
:
1187 key_flags
|= cpu_to_le16(STA_KEY_FLG_TKIP
);
1188 cmd
.tkip_rx_tsc_byte2
= tkip_iv32
;
1189 for (i
= 0; i
< 5; i
++)
1190 cmd
.tkip_rx_ttak
[i
] = cpu_to_le16(tkip_p1k
[i
]);
1191 memcpy(cmd
.key
, keyconf
->key
, keyconf
->keylen
);
1193 case WLAN_CIPHER_SUITE_CCMP
:
1194 key_flags
|= cpu_to_le16(STA_KEY_FLG_CCM
);
1195 memcpy(cmd
.key
, keyconf
->key
, keyconf
->keylen
);
1197 case WLAN_CIPHER_SUITE_WEP104
:
1198 key_flags
|= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES
);
1199 case WLAN_CIPHER_SUITE_WEP40
:
1200 key_flags
|= cpu_to_le16(STA_KEY_FLG_WEP
);
1201 memcpy(cmd
.key
+ 3, keyconf
->key
, keyconf
->keylen
);
1204 key_flags
|= cpu_to_le16(STA_KEY_FLG_EXT
);
1205 memcpy(cmd
.key
, keyconf
->key
, keyconf
->keylen
);
1209 key_flags
|= cpu_to_le16(STA_KEY_MULTICAST
);
1211 cmd
.key_offset
= keyconf
->hw_key_idx
;
1212 cmd
.key_flags
= key_flags
;
1213 cmd
.sta_id
= sta_id
;
1215 status
= ADD_STA_SUCCESS
;
1216 if (cmd_flags
& CMD_ASYNC
)
1217 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA_KEY
, CMD_ASYNC
,
1220 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA_KEY
, sizeof(cmd
),
1224 case ADD_STA_SUCCESS
:
1225 IWL_DEBUG_WEP(mvm
, "MODIFY_STA: set dynamic key passed\n");
1229 IWL_ERR(mvm
, "MODIFY_STA: set dynamic key failed\n");
1236 static int iwl_mvm_send_sta_igtk(struct iwl_mvm
*mvm
,
1237 struct ieee80211_key_conf
*keyconf
,
1238 u8 sta_id
, bool remove_key
)
1240 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd
= {};
1242 /* verify the key details match the required command's expectations */
1243 if (WARN_ON((keyconf
->cipher
!= WLAN_CIPHER_SUITE_AES_CMAC
) ||
1244 (keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
) ||
1245 (keyconf
->keyidx
!= 4 && keyconf
->keyidx
!= 5)))
1248 igtk_cmd
.key_id
= cpu_to_le32(keyconf
->keyidx
);
1249 igtk_cmd
.sta_id
= cpu_to_le32(sta_id
);
1252 igtk_cmd
.ctrl_flags
|= cpu_to_le32(STA_KEY_NOT_VALID
);
1254 struct ieee80211_key_seq seq
;
1257 memcpy(igtk_cmd
.IGTK
, keyconf
->key
, keyconf
->keylen
);
1258 ieee80211_aes_cmac_calculate_k1_k2(keyconf
,
1259 igtk_cmd
.K1
, igtk_cmd
.K2
);
1260 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1261 pn
= seq
.aes_cmac
.pn
;
1262 igtk_cmd
.receive_seq_cnt
= cpu_to_le64(((u64
) pn
[5] << 0) |
1263 ((u64
) pn
[4] << 8) |
1264 ((u64
) pn
[3] << 16) |
1265 ((u64
) pn
[2] << 24) |
1266 ((u64
) pn
[1] << 32) |
1267 ((u64
) pn
[0] << 40));
1270 IWL_DEBUG_INFO(mvm
, "%s igtk for sta %u\n",
1271 remove_key
? "removing" : "installing",
1274 return iwl_mvm_send_cmd_pdu(mvm
, MGMT_MCAST_KEY
, 0,
1275 sizeof(igtk_cmd
), &igtk_cmd
);
1279 static inline u8
*iwl_mvm_get_mac_addr(struct iwl_mvm
*mvm
,
1280 struct ieee80211_vif
*vif
,
1281 struct ieee80211_sta
*sta
)
1283 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1288 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1289 mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
1290 u8 sta_id
= mvmvif
->ap_sta_id
;
1291 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1292 lockdep_is_held(&mvm
->mutex
));
1300 static int __iwl_mvm_set_sta_key(struct iwl_mvm
*mvm
,
1301 struct ieee80211_vif
*vif
,
1302 struct ieee80211_sta
*sta
,
1303 struct ieee80211_key_conf
*keyconf
,
1306 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1309 struct ieee80211_key_seq seq
;
1312 switch (keyconf
->cipher
) {
1313 case WLAN_CIPHER_SUITE_TKIP
:
1314 addr
= iwl_mvm_get_mac_addr(mvm
, vif
, sta
);
1315 /* get phase 1 key from mac80211 */
1316 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1317 ieee80211_get_tkip_rx_p1k(keyconf
, addr
, seq
.tkip
.iv32
, p1k
);
1318 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
1319 seq
.tkip
.iv32
, p1k
, 0);
1321 case WLAN_CIPHER_SUITE_CCMP
:
1322 case WLAN_CIPHER_SUITE_WEP40
:
1323 case WLAN_CIPHER_SUITE_WEP104
:
1324 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
1328 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
1335 static int __iwl_mvm_remove_sta_key(struct iwl_mvm
*mvm
, u8 sta_id
,
1336 struct ieee80211_key_conf
*keyconf
,
1339 struct iwl_mvm_add_sta_key_cmd cmd
= {};
1344 key_flags
= cpu_to_le16((keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
) &
1345 STA_KEY_FLG_KEYID_MSK
);
1346 key_flags
|= cpu_to_le16(STA_KEY_FLG_NO_ENC
| STA_KEY_FLG_WEP_KEY_MAP
);
1347 key_flags
|= cpu_to_le16(STA_KEY_NOT_VALID
);
1350 key_flags
|= cpu_to_le16(STA_KEY_MULTICAST
);
1352 cmd
.key_flags
= key_flags
;
1353 cmd
.key_offset
= keyconf
->hw_key_idx
;
1354 cmd
.sta_id
= sta_id
;
1356 status
= ADD_STA_SUCCESS
;
1357 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA_KEY
, sizeof(cmd
),
1361 case ADD_STA_SUCCESS
:
1362 IWL_DEBUG_WEP(mvm
, "MODIFY_STA: remove sta key passed\n");
1366 IWL_ERR(mvm
, "MODIFY_STA: remove sta key failed\n");
1373 int iwl_mvm_set_sta_key(struct iwl_mvm
*mvm
,
1374 struct ieee80211_vif
*vif
,
1375 struct ieee80211_sta
*sta
,
1376 struct ieee80211_key_conf
*keyconf
,
1377 bool have_key_offset
)
1379 bool mcast
= !(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
1383 lockdep_assert_held(&mvm
->mutex
);
1385 /* Get the station id from the mvm local station table */
1386 sta_id
= iwl_mvm_get_key_sta_id(vif
, sta
);
1387 if (sta_id
== IWL_MVM_STATION_COUNT
) {
1388 IWL_ERR(mvm
, "Failed to find station id\n");
1392 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
) {
1393 ret
= iwl_mvm_send_sta_igtk(mvm
, keyconf
, sta_id
, false);
1398 * It is possible that the 'sta' parameter is NULL, and thus
1399 * there is a need to retrieve the sta from the local station table.
1402 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1403 lockdep_is_held(&mvm
->mutex
));
1404 if (IS_ERR_OR_NULL(sta
)) {
1405 IWL_ERR(mvm
, "Invalid station id\n");
1410 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta
)->vif
!= vif
))
1413 if (!have_key_offset
) {
1415 * The D3 firmware hardcodes the PTK offset to 0, so we have to
1416 * configure it there. As a result, this workaround exists to
1417 * let the caller set the key offset (hw_key_idx), see d3.c.
1419 keyconf
->hw_key_idx
= iwl_mvm_set_fw_key_idx(mvm
);
1420 if (keyconf
->hw_key_idx
== STA_KEY_IDX_INVALID
)
1424 ret
= __iwl_mvm_set_sta_key(mvm
, vif
, sta
, keyconf
, mcast
);
1426 __clear_bit(keyconf
->hw_key_idx
, mvm
->fw_key_table
);
1431 * For WEP, the same key is used for multicast and unicast. Upload it
1432 * again, using the same key offset, and now pointing the other one
1433 * to the same key slot (offset).
1434 * If this fails, remove the original as well.
1436 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
1437 keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP104
) {
1438 ret
= __iwl_mvm_set_sta_key(mvm
, vif
, sta
, keyconf
, !mcast
);
1440 __clear_bit(keyconf
->hw_key_idx
, mvm
->fw_key_table
);
1441 __iwl_mvm_remove_sta_key(mvm
, sta_id
, keyconf
, mcast
);
1446 IWL_DEBUG_WEP(mvm
, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
1447 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
1452 int iwl_mvm_remove_sta_key(struct iwl_mvm
*mvm
,
1453 struct ieee80211_vif
*vif
,
1454 struct ieee80211_sta
*sta
,
1455 struct ieee80211_key_conf
*keyconf
)
1457 bool mcast
= !(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
1461 lockdep_assert_held(&mvm
->mutex
);
1463 /* Get the station id from the mvm local station table */
1464 sta_id
= iwl_mvm_get_key_sta_id(vif
, sta
);
1466 IWL_DEBUG_WEP(mvm
, "mvm remove dynamic key: idx=%d sta=%d\n",
1467 keyconf
->keyidx
, sta_id
);
1469 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
)
1470 return iwl_mvm_send_sta_igtk(mvm
, keyconf
, sta_id
, true);
1472 if (!__test_and_clear_bit(keyconf
->hw_key_idx
, mvm
->fw_key_table
)) {
1473 IWL_ERR(mvm
, "offset %d not used in fw key table.\n",
1474 keyconf
->hw_key_idx
);
1478 if (sta_id
== IWL_MVM_STATION_COUNT
) {
1479 IWL_DEBUG_WEP(mvm
, "station non-existent, early return.\n");
1484 * It is possible that the 'sta' parameter is NULL, and thus
1485 * there is a need to retrieve the sta from the local station table,
1486 * for example when a GTK is removed (where the sta_id will then be
1487 * the AP ID, and no station was passed by mac80211.)
1490 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1491 lockdep_is_held(&mvm
->mutex
));
1493 IWL_ERR(mvm
, "Invalid station id\n");
1498 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta
)->vif
!= vif
))
1501 ret
= __iwl_mvm_remove_sta_key(mvm
, sta_id
, keyconf
, mcast
);
1505 /* delete WEP key twice to get rid of (now useless) offset */
1506 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP40
||
1507 keyconf
->cipher
== WLAN_CIPHER_SUITE_WEP104
)
1508 ret
= __iwl_mvm_remove_sta_key(mvm
, sta_id
, keyconf
, !mcast
);
1513 void iwl_mvm_update_tkip_key(struct iwl_mvm
*mvm
,
1514 struct ieee80211_vif
*vif
,
1515 struct ieee80211_key_conf
*keyconf
,
1516 struct ieee80211_sta
*sta
, u32 iv32
,
1519 struct iwl_mvm_sta
*mvm_sta
;
1520 u8 sta_id
= iwl_mvm_get_key_sta_id(vif
, sta
);
1521 bool mcast
= !(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
);
1523 if (WARN_ON_ONCE(sta_id
== IWL_MVM_STATION_COUNT
))
1529 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
1530 if (WARN_ON(IS_ERR_OR_NULL(sta
))) {
1536 mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1537 iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, mcast
,
1538 iv32
, phase1key
, CMD_ASYNC
);
1542 void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm
*mvm
,
1543 struct ieee80211_sta
*sta
)
1545 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1546 struct iwl_mvm_add_sta_cmd cmd
= {
1547 .add_modify
= STA_MODE_MODIFY
,
1548 .sta_id
= mvmsta
->sta_id
,
1549 .station_flags_msk
= cpu_to_le32(STA_FLG_PS
),
1550 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
1554 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, CMD_ASYNC
, sizeof(cmd
), &cmd
);
1556 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
1559 void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm
*mvm
,
1560 struct ieee80211_sta
*sta
,
1561 enum ieee80211_frame_release_type reason
,
1562 u16 cnt
, u16 tids
, bool more_data
,
1565 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1566 struct iwl_mvm_add_sta_cmd cmd
= {
1567 .add_modify
= STA_MODE_MODIFY
,
1568 .sta_id
= mvmsta
->sta_id
,
1569 .modify_mask
= STA_MODIFY_SLEEPING_STA_TX_COUNT
,
1570 .sleep_tx_count
= cpu_to_le16(cnt
),
1571 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
1574 unsigned long _tids
= tids
;
1576 /* convert TIDs to ACs - we don't support TSPEC so that's OK
1577 * Note that this field is reserved and unused by firmware not
1578 * supporting GO uAPSD, so it's safe to always do this.
1580 for_each_set_bit(tid
, &_tids
, IWL_MAX_TID_COUNT
)
1581 cmd
.awake_acs
|= BIT(tid_to_ucode_ac
[tid
]);
1583 /* If we're releasing frames from aggregation queues then check if the
1584 * all queues combined that we're releasing frames from have
1585 * - more frames than the service period, in which case more_data
1587 * - fewer than 'cnt' frames, in which case we need to adjust the
1588 * firmware command (but do that unconditionally)
1591 int remaining
= cnt
;
1593 spin_lock_bh(&mvmsta
->lock
);
1594 for_each_set_bit(tid
, &_tids
, IWL_MAX_TID_COUNT
) {
1595 struct iwl_mvm_tid_data
*tid_data
;
1598 tid_data
= &mvmsta
->tid_data
[tid
];
1599 if (WARN(tid_data
->state
!= IWL_AGG_ON
&&
1600 tid_data
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
,
1601 "TID %d state is %d\n",
1602 tid
, tid_data
->state
)) {
1603 spin_unlock_bh(&mvmsta
->lock
);
1604 ieee80211_sta_eosp(sta
);
1608 n_queued
= iwl_mvm_tid_queued(tid_data
);
1609 if (n_queued
> remaining
) {
1614 remaining
-= n_queued
;
1616 spin_unlock_bh(&mvmsta
->lock
);
1618 cmd
.sleep_tx_count
= cpu_to_le16(cnt
- remaining
);
1619 if (WARN_ON(cnt
- remaining
== 0)) {
1620 ieee80211_sta_eosp(sta
);
1625 /* Note: this is ignored by firmware not supporting GO uAPSD */
1627 cmd
.sleep_state_flags
|= cpu_to_le16(STA_SLEEP_STATE_MOREDATA
);
1629 if (reason
== IEEE80211_FRAME_RELEASE_PSPOLL
) {
1630 mvmsta
->next_status_eosp
= true;
1631 cmd
.sleep_state_flags
|= cpu_to_le16(STA_SLEEP_STATE_PS_POLL
);
1633 cmd
.sleep_state_flags
|= cpu_to_le16(STA_SLEEP_STATE_UAPSD
);
1636 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, CMD_ASYNC
, sizeof(cmd
), &cmd
);
1638 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
1641 int iwl_mvm_rx_eosp_notif(struct iwl_mvm
*mvm
,
1642 struct iwl_rx_cmd_buffer
*rxb
,
1643 struct iwl_device_cmd
*cmd
)
1645 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1646 struct iwl_mvm_eosp_notification
*notif
= (void *)pkt
->data
;
1647 struct ieee80211_sta
*sta
;
1648 u32 sta_id
= le32_to_cpu(notif
->sta_id
);
1650 if (WARN_ON_ONCE(sta_id
>= IWL_MVM_STATION_COUNT
))
1654 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
1655 if (!IS_ERR_OR_NULL(sta
))
1656 ieee80211_sta_eosp(sta
);
1662 void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm
*mvm
,
1663 struct iwl_mvm_sta
*mvmsta
, bool disable
)
1665 struct iwl_mvm_add_sta_cmd cmd
= {
1666 .add_modify
= STA_MODE_MODIFY
,
1667 .sta_id
= mvmsta
->sta_id
,
1668 .station_flags
= disable
? cpu_to_le32(STA_FLG_DISABLE_TX
) : 0,
1669 .station_flags_msk
= cpu_to_le32(STA_FLG_DISABLE_TX
),
1670 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
1674 if (!(mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_DISABLE_STA_TX
))
1677 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, CMD_ASYNC
, sizeof(cmd
), &cmd
);
1679 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
1682 void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm
*mvm
,
1683 struct ieee80211_sta
*sta
,
1686 struct iwl_mvm_sta
*mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1688 spin_lock_bh(&mvm_sta
->lock
);
1690 if (mvm_sta
->disable_tx
== disable
) {
1691 spin_unlock_bh(&mvm_sta
->lock
);
1695 mvm_sta
->disable_tx
= disable
;
1698 * Tell mac80211 to start/stop queueing tx for this station,
1699 * but don't stop queueing if there are still pending frames
1702 if (disable
|| !atomic_read(&mvm
->pending_frames
[mvm_sta
->sta_id
]))
1703 ieee80211_sta_block_awake(mvm
->hw
, sta
, disable
);
1705 iwl_mvm_sta_modify_disable_tx(mvm
, mvm_sta
, disable
);
1707 spin_unlock_bh(&mvm_sta
->lock
);
1710 void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm
*mvm
,
1711 struct iwl_mvm_vif
*mvmvif
,
1714 struct ieee80211_sta
*sta
;
1715 struct iwl_mvm_sta
*mvm_sta
;
1718 lockdep_assert_held(&mvm
->mutex
);
1720 /* Block/unblock all the stations of the given mvmvif */
1721 for (i
= 0; i
< IWL_MVM_STATION_COUNT
; i
++) {
1722 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[i
],
1723 lockdep_is_held(&mvm
->mutex
));
1724 if (IS_ERR_OR_NULL(sta
))
1727 mvm_sta
= iwl_mvm_sta_from_mac80211(sta
);
1728 if (mvm_sta
->mac_id_n_color
!=
1729 FW_CMD_ID_AND_COLOR(mvmvif
->id
, mvmvif
->color
))
1732 iwl_mvm_sta_modify_disable_tx_ap(mvm
, sta
, disable
);
1736 void iwl_mvm_csa_client_absent(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
1738 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1739 struct iwl_mvm_sta
*mvmsta
;
1743 mvmsta
= iwl_mvm_sta_from_staid_rcu(mvm
, mvmvif
->ap_sta_id
);
1745 if (!WARN_ON(!mvmsta
))
1746 iwl_mvm_sta_modify_disable_tx(mvm
, mvmsta
, true);