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.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 *****************************************************************************/
63 #include <net/mac80211.h>
69 static int iwl_mvm_find_free_sta_id(struct iwl_mvm
*mvm
,
70 enum nl80211_iftype iftype
)
75 BUILD_BUG_ON(IWL_MVM_STATION_COUNT
> 32);
76 WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
));
78 lockdep_assert_held(&mvm
->mutex
);
80 /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */
81 if (iftype
!= NL80211_IFTYPE_STATION
)
82 reserved_ids
= BIT(0);
84 /* Don't take rcu_read_lock() since we are protected by mvm->mutex */
85 for (sta_id
= 0; sta_id
< IWL_MVM_STATION_COUNT
; sta_id
++) {
86 if (BIT(sta_id
) & reserved_ids
)
89 if (!rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
90 lockdep_is_held(&mvm
->mutex
)))
93 return IWL_MVM_STATION_COUNT
;
96 /* send station add/update command to firmware */
97 int iwl_mvm_sta_send_to_fw(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
100 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
101 struct iwl_mvm_add_sta_cmd add_sta_cmd
;
104 u32 agg_size
= 0, mpdu_dens
= 0;
106 memset(&add_sta_cmd
, 0, sizeof(add_sta_cmd
));
108 add_sta_cmd
.sta_id
= mvm_sta
->sta_id
;
109 add_sta_cmd
.mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
);
111 add_sta_cmd
.tfd_queue_msk
= cpu_to_le32(mvm_sta
->tfd_queue_msk
);
112 memcpy(&add_sta_cmd
.addr
, sta
->addr
, ETH_ALEN
);
114 add_sta_cmd
.add_modify
= update
? 1 : 0;
116 add_sta_cmd
.station_flags_msk
|= cpu_to_le32(STA_FLG_FAT_EN_MSK
|
117 STA_FLG_MIMO_EN_MSK
);
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 int iwl_mvm_add_sta(struct iwl_mvm
*mvm
,
208 struct ieee80211_vif
*vif
,
209 struct ieee80211_sta
*sta
)
211 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
212 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
215 lockdep_assert_held(&mvm
->mutex
);
217 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
218 sta_id
= iwl_mvm_find_free_sta_id(mvm
,
219 ieee80211_vif_type_p2p(vif
));
221 sta_id
= mvm_sta
->sta_id
;
223 if (WARN_ON_ONCE(sta_id
== IWL_MVM_STATION_COUNT
))
226 spin_lock_init(&mvm_sta
->lock
);
228 mvm_sta
->sta_id
= sta_id
;
229 mvm_sta
->mac_id_n_color
= FW_CMD_ID_AND_COLOR(mvmvif
->id
,
232 mvm_sta
->max_agg_bufsize
= LINK_QUAL_AGG_FRAME_LIMIT_DEF
;
233 mvm_sta
->tx_protection
= 0;
234 mvm_sta
->tt_tx_protection
= false;
236 /* HW restart, don't assume the memory has been zeroed */
237 atomic_set(&mvm
->pending_frames
[sta_id
], 0);
238 mvm_sta
->tid_disable_agg
= 0;
239 mvm_sta
->tfd_queue_msk
= 0;
240 for (i
= 0; i
< IEEE80211_NUM_ACS
; i
++)
241 if (vif
->hw_queue
[i
] != IEEE80211_INVAL_HW_QUEUE
)
242 mvm_sta
->tfd_queue_msk
|= BIT(vif
->hw_queue
[i
]);
244 /* for HW restart - reset everything but the sequence number */
245 for (i
= 0; i
< IWL_MAX_TID_COUNT
; i
++) {
246 u16 seq
= mvm_sta
->tid_data
[i
].seq_number
;
247 memset(&mvm_sta
->tid_data
[i
], 0, sizeof(mvm_sta
->tid_data
[i
]));
248 mvm_sta
->tid_data
[i
].seq_number
= seq
;
251 ret
= iwl_mvm_sta_send_to_fw(mvm
, sta
, false);
255 /* The first station added is the AP, the others are TDLS STAs */
256 if (vif
->type
== NL80211_IFTYPE_STATION
&&
257 mvmvif
->ap_sta_id
== IWL_MVM_STATION_COUNT
)
258 mvmvif
->ap_sta_id
= sta_id
;
260 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta_id
], sta
);
265 int iwl_mvm_update_sta(struct iwl_mvm
*mvm
,
266 struct ieee80211_vif
*vif
,
267 struct ieee80211_sta
*sta
)
269 return iwl_mvm_sta_send_to_fw(mvm
, sta
, true);
272 int iwl_mvm_drain_sta(struct iwl_mvm
*mvm
, struct iwl_mvm_sta
*mvmsta
,
275 struct iwl_mvm_add_sta_cmd cmd
= {};
279 lockdep_assert_held(&mvm
->mutex
);
281 cmd
.mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
);
282 cmd
.sta_id
= mvmsta
->sta_id
;
283 cmd
.add_modify
= STA_MODE_MODIFY
;
284 cmd
.station_flags
= drain
? cpu_to_le32(STA_FLG_DRAIN_FLOW
) : 0;
285 cmd
.station_flags_msk
= cpu_to_le32(STA_FLG_DRAIN_FLOW
);
287 status
= ADD_STA_SUCCESS
;
288 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(cmd
),
294 case ADD_STA_SUCCESS
:
295 IWL_DEBUG_INFO(mvm
, "Frames for staid %d will drained in fw\n",
300 IWL_ERR(mvm
, "Couldn't drain frames for staid %d\n",
309 * Remove a station from the FW table. Before sending the command to remove
310 * the station validate that the station is indeed known to the driver (sanity
313 static int iwl_mvm_rm_sta_common(struct iwl_mvm
*mvm
, u8 sta_id
)
315 struct ieee80211_sta
*sta
;
316 struct iwl_mvm_rm_sta_cmd rm_sta_cmd
= {
321 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
322 lockdep_is_held(&mvm
->mutex
));
324 /* Note: internal stations are marked as error values */
326 IWL_ERR(mvm
, "Invalid station id\n");
330 ret
= iwl_mvm_send_cmd_pdu(mvm
, REMOVE_STA
, CMD_SYNC
,
331 sizeof(rm_sta_cmd
), &rm_sta_cmd
);
333 IWL_ERR(mvm
, "Failed to remove station. Id=%d\n", sta_id
);
340 void iwl_mvm_sta_drained_wk(struct work_struct
*wk
)
342 struct iwl_mvm
*mvm
= container_of(wk
, struct iwl_mvm
, sta_drained_wk
);
346 * The mutex is needed because of the SYNC cmd, but not only: if the
347 * work would run concurrently with iwl_mvm_rm_sta, it would run before
348 * iwl_mvm_rm_sta sets the station as busy, and exit. Then
349 * iwl_mvm_rm_sta would set the station as busy, and nobody will clean
352 mutex_lock(&mvm
->mutex
);
354 for_each_set_bit(sta_id
, mvm
->sta_drained
, IWL_MVM_STATION_COUNT
) {
356 struct ieee80211_sta
*sta
=
357 rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
358 lockdep_is_held(&mvm
->mutex
));
361 * This station is in use or RCU-removed; the latter happens in
362 * managed mode, where mac80211 removes the station before we
363 * can remove it from firmware (we can only do that after the
364 * MAC is marked unassociated), and possibly while the deauth
365 * frame to disconnect from the AP is still queued. Then, the
366 * station pointer is -ENOENT when the last skb is reclaimed.
368 if (!IS_ERR(sta
) || PTR_ERR(sta
) == -ENOENT
)
371 if (PTR_ERR(sta
) == -EINVAL
) {
372 IWL_ERR(mvm
, "Drained sta %d, but it is internal?\n",
378 IWL_ERR(mvm
, "Drained sta %d, but it was NULL?\n",
383 WARN_ON(PTR_ERR(sta
) != -EBUSY
);
384 /* This station was removed and we waited until it got drained,
385 * we can now proceed and remove it.
387 ret
= iwl_mvm_rm_sta_common(mvm
, sta_id
);
390 "Couldn't remove sta %d after it was drained\n",
394 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta_id
], NULL
);
395 clear_bit(sta_id
, mvm
->sta_drained
);
398 mutex_unlock(&mvm
->mutex
);
401 int iwl_mvm_rm_sta(struct iwl_mvm
*mvm
,
402 struct ieee80211_vif
*vif
,
403 struct ieee80211_sta
*sta
)
405 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
406 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
409 lockdep_assert_held(&mvm
->mutex
);
411 if (vif
->type
== NL80211_IFTYPE_STATION
&&
412 mvmvif
->ap_sta_id
== mvm_sta
->sta_id
) {
413 /* flush its queues here since we are freeing mvm_sta */
414 ret
= iwl_mvm_flush_tx_path(mvm
, mvm_sta
->tfd_queue_msk
, true);
416 /* if we are associated - we can't remove the AP STA now */
417 if (vif
->bss_conf
.assoc
)
420 /* unassoc - go ahead - remove the AP STA now */
421 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
423 /* clear d0i3_ap_sta_id if no longer relevant */
424 if (mvm
->d0i3_ap_sta_id
== mvm_sta
->sta_id
)
425 mvm
->d0i3_ap_sta_id
= IWL_MVM_STATION_COUNT
;
429 * Make sure that the tx response code sees the station as -EBUSY and
430 * calls the drain worker.
432 spin_lock_bh(&mvm_sta
->lock
);
434 * There are frames pending on the AC queues for this station.
435 * We need to wait until all the frames are drained...
437 if (atomic_read(&mvm
->pending_frames
[mvm_sta
->sta_id
])) {
438 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
],
440 spin_unlock_bh(&mvm_sta
->lock
);
441 ret
= iwl_mvm_drain_sta(mvm
, mvm_sta
, true);
443 spin_unlock_bh(&mvm_sta
->lock
);
444 ret
= iwl_mvm_rm_sta_common(mvm
, mvm_sta
->sta_id
);
445 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
], NULL
);
451 int iwl_mvm_rm_sta_id(struct iwl_mvm
*mvm
,
452 struct ieee80211_vif
*vif
,
455 int ret
= iwl_mvm_rm_sta_common(mvm
, sta_id
);
457 lockdep_assert_held(&mvm
->mutex
);
459 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta_id
], NULL
);
463 int iwl_mvm_allocate_int_sta(struct iwl_mvm
*mvm
, struct iwl_mvm_int_sta
*sta
,
464 u32 qmask
, enum nl80211_iftype iftype
)
466 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
467 sta
->sta_id
= iwl_mvm_find_free_sta_id(mvm
, iftype
);
468 if (WARN_ON_ONCE(sta
->sta_id
== IWL_MVM_STATION_COUNT
))
472 sta
->tfd_queue_msk
= qmask
;
474 /* put a non-NULL value so iterating over the stations won't stop */
475 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[sta
->sta_id
], ERR_PTR(-EINVAL
));
479 void iwl_mvm_dealloc_int_sta(struct iwl_mvm
*mvm
, struct iwl_mvm_int_sta
*sta
)
481 RCU_INIT_POINTER(mvm
->fw_id_to_mac_id
[sta
->sta_id
], NULL
);
482 memset(sta
, 0, sizeof(struct iwl_mvm_int_sta
));
483 sta
->sta_id
= IWL_MVM_STATION_COUNT
;
486 static int iwl_mvm_add_int_sta_common(struct iwl_mvm
*mvm
,
487 struct iwl_mvm_int_sta
*sta
,
489 u16 mac_id
, u16 color
)
491 struct iwl_mvm_add_sta_cmd cmd
;
495 lockdep_assert_held(&mvm
->mutex
);
497 memset(&cmd
, 0, sizeof(cmd
));
498 cmd
.sta_id
= sta
->sta_id
;
499 cmd
.mac_id_n_color
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id
,
502 cmd
.tfd_queue_msk
= cpu_to_le32(sta
->tfd_queue_msk
);
505 memcpy(cmd
.addr
, addr
, ETH_ALEN
);
507 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(cmd
),
513 case ADD_STA_SUCCESS
:
514 IWL_DEBUG_INFO(mvm
, "Internal station added.\n");
518 IWL_ERR(mvm
, "Add internal station failed, status=0x%x\n",
525 int iwl_mvm_add_aux_sta(struct iwl_mvm
*mvm
)
529 lockdep_assert_held(&mvm
->mutex
);
531 /* Add the aux station, but without any queues */
532 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvm
->aux_sta
, 0,
533 NL80211_IFTYPE_UNSPECIFIED
);
537 ret
= iwl_mvm_add_int_sta_common(mvm
, &mvm
->aux_sta
, NULL
,
541 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
546 * Send the add station command for the vif's broadcast station.
547 * Assumes that the station was already allocated.
549 * @mvm: the mvm component
550 * @vif: the interface to which the broadcast station is added
551 * @bsta: the broadcast station to add.
553 int iwl_mvm_send_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
554 struct iwl_mvm_int_sta
*bsta
)
556 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
557 static const u8 _baddr
[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
558 const u8
*baddr
= _baddr
;
560 lockdep_assert_held(&mvm
->mutex
);
562 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
563 baddr
= vif
->bss_conf
.bssid
;
565 if (WARN_ON_ONCE(bsta
->sta_id
== IWL_MVM_STATION_COUNT
))
568 return iwl_mvm_add_int_sta_common(mvm
, bsta
, baddr
,
569 mvmvif
->id
, mvmvif
->color
);
572 /* Send the FW a request to remove the station from it's internal data
573 * structures, but DO NOT remove the entry from the local data structures. */
574 int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm
*mvm
,
575 struct iwl_mvm_int_sta
*bsta
)
579 lockdep_assert_held(&mvm
->mutex
);
581 ret
= iwl_mvm_rm_sta_common(mvm
, bsta
->sta_id
);
583 IWL_WARN(mvm
, "Failed sending remove station\n");
587 /* Allocate a new station entry for the broadcast station to the given vif,
588 * and send it to the FW.
589 * Note that each P2P mac should have its own broadcast station.
591 * @mvm: the mvm component
592 * @vif: the interface to which the broadcast station is added
593 * @bsta: the broadcast station to add. */
594 int iwl_mvm_add_bcast_sta(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
595 struct iwl_mvm_int_sta
*bsta
)
597 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
598 static const u8 baddr
[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
602 lockdep_assert_held(&mvm
->mutex
);
604 qmask
= iwl_mvm_mac_get_queues_mask(mvm
, vif
);
605 ret
= iwl_mvm_allocate_int_sta(mvm
, bsta
, qmask
,
606 ieee80211_vif_type_p2p(vif
));
610 ret
= iwl_mvm_add_int_sta_common(mvm
, bsta
, baddr
,
611 mvmvif
->id
, mvmvif
->color
);
614 iwl_mvm_dealloc_int_sta(mvm
, bsta
);
619 * Send the FW a request to remove the station from it's internal data
620 * structures, and in addition remove it from the local data structure.
622 int iwl_mvm_rm_bcast_sta(struct iwl_mvm
*mvm
, struct iwl_mvm_int_sta
*bsta
)
626 lockdep_assert_held(&mvm
->mutex
);
628 ret
= iwl_mvm_rm_sta_common(mvm
, bsta
->sta_id
);
632 iwl_mvm_dealloc_int_sta(mvm
, bsta
);
636 #define IWL_MAX_RX_BA_SESSIONS 16
638 int iwl_mvm_sta_rx_agg(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
639 int tid
, u16 ssn
, bool start
)
641 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
642 struct iwl_mvm_add_sta_cmd cmd
= {};
646 lockdep_assert_held(&mvm
->mutex
);
648 if (start
&& mvm
->rx_ba_sessions
>= IWL_MAX_RX_BA_SESSIONS
) {
649 IWL_WARN(mvm
, "Not enough RX BA SESSIONS\n");
653 cmd
.mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
);
654 cmd
.sta_id
= mvm_sta
->sta_id
;
655 cmd
.add_modify
= STA_MODE_MODIFY
;
657 cmd
.add_immediate_ba_tid
= (u8
) tid
;
658 cmd
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
660 cmd
.remove_immediate_ba_tid
= (u8
) tid
;
662 cmd
.modify_mask
= start
? STA_MODIFY_ADD_BA_TID
:
663 STA_MODIFY_REMOVE_BA_TID
;
665 status
= ADD_STA_SUCCESS
;
666 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(cmd
),
672 case ADD_STA_SUCCESS
:
673 IWL_DEBUG_INFO(mvm
, "RX BA Session %sed in fw\n",
674 start
? "start" : "stopp");
676 case ADD_STA_IMMEDIATE_BA_FAILURE
:
677 IWL_WARN(mvm
, "RX BA Session refused by fw\n");
682 IWL_ERR(mvm
, "RX BA Session failed %sing, status 0x%x\n",
683 start
? "start" : "stopp", status
);
689 mvm
->rx_ba_sessions
++;
690 else if (mvm
->rx_ba_sessions
> 0)
691 /* check that restart flow didn't zero the counter */
692 mvm
->rx_ba_sessions
--;
698 static int iwl_mvm_sta_tx_agg(struct iwl_mvm
*mvm
, struct ieee80211_sta
*sta
,
699 int tid
, u8 queue
, bool start
)
701 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
702 struct iwl_mvm_add_sta_cmd cmd
= {};
706 lockdep_assert_held(&mvm
->mutex
);
709 mvm_sta
->tfd_queue_msk
|= BIT(queue
);
710 mvm_sta
->tid_disable_agg
&= ~BIT(tid
);
712 mvm_sta
->tfd_queue_msk
&= ~BIT(queue
);
713 mvm_sta
->tid_disable_agg
|= BIT(tid
);
716 cmd
.mac_id_n_color
= cpu_to_le32(mvm_sta
->mac_id_n_color
);
717 cmd
.sta_id
= mvm_sta
->sta_id
;
718 cmd
.add_modify
= STA_MODE_MODIFY
;
719 cmd
.modify_mask
= STA_MODIFY_QUEUES
| STA_MODIFY_TID_DISABLE_TX
;
720 cmd
.tfd_queue_msk
= cpu_to_le32(mvm_sta
->tfd_queue_msk
);
721 cmd
.tid_disable_tx
= cpu_to_le16(mvm_sta
->tid_disable_agg
);
723 status
= ADD_STA_SUCCESS
;
724 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA
, sizeof(cmd
),
730 case ADD_STA_SUCCESS
:
734 IWL_ERR(mvm
, "TX BA Session failed %sing, status 0x%x\n",
735 start
? "start" : "stopp", status
);
742 const u8 tid_to_mac80211_ac
[] = {
753 static const u8 tid_to_ucode_ac
[] = {
764 int iwl_mvm_sta_tx_agg_start(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
765 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
)
767 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
768 struct iwl_mvm_tid_data
*tid_data
;
771 if (WARN_ON_ONCE(tid
>= IWL_MAX_TID_COUNT
))
774 if (mvmsta
->tid_data
[tid
].state
!= IWL_AGG_OFF
) {
775 IWL_ERR(mvm
, "Start AGG when state is not IWL_AGG_OFF %d!\n",
776 mvmsta
->tid_data
[tid
].state
);
780 lockdep_assert_held(&mvm
->mutex
);
782 for (txq_id
= mvm
->first_agg_queue
;
783 txq_id
<= mvm
->last_agg_queue
; txq_id
++)
784 if (mvm
->queue_to_mac80211
[txq_id
] ==
785 IWL_INVALID_MAC80211_QUEUE
)
788 if (txq_id
> mvm
->last_agg_queue
) {
789 IWL_ERR(mvm
, "Failed to allocate agg queue\n");
793 spin_lock_bh(&mvmsta
->lock
);
795 /* possible race condition - we entered D0i3 while starting agg */
796 if (test_bit(IWL_MVM_STATUS_IN_D0I3
, &mvm
->status
)) {
797 spin_unlock_bh(&mvmsta
->lock
);
798 IWL_ERR(mvm
, "Entered D0i3 while starting Tx agg\n");
802 /* the new tx queue is still connected to the same mac80211 queue */
803 mvm
->queue_to_mac80211
[txq_id
] = vif
->hw_queue
[tid_to_mac80211_ac
[tid
]];
805 tid_data
= &mvmsta
->tid_data
[tid
];
806 tid_data
->ssn
= IEEE80211_SEQ_TO_SN(tid_data
->seq_number
);
807 tid_data
->txq_id
= txq_id
;
808 *ssn
= tid_data
->ssn
;
810 IWL_DEBUG_TX_QUEUES(mvm
,
811 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
812 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->ssn
,
813 tid_data
->next_reclaimed
);
815 if (tid_data
->ssn
== tid_data
->next_reclaimed
) {
816 tid_data
->state
= IWL_AGG_STARTING
;
817 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
819 tid_data
->state
= IWL_EMPTYING_HW_QUEUE_ADDBA
;
822 spin_unlock_bh(&mvmsta
->lock
);
827 int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
828 struct ieee80211_sta
*sta
, u16 tid
, u8 buf_size
)
830 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
831 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
832 int queue
, fifo
, ret
;
835 buf_size
= min_t(int, buf_size
, LINK_QUAL_AGG_FRAME_LIMIT_DEF
);
837 spin_lock_bh(&mvmsta
->lock
);
839 queue
= tid_data
->txq_id
;
840 tid_data
->state
= IWL_AGG_ON
;
841 tid_data
->ssn
= 0xffff;
842 spin_unlock_bh(&mvmsta
->lock
);
844 fifo
= iwl_mvm_ac_to_tx_fifo
[tid_to_mac80211_ac
[tid
]];
846 ret
= iwl_mvm_sta_tx_agg(mvm
, sta
, tid
, queue
, true);
850 iwl_trans_txq_enable(mvm
->trans
, queue
, fifo
, mvmsta
->sta_id
, tid
,
854 * Even though in theory the peer could have different
855 * aggregation reorder buffer sizes for different sessions,
856 * our ucode doesn't allow for that and has a global limit
857 * for each station. Therefore, use the minimum of all the
858 * aggregation sessions and our default value.
860 mvmsta
->max_agg_bufsize
=
861 min(mvmsta
->max_agg_bufsize
, buf_size
);
862 mvmsta
->lq_sta
.lq
.agg_frame_cnt_limit
= mvmsta
->max_agg_bufsize
;
864 IWL_DEBUG_HT(mvm
, "Tx aggregation enabled on ra = %pM tid = %d\n",
867 return iwl_mvm_send_lq_cmd(mvm
, &mvmsta
->lq_sta
.lq
, false);
870 int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
871 struct ieee80211_sta
*sta
, u16 tid
)
873 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
874 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
880 * If mac80211 is cleaning its state, then say that we finished since
881 * our state has been cleared anyway.
883 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
884 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
888 spin_lock_bh(&mvmsta
->lock
);
890 txq_id
= tid_data
->txq_id
;
892 IWL_DEBUG_TX_QUEUES(mvm
, "Stop AGG: sta %d tid %d q %d state %d\n",
893 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->state
);
895 switch (tid_data
->state
) {
897 tid_data
->ssn
= IEEE80211_SEQ_TO_SN(tid_data
->seq_number
);
899 IWL_DEBUG_TX_QUEUES(mvm
,
900 "ssn = %d, next_recl = %d\n",
901 tid_data
->ssn
, tid_data
->next_reclaimed
);
903 /* There are still packets for this RA / TID in the HW */
904 if (tid_data
->ssn
!= tid_data
->next_reclaimed
) {
905 tid_data
->state
= IWL_EMPTYING_HW_QUEUE_DELBA
;
910 tid_data
->ssn
= 0xffff;
911 iwl_trans_txq_disable(mvm
->trans
, txq_id
);
913 case IWL_AGG_STARTING
:
914 case IWL_EMPTYING_HW_QUEUE_ADDBA
:
916 * The agg session has been stopped before it was set up. This
917 * can happen when the AddBA timer times out for example.
920 /* No barriers since we are under mutex */
921 lockdep_assert_held(&mvm
->mutex
);
922 mvm
->queue_to_mac80211
[txq_id
] = IWL_INVALID_MAC80211_QUEUE
;
924 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
925 tid_data
->state
= IWL_AGG_OFF
;
930 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
931 mvmsta
->sta_id
, tid
, tid_data
->state
);
933 "\ttid_data->txq_id = %d\n", tid_data
->txq_id
);
937 spin_unlock_bh(&mvmsta
->lock
);
942 int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
943 struct ieee80211_sta
*sta
, u16 tid
)
945 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
946 struct iwl_mvm_tid_data
*tid_data
= &mvmsta
->tid_data
[tid
];
948 enum iwl_mvm_agg_state old_state
;
951 * First set the agg state to OFF to avoid calling
952 * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
954 spin_lock_bh(&mvmsta
->lock
);
955 txq_id
= tid_data
->txq_id
;
956 IWL_DEBUG_TX_QUEUES(mvm
, "Flush AGG: sta %d tid %d q %d state %d\n",
957 mvmsta
->sta_id
, tid
, txq_id
, tid_data
->state
);
958 old_state
= tid_data
->state
;
959 tid_data
->state
= IWL_AGG_OFF
;
960 spin_unlock_bh(&mvmsta
->lock
);
962 if (old_state
>= IWL_AGG_ON
) {
963 if (iwl_mvm_flush_tx_path(mvm
, BIT(txq_id
), true))
964 IWL_ERR(mvm
, "Couldn't flush the AGG queue\n");
966 iwl_trans_txq_disable(mvm
->trans
, tid_data
->txq_id
);
969 mvm
->queue_to_mac80211
[tid_data
->txq_id
] =
970 IWL_INVALID_MAC80211_QUEUE
;
975 static int iwl_mvm_set_fw_key_idx(struct iwl_mvm
*mvm
)
979 lockdep_assert_held(&mvm
->mutex
);
981 i
= find_first_zero_bit(mvm
->fw_key_table
, STA_KEY_MAX_NUM
);
983 if (i
== STA_KEY_MAX_NUM
)
984 return STA_KEY_IDX_INVALID
;
986 __set_bit(i
, mvm
->fw_key_table
);
991 static u8
iwl_mvm_get_key_sta_id(struct ieee80211_vif
*vif
,
992 struct ieee80211_sta
*sta
)
994 struct iwl_mvm_vif
*mvmvif
= (void *)vif
->drv_priv
;
997 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
999 return mvm_sta
->sta_id
;
1003 * The device expects GTKs for station interfaces to be
1004 * installed as GTKs for the AP station. If we have no
1005 * station ID, then use AP's station ID.
1007 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1008 mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
)
1009 return mvmvif
->ap_sta_id
;
1011 return IWL_MVM_STATION_COUNT
;
1014 static int iwl_mvm_send_sta_key(struct iwl_mvm
*mvm
,
1015 struct iwl_mvm_sta
*mvm_sta
,
1016 struct ieee80211_key_conf
*keyconf
,
1017 u8 sta_id
, u32 tkip_iv32
, u16
*tkip_p1k
,
1020 struct iwl_mvm_add_sta_key_cmd cmd
= {};
1026 keyidx
= (keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
) &
1027 STA_KEY_FLG_KEYID_MSK
;
1028 key_flags
= cpu_to_le16(keyidx
);
1029 key_flags
|= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP
);
1031 switch (keyconf
->cipher
) {
1032 case WLAN_CIPHER_SUITE_TKIP
:
1033 key_flags
|= cpu_to_le16(STA_KEY_FLG_TKIP
);
1034 cmd
.tkip_rx_tsc_byte2
= tkip_iv32
;
1035 for (i
= 0; i
< 5; i
++)
1036 cmd
.tkip_rx_ttak
[i
] = cpu_to_le16(tkip_p1k
[i
]);
1037 memcpy(cmd
.key
, keyconf
->key
, keyconf
->keylen
);
1039 case WLAN_CIPHER_SUITE_CCMP
:
1040 key_flags
|= cpu_to_le16(STA_KEY_FLG_CCM
);
1041 memcpy(cmd
.key
, keyconf
->key
, keyconf
->keylen
);
1044 key_flags
|= cpu_to_le16(STA_KEY_FLG_EXT
);
1045 memcpy(cmd
.key
, keyconf
->key
, keyconf
->keylen
);
1048 if (!(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1049 key_flags
|= cpu_to_le16(STA_KEY_MULTICAST
);
1051 cmd
.key_offset
= keyconf
->hw_key_idx
;
1052 cmd
.key_flags
= key_flags
;
1053 cmd
.sta_id
= sta_id
;
1055 status
= ADD_STA_SUCCESS
;
1056 if (cmd_flags
== CMD_SYNC
)
1057 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA_KEY
, sizeof(cmd
),
1060 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA_KEY
, CMD_ASYNC
,
1064 case ADD_STA_SUCCESS
:
1065 IWL_DEBUG_WEP(mvm
, "MODIFY_STA: set dynamic key passed\n");
1069 IWL_ERR(mvm
, "MODIFY_STA: set dynamic key failed\n");
1076 static int iwl_mvm_send_sta_igtk(struct iwl_mvm
*mvm
,
1077 struct ieee80211_key_conf
*keyconf
,
1078 u8 sta_id
, bool remove_key
)
1080 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd
= {};
1082 /* verify the key details match the required command's expectations */
1083 if (WARN_ON((keyconf
->cipher
!= WLAN_CIPHER_SUITE_AES_CMAC
) ||
1084 (keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
) ||
1085 (keyconf
->keyidx
!= 4 && keyconf
->keyidx
!= 5)))
1088 igtk_cmd
.key_id
= cpu_to_le32(keyconf
->keyidx
);
1089 igtk_cmd
.sta_id
= cpu_to_le32(sta_id
);
1092 igtk_cmd
.ctrl_flags
|= cpu_to_le32(STA_KEY_NOT_VALID
);
1094 struct ieee80211_key_seq seq
;
1097 memcpy(igtk_cmd
.IGTK
, keyconf
->key
, keyconf
->keylen
);
1098 ieee80211_aes_cmac_calculate_k1_k2(keyconf
,
1099 igtk_cmd
.K1
, igtk_cmd
.K2
);
1100 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1101 pn
= seq
.aes_cmac
.pn
;
1102 igtk_cmd
.receive_seq_cnt
= cpu_to_le64(((u64
) pn
[5] << 0) |
1103 ((u64
) pn
[4] << 8) |
1104 ((u64
) pn
[3] << 16) |
1105 ((u64
) pn
[2] << 24) |
1106 ((u64
) pn
[1] << 32) |
1107 ((u64
) pn
[0] << 40));
1110 IWL_DEBUG_INFO(mvm
, "%s igtk for sta %u\n",
1111 remove_key
? "removing" : "installing",
1114 return iwl_mvm_send_cmd_pdu(mvm
, MGMT_MCAST_KEY
, CMD_SYNC
,
1115 sizeof(igtk_cmd
), &igtk_cmd
);
1119 static inline u8
*iwl_mvm_get_mac_addr(struct iwl_mvm
*mvm
,
1120 struct ieee80211_vif
*vif
,
1121 struct ieee80211_sta
*sta
)
1123 struct iwl_mvm_vif
*mvmvif
= (void *)vif
->drv_priv
;
1128 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1129 mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
1130 u8 sta_id
= mvmvif
->ap_sta_id
;
1131 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1132 lockdep_is_held(&mvm
->mutex
));
1140 int iwl_mvm_set_sta_key(struct iwl_mvm
*mvm
,
1141 struct ieee80211_vif
*vif
,
1142 struct ieee80211_sta
*sta
,
1143 struct ieee80211_key_conf
*keyconf
,
1144 bool have_key_offset
)
1146 struct iwl_mvm_sta
*mvm_sta
;
1149 struct ieee80211_key_seq seq
;
1152 lockdep_assert_held(&mvm
->mutex
);
1154 /* Get the station id from the mvm local station table */
1155 sta_id
= iwl_mvm_get_key_sta_id(vif
, sta
);
1156 if (sta_id
== IWL_MVM_STATION_COUNT
) {
1157 IWL_ERR(mvm
, "Failed to find station id\n");
1161 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
) {
1162 ret
= iwl_mvm_send_sta_igtk(mvm
, keyconf
, sta_id
, false);
1167 * It is possible that the 'sta' parameter is NULL, and thus
1168 * there is a need to retrieve the sta from the local station table.
1171 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1172 lockdep_is_held(&mvm
->mutex
));
1173 if (IS_ERR_OR_NULL(sta
)) {
1174 IWL_ERR(mvm
, "Invalid station id\n");
1179 mvm_sta
= (struct iwl_mvm_sta
*)sta
->drv_priv
;
1180 if (WARN_ON_ONCE(mvm_sta
->vif
!= vif
))
1183 if (!have_key_offset
) {
1185 * The D3 firmware hardcodes the PTK offset to 0, so we have to
1186 * configure it there. As a result, this workaround exists to
1187 * let the caller set the key offset (hw_key_idx), see d3.c.
1189 keyconf
->hw_key_idx
= iwl_mvm_set_fw_key_idx(mvm
);
1190 if (keyconf
->hw_key_idx
== STA_KEY_IDX_INVALID
)
1194 switch (keyconf
->cipher
) {
1195 case WLAN_CIPHER_SUITE_TKIP
:
1196 addr
= iwl_mvm_get_mac_addr(mvm
, vif
, sta
);
1197 /* get phase 1 key from mac80211 */
1198 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1199 ieee80211_get_tkip_rx_p1k(keyconf
, addr
, seq
.tkip
.iv32
, p1k
);
1200 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, sta_id
,
1201 seq
.tkip
.iv32
, p1k
, CMD_SYNC
);
1203 case WLAN_CIPHER_SUITE_CCMP
:
1204 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, sta_id
,
1208 ret
= iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
,
1209 sta_id
, 0, NULL
, CMD_SYNC
);
1213 __clear_bit(keyconf
->hw_key_idx
, mvm
->fw_key_table
);
1216 IWL_DEBUG_WEP(mvm
, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
1217 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
1222 int iwl_mvm_remove_sta_key(struct iwl_mvm
*mvm
,
1223 struct ieee80211_vif
*vif
,
1224 struct ieee80211_sta
*sta
,
1225 struct ieee80211_key_conf
*keyconf
)
1227 struct iwl_mvm_sta
*mvm_sta
;
1228 struct iwl_mvm_add_sta_key_cmd cmd
= {};
1233 lockdep_assert_held(&mvm
->mutex
);
1235 /* Get the station id from the mvm local station table */
1236 sta_id
= iwl_mvm_get_key_sta_id(vif
, sta
);
1238 IWL_DEBUG_WEP(mvm
, "mvm remove dynamic key: idx=%d sta=%d\n",
1239 keyconf
->keyidx
, sta_id
);
1241 if (keyconf
->cipher
== WLAN_CIPHER_SUITE_AES_CMAC
)
1242 return iwl_mvm_send_sta_igtk(mvm
, keyconf
, sta_id
, true);
1244 ret
= __test_and_clear_bit(keyconf
->hw_key_idx
, mvm
->fw_key_table
);
1246 IWL_ERR(mvm
, "offset %d not used in fw key table.\n",
1247 keyconf
->hw_key_idx
);
1251 if (sta_id
== IWL_MVM_STATION_COUNT
) {
1252 IWL_DEBUG_WEP(mvm
, "station non-existent, early return.\n");
1257 * It is possible that the 'sta' parameter is NULL, and thus
1258 * there is a need to retrieve the sta from the local station table,
1259 * for example when a GTK is removed (where the sta_id will then be
1260 * the AP ID, and no station was passed by mac80211.)
1263 sta
= rcu_dereference_protected(mvm
->fw_id_to_mac_id
[sta_id
],
1264 lockdep_is_held(&mvm
->mutex
));
1266 IWL_ERR(mvm
, "Invalid station id\n");
1271 mvm_sta
= (struct iwl_mvm_sta
*)sta
->drv_priv
;
1272 if (WARN_ON_ONCE(mvm_sta
->vif
!= vif
))
1275 key_flags
= cpu_to_le16((keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
) &
1276 STA_KEY_FLG_KEYID_MSK
);
1277 key_flags
|= cpu_to_le16(STA_KEY_FLG_NO_ENC
| STA_KEY_FLG_WEP_KEY_MAP
);
1278 key_flags
|= cpu_to_le16(STA_KEY_NOT_VALID
);
1280 if (!(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1281 key_flags
|= cpu_to_le16(STA_KEY_MULTICAST
);
1283 cmd
.key_flags
= key_flags
;
1284 cmd
.key_offset
= keyconf
->hw_key_idx
;
1285 cmd
.sta_id
= sta_id
;
1287 status
= ADD_STA_SUCCESS
;
1288 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, ADD_STA_KEY
, sizeof(cmd
),
1292 case ADD_STA_SUCCESS
:
1293 IWL_DEBUG_WEP(mvm
, "MODIFY_STA: remove sta key passed\n");
1297 IWL_ERR(mvm
, "MODIFY_STA: remove sta key failed\n");
1304 void iwl_mvm_update_tkip_key(struct iwl_mvm
*mvm
,
1305 struct ieee80211_vif
*vif
,
1306 struct ieee80211_key_conf
*keyconf
,
1307 struct ieee80211_sta
*sta
, u32 iv32
,
1310 struct iwl_mvm_sta
*mvm_sta
;
1311 u8 sta_id
= iwl_mvm_get_key_sta_id(vif
, sta
);
1313 if (WARN_ON_ONCE(sta_id
== IWL_MVM_STATION_COUNT
))
1319 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
1320 if (WARN_ON(IS_ERR_OR_NULL(sta
))) {
1326 mvm_sta
= (void *)sta
->drv_priv
;
1327 iwl_mvm_send_sta_key(mvm
, mvm_sta
, keyconf
, sta_id
,
1328 iv32
, phase1key
, CMD_ASYNC
);
1332 void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm
*mvm
,
1333 struct ieee80211_sta
*sta
)
1335 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1336 struct iwl_mvm_add_sta_cmd cmd
= {
1337 .add_modify
= STA_MODE_MODIFY
,
1338 .sta_id
= mvmsta
->sta_id
,
1339 .station_flags_msk
= cpu_to_le32(STA_FLG_PS
),
1340 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
1344 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, CMD_ASYNC
, sizeof(cmd
), &cmd
);
1346 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
1349 void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm
*mvm
,
1350 struct ieee80211_sta
*sta
,
1351 enum ieee80211_frame_release_type reason
,
1352 u16 cnt
, u16 tids
, bool more_data
,
1355 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1356 struct iwl_mvm_add_sta_cmd cmd
= {
1357 .add_modify
= STA_MODE_MODIFY
,
1358 .sta_id
= mvmsta
->sta_id
,
1359 .modify_mask
= STA_MODIFY_SLEEPING_STA_TX_COUNT
,
1360 .sleep_tx_count
= cpu_to_le16(cnt
),
1361 .mac_id_n_color
= cpu_to_le32(mvmsta
->mac_id_n_color
),
1364 unsigned long _tids
= tids
;
1366 /* convert TIDs to ACs - we don't support TSPEC so that's OK
1367 * Note that this field is reserved and unused by firmware not
1368 * supporting GO uAPSD, so it's safe to always do this.
1370 for_each_set_bit(tid
, &_tids
, IWL_MAX_TID_COUNT
)
1371 cmd
.awake_acs
|= BIT(tid_to_ucode_ac
[tid
]);
1373 /* If we're releasing frames from aggregation queues then check if the
1374 * all queues combined that we're releasing frames from have
1375 * - more frames than the service period, in which case more_data
1377 * - fewer than 'cnt' frames, in which case we need to adjust the
1378 * firmware command (but do that unconditionally)
1381 int remaining
= cnt
;
1383 spin_lock_bh(&mvmsta
->lock
);
1384 for_each_set_bit(tid
, &_tids
, IWL_MAX_TID_COUNT
) {
1385 struct iwl_mvm_tid_data
*tid_data
;
1388 tid_data
= &mvmsta
->tid_data
[tid
];
1389 if (WARN(tid_data
->state
!= IWL_AGG_ON
&&
1390 tid_data
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
,
1391 "TID %d state is %d\n",
1392 tid
, tid_data
->state
)) {
1393 spin_unlock_bh(&mvmsta
->lock
);
1394 ieee80211_sta_eosp(sta
);
1398 n_queued
= iwl_mvm_tid_queued(tid_data
);
1399 if (n_queued
> remaining
) {
1404 remaining
-= n_queued
;
1406 spin_unlock_bh(&mvmsta
->lock
);
1408 cmd
.sleep_tx_count
= cpu_to_le16(cnt
- remaining
);
1409 if (WARN_ON(cnt
- remaining
== 0)) {
1410 ieee80211_sta_eosp(sta
);
1415 /* Note: this is ignored by firmware not supporting GO uAPSD */
1417 cmd
.sleep_state_flags
|= cpu_to_le16(STA_SLEEP_STATE_MOREDATA
);
1419 if (reason
== IEEE80211_FRAME_RELEASE_PSPOLL
) {
1420 mvmsta
->next_status_eosp
= true;
1421 cmd
.sleep_state_flags
|= cpu_to_le16(STA_SLEEP_STATE_PS_POLL
);
1423 cmd
.sleep_state_flags
|= cpu_to_le16(STA_SLEEP_STATE_UAPSD
);
1426 ret
= iwl_mvm_send_cmd_pdu(mvm
, ADD_STA
, CMD_ASYNC
, sizeof(cmd
), &cmd
);
1428 IWL_ERR(mvm
, "Failed to send ADD_STA command (%d)\n", ret
);
1431 int iwl_mvm_rx_eosp_notif(struct iwl_mvm
*mvm
,
1432 struct iwl_rx_cmd_buffer
*rxb
,
1433 struct iwl_device_cmd
*cmd
)
1435 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1436 struct iwl_mvm_eosp_notification
*notif
= (void *)pkt
->data
;
1437 struct ieee80211_sta
*sta
;
1438 u32 sta_id
= le32_to_cpu(notif
->sta_id
);
1440 if (WARN_ON_ONCE(sta_id
>= IWL_MVM_STATION_COUNT
))
1444 sta
= rcu_dereference(mvm
->fw_id_to_mac_id
[sta_id
]);
1445 if (!IS_ERR_OR_NULL(sta
))
1446 ieee80211_sta_eosp(sta
);