Commit | Line | Data |
---|---|---|
8ca151b5 JB |
1 | /****************************************************************************** |
2 | * | |
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. | |
5 | * | |
6 | * GPL LICENSE SUMMARY | |
7 | * | |
fa7878e7 AO |
8 | * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved. |
9 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH | |
854c5705 | 10 | * Copyright(c) 2016 Intel Deutschland GmbH |
8ca151b5 JB |
11 | * |
12 | * This program is free software; you can redistribute it and/or modify | |
13 | * it under the terms of version 2 of the GNU General Public License as | |
14 | * published by the Free Software Foundation. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, but | |
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | * General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU General Public License | |
22 | * along with this program; if not, write to the Free Software | |
23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | |
24 | * USA | |
25 | * | |
26 | * The full GNU General Public License is included in this distribution | |
410dc5aa | 27 | * in the file called COPYING. |
8ca151b5 JB |
28 | * |
29 | * Contact Information: | |
cb2f8277 | 30 | * Intel Linux Wireless <linuxwifi@intel.com> |
8ca151b5 JB |
31 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
32 | * | |
33 | * BSD LICENSE | |
34 | * | |
fa7878e7 AO |
35 | * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved. |
36 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH | |
854c5705 | 37 | * Copyright(c) 2016 Intel Deutschland GmbH |
8ca151b5 JB |
38 | * All rights reserved. |
39 | * | |
40 | * Redistribution and use in source and binary forms, with or without | |
41 | * modification, are permitted provided that the following conditions | |
42 | * are met: | |
43 | * | |
44 | * * Redistributions of source code must retain the above copyright | |
45 | * notice, this list of conditions and the following disclaimer. | |
46 | * * Redistributions in binary form must reproduce the above copyright | |
47 | * notice, this list of conditions and the following disclaimer in | |
48 | * the documentation and/or other materials provided with the | |
49 | * distribution. | |
50 | * * Neither the name Intel Corporation nor the names of its | |
51 | * contributors may be used to endorse or promote products derived | |
52 | * from this software without specific prior written permission. | |
53 | * | |
54 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
55 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
56 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
57 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
58 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
59 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
60 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
61 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
62 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
63 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
64 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
65 | * | |
66 | *****************************************************************************/ | |
67 | #include <net/mac80211.h> | |
68 | ||
69 | #include "mvm.h" | |
70 | #include "sta.h" | |
9ee718aa | 71 | #include "rs.h" |
8ca151b5 | 72 | |
854c5705 SS |
73 | /* |
74 | * New version of ADD_STA_sta command added new fields at the end of the | |
75 | * structure, so sending the size of the relevant API's structure is enough to | |
76 | * support both API versions. | |
77 | */ | |
78 | static inline int iwl_mvm_add_sta_cmd_size(struct iwl_mvm *mvm) | |
79 | { | |
80 | return iwl_mvm_has_new_rx_api(mvm) ? | |
81 | sizeof(struct iwl_mvm_add_sta_cmd) : | |
82 | sizeof(struct iwl_mvm_add_sta_cmd_v7); | |
83 | } | |
84 | ||
b92e661b EP |
85 | static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm, |
86 | enum nl80211_iftype iftype) | |
8ca151b5 JB |
87 | { |
88 | int sta_id; | |
b92e661b | 89 | u32 reserved_ids = 0; |
8ca151b5 | 90 | |
b92e661b | 91 | BUILD_BUG_ON(IWL_MVM_STATION_COUNT > 32); |
8ca151b5 JB |
92 | WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)); |
93 | ||
94 | lockdep_assert_held(&mvm->mutex); | |
95 | ||
b92e661b EP |
96 | /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */ |
97 | if (iftype != NL80211_IFTYPE_STATION) | |
98 | reserved_ids = BIT(0); | |
99 | ||
8ca151b5 | 100 | /* Don't take rcu_read_lock() since we are protected by mvm->mutex */ |
b92e661b EP |
101 | for (sta_id = 0; sta_id < IWL_MVM_STATION_COUNT; sta_id++) { |
102 | if (BIT(sta_id) & reserved_ids) | |
103 | continue; | |
104 | ||
8ca151b5 JB |
105 | if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
106 | lockdep_is_held(&mvm->mutex))) | |
107 | return sta_id; | |
b92e661b | 108 | } |
8ca151b5 JB |
109 | return IWL_MVM_STATION_COUNT; |
110 | } | |
111 | ||
7a453973 JB |
112 | /* send station add/update command to firmware */ |
113 | int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta, | |
24afba76 | 114 | bool update, unsigned int flags) |
8ca151b5 | 115 | { |
9d8ce6af | 116 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
4b8265ab EG |
117 | struct iwl_mvm_add_sta_cmd add_sta_cmd = { |
118 | .sta_id = mvm_sta->sta_id, | |
119 | .mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color), | |
120 | .add_modify = update ? 1 : 0, | |
121 | .station_flags_msk = cpu_to_le32(STA_FLG_FAT_EN_MSK | | |
122 | STA_FLG_MIMO_EN_MSK), | |
cf0cda19 | 123 | .tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg), |
4b8265ab | 124 | }; |
8ca151b5 JB |
125 | int ret; |
126 | u32 status; | |
127 | u32 agg_size = 0, mpdu_dens = 0; | |
128 | ||
24afba76 | 129 | if (!update || (flags & STA_MODIFY_QUEUES)) { |
7a453973 JB |
130 | add_sta_cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); |
131 | memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN); | |
24afba76 LK |
132 | |
133 | if (flags & STA_MODIFY_QUEUES) | |
134 | add_sta_cmd.modify_mask |= STA_MODIFY_QUEUES; | |
7a453973 | 135 | } |
5bc5aaad JB |
136 | |
137 | switch (sta->bandwidth) { | |
138 | case IEEE80211_STA_RX_BW_160: | |
139 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_160MHZ); | |
140 | /* fall through */ | |
141 | case IEEE80211_STA_RX_BW_80: | |
142 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_80MHZ); | |
143 | /* fall through */ | |
144 | case IEEE80211_STA_RX_BW_40: | |
145 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_40MHZ); | |
146 | /* fall through */ | |
147 | case IEEE80211_STA_RX_BW_20: | |
148 | if (sta->ht_cap.ht_supported) | |
149 | add_sta_cmd.station_flags |= | |
150 | cpu_to_le32(STA_FLG_FAT_EN_20MHZ); | |
151 | break; | |
152 | } | |
153 | ||
154 | switch (sta->rx_nss) { | |
155 | case 1: | |
156 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO); | |
157 | break; | |
158 | case 2: | |
159 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2); | |
160 | break; | |
161 | case 3 ... 8: | |
162 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3); | |
163 | break; | |
164 | } | |
165 | ||
166 | switch (sta->smps_mode) { | |
167 | case IEEE80211_SMPS_AUTOMATIC: | |
168 | case IEEE80211_SMPS_NUM_MODES: | |
169 | WARN_ON(1); | |
170 | break; | |
171 | case IEEE80211_SMPS_STATIC: | |
172 | /* override NSS */ | |
173 | add_sta_cmd.station_flags &= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK); | |
174 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO); | |
175 | break; | |
176 | case IEEE80211_SMPS_DYNAMIC: | |
177 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_RTS_MIMO_PROT); | |
178 | break; | |
179 | case IEEE80211_SMPS_OFF: | |
180 | /* nothing */ | |
181 | break; | |
182 | } | |
8ca151b5 JB |
183 | |
184 | if (sta->ht_cap.ht_supported) { | |
185 | add_sta_cmd.station_flags_msk |= | |
186 | cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK | | |
187 | STA_FLG_AGG_MPDU_DENS_MSK); | |
188 | ||
189 | mpdu_dens = sta->ht_cap.ampdu_density; | |
190 | } | |
191 | ||
192 | if (sta->vht_cap.vht_supported) { | |
193 | agg_size = sta->vht_cap.cap & | |
194 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; | |
195 | agg_size >>= | |
196 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; | |
197 | } else if (sta->ht_cap.ht_supported) { | |
198 | agg_size = sta->ht_cap.ampdu_factor; | |
199 | } | |
200 | ||
201 | add_sta_cmd.station_flags |= | |
202 | cpu_to_le32(agg_size << STA_FLG_MAX_AGG_SIZE_SHIFT); | |
203 | add_sta_cmd.station_flags |= | |
204 | cpu_to_le32(mpdu_dens << STA_FLG_AGG_MPDU_DENS_SHIFT); | |
205 | ||
206 | status = ADD_STA_SUCCESS; | |
854c5705 SS |
207 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
208 | iwl_mvm_add_sta_cmd_size(mvm), | |
f9dc0004 | 209 | &add_sta_cmd, &status); |
8ca151b5 JB |
210 | if (ret) |
211 | return ret; | |
212 | ||
837c4da9 | 213 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
8ca151b5 JB |
214 | case ADD_STA_SUCCESS: |
215 | IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n"); | |
216 | break; | |
217 | default: | |
218 | ret = -EIO; | |
219 | IWL_ERR(mvm, "ADD_STA failed\n"); | |
220 | break; | |
221 | } | |
222 | ||
223 | return ret; | |
224 | } | |
225 | ||
10b2b201 SS |
226 | static void iwl_mvm_rx_agg_session_expired(unsigned long data) |
227 | { | |
228 | struct iwl_mvm_baid_data __rcu **rcu_ptr = (void *)data; | |
229 | struct iwl_mvm_baid_data *ba_data; | |
230 | struct ieee80211_sta *sta; | |
231 | struct iwl_mvm_sta *mvm_sta; | |
232 | unsigned long timeout; | |
233 | ||
234 | rcu_read_lock(); | |
235 | ||
236 | ba_data = rcu_dereference(*rcu_ptr); | |
237 | ||
238 | if (WARN_ON(!ba_data)) | |
239 | goto unlock; | |
240 | ||
241 | if (!ba_data->timeout) | |
242 | goto unlock; | |
243 | ||
244 | timeout = ba_data->last_rx + TU_TO_JIFFIES(ba_data->timeout * 2); | |
245 | if (time_is_after_jiffies(timeout)) { | |
246 | mod_timer(&ba_data->session_timer, timeout); | |
247 | goto unlock; | |
248 | } | |
249 | ||
250 | /* Timer expired */ | |
251 | sta = rcu_dereference(ba_data->mvm->fw_id_to_mac_id[ba_data->sta_id]); | |
252 | mvm_sta = iwl_mvm_sta_from_mac80211(sta); | |
253 | ieee80211_stop_rx_ba_session_offl(mvm_sta->vif, | |
254 | sta->addr, ba_data->tid); | |
255 | unlock: | |
256 | rcu_read_unlock(); | |
257 | } | |
258 | ||
a0f6bf2a AN |
259 | static int iwl_mvm_tdls_sta_init(struct iwl_mvm *mvm, |
260 | struct ieee80211_sta *sta) | |
261 | { | |
262 | unsigned long used_hw_queues; | |
263 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
5d42e7b2 EG |
264 | unsigned int wdg_timeout = |
265 | iwl_mvm_get_wd_timeout(mvm, NULL, true, false); | |
a0f6bf2a AN |
266 | u32 ac; |
267 | ||
268 | lockdep_assert_held(&mvm->mutex); | |
269 | ||
270 | used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, NULL); | |
271 | ||
272 | /* Find available queues, and allocate them to the ACs */ | |
273 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { | |
274 | u8 queue = find_first_zero_bit(&used_hw_queues, | |
275 | mvm->first_agg_queue); | |
276 | ||
277 | if (queue >= mvm->first_agg_queue) { | |
278 | IWL_ERR(mvm, "Failed to allocate STA queue\n"); | |
279 | return -EBUSY; | |
280 | } | |
281 | ||
282 | __set_bit(queue, &used_hw_queues); | |
283 | mvmsta->hw_queue[ac] = queue; | |
284 | } | |
285 | ||
286 | /* Found a place for all queues - enable them */ | |
287 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { | |
288 | iwl_mvm_enable_ac_txq(mvm, mvmsta->hw_queue[ac], | |
4ecafae9 | 289 | mvmsta->hw_queue[ac], |
5c1156ef LK |
290 | iwl_mvm_ac_to_tx_fifo[ac], 0, |
291 | wdg_timeout); | |
a0f6bf2a AN |
292 | mvmsta->tfd_queue_msk |= BIT(mvmsta->hw_queue[ac]); |
293 | } | |
294 | ||
295 | return 0; | |
296 | } | |
297 | ||
298 | static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm *mvm, | |
299 | struct ieee80211_sta *sta) | |
300 | { | |
301 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
302 | unsigned long sta_msk; | |
303 | int i; | |
304 | ||
305 | lockdep_assert_held(&mvm->mutex); | |
306 | ||
307 | /* disable the TDLS STA-specific queues */ | |
308 | sta_msk = mvmsta->tfd_queue_msk; | |
a4ca3ed4 | 309 | for_each_set_bit(i, &sta_msk, sizeof(sta_msk) * BITS_PER_BYTE) |
06ecdba3 | 310 | iwl_mvm_disable_txq(mvm, i, i, IWL_MAX_TID_COUNT, 0); |
a0f6bf2a AN |
311 | } |
312 | ||
9794c64f LK |
313 | /* Disable aggregations for a bitmap of TIDs for a given station */ |
314 | static int iwl_mvm_invalidate_sta_queue(struct iwl_mvm *mvm, int queue, | |
315 | unsigned long disable_agg_tids, | |
316 | bool remove_queue) | |
317 | { | |
318 | struct iwl_mvm_add_sta_cmd cmd = {}; | |
319 | struct ieee80211_sta *sta; | |
320 | struct iwl_mvm_sta *mvmsta; | |
321 | u32 status; | |
322 | u8 sta_id; | |
323 | int ret; | |
324 | ||
325 | spin_lock_bh(&mvm->queue_info_lock); | |
326 | sta_id = mvm->queue_info[queue].ra_sta_id; | |
327 | spin_unlock_bh(&mvm->queue_info_lock); | |
328 | ||
329 | rcu_read_lock(); | |
330 | ||
331 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); | |
332 | ||
333 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) { | |
334 | rcu_read_unlock(); | |
335 | return -EINVAL; | |
336 | } | |
337 | ||
338 | mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
339 | ||
340 | mvmsta->tid_disable_agg |= disable_agg_tids; | |
341 | ||
342 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); | |
343 | cmd.sta_id = mvmsta->sta_id; | |
344 | cmd.add_modify = STA_MODE_MODIFY; | |
345 | cmd.modify_mask = STA_MODIFY_QUEUES; | |
346 | if (disable_agg_tids) | |
347 | cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX; | |
348 | if (remove_queue) | |
349 | cmd.modify_mask |= STA_MODIFY_QUEUE_REMOVAL; | |
350 | cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk); | |
351 | cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg); | |
352 | ||
353 | rcu_read_unlock(); | |
354 | ||
355 | /* Notify FW of queue removal from the STA queues */ | |
356 | status = ADD_STA_SUCCESS; | |
357 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, | |
358 | iwl_mvm_add_sta_cmd_size(mvm), | |
359 | &cmd, &status); | |
360 | ||
361 | return ret; | |
362 | } | |
363 | ||
42db09c1 LK |
364 | static int iwl_mvm_get_queue_agg_tids(struct iwl_mvm *mvm, int queue) |
365 | { | |
366 | struct ieee80211_sta *sta; | |
367 | struct iwl_mvm_sta *mvmsta; | |
368 | unsigned long tid_bitmap; | |
369 | unsigned long agg_tids = 0; | |
370 | s8 sta_id; | |
371 | int tid; | |
372 | ||
373 | lockdep_assert_held(&mvm->mutex); | |
374 | ||
375 | spin_lock_bh(&mvm->queue_info_lock); | |
376 | sta_id = mvm->queue_info[queue].ra_sta_id; | |
377 | tid_bitmap = mvm->queue_info[queue].tid_bitmap; | |
378 | spin_unlock_bh(&mvm->queue_info_lock); | |
379 | ||
380 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
381 | lockdep_is_held(&mvm->mutex)); | |
382 | ||
383 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) | |
384 | return -EINVAL; | |
385 | ||
386 | mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
387 | ||
388 | spin_lock_bh(&mvmsta->lock); | |
389 | for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) { | |
390 | if (mvmsta->tid_data[tid].state == IWL_AGG_ON) | |
391 | agg_tids |= BIT(tid); | |
392 | } | |
393 | spin_unlock_bh(&mvmsta->lock); | |
394 | ||
395 | return agg_tids; | |
396 | } | |
397 | ||
9794c64f LK |
398 | /* |
399 | * Remove a queue from a station's resources. | |
400 | * Note that this only marks as free. It DOESN'T delete a BA agreement, and | |
401 | * doesn't disable the queue | |
402 | */ | |
403 | static int iwl_mvm_remove_sta_queue_marking(struct iwl_mvm *mvm, int queue) | |
404 | { | |
405 | struct ieee80211_sta *sta; | |
406 | struct iwl_mvm_sta *mvmsta; | |
407 | unsigned long tid_bitmap; | |
408 | unsigned long disable_agg_tids = 0; | |
409 | u8 sta_id; | |
410 | int tid; | |
411 | ||
412 | lockdep_assert_held(&mvm->mutex); | |
413 | ||
414 | spin_lock_bh(&mvm->queue_info_lock); | |
415 | sta_id = mvm->queue_info[queue].ra_sta_id; | |
416 | tid_bitmap = mvm->queue_info[queue].tid_bitmap; | |
417 | spin_unlock_bh(&mvm->queue_info_lock); | |
418 | ||
419 | rcu_read_lock(); | |
420 | ||
421 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); | |
422 | ||
423 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) { | |
424 | rcu_read_unlock(); | |
425 | return 0; | |
426 | } | |
427 | ||
428 | mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
429 | ||
430 | spin_lock_bh(&mvmsta->lock); | |
42db09c1 | 431 | /* Unmap MAC queues and TIDs from this queue */ |
9794c64f | 432 | for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) { |
9794c64f LK |
433 | if (mvmsta->tid_data[tid].state == IWL_AGG_ON) |
434 | disable_agg_tids |= BIT(tid); | |
42db09c1 | 435 | mvmsta->tid_data[tid].txq_id = IEEE80211_INVAL_HW_QUEUE; |
9794c64f | 436 | } |
9794c64f | 437 | |
42db09c1 | 438 | mvmsta->tfd_queue_msk &= ~BIT(queue); /* Don't use this queue anymore */ |
9794c64f LK |
439 | spin_unlock_bh(&mvmsta->lock); |
440 | ||
441 | rcu_read_unlock(); | |
442 | ||
42db09c1 | 443 | spin_lock_bh(&mvm->queue_info_lock); |
9794c64f LK |
444 | /* Unmap MAC queues and TIDs from this queue */ |
445 | mvm->queue_info[queue].hw_queue_to_mac80211 = 0; | |
446 | mvm->queue_info[queue].hw_queue_refcount = 0; | |
447 | mvm->queue_info[queue].tid_bitmap = 0; | |
42db09c1 | 448 | spin_unlock_bh(&mvm->queue_info_lock); |
9794c64f LK |
449 | |
450 | return disable_agg_tids; | |
451 | } | |
452 | ||
42db09c1 LK |
453 | static int iwl_mvm_get_shared_queue(struct iwl_mvm *mvm, |
454 | unsigned long tfd_queue_mask, u8 ac) | |
455 | { | |
456 | int queue = 0; | |
457 | u8 ac_to_queue[IEEE80211_NUM_ACS]; | |
458 | int i; | |
459 | ||
460 | lockdep_assert_held(&mvm->queue_info_lock); | |
461 | ||
462 | memset(&ac_to_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(ac_to_queue)); | |
463 | ||
464 | /* See what ACs the existing queues for this STA have */ | |
465 | for_each_set_bit(i, &tfd_queue_mask, IWL_MVM_DQA_MAX_DATA_QUEUE) { | |
466 | /* Only DATA queues can be shared */ | |
467 | if (i < IWL_MVM_DQA_MIN_DATA_QUEUE && | |
468 | i != IWL_MVM_DQA_BSS_CLIENT_QUEUE) | |
469 | continue; | |
470 | ||
9f9af3d7 LK |
471 | /* Don't try and take queues being reconfigured */ |
472 | if (mvm->queue_info[queue].status == | |
473 | IWL_MVM_QUEUE_RECONFIGURING) | |
474 | continue; | |
475 | ||
42db09c1 LK |
476 | ac_to_queue[mvm->queue_info[i].mac80211_ac] = i; |
477 | } | |
478 | ||
479 | /* | |
480 | * The queue to share is chosen only from DATA queues as follows (in | |
481 | * descending priority): | |
482 | * 1. An AC_BE queue | |
483 | * 2. Same AC queue | |
484 | * 3. Highest AC queue that is lower than new AC | |
485 | * 4. Any existing AC (there always is at least 1 DATA queue) | |
486 | */ | |
487 | ||
488 | /* Priority 1: An AC_BE queue */ | |
489 | if (ac_to_queue[IEEE80211_AC_BE] != IEEE80211_INVAL_HW_QUEUE) | |
490 | queue = ac_to_queue[IEEE80211_AC_BE]; | |
491 | /* Priority 2: Same AC queue */ | |
492 | else if (ac_to_queue[ac] != IEEE80211_INVAL_HW_QUEUE) | |
493 | queue = ac_to_queue[ac]; | |
494 | /* Priority 3a: If new AC is VO and VI exists - use VI */ | |
495 | else if (ac == IEEE80211_AC_VO && | |
496 | ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE) | |
497 | queue = ac_to_queue[IEEE80211_AC_VI]; | |
498 | /* Priority 3b: No BE so only AC less than the new one is BK */ | |
499 | else if (ac_to_queue[IEEE80211_AC_BK] != IEEE80211_INVAL_HW_QUEUE) | |
500 | queue = ac_to_queue[IEEE80211_AC_BK]; | |
501 | /* Priority 4a: No BE nor BK - use VI if exists */ | |
502 | else if (ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE) | |
503 | queue = ac_to_queue[IEEE80211_AC_VI]; | |
504 | /* Priority 4b: No BE, BK nor VI - use VO if exists */ | |
505 | else if (ac_to_queue[IEEE80211_AC_VO] != IEEE80211_INVAL_HW_QUEUE) | |
506 | queue = ac_to_queue[IEEE80211_AC_VO]; | |
507 | ||
508 | /* Make sure queue found (or not) is legal */ | |
9f9af3d7 LK |
509 | if (!iwl_mvm_is_dqa_data_queue(mvm, queue) && |
510 | !iwl_mvm_is_dqa_mgmt_queue(mvm, queue) && | |
511 | (queue != IWL_MVM_DQA_BSS_CLIENT_QUEUE)) { | |
42db09c1 | 512 | IWL_ERR(mvm, "No DATA queues available to share\n"); |
9f9af3d7 LK |
513 | return -ENOSPC; |
514 | } | |
515 | ||
516 | /* Make sure the queue isn't in the middle of being reconfigured */ | |
517 | if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_RECONFIGURING) { | |
518 | IWL_ERR(mvm, | |
519 | "TXQ %d is in the middle of re-config - try again\n", | |
520 | queue); | |
521 | return -EBUSY; | |
42db09c1 LK |
522 | } |
523 | ||
524 | return queue; | |
525 | } | |
526 | ||
58f2cc57 | 527 | /* |
9f9af3d7 LK |
528 | * If a given queue has a higher AC than the TID stream that is being compared |
529 | * to, the queue needs to be redirected to the lower AC. This function does that | |
58f2cc57 LK |
530 | * in such a case, otherwise - if no redirection required - it does nothing, |
531 | * unless the %force param is true. | |
532 | */ | |
9f9af3d7 LK |
533 | int iwl_mvm_scd_queue_redirect(struct iwl_mvm *mvm, int queue, int tid, |
534 | int ac, int ssn, unsigned int wdg_timeout, | |
535 | bool force) | |
58f2cc57 LK |
536 | { |
537 | struct iwl_scd_txq_cfg_cmd cmd = { | |
538 | .scd_queue = queue, | |
539 | .enable = 0, | |
540 | }; | |
541 | bool shared_queue; | |
542 | unsigned long mq; | |
543 | int ret; | |
544 | ||
545 | /* | |
546 | * If the AC is lower than current one - FIFO needs to be redirected to | |
547 | * the lowest one of the streams in the queue. Check if this is needed | |
548 | * here. | |
549 | * Notice that the enum ieee80211_ac_numbers is "flipped", so BK is with | |
550 | * value 3 and VO with value 0, so to check if ac X is lower than ac Y | |
551 | * we need to check if the numerical value of X is LARGER than of Y. | |
552 | */ | |
553 | spin_lock_bh(&mvm->queue_info_lock); | |
554 | if (ac <= mvm->queue_info[queue].mac80211_ac && !force) { | |
555 | spin_unlock_bh(&mvm->queue_info_lock); | |
556 | ||
557 | IWL_DEBUG_TX_QUEUES(mvm, | |
558 | "No redirection needed on TXQ #%d\n", | |
559 | queue); | |
560 | return 0; | |
561 | } | |
562 | ||
563 | cmd.sta_id = mvm->queue_info[queue].ra_sta_id; | |
564 | cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[mvm->queue_info[queue].mac80211_ac]; | |
565 | mq = mvm->queue_info[queue].hw_queue_to_mac80211; | |
566 | shared_queue = (mvm->queue_info[queue].hw_queue_refcount > 1); | |
567 | spin_unlock_bh(&mvm->queue_info_lock); | |
568 | ||
9f9af3d7 | 569 | IWL_DEBUG_TX_QUEUES(mvm, "Redirecting TXQ #%d to FIFO #%d\n", |
58f2cc57 LK |
570 | queue, iwl_mvm_ac_to_tx_fifo[ac]); |
571 | ||
572 | /* Stop MAC queues and wait for this queue to empty */ | |
573 | iwl_mvm_stop_mac_queues(mvm, mq); | |
574 | ret = iwl_trans_wait_tx_queue_empty(mvm->trans, BIT(queue)); | |
575 | if (ret) { | |
576 | IWL_ERR(mvm, "Error draining queue %d before reconfig\n", | |
577 | queue); | |
578 | ret = -EIO; | |
579 | goto out; | |
580 | } | |
581 | ||
582 | /* Before redirecting the queue we need to de-activate it */ | |
583 | iwl_trans_txq_disable(mvm->trans, queue, false); | |
584 | ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd); | |
585 | if (ret) | |
586 | IWL_ERR(mvm, "Failed SCD disable TXQ %d (ret=%d)\n", queue, | |
587 | ret); | |
588 | ||
589 | /* Make sure the SCD wrptr is correctly set before reconfiguring */ | |
590 | iwl_trans_txq_enable(mvm->trans, queue, iwl_mvm_ac_to_tx_fifo[ac], | |
591 | cmd.sta_id, tid, LINK_QUAL_AGG_FRAME_LIMIT_DEF, | |
592 | ssn, wdg_timeout); | |
593 | ||
594 | /* TODO: Work-around SCD bug when moving back by multiples of 0x40 */ | |
595 | ||
596 | /* Redirect to lower AC */ | |
597 | iwl_mvm_reconfig_scd(mvm, queue, iwl_mvm_ac_to_tx_fifo[ac], | |
598 | cmd.sta_id, tid, LINK_QUAL_AGG_FRAME_LIMIT_DEF, | |
599 | ssn); | |
600 | ||
601 | /* Update AC marking of the queue */ | |
602 | spin_lock_bh(&mvm->queue_info_lock); | |
603 | mvm->queue_info[queue].mac80211_ac = ac; | |
604 | spin_unlock_bh(&mvm->queue_info_lock); | |
605 | ||
606 | /* | |
607 | * Mark queue as shared in transport if shared | |
608 | * Note this has to be done after queue enablement because enablement | |
609 | * can also set this value, and there is no indication there to shared | |
610 | * queues | |
611 | */ | |
612 | if (shared_queue) | |
613 | iwl_trans_txq_set_shared_mode(mvm->trans, queue, true); | |
614 | ||
615 | out: | |
616 | /* Continue using the MAC queues */ | |
617 | iwl_mvm_start_mac_queues(mvm, mq); | |
618 | ||
619 | return ret; | |
620 | } | |
621 | ||
24afba76 LK |
622 | static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm, |
623 | struct ieee80211_sta *sta, u8 ac, int tid, | |
624 | struct ieee80211_hdr *hdr) | |
625 | { | |
626 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
627 | struct iwl_trans_txq_scd_cfg cfg = { | |
628 | .fifo = iwl_mvm_ac_to_tx_fifo[ac], | |
629 | .sta_id = mvmsta->sta_id, | |
630 | .tid = tid, | |
631 | .frame_limit = IWL_FRAME_LIMIT, | |
632 | }; | |
633 | unsigned int wdg_timeout = | |
634 | iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false); | |
635 | u8 mac_queue = mvmsta->vif->hw_queue[ac]; | |
636 | int queue = -1; | |
9794c64f LK |
637 | bool using_inactive_queue = false; |
638 | unsigned long disable_agg_tids = 0; | |
639 | enum iwl_mvm_agg_state queue_state; | |
42db09c1 | 640 | bool shared_queue = false; |
24afba76 | 641 | int ssn; |
42db09c1 | 642 | unsigned long tfd_queue_mask; |
cf961e16 | 643 | int ret; |
24afba76 LK |
644 | |
645 | lockdep_assert_held(&mvm->mutex); | |
646 | ||
42db09c1 LK |
647 | spin_lock_bh(&mvmsta->lock); |
648 | tfd_queue_mask = mvmsta->tfd_queue_msk; | |
649 | spin_unlock_bh(&mvmsta->lock); | |
650 | ||
d2515a99 | 651 | spin_lock_bh(&mvm->queue_info_lock); |
24afba76 LK |
652 | |
653 | /* | |
654 | * Non-QoS, QoS NDP and MGMT frames should go to a MGMT queue, if one | |
655 | * exists | |
656 | */ | |
657 | if (!ieee80211_is_data_qos(hdr->frame_control) || | |
658 | ieee80211_is_qos_nullfunc(hdr->frame_control)) { | |
9794c64f LK |
659 | queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, |
660 | IWL_MVM_DQA_MIN_MGMT_QUEUE, | |
24afba76 LK |
661 | IWL_MVM_DQA_MAX_MGMT_QUEUE); |
662 | if (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE) | |
663 | IWL_DEBUG_TX_QUEUES(mvm, "Found free MGMT queue #%d\n", | |
664 | queue); | |
665 | ||
666 | /* If no such queue is found, we'll use a DATA queue instead */ | |
667 | } | |
668 | ||
9794c64f LK |
669 | if ((queue < 0 && mvmsta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) && |
670 | (mvm->queue_info[mvmsta->reserved_queue].status == | |
671 | IWL_MVM_QUEUE_RESERVED || | |
672 | mvm->queue_info[mvmsta->reserved_queue].status == | |
673 | IWL_MVM_QUEUE_INACTIVE)) { | |
24afba76 | 674 | queue = mvmsta->reserved_queue; |
9794c64f | 675 | mvm->queue_info[queue].reserved = true; |
24afba76 LK |
676 | IWL_DEBUG_TX_QUEUES(mvm, "Using reserved queue #%d\n", queue); |
677 | } | |
678 | ||
679 | if (queue < 0) | |
9794c64f LK |
680 | queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, |
681 | IWL_MVM_DQA_MIN_DATA_QUEUE, | |
24afba76 | 682 | IWL_MVM_DQA_MAX_DATA_QUEUE); |
cf961e16 | 683 | |
9794c64f LK |
684 | /* |
685 | * Check if this queue is already allocated but inactive. | |
686 | * In such a case, we'll need to first free this queue before enabling | |
687 | * it again, so we'll mark it as reserved to make sure no new traffic | |
688 | * arrives on it | |
689 | */ | |
690 | if (queue > 0 && | |
691 | mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) { | |
692 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED; | |
693 | using_inactive_queue = true; | |
694 | IWL_DEBUG_TX_QUEUES(mvm, | |
695 | "Re-assigning TXQ %d: sta_id=%d, tid=%d\n", | |
696 | queue, mvmsta->sta_id, tid); | |
697 | } | |
698 | ||
42db09c1 LK |
699 | /* No free queue - we'll have to share */ |
700 | if (queue <= 0) { | |
701 | queue = iwl_mvm_get_shared_queue(mvm, tfd_queue_mask, ac); | |
702 | if (queue > 0) { | |
703 | shared_queue = true; | |
704 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_SHARED; | |
705 | } | |
706 | } | |
707 | ||
cf961e16 LK |
708 | /* |
709 | * Mark TXQ as ready, even though it hasn't been fully configured yet, | |
710 | * to make sure no one else takes it. | |
711 | * This will allow avoiding re-acquiring the lock at the end of the | |
712 | * configuration. On error we'll mark it back as free. | |
713 | */ | |
42db09c1 | 714 | if ((queue > 0) && !shared_queue) |
cf961e16 | 715 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY; |
24afba76 | 716 | |
d2515a99 | 717 | spin_unlock_bh(&mvm->queue_info_lock); |
24afba76 | 718 | |
42db09c1 LK |
719 | /* This shouldn't happen - out of queues */ |
720 | if (WARN_ON(queue <= 0)) { | |
721 | IWL_ERR(mvm, "No available queues for tid %d on sta_id %d\n", | |
722 | tid, cfg.sta_id); | |
9f9af3d7 | 723 | return queue; |
42db09c1 | 724 | } |
24afba76 LK |
725 | |
726 | /* | |
727 | * Actual en/disablement of aggregations is through the ADD_STA HCMD, | |
728 | * but for configuring the SCD to send A-MPDUs we need to mark the queue | |
729 | * as aggregatable. | |
730 | * Mark all DATA queues as allowing to be aggregated at some point | |
731 | */ | |
d5216a28 LK |
732 | cfg.aggregate = (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE || |
733 | queue == IWL_MVM_DQA_BSS_CLIENT_QUEUE); | |
24afba76 | 734 | |
9794c64f LK |
735 | /* |
736 | * If this queue was previously inactive (idle) - we need to free it | |
737 | * first | |
738 | */ | |
739 | if (using_inactive_queue) { | |
740 | struct iwl_scd_txq_cfg_cmd cmd = { | |
741 | .scd_queue = queue, | |
742 | .enable = 0, | |
743 | }; | |
93f436e2 | 744 | u8 ac; |
9794c64f LK |
745 | |
746 | disable_agg_tids = iwl_mvm_remove_sta_queue_marking(mvm, queue); | |
747 | ||
93f436e2 LK |
748 | spin_lock_bh(&mvm->queue_info_lock); |
749 | ac = mvm->queue_info[queue].mac80211_ac; | |
750 | cmd.sta_id = mvm->queue_info[queue].ra_sta_id; | |
751 | cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[ac]; | |
752 | spin_unlock_bh(&mvm->queue_info_lock); | |
753 | ||
9794c64f LK |
754 | /* Disable the queue */ |
755 | iwl_mvm_invalidate_sta_queue(mvm, queue, disable_agg_tids, | |
756 | true); | |
757 | iwl_trans_txq_disable(mvm->trans, queue, false); | |
758 | ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), | |
759 | &cmd); | |
760 | if (ret) { | |
761 | IWL_ERR(mvm, | |
762 | "Failed to free inactive queue %d (ret=%d)\n", | |
763 | queue, ret); | |
764 | ||
765 | /* Re-mark the inactive queue as inactive */ | |
766 | spin_lock_bh(&mvm->queue_info_lock); | |
767 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_INACTIVE; | |
768 | spin_unlock_bh(&mvm->queue_info_lock); | |
769 | ||
770 | return ret; | |
771 | } | |
772 | } | |
773 | ||
42db09c1 LK |
774 | IWL_DEBUG_TX_QUEUES(mvm, |
775 | "Allocating %squeue #%d to sta %d on tid %d\n", | |
776 | shared_queue ? "shared " : "", queue, | |
777 | mvmsta->sta_id, tid); | |
778 | ||
779 | if (shared_queue) { | |
780 | /* Disable any open aggs on this queue */ | |
781 | disable_agg_tids = iwl_mvm_get_queue_agg_tids(mvm, queue); | |
782 | ||
783 | if (disable_agg_tids) { | |
784 | IWL_DEBUG_TX_QUEUES(mvm, "Disabling aggs on queue %d\n", | |
785 | queue); | |
786 | iwl_mvm_invalidate_sta_queue(mvm, queue, | |
787 | disable_agg_tids, false); | |
788 | } | |
42db09c1 | 789 | } |
24afba76 LK |
790 | |
791 | ssn = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl)); | |
792 | iwl_mvm_enable_txq(mvm, queue, mac_queue, ssn, &cfg, | |
793 | wdg_timeout); | |
794 | ||
58f2cc57 LK |
795 | /* |
796 | * Mark queue as shared in transport if shared | |
797 | * Note this has to be done after queue enablement because enablement | |
798 | * can also set this value, and there is no indication there to shared | |
799 | * queues | |
800 | */ | |
801 | if (shared_queue) | |
802 | iwl_trans_txq_set_shared_mode(mvm->trans, queue, true); | |
803 | ||
24afba76 LK |
804 | spin_lock_bh(&mvmsta->lock); |
805 | mvmsta->tid_data[tid].txq_id = queue; | |
9794c64f | 806 | mvmsta->tid_data[tid].is_tid_active = true; |
24afba76 | 807 | mvmsta->tfd_queue_msk |= BIT(queue); |
9794c64f | 808 | queue_state = mvmsta->tid_data[tid].state; |
24afba76 LK |
809 | |
810 | if (mvmsta->reserved_queue == queue) | |
811 | mvmsta->reserved_queue = IEEE80211_INVAL_HW_QUEUE; | |
812 | spin_unlock_bh(&mvmsta->lock); | |
813 | ||
42db09c1 LK |
814 | if (!shared_queue) { |
815 | ret = iwl_mvm_sta_send_to_fw(mvm, sta, true, STA_MODIFY_QUEUES); | |
816 | if (ret) | |
817 | goto out_err; | |
cf961e16 | 818 | |
42db09c1 LK |
819 | /* If we need to re-enable aggregations... */ |
820 | if (queue_state == IWL_AGG_ON) { | |
821 | ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); | |
822 | if (ret) | |
823 | goto out_err; | |
824 | } | |
58f2cc57 LK |
825 | } else { |
826 | /* Redirect queue, if needed */ | |
827 | ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid, ac, ssn, | |
828 | wdg_timeout, false); | |
829 | if (ret) | |
830 | goto out_err; | |
42db09c1 | 831 | } |
9794c64f | 832 | |
42db09c1 | 833 | return 0; |
cf961e16 LK |
834 | |
835 | out_err: | |
836 | iwl_mvm_disable_txq(mvm, queue, mac_queue, tid, 0); | |
837 | ||
838 | return ret; | |
24afba76 LK |
839 | } |
840 | ||
9f9af3d7 LK |
841 | static void iwl_mvm_unshare_queue(struct iwl_mvm *mvm, int queue) |
842 | { | |
843 | struct ieee80211_sta *sta; | |
844 | struct iwl_mvm_sta *mvmsta; | |
845 | s8 sta_id; | |
846 | int tid = -1; | |
847 | unsigned long tid_bitmap; | |
848 | unsigned int wdg_timeout; | |
849 | int ssn; | |
850 | int ret = true; | |
851 | ||
852 | lockdep_assert_held(&mvm->mutex); | |
853 | ||
854 | spin_lock_bh(&mvm->queue_info_lock); | |
855 | sta_id = mvm->queue_info[queue].ra_sta_id; | |
856 | tid_bitmap = mvm->queue_info[queue].tid_bitmap; | |
857 | spin_unlock_bh(&mvm->queue_info_lock); | |
858 | ||
859 | /* Find TID for queue, and make sure it is the only one on the queue */ | |
860 | tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1); | |
861 | if (tid_bitmap != BIT(tid)) { | |
862 | IWL_ERR(mvm, "Failed to unshare q %d, active tids=0x%lx\n", | |
863 | queue, tid_bitmap); | |
864 | return; | |
865 | } | |
866 | ||
867 | IWL_DEBUG_TX_QUEUES(mvm, "Unsharing TXQ %d, keeping tid %d\n", queue, | |
868 | tid); | |
869 | ||
870 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
871 | lockdep_is_held(&mvm->mutex)); | |
872 | ||
873 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) | |
874 | return; | |
875 | ||
876 | mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
877 | wdg_timeout = iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false); | |
878 | ||
879 | ssn = IEEE80211_SEQ_TO_SN(mvmsta->tid_data[tid].seq_number); | |
880 | ||
881 | ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid, | |
882 | tid_to_mac80211_ac[tid], ssn, | |
883 | wdg_timeout, true); | |
884 | if (ret) { | |
885 | IWL_ERR(mvm, "Failed to redirect TXQ %d\n", queue); | |
886 | return; | |
887 | } | |
888 | ||
889 | /* If aggs should be turned back on - do it */ | |
890 | if (mvmsta->tid_data[tid].state == IWL_AGG_ON) { | |
891 | struct iwl_mvm_add_sta_cmd cmd; | |
892 | ||
893 | mvmsta->tid_disable_agg &= ~BIT(tid); | |
894 | ||
895 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); | |
896 | cmd.sta_id = mvmsta->sta_id; | |
897 | cmd.add_modify = STA_MODE_MODIFY; | |
898 | cmd.modify_mask = STA_MODIFY_TID_DISABLE_TX; | |
899 | cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk); | |
900 | cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg); | |
901 | ||
902 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, | |
903 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); | |
904 | if (!ret) { | |
905 | IWL_DEBUG_TX_QUEUES(mvm, | |
906 | "TXQ #%d is now aggregated again\n", | |
907 | queue); | |
908 | ||
909 | /* Mark queue intenally as aggregating again */ | |
910 | iwl_trans_txq_set_shared_mode(mvm->trans, queue, false); | |
911 | } | |
912 | } | |
913 | ||
914 | spin_lock_bh(&mvm->queue_info_lock); | |
915 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY; | |
916 | spin_unlock_bh(&mvm->queue_info_lock); | |
917 | } | |
918 | ||
24afba76 LK |
919 | static inline u8 iwl_mvm_tid_to_ac_queue(int tid) |
920 | { | |
921 | if (tid == IWL_MAX_TID_COUNT) | |
922 | return IEEE80211_AC_VO; /* MGMT */ | |
923 | ||
924 | return tid_to_mac80211_ac[tid]; | |
925 | } | |
926 | ||
927 | static void iwl_mvm_tx_deferred_stream(struct iwl_mvm *mvm, | |
928 | struct ieee80211_sta *sta, int tid) | |
929 | { | |
930 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
931 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; | |
932 | struct sk_buff *skb; | |
933 | struct ieee80211_hdr *hdr; | |
934 | struct sk_buff_head deferred_tx; | |
935 | u8 mac_queue; | |
936 | bool no_queue = false; /* Marks if there is a problem with the queue */ | |
937 | u8 ac; | |
938 | ||
939 | lockdep_assert_held(&mvm->mutex); | |
940 | ||
941 | skb = skb_peek(&tid_data->deferred_tx_frames); | |
942 | if (!skb) | |
943 | return; | |
944 | hdr = (void *)skb->data; | |
945 | ||
946 | ac = iwl_mvm_tid_to_ac_queue(tid); | |
947 | mac_queue = IEEE80211_SKB_CB(skb)->hw_queue; | |
948 | ||
949 | if (tid_data->txq_id == IEEE80211_INVAL_HW_QUEUE && | |
950 | iwl_mvm_sta_alloc_queue(mvm, sta, ac, tid, hdr)) { | |
951 | IWL_ERR(mvm, | |
952 | "Can't alloc TXQ for sta %d tid %d - dropping frame\n", | |
953 | mvmsta->sta_id, tid); | |
954 | ||
955 | /* | |
956 | * Mark queue as problematic so later the deferred traffic is | |
957 | * freed, as we can do nothing with it | |
958 | */ | |
959 | no_queue = true; | |
960 | } | |
961 | ||
962 | __skb_queue_head_init(&deferred_tx); | |
963 | ||
d2515a99 LK |
964 | /* Disable bottom-halves when entering TX path */ |
965 | local_bh_disable(); | |
24afba76 LK |
966 | spin_lock(&mvmsta->lock); |
967 | skb_queue_splice_init(&tid_data->deferred_tx_frames, &deferred_tx); | |
968 | spin_unlock(&mvmsta->lock); | |
969 | ||
24afba76 LK |
970 | while ((skb = __skb_dequeue(&deferred_tx))) |
971 | if (no_queue || iwl_mvm_tx_skb(mvm, skb, sta)) | |
972 | ieee80211_free_txskb(mvm->hw, skb); | |
973 | local_bh_enable(); | |
974 | ||
975 | /* Wake queue */ | |
976 | iwl_mvm_start_mac_queues(mvm, BIT(mac_queue)); | |
977 | } | |
978 | ||
979 | void iwl_mvm_add_new_dqa_stream_wk(struct work_struct *wk) | |
980 | { | |
981 | struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, | |
982 | add_stream_wk); | |
983 | struct ieee80211_sta *sta; | |
984 | struct iwl_mvm_sta *mvmsta; | |
985 | unsigned long deferred_tid_traffic; | |
9f9af3d7 | 986 | int queue, sta_id, tid; |
24afba76 | 987 | |
9794c64f LK |
988 | /* Check inactivity of queues */ |
989 | iwl_mvm_inactivity_check(mvm); | |
990 | ||
24afba76 LK |
991 | mutex_lock(&mvm->mutex); |
992 | ||
9f9af3d7 LK |
993 | /* Reconfigure queues requiring reconfiguation */ |
994 | for (queue = 0; queue < IWL_MAX_HW_QUEUES; queue++) { | |
995 | bool reconfig; | |
996 | ||
997 | spin_lock_bh(&mvm->queue_info_lock); | |
998 | reconfig = (mvm->queue_info[queue].status == | |
999 | IWL_MVM_QUEUE_RECONFIGURING); | |
1000 | spin_unlock_bh(&mvm->queue_info_lock); | |
1001 | ||
1002 | if (reconfig) | |
1003 | iwl_mvm_unshare_queue(mvm, queue); | |
1004 | } | |
1005 | ||
24afba76 LK |
1006 | /* Go over all stations with deferred traffic */ |
1007 | for_each_set_bit(sta_id, mvm->sta_deferred_frames, | |
1008 | IWL_MVM_STATION_COUNT) { | |
1009 | clear_bit(sta_id, mvm->sta_deferred_frames); | |
1010 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
1011 | lockdep_is_held(&mvm->mutex)); | |
1012 | if (IS_ERR_OR_NULL(sta)) | |
1013 | continue; | |
1014 | ||
1015 | mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
1016 | deferred_tid_traffic = mvmsta->deferred_traffic_tid_map; | |
1017 | ||
1018 | for_each_set_bit(tid, &deferred_tid_traffic, | |
1019 | IWL_MAX_TID_COUNT + 1) | |
1020 | iwl_mvm_tx_deferred_stream(mvm, sta, tid); | |
1021 | } | |
1022 | ||
1023 | mutex_unlock(&mvm->mutex); | |
1024 | } | |
1025 | ||
1026 | static int iwl_mvm_reserve_sta_stream(struct iwl_mvm *mvm, | |
d5216a28 LK |
1027 | struct ieee80211_sta *sta, |
1028 | enum nl80211_iftype vif_type) | |
24afba76 LK |
1029 | { |
1030 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); | |
1031 | int queue; | |
1032 | ||
9794c64f LK |
1033 | /* |
1034 | * Check for inactive queues, so we don't reach a situation where we | |
1035 | * can't add a STA due to a shortage in queues that doesn't really exist | |
1036 | */ | |
1037 | iwl_mvm_inactivity_check(mvm); | |
1038 | ||
24afba76 LK |
1039 | spin_lock_bh(&mvm->queue_info_lock); |
1040 | ||
1041 | /* Make sure we have free resources for this STA */ | |
d5216a28 LK |
1042 | if (vif_type == NL80211_IFTYPE_STATION && !sta->tdls && |
1043 | !mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].hw_queue_refcount && | |
cf961e16 LK |
1044 | (mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].status == |
1045 | IWL_MVM_QUEUE_FREE)) | |
d5216a28 LK |
1046 | queue = IWL_MVM_DQA_BSS_CLIENT_QUEUE; |
1047 | else | |
9794c64f LK |
1048 | queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, |
1049 | IWL_MVM_DQA_MIN_DATA_QUEUE, | |
d5216a28 | 1050 | IWL_MVM_DQA_MAX_DATA_QUEUE); |
24afba76 LK |
1051 | if (queue < 0) { |
1052 | spin_unlock_bh(&mvm->queue_info_lock); | |
1053 | IWL_ERR(mvm, "No available queues for new station\n"); | |
1054 | return -ENOSPC; | |
1055 | } | |
cf961e16 | 1056 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED; |
24afba76 LK |
1057 | |
1058 | spin_unlock_bh(&mvm->queue_info_lock); | |
1059 | ||
1060 | mvmsta->reserved_queue = queue; | |
1061 | ||
1062 | IWL_DEBUG_TX_QUEUES(mvm, "Reserving data queue #%d for sta_id %d\n", | |
1063 | queue, mvmsta->sta_id); | |
1064 | ||
1065 | return 0; | |
1066 | } | |
1067 | ||
8ca151b5 JB |
1068 | int iwl_mvm_add_sta(struct iwl_mvm *mvm, |
1069 | struct ieee80211_vif *vif, | |
1070 | struct ieee80211_sta *sta) | |
1071 | { | |
1072 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
9d8ce6af | 1073 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
a571f5f6 | 1074 | struct iwl_mvm_rxq_dup_data *dup_data; |
8ca151b5 JB |
1075 | int i, ret, sta_id; |
1076 | ||
1077 | lockdep_assert_held(&mvm->mutex); | |
1078 | ||
1079 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) | |
b92e661b EP |
1080 | sta_id = iwl_mvm_find_free_sta_id(mvm, |
1081 | ieee80211_vif_type_p2p(vif)); | |
8ca151b5 JB |
1082 | else |
1083 | sta_id = mvm_sta->sta_id; | |
1084 | ||
36f4631c | 1085 | if (sta_id == IWL_MVM_STATION_COUNT) |
8ca151b5 JB |
1086 | return -ENOSPC; |
1087 | ||
1088 | spin_lock_init(&mvm_sta->lock); | |
1089 | ||
1090 | mvm_sta->sta_id = sta_id; | |
1091 | mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, | |
1092 | mvmvif->color); | |
1093 | mvm_sta->vif = vif; | |
1094 | mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF; | |
9ee718aa EL |
1095 | mvm_sta->tx_protection = 0; |
1096 | mvm_sta->tt_tx_protection = false; | |
8ca151b5 JB |
1097 | |
1098 | /* HW restart, don't assume the memory has been zeroed */ | |
e3d4bc8c | 1099 | atomic_set(&mvm->pending_frames[sta_id], 0); |
69191afe | 1100 | mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */ |
8ca151b5 | 1101 | mvm_sta->tfd_queue_msk = 0; |
a0f6bf2a | 1102 | |
e3118ad7 LK |
1103 | /* |
1104 | * Allocate new queues for a TDLS station, unless we're in DQA mode, | |
1105 | * and then they'll be allocated dynamically | |
1106 | */ | |
1107 | if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) { | |
a0f6bf2a AN |
1108 | ret = iwl_mvm_tdls_sta_init(mvm, sta); |
1109 | if (ret) | |
1110 | return ret; | |
24afba76 | 1111 | } else if (!iwl_mvm_is_dqa_supported(mvm)) { |
a0f6bf2a AN |
1112 | for (i = 0; i < IEEE80211_NUM_ACS; i++) |
1113 | if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE) | |
1114 | mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]); | |
1115 | } | |
8ca151b5 | 1116 | |
6d9d32b8 | 1117 | /* for HW restart - reset everything but the sequence number */ |
24afba76 | 1118 | for (i = 0; i <= IWL_MAX_TID_COUNT; i++) { |
6d9d32b8 JB |
1119 | u16 seq = mvm_sta->tid_data[i].seq_number; |
1120 | memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i])); | |
1121 | mvm_sta->tid_data[i].seq_number = seq; | |
24afba76 LK |
1122 | |
1123 | if (!iwl_mvm_is_dqa_supported(mvm)) | |
1124 | continue; | |
1125 | ||
1126 | /* | |
1127 | * Mark all queues for this STA as unallocated and defer TX | |
1128 | * frames until the queue is allocated | |
1129 | */ | |
1130 | mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE; | |
1131 | skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames); | |
6d9d32b8 | 1132 | } |
24afba76 | 1133 | mvm_sta->deferred_traffic_tid_map = 0; |
efed6640 | 1134 | mvm_sta->agg_tids = 0; |
8ca151b5 | 1135 | |
a571f5f6 SS |
1136 | if (iwl_mvm_has_new_rx_api(mvm) && |
1137 | !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { | |
1138 | dup_data = kcalloc(mvm->trans->num_rx_queues, | |
1139 | sizeof(*dup_data), | |
1140 | GFP_KERNEL); | |
1141 | if (!dup_data) | |
1142 | return -ENOMEM; | |
1143 | mvm_sta->dup_data = dup_data; | |
1144 | } | |
1145 | ||
24afba76 | 1146 | if (iwl_mvm_is_dqa_supported(mvm)) { |
d5216a28 LK |
1147 | ret = iwl_mvm_reserve_sta_stream(mvm, sta, |
1148 | ieee80211_vif_type_p2p(vif)); | |
24afba76 LK |
1149 | if (ret) |
1150 | goto err; | |
1151 | } | |
1152 | ||
1153 | ret = iwl_mvm_sta_send_to_fw(mvm, sta, false, 0); | |
8ca151b5 | 1154 | if (ret) |
a0f6bf2a | 1155 | goto err; |
8ca151b5 | 1156 | |
9e848010 JB |
1157 | if (vif->type == NL80211_IFTYPE_STATION) { |
1158 | if (!sta->tdls) { | |
1159 | WARN_ON(mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT); | |
1160 | mvmvif->ap_sta_id = sta_id; | |
1161 | } else { | |
1162 | WARN_ON(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT); | |
1163 | } | |
1164 | } | |
8ca151b5 JB |
1165 | |
1166 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta); | |
1167 | ||
1168 | return 0; | |
a0f6bf2a AN |
1169 | |
1170 | err: | |
e3118ad7 LK |
1171 | if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) |
1172 | iwl_mvm_tdls_sta_deinit(mvm, sta); | |
a0f6bf2a | 1173 | return ret; |
8ca151b5 JB |
1174 | } |
1175 | ||
7a453973 JB |
1176 | int iwl_mvm_update_sta(struct iwl_mvm *mvm, |
1177 | struct ieee80211_vif *vif, | |
1178 | struct ieee80211_sta *sta) | |
1179 | { | |
24afba76 | 1180 | return iwl_mvm_sta_send_to_fw(mvm, sta, true, 0); |
7a453973 JB |
1181 | } |
1182 | ||
8ca151b5 JB |
1183 | int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, |
1184 | bool drain) | |
1185 | { | |
f9dc0004 | 1186 | struct iwl_mvm_add_sta_cmd cmd = {}; |
8ca151b5 JB |
1187 | int ret; |
1188 | u32 status; | |
1189 | ||
1190 | lockdep_assert_held(&mvm->mutex); | |
1191 | ||
1192 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); | |
1193 | cmd.sta_id = mvmsta->sta_id; | |
1194 | cmd.add_modify = STA_MODE_MODIFY; | |
1195 | cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0; | |
1196 | cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW); | |
1197 | ||
1198 | status = ADD_STA_SUCCESS; | |
854c5705 SS |
1199 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
1200 | iwl_mvm_add_sta_cmd_size(mvm), | |
f9dc0004 | 1201 | &cmd, &status); |
8ca151b5 JB |
1202 | if (ret) |
1203 | return ret; | |
1204 | ||
837c4da9 | 1205 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
8ca151b5 JB |
1206 | case ADD_STA_SUCCESS: |
1207 | IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n", | |
1208 | mvmsta->sta_id); | |
1209 | break; | |
1210 | default: | |
1211 | ret = -EIO; | |
1212 | IWL_ERR(mvm, "Couldn't drain frames for staid %d\n", | |
1213 | mvmsta->sta_id); | |
1214 | break; | |
1215 | } | |
1216 | ||
1217 | return ret; | |
1218 | } | |
1219 | ||
1220 | /* | |
1221 | * Remove a station from the FW table. Before sending the command to remove | |
1222 | * the station validate that the station is indeed known to the driver (sanity | |
1223 | * only). | |
1224 | */ | |
1225 | static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id) | |
1226 | { | |
1227 | struct ieee80211_sta *sta; | |
1228 | struct iwl_mvm_rm_sta_cmd rm_sta_cmd = { | |
1229 | .sta_id = sta_id, | |
1230 | }; | |
1231 | int ret; | |
1232 | ||
1233 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
1234 | lockdep_is_held(&mvm->mutex)); | |
1235 | ||
1236 | /* Note: internal stations are marked as error values */ | |
1237 | if (!sta) { | |
1238 | IWL_ERR(mvm, "Invalid station id\n"); | |
1239 | return -EINVAL; | |
1240 | } | |
1241 | ||
a1022927 | 1242 | ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0, |
8ca151b5 JB |
1243 | sizeof(rm_sta_cmd), &rm_sta_cmd); |
1244 | if (ret) { | |
1245 | IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id); | |
1246 | return ret; | |
1247 | } | |
1248 | ||
1249 | return 0; | |
1250 | } | |
1251 | ||
1252 | void iwl_mvm_sta_drained_wk(struct work_struct *wk) | |
1253 | { | |
1254 | struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk); | |
1255 | u8 sta_id; | |
1256 | ||
1257 | /* | |
1258 | * The mutex is needed because of the SYNC cmd, but not only: if the | |
1259 | * work would run concurrently with iwl_mvm_rm_sta, it would run before | |
1260 | * iwl_mvm_rm_sta sets the station as busy, and exit. Then | |
1261 | * iwl_mvm_rm_sta would set the station as busy, and nobody will clean | |
1262 | * that later. | |
1263 | */ | |
1264 | mutex_lock(&mvm->mutex); | |
1265 | ||
1266 | for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) { | |
1267 | int ret; | |
1268 | struct ieee80211_sta *sta = | |
1269 | rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
1270 | lockdep_is_held(&mvm->mutex)); | |
1271 | ||
1ddbbb0c JB |
1272 | /* |
1273 | * This station is in use or RCU-removed; the latter happens in | |
1274 | * managed mode, where mac80211 removes the station before we | |
1275 | * can remove it from firmware (we can only do that after the | |
1276 | * MAC is marked unassociated), and possibly while the deauth | |
1277 | * frame to disconnect from the AP is still queued. Then, the | |
1278 | * station pointer is -ENOENT when the last skb is reclaimed. | |
1279 | */ | |
1280 | if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT) | |
8ca151b5 JB |
1281 | continue; |
1282 | ||
1283 | if (PTR_ERR(sta) == -EINVAL) { | |
1284 | IWL_ERR(mvm, "Drained sta %d, but it is internal?\n", | |
1285 | sta_id); | |
1286 | continue; | |
1287 | } | |
1288 | ||
1289 | if (!sta) { | |
1290 | IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n", | |
1291 | sta_id); | |
1292 | continue; | |
1293 | } | |
1294 | ||
1295 | WARN_ON(PTR_ERR(sta) != -EBUSY); | |
1296 | /* This station was removed and we waited until it got drained, | |
1297 | * we can now proceed and remove it. | |
1298 | */ | |
1299 | ret = iwl_mvm_rm_sta_common(mvm, sta_id); | |
1300 | if (ret) { | |
1301 | IWL_ERR(mvm, | |
1302 | "Couldn't remove sta %d after it was drained\n", | |
1303 | sta_id); | |
1304 | continue; | |
1305 | } | |
c531c771 | 1306 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
8ca151b5 | 1307 | clear_bit(sta_id, mvm->sta_drained); |
a0f6bf2a AN |
1308 | |
1309 | if (mvm->tfd_drained[sta_id]) { | |
1310 | unsigned long i, msk = mvm->tfd_drained[sta_id]; | |
1311 | ||
a4ca3ed4 | 1312 | for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE) |
06ecdba3 AN |
1313 | iwl_mvm_disable_txq(mvm, i, i, |
1314 | IWL_MAX_TID_COUNT, 0); | |
a0f6bf2a AN |
1315 | |
1316 | mvm->tfd_drained[sta_id] = 0; | |
1317 | IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n", | |
1318 | sta_id, msk); | |
1319 | } | |
8ca151b5 JB |
1320 | } |
1321 | ||
1322 | mutex_unlock(&mvm->mutex); | |
1323 | } | |
1324 | ||
24afba76 LK |
1325 | static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm, |
1326 | struct ieee80211_vif *vif, | |
1327 | struct iwl_mvm_sta *mvm_sta) | |
1328 | { | |
1329 | int ac; | |
1330 | int i; | |
1331 | ||
1332 | lockdep_assert_held(&mvm->mutex); | |
1333 | ||
1334 | for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) { | |
1335 | if (mvm_sta->tid_data[i].txq_id == IEEE80211_INVAL_HW_QUEUE) | |
1336 | continue; | |
1337 | ||
1338 | ac = iwl_mvm_tid_to_ac_queue(i); | |
1339 | iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id, | |
1340 | vif->hw_queue[ac], i, 0); | |
1341 | mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE; | |
1342 | } | |
1343 | } | |
1344 | ||
8ca151b5 JB |
1345 | int iwl_mvm_rm_sta(struct iwl_mvm *mvm, |
1346 | struct ieee80211_vif *vif, | |
1347 | struct ieee80211_sta *sta) | |
1348 | { | |
1349 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
9d8ce6af | 1350 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
1351 | int ret; |
1352 | ||
1353 | lockdep_assert_held(&mvm->mutex); | |
1354 | ||
a571f5f6 SS |
1355 | if (iwl_mvm_has_new_rx_api(mvm)) |
1356 | kfree(mvm_sta->dup_data); | |
1357 | ||
a6f035a0 LK |
1358 | if ((vif->type == NL80211_IFTYPE_STATION && |
1359 | mvmvif->ap_sta_id == mvm_sta->sta_id) || | |
1360 | iwl_mvm_is_dqa_supported(mvm)){ | |
fe92e32a EG |
1361 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
1362 | if (ret) | |
1363 | return ret; | |
80d85655 | 1364 | /* flush its queues here since we are freeing mvm_sta */ |
5888a40c | 1365 | ret = iwl_mvm_flush_tx_path(mvm, mvm_sta->tfd_queue_msk, 0); |
fe92e32a EG |
1366 | if (ret) |
1367 | return ret; | |
1368 | ret = iwl_trans_wait_tx_queue_empty(mvm->trans, | |
1369 | mvm_sta->tfd_queue_msk); | |
1370 | if (ret) | |
1371 | return ret; | |
1372 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, false); | |
80d85655 | 1373 | |
24afba76 LK |
1374 | /* If DQA is supported - the queues can be disabled now */ |
1375 | if (iwl_mvm_is_dqa_supported(mvm)) | |
1376 | iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta); | |
1377 | ||
e3118ad7 LK |
1378 | if (vif->type == NL80211_IFTYPE_STATION && |
1379 | mvmvif->ap_sta_id == mvm_sta->sta_id) { | |
1380 | /* if associated - we can't remove the AP STA now */ | |
1381 | if (vif->bss_conf.assoc) | |
1382 | return ret; | |
8ca151b5 | 1383 | |
e3118ad7 LK |
1384 | /* unassoc - go ahead - remove the AP STA now */ |
1385 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; | |
37577fe2 | 1386 | |
e3118ad7 LK |
1387 | /* clear d0i3_ap_sta_id if no longer relevant */ |
1388 | if (mvm->d0i3_ap_sta_id == mvm_sta->sta_id) | |
1389 | mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT; | |
1390 | } | |
8ca151b5 JB |
1391 | } |
1392 | ||
1d3c3f63 AN |
1393 | /* |
1394 | * This shouldn't happen - the TDLS channel switch should be canceled | |
1395 | * before the STA is removed. | |
1396 | */ | |
1397 | if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == mvm_sta->sta_id)) { | |
1398 | mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT; | |
1399 | cancel_delayed_work(&mvm->tdls_cs.dwork); | |
1400 | } | |
1401 | ||
e3d4bc8c EG |
1402 | /* |
1403 | * Make sure that the tx response code sees the station as -EBUSY and | |
1404 | * calls the drain worker. | |
1405 | */ | |
1406 | spin_lock_bh(&mvm_sta->lock); | |
8ca151b5 JB |
1407 | /* |
1408 | * There are frames pending on the AC queues for this station. | |
1409 | * We need to wait until all the frames are drained... | |
1410 | */ | |
e3d4bc8c | 1411 | if (atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) { |
8ca151b5 JB |
1412 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], |
1413 | ERR_PTR(-EBUSY)); | |
e3d4bc8c | 1414 | spin_unlock_bh(&mvm_sta->lock); |
a0f6bf2a AN |
1415 | |
1416 | /* disable TDLS sta queues on drain complete */ | |
1417 | if (sta->tdls) { | |
1418 | mvm->tfd_drained[mvm_sta->sta_id] = | |
1419 | mvm_sta->tfd_queue_msk; | |
1420 | IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n", | |
1421 | mvm_sta->sta_id); | |
1422 | } | |
1423 | ||
e3d4bc8c | 1424 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
8ca151b5 | 1425 | } else { |
e3d4bc8c | 1426 | spin_unlock_bh(&mvm_sta->lock); |
a0f6bf2a | 1427 | |
e3118ad7 | 1428 | if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) |
a0f6bf2a AN |
1429 | iwl_mvm_tdls_sta_deinit(mvm, sta); |
1430 | ||
8ca151b5 | 1431 | ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id); |
c531c771 | 1432 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL); |
8ca151b5 JB |
1433 | } |
1434 | ||
1435 | return ret; | |
1436 | } | |
1437 | ||
1438 | int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm, | |
1439 | struct ieee80211_vif *vif, | |
1440 | u8 sta_id) | |
1441 | { | |
1442 | int ret = iwl_mvm_rm_sta_common(mvm, sta_id); | |
1443 | ||
1444 | lockdep_assert_held(&mvm->mutex); | |
1445 | ||
c531c771 | 1446 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
8ca151b5 JB |
1447 | return ret; |
1448 | } | |
1449 | ||
0e39eb03 CRI |
1450 | int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm, |
1451 | struct iwl_mvm_int_sta *sta, | |
1452 | u32 qmask, enum nl80211_iftype iftype) | |
8ca151b5 JB |
1453 | { |
1454 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { | |
b92e661b | 1455 | sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype); |
8ca151b5 JB |
1456 | if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_STATION_COUNT)) |
1457 | return -ENOSPC; | |
1458 | } | |
1459 | ||
1460 | sta->tfd_queue_msk = qmask; | |
1461 | ||
1462 | /* put a non-NULL value so iterating over the stations won't stop */ | |
1463 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL)); | |
1464 | return 0; | |
1465 | } | |
1466 | ||
712b24ad JB |
1467 | static void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm, |
1468 | struct iwl_mvm_int_sta *sta) | |
8ca151b5 | 1469 | { |
c531c771 | 1470 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta->sta_id], NULL); |
8ca151b5 JB |
1471 | memset(sta, 0, sizeof(struct iwl_mvm_int_sta)); |
1472 | sta->sta_id = IWL_MVM_STATION_COUNT; | |
1473 | } | |
1474 | ||
1475 | static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm, | |
1476 | struct iwl_mvm_int_sta *sta, | |
1477 | const u8 *addr, | |
1478 | u16 mac_id, u16 color) | |
1479 | { | |
f9dc0004 | 1480 | struct iwl_mvm_add_sta_cmd cmd; |
8ca151b5 JB |
1481 | int ret; |
1482 | u32 status; | |
1483 | ||
1484 | lockdep_assert_held(&mvm->mutex); | |
1485 | ||
f9dc0004 | 1486 | memset(&cmd, 0, sizeof(cmd)); |
8ca151b5 JB |
1487 | cmd.sta_id = sta->sta_id; |
1488 | cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id, | |
1489 | color)); | |
1490 | ||
1491 | cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk); | |
cf0cda19 | 1492 | cmd.tid_disable_tx = cpu_to_le16(0xffff); |
8ca151b5 JB |
1493 | |
1494 | if (addr) | |
1495 | memcpy(cmd.addr, addr, ETH_ALEN); | |
1496 | ||
854c5705 SS |
1497 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
1498 | iwl_mvm_add_sta_cmd_size(mvm), | |
f9dc0004 | 1499 | &cmd, &status); |
8ca151b5 JB |
1500 | if (ret) |
1501 | return ret; | |
1502 | ||
837c4da9 | 1503 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
8ca151b5 JB |
1504 | case ADD_STA_SUCCESS: |
1505 | IWL_DEBUG_INFO(mvm, "Internal station added.\n"); | |
1506 | return 0; | |
1507 | default: | |
1508 | ret = -EIO; | |
1509 | IWL_ERR(mvm, "Add internal station failed, status=0x%x\n", | |
1510 | status); | |
1511 | break; | |
1512 | } | |
1513 | return ret; | |
1514 | } | |
1515 | ||
1516 | int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm) | |
1517 | { | |
4cf677fd EG |
1518 | unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ? |
1519 | mvm->cfg->base_params->wd_timeout : | |
1520 | IWL_WATCHDOG_DISABLED; | |
8ca151b5 JB |
1521 | int ret; |
1522 | ||
1523 | lockdep_assert_held(&mvm->mutex); | |
1524 | ||
7da91b0e | 1525 | /* Map Aux queue to fifo - needs to happen before adding Aux station */ |
28d0793e LK |
1526 | if (!iwl_mvm_is_dqa_supported(mvm)) |
1527 | iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue, | |
1528 | IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout); | |
7da91b0e AM |
1529 | |
1530 | /* Allocate aux station and assign to it the aux queue */ | |
1531 | ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue), | |
b92e661b | 1532 | NL80211_IFTYPE_UNSPECIFIED); |
8ca151b5 JB |
1533 | if (ret) |
1534 | return ret; | |
1535 | ||
28d0793e LK |
1536 | if (iwl_mvm_is_dqa_supported(mvm)) { |
1537 | struct iwl_trans_txq_scd_cfg cfg = { | |
1538 | .fifo = IWL_MVM_TX_FIFO_MCAST, | |
1539 | .sta_id = mvm->aux_sta.sta_id, | |
1540 | .tid = IWL_MAX_TID_COUNT, | |
1541 | .aggregate = false, | |
1542 | .frame_limit = IWL_FRAME_LIMIT, | |
1543 | }; | |
1544 | ||
1545 | iwl_mvm_enable_txq(mvm, mvm->aux_queue, mvm->aux_queue, 0, &cfg, | |
1546 | wdg_timeout); | |
1547 | } | |
1548 | ||
8ca151b5 JB |
1549 | ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL, |
1550 | MAC_INDEX_AUX, 0); | |
1551 | ||
1552 | if (ret) | |
1553 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); | |
1554 | return ret; | |
1555 | } | |
1556 | ||
0e39eb03 CRI |
1557 | int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
1558 | { | |
1559 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1560 | ||
1561 | lockdep_assert_held(&mvm->mutex); | |
1562 | return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr, | |
1563 | mvmvif->id, 0); | |
1564 | } | |
1565 | ||
1566 | int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) | |
1567 | { | |
1568 | int ret; | |
1569 | ||
1570 | lockdep_assert_held(&mvm->mutex); | |
1571 | ||
1572 | ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id); | |
1573 | if (ret) | |
1574 | IWL_WARN(mvm, "Failed sending remove station\n"); | |
1575 | ||
1576 | return ret; | |
1577 | } | |
1578 | ||
1579 | void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm) | |
1580 | { | |
1581 | iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta); | |
1582 | } | |
1583 | ||
712b24ad JB |
1584 | void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm) |
1585 | { | |
1586 | lockdep_assert_held(&mvm->mutex); | |
1587 | ||
1588 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); | |
1589 | } | |
1590 | ||
8ca151b5 JB |
1591 | /* |
1592 | * Send the add station command for the vif's broadcast station. | |
1593 | * Assumes that the station was already allocated. | |
1594 | * | |
1595 | * @mvm: the mvm component | |
1596 | * @vif: the interface to which the broadcast station is added | |
1597 | * @bsta: the broadcast station to add. | |
1598 | */ | |
013290aa | 1599 | int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
8ca151b5 JB |
1600 | { |
1601 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
013290aa | 1602 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
5023d966 | 1603 | static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
a4243402 | 1604 | const u8 *baddr = _baddr; |
8ca151b5 JB |
1605 | |
1606 | lockdep_assert_held(&mvm->mutex); | |
1607 | ||
de24f638 LK |
1608 | if (iwl_mvm_is_dqa_supported(mvm)) { |
1609 | struct iwl_trans_txq_scd_cfg cfg = { | |
1610 | .fifo = IWL_MVM_TX_FIFO_VO, | |
1611 | .sta_id = mvmvif->bcast_sta.sta_id, | |
1612 | .tid = IWL_MAX_TID_COUNT, | |
1613 | .aggregate = false, | |
1614 | .frame_limit = IWL_FRAME_LIMIT, | |
1615 | }; | |
1616 | unsigned int wdg_timeout = | |
1617 | iwl_mvm_get_wd_timeout(mvm, vif, false, false); | |
1618 | int queue; | |
1619 | ||
1620 | if ((vif->type == NL80211_IFTYPE_AP) && | |
1621 | (mvmvif->bcast_sta.tfd_queue_msk & | |
1622 | BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE))) | |
1623 | queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE; | |
4c965139 LK |
1624 | else if ((vif->type == NL80211_IFTYPE_P2P_DEVICE) && |
1625 | (mvmvif->bcast_sta.tfd_queue_msk & | |
1626 | BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE))) | |
1627 | queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE; | |
de24f638 LK |
1628 | else if (WARN(1, "Missed required TXQ for adding bcast STA\n")) |
1629 | return -EINVAL; | |
1630 | ||
1631 | iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[0], 0, &cfg, | |
1632 | wdg_timeout); | |
1633 | } | |
1634 | ||
5023d966 JB |
1635 | if (vif->type == NL80211_IFTYPE_ADHOC) |
1636 | baddr = vif->bss_conf.bssid; | |
1637 | ||
8ca151b5 JB |
1638 | if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_STATION_COUNT)) |
1639 | return -ENOSPC; | |
1640 | ||
1641 | return iwl_mvm_add_int_sta_common(mvm, bsta, baddr, | |
1642 | mvmvif->id, mvmvif->color); | |
1643 | } | |
1644 | ||
1645 | /* Send the FW a request to remove the station from it's internal data | |
1646 | * structures, but DO NOT remove the entry from the local data structures. */ | |
013290aa | 1647 | int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
8ca151b5 | 1648 | { |
013290aa | 1649 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
8ca151b5 JB |
1650 | int ret; |
1651 | ||
1652 | lockdep_assert_held(&mvm->mutex); | |
1653 | ||
013290aa | 1654 | ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id); |
8ca151b5 JB |
1655 | if (ret) |
1656 | IWL_WARN(mvm, "Failed sending remove station\n"); | |
1657 | return ret; | |
1658 | } | |
1659 | ||
013290aa JB |
1660 | int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
1661 | { | |
1662 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
de24f638 | 1663 | u32 qmask = 0; |
013290aa JB |
1664 | |
1665 | lockdep_assert_held(&mvm->mutex); | |
1666 | ||
de24f638 LK |
1667 | if (!iwl_mvm_is_dqa_supported(mvm)) |
1668 | qmask = iwl_mvm_mac_get_queues_mask(vif); | |
013290aa | 1669 | |
de24f638 LK |
1670 | if (vif->type == NL80211_IFTYPE_AP) { |
1671 | /* | |
1672 | * The firmware defines the TFD queue mask to only be relevant | |
1673 | * for *unicast* queues, so the multicast (CAB) queue shouldn't | |
1674 | * be included. | |
1675 | */ | |
013290aa JB |
1676 | qmask &= ~BIT(vif->cab_queue); |
1677 | ||
de24f638 LK |
1678 | if (iwl_mvm_is_dqa_supported(mvm)) |
1679 | qmask |= BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE); | |
4c965139 LK |
1680 | } else if (iwl_mvm_is_dqa_supported(mvm) && |
1681 | vif->type == NL80211_IFTYPE_P2P_DEVICE) { | |
1682 | qmask |= BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE); | |
de24f638 LK |
1683 | } |
1684 | ||
013290aa JB |
1685 | return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask, |
1686 | ieee80211_vif_type_p2p(vif)); | |
1687 | } | |
1688 | ||
8ca151b5 JB |
1689 | /* Allocate a new station entry for the broadcast station to the given vif, |
1690 | * and send it to the FW. | |
1691 | * Note that each P2P mac should have its own broadcast station. | |
1692 | * | |
1693 | * @mvm: the mvm component | |
1694 | * @vif: the interface to which the broadcast station is added | |
1695 | * @bsta: the broadcast station to add. */ | |
013290aa | 1696 | int iwl_mvm_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
8ca151b5 JB |
1697 | { |
1698 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
013290aa | 1699 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
8ca151b5 JB |
1700 | int ret; |
1701 | ||
1702 | lockdep_assert_held(&mvm->mutex); | |
1703 | ||
013290aa | 1704 | ret = iwl_mvm_alloc_bcast_sta(mvm, vif); |
8ca151b5 JB |
1705 | if (ret) |
1706 | return ret; | |
1707 | ||
013290aa | 1708 | ret = iwl_mvm_send_add_bcast_sta(mvm, vif); |
8ca151b5 JB |
1709 | |
1710 | if (ret) | |
1711 | iwl_mvm_dealloc_int_sta(mvm, bsta); | |
013290aa | 1712 | |
8ca151b5 JB |
1713 | return ret; |
1714 | } | |
1715 | ||
013290aa JB |
1716 | void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
1717 | { | |
1718 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1719 | ||
1720 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); | |
1721 | } | |
1722 | ||
8ca151b5 JB |
1723 | /* |
1724 | * Send the FW a request to remove the station from it's internal data | |
1725 | * structures, and in addition remove it from the local data structure. | |
1726 | */ | |
013290aa | 1727 | int iwl_mvm_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
8ca151b5 JB |
1728 | { |
1729 | int ret; | |
1730 | ||
1731 | lockdep_assert_held(&mvm->mutex); | |
1732 | ||
013290aa JB |
1733 | ret = iwl_mvm_send_rm_bcast_sta(mvm, vif); |
1734 | ||
1735 | iwl_mvm_dealloc_bcast_sta(mvm, vif); | |
8ca151b5 | 1736 | |
8ca151b5 JB |
1737 | return ret; |
1738 | } | |
1739 | ||
113a0447 EG |
1740 | #define IWL_MAX_RX_BA_SESSIONS 16 |
1741 | ||
b915c101 | 1742 | static void iwl_mvm_sync_rxq_del_ba(struct iwl_mvm *mvm, u8 baid) |
10b2b201 | 1743 | { |
b915c101 SS |
1744 | struct iwl_mvm_delba_notif notif = { |
1745 | .metadata.type = IWL_MVM_RXQ_NOTIF_DEL_BA, | |
1746 | .metadata.sync = 1, | |
1747 | .delba.baid = baid, | |
10b2b201 | 1748 | }; |
b915c101 SS |
1749 | iwl_mvm_sync_rx_queues_internal(mvm, (void *)¬if, sizeof(notif)); |
1750 | }; | |
10b2b201 | 1751 | |
b915c101 SS |
1752 | static void iwl_mvm_free_reorder(struct iwl_mvm *mvm, |
1753 | struct iwl_mvm_baid_data *data) | |
1754 | { | |
1755 | int i; | |
1756 | ||
1757 | iwl_mvm_sync_rxq_del_ba(mvm, data->baid); | |
1758 | ||
1759 | for (i = 0; i < mvm->trans->num_rx_queues; i++) { | |
1760 | int j; | |
1761 | struct iwl_mvm_reorder_buffer *reorder_buf = | |
1762 | &data->reorder_buf[i]; | |
1763 | ||
0690405f SS |
1764 | spin_lock_bh(&reorder_buf->lock); |
1765 | if (likely(!reorder_buf->num_stored)) { | |
1766 | spin_unlock_bh(&reorder_buf->lock); | |
b915c101 | 1767 | continue; |
0690405f | 1768 | } |
b915c101 SS |
1769 | |
1770 | /* | |
1771 | * This shouldn't happen in regular DELBA since the internal | |
1772 | * delBA notification should trigger a release of all frames in | |
1773 | * the reorder buffer. | |
1774 | */ | |
1775 | WARN_ON(1); | |
1776 | ||
1777 | for (j = 0; j < reorder_buf->buf_size; j++) | |
1778 | __skb_queue_purge(&reorder_buf->entries[j]); | |
0690405f SS |
1779 | /* |
1780 | * Prevent timer re-arm. This prevents a very far fetched case | |
1781 | * where we timed out on the notification. There may be prior | |
1782 | * RX frames pending in the RX queue before the notification | |
1783 | * that might get processed between now and the actual deletion | |
1784 | * and we would re-arm the timer although we are deleting the | |
1785 | * reorder buffer. | |
1786 | */ | |
1787 | reorder_buf->removed = true; | |
1788 | spin_unlock_bh(&reorder_buf->lock); | |
1789 | del_timer_sync(&reorder_buf->reorder_timer); | |
b915c101 SS |
1790 | } |
1791 | } | |
1792 | ||
1793 | static void iwl_mvm_init_reorder_buffer(struct iwl_mvm *mvm, | |
1794 | u32 sta_id, | |
1795 | struct iwl_mvm_baid_data *data, | |
1796 | u16 ssn, u8 buf_size) | |
1797 | { | |
1798 | int i; | |
1799 | ||
1800 | for (i = 0; i < mvm->trans->num_rx_queues; i++) { | |
1801 | struct iwl_mvm_reorder_buffer *reorder_buf = | |
1802 | &data->reorder_buf[i]; | |
1803 | int j; | |
1804 | ||
1805 | reorder_buf->num_stored = 0; | |
1806 | reorder_buf->head_sn = ssn; | |
1807 | reorder_buf->buf_size = buf_size; | |
0690405f SS |
1808 | /* rx reorder timer */ |
1809 | reorder_buf->reorder_timer.function = | |
1810 | iwl_mvm_reorder_timer_expired; | |
1811 | reorder_buf->reorder_timer.data = (unsigned long)reorder_buf; | |
1812 | init_timer(&reorder_buf->reorder_timer); | |
1813 | spin_lock_init(&reorder_buf->lock); | |
1814 | reorder_buf->mvm = mvm; | |
b915c101 SS |
1815 | reorder_buf->queue = i; |
1816 | reorder_buf->sta_id = sta_id; | |
1817 | for (j = 0; j < reorder_buf->buf_size; j++) | |
1818 | __skb_queue_head_init(&reorder_buf->entries[j]); | |
1819 | } | |
10b2b201 SS |
1820 | } |
1821 | ||
8ca151b5 | 1822 | int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
10b2b201 | 1823 | int tid, u16 ssn, bool start, u8 buf_size, u16 timeout) |
8ca151b5 | 1824 | { |
9d8ce6af | 1825 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
f9dc0004 | 1826 | struct iwl_mvm_add_sta_cmd cmd = {}; |
10b2b201 | 1827 | struct iwl_mvm_baid_data *baid_data = NULL; |
8ca151b5 JB |
1828 | int ret; |
1829 | u32 status; | |
1830 | ||
1831 | lockdep_assert_held(&mvm->mutex); | |
1832 | ||
113a0447 EG |
1833 | if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) { |
1834 | IWL_WARN(mvm, "Not enough RX BA SESSIONS\n"); | |
1835 | return -ENOSPC; | |
1836 | } | |
1837 | ||
10b2b201 SS |
1838 | if (iwl_mvm_has_new_rx_api(mvm) && start) { |
1839 | /* | |
1840 | * Allocate here so if allocation fails we can bail out early | |
1841 | * before starting the BA session in the firmware | |
1842 | */ | |
b915c101 SS |
1843 | baid_data = kzalloc(sizeof(*baid_data) + |
1844 | mvm->trans->num_rx_queues * | |
1845 | sizeof(baid_data->reorder_buf[0]), | |
1846 | GFP_KERNEL); | |
10b2b201 SS |
1847 | if (!baid_data) |
1848 | return -ENOMEM; | |
1849 | } | |
1850 | ||
8ca151b5 JB |
1851 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
1852 | cmd.sta_id = mvm_sta->sta_id; | |
1853 | cmd.add_modify = STA_MODE_MODIFY; | |
93a42667 EG |
1854 | if (start) { |
1855 | cmd.add_immediate_ba_tid = (u8) tid; | |
1856 | cmd.add_immediate_ba_ssn = cpu_to_le16(ssn); | |
854c5705 | 1857 | cmd.rx_ba_window = cpu_to_le16((u16)buf_size); |
93a42667 EG |
1858 | } else { |
1859 | cmd.remove_immediate_ba_tid = (u8) tid; | |
1860 | } | |
8ca151b5 JB |
1861 | cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID : |
1862 | STA_MODIFY_REMOVE_BA_TID; | |
1863 | ||
1864 | status = ADD_STA_SUCCESS; | |
854c5705 SS |
1865 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
1866 | iwl_mvm_add_sta_cmd_size(mvm), | |
f9dc0004 | 1867 | &cmd, &status); |
8ca151b5 | 1868 | if (ret) |
10b2b201 | 1869 | goto out_free; |
8ca151b5 | 1870 | |
837c4da9 | 1871 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
8ca151b5 | 1872 | case ADD_STA_SUCCESS: |
35263a03 SS |
1873 | IWL_DEBUG_HT(mvm, "RX BA Session %sed in fw\n", |
1874 | start ? "start" : "stopp"); | |
8ca151b5 JB |
1875 | break; |
1876 | case ADD_STA_IMMEDIATE_BA_FAILURE: | |
1877 | IWL_WARN(mvm, "RX BA Session refused by fw\n"); | |
1878 | ret = -ENOSPC; | |
1879 | break; | |
1880 | default: | |
1881 | ret = -EIO; | |
1882 | IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n", | |
1883 | start ? "start" : "stopp", status); | |
1884 | break; | |
1885 | } | |
1886 | ||
10b2b201 SS |
1887 | if (ret) |
1888 | goto out_free; | |
1889 | ||
1890 | if (start) { | |
1891 | u8 baid; | |
1892 | ||
1893 | mvm->rx_ba_sessions++; | |
1894 | ||
1895 | if (!iwl_mvm_has_new_rx_api(mvm)) | |
1896 | return 0; | |
1897 | ||
1898 | if (WARN_ON(!(status & IWL_ADD_STA_BAID_VALID_MASK))) { | |
1899 | ret = -EINVAL; | |
1900 | goto out_free; | |
1901 | } | |
1902 | baid = (u8)((status & IWL_ADD_STA_BAID_MASK) >> | |
1903 | IWL_ADD_STA_BAID_SHIFT); | |
1904 | baid_data->baid = baid; | |
1905 | baid_data->timeout = timeout; | |
1906 | baid_data->last_rx = jiffies; | |
1907 | init_timer(&baid_data->session_timer); | |
1908 | baid_data->session_timer.function = | |
1909 | iwl_mvm_rx_agg_session_expired; | |
1910 | baid_data->session_timer.data = | |
1911 | (unsigned long)&mvm->baid_map[baid]; | |
1912 | baid_data->mvm = mvm; | |
1913 | baid_data->tid = tid; | |
1914 | baid_data->sta_id = mvm_sta->sta_id; | |
1915 | ||
1916 | mvm_sta->tid_to_baid[tid] = baid; | |
1917 | if (timeout) | |
1918 | mod_timer(&baid_data->session_timer, | |
1919 | TU_TO_EXP_TIME(timeout * 2)); | |
1920 | ||
b915c101 SS |
1921 | iwl_mvm_init_reorder_buffer(mvm, mvm_sta->sta_id, |
1922 | baid_data, ssn, buf_size); | |
10b2b201 SS |
1923 | /* |
1924 | * protect the BA data with RCU to cover a case where our | |
1925 | * internal RX sync mechanism will timeout (not that it's | |
1926 | * supposed to happen) and we will free the session data while | |
1927 | * RX is being processed in parallel | |
1928 | */ | |
35263a03 SS |
1929 | IWL_DEBUG_HT(mvm, "Sta %d(%d) is assigned to BAID %d\n", |
1930 | mvm_sta->sta_id, tid, baid); | |
10b2b201 SS |
1931 | WARN_ON(rcu_access_pointer(mvm->baid_map[baid])); |
1932 | rcu_assign_pointer(mvm->baid_map[baid], baid_data); | |
60dec523 | 1933 | } else { |
10b2b201 SS |
1934 | u8 baid = mvm_sta->tid_to_baid[tid]; |
1935 | ||
60dec523 SS |
1936 | if (mvm->rx_ba_sessions > 0) |
1937 | /* check that restart flow didn't zero the counter */ | |
1938 | mvm->rx_ba_sessions--; | |
10b2b201 SS |
1939 | if (!iwl_mvm_has_new_rx_api(mvm)) |
1940 | return 0; | |
1941 | ||
1942 | if (WARN_ON(baid == IWL_RX_REORDER_DATA_INVALID_BAID)) | |
1943 | return -EINVAL; | |
1944 | ||
1945 | baid_data = rcu_access_pointer(mvm->baid_map[baid]); | |
1946 | if (WARN_ON(!baid_data)) | |
1947 | return -EINVAL; | |
1948 | ||
1949 | /* synchronize all rx queues so we can safely delete */ | |
b915c101 | 1950 | iwl_mvm_free_reorder(mvm, baid_data); |
10b2b201 | 1951 | del_timer_sync(&baid_data->session_timer); |
10b2b201 SS |
1952 | RCU_INIT_POINTER(mvm->baid_map[baid], NULL); |
1953 | kfree_rcu(baid_data, rcu_head); | |
35263a03 | 1954 | IWL_DEBUG_HT(mvm, "BAID %d is free\n", baid); |
113a0447 | 1955 | } |
10b2b201 | 1956 | return 0; |
113a0447 | 1957 | |
10b2b201 SS |
1958 | out_free: |
1959 | kfree(baid_data); | |
8ca151b5 JB |
1960 | return ret; |
1961 | } | |
1962 | ||
9794c64f LK |
1963 | int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
1964 | int tid, u8 queue, bool start) | |
8ca151b5 | 1965 | { |
9d8ce6af | 1966 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
f9dc0004 | 1967 | struct iwl_mvm_add_sta_cmd cmd = {}; |
8ca151b5 JB |
1968 | int ret; |
1969 | u32 status; | |
1970 | ||
1971 | lockdep_assert_held(&mvm->mutex); | |
1972 | ||
1973 | if (start) { | |
1974 | mvm_sta->tfd_queue_msk |= BIT(queue); | |
1975 | mvm_sta->tid_disable_agg &= ~BIT(tid); | |
1976 | } else { | |
cf961e16 LK |
1977 | /* In DQA-mode the queue isn't removed on agg termination */ |
1978 | if (!iwl_mvm_is_dqa_supported(mvm)) | |
1979 | mvm_sta->tfd_queue_msk &= ~BIT(queue); | |
8ca151b5 JB |
1980 | mvm_sta->tid_disable_agg |= BIT(tid); |
1981 | } | |
1982 | ||
1983 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); | |
1984 | cmd.sta_id = mvm_sta->sta_id; | |
1985 | cmd.add_modify = STA_MODE_MODIFY; | |
1986 | cmd.modify_mask = STA_MODIFY_QUEUES | STA_MODIFY_TID_DISABLE_TX; | |
1987 | cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); | |
1988 | cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg); | |
1989 | ||
1990 | status = ADD_STA_SUCCESS; | |
854c5705 SS |
1991 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
1992 | iwl_mvm_add_sta_cmd_size(mvm), | |
f9dc0004 | 1993 | &cmd, &status); |
8ca151b5 JB |
1994 | if (ret) |
1995 | return ret; | |
1996 | ||
837c4da9 | 1997 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
8ca151b5 JB |
1998 | case ADD_STA_SUCCESS: |
1999 | break; | |
2000 | default: | |
2001 | ret = -EIO; | |
2002 | IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n", | |
2003 | start ? "start" : "stopp", status); | |
2004 | break; | |
2005 | } | |
2006 | ||
2007 | return ret; | |
2008 | } | |
2009 | ||
b797e3fb | 2010 | const u8 tid_to_mac80211_ac[] = { |
8ca151b5 JB |
2011 | IEEE80211_AC_BE, |
2012 | IEEE80211_AC_BK, | |
2013 | IEEE80211_AC_BK, | |
2014 | IEEE80211_AC_BE, | |
2015 | IEEE80211_AC_VI, | |
2016 | IEEE80211_AC_VI, | |
2017 | IEEE80211_AC_VO, | |
2018 | IEEE80211_AC_VO, | |
9794c64f | 2019 | IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */ |
8ca151b5 JB |
2020 | }; |
2021 | ||
3e56eadf JB |
2022 | static const u8 tid_to_ucode_ac[] = { |
2023 | AC_BE, | |
2024 | AC_BK, | |
2025 | AC_BK, | |
2026 | AC_BE, | |
2027 | AC_VI, | |
2028 | AC_VI, | |
2029 | AC_VO, | |
2030 | AC_VO, | |
2031 | }; | |
2032 | ||
8ca151b5 JB |
2033 | int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
2034 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) | |
2035 | { | |
5b577a90 | 2036 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
2037 | struct iwl_mvm_tid_data *tid_data; |
2038 | int txq_id; | |
4ecafae9 | 2039 | int ret; |
8ca151b5 JB |
2040 | |
2041 | if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) | |
2042 | return -EINVAL; | |
2043 | ||
2044 | if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) { | |
2045 | IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n", | |
2046 | mvmsta->tid_data[tid].state); | |
2047 | return -ENXIO; | |
2048 | } | |
2049 | ||
2050 | lockdep_assert_held(&mvm->mutex); | |
2051 | ||
b2492501 AN |
2052 | spin_lock_bh(&mvmsta->lock); |
2053 | ||
2054 | /* possible race condition - we entered D0i3 while starting agg */ | |
2055 | if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) { | |
2056 | spin_unlock_bh(&mvmsta->lock); | |
2057 | IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n"); | |
2058 | return -EIO; | |
2059 | } | |
2060 | ||
9f9af3d7 | 2061 | spin_lock(&mvm->queue_info_lock); |
4ecafae9 | 2062 | |
cf961e16 LK |
2063 | /* |
2064 | * Note the possible cases: | |
2065 | * 1. In DQA mode with an enabled TXQ - TXQ needs to become agg'ed | |
2066 | * 2. Non-DQA mode: the TXQ hasn't yet been enabled, so find a free | |
2067 | * one and mark it as reserved | |
2068 | * 3. In DQA mode, but no traffic yet on this TID: same treatment as in | |
2069 | * non-DQA mode, since the TXQ hasn't yet been allocated | |
2070 | */ | |
2071 | txq_id = mvmsta->tid_data[tid].txq_id; | |
9f9af3d7 LK |
2072 | if (iwl_mvm_is_dqa_supported(mvm) && |
2073 | unlikely(mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_SHARED)) { | |
2074 | ret = -ENXIO; | |
2075 | IWL_DEBUG_TX_QUEUES(mvm, | |
2076 | "Can't start tid %d agg on shared queue!\n", | |
2077 | tid); | |
2078 | goto release_locks; | |
2079 | } else if (!iwl_mvm_is_dqa_supported(mvm) || | |
cf961e16 | 2080 | mvm->queue_info[txq_id].status != IWL_MVM_QUEUE_READY) { |
9794c64f LK |
2081 | txq_id = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, |
2082 | mvm->first_agg_queue, | |
cf961e16 LK |
2083 | mvm->last_agg_queue); |
2084 | if (txq_id < 0) { | |
2085 | ret = txq_id; | |
cf961e16 LK |
2086 | IWL_ERR(mvm, "Failed to allocate agg queue\n"); |
2087 | goto release_locks; | |
2088 | } | |
2089 | ||
2090 | /* TXQ hasn't yet been enabled, so mark it only as reserved */ | |
2091 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_RESERVED; | |
4ecafae9 | 2092 | } |
9f9af3d7 LK |
2093 | |
2094 | spin_unlock(&mvm->queue_info_lock); | |
8ca151b5 | 2095 | |
cf961e16 LK |
2096 | IWL_DEBUG_TX_QUEUES(mvm, |
2097 | "AGG for tid %d will be on queue #%d\n", | |
2098 | tid, txq_id); | |
2099 | ||
8ca151b5 | 2100 | tid_data = &mvmsta->tid_data[tid]; |
9a886586 | 2101 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
8ca151b5 JB |
2102 | tid_data->txq_id = txq_id; |
2103 | *ssn = tid_data->ssn; | |
2104 | ||
2105 | IWL_DEBUG_TX_QUEUES(mvm, | |
2106 | "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n", | |
2107 | mvmsta->sta_id, tid, txq_id, tid_data->ssn, | |
2108 | tid_data->next_reclaimed); | |
2109 | ||
2110 | if (tid_data->ssn == tid_data->next_reclaimed) { | |
2111 | tid_data->state = IWL_AGG_STARTING; | |
2112 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); | |
2113 | } else { | |
2114 | tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA; | |
2115 | } | |
2116 | ||
4ecafae9 | 2117 | ret = 0; |
9f9af3d7 | 2118 | goto out; |
4ecafae9 LK |
2119 | |
2120 | release_locks: | |
9f9af3d7 LK |
2121 | spin_unlock(&mvm->queue_info_lock); |
2122 | out: | |
8ca151b5 JB |
2123 | spin_unlock_bh(&mvmsta->lock); |
2124 | ||
4ecafae9 | 2125 | return ret; |
8ca151b5 JB |
2126 | } |
2127 | ||
2128 | int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif, | |
bb81bb68 EG |
2129 | struct ieee80211_sta *sta, u16 tid, u8 buf_size, |
2130 | bool amsdu) | |
8ca151b5 | 2131 | { |
5b577a90 | 2132 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 | 2133 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
5d42e7b2 EG |
2134 | unsigned int wdg_timeout = |
2135 | iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false); | |
eea76c36 | 2136 | int queue, ret; |
cf961e16 | 2137 | bool alloc_queue = true; |
9f9af3d7 | 2138 | enum iwl_mvm_queue_status queue_status; |
8ca151b5 JB |
2139 | u16 ssn; |
2140 | ||
eea76c36 EG |
2141 | struct iwl_trans_txq_scd_cfg cfg = { |
2142 | .sta_id = mvmsta->sta_id, | |
2143 | .tid = tid, | |
2144 | .frame_limit = buf_size, | |
2145 | .aggregate = true, | |
2146 | }; | |
2147 | ||
efed6640 ES |
2148 | BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE) |
2149 | != IWL_MAX_TID_COUNT); | |
2150 | ||
8ca151b5 JB |
2151 | buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF); |
2152 | ||
2153 | spin_lock_bh(&mvmsta->lock); | |
2154 | ssn = tid_data->ssn; | |
2155 | queue = tid_data->txq_id; | |
2156 | tid_data->state = IWL_AGG_ON; | |
efed6640 | 2157 | mvmsta->agg_tids |= BIT(tid); |
8ca151b5 | 2158 | tid_data->ssn = 0xffff; |
bb81bb68 | 2159 | tid_data->amsdu_in_ampdu_allowed = amsdu; |
8ca151b5 JB |
2160 | spin_unlock_bh(&mvmsta->lock); |
2161 | ||
eea76c36 | 2162 | cfg.fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]]; |
8ca151b5 | 2163 | |
9f9af3d7 LK |
2164 | spin_lock_bh(&mvm->queue_info_lock); |
2165 | queue_status = mvm->queue_info[queue].status; | |
2166 | spin_unlock_bh(&mvm->queue_info_lock); | |
2167 | ||
cf961e16 LK |
2168 | /* In DQA mode, the existing queue might need to be reconfigured */ |
2169 | if (iwl_mvm_is_dqa_supported(mvm)) { | |
cf961e16 LK |
2170 | /* Maybe there is no need to even alloc a queue... */ |
2171 | if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_READY) | |
2172 | alloc_queue = false; | |
cf961e16 LK |
2173 | |
2174 | /* | |
2175 | * Only reconfig the SCD for the queue if the window size has | |
2176 | * changed from current (become smaller) | |
2177 | */ | |
2178 | if (!alloc_queue && buf_size < mvmsta->max_agg_bufsize) { | |
2179 | /* | |
2180 | * If reconfiguring an existing queue, it first must be | |
2181 | * drained | |
2182 | */ | |
2183 | ret = iwl_trans_wait_tx_queue_empty(mvm->trans, | |
2184 | BIT(queue)); | |
2185 | if (ret) { | |
2186 | IWL_ERR(mvm, | |
2187 | "Error draining queue before reconfig\n"); | |
2188 | return ret; | |
2189 | } | |
2190 | ||
2191 | ret = iwl_mvm_reconfig_scd(mvm, queue, cfg.fifo, | |
2192 | mvmsta->sta_id, tid, | |
2193 | buf_size, ssn); | |
2194 | if (ret) { | |
2195 | IWL_ERR(mvm, | |
2196 | "Error reconfiguring TXQ #%d\n", queue); | |
2197 | return ret; | |
2198 | } | |
2199 | } | |
2200 | } | |
2201 | ||
2202 | if (alloc_queue) | |
2203 | iwl_mvm_enable_txq(mvm, queue, | |
2204 | vif->hw_queue[tid_to_mac80211_ac[tid]], ssn, | |
2205 | &cfg, wdg_timeout); | |
fa7878e7 | 2206 | |
9f9af3d7 LK |
2207 | /* Send ADD_STA command to enable aggs only if the queue isn't shared */ |
2208 | if (queue_status != IWL_MVM_QUEUE_SHARED) { | |
2209 | ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); | |
2210 | if (ret) | |
2211 | return -EIO; | |
2212 | } | |
8ca151b5 | 2213 | |
4ecafae9 LK |
2214 | /* No need to mark as reserved */ |
2215 | spin_lock_bh(&mvm->queue_info_lock); | |
cf961e16 | 2216 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY; |
4ecafae9 LK |
2217 | spin_unlock_bh(&mvm->queue_info_lock); |
2218 | ||
8ca151b5 JB |
2219 | /* |
2220 | * Even though in theory the peer could have different | |
2221 | * aggregation reorder buffer sizes for different sessions, | |
2222 | * our ucode doesn't allow for that and has a global limit | |
2223 | * for each station. Therefore, use the minimum of all the | |
2224 | * aggregation sessions and our default value. | |
2225 | */ | |
2226 | mvmsta->max_agg_bufsize = | |
2227 | min(mvmsta->max_agg_bufsize, buf_size); | |
2228 | mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize; | |
2229 | ||
9ee718aa EL |
2230 | IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n", |
2231 | sta->addr, tid); | |
2232 | ||
9e680946 | 2233 | return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false); |
8ca151b5 JB |
2234 | } |
2235 | ||
2236 | int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif, | |
2237 | struct ieee80211_sta *sta, u16 tid) | |
2238 | { | |
5b577a90 | 2239 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
2240 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
2241 | u16 txq_id; | |
2242 | int err; | |
2243 | ||
f9aa8dd3 EG |
2244 | /* |
2245 | * If mac80211 is cleaning its state, then say that we finished since | |
2246 | * our state has been cleared anyway. | |
2247 | */ | |
2248 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { | |
2249 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); | |
2250 | return 0; | |
2251 | } | |
2252 | ||
8ca151b5 JB |
2253 | spin_lock_bh(&mvmsta->lock); |
2254 | ||
2255 | txq_id = tid_data->txq_id; | |
2256 | ||
2257 | IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n", | |
2258 | mvmsta->sta_id, tid, txq_id, tid_data->state); | |
2259 | ||
efed6640 ES |
2260 | mvmsta->agg_tids &= ~BIT(tid); |
2261 | ||
4ecafae9 | 2262 | spin_lock_bh(&mvm->queue_info_lock); |
cf961e16 LK |
2263 | /* |
2264 | * The TXQ is marked as reserved only if no traffic came through yet | |
2265 | * This means no traffic has been sent on this TID (agg'd or not), so | |
2266 | * we no longer have use for the queue. Since it hasn't even been | |
2267 | * allocated through iwl_mvm_enable_txq, so we can just mark it back as | |
2268 | * free. | |
2269 | */ | |
2270 | if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED) | |
2271 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE; | |
9f9af3d7 | 2272 | |
4ecafae9 LK |
2273 | spin_unlock_bh(&mvm->queue_info_lock); |
2274 | ||
8ca151b5 JB |
2275 | switch (tid_data->state) { |
2276 | case IWL_AGG_ON: | |
9a886586 | 2277 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
8ca151b5 JB |
2278 | |
2279 | IWL_DEBUG_TX_QUEUES(mvm, | |
2280 | "ssn = %d, next_recl = %d\n", | |
2281 | tid_data->ssn, tid_data->next_reclaimed); | |
2282 | ||
2283 | /* There are still packets for this RA / TID in the HW */ | |
2284 | if (tid_data->ssn != tid_data->next_reclaimed) { | |
2285 | tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA; | |
2286 | err = 0; | |
2287 | break; | |
2288 | } | |
2289 | ||
2290 | tid_data->ssn = 0xffff; | |
f7f89e7b | 2291 | tid_data->state = IWL_AGG_OFF; |
f7f89e7b JB |
2292 | spin_unlock_bh(&mvmsta->lock); |
2293 | ||
2294 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); | |
2295 | ||
2296 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); | |
2297 | ||
cf961e16 LK |
2298 | if (!iwl_mvm_is_dqa_supported(mvm)) { |
2299 | int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]]; | |
2300 | ||
2301 | iwl_mvm_disable_txq(mvm, txq_id, mac_queue, tid, 0); | |
2302 | } | |
f7f89e7b | 2303 | return 0; |
8ca151b5 JB |
2304 | case IWL_AGG_STARTING: |
2305 | case IWL_EMPTYING_HW_QUEUE_ADDBA: | |
2306 | /* | |
2307 | * The agg session has been stopped before it was set up. This | |
2308 | * can happen when the AddBA timer times out for example. | |
2309 | */ | |
2310 | ||
2311 | /* No barriers since we are under mutex */ | |
2312 | lockdep_assert_held(&mvm->mutex); | |
8ca151b5 JB |
2313 | |
2314 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); | |
2315 | tid_data->state = IWL_AGG_OFF; | |
2316 | err = 0; | |
2317 | break; | |
2318 | default: | |
2319 | IWL_ERR(mvm, | |
2320 | "Stopping AGG while state not ON or starting for %d on %d (%d)\n", | |
2321 | mvmsta->sta_id, tid, tid_data->state); | |
2322 | IWL_ERR(mvm, | |
2323 | "\ttid_data->txq_id = %d\n", tid_data->txq_id); | |
2324 | err = -EINVAL; | |
2325 | } | |
2326 | ||
2327 | spin_unlock_bh(&mvmsta->lock); | |
2328 | ||
2329 | return err; | |
2330 | } | |
2331 | ||
e3d9e7ce EG |
2332 | int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
2333 | struct ieee80211_sta *sta, u16 tid) | |
2334 | { | |
5b577a90 | 2335 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
e3d9e7ce EG |
2336 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
2337 | u16 txq_id; | |
b6658ff8 | 2338 | enum iwl_mvm_agg_state old_state; |
e3d9e7ce EG |
2339 | |
2340 | /* | |
2341 | * First set the agg state to OFF to avoid calling | |
2342 | * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty. | |
2343 | */ | |
2344 | spin_lock_bh(&mvmsta->lock); | |
2345 | txq_id = tid_data->txq_id; | |
2346 | IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n", | |
2347 | mvmsta->sta_id, tid, txq_id, tid_data->state); | |
b6658ff8 | 2348 | old_state = tid_data->state; |
e3d9e7ce | 2349 | tid_data->state = IWL_AGG_OFF; |
efed6640 | 2350 | mvmsta->agg_tids &= ~BIT(tid); |
e3d9e7ce EG |
2351 | spin_unlock_bh(&mvmsta->lock); |
2352 | ||
4ecafae9 | 2353 | spin_lock_bh(&mvm->queue_info_lock); |
cf961e16 LK |
2354 | /* |
2355 | * The TXQ is marked as reserved only if no traffic came through yet | |
2356 | * This means no traffic has been sent on this TID (agg'd or not), so | |
2357 | * we no longer have use for the queue. Since it hasn't even been | |
2358 | * allocated through iwl_mvm_enable_txq, so we can just mark it back as | |
2359 | * free. | |
2360 | */ | |
2361 | if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED) | |
2362 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE; | |
4ecafae9 LK |
2363 | spin_unlock_bh(&mvm->queue_info_lock); |
2364 | ||
b6658ff8 | 2365 | if (old_state >= IWL_AGG_ON) { |
fe92e32a | 2366 | iwl_mvm_drain_sta(mvm, mvmsta, true); |
5888a40c | 2367 | if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0)) |
b6658ff8 | 2368 | IWL_ERR(mvm, "Couldn't flush the AGG queue\n"); |
fe92e32a EG |
2369 | iwl_trans_wait_tx_queue_empty(mvm->trans, |
2370 | mvmsta->tfd_queue_msk); | |
2371 | iwl_mvm_drain_sta(mvm, mvmsta, false); | |
b6658ff8 | 2372 | |
f7f89e7b JB |
2373 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
2374 | ||
cf961e16 LK |
2375 | if (!iwl_mvm_is_dqa_supported(mvm)) { |
2376 | int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]]; | |
2377 | ||
2378 | iwl_mvm_disable_txq(mvm, tid_data->txq_id, mac_queue, | |
2379 | tid, 0); | |
2380 | } | |
b6658ff8 | 2381 | } |
e3d9e7ce | 2382 | |
e3d9e7ce EG |
2383 | return 0; |
2384 | } | |
2385 | ||
8ca151b5 JB |
2386 | static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm) |
2387 | { | |
2dc2a15e | 2388 | int i, max = -1, max_offs = -1; |
8ca151b5 JB |
2389 | |
2390 | lockdep_assert_held(&mvm->mutex); | |
2391 | ||
2dc2a15e JB |
2392 | /* Pick the unused key offset with the highest 'deleted' |
2393 | * counter. Every time a key is deleted, all the counters | |
2394 | * are incremented and the one that was just deleted is | |
2395 | * reset to zero. Thus, the highest counter is the one | |
2396 | * that was deleted longest ago. Pick that one. | |
2397 | */ | |
2398 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { | |
2399 | if (test_bit(i, mvm->fw_key_table)) | |
2400 | continue; | |
2401 | if (mvm->fw_key_deleted[i] > max) { | |
2402 | max = mvm->fw_key_deleted[i]; | |
2403 | max_offs = i; | |
2404 | } | |
2405 | } | |
8ca151b5 | 2406 | |
2dc2a15e | 2407 | if (max_offs < 0) |
8ca151b5 JB |
2408 | return STA_KEY_IDX_INVALID; |
2409 | ||
2dc2a15e | 2410 | return max_offs; |
8ca151b5 JB |
2411 | } |
2412 | ||
5f7a1847 JB |
2413 | static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm, |
2414 | struct ieee80211_vif *vif, | |
2415 | struct ieee80211_sta *sta) | |
8ca151b5 | 2416 | { |
5b530e95 | 2417 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
8ca151b5 | 2418 | |
5f7a1847 JB |
2419 | if (sta) |
2420 | return iwl_mvm_sta_from_mac80211(sta); | |
8ca151b5 JB |
2421 | |
2422 | /* | |
2423 | * The device expects GTKs for station interfaces to be | |
2424 | * installed as GTKs for the AP station. If we have no | |
2425 | * station ID, then use AP's station ID. | |
2426 | */ | |
2427 | if (vif->type == NL80211_IFTYPE_STATION && | |
9513c5e1 AA |
2428 | mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
2429 | u8 sta_id = mvmvif->ap_sta_id; | |
2430 | ||
7d6a1ab6 EG |
2431 | sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id], |
2432 | lockdep_is_held(&mvm->mutex)); | |
2433 | ||
9513c5e1 AA |
2434 | /* |
2435 | * It is possible that the 'sta' parameter is NULL, | |
2436 | * for example when a GTK is removed - the sta_id will then | |
2437 | * be the AP ID, and no station was passed by mac80211. | |
2438 | */ | |
7d6a1ab6 EG |
2439 | if (IS_ERR_OR_NULL(sta)) |
2440 | return NULL; | |
2441 | ||
2442 | return iwl_mvm_sta_from_mac80211(sta); | |
9513c5e1 | 2443 | } |
8ca151b5 | 2444 | |
5f7a1847 | 2445 | return NULL; |
8ca151b5 JB |
2446 | } |
2447 | ||
2448 | static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm, | |
2449 | struct iwl_mvm_sta *mvm_sta, | |
ba3943b0 | 2450 | struct ieee80211_key_conf *keyconf, bool mcast, |
d6ee54a9 LC |
2451 | u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags, |
2452 | u8 key_offset) | |
8ca151b5 | 2453 | { |
5a258aae | 2454 | struct iwl_mvm_add_sta_key_cmd cmd = {}; |
f9dc0004 | 2455 | __le16 key_flags; |
79920749 JB |
2456 | int ret; |
2457 | u32 status; | |
8ca151b5 JB |
2458 | u16 keyidx; |
2459 | int i; | |
2f6319d1 | 2460 | u8 sta_id = mvm_sta->sta_id; |
8ca151b5 JB |
2461 | |
2462 | keyidx = (keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & | |
2463 | STA_KEY_FLG_KEYID_MSK; | |
2464 | key_flags = cpu_to_le16(keyidx); | |
2465 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP); | |
2466 | ||
2467 | switch (keyconf->cipher) { | |
2468 | case WLAN_CIPHER_SUITE_TKIP: | |
2469 | key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP); | |
5a258aae | 2470 | cmd.tkip_rx_tsc_byte2 = tkip_iv32; |
8ca151b5 | 2471 | for (i = 0; i < 5; i++) |
5a258aae MS |
2472 | cmd.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]); |
2473 | memcpy(cmd.key, keyconf->key, keyconf->keylen); | |
8ca151b5 JB |
2474 | break; |
2475 | case WLAN_CIPHER_SUITE_CCMP: | |
2476 | key_flags |= cpu_to_le16(STA_KEY_FLG_CCM); | |
5a258aae | 2477 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
8ca151b5 | 2478 | break; |
ba3943b0 JB |
2479 | case WLAN_CIPHER_SUITE_WEP104: |
2480 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES); | |
aa0cb08b | 2481 | /* fall through */ |
ba3943b0 JB |
2482 | case WLAN_CIPHER_SUITE_WEP40: |
2483 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP); | |
2484 | memcpy(cmd.key + 3, keyconf->key, keyconf->keylen); | |
2485 | break; | |
2a53d166 AB |
2486 | case WLAN_CIPHER_SUITE_GCMP_256: |
2487 | key_flags |= cpu_to_le16(STA_KEY_FLG_KEY_32BYTES); | |
2488 | /* fall through */ | |
2489 | case WLAN_CIPHER_SUITE_GCMP: | |
2490 | key_flags |= cpu_to_le16(STA_KEY_FLG_GCMP); | |
2491 | memcpy(cmd.key, keyconf->key, keyconf->keylen); | |
2492 | break; | |
8ca151b5 | 2493 | default: |
e36e5433 MS |
2494 | key_flags |= cpu_to_le16(STA_KEY_FLG_EXT); |
2495 | memcpy(cmd.key, keyconf->key, keyconf->keylen); | |
8ca151b5 JB |
2496 | } |
2497 | ||
ba3943b0 | 2498 | if (mcast) |
8ca151b5 JB |
2499 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
2500 | ||
d6ee54a9 | 2501 | cmd.key_offset = key_offset; |
5a258aae | 2502 | cmd.key_flags = key_flags; |
8ca151b5 JB |
2503 | cmd.sta_id = sta_id; |
2504 | ||
2505 | status = ADD_STA_SUCCESS; | |
a1022927 | 2506 | if (cmd_flags & CMD_ASYNC) |
f9dc0004 EG |
2507 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC, |
2508 | sizeof(cmd), &cmd); | |
a1022927 EG |
2509 | else |
2510 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd), | |
2511 | &cmd, &status); | |
8ca151b5 JB |
2512 | |
2513 | switch (status) { | |
2514 | case ADD_STA_SUCCESS: | |
2515 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n"); | |
2516 | break; | |
2517 | default: | |
2518 | ret = -EIO; | |
2519 | IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n"); | |
2520 | break; | |
2521 | } | |
2522 | ||
2523 | return ret; | |
2524 | } | |
2525 | ||
2526 | static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm, | |
2527 | struct ieee80211_key_conf *keyconf, | |
2528 | u8 sta_id, bool remove_key) | |
2529 | { | |
2530 | struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {}; | |
2531 | ||
2532 | /* verify the key details match the required command's expectations */ | |
8e160ab8 AB |
2533 | if (WARN_ON((keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) || |
2534 | (keyconf->keyidx != 4 && keyconf->keyidx != 5) || | |
2535 | (keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC && | |
2536 | keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_128 && | |
2537 | keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_256))) | |
2538 | return -EINVAL; | |
2539 | ||
2540 | if (WARN_ON(!iwl_mvm_has_new_rx_api(mvm) && | |
2541 | keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC)) | |
8ca151b5 JB |
2542 | return -EINVAL; |
2543 | ||
2544 | igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx); | |
2545 | igtk_cmd.sta_id = cpu_to_le32(sta_id); | |
2546 | ||
2547 | if (remove_key) { | |
2548 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID); | |
2549 | } else { | |
2550 | struct ieee80211_key_seq seq; | |
2551 | const u8 *pn; | |
2552 | ||
aa950524 AB |
2553 | switch (keyconf->cipher) { |
2554 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
2555 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_CCM); | |
2556 | break; | |
8e160ab8 AB |
2557 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
2558 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: | |
2559 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_GCMP); | |
2560 | break; | |
aa950524 AB |
2561 | default: |
2562 | return -EINVAL; | |
2563 | } | |
2564 | ||
8e160ab8 AB |
2565 | memcpy(igtk_cmd.igtk, keyconf->key, keyconf->keylen); |
2566 | if (keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) | |
2567 | igtk_cmd.ctrl_flags |= | |
2568 | cpu_to_le32(STA_KEY_FLG_KEY_32BYTES); | |
8ca151b5 JB |
2569 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
2570 | pn = seq.aes_cmac.pn; | |
2571 | igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) | | |
2572 | ((u64) pn[4] << 8) | | |
2573 | ((u64) pn[3] << 16) | | |
2574 | ((u64) pn[2] << 24) | | |
2575 | ((u64) pn[1] << 32) | | |
2576 | ((u64) pn[0] << 40)); | |
2577 | } | |
2578 | ||
2579 | IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n", | |
2580 | remove_key ? "removing" : "installing", | |
2581 | igtk_cmd.sta_id); | |
2582 | ||
8e160ab8 AB |
2583 | if (!iwl_mvm_has_new_rx_api(mvm)) { |
2584 | struct iwl_mvm_mgmt_mcast_key_cmd_v1 igtk_cmd_v1 = { | |
2585 | .ctrl_flags = igtk_cmd.ctrl_flags, | |
2586 | .key_id = igtk_cmd.key_id, | |
2587 | .sta_id = igtk_cmd.sta_id, | |
2588 | .receive_seq_cnt = igtk_cmd.receive_seq_cnt | |
2589 | }; | |
2590 | ||
2591 | memcpy(igtk_cmd_v1.igtk, igtk_cmd.igtk, | |
2592 | ARRAY_SIZE(igtk_cmd_v1.igtk)); | |
2593 | return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0, | |
2594 | sizeof(igtk_cmd_v1), &igtk_cmd_v1); | |
2595 | } | |
a1022927 | 2596 | return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0, |
8ca151b5 JB |
2597 | sizeof(igtk_cmd), &igtk_cmd); |
2598 | } | |
2599 | ||
2600 | ||
2601 | static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm, | |
2602 | struct ieee80211_vif *vif, | |
2603 | struct ieee80211_sta *sta) | |
2604 | { | |
5b530e95 | 2605 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
8ca151b5 JB |
2606 | |
2607 | if (sta) | |
2608 | return sta->addr; | |
2609 | ||
2610 | if (vif->type == NL80211_IFTYPE_STATION && | |
2611 | mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { | |
2612 | u8 sta_id = mvmvif->ap_sta_id; | |
2613 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
2614 | lockdep_is_held(&mvm->mutex)); | |
2615 | return sta->addr; | |
2616 | } | |
2617 | ||
2618 | ||
2619 | return NULL; | |
2620 | } | |
2621 | ||
2f6319d1 JB |
2622 | static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
2623 | struct ieee80211_vif *vif, | |
2624 | struct ieee80211_sta *sta, | |
ba3943b0 | 2625 | struct ieee80211_key_conf *keyconf, |
d6ee54a9 | 2626 | u8 key_offset, |
ba3943b0 | 2627 | bool mcast) |
2f6319d1 JB |
2628 | { |
2629 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); | |
2630 | int ret; | |
2631 | const u8 *addr; | |
2632 | struct ieee80211_key_seq seq; | |
2633 | u16 p1k[5]; | |
2634 | ||
2635 | switch (keyconf->cipher) { | |
2636 | case WLAN_CIPHER_SUITE_TKIP: | |
2637 | addr = iwl_mvm_get_mac_addr(mvm, vif, sta); | |
2638 | /* get phase 1 key from mac80211 */ | |
2639 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); | |
2640 | ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k); | |
ba3943b0 | 2641 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
d6ee54a9 | 2642 | seq.tkip.iv32, p1k, 0, key_offset); |
2f6319d1 JB |
2643 | break; |
2644 | case WLAN_CIPHER_SUITE_CCMP: | |
ba3943b0 JB |
2645 | case WLAN_CIPHER_SUITE_WEP40: |
2646 | case WLAN_CIPHER_SUITE_WEP104: | |
2a53d166 AB |
2647 | case WLAN_CIPHER_SUITE_GCMP: |
2648 | case WLAN_CIPHER_SUITE_GCMP_256: | |
ba3943b0 | 2649 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
d6ee54a9 | 2650 | 0, NULL, 0, key_offset); |
2f6319d1 JB |
2651 | break; |
2652 | default: | |
ba3943b0 | 2653 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
d6ee54a9 | 2654 | 0, NULL, 0, key_offset); |
2f6319d1 JB |
2655 | } |
2656 | ||
2657 | return ret; | |
2658 | } | |
2659 | ||
2660 | static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id, | |
ba3943b0 JB |
2661 | struct ieee80211_key_conf *keyconf, |
2662 | bool mcast) | |
2f6319d1 JB |
2663 | { |
2664 | struct iwl_mvm_add_sta_key_cmd cmd = {}; | |
2665 | __le16 key_flags; | |
2666 | int ret; | |
2667 | u32 status; | |
2668 | ||
2669 | key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & | |
2670 | STA_KEY_FLG_KEYID_MSK); | |
2671 | key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP); | |
2672 | key_flags |= cpu_to_le16(STA_KEY_NOT_VALID); | |
2673 | ||
ba3943b0 | 2674 | if (mcast) |
2f6319d1 JB |
2675 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
2676 | ||
2677 | cmd.key_flags = key_flags; | |
2678 | cmd.key_offset = keyconf->hw_key_idx; | |
2679 | cmd.sta_id = sta_id; | |
2680 | ||
2681 | status = ADD_STA_SUCCESS; | |
2682 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd), | |
2683 | &cmd, &status); | |
2684 | ||
2685 | switch (status) { | |
2686 | case ADD_STA_SUCCESS: | |
2687 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n"); | |
2688 | break; | |
2689 | default: | |
2690 | ret = -EIO; | |
2691 | IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n"); | |
2692 | break; | |
2693 | } | |
2694 | ||
2695 | return ret; | |
2696 | } | |
2697 | ||
8ca151b5 JB |
2698 | int iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
2699 | struct ieee80211_vif *vif, | |
2700 | struct ieee80211_sta *sta, | |
2701 | struct ieee80211_key_conf *keyconf, | |
d6ee54a9 | 2702 | u8 key_offset) |
8ca151b5 | 2703 | { |
ba3943b0 | 2704 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
5f7a1847 | 2705 | struct iwl_mvm_sta *mvm_sta; |
2f6319d1 | 2706 | u8 sta_id; |
8ca151b5 | 2707 | int ret; |
11828dbc | 2708 | static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0}; |
8ca151b5 JB |
2709 | |
2710 | lockdep_assert_held(&mvm->mutex); | |
2711 | ||
2712 | /* Get the station id from the mvm local station table */ | |
5f7a1847 JB |
2713 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
2714 | if (!mvm_sta) { | |
2715 | IWL_ERR(mvm, "Failed to find station\n"); | |
8ca151b5 JB |
2716 | return -EINVAL; |
2717 | } | |
5f7a1847 | 2718 | sta_id = mvm_sta->sta_id; |
8ca151b5 | 2719 | |
8e160ab8 AB |
2720 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC || |
2721 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || | |
2722 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) { | |
8ca151b5 JB |
2723 | ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false); |
2724 | goto end; | |
2725 | } | |
2726 | ||
2727 | /* | |
2728 | * It is possible that the 'sta' parameter is NULL, and thus | |
2729 | * there is a need to retrieve the sta from the local station table. | |
2730 | */ | |
2731 | if (!sta) { | |
2732 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
2733 | lockdep_is_held(&mvm->mutex)); | |
2734 | if (IS_ERR_OR_NULL(sta)) { | |
2735 | IWL_ERR(mvm, "Invalid station id\n"); | |
2736 | return -EINVAL; | |
2737 | } | |
2738 | } | |
2739 | ||
2f6319d1 | 2740 | if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif)) |
8ca151b5 JB |
2741 | return -EINVAL; |
2742 | ||
d6ee54a9 LC |
2743 | /* If the key_offset is not pre-assigned, we need to find a |
2744 | * new offset to use. In normal cases, the offset is not | |
2745 | * pre-assigned, but during HW_RESTART we want to reuse the | |
2746 | * same indices, so we pass them when this function is called. | |
2747 | * | |
2748 | * In D3 entry, we need to hardcoded the indices (because the | |
2749 | * firmware hardcodes the PTK offset to 0). In this case, we | |
2750 | * need to make sure we don't overwrite the hw_key_idx in the | |
2751 | * keyconf structure, because otherwise we cannot configure | |
2752 | * the original ones back when resuming. | |
2753 | */ | |
2754 | if (key_offset == STA_KEY_IDX_INVALID) { | |
2755 | key_offset = iwl_mvm_set_fw_key_idx(mvm); | |
2756 | if (key_offset == STA_KEY_IDX_INVALID) | |
8ca151b5 | 2757 | return -ENOSPC; |
d6ee54a9 | 2758 | keyconf->hw_key_idx = key_offset; |
8ca151b5 JB |
2759 | } |
2760 | ||
d6ee54a9 | 2761 | ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, key_offset, mcast); |
9c3deeb5 | 2762 | if (ret) |
ba3943b0 | 2763 | goto end; |
ba3943b0 JB |
2764 | |
2765 | /* | |
2766 | * For WEP, the same key is used for multicast and unicast. Upload it | |
2767 | * again, using the same key offset, and now pointing the other one | |
2768 | * to the same key slot (offset). | |
2769 | * If this fails, remove the original as well. | |
2770 | */ | |
2771 | if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || | |
2772 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) { | |
d6ee54a9 LC |
2773 | ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, |
2774 | key_offset, !mcast); | |
ba3943b0 | 2775 | if (ret) { |
ba3943b0 | 2776 | __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
9c3deeb5 | 2777 | goto end; |
ba3943b0 JB |
2778 | } |
2779 | } | |
8ca151b5 | 2780 | |
9c3deeb5 LC |
2781 | __set_bit(key_offset, mvm->fw_key_table); |
2782 | ||
8ca151b5 JB |
2783 | end: |
2784 | IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n", | |
2785 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, | |
11828dbc | 2786 | sta ? sta->addr : zero_addr, ret); |
8ca151b5 JB |
2787 | return ret; |
2788 | } | |
2789 | ||
2790 | int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, | |
2791 | struct ieee80211_vif *vif, | |
2792 | struct ieee80211_sta *sta, | |
2793 | struct ieee80211_key_conf *keyconf) | |
2794 | { | |
ba3943b0 | 2795 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
5f7a1847 JB |
2796 | struct iwl_mvm_sta *mvm_sta; |
2797 | u8 sta_id = IWL_MVM_STATION_COUNT; | |
2dc2a15e | 2798 | int ret, i; |
8ca151b5 JB |
2799 | |
2800 | lockdep_assert_held(&mvm->mutex); | |
2801 | ||
5f7a1847 JB |
2802 | /* Get the station from the mvm local station table */ |
2803 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); | |
8ca151b5 JB |
2804 | |
2805 | IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n", | |
2806 | keyconf->keyidx, sta_id); | |
2807 | ||
8e160ab8 AB |
2808 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC || |
2809 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || | |
2810 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) | |
8ca151b5 JB |
2811 | return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true); |
2812 | ||
2f6319d1 | 2813 | if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) { |
8ca151b5 JB |
2814 | IWL_ERR(mvm, "offset %d not used in fw key table.\n", |
2815 | keyconf->hw_key_idx); | |
2816 | return -ENOENT; | |
2817 | } | |
2818 | ||
2dc2a15e JB |
2819 | /* track which key was deleted last */ |
2820 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { | |
2821 | if (mvm->fw_key_deleted[i] < U8_MAX) | |
2822 | mvm->fw_key_deleted[i]++; | |
2823 | } | |
2824 | mvm->fw_key_deleted[keyconf->hw_key_idx] = 0; | |
2825 | ||
5f7a1847 | 2826 | if (!mvm_sta) { |
8ca151b5 JB |
2827 | IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n"); |
2828 | return 0; | |
2829 | } | |
2830 | ||
5f7a1847 JB |
2831 | sta_id = mvm_sta->sta_id; |
2832 | ||
ba3943b0 JB |
2833 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
2834 | if (ret) | |
2835 | return ret; | |
2836 | ||
2837 | /* delete WEP key twice to get rid of (now useless) offset */ | |
2838 | if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || | |
2839 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) | |
2840 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast); | |
2841 | ||
2842 | return ret; | |
8ca151b5 JB |
2843 | } |
2844 | ||
2845 | void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm, | |
2846 | struct ieee80211_vif *vif, | |
2847 | struct ieee80211_key_conf *keyconf, | |
2848 | struct ieee80211_sta *sta, u32 iv32, | |
2849 | u16 *phase1key) | |
2850 | { | |
c3eb536a | 2851 | struct iwl_mvm_sta *mvm_sta; |
ba3943b0 | 2852 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
8ca151b5 | 2853 | |
c3eb536a BL |
2854 | rcu_read_lock(); |
2855 | ||
5f7a1847 JB |
2856 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
2857 | if (WARN_ON_ONCE(!mvm_sta)) | |
45854360 | 2858 | goto unlock; |
ba3943b0 | 2859 | iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
d6ee54a9 | 2860 | iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx); |
45854360 JB |
2861 | |
2862 | unlock: | |
c3eb536a | 2863 | rcu_read_unlock(); |
8ca151b5 JB |
2864 | } |
2865 | ||
9cc40712 JB |
2866 | void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm, |
2867 | struct ieee80211_sta *sta) | |
8ca151b5 | 2868 | { |
5b577a90 | 2869 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
f9dc0004 | 2870 | struct iwl_mvm_add_sta_cmd cmd = { |
8ca151b5 | 2871 | .add_modify = STA_MODE_MODIFY, |
9cc40712 | 2872 | .sta_id = mvmsta->sta_id, |
5af01772 | 2873 | .station_flags_msk = cpu_to_le32(STA_FLG_PS), |
9cc40712 | 2874 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
8ca151b5 JB |
2875 | }; |
2876 | int ret; | |
2877 | ||
854c5705 SS |
2878 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
2879 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); | |
8ca151b5 JB |
2880 | if (ret) |
2881 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); | |
2882 | } | |
2883 | ||
9cc40712 JB |
2884 | void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm, |
2885 | struct ieee80211_sta *sta, | |
8ca151b5 | 2886 | enum ieee80211_frame_release_type reason, |
3e56eadf JB |
2887 | u16 cnt, u16 tids, bool more_data, |
2888 | bool agg) | |
8ca151b5 | 2889 | { |
5b577a90 | 2890 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
f9dc0004 | 2891 | struct iwl_mvm_add_sta_cmd cmd = { |
8ca151b5 | 2892 | .add_modify = STA_MODE_MODIFY, |
9cc40712 | 2893 | .sta_id = mvmsta->sta_id, |
8ca151b5 JB |
2894 | .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT, |
2895 | .sleep_tx_count = cpu_to_le16(cnt), | |
9cc40712 | 2896 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
8ca151b5 | 2897 | }; |
3e56eadf JB |
2898 | int tid, ret; |
2899 | unsigned long _tids = tids; | |
2900 | ||
2901 | /* convert TIDs to ACs - we don't support TSPEC so that's OK | |
2902 | * Note that this field is reserved and unused by firmware not | |
2903 | * supporting GO uAPSD, so it's safe to always do this. | |
2904 | */ | |
2905 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) | |
2906 | cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]); | |
2907 | ||
2908 | /* If we're releasing frames from aggregation queues then check if the | |
2909 | * all queues combined that we're releasing frames from have | |
2910 | * - more frames than the service period, in which case more_data | |
2911 | * needs to be set | |
2912 | * - fewer than 'cnt' frames, in which case we need to adjust the | |
2913 | * firmware command (but do that unconditionally) | |
2914 | */ | |
2915 | if (agg) { | |
2916 | int remaining = cnt; | |
36be0eb6 | 2917 | int sleep_tx_count; |
3e56eadf JB |
2918 | |
2919 | spin_lock_bh(&mvmsta->lock); | |
2920 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) { | |
2921 | struct iwl_mvm_tid_data *tid_data; | |
2922 | u16 n_queued; | |
2923 | ||
2924 | tid_data = &mvmsta->tid_data[tid]; | |
2925 | if (WARN(tid_data->state != IWL_AGG_ON && | |
2926 | tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA, | |
2927 | "TID %d state is %d\n", | |
2928 | tid, tid_data->state)) { | |
2929 | spin_unlock_bh(&mvmsta->lock); | |
2930 | ieee80211_sta_eosp(sta); | |
2931 | return; | |
2932 | } | |
2933 | ||
2934 | n_queued = iwl_mvm_tid_queued(tid_data); | |
2935 | if (n_queued > remaining) { | |
2936 | more_data = true; | |
2937 | remaining = 0; | |
2938 | break; | |
2939 | } | |
2940 | remaining -= n_queued; | |
2941 | } | |
36be0eb6 EG |
2942 | sleep_tx_count = cnt - remaining; |
2943 | if (reason == IEEE80211_FRAME_RELEASE_UAPSD) | |
2944 | mvmsta->sleep_tx_count = sleep_tx_count; | |
3e56eadf JB |
2945 | spin_unlock_bh(&mvmsta->lock); |
2946 | ||
36be0eb6 | 2947 | cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count); |
3e56eadf JB |
2948 | if (WARN_ON(cnt - remaining == 0)) { |
2949 | ieee80211_sta_eosp(sta); | |
2950 | return; | |
2951 | } | |
2952 | } | |
2953 | ||
2954 | /* Note: this is ignored by firmware not supporting GO uAPSD */ | |
2955 | if (more_data) | |
2956 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA); | |
2957 | ||
2958 | if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) { | |
2959 | mvmsta->next_status_eosp = true; | |
2960 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL); | |
2961 | } else { | |
2962 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD); | |
2963 | } | |
8ca151b5 | 2964 | |
156f92f2 EG |
2965 | /* block the Tx queues until the FW updated the sleep Tx count */ |
2966 | iwl_trans_block_txq_ptrs(mvm->trans, true); | |
2967 | ||
2968 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, | |
2969 | CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK, | |
854c5705 | 2970 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
8ca151b5 JB |
2971 | if (ret) |
2972 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); | |
2973 | } | |
3e56eadf | 2974 | |
0416841d JB |
2975 | void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm, |
2976 | struct iwl_rx_cmd_buffer *rxb) | |
3e56eadf JB |
2977 | { |
2978 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
2979 | struct iwl_mvm_eosp_notification *notif = (void *)pkt->data; | |
2980 | struct ieee80211_sta *sta; | |
2981 | u32 sta_id = le32_to_cpu(notif->sta_id); | |
2982 | ||
2983 | if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT)) | |
0416841d | 2984 | return; |
3e56eadf JB |
2985 | |
2986 | rcu_read_lock(); | |
2987 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); | |
2988 | if (!IS_ERR_OR_NULL(sta)) | |
2989 | ieee80211_sta_eosp(sta); | |
2990 | rcu_read_unlock(); | |
3e56eadf | 2991 | } |
09b0ce1a AO |
2992 | |
2993 | void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm, | |
2994 | struct iwl_mvm_sta *mvmsta, bool disable) | |
2995 | { | |
2996 | struct iwl_mvm_add_sta_cmd cmd = { | |
2997 | .add_modify = STA_MODE_MODIFY, | |
2998 | .sta_id = mvmsta->sta_id, | |
2999 | .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0, | |
3000 | .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX), | |
3001 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), | |
3002 | }; | |
3003 | int ret; | |
3004 | ||
854c5705 SS |
3005 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
3006 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); | |
09b0ce1a AO |
3007 | if (ret) |
3008 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); | |
3009 | } | |
003e5236 AO |
3010 | |
3011 | void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm, | |
3012 | struct ieee80211_sta *sta, | |
3013 | bool disable) | |
3014 | { | |
3015 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); | |
3016 | ||
3017 | spin_lock_bh(&mvm_sta->lock); | |
3018 | ||
3019 | if (mvm_sta->disable_tx == disable) { | |
3020 | spin_unlock_bh(&mvm_sta->lock); | |
3021 | return; | |
3022 | } | |
3023 | ||
3024 | mvm_sta->disable_tx = disable; | |
3025 | ||
3026 | /* | |
0d365ae5 SS |
3027 | * Tell mac80211 to start/stop queuing tx for this station, |
3028 | * but don't stop queuing if there are still pending frames | |
003e5236 AO |
3029 | * for this station. |
3030 | */ | |
3031 | if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) | |
3032 | ieee80211_sta_block_awake(mvm->hw, sta, disable); | |
3033 | ||
3034 | iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable); | |
3035 | ||
3036 | spin_unlock_bh(&mvm_sta->lock); | |
3037 | } | |
3038 | ||
3039 | void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm, | |
3040 | struct iwl_mvm_vif *mvmvif, | |
3041 | bool disable) | |
3042 | { | |
3043 | struct ieee80211_sta *sta; | |
3044 | struct iwl_mvm_sta *mvm_sta; | |
3045 | int i; | |
3046 | ||
3047 | lockdep_assert_held(&mvm->mutex); | |
3048 | ||
3049 | /* Block/unblock all the stations of the given mvmvif */ | |
3050 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { | |
3051 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], | |
3052 | lockdep_is_held(&mvm->mutex)); | |
3053 | if (IS_ERR_OR_NULL(sta)) | |
3054 | continue; | |
3055 | ||
3056 | mvm_sta = iwl_mvm_sta_from_mac80211(sta); | |
3057 | if (mvm_sta->mac_id_n_color != | |
3058 | FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)) | |
3059 | continue; | |
3060 | ||
3061 | iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable); | |
3062 | } | |
3063 | } | |
dc88b4ba LC |
3064 | |
3065 | void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif) | |
3066 | { | |
3067 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
3068 | struct iwl_mvm_sta *mvmsta; | |
3069 | ||
3070 | rcu_read_lock(); | |
3071 | ||
3072 | mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id); | |
3073 | ||
3074 | if (!WARN_ON(!mvmsta)) | |
3075 | iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true); | |
3076 | ||
3077 | rcu_read_unlock(); | |
3078 | } |