blob: c0c2ea344ad4d41428056ca9d012a02a9cb631e9 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
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 *
Andrei Otcheretianskifa7878e2015-05-05 09:28:16 +03008 * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Sara Sharon854c5702016-01-26 13:17:47 +020010 * Copyright(c) 2016 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010011 *
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
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020027 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010028 *
29 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020030 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg8ca151b2013-01-24 14:25:36 +010031 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
Andrei Otcheretianskifa7878e2015-05-05 09:28:16 +030035 * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved.
36 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Sara Sharon854c5702016-01-26 13:17:47 +020037 * Copyright(c) 2016 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010038 * 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"
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +030071#include "rs.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010072
Sara Sharon854c5702016-01-26 13:17:47 +020073/*
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 */
78static 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
Eliad Pellerb92e6612014-01-23 17:58:23 +020085static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm,
86 enum nl80211_iftype iftype)
Johannes Berg8ca151b2013-01-24 14:25:36 +010087{
88 int sta_id;
Eliad Pellerb92e6612014-01-23 17:58:23 +020089 u32 reserved_ids = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +010090
Eliad Pellerb92e6612014-01-23 17:58:23 +020091 BUILD_BUG_ON(IWL_MVM_STATION_COUNT > 32);
Johannes Berg8ca151b2013-01-24 14:25:36 +010092 WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status));
93
94 lockdep_assert_held(&mvm->mutex);
95
Eliad Pellerb92e6612014-01-23 17:58:23 +020096 /* 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
Johannes Berg8ca151b2013-01-24 14:25:36 +0100100 /* Don't take rcu_read_lock() since we are protected by mvm->mutex */
Eliad Pellerb92e6612014-01-23 17:58:23 +0200101 for (sta_id = 0; sta_id < IWL_MVM_STATION_COUNT; sta_id++) {
102 if (BIT(sta_id) & reserved_ids)
103 continue;
104
Johannes Berg8ca151b2013-01-24 14:25:36 +0100105 if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
106 lockdep_is_held(&mvm->mutex)))
107 return sta_id;
Eliad Pellerb92e6612014-01-23 17:58:23 +0200108 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100109 return IWL_MVM_STATION_COUNT;
110}
111
Johannes Berg7a453972013-02-12 13:10:44 +0100112/* send station add/update command to firmware */
113int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
Liad Kaufman24afba72015-07-28 18:56:08 +0300114 bool update, unsigned int flags)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100115{
Johannes Berg9d8ce6a2014-12-23 16:02:40 +0100116 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbach4b8265a2014-07-13 08:58:04 +0300117 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),
Liad Kaufmancf0cda12015-09-24 10:44:12 +0200123 .tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg),
Emmanuel Grumbach4b8265a2014-07-13 08:58:04 +0300124 };
Johannes Berg8ca151b2013-01-24 14:25:36 +0100125 int ret;
126 u32 status;
127 u32 agg_size = 0, mpdu_dens = 0;
128
Liad Kaufman24afba72015-07-28 18:56:08 +0300129 if (!update || (flags & STA_MODIFY_QUEUES)) {
Johannes Berg7a453972013-02-12 13:10:44 +0100130 add_sta_cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk);
131 memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN);
Liad Kaufman24afba72015-07-28 18:56:08 +0300132
133 if (flags & STA_MODIFY_QUEUES)
134 add_sta_cmd.modify_mask |= STA_MODIFY_QUEUES;
Johannes Berg7a453972013-02-12 13:10:44 +0100135 }
Johannes Berg5bc5aaa2013-02-12 14:35:36 +0100136
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 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100183
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;
Sara Sharon854c5702016-01-26 13:17:47 +0200207 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
208 iwl_mvm_add_sta_cmd_size(mvm),
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300209 &add_sta_cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100210 if (ret)
211 return ret;
212
Sara Sharon837c4da2016-01-07 16:50:45 +0200213 switch (status & IWL_ADD_STA_STATUS_MASK) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100214 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
Sara Sharon10b2b202016-03-20 16:23:41 +0200226static 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);
255unlock:
256 rcu_read_unlock();
257}
258
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300259static 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);
Emmanuel Grumbach5d42e7b2015-03-19 20:04:51 +0200264 unsigned int wdg_timeout =
265 iwl_mvm_get_wd_timeout(mvm, NULL, true, false);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300266 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],
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300289 mvmsta->hw_queue[ac],
Liad Kaufman5c1156e2015-07-22 17:59:53 +0300290 iwl_mvm_ac_to_tx_fifo[ac], 0,
291 wdg_timeout);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300292 mvmsta->tfd_queue_msk |= BIT(mvmsta->hw_queue[ac]);
293 }
294
295 return 0;
296}
297
298static 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;
Emmanuel Grumbacha4ca3ed2015-01-20 17:07:10 +0200309 for_each_set_bit(i, &sta_msk, sizeof(sta_msk) * BITS_PER_BYTE)
Arik Nemtsov06ecdba2015-10-12 14:47:11 +0300310 iwl_mvm_disable_txq(mvm, i, i, IWL_MAX_TID_COUNT, 0);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300311}
312
Liad Kaufman9794c642015-08-19 17:34:28 +0300313/* Disable aggregations for a bitmap of TIDs for a given station */
314static 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
Liad Kaufman42db09c2016-05-02 14:01:14 +0300364static 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
Liad Kaufman9794c642015-08-19 17:34:28 +0300398/*
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 */
403static 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);
Liad Kaufman42db09c2016-05-02 14:01:14 +0300431 /* Unmap MAC queues and TIDs from this queue */
Liad Kaufman9794c642015-08-19 17:34:28 +0300432 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
Liad Kaufman9794c642015-08-19 17:34:28 +0300433 if (mvmsta->tid_data[tid].state == IWL_AGG_ON)
434 disable_agg_tids |= BIT(tid);
Liad Kaufman42db09c2016-05-02 14:01:14 +0300435 mvmsta->tid_data[tid].txq_id = IEEE80211_INVAL_HW_QUEUE;
Liad Kaufman9794c642015-08-19 17:34:28 +0300436 }
Liad Kaufman9794c642015-08-19 17:34:28 +0300437
Liad Kaufman42db09c2016-05-02 14:01:14 +0300438 mvmsta->tfd_queue_msk &= ~BIT(queue); /* Don't use this queue anymore */
Liad Kaufman9794c642015-08-19 17:34:28 +0300439 spin_unlock_bh(&mvmsta->lock);
440
441 rcu_read_unlock();
442
Liad Kaufman42db09c2016-05-02 14:01:14 +0300443 spin_lock_bh(&mvm->queue_info_lock);
Liad Kaufman9794c642015-08-19 17:34:28 +0300444 /* 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;
Liad Kaufman42db09c2016-05-02 14:01:14 +0300448 spin_unlock_bh(&mvm->queue_info_lock);
Liad Kaufman9794c642015-08-19 17:34:28 +0300449
450 return disable_agg_tids;
451}
452
Liad Kaufman42db09c2016-05-02 14:01:14 +0300453static 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
471 ac_to_queue[mvm->queue_info[i].mac80211_ac] = i;
472 }
473
474 /*
475 * The queue to share is chosen only from DATA queues as follows (in
476 * descending priority):
477 * 1. An AC_BE queue
478 * 2. Same AC queue
479 * 3. Highest AC queue that is lower than new AC
480 * 4. Any existing AC (there always is at least 1 DATA queue)
481 */
482
483 /* Priority 1: An AC_BE queue */
484 if (ac_to_queue[IEEE80211_AC_BE] != IEEE80211_INVAL_HW_QUEUE)
485 queue = ac_to_queue[IEEE80211_AC_BE];
486 /* Priority 2: Same AC queue */
487 else if (ac_to_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
488 queue = ac_to_queue[ac];
489 /* Priority 3a: If new AC is VO and VI exists - use VI */
490 else if (ac == IEEE80211_AC_VO &&
491 ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE)
492 queue = ac_to_queue[IEEE80211_AC_VI];
493 /* Priority 3b: No BE so only AC less than the new one is BK */
494 else if (ac_to_queue[IEEE80211_AC_BK] != IEEE80211_INVAL_HW_QUEUE)
495 queue = ac_to_queue[IEEE80211_AC_BK];
496 /* Priority 4a: No BE nor BK - use VI if exists */
497 else if (ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE)
498 queue = ac_to_queue[IEEE80211_AC_VI];
499 /* Priority 4b: No BE, BK nor VI - use VO if exists */
500 else if (ac_to_queue[IEEE80211_AC_VO] != IEEE80211_INVAL_HW_QUEUE)
501 queue = ac_to_queue[IEEE80211_AC_VO];
502
503 /* Make sure queue found (or not) is legal */
504 if (!((queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE &&
505 queue <= IWL_MVM_DQA_MAX_MGMT_QUEUE) ||
506 (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE &&
507 queue <= IWL_MVM_DQA_MAX_DATA_QUEUE) ||
508 (queue == IWL_MVM_DQA_BSS_CLIENT_QUEUE))) {
509 IWL_ERR(mvm, "No DATA queues available to share\n");
510 queue = -ENOSPC;
511 }
512
513 return queue;
514}
515
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200516/*
517 * If a given queue has a higher AC than the TID stream that is being added to
518 * it, the queue needs to be redirected to the lower AC. This function does that
519 * in such a case, otherwise - if no redirection required - it does nothing,
520 * unless the %force param is true.
521 */
522static int iwl_mvm_scd_queue_redirect(struct iwl_mvm *mvm, int queue, int tid,
523 int ac, int ssn, unsigned int wdg_timeout,
524 bool force)
525{
526 struct iwl_scd_txq_cfg_cmd cmd = {
527 .scd_queue = queue,
528 .enable = 0,
529 };
530 bool shared_queue;
531 unsigned long mq;
532 int ret;
533
534 /*
535 * If the AC is lower than current one - FIFO needs to be redirected to
536 * the lowest one of the streams in the queue. Check if this is needed
537 * here.
538 * Notice that the enum ieee80211_ac_numbers is "flipped", so BK is with
539 * value 3 and VO with value 0, so to check if ac X is lower than ac Y
540 * we need to check if the numerical value of X is LARGER than of Y.
541 */
542 spin_lock_bh(&mvm->queue_info_lock);
543 if (ac <= mvm->queue_info[queue].mac80211_ac && !force) {
544 spin_unlock_bh(&mvm->queue_info_lock);
545
546 IWL_DEBUG_TX_QUEUES(mvm,
547 "No redirection needed on TXQ #%d\n",
548 queue);
549 return 0;
550 }
551
552 cmd.sta_id = mvm->queue_info[queue].ra_sta_id;
553 cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[mvm->queue_info[queue].mac80211_ac];
554 mq = mvm->queue_info[queue].hw_queue_to_mac80211;
555 shared_queue = (mvm->queue_info[queue].hw_queue_refcount > 1);
556 spin_unlock_bh(&mvm->queue_info_lock);
557
558 IWL_DEBUG_TX_QUEUES(mvm, "Redirecting shared TXQ #%d to FIFO #%d\n",
559 queue, iwl_mvm_ac_to_tx_fifo[ac]);
560
561 /* Stop MAC queues and wait for this queue to empty */
562 iwl_mvm_stop_mac_queues(mvm, mq);
563 ret = iwl_trans_wait_tx_queue_empty(mvm->trans, BIT(queue));
564 if (ret) {
565 IWL_ERR(mvm, "Error draining queue %d before reconfig\n",
566 queue);
567 ret = -EIO;
568 goto out;
569 }
570
571 /* Before redirecting the queue we need to de-activate it */
572 iwl_trans_txq_disable(mvm->trans, queue, false);
573 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd);
574 if (ret)
575 IWL_ERR(mvm, "Failed SCD disable TXQ %d (ret=%d)\n", queue,
576 ret);
577
578 /* Make sure the SCD wrptr is correctly set before reconfiguring */
579 iwl_trans_txq_enable(mvm->trans, queue, iwl_mvm_ac_to_tx_fifo[ac],
580 cmd.sta_id, tid, LINK_QUAL_AGG_FRAME_LIMIT_DEF,
581 ssn, wdg_timeout);
582
583 /* TODO: Work-around SCD bug when moving back by multiples of 0x40 */
584
585 /* Redirect to lower AC */
586 iwl_mvm_reconfig_scd(mvm, queue, iwl_mvm_ac_to_tx_fifo[ac],
587 cmd.sta_id, tid, LINK_QUAL_AGG_FRAME_LIMIT_DEF,
588 ssn);
589
590 /* Update AC marking of the queue */
591 spin_lock_bh(&mvm->queue_info_lock);
592 mvm->queue_info[queue].mac80211_ac = ac;
593 spin_unlock_bh(&mvm->queue_info_lock);
594
595 /*
596 * Mark queue as shared in transport if shared
597 * Note this has to be done after queue enablement because enablement
598 * can also set this value, and there is no indication there to shared
599 * queues
600 */
601 if (shared_queue)
602 iwl_trans_txq_set_shared_mode(mvm->trans, queue, true);
603
604out:
605 /* Continue using the MAC queues */
606 iwl_mvm_start_mac_queues(mvm, mq);
607
608 return ret;
609}
610
Liad Kaufman24afba72015-07-28 18:56:08 +0300611static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm,
612 struct ieee80211_sta *sta, u8 ac, int tid,
613 struct ieee80211_hdr *hdr)
614{
615 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
616 struct iwl_trans_txq_scd_cfg cfg = {
617 .fifo = iwl_mvm_ac_to_tx_fifo[ac],
618 .sta_id = mvmsta->sta_id,
619 .tid = tid,
620 .frame_limit = IWL_FRAME_LIMIT,
621 };
622 unsigned int wdg_timeout =
623 iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
624 u8 mac_queue = mvmsta->vif->hw_queue[ac];
625 int queue = -1;
Liad Kaufman9794c642015-08-19 17:34:28 +0300626 bool using_inactive_queue = false;
627 unsigned long disable_agg_tids = 0;
628 enum iwl_mvm_agg_state queue_state;
Liad Kaufman42db09c2016-05-02 14:01:14 +0300629 bool shared_queue = false;
Liad Kaufman24afba72015-07-28 18:56:08 +0300630 int ssn;
Liad Kaufman42db09c2016-05-02 14:01:14 +0300631 unsigned long tfd_queue_mask;
Liad Kaufmancf961e12015-08-13 19:16:08 +0300632 int ret;
Liad Kaufman24afba72015-07-28 18:56:08 +0300633
634 lockdep_assert_held(&mvm->mutex);
635
Liad Kaufman42db09c2016-05-02 14:01:14 +0300636 spin_lock_bh(&mvmsta->lock);
637 tfd_queue_mask = mvmsta->tfd_queue_msk;
638 spin_unlock_bh(&mvmsta->lock);
639
Liad Kaufmand2515a92016-03-23 16:31:08 +0200640 spin_lock_bh(&mvm->queue_info_lock);
Liad Kaufman24afba72015-07-28 18:56:08 +0300641
642 /*
643 * Non-QoS, QoS NDP and MGMT frames should go to a MGMT queue, if one
644 * exists
645 */
646 if (!ieee80211_is_data_qos(hdr->frame_control) ||
647 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
Liad Kaufman9794c642015-08-19 17:34:28 +0300648 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
649 IWL_MVM_DQA_MIN_MGMT_QUEUE,
Liad Kaufman24afba72015-07-28 18:56:08 +0300650 IWL_MVM_DQA_MAX_MGMT_QUEUE);
651 if (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE)
652 IWL_DEBUG_TX_QUEUES(mvm, "Found free MGMT queue #%d\n",
653 queue);
654
655 /* If no such queue is found, we'll use a DATA queue instead */
656 }
657
Liad Kaufman9794c642015-08-19 17:34:28 +0300658 if ((queue < 0 && mvmsta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) &&
659 (mvm->queue_info[mvmsta->reserved_queue].status ==
660 IWL_MVM_QUEUE_RESERVED ||
661 mvm->queue_info[mvmsta->reserved_queue].status ==
662 IWL_MVM_QUEUE_INACTIVE)) {
Liad Kaufman24afba72015-07-28 18:56:08 +0300663 queue = mvmsta->reserved_queue;
Liad Kaufman9794c642015-08-19 17:34:28 +0300664 mvm->queue_info[queue].reserved = true;
Liad Kaufman24afba72015-07-28 18:56:08 +0300665 IWL_DEBUG_TX_QUEUES(mvm, "Using reserved queue #%d\n", queue);
666 }
667
668 if (queue < 0)
Liad Kaufman9794c642015-08-19 17:34:28 +0300669 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
670 IWL_MVM_DQA_MIN_DATA_QUEUE,
Liad Kaufman24afba72015-07-28 18:56:08 +0300671 IWL_MVM_DQA_MAX_DATA_QUEUE);
Liad Kaufmancf961e12015-08-13 19:16:08 +0300672
673 /*
Liad Kaufman9794c642015-08-19 17:34:28 +0300674 * Check if this queue is already allocated but inactive.
675 * In such a case, we'll need to first free this queue before enabling
676 * it again, so we'll mark it as reserved to make sure no new traffic
677 * arrives on it
678 */
679 if (queue > 0 &&
680 mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) {
681 mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED;
682 using_inactive_queue = true;
683 IWL_DEBUG_TX_QUEUES(mvm,
684 "Re-assigning TXQ %d: sta_id=%d, tid=%d\n",
685 queue, mvmsta->sta_id, tid);
686 }
687
Liad Kaufman42db09c2016-05-02 14:01:14 +0300688 /* No free queue - we'll have to share */
689 if (queue <= 0) {
690 queue = iwl_mvm_get_shared_queue(mvm, tfd_queue_mask, ac);
691 if (queue > 0) {
692 shared_queue = true;
693 mvm->queue_info[queue].status = IWL_MVM_QUEUE_SHARED;
694 }
695 }
696
Liad Kaufman9794c642015-08-19 17:34:28 +0300697 /*
Liad Kaufmancf961e12015-08-13 19:16:08 +0300698 * Mark TXQ as ready, even though it hasn't been fully configured yet,
699 * to make sure no one else takes it.
700 * This will allow avoiding re-acquiring the lock at the end of the
701 * configuration. On error we'll mark it back as free.
702 */
Liad Kaufman42db09c2016-05-02 14:01:14 +0300703 if ((queue > 0) && !shared_queue)
Liad Kaufmancf961e12015-08-13 19:16:08 +0300704 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
Liad Kaufman24afba72015-07-28 18:56:08 +0300705
Liad Kaufmand2515a92016-03-23 16:31:08 +0200706 spin_unlock_bh(&mvm->queue_info_lock);
Liad Kaufman24afba72015-07-28 18:56:08 +0300707
Liad Kaufman42db09c2016-05-02 14:01:14 +0300708 /* This shouldn't happen - out of queues */
709 if (WARN_ON(queue <= 0)) {
710 IWL_ERR(mvm, "No available queues for tid %d on sta_id %d\n",
711 tid, cfg.sta_id);
Liad Kaufman24afba72015-07-28 18:56:08 +0300712 return -ENOSPC;
Liad Kaufman42db09c2016-05-02 14:01:14 +0300713 }
Liad Kaufman24afba72015-07-28 18:56:08 +0300714
715 /*
716 * Actual en/disablement of aggregations is through the ADD_STA HCMD,
717 * but for configuring the SCD to send A-MPDUs we need to mark the queue
718 * as aggregatable.
719 * Mark all DATA queues as allowing to be aggregated at some point
720 */
Liad Kaufmand5216a22015-08-09 15:50:51 +0300721 cfg.aggregate = (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
722 queue == IWL_MVM_DQA_BSS_CLIENT_QUEUE);
Liad Kaufman24afba72015-07-28 18:56:08 +0300723
Liad Kaufman9794c642015-08-19 17:34:28 +0300724 /*
725 * If this queue was previously inactive (idle) - we need to free it
726 * first
727 */
728 if (using_inactive_queue) {
729 struct iwl_scd_txq_cfg_cmd cmd = {
730 .scd_queue = queue,
731 .enable = 0,
732 };
Liad Kaufman93f436e2015-08-31 13:41:26 +0300733 u8 ac;
Liad Kaufman9794c642015-08-19 17:34:28 +0300734
735 disable_agg_tids = iwl_mvm_remove_sta_queue_marking(mvm, queue);
736
Liad Kaufman93f436e2015-08-31 13:41:26 +0300737 spin_lock_bh(&mvm->queue_info_lock);
738 ac = mvm->queue_info[queue].mac80211_ac;
739 cmd.sta_id = mvm->queue_info[queue].ra_sta_id;
740 cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[ac];
741 spin_unlock_bh(&mvm->queue_info_lock);
742
Liad Kaufman9794c642015-08-19 17:34:28 +0300743 /* Disable the queue */
744 iwl_mvm_invalidate_sta_queue(mvm, queue, disable_agg_tids,
745 true);
746 iwl_trans_txq_disable(mvm->trans, queue, false);
747 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd),
748 &cmd);
749 if (ret) {
750 IWL_ERR(mvm,
751 "Failed to free inactive queue %d (ret=%d)\n",
752 queue, ret);
753
754 /* Re-mark the inactive queue as inactive */
755 spin_lock_bh(&mvm->queue_info_lock);
756 mvm->queue_info[queue].status = IWL_MVM_QUEUE_INACTIVE;
757 spin_unlock_bh(&mvm->queue_info_lock);
758
759 return ret;
760 }
761 }
762
Liad Kaufman42db09c2016-05-02 14:01:14 +0300763 IWL_DEBUG_TX_QUEUES(mvm,
764 "Allocating %squeue #%d to sta %d on tid %d\n",
765 shared_queue ? "shared " : "", queue,
766 mvmsta->sta_id, tid);
767
768 if (shared_queue) {
769 /* Disable any open aggs on this queue */
770 disable_agg_tids = iwl_mvm_get_queue_agg_tids(mvm, queue);
771
772 if (disable_agg_tids) {
773 IWL_DEBUG_TX_QUEUES(mvm, "Disabling aggs on queue %d\n",
774 queue);
775 iwl_mvm_invalidate_sta_queue(mvm, queue,
776 disable_agg_tids, false);
777 }
Liad Kaufman42db09c2016-05-02 14:01:14 +0300778 }
Liad Kaufman24afba72015-07-28 18:56:08 +0300779
780 ssn = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
781 iwl_mvm_enable_txq(mvm, queue, mac_queue, ssn, &cfg,
782 wdg_timeout);
783
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200784 /*
785 * Mark queue as shared in transport if shared
786 * Note this has to be done after queue enablement because enablement
787 * can also set this value, and there is no indication there to shared
788 * queues
789 */
790 if (shared_queue)
791 iwl_trans_txq_set_shared_mode(mvm->trans, queue, true);
792
Liad Kaufman24afba72015-07-28 18:56:08 +0300793 spin_lock_bh(&mvmsta->lock);
794 mvmsta->tid_data[tid].txq_id = queue;
Liad Kaufman9794c642015-08-19 17:34:28 +0300795 mvmsta->tid_data[tid].is_tid_active = true;
Liad Kaufman24afba72015-07-28 18:56:08 +0300796 mvmsta->tfd_queue_msk |= BIT(queue);
Liad Kaufman9794c642015-08-19 17:34:28 +0300797 queue_state = mvmsta->tid_data[tid].state;
Liad Kaufman24afba72015-07-28 18:56:08 +0300798
799 if (mvmsta->reserved_queue == queue)
800 mvmsta->reserved_queue = IEEE80211_INVAL_HW_QUEUE;
801 spin_unlock_bh(&mvmsta->lock);
802
Liad Kaufman42db09c2016-05-02 14:01:14 +0300803 if (!shared_queue) {
804 ret = iwl_mvm_sta_send_to_fw(mvm, sta, true, STA_MODIFY_QUEUES);
805 if (ret)
806 goto out_err;
Liad Kaufmancf961e12015-08-13 19:16:08 +0300807
Liad Kaufman42db09c2016-05-02 14:01:14 +0300808 /* If we need to re-enable aggregations... */
809 if (queue_state == IWL_AGG_ON) {
810 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
811 if (ret)
812 goto out_err;
813 }
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200814 } else {
815 /* Redirect queue, if needed */
816 ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid, ac, ssn,
817 wdg_timeout, false);
818 if (ret)
819 goto out_err;
Liad Kaufman42db09c2016-05-02 14:01:14 +0300820 }
Liad Kaufman9794c642015-08-19 17:34:28 +0300821
Liad Kaufman42db09c2016-05-02 14:01:14 +0300822 return 0;
Liad Kaufmancf961e12015-08-13 19:16:08 +0300823
824out_err:
825 iwl_mvm_disable_txq(mvm, queue, mac_queue, tid, 0);
826
827 return ret;
Liad Kaufman24afba72015-07-28 18:56:08 +0300828}
829
830static inline u8 iwl_mvm_tid_to_ac_queue(int tid)
831{
832 if (tid == IWL_MAX_TID_COUNT)
833 return IEEE80211_AC_VO; /* MGMT */
834
835 return tid_to_mac80211_ac[tid];
836}
837
838static void iwl_mvm_tx_deferred_stream(struct iwl_mvm *mvm,
839 struct ieee80211_sta *sta, int tid)
840{
841 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
842 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
843 struct sk_buff *skb;
844 struct ieee80211_hdr *hdr;
845 struct sk_buff_head deferred_tx;
846 u8 mac_queue;
847 bool no_queue = false; /* Marks if there is a problem with the queue */
848 u8 ac;
849
850 lockdep_assert_held(&mvm->mutex);
851
852 skb = skb_peek(&tid_data->deferred_tx_frames);
853 if (!skb)
854 return;
855 hdr = (void *)skb->data;
856
857 ac = iwl_mvm_tid_to_ac_queue(tid);
858 mac_queue = IEEE80211_SKB_CB(skb)->hw_queue;
859
860 if (tid_data->txq_id == IEEE80211_INVAL_HW_QUEUE &&
861 iwl_mvm_sta_alloc_queue(mvm, sta, ac, tid, hdr)) {
862 IWL_ERR(mvm,
863 "Can't alloc TXQ for sta %d tid %d - dropping frame\n",
864 mvmsta->sta_id, tid);
865
866 /*
867 * Mark queue as problematic so later the deferred traffic is
868 * freed, as we can do nothing with it
869 */
870 no_queue = true;
871 }
872
873 __skb_queue_head_init(&deferred_tx);
874
Liad Kaufmand2515a92016-03-23 16:31:08 +0200875 /* Disable bottom-halves when entering TX path */
876 local_bh_disable();
Liad Kaufman24afba72015-07-28 18:56:08 +0300877 spin_lock(&mvmsta->lock);
878 skb_queue_splice_init(&tid_data->deferred_tx_frames, &deferred_tx);
879 spin_unlock(&mvmsta->lock);
880
Liad Kaufman24afba72015-07-28 18:56:08 +0300881 while ((skb = __skb_dequeue(&deferred_tx)))
882 if (no_queue || iwl_mvm_tx_skb(mvm, skb, sta))
883 ieee80211_free_txskb(mvm->hw, skb);
884 local_bh_enable();
885
886 /* Wake queue */
887 iwl_mvm_start_mac_queues(mvm, BIT(mac_queue));
888}
889
890void iwl_mvm_add_new_dqa_stream_wk(struct work_struct *wk)
891{
892 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm,
893 add_stream_wk);
894 struct ieee80211_sta *sta;
895 struct iwl_mvm_sta *mvmsta;
896 unsigned long deferred_tid_traffic;
897 int sta_id, tid;
898
Liad Kaufman9794c642015-08-19 17:34:28 +0300899 /* Check inactivity of queues */
900 iwl_mvm_inactivity_check(mvm);
901
Liad Kaufman24afba72015-07-28 18:56:08 +0300902 mutex_lock(&mvm->mutex);
903
904 /* Go over all stations with deferred traffic */
905 for_each_set_bit(sta_id, mvm->sta_deferred_frames,
906 IWL_MVM_STATION_COUNT) {
907 clear_bit(sta_id, mvm->sta_deferred_frames);
908 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
909 lockdep_is_held(&mvm->mutex));
910 if (IS_ERR_OR_NULL(sta))
911 continue;
912
913 mvmsta = iwl_mvm_sta_from_mac80211(sta);
914 deferred_tid_traffic = mvmsta->deferred_traffic_tid_map;
915
916 for_each_set_bit(tid, &deferred_tid_traffic,
917 IWL_MAX_TID_COUNT + 1)
918 iwl_mvm_tx_deferred_stream(mvm, sta, tid);
919 }
920
921 mutex_unlock(&mvm->mutex);
922}
923
924static int iwl_mvm_reserve_sta_stream(struct iwl_mvm *mvm,
Liad Kaufmand5216a22015-08-09 15:50:51 +0300925 struct ieee80211_sta *sta,
926 enum nl80211_iftype vif_type)
Liad Kaufman24afba72015-07-28 18:56:08 +0300927{
928 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
929 int queue;
930
Liad Kaufman9794c642015-08-19 17:34:28 +0300931 /*
932 * Check for inactive queues, so we don't reach a situation where we
933 * can't add a STA due to a shortage in queues that doesn't really exist
934 */
935 iwl_mvm_inactivity_check(mvm);
936
Liad Kaufman24afba72015-07-28 18:56:08 +0300937 spin_lock_bh(&mvm->queue_info_lock);
938
939 /* Make sure we have free resources for this STA */
Liad Kaufmand5216a22015-08-09 15:50:51 +0300940 if (vif_type == NL80211_IFTYPE_STATION && !sta->tdls &&
941 !mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].hw_queue_refcount &&
Liad Kaufmancf961e12015-08-13 19:16:08 +0300942 (mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].status ==
943 IWL_MVM_QUEUE_FREE))
Liad Kaufmand5216a22015-08-09 15:50:51 +0300944 queue = IWL_MVM_DQA_BSS_CLIENT_QUEUE;
945 else
Liad Kaufman9794c642015-08-19 17:34:28 +0300946 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
947 IWL_MVM_DQA_MIN_DATA_QUEUE,
Liad Kaufmand5216a22015-08-09 15:50:51 +0300948 IWL_MVM_DQA_MAX_DATA_QUEUE);
Liad Kaufman24afba72015-07-28 18:56:08 +0300949 if (queue < 0) {
950 spin_unlock_bh(&mvm->queue_info_lock);
951 IWL_ERR(mvm, "No available queues for new station\n");
952 return -ENOSPC;
953 }
Liad Kaufmancf961e12015-08-13 19:16:08 +0300954 mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED;
Liad Kaufman24afba72015-07-28 18:56:08 +0300955
956 spin_unlock_bh(&mvm->queue_info_lock);
957
958 mvmsta->reserved_queue = queue;
959
960 IWL_DEBUG_TX_QUEUES(mvm, "Reserving data queue #%d for sta_id %d\n",
961 queue, mvmsta->sta_id);
962
963 return 0;
964}
965
Johannes Berg8ca151b2013-01-24 14:25:36 +0100966int iwl_mvm_add_sta(struct iwl_mvm *mvm,
967 struct ieee80211_vif *vif,
968 struct ieee80211_sta *sta)
969{
970 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +0100971 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Sara Sharona571f5f2015-12-07 12:50:58 +0200972 struct iwl_mvm_rxq_dup_data *dup_data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100973 int i, ret, sta_id;
974
975 lockdep_assert_held(&mvm->mutex);
976
977 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
Eliad Pellerb92e6612014-01-23 17:58:23 +0200978 sta_id = iwl_mvm_find_free_sta_id(mvm,
979 ieee80211_vif_type_p2p(vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100980 else
981 sta_id = mvm_sta->sta_id;
982
Johannes Berg36f46312015-03-10 20:32:08 +0100983 if (sta_id == IWL_MVM_STATION_COUNT)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100984 return -ENOSPC;
985
986 spin_lock_init(&mvm_sta->lock);
987
988 mvm_sta->sta_id = sta_id;
989 mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id,
990 mvmvif->color);
991 mvm_sta->vif = vif;
992 mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300993 mvm_sta->tx_protection = 0;
994 mvm_sta->tt_tx_protection = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100995
996 /* HW restart, don't assume the memory has been zeroed */
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +0300997 atomic_set(&mvm->pending_frames[sta_id], 0);
Liad Kaufman69191af2015-09-01 18:50:22 +0300998 mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100999 mvm_sta->tfd_queue_msk = 0;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001000
Liad Kaufmane3118ad2016-06-05 10:49:02 +03001001 /*
1002 * Allocate new queues for a TDLS station, unless we're in DQA mode,
1003 * and then they'll be allocated dynamically
1004 */
1005 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) {
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001006 ret = iwl_mvm_tdls_sta_init(mvm, sta);
1007 if (ret)
1008 return ret;
Liad Kaufman24afba72015-07-28 18:56:08 +03001009 } else if (!iwl_mvm_is_dqa_supported(mvm)) {
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001010 for (i = 0; i < IEEE80211_NUM_ACS; i++)
1011 if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE)
1012 mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]);
1013 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001014
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001015 /* for HW restart - reset everything but the sequence number */
Liad Kaufman24afba72015-07-28 18:56:08 +03001016 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001017 u16 seq = mvm_sta->tid_data[i].seq_number;
1018 memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i]));
1019 mvm_sta->tid_data[i].seq_number = seq;
Liad Kaufman24afba72015-07-28 18:56:08 +03001020
1021 if (!iwl_mvm_is_dqa_supported(mvm))
1022 continue;
1023
1024 /*
1025 * Mark all queues for this STA as unallocated and defer TX
1026 * frames until the queue is allocated
1027 */
1028 mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE;
1029 skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001030 }
Liad Kaufman24afba72015-07-28 18:56:08 +03001031 mvm_sta->deferred_traffic_tid_map = 0;
Eyal Shapiraefed6642014-09-14 15:58:53 +03001032 mvm_sta->agg_tids = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001033
Sara Sharona571f5f2015-12-07 12:50:58 +02001034 if (iwl_mvm_has_new_rx_api(mvm) &&
1035 !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1036 dup_data = kcalloc(mvm->trans->num_rx_queues,
1037 sizeof(*dup_data),
1038 GFP_KERNEL);
1039 if (!dup_data)
1040 return -ENOMEM;
1041 mvm_sta->dup_data = dup_data;
1042 }
1043
Liad Kaufman24afba72015-07-28 18:56:08 +03001044 if (iwl_mvm_is_dqa_supported(mvm)) {
Liad Kaufmand5216a22015-08-09 15:50:51 +03001045 ret = iwl_mvm_reserve_sta_stream(mvm, sta,
1046 ieee80211_vif_type_p2p(vif));
Liad Kaufman24afba72015-07-28 18:56:08 +03001047 if (ret)
1048 goto err;
1049 }
1050
1051 ret = iwl_mvm_sta_send_to_fw(mvm, sta, false, 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001052 if (ret)
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001053 goto err;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001054
Johannes Berg9e848012014-08-04 14:33:42 +02001055 if (vif->type == NL80211_IFTYPE_STATION) {
1056 if (!sta->tdls) {
1057 WARN_ON(mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT);
1058 mvmvif->ap_sta_id = sta_id;
1059 } else {
1060 WARN_ON(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT);
1061 }
1062 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001063
1064 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta);
1065
1066 return 0;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001067
1068err:
Liad Kaufmane3118ad2016-06-05 10:49:02 +03001069 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls)
1070 iwl_mvm_tdls_sta_deinit(mvm, sta);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001071 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001072}
1073
Johannes Berg7a453972013-02-12 13:10:44 +01001074int iwl_mvm_update_sta(struct iwl_mvm *mvm,
1075 struct ieee80211_vif *vif,
1076 struct ieee80211_sta *sta)
1077{
Liad Kaufman24afba72015-07-28 18:56:08 +03001078 return iwl_mvm_sta_send_to_fw(mvm, sta, true, 0);
Johannes Berg7a453972013-02-12 13:10:44 +01001079}
1080
Johannes Berg8ca151b2013-01-24 14:25:36 +01001081int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
1082 bool drain)
1083{
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001084 struct iwl_mvm_add_sta_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +01001085 int ret;
1086 u32 status;
1087
1088 lockdep_assert_held(&mvm->mutex);
1089
1090 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
1091 cmd.sta_id = mvmsta->sta_id;
1092 cmd.add_modify = STA_MODE_MODIFY;
1093 cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0;
1094 cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW);
1095
1096 status = ADD_STA_SUCCESS;
Sara Sharon854c5702016-01-26 13:17:47 +02001097 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1098 iwl_mvm_add_sta_cmd_size(mvm),
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001099 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001100 if (ret)
1101 return ret;
1102
Sara Sharon837c4da2016-01-07 16:50:45 +02001103 switch (status & IWL_ADD_STA_STATUS_MASK) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001104 case ADD_STA_SUCCESS:
1105 IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n",
1106 mvmsta->sta_id);
1107 break;
1108 default:
1109 ret = -EIO;
1110 IWL_ERR(mvm, "Couldn't drain frames for staid %d\n",
1111 mvmsta->sta_id);
1112 break;
1113 }
1114
1115 return ret;
1116}
1117
1118/*
1119 * Remove a station from the FW table. Before sending the command to remove
1120 * the station validate that the station is indeed known to the driver (sanity
1121 * only).
1122 */
1123static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id)
1124{
1125 struct ieee80211_sta *sta;
1126 struct iwl_mvm_rm_sta_cmd rm_sta_cmd = {
1127 .sta_id = sta_id,
1128 };
1129 int ret;
1130
1131 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1132 lockdep_is_held(&mvm->mutex));
1133
1134 /* Note: internal stations are marked as error values */
1135 if (!sta) {
1136 IWL_ERR(mvm, "Invalid station id\n");
1137 return -EINVAL;
1138 }
1139
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001140 ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001141 sizeof(rm_sta_cmd), &rm_sta_cmd);
1142 if (ret) {
1143 IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id);
1144 return ret;
1145 }
1146
1147 return 0;
1148}
1149
1150void iwl_mvm_sta_drained_wk(struct work_struct *wk)
1151{
1152 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk);
1153 u8 sta_id;
1154
1155 /*
1156 * The mutex is needed because of the SYNC cmd, but not only: if the
1157 * work would run concurrently with iwl_mvm_rm_sta, it would run before
1158 * iwl_mvm_rm_sta sets the station as busy, and exit. Then
1159 * iwl_mvm_rm_sta would set the station as busy, and nobody will clean
1160 * that later.
1161 */
1162 mutex_lock(&mvm->mutex);
1163
1164 for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) {
1165 int ret;
1166 struct ieee80211_sta *sta =
1167 rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1168 lockdep_is_held(&mvm->mutex));
1169
Johannes Berg1ddbbb02013-12-04 22:39:17 +01001170 /*
1171 * This station is in use or RCU-removed; the latter happens in
1172 * managed mode, where mac80211 removes the station before we
1173 * can remove it from firmware (we can only do that after the
1174 * MAC is marked unassociated), and possibly while the deauth
1175 * frame to disconnect from the AP is still queued. Then, the
1176 * station pointer is -ENOENT when the last skb is reclaimed.
1177 */
1178 if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001179 continue;
1180
1181 if (PTR_ERR(sta) == -EINVAL) {
1182 IWL_ERR(mvm, "Drained sta %d, but it is internal?\n",
1183 sta_id);
1184 continue;
1185 }
1186
1187 if (!sta) {
1188 IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n",
1189 sta_id);
1190 continue;
1191 }
1192
1193 WARN_ON(PTR_ERR(sta) != -EBUSY);
1194 /* This station was removed and we waited until it got drained,
1195 * we can now proceed and remove it.
1196 */
1197 ret = iwl_mvm_rm_sta_common(mvm, sta_id);
1198 if (ret) {
1199 IWL_ERR(mvm,
1200 "Couldn't remove sta %d after it was drained\n",
1201 sta_id);
1202 continue;
1203 }
Monam Agarwalc531c772014-03-24 00:05:56 +05301204 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001205 clear_bit(sta_id, mvm->sta_drained);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001206
1207 if (mvm->tfd_drained[sta_id]) {
1208 unsigned long i, msk = mvm->tfd_drained[sta_id];
1209
Emmanuel Grumbacha4ca3ed2015-01-20 17:07:10 +02001210 for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE)
Arik Nemtsov06ecdba2015-10-12 14:47:11 +03001211 iwl_mvm_disable_txq(mvm, i, i,
1212 IWL_MAX_TID_COUNT, 0);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001213
1214 mvm->tfd_drained[sta_id] = 0;
1215 IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n",
1216 sta_id, msk);
1217 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001218 }
1219
1220 mutex_unlock(&mvm->mutex);
1221}
1222
Liad Kaufman24afba72015-07-28 18:56:08 +03001223static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm,
1224 struct ieee80211_vif *vif,
1225 struct iwl_mvm_sta *mvm_sta)
1226{
1227 int ac;
1228 int i;
1229
1230 lockdep_assert_held(&mvm->mutex);
1231
1232 for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) {
1233 if (mvm_sta->tid_data[i].txq_id == IEEE80211_INVAL_HW_QUEUE)
1234 continue;
1235
1236 ac = iwl_mvm_tid_to_ac_queue(i);
1237 iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id,
1238 vif->hw_queue[ac], i, 0);
1239 mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE;
1240 }
1241}
1242
Johannes Berg8ca151b2013-01-24 14:25:36 +01001243int iwl_mvm_rm_sta(struct iwl_mvm *mvm,
1244 struct ieee80211_vif *vif,
1245 struct ieee80211_sta *sta)
1246{
1247 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01001248 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001249 int ret;
1250
1251 lockdep_assert_held(&mvm->mutex);
1252
Sara Sharona571f5f2015-12-07 12:50:58 +02001253 if (iwl_mvm_has_new_rx_api(mvm))
1254 kfree(mvm_sta->dup_data);
1255
Liad Kaufmana6f035a2015-08-24 15:23:14 +03001256 if ((vif->type == NL80211_IFTYPE_STATION &&
1257 mvmvif->ap_sta_id == mvm_sta->sta_id) ||
1258 iwl_mvm_is_dqa_supported(mvm)){
Emmanuel Grumbachfe92e322015-03-11 09:34:31 +02001259 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
1260 if (ret)
1261 return ret;
Emmanuel Grumbach80d85652013-02-19 15:32:42 +02001262 /* flush its queues here since we are freeing mvm_sta */
Luca Coelho5888a402015-10-06 09:54:57 +03001263 ret = iwl_mvm_flush_tx_path(mvm, mvm_sta->tfd_queue_msk, 0);
Emmanuel Grumbachfe92e322015-03-11 09:34:31 +02001264 if (ret)
1265 return ret;
1266 ret = iwl_trans_wait_tx_queue_empty(mvm->trans,
1267 mvm_sta->tfd_queue_msk);
1268 if (ret)
1269 return ret;
1270 ret = iwl_mvm_drain_sta(mvm, mvm_sta, false);
Emmanuel Grumbach80d85652013-02-19 15:32:42 +02001271
Liad Kaufman24afba72015-07-28 18:56:08 +03001272 /* If DQA is supported - the queues can be disabled now */
1273 if (iwl_mvm_is_dqa_supported(mvm))
1274 iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta);
1275
Liad Kaufmane3118ad2016-06-05 10:49:02 +03001276 if (vif->type == NL80211_IFTYPE_STATION &&
1277 mvmvif->ap_sta_id == mvm_sta->sta_id) {
1278 /* if associated - we can't remove the AP STA now */
1279 if (vif->bss_conf.assoc)
1280 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001281
Liad Kaufmane3118ad2016-06-05 10:49:02 +03001282 /* unassoc - go ahead - remove the AP STA now */
1283 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
Eliad Peller37577fe2013-12-05 17:19:39 +02001284
Liad Kaufmane3118ad2016-06-05 10:49:02 +03001285 /* clear d0i3_ap_sta_id if no longer relevant */
1286 if (mvm->d0i3_ap_sta_id == mvm_sta->sta_id)
1287 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
1288 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001289 }
1290
1291 /*
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +03001292 * This shouldn't happen - the TDLS channel switch should be canceled
1293 * before the STA is removed.
1294 */
1295 if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == mvm_sta->sta_id)) {
1296 mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT;
1297 cancel_delayed_work(&mvm->tdls_cs.dwork);
1298 }
1299
1300 /*
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03001301 * Make sure that the tx response code sees the station as -EBUSY and
1302 * calls the drain worker.
1303 */
1304 spin_lock_bh(&mvm_sta->lock);
1305 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +01001306 * There are frames pending on the AC queues for this station.
1307 * We need to wait until all the frames are drained...
1308 */
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03001309 if (atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001310 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
1311 ERR_PTR(-EBUSY));
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03001312 spin_unlock_bh(&mvm_sta->lock);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001313
1314 /* disable TDLS sta queues on drain complete */
1315 if (sta->tdls) {
1316 mvm->tfd_drained[mvm_sta->sta_id] =
1317 mvm_sta->tfd_queue_msk;
1318 IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n",
1319 mvm_sta->sta_id);
1320 }
1321
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03001322 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001323 } else {
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03001324 spin_unlock_bh(&mvm_sta->lock);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001325
Liad Kaufmane3118ad2016-06-05 10:49:02 +03001326 if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls)
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001327 iwl_mvm_tdls_sta_deinit(mvm, sta);
1328
Johannes Berg8ca151b2013-01-24 14:25:36 +01001329 ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id);
Monam Agarwalc531c772014-03-24 00:05:56 +05301330 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001331 }
1332
1333 return ret;
1334}
1335
1336int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm,
1337 struct ieee80211_vif *vif,
1338 u8 sta_id)
1339{
1340 int ret = iwl_mvm_rm_sta_common(mvm, sta_id);
1341
1342 lockdep_assert_held(&mvm->mutex);
1343
Monam Agarwalc531c772014-03-24 00:05:56 +05301344 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001345 return ret;
1346}
1347
Chaya Rachel Ivgi0e39eb02015-12-03 15:51:46 +02001348int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm,
1349 struct iwl_mvm_int_sta *sta,
1350 u32 qmask, enum nl80211_iftype iftype)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001351{
1352 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
Eliad Pellerb92e6612014-01-23 17:58:23 +02001353 sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001354 if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_STATION_COUNT))
1355 return -ENOSPC;
1356 }
1357
1358 sta->tfd_queue_msk = qmask;
1359
1360 /* put a non-NULL value so iterating over the stations won't stop */
1361 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL));
1362 return 0;
1363}
1364
Johannes Berg712b24a2014-08-04 14:14:14 +02001365static void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm,
1366 struct iwl_mvm_int_sta *sta)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001367{
Monam Agarwalc531c772014-03-24 00:05:56 +05301368 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta->sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001369 memset(sta, 0, sizeof(struct iwl_mvm_int_sta));
1370 sta->sta_id = IWL_MVM_STATION_COUNT;
1371}
1372
1373static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm,
1374 struct iwl_mvm_int_sta *sta,
1375 const u8 *addr,
1376 u16 mac_id, u16 color)
1377{
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001378 struct iwl_mvm_add_sta_cmd cmd;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001379 int ret;
1380 u32 status;
1381
1382 lockdep_assert_held(&mvm->mutex);
1383
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001384 memset(&cmd, 0, sizeof(cmd));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001385 cmd.sta_id = sta->sta_id;
1386 cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id,
1387 color));
1388
1389 cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk);
Liad Kaufmancf0cda12015-09-24 10:44:12 +02001390 cmd.tid_disable_tx = cpu_to_le16(0xffff);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001391
1392 if (addr)
1393 memcpy(cmd.addr, addr, ETH_ALEN);
1394
Sara Sharon854c5702016-01-26 13:17:47 +02001395 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1396 iwl_mvm_add_sta_cmd_size(mvm),
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001397 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001398 if (ret)
1399 return ret;
1400
Sara Sharon837c4da2016-01-07 16:50:45 +02001401 switch (status & IWL_ADD_STA_STATUS_MASK) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001402 case ADD_STA_SUCCESS:
1403 IWL_DEBUG_INFO(mvm, "Internal station added.\n");
1404 return 0;
1405 default:
1406 ret = -EIO;
1407 IWL_ERR(mvm, "Add internal station failed, status=0x%x\n",
1408 status);
1409 break;
1410 }
1411 return ret;
1412}
1413
1414int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm)
1415{
Emmanuel Grumbach4cf677f2015-01-12 14:38:29 +02001416 unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ?
1417 mvm->cfg->base_params->wd_timeout :
1418 IWL_WATCHDOG_DISABLED;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001419 int ret;
1420
1421 lockdep_assert_held(&mvm->mutex);
1422
Ariej Marjieh7da91b02014-07-07 12:09:40 +03001423 /* Map Aux queue to fifo - needs to happen before adding Aux station */
Liad Kaufman28d07932015-09-01 16:36:25 +03001424 if (!iwl_mvm_is_dqa_supported(mvm))
1425 iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue,
1426 IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout);
Ariej Marjieh7da91b02014-07-07 12:09:40 +03001427
1428 /* Allocate aux station and assign to it the aux queue */
1429 ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue),
Eliad Pellerb92e6612014-01-23 17:58:23 +02001430 NL80211_IFTYPE_UNSPECIFIED);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001431 if (ret)
1432 return ret;
1433
Liad Kaufman28d07932015-09-01 16:36:25 +03001434 if (iwl_mvm_is_dqa_supported(mvm)) {
1435 struct iwl_trans_txq_scd_cfg cfg = {
1436 .fifo = IWL_MVM_TX_FIFO_MCAST,
1437 .sta_id = mvm->aux_sta.sta_id,
1438 .tid = IWL_MAX_TID_COUNT,
1439 .aggregate = false,
1440 .frame_limit = IWL_FRAME_LIMIT,
1441 };
1442
1443 iwl_mvm_enable_txq(mvm, mvm->aux_queue, mvm->aux_queue, 0, &cfg,
1444 wdg_timeout);
1445 }
1446
Johannes Berg8ca151b2013-01-24 14:25:36 +01001447 ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL,
1448 MAC_INDEX_AUX, 0);
1449
1450 if (ret)
1451 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
1452 return ret;
1453}
1454
Chaya Rachel Ivgi0e39eb02015-12-03 15:51:46 +02001455int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1456{
1457 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1458
1459 lockdep_assert_held(&mvm->mutex);
1460 return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr,
1461 mvmvif->id, 0);
1462}
1463
1464int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1465{
1466 int ret;
1467
1468 lockdep_assert_held(&mvm->mutex);
1469
1470 ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id);
1471 if (ret)
1472 IWL_WARN(mvm, "Failed sending remove station\n");
1473
1474 return ret;
1475}
1476
1477void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm)
1478{
1479 iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta);
1480}
1481
Johannes Berg712b24a2014-08-04 14:14:14 +02001482void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm)
1483{
1484 lockdep_assert_held(&mvm->mutex);
1485
1486 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
1487}
1488
Johannes Berg8ca151b2013-01-24 14:25:36 +01001489/*
1490 * Send the add station command for the vif's broadcast station.
1491 * Assumes that the station was already allocated.
1492 *
1493 * @mvm: the mvm component
1494 * @vif: the interface to which the broadcast station is added
1495 * @bsta: the broadcast station to add.
1496 */
Johannes Berg013290a2014-08-04 13:38:48 +02001497int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001498{
1499 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg013290a2014-08-04 13:38:48 +02001500 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
Johannes Berg5023d962013-07-31 14:07:43 +02001501 static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
Johannes Berga4243402014-01-20 23:46:38 +01001502 const u8 *baddr = _baddr;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001503
1504 lockdep_assert_held(&mvm->mutex);
1505
Liad Kaufmande24f632015-08-04 15:19:18 +03001506 if (iwl_mvm_is_dqa_supported(mvm)) {
1507 struct iwl_trans_txq_scd_cfg cfg = {
1508 .fifo = IWL_MVM_TX_FIFO_VO,
1509 .sta_id = mvmvif->bcast_sta.sta_id,
1510 .tid = IWL_MAX_TID_COUNT,
1511 .aggregate = false,
1512 .frame_limit = IWL_FRAME_LIMIT,
1513 };
1514 unsigned int wdg_timeout =
1515 iwl_mvm_get_wd_timeout(mvm, vif, false, false);
1516 int queue;
1517
1518 if ((vif->type == NL80211_IFTYPE_AP) &&
1519 (mvmvif->bcast_sta.tfd_queue_msk &
1520 BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE)))
1521 queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE;
Liad Kaufman4c965132015-08-09 19:26:56 +03001522 else if ((vif->type == NL80211_IFTYPE_P2P_DEVICE) &&
1523 (mvmvif->bcast_sta.tfd_queue_msk &
1524 BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE)))
1525 queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE;
Liad Kaufmande24f632015-08-04 15:19:18 +03001526 else if (WARN(1, "Missed required TXQ for adding bcast STA\n"))
1527 return -EINVAL;
1528
1529 iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[0], 0, &cfg,
1530 wdg_timeout);
1531 }
1532
Johannes Berg5023d962013-07-31 14:07:43 +02001533 if (vif->type == NL80211_IFTYPE_ADHOC)
1534 baddr = vif->bss_conf.bssid;
1535
Johannes Berg8ca151b2013-01-24 14:25:36 +01001536 if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_STATION_COUNT))
1537 return -ENOSPC;
1538
1539 return iwl_mvm_add_int_sta_common(mvm, bsta, baddr,
1540 mvmvif->id, mvmvif->color);
1541}
1542
1543/* Send the FW a request to remove the station from it's internal data
1544 * structures, but DO NOT remove the entry from the local data structures. */
Johannes Berg013290a2014-08-04 13:38:48 +02001545int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001546{
Johannes Berg013290a2014-08-04 13:38:48 +02001547 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001548 int ret;
1549
1550 lockdep_assert_held(&mvm->mutex);
1551
Johannes Berg013290a2014-08-04 13:38:48 +02001552 ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001553 if (ret)
1554 IWL_WARN(mvm, "Failed sending remove station\n");
1555 return ret;
1556}
1557
Johannes Berg013290a2014-08-04 13:38:48 +02001558int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1559{
1560 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Liad Kaufmande24f632015-08-04 15:19:18 +03001561 u32 qmask = 0;
Johannes Berg013290a2014-08-04 13:38:48 +02001562
1563 lockdep_assert_held(&mvm->mutex);
1564
Liad Kaufmande24f632015-08-04 15:19:18 +03001565 if (!iwl_mvm_is_dqa_supported(mvm))
1566 qmask = iwl_mvm_mac_get_queues_mask(vif);
Johannes Berg013290a2014-08-04 13:38:48 +02001567
Liad Kaufmande24f632015-08-04 15:19:18 +03001568 if (vif->type == NL80211_IFTYPE_AP) {
1569 /*
1570 * The firmware defines the TFD queue mask to only be relevant
1571 * for *unicast* queues, so the multicast (CAB) queue shouldn't
1572 * be included.
1573 */
Johannes Berg013290a2014-08-04 13:38:48 +02001574 qmask &= ~BIT(vif->cab_queue);
1575
Liad Kaufmande24f632015-08-04 15:19:18 +03001576 if (iwl_mvm_is_dqa_supported(mvm))
1577 qmask |= BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE);
Liad Kaufman4c965132015-08-09 19:26:56 +03001578 } else if (iwl_mvm_is_dqa_supported(mvm) &&
1579 vif->type == NL80211_IFTYPE_P2P_DEVICE) {
1580 qmask |= BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE);
Liad Kaufmande24f632015-08-04 15:19:18 +03001581 }
1582
Johannes Berg013290a2014-08-04 13:38:48 +02001583 return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask,
1584 ieee80211_vif_type_p2p(vif));
1585}
1586
Johannes Berg8ca151b2013-01-24 14:25:36 +01001587/* Allocate a new station entry for the broadcast station to the given vif,
1588 * and send it to the FW.
1589 * Note that each P2P mac should have its own broadcast station.
1590 *
1591 * @mvm: the mvm component
1592 * @vif: the interface to which the broadcast station is added
1593 * @bsta: the broadcast station to add. */
Johannes Berg013290a2014-08-04 13:38:48 +02001594int iwl_mvm_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001595{
1596 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg013290a2014-08-04 13:38:48 +02001597 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001598 int ret;
1599
1600 lockdep_assert_held(&mvm->mutex);
1601
Johannes Berg013290a2014-08-04 13:38:48 +02001602 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001603 if (ret)
1604 return ret;
1605
Johannes Berg013290a2014-08-04 13:38:48 +02001606 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001607
1608 if (ret)
1609 iwl_mvm_dealloc_int_sta(mvm, bsta);
Johannes Berg013290a2014-08-04 13:38:48 +02001610
Johannes Berg8ca151b2013-01-24 14:25:36 +01001611 return ret;
1612}
1613
Johannes Berg013290a2014-08-04 13:38:48 +02001614void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1615{
1616 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1617
1618 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
1619}
1620
Johannes Berg8ca151b2013-01-24 14:25:36 +01001621/*
1622 * Send the FW a request to remove the station from it's internal data
1623 * structures, and in addition remove it from the local data structure.
1624 */
Johannes Berg013290a2014-08-04 13:38:48 +02001625int iwl_mvm_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001626{
1627 int ret;
1628
1629 lockdep_assert_held(&mvm->mutex);
1630
Johannes Berg013290a2014-08-04 13:38:48 +02001631 ret = iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001632
Johannes Berg013290a2014-08-04 13:38:48 +02001633 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1634
Johannes Berg8ca151b2013-01-24 14:25:36 +01001635 return ret;
1636}
1637
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03001638#define IWL_MAX_RX_BA_SESSIONS 16
1639
Sara Sharonb915c102016-03-23 16:32:02 +02001640static void iwl_mvm_sync_rxq_del_ba(struct iwl_mvm *mvm, u8 baid)
Sara Sharon10b2b202016-03-20 16:23:41 +02001641{
Sara Sharonb915c102016-03-23 16:32:02 +02001642 struct iwl_mvm_delba_notif notif = {
1643 .metadata.type = IWL_MVM_RXQ_NOTIF_DEL_BA,
1644 .metadata.sync = 1,
1645 .delba.baid = baid,
Sara Sharon10b2b202016-03-20 16:23:41 +02001646 };
Sara Sharonb915c102016-03-23 16:32:02 +02001647 iwl_mvm_sync_rx_queues_internal(mvm, (void *)&notif, sizeof(notif));
1648};
Sara Sharon10b2b202016-03-20 16:23:41 +02001649
Sara Sharonb915c102016-03-23 16:32:02 +02001650static void iwl_mvm_free_reorder(struct iwl_mvm *mvm,
1651 struct iwl_mvm_baid_data *data)
1652{
1653 int i;
1654
1655 iwl_mvm_sync_rxq_del_ba(mvm, data->baid);
1656
1657 for (i = 0; i < mvm->trans->num_rx_queues; i++) {
1658 int j;
1659 struct iwl_mvm_reorder_buffer *reorder_buf =
1660 &data->reorder_buf[i];
1661
Sara Sharon06904052016-02-28 20:28:17 +02001662 spin_lock_bh(&reorder_buf->lock);
1663 if (likely(!reorder_buf->num_stored)) {
1664 spin_unlock_bh(&reorder_buf->lock);
Sara Sharonb915c102016-03-23 16:32:02 +02001665 continue;
Sara Sharon06904052016-02-28 20:28:17 +02001666 }
Sara Sharonb915c102016-03-23 16:32:02 +02001667
1668 /*
1669 * This shouldn't happen in regular DELBA since the internal
1670 * delBA notification should trigger a release of all frames in
1671 * the reorder buffer.
1672 */
1673 WARN_ON(1);
1674
1675 for (j = 0; j < reorder_buf->buf_size; j++)
1676 __skb_queue_purge(&reorder_buf->entries[j]);
Sara Sharon06904052016-02-28 20:28:17 +02001677 /*
1678 * Prevent timer re-arm. This prevents a very far fetched case
1679 * where we timed out on the notification. There may be prior
1680 * RX frames pending in the RX queue before the notification
1681 * that might get processed between now and the actual deletion
1682 * and we would re-arm the timer although we are deleting the
1683 * reorder buffer.
1684 */
1685 reorder_buf->removed = true;
1686 spin_unlock_bh(&reorder_buf->lock);
1687 del_timer_sync(&reorder_buf->reorder_timer);
Sara Sharonb915c102016-03-23 16:32:02 +02001688 }
1689}
1690
1691static void iwl_mvm_init_reorder_buffer(struct iwl_mvm *mvm,
1692 u32 sta_id,
1693 struct iwl_mvm_baid_data *data,
1694 u16 ssn, u8 buf_size)
1695{
1696 int i;
1697
1698 for (i = 0; i < mvm->trans->num_rx_queues; i++) {
1699 struct iwl_mvm_reorder_buffer *reorder_buf =
1700 &data->reorder_buf[i];
1701 int j;
1702
1703 reorder_buf->num_stored = 0;
1704 reorder_buf->head_sn = ssn;
1705 reorder_buf->buf_size = buf_size;
Sara Sharon06904052016-02-28 20:28:17 +02001706 /* rx reorder timer */
1707 reorder_buf->reorder_timer.function =
1708 iwl_mvm_reorder_timer_expired;
1709 reorder_buf->reorder_timer.data = (unsigned long)reorder_buf;
1710 init_timer(&reorder_buf->reorder_timer);
1711 spin_lock_init(&reorder_buf->lock);
1712 reorder_buf->mvm = mvm;
Sara Sharonb915c102016-03-23 16:32:02 +02001713 reorder_buf->queue = i;
1714 reorder_buf->sta_id = sta_id;
1715 for (j = 0; j < reorder_buf->buf_size; j++)
1716 __skb_queue_head_init(&reorder_buf->entries[j]);
1717 }
Sara Sharon10b2b202016-03-20 16:23:41 +02001718}
1719
Johannes Berg8ca151b2013-01-24 14:25:36 +01001720int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
Sara Sharon10b2b202016-03-20 16:23:41 +02001721 int tid, u16 ssn, bool start, u8 buf_size, u16 timeout)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001722{
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01001723 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001724 struct iwl_mvm_add_sta_cmd cmd = {};
Sara Sharon10b2b202016-03-20 16:23:41 +02001725 struct iwl_mvm_baid_data *baid_data = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001726 int ret;
1727 u32 status;
1728
1729 lockdep_assert_held(&mvm->mutex);
1730
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03001731 if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) {
1732 IWL_WARN(mvm, "Not enough RX BA SESSIONS\n");
1733 return -ENOSPC;
1734 }
1735
Sara Sharon10b2b202016-03-20 16:23:41 +02001736 if (iwl_mvm_has_new_rx_api(mvm) && start) {
1737 /*
1738 * Allocate here so if allocation fails we can bail out early
1739 * before starting the BA session in the firmware
1740 */
Sara Sharonb915c102016-03-23 16:32:02 +02001741 baid_data = kzalloc(sizeof(*baid_data) +
1742 mvm->trans->num_rx_queues *
1743 sizeof(baid_data->reorder_buf[0]),
1744 GFP_KERNEL);
Sara Sharon10b2b202016-03-20 16:23:41 +02001745 if (!baid_data)
1746 return -ENOMEM;
1747 }
1748
Johannes Berg8ca151b2013-01-24 14:25:36 +01001749 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
1750 cmd.sta_id = mvm_sta->sta_id;
1751 cmd.add_modify = STA_MODE_MODIFY;
Emmanuel Grumbach93a42662013-07-02 13:35:35 +03001752 if (start) {
1753 cmd.add_immediate_ba_tid = (u8) tid;
1754 cmd.add_immediate_ba_ssn = cpu_to_le16(ssn);
Sara Sharon854c5702016-01-26 13:17:47 +02001755 cmd.rx_ba_window = cpu_to_le16((u16)buf_size);
Emmanuel Grumbach93a42662013-07-02 13:35:35 +03001756 } else {
1757 cmd.remove_immediate_ba_tid = (u8) tid;
1758 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001759 cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID :
1760 STA_MODIFY_REMOVE_BA_TID;
1761
1762 status = ADD_STA_SUCCESS;
Sara Sharon854c5702016-01-26 13:17:47 +02001763 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1764 iwl_mvm_add_sta_cmd_size(mvm),
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001765 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001766 if (ret)
Sara Sharon10b2b202016-03-20 16:23:41 +02001767 goto out_free;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001768
Sara Sharon837c4da2016-01-07 16:50:45 +02001769 switch (status & IWL_ADD_STA_STATUS_MASK) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001770 case ADD_STA_SUCCESS:
Sara Sharon35263a02016-06-21 12:12:10 +03001771 IWL_DEBUG_HT(mvm, "RX BA Session %sed in fw\n",
1772 start ? "start" : "stopp");
Johannes Berg8ca151b2013-01-24 14:25:36 +01001773 break;
1774 case ADD_STA_IMMEDIATE_BA_FAILURE:
1775 IWL_WARN(mvm, "RX BA Session refused by fw\n");
1776 ret = -ENOSPC;
1777 break;
1778 default:
1779 ret = -EIO;
1780 IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n",
1781 start ? "start" : "stopp", status);
1782 break;
1783 }
1784
Sara Sharon10b2b202016-03-20 16:23:41 +02001785 if (ret)
1786 goto out_free;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03001787
Sara Sharon10b2b202016-03-20 16:23:41 +02001788 if (start) {
1789 u8 baid;
1790
1791 mvm->rx_ba_sessions++;
1792
1793 if (!iwl_mvm_has_new_rx_api(mvm))
1794 return 0;
1795
1796 if (WARN_ON(!(status & IWL_ADD_STA_BAID_VALID_MASK))) {
1797 ret = -EINVAL;
1798 goto out_free;
1799 }
1800 baid = (u8)((status & IWL_ADD_STA_BAID_MASK) >>
1801 IWL_ADD_STA_BAID_SHIFT);
1802 baid_data->baid = baid;
1803 baid_data->timeout = timeout;
1804 baid_data->last_rx = jiffies;
1805 init_timer(&baid_data->session_timer);
1806 baid_data->session_timer.function =
1807 iwl_mvm_rx_agg_session_expired;
1808 baid_data->session_timer.data =
1809 (unsigned long)&mvm->baid_map[baid];
1810 baid_data->mvm = mvm;
1811 baid_data->tid = tid;
1812 baid_data->sta_id = mvm_sta->sta_id;
1813
1814 mvm_sta->tid_to_baid[tid] = baid;
1815 if (timeout)
1816 mod_timer(&baid_data->session_timer,
1817 TU_TO_EXP_TIME(timeout * 2));
1818
Sara Sharonb915c102016-03-23 16:32:02 +02001819 iwl_mvm_init_reorder_buffer(mvm, mvm_sta->sta_id,
1820 baid_data, ssn, buf_size);
Sara Sharon10b2b202016-03-20 16:23:41 +02001821 /*
1822 * protect the BA data with RCU to cover a case where our
1823 * internal RX sync mechanism will timeout (not that it's
1824 * supposed to happen) and we will free the session data while
1825 * RX is being processed in parallel
1826 */
Sara Sharon35263a02016-06-21 12:12:10 +03001827 IWL_DEBUG_HT(mvm, "Sta %d(%d) is assigned to BAID %d\n",
1828 mvm_sta->sta_id, tid, baid);
Sara Sharon10b2b202016-03-20 16:23:41 +02001829 WARN_ON(rcu_access_pointer(mvm->baid_map[baid]));
1830 rcu_assign_pointer(mvm->baid_map[baid], baid_data);
1831 } else if (mvm->rx_ba_sessions > 0) {
1832 u8 baid = mvm_sta->tid_to_baid[tid];
1833
1834 /* check that restart flow didn't zero the counter */
1835 mvm->rx_ba_sessions--;
1836 if (!iwl_mvm_has_new_rx_api(mvm))
1837 return 0;
1838
1839 if (WARN_ON(baid == IWL_RX_REORDER_DATA_INVALID_BAID))
1840 return -EINVAL;
1841
1842 baid_data = rcu_access_pointer(mvm->baid_map[baid]);
1843 if (WARN_ON(!baid_data))
1844 return -EINVAL;
1845
1846 /* synchronize all rx queues so we can safely delete */
Sara Sharonb915c102016-03-23 16:32:02 +02001847 iwl_mvm_free_reorder(mvm, baid_data);
Sara Sharon10b2b202016-03-20 16:23:41 +02001848 del_timer_sync(&baid_data->session_timer);
Sara Sharon10b2b202016-03-20 16:23:41 +02001849 RCU_INIT_POINTER(mvm->baid_map[baid], NULL);
1850 kfree_rcu(baid_data, rcu_head);
Sara Sharon35263a02016-06-21 12:12:10 +03001851 IWL_DEBUG_HT(mvm, "BAID %d is free\n", baid);
Sara Sharon10b2b202016-03-20 16:23:41 +02001852 }
1853 return 0;
1854
1855out_free:
1856 kfree(baid_data);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001857 return ret;
1858}
1859
Liad Kaufman9794c642015-08-19 17:34:28 +03001860int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
1861 int tid, u8 queue, bool start)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001862{
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01001863 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001864 struct iwl_mvm_add_sta_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +01001865 int ret;
1866 u32 status;
1867
1868 lockdep_assert_held(&mvm->mutex);
1869
1870 if (start) {
1871 mvm_sta->tfd_queue_msk |= BIT(queue);
1872 mvm_sta->tid_disable_agg &= ~BIT(tid);
1873 } else {
Liad Kaufmancf961e12015-08-13 19:16:08 +03001874 /* In DQA-mode the queue isn't removed on agg termination */
1875 if (!iwl_mvm_is_dqa_supported(mvm))
1876 mvm_sta->tfd_queue_msk &= ~BIT(queue);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001877 mvm_sta->tid_disable_agg |= BIT(tid);
1878 }
1879
1880 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
1881 cmd.sta_id = mvm_sta->sta_id;
1882 cmd.add_modify = STA_MODE_MODIFY;
1883 cmd.modify_mask = STA_MODIFY_QUEUES | STA_MODIFY_TID_DISABLE_TX;
1884 cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk);
1885 cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg);
1886
1887 status = ADD_STA_SUCCESS;
Sara Sharon854c5702016-01-26 13:17:47 +02001888 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1889 iwl_mvm_add_sta_cmd_size(mvm),
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001890 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001891 if (ret)
1892 return ret;
1893
Sara Sharon837c4da2016-01-07 16:50:45 +02001894 switch (status & IWL_ADD_STA_STATUS_MASK) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001895 case ADD_STA_SUCCESS:
1896 break;
1897 default:
1898 ret = -EIO;
1899 IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n",
1900 start ? "start" : "stopp", status);
1901 break;
1902 }
1903
1904 return ret;
1905}
1906
Emmanuel Grumbachb797e3f2014-03-06 14:49:36 +02001907const u8 tid_to_mac80211_ac[] = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001908 IEEE80211_AC_BE,
1909 IEEE80211_AC_BK,
1910 IEEE80211_AC_BK,
1911 IEEE80211_AC_BE,
1912 IEEE80211_AC_VI,
1913 IEEE80211_AC_VI,
1914 IEEE80211_AC_VO,
1915 IEEE80211_AC_VO,
Liad Kaufman9794c642015-08-19 17:34:28 +03001916 IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001917};
1918
Johannes Berg3e56ead2013-02-15 22:23:18 +01001919static const u8 tid_to_ucode_ac[] = {
1920 AC_BE,
1921 AC_BK,
1922 AC_BK,
1923 AC_BE,
1924 AC_VI,
1925 AC_VI,
1926 AC_VO,
1927 AC_VO,
1928};
1929
Johannes Berg8ca151b2013-01-24 14:25:36 +01001930int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1931 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
1932{
Johannes Berg5b577a92013-11-14 18:20:04 +01001933 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001934 struct iwl_mvm_tid_data *tid_data;
1935 int txq_id;
Liad Kaufman4ecafae2015-07-14 13:36:18 +03001936 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001937
1938 if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
1939 return -EINVAL;
1940
1941 if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) {
1942 IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n",
1943 mvmsta->tid_data[tid].state);
1944 return -ENXIO;
1945 }
1946
1947 lockdep_assert_held(&mvm->mutex);
1948
Arik Nemtsovb2492502014-03-13 12:21:50 +02001949 spin_lock_bh(&mvmsta->lock);
1950
1951 /* possible race condition - we entered D0i3 while starting agg */
1952 if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) {
1953 spin_unlock_bh(&mvmsta->lock);
1954 IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n");
1955 return -EIO;
1956 }
1957
Liad Kaufman4ecafae2015-07-14 13:36:18 +03001958 spin_lock_bh(&mvm->queue_info_lock);
1959
Liad Kaufmancf961e12015-08-13 19:16:08 +03001960 /*
1961 * Note the possible cases:
1962 * 1. In DQA mode with an enabled TXQ - TXQ needs to become agg'ed
1963 * 2. Non-DQA mode: the TXQ hasn't yet been enabled, so find a free
1964 * one and mark it as reserved
1965 * 3. In DQA mode, but no traffic yet on this TID: same treatment as in
1966 * non-DQA mode, since the TXQ hasn't yet been allocated
1967 */
1968 txq_id = mvmsta->tid_data[tid].txq_id;
1969 if (!iwl_mvm_is_dqa_supported(mvm) ||
1970 mvm->queue_info[txq_id].status != IWL_MVM_QUEUE_READY) {
Liad Kaufman9794c642015-08-19 17:34:28 +03001971 txq_id = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
1972 mvm->first_agg_queue,
Liad Kaufmancf961e12015-08-13 19:16:08 +03001973 mvm->last_agg_queue);
1974 if (txq_id < 0) {
1975 ret = txq_id;
1976 spin_unlock_bh(&mvm->queue_info_lock);
1977 IWL_ERR(mvm, "Failed to allocate agg queue\n");
1978 goto release_locks;
1979 }
1980
1981 /* TXQ hasn't yet been enabled, so mark it only as reserved */
1982 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_RESERVED;
Liad Kaufman4ecafae2015-07-14 13:36:18 +03001983 }
Liad Kaufman4ecafae2015-07-14 13:36:18 +03001984 spin_unlock_bh(&mvm->queue_info_lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001985
Liad Kaufmancf961e12015-08-13 19:16:08 +03001986 IWL_DEBUG_TX_QUEUES(mvm,
1987 "AGG for tid %d will be on queue #%d\n",
1988 tid, txq_id);
1989
Johannes Berg8ca151b2013-01-24 14:25:36 +01001990 tid_data = &mvmsta->tid_data[tid];
Johannes Berg9a886582013-02-15 19:25:00 +01001991 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001992 tid_data->txq_id = txq_id;
1993 *ssn = tid_data->ssn;
1994
1995 IWL_DEBUG_TX_QUEUES(mvm,
1996 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
1997 mvmsta->sta_id, tid, txq_id, tid_data->ssn,
1998 tid_data->next_reclaimed);
1999
2000 if (tid_data->ssn == tid_data->next_reclaimed) {
2001 tid_data->state = IWL_AGG_STARTING;
2002 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2003 } else {
2004 tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA;
2005 }
2006
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002007 ret = 0;
2008
2009release_locks:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002010 spin_unlock_bh(&mvmsta->lock);
2011
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002012 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002013}
2014
2015int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
Emmanuel Grumbachbb81bb62015-10-26 16:00:29 +02002016 struct ieee80211_sta *sta, u16 tid, u8 buf_size,
2017 bool amsdu)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002018{
Johannes Berg5b577a92013-11-14 18:20:04 +01002019 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002020 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
Emmanuel Grumbach5d42e7b2015-03-19 20:04:51 +02002021 unsigned int wdg_timeout =
2022 iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false);
Emmanuel Grumbacheea76c32016-02-21 16:29:17 +02002023 int queue, ret;
Liad Kaufmancf961e12015-08-13 19:16:08 +03002024 bool alloc_queue = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002025 u16 ssn;
2026
Emmanuel Grumbacheea76c32016-02-21 16:29:17 +02002027 struct iwl_trans_txq_scd_cfg cfg = {
2028 .sta_id = mvmsta->sta_id,
2029 .tid = tid,
2030 .frame_limit = buf_size,
2031 .aggregate = true,
2032 };
2033
Eyal Shapiraefed6642014-09-14 15:58:53 +03002034 BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE)
2035 != IWL_MAX_TID_COUNT);
2036
Johannes Berg8ca151b2013-01-24 14:25:36 +01002037 buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
2038
2039 spin_lock_bh(&mvmsta->lock);
2040 ssn = tid_data->ssn;
2041 queue = tid_data->txq_id;
2042 tid_data->state = IWL_AGG_ON;
Eyal Shapiraefed6642014-09-14 15:58:53 +03002043 mvmsta->agg_tids |= BIT(tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002044 tid_data->ssn = 0xffff;
Emmanuel Grumbachbb81bb62015-10-26 16:00:29 +02002045 tid_data->amsdu_in_ampdu_allowed = amsdu;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002046 spin_unlock_bh(&mvmsta->lock);
2047
Emmanuel Grumbacheea76c32016-02-21 16:29:17 +02002048 cfg.fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002049
Liad Kaufmancf961e12015-08-13 19:16:08 +03002050 /* In DQA mode, the existing queue might need to be reconfigured */
2051 if (iwl_mvm_is_dqa_supported(mvm)) {
2052 spin_lock_bh(&mvm->queue_info_lock);
2053 /* Maybe there is no need to even alloc a queue... */
2054 if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_READY)
2055 alloc_queue = false;
2056 spin_unlock_bh(&mvm->queue_info_lock);
2057
2058 /*
2059 * Only reconfig the SCD for the queue if the window size has
2060 * changed from current (become smaller)
2061 */
2062 if (!alloc_queue && buf_size < mvmsta->max_agg_bufsize) {
2063 /*
2064 * If reconfiguring an existing queue, it first must be
2065 * drained
2066 */
2067 ret = iwl_trans_wait_tx_queue_empty(mvm->trans,
2068 BIT(queue));
2069 if (ret) {
2070 IWL_ERR(mvm,
2071 "Error draining queue before reconfig\n");
2072 return ret;
2073 }
2074
2075 ret = iwl_mvm_reconfig_scd(mvm, queue, cfg.fifo,
2076 mvmsta->sta_id, tid,
2077 buf_size, ssn);
2078 if (ret) {
2079 IWL_ERR(mvm,
2080 "Error reconfiguring TXQ #%d\n", queue);
2081 return ret;
2082 }
2083 }
2084 }
2085
2086 if (alloc_queue)
2087 iwl_mvm_enable_txq(mvm, queue,
2088 vif->hw_queue[tid_to_mac80211_ac[tid]], ssn,
2089 &cfg, wdg_timeout);
Andrei Otcheretianskifa7878e2015-05-05 09:28:16 +03002090
Johannes Berg8ca151b2013-01-24 14:25:36 +01002091 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
2092 if (ret)
2093 return -EIO;
2094
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002095 /* No need to mark as reserved */
2096 spin_lock_bh(&mvm->queue_info_lock);
Liad Kaufmancf961e12015-08-13 19:16:08 +03002097 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002098 spin_unlock_bh(&mvm->queue_info_lock);
2099
Johannes Berg8ca151b2013-01-24 14:25:36 +01002100 /*
2101 * Even though in theory the peer could have different
2102 * aggregation reorder buffer sizes for different sessions,
2103 * our ucode doesn't allow for that and has a global limit
2104 * for each station. Therefore, use the minimum of all the
2105 * aggregation sessions and our default value.
2106 */
2107 mvmsta->max_agg_bufsize =
2108 min(mvmsta->max_agg_bufsize, buf_size);
2109 mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize;
2110
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +03002111 IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n",
2112 sta->addr, tid);
2113
Eyal Shapira9e680942013-11-09 00:16:16 +02002114 return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002115}
2116
2117int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2118 struct ieee80211_sta *sta, u16 tid)
2119{
Johannes Berg5b577a92013-11-14 18:20:04 +01002120 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002121 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2122 u16 txq_id;
2123 int err;
2124
Emmanuel Grumbachf9aa8dd2013-03-04 09:11:08 +02002125
2126 /*
2127 * If mac80211 is cleaning its state, then say that we finished since
2128 * our state has been cleared anyway.
2129 */
2130 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2131 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2132 return 0;
2133 }
2134
Johannes Berg8ca151b2013-01-24 14:25:36 +01002135 spin_lock_bh(&mvmsta->lock);
2136
2137 txq_id = tid_data->txq_id;
2138
2139 IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n",
2140 mvmsta->sta_id, tid, txq_id, tid_data->state);
2141
Eyal Shapiraefed6642014-09-14 15:58:53 +03002142 mvmsta->agg_tids &= ~BIT(tid);
2143
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002144 spin_lock_bh(&mvm->queue_info_lock);
Liad Kaufmancf961e12015-08-13 19:16:08 +03002145 /*
2146 * The TXQ is marked as reserved only if no traffic came through yet
2147 * This means no traffic has been sent on this TID (agg'd or not), so
2148 * we no longer have use for the queue. Since it hasn't even been
2149 * allocated through iwl_mvm_enable_txq, so we can just mark it back as
2150 * free.
2151 */
2152 if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED)
2153 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE;
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002154 spin_unlock_bh(&mvm->queue_info_lock);
2155
Johannes Berg8ca151b2013-01-24 14:25:36 +01002156 switch (tid_data->state) {
2157 case IWL_AGG_ON:
Johannes Berg9a886582013-02-15 19:25:00 +01002158 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002159
2160 IWL_DEBUG_TX_QUEUES(mvm,
2161 "ssn = %d, next_recl = %d\n",
2162 tid_data->ssn, tid_data->next_reclaimed);
2163
2164 /* There are still packets for this RA / TID in the HW */
2165 if (tid_data->ssn != tid_data->next_reclaimed) {
2166 tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA;
2167 err = 0;
2168 break;
2169 }
2170
2171 tid_data->ssn = 0xffff;
Johannes Bergf7f89e72014-08-05 15:24:44 +02002172 tid_data->state = IWL_AGG_OFF;
Johannes Bergf7f89e72014-08-05 15:24:44 +02002173 spin_unlock_bh(&mvmsta->lock);
2174
2175 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2176
2177 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
2178
Liad Kaufmancf961e12015-08-13 19:16:08 +03002179 if (!iwl_mvm_is_dqa_supported(mvm)) {
2180 int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]];
2181
2182 iwl_mvm_disable_txq(mvm, txq_id, mac_queue, tid, 0);
2183 }
Johannes Bergf7f89e72014-08-05 15:24:44 +02002184 return 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002185 case IWL_AGG_STARTING:
2186 case IWL_EMPTYING_HW_QUEUE_ADDBA:
2187 /*
2188 * The agg session has been stopped before it was set up. This
2189 * can happen when the AddBA timer times out for example.
2190 */
2191
2192 /* No barriers since we are under mutex */
2193 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002194
2195 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2196 tid_data->state = IWL_AGG_OFF;
2197 err = 0;
2198 break;
2199 default:
2200 IWL_ERR(mvm,
2201 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
2202 mvmsta->sta_id, tid, tid_data->state);
2203 IWL_ERR(mvm,
2204 "\ttid_data->txq_id = %d\n", tid_data->txq_id);
2205 err = -EINVAL;
2206 }
2207
2208 spin_unlock_bh(&mvmsta->lock);
2209
2210 return err;
2211}
2212
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02002213int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2214 struct ieee80211_sta *sta, u16 tid)
2215{
Johannes Berg5b577a92013-11-14 18:20:04 +01002216 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02002217 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2218 u16 txq_id;
Johannes Bergb6658ff2013-07-24 13:55:51 +02002219 enum iwl_mvm_agg_state old_state;
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02002220
2221 /*
2222 * First set the agg state to OFF to avoid calling
2223 * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
2224 */
2225 spin_lock_bh(&mvmsta->lock);
2226 txq_id = tid_data->txq_id;
2227 IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n",
2228 mvmsta->sta_id, tid, txq_id, tid_data->state);
Johannes Bergb6658ff2013-07-24 13:55:51 +02002229 old_state = tid_data->state;
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02002230 tid_data->state = IWL_AGG_OFF;
Eyal Shapiraefed6642014-09-14 15:58:53 +03002231 mvmsta->agg_tids &= ~BIT(tid);
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02002232 spin_unlock_bh(&mvmsta->lock);
2233
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002234 spin_lock_bh(&mvm->queue_info_lock);
Liad Kaufmancf961e12015-08-13 19:16:08 +03002235 /*
2236 * The TXQ is marked as reserved only if no traffic came through yet
2237 * This means no traffic has been sent on this TID (agg'd or not), so
2238 * we no longer have use for the queue. Since it hasn't even been
2239 * allocated through iwl_mvm_enable_txq, so we can just mark it back as
2240 * free.
2241 */
2242 if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED)
2243 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE;
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002244 spin_unlock_bh(&mvm->queue_info_lock);
2245
Johannes Bergb6658ff2013-07-24 13:55:51 +02002246 if (old_state >= IWL_AGG_ON) {
Emmanuel Grumbachfe92e322015-03-11 09:34:31 +02002247 iwl_mvm_drain_sta(mvm, mvmsta, true);
Luca Coelho5888a402015-10-06 09:54:57 +03002248 if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0))
Johannes Bergb6658ff2013-07-24 13:55:51 +02002249 IWL_ERR(mvm, "Couldn't flush the AGG queue\n");
Emmanuel Grumbachfe92e322015-03-11 09:34:31 +02002250 iwl_trans_wait_tx_queue_empty(mvm->trans,
2251 mvmsta->tfd_queue_msk);
2252 iwl_mvm_drain_sta(mvm, mvmsta, false);
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02002253
Johannes Bergf7f89e72014-08-05 15:24:44 +02002254 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
2255
Liad Kaufmancf961e12015-08-13 19:16:08 +03002256 if (!iwl_mvm_is_dqa_supported(mvm)) {
2257 int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]];
2258
2259 iwl_mvm_disable_txq(mvm, tid_data->txq_id, mac_queue,
2260 tid, 0);
2261 }
Johannes Bergb6658ff2013-07-24 13:55:51 +02002262 }
2263
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02002264 return 0;
2265}
2266
Johannes Berg8ca151b2013-01-24 14:25:36 +01002267static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm)
2268{
Johannes Berg2dc2a152015-06-16 17:09:18 +02002269 int i, max = -1, max_offs = -1;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002270
2271 lockdep_assert_held(&mvm->mutex);
2272
Johannes Berg2dc2a152015-06-16 17:09:18 +02002273 /* Pick the unused key offset with the highest 'deleted'
2274 * counter. Every time a key is deleted, all the counters
2275 * are incremented and the one that was just deleted is
2276 * reset to zero. Thus, the highest counter is the one
2277 * that was deleted longest ago. Pick that one.
2278 */
2279 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
2280 if (test_bit(i, mvm->fw_key_table))
2281 continue;
2282 if (mvm->fw_key_deleted[i] > max) {
2283 max = mvm->fw_key_deleted[i];
2284 max_offs = i;
2285 }
2286 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002287
Johannes Berg2dc2a152015-06-16 17:09:18 +02002288 if (max_offs < 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002289 return STA_KEY_IDX_INVALID;
2290
Johannes Berg2dc2a152015-06-16 17:09:18 +02002291 return max_offs;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002292}
2293
Johannes Berg5f7a1842015-12-11 09:36:10 +01002294static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm,
2295 struct ieee80211_vif *vif,
2296 struct ieee80211_sta *sta)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002297{
Johannes Berg5b530e92014-12-23 16:00:17 +01002298 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002299
Johannes Berg5f7a1842015-12-11 09:36:10 +01002300 if (sta)
2301 return iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002302
2303 /*
2304 * The device expects GTKs for station interfaces to be
2305 * installed as GTKs for the AP station. If we have no
2306 * station ID, then use AP's station ID.
2307 */
2308 if (vif->type == NL80211_IFTYPE_STATION &&
Avri Altman9513c5e2015-10-19 16:29:11 +02002309 mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
2310 u8 sta_id = mvmvif->ap_sta_id;
2311
Avri Altman9513c5e2015-10-19 16:29:11 +02002312 /*
2313 * It is possible that the 'sta' parameter is NULL,
2314 * for example when a GTK is removed - the sta_id will then
2315 * be the AP ID, and no station was passed by mac80211.
2316 */
Sara Sharon13303c02016-04-10 15:51:54 +03002317 return iwl_mvm_sta_from_staid_protected(mvm, sta_id);
Avri Altman9513c5e2015-10-19 16:29:11 +02002318 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002319
Johannes Berg5f7a1842015-12-11 09:36:10 +01002320 return NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002321}
2322
2323static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm,
2324 struct iwl_mvm_sta *mvm_sta,
Johannes Bergba3943b2014-11-12 23:54:48 +01002325 struct ieee80211_key_conf *keyconf, bool mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002326 u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags,
2327 u8 key_offset)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002328{
Max Stepanov5a258aa2013-04-07 09:11:21 +03002329 struct iwl_mvm_add_sta_key_cmd cmd = {};
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03002330 __le16 key_flags;
Johannes Berg79920742014-11-03 15:43:04 +01002331 int ret;
2332 u32 status;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002333 u16 keyidx;
2334 int i;
Johannes Berg2f6319d2014-11-12 23:39:56 +01002335 u8 sta_id = mvm_sta->sta_id;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002336
2337 keyidx = (keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
2338 STA_KEY_FLG_KEYID_MSK;
2339 key_flags = cpu_to_le16(keyidx);
2340 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP);
2341
2342 switch (keyconf->cipher) {
2343 case WLAN_CIPHER_SUITE_TKIP:
2344 key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP);
Max Stepanov5a258aa2013-04-07 09:11:21 +03002345 cmd.tkip_rx_tsc_byte2 = tkip_iv32;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002346 for (i = 0; i < 5; i++)
Max Stepanov5a258aa2013-04-07 09:11:21 +03002347 cmd.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]);
2348 memcpy(cmd.key, keyconf->key, keyconf->keylen);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002349 break;
2350 case WLAN_CIPHER_SUITE_CCMP:
2351 key_flags |= cpu_to_le16(STA_KEY_FLG_CCM);
Max Stepanov5a258aa2013-04-07 09:11:21 +03002352 memcpy(cmd.key, keyconf->key, keyconf->keylen);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002353 break;
Johannes Bergba3943b2014-11-12 23:54:48 +01002354 case WLAN_CIPHER_SUITE_WEP104:
2355 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES);
John W. Linvilleaa0cb082015-01-12 16:18:11 -05002356 /* fall through */
Johannes Bergba3943b2014-11-12 23:54:48 +01002357 case WLAN_CIPHER_SUITE_WEP40:
2358 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP);
2359 memcpy(cmd.key + 3, keyconf->key, keyconf->keylen);
2360 break;
Ayala Beker2a53d162016-04-07 16:21:57 +03002361 case WLAN_CIPHER_SUITE_GCMP_256:
2362 key_flags |= cpu_to_le16(STA_KEY_FLG_KEY_32BYTES);
2363 /* fall through */
2364 case WLAN_CIPHER_SUITE_GCMP:
2365 key_flags |= cpu_to_le16(STA_KEY_FLG_GCMP);
2366 memcpy(cmd.key, keyconf->key, keyconf->keylen);
2367 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002368 default:
Max Stepanove36e5432013-08-27 19:56:13 +03002369 key_flags |= cpu_to_le16(STA_KEY_FLG_EXT);
2370 memcpy(cmd.key, keyconf->key, keyconf->keylen);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002371 }
2372
Johannes Bergba3943b2014-11-12 23:54:48 +01002373 if (mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002374 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
2375
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002376 cmd.key_offset = key_offset;
Max Stepanov5a258aa2013-04-07 09:11:21 +03002377 cmd.key_flags = key_flags;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002378 cmd.sta_id = sta_id;
2379
2380 status = ADD_STA_SUCCESS;
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002381 if (cmd_flags & CMD_ASYNC)
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03002382 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC,
2383 sizeof(cmd), &cmd);
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002384 else
2385 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd),
2386 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002387
2388 switch (status) {
2389 case ADD_STA_SUCCESS:
2390 IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n");
2391 break;
2392 default:
2393 ret = -EIO;
2394 IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n");
2395 break;
2396 }
2397
2398 return ret;
2399}
2400
2401static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm,
2402 struct ieee80211_key_conf *keyconf,
2403 u8 sta_id, bool remove_key)
2404{
2405 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {};
2406
2407 /* verify the key details match the required command's expectations */
2408 if (WARN_ON((keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC) ||
2409 (keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) ||
2410 (keyconf->keyidx != 4 && keyconf->keyidx != 5)))
2411 return -EINVAL;
2412
2413 igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx);
2414 igtk_cmd.sta_id = cpu_to_le32(sta_id);
2415
2416 if (remove_key) {
2417 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID);
2418 } else {
2419 struct ieee80211_key_seq seq;
2420 const u8 *pn;
2421
2422 memcpy(igtk_cmd.IGTK, keyconf->key, keyconf->keylen);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002423 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
2424 pn = seq.aes_cmac.pn;
2425 igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) |
2426 ((u64) pn[4] << 8) |
2427 ((u64) pn[3] << 16) |
2428 ((u64) pn[2] << 24) |
2429 ((u64) pn[1] << 32) |
2430 ((u64) pn[0] << 40));
2431 }
2432
2433 IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n",
2434 remove_key ? "removing" : "installing",
2435 igtk_cmd.sta_id);
2436
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002437 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002438 sizeof(igtk_cmd), &igtk_cmd);
2439}
2440
2441
2442static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm,
2443 struct ieee80211_vif *vif,
2444 struct ieee80211_sta *sta)
2445{
Johannes Berg5b530e92014-12-23 16:00:17 +01002446 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002447
2448 if (sta)
2449 return sta->addr;
2450
2451 if (vif->type == NL80211_IFTYPE_STATION &&
2452 mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
2453 u8 sta_id = mvmvif->ap_sta_id;
2454 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
2455 lockdep_is_held(&mvm->mutex));
2456 return sta->addr;
2457 }
2458
2459
2460 return NULL;
2461}
2462
Johannes Berg2f6319d2014-11-12 23:39:56 +01002463static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
2464 struct ieee80211_vif *vif,
2465 struct ieee80211_sta *sta,
Johannes Bergba3943b2014-11-12 23:54:48 +01002466 struct ieee80211_key_conf *keyconf,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002467 u8 key_offset,
Johannes Bergba3943b2014-11-12 23:54:48 +01002468 bool mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002469{
Johannes Berg2f6319d2014-11-12 23:39:56 +01002470 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002471 int ret;
Johannes Berg2f6319d2014-11-12 23:39:56 +01002472 const u8 *addr;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002473 struct ieee80211_key_seq seq;
2474 u16 p1k[5];
2475
Johannes Berg8ca151b2013-01-24 14:25:36 +01002476 switch (keyconf->cipher) {
2477 case WLAN_CIPHER_SUITE_TKIP:
2478 addr = iwl_mvm_get_mac_addr(mvm, vif, sta);
2479 /* get phase 1 key from mac80211 */
2480 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
2481 ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k);
Johannes Bergba3943b2014-11-12 23:54:48 +01002482 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002483 seq.tkip.iv32, p1k, 0, key_offset);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002484 break;
2485 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergba3943b2014-11-12 23:54:48 +01002486 case WLAN_CIPHER_SUITE_WEP40:
2487 case WLAN_CIPHER_SUITE_WEP104:
Ayala Beker2a53d162016-04-07 16:21:57 +03002488 case WLAN_CIPHER_SUITE_GCMP:
2489 case WLAN_CIPHER_SUITE_GCMP_256:
Johannes Bergba3943b2014-11-12 23:54:48 +01002490 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002491 0, NULL, 0, key_offset);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002492 break;
2493 default:
Johannes Bergba3943b2014-11-12 23:54:48 +01002494 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002495 0, NULL, 0, key_offset);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002496 }
2497
Johannes Berg8ca151b2013-01-24 14:25:36 +01002498 return ret;
2499}
2500
Johannes Berg2f6319d2014-11-12 23:39:56 +01002501static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id,
Johannes Bergba3943b2014-11-12 23:54:48 +01002502 struct ieee80211_key_conf *keyconf,
2503 bool mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002504{
Max Stepanov5a258aa2013-04-07 09:11:21 +03002505 struct iwl_mvm_add_sta_key_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +01002506 __le16 key_flags;
Johannes Berg79920742014-11-03 15:43:04 +01002507 int ret;
2508 u32 status;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002509
Emmanuel Grumbach8115efb2013-02-05 10:08:35 +02002510 key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
2511 STA_KEY_FLG_KEYID_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002512 key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP);
2513 key_flags |= cpu_to_le16(STA_KEY_NOT_VALID);
2514
Johannes Bergba3943b2014-11-12 23:54:48 +01002515 if (mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002516 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
2517
Max Stepanov5a258aa2013-04-07 09:11:21 +03002518 cmd.key_flags = key_flags;
2519 cmd.key_offset = keyconf->hw_key_idx;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002520 cmd.sta_id = sta_id;
2521
Johannes Berg8ca151b2013-01-24 14:25:36 +01002522 status = ADD_STA_SUCCESS;
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03002523 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd),
2524 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002525
2526 switch (status) {
2527 case ADD_STA_SUCCESS:
2528 IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n");
2529 break;
2530 default:
2531 ret = -EIO;
2532 IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n");
2533 break;
2534 }
2535
2536 return ret;
2537}
2538
Johannes Berg2f6319d2014-11-12 23:39:56 +01002539int iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
2540 struct ieee80211_vif *vif,
2541 struct ieee80211_sta *sta,
2542 struct ieee80211_key_conf *keyconf,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002543 u8 key_offset)
Johannes Berg2f6319d2014-11-12 23:39:56 +01002544{
Johannes Bergba3943b2014-11-12 23:54:48 +01002545 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
Johannes Berg5f7a1842015-12-11 09:36:10 +01002546 struct iwl_mvm_sta *mvm_sta;
Johannes Berg2f6319d2014-11-12 23:39:56 +01002547 u8 sta_id;
2548 int ret;
Matti Gottlieb11828db2015-06-01 15:15:11 +03002549 static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0};
Johannes Berg2f6319d2014-11-12 23:39:56 +01002550
2551 lockdep_assert_held(&mvm->mutex);
2552
2553 /* Get the station id from the mvm local station table */
Johannes Berg5f7a1842015-12-11 09:36:10 +01002554 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
2555 if (!mvm_sta) {
2556 IWL_ERR(mvm, "Failed to find station\n");
Johannes Berg2f6319d2014-11-12 23:39:56 +01002557 return -EINVAL;
2558 }
Johannes Berg5f7a1842015-12-11 09:36:10 +01002559 sta_id = mvm_sta->sta_id;
Johannes Berg2f6319d2014-11-12 23:39:56 +01002560
2561 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
2562 ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false);
2563 goto end;
2564 }
2565
2566 /*
2567 * It is possible that the 'sta' parameter is NULL, and thus
2568 * there is a need to retrieve the sta from the local station table.
2569 */
2570 if (!sta) {
2571 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
2572 lockdep_is_held(&mvm->mutex));
2573 if (IS_ERR_OR_NULL(sta)) {
2574 IWL_ERR(mvm, "Invalid station id\n");
2575 return -EINVAL;
2576 }
2577 }
2578
2579 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif))
2580 return -EINVAL;
2581
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002582 /* If the key_offset is not pre-assigned, we need to find a
2583 * new offset to use. In normal cases, the offset is not
2584 * pre-assigned, but during HW_RESTART we want to reuse the
2585 * same indices, so we pass them when this function is called.
2586 *
2587 * In D3 entry, we need to hardcoded the indices (because the
2588 * firmware hardcodes the PTK offset to 0). In this case, we
2589 * need to make sure we don't overwrite the hw_key_idx in the
2590 * keyconf structure, because otherwise we cannot configure
2591 * the original ones back when resuming.
2592 */
2593 if (key_offset == STA_KEY_IDX_INVALID) {
2594 key_offset = iwl_mvm_set_fw_key_idx(mvm);
2595 if (key_offset == STA_KEY_IDX_INVALID)
Johannes Berg2f6319d2014-11-12 23:39:56 +01002596 return -ENOSPC;
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002597 keyconf->hw_key_idx = key_offset;
Johannes Berg2f6319d2014-11-12 23:39:56 +01002598 }
2599
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002600 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, key_offset, mcast);
Luca Coelho9c3deeb2015-11-11 01:06:17 +02002601 if (ret)
Johannes Bergba3943b2014-11-12 23:54:48 +01002602 goto end;
Johannes Bergba3943b2014-11-12 23:54:48 +01002603
2604 /*
2605 * For WEP, the same key is used for multicast and unicast. Upload it
2606 * again, using the same key offset, and now pointing the other one
2607 * to the same key slot (offset).
2608 * If this fails, remove the original as well.
2609 */
2610 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2611 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) {
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002612 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf,
2613 key_offset, !mcast);
Johannes Bergba3943b2014-11-12 23:54:48 +01002614 if (ret) {
Johannes Bergba3943b2014-11-12 23:54:48 +01002615 __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
Luca Coelho9c3deeb2015-11-11 01:06:17 +02002616 goto end;
Johannes Bergba3943b2014-11-12 23:54:48 +01002617 }
2618 }
Johannes Berg2f6319d2014-11-12 23:39:56 +01002619
Luca Coelho9c3deeb2015-11-11 01:06:17 +02002620 __set_bit(key_offset, mvm->fw_key_table);
2621
Johannes Berg2f6319d2014-11-12 23:39:56 +01002622end:
2623 IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
2624 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
Matti Gottlieb11828db2015-06-01 15:15:11 +03002625 sta ? sta->addr : zero_addr, ret);
Johannes Berg2f6319d2014-11-12 23:39:56 +01002626 return ret;
2627}
2628
2629int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm,
2630 struct ieee80211_vif *vif,
2631 struct ieee80211_sta *sta,
2632 struct ieee80211_key_conf *keyconf)
2633{
Johannes Bergba3943b2014-11-12 23:54:48 +01002634 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
Johannes Berg5f7a1842015-12-11 09:36:10 +01002635 struct iwl_mvm_sta *mvm_sta;
2636 u8 sta_id = IWL_MVM_STATION_COUNT;
Johannes Berg2dc2a152015-06-16 17:09:18 +02002637 int ret, i;
Johannes Berg2f6319d2014-11-12 23:39:56 +01002638
2639 lockdep_assert_held(&mvm->mutex);
2640
Johannes Berg5f7a1842015-12-11 09:36:10 +01002641 /* Get the station from the mvm local station table */
2642 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
Johannes Berg2f6319d2014-11-12 23:39:56 +01002643
2644 IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n",
2645 keyconf->keyidx, sta_id);
2646
2647 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
2648 return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true);
2649
2650 if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) {
2651 IWL_ERR(mvm, "offset %d not used in fw key table.\n",
2652 keyconf->hw_key_idx);
2653 return -ENOENT;
2654 }
2655
Johannes Berg2dc2a152015-06-16 17:09:18 +02002656 /* track which key was deleted last */
2657 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
2658 if (mvm->fw_key_deleted[i] < U8_MAX)
2659 mvm->fw_key_deleted[i]++;
2660 }
2661 mvm->fw_key_deleted[keyconf->hw_key_idx] = 0;
2662
Johannes Berg5f7a1842015-12-11 09:36:10 +01002663 if (!mvm_sta) {
Johannes Berg2f6319d2014-11-12 23:39:56 +01002664 IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n");
2665 return 0;
2666 }
2667
Johannes Berg5f7a1842015-12-11 09:36:10 +01002668 sta_id = mvm_sta->sta_id;
2669
Johannes Bergba3943b2014-11-12 23:54:48 +01002670 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
2671 if (ret)
2672 return ret;
2673
2674 /* delete WEP key twice to get rid of (now useless) offset */
2675 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
2676 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104)
2677 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast);
2678
2679 return ret;
Johannes Berg2f6319d2014-11-12 23:39:56 +01002680}
2681
Johannes Berg8ca151b2013-01-24 14:25:36 +01002682void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm,
2683 struct ieee80211_vif *vif,
2684 struct ieee80211_key_conf *keyconf,
2685 struct ieee80211_sta *sta, u32 iv32,
2686 u16 *phase1key)
2687{
Beni Levc3eb5362013-02-06 17:22:18 +02002688 struct iwl_mvm_sta *mvm_sta;
Johannes Bergba3943b2014-11-12 23:54:48 +01002689 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002690
Beni Levc3eb5362013-02-06 17:22:18 +02002691 rcu_read_lock();
2692
Johannes Berg5f7a1842015-12-11 09:36:10 +01002693 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
2694 if (WARN_ON_ONCE(!mvm_sta))
Emmanuel Grumbach12f17212015-12-20 14:48:08 +02002695 goto unlock;
Johannes Bergba3943b2014-11-12 23:54:48 +01002696 iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002697 iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx);
Emmanuel Grumbach12f17212015-12-20 14:48:08 +02002698
2699 unlock:
Beni Levc3eb5362013-02-06 17:22:18 +02002700 rcu_read_unlock();
Johannes Berg8ca151b2013-01-24 14:25:36 +01002701}
2702
Johannes Berg9cc40712013-02-15 22:47:48 +01002703void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm,
2704 struct ieee80211_sta *sta)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002705{
Johannes Berg5b577a92013-11-14 18:20:04 +01002706 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03002707 struct iwl_mvm_add_sta_cmd cmd = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002708 .add_modify = STA_MODE_MODIFY,
Johannes Berg9cc40712013-02-15 22:47:48 +01002709 .sta_id = mvmsta->sta_id,
Emmanuel Grumbach5af01772013-06-09 12:59:24 +03002710 .station_flags_msk = cpu_to_le32(STA_FLG_PS),
Johannes Berg9cc40712013-02-15 22:47:48 +01002711 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
Johannes Berg8ca151b2013-01-24 14:25:36 +01002712 };
2713 int ret;
2714
Sara Sharon854c5702016-01-26 13:17:47 +02002715 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
2716 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002717 if (ret)
2718 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
2719}
2720
Johannes Berg9cc40712013-02-15 22:47:48 +01002721void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm,
2722 struct ieee80211_sta *sta,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002723 enum ieee80211_frame_release_type reason,
Johannes Berg3e56ead2013-02-15 22:23:18 +01002724 u16 cnt, u16 tids, bool more_data,
2725 bool agg)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002726{
Johannes Berg5b577a92013-11-14 18:20:04 +01002727 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03002728 struct iwl_mvm_add_sta_cmd cmd = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002729 .add_modify = STA_MODE_MODIFY,
Johannes Berg9cc40712013-02-15 22:47:48 +01002730 .sta_id = mvmsta->sta_id,
Johannes Berg8ca151b2013-01-24 14:25:36 +01002731 .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT,
2732 .sleep_tx_count = cpu_to_le16(cnt),
Johannes Berg9cc40712013-02-15 22:47:48 +01002733 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
Johannes Berg8ca151b2013-01-24 14:25:36 +01002734 };
Johannes Berg3e56ead2013-02-15 22:23:18 +01002735 int tid, ret;
2736 unsigned long _tids = tids;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002737
Johannes Berg3e56ead2013-02-15 22:23:18 +01002738 /* convert TIDs to ACs - we don't support TSPEC so that's OK
2739 * Note that this field is reserved and unused by firmware not
2740 * supporting GO uAPSD, so it's safe to always do this.
2741 */
2742 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT)
2743 cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]);
2744
2745 /* If we're releasing frames from aggregation queues then check if the
2746 * all queues combined that we're releasing frames from have
2747 * - more frames than the service period, in which case more_data
2748 * needs to be set
2749 * - fewer than 'cnt' frames, in which case we need to adjust the
2750 * firmware command (but do that unconditionally)
2751 */
2752 if (agg) {
2753 int remaining = cnt;
Emmanuel Grumbach36be0eb2015-11-05 10:32:31 +02002754 int sleep_tx_count;
Johannes Berg3e56ead2013-02-15 22:23:18 +01002755
2756 spin_lock_bh(&mvmsta->lock);
2757 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) {
2758 struct iwl_mvm_tid_data *tid_data;
2759 u16 n_queued;
2760
2761 tid_data = &mvmsta->tid_data[tid];
2762 if (WARN(tid_data->state != IWL_AGG_ON &&
2763 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA,
2764 "TID %d state is %d\n",
2765 tid, tid_data->state)) {
2766 spin_unlock_bh(&mvmsta->lock);
2767 ieee80211_sta_eosp(sta);
2768 return;
2769 }
2770
2771 n_queued = iwl_mvm_tid_queued(tid_data);
2772 if (n_queued > remaining) {
2773 more_data = true;
2774 remaining = 0;
2775 break;
2776 }
2777 remaining -= n_queued;
2778 }
Emmanuel Grumbach36be0eb2015-11-05 10:32:31 +02002779 sleep_tx_count = cnt - remaining;
2780 if (reason == IEEE80211_FRAME_RELEASE_UAPSD)
2781 mvmsta->sleep_tx_count = sleep_tx_count;
Johannes Berg3e56ead2013-02-15 22:23:18 +01002782 spin_unlock_bh(&mvmsta->lock);
2783
Emmanuel Grumbach36be0eb2015-11-05 10:32:31 +02002784 cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count);
Johannes Berg3e56ead2013-02-15 22:23:18 +01002785 if (WARN_ON(cnt - remaining == 0)) {
2786 ieee80211_sta_eosp(sta);
2787 return;
2788 }
2789 }
2790
2791 /* Note: this is ignored by firmware not supporting GO uAPSD */
2792 if (more_data)
2793 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA);
2794
2795 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) {
2796 mvmsta->next_status_eosp = true;
2797 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL);
2798 } else {
2799 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD);
2800 }
2801
Emmanuel Grumbach156f92f2015-11-24 14:55:18 +02002802 /* block the Tx queues until the FW updated the sleep Tx count */
2803 iwl_trans_block_txq_ptrs(mvm->trans, true);
2804
2805 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA,
2806 CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK,
Sara Sharon854c5702016-01-26 13:17:47 +02002807 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002808 if (ret)
2809 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
2810}
Johannes Berg3e56ead2013-02-15 22:23:18 +01002811
Johannes Berg04168412015-06-23 21:22:09 +02002812void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm,
2813 struct iwl_rx_cmd_buffer *rxb)
Johannes Berg3e56ead2013-02-15 22:23:18 +01002814{
2815 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2816 struct iwl_mvm_eosp_notification *notif = (void *)pkt->data;
2817 struct ieee80211_sta *sta;
2818 u32 sta_id = le32_to_cpu(notif->sta_id);
2819
2820 if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT))
Johannes Berg04168412015-06-23 21:22:09 +02002821 return;
Johannes Berg3e56ead2013-02-15 22:23:18 +01002822
2823 rcu_read_lock();
2824 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
2825 if (!IS_ERR_OR_NULL(sta))
2826 ieee80211_sta_eosp(sta);
2827 rcu_read_unlock();
Johannes Berg3e56ead2013-02-15 22:23:18 +01002828}
Andrei Otcheretianski09b0ce12014-05-25 17:07:38 +03002829
2830void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm,
2831 struct iwl_mvm_sta *mvmsta, bool disable)
2832{
2833 struct iwl_mvm_add_sta_cmd cmd = {
2834 .add_modify = STA_MODE_MODIFY,
2835 .sta_id = mvmsta->sta_id,
2836 .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0,
2837 .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX),
2838 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
2839 };
2840 int ret;
2841
Sara Sharon854c5702016-01-26 13:17:47 +02002842 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
2843 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
Andrei Otcheretianski09b0ce12014-05-25 17:07:38 +03002844 if (ret)
2845 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
2846}
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03002847
2848void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm,
2849 struct ieee80211_sta *sta,
2850 bool disable)
2851{
2852 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2853
2854 spin_lock_bh(&mvm_sta->lock);
2855
2856 if (mvm_sta->disable_tx == disable) {
2857 spin_unlock_bh(&mvm_sta->lock);
2858 return;
2859 }
2860
2861 mvm_sta->disable_tx = disable;
2862
2863 /*
Sara Sharon0d365ae2015-03-31 12:24:05 +03002864 * Tell mac80211 to start/stop queuing tx for this station,
2865 * but don't stop queuing if there are still pending frames
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03002866 * for this station.
2867 */
2868 if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id]))
2869 ieee80211_sta_block_awake(mvm->hw, sta, disable);
2870
2871 iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable);
2872
2873 spin_unlock_bh(&mvm_sta->lock);
2874}
2875
2876void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm,
2877 struct iwl_mvm_vif *mvmvif,
2878 bool disable)
2879{
2880 struct ieee80211_sta *sta;
2881 struct iwl_mvm_sta *mvm_sta;
2882 int i;
2883
2884 lockdep_assert_held(&mvm->mutex);
2885
2886 /* Block/unblock all the stations of the given mvmvif */
2887 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
2888 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
2889 lockdep_is_held(&mvm->mutex));
2890 if (IS_ERR_OR_NULL(sta))
2891 continue;
2892
2893 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2894 if (mvm_sta->mac_id_n_color !=
2895 FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color))
2896 continue;
2897
2898 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable);
2899 }
2900}
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02002901
2902void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2903{
2904 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2905 struct iwl_mvm_sta *mvmsta;
2906
2907 rcu_read_lock();
2908
2909 mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id);
2910
2911 if (!WARN_ON(!mvmsta))
2912 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true);
2913
2914 rcu_read_unlock();
2915}