blob: 039efcd2735d91f9cfd5fcf49fc979c4932db13d [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 Sharon26d6c162017-01-03 12:00:19 +020010 * Copyright(c) 2016 - 2017 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 Sharon26d6c162017-01-03 12:00:19 +020037 * Copyright(c) 2016 - 2017 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{
Sara Sharonced19f22017-02-06 19:09:32 +020080 if (iwl_mvm_has_new_rx_api(mvm) ||
81 fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
82 return sizeof(struct iwl_mvm_add_sta_cmd);
83 else
84 return sizeof(struct iwl_mvm_add_sta_cmd_v7);
Sara Sharon854c5702016-01-26 13:17:47 +020085}
86
Eliad Pellerb92e6612014-01-23 17:58:23 +020087static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm,
88 enum nl80211_iftype iftype)
Johannes Berg8ca151b2013-01-24 14:25:36 +010089{
90 int sta_id;
Eliad Pellerb92e6612014-01-23 17:58:23 +020091 u32 reserved_ids = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +010092
Eliad Pellerb92e6612014-01-23 17:58:23 +020093 BUILD_BUG_ON(IWL_MVM_STATION_COUNT > 32);
Johannes Berg8ca151b2013-01-24 14:25:36 +010094 WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status));
95
96 lockdep_assert_held(&mvm->mutex);
97
Eliad Pellerb92e6612014-01-23 17:58:23 +020098 /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */
99 if (iftype != NL80211_IFTYPE_STATION)
100 reserved_ids = BIT(0);
101
Johannes Berg8ca151b2013-01-24 14:25:36 +0100102 /* Don't take rcu_read_lock() since we are protected by mvm->mutex */
Sara Sharon0ae98812017-01-04 14:53:58 +0200103 for (sta_id = 0; sta_id < ARRAY_SIZE(mvm->fw_id_to_mac_id); sta_id++) {
Eliad Pellerb92e6612014-01-23 17:58:23 +0200104 if (BIT(sta_id) & reserved_ids)
105 continue;
106
Johannes Berg8ca151b2013-01-24 14:25:36 +0100107 if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
108 lockdep_is_held(&mvm->mutex)))
109 return sta_id;
Eliad Pellerb92e6612014-01-23 17:58:23 +0200110 }
Sara Sharon0ae98812017-01-04 14:53:58 +0200111 return IWL_MVM_INVALID_STA;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100112}
113
Johannes Berg7a453972013-02-12 13:10:44 +0100114/* send station add/update command to firmware */
115int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
Liad Kaufman24afba72015-07-28 18:56:08 +0300116 bool update, unsigned int flags)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100117{
Johannes Berg9d8ce6a2014-12-23 16:02:40 +0100118 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbach4b8265a2014-07-13 08:58:04 +0300119 struct iwl_mvm_add_sta_cmd add_sta_cmd = {
120 .sta_id = mvm_sta->sta_id,
121 .mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color),
122 .add_modify = update ? 1 : 0,
123 .station_flags_msk = cpu_to_le32(STA_FLG_FAT_EN_MSK |
Naftali Goldstein8addabf2017-07-27 04:53:55 +0300124 STA_FLG_MIMO_EN_MSK |
125 STA_FLG_RTS_MIMO_PROT),
Liad Kaufmancf0cda12015-09-24 10:44:12 +0200126 .tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg),
Emmanuel Grumbach4b8265a2014-07-13 08:58:04 +0300127 };
Johannes Berg8ca151b2013-01-24 14:25:36 +0100128 int ret;
129 u32 status;
130 u32 agg_size = 0, mpdu_dens = 0;
131
Sara Sharonced19f22017-02-06 19:09:32 +0200132 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
133 add_sta_cmd.station_type = mvm_sta->sta_type;
134
Liad Kaufman24afba72015-07-28 18:56:08 +0300135 if (!update || (flags & STA_MODIFY_QUEUES)) {
Johannes Berg7a453972013-02-12 13:10:44 +0100136 memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN);
Liad Kaufman24afba72015-07-28 18:56:08 +0300137
Sara Sharonbb497012016-09-29 14:52:40 +0300138 if (!iwl_mvm_has_new_tx_api(mvm)) {
139 add_sta_cmd.tfd_queue_msk =
140 cpu_to_le32(mvm_sta->tfd_queue_msk);
141
142 if (flags & STA_MODIFY_QUEUES)
143 add_sta_cmd.modify_mask |= STA_MODIFY_QUEUES;
144 } else {
145 WARN_ON(flags & STA_MODIFY_QUEUES);
146 }
Johannes Berg7a453972013-02-12 13:10:44 +0100147 }
Johannes Berg5bc5aaa2013-02-12 14:35:36 +0100148
149 switch (sta->bandwidth) {
150 case IEEE80211_STA_RX_BW_160:
151 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_160MHZ);
152 /* fall through */
153 case IEEE80211_STA_RX_BW_80:
154 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_80MHZ);
155 /* fall through */
156 case IEEE80211_STA_RX_BW_40:
157 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_40MHZ);
158 /* fall through */
159 case IEEE80211_STA_RX_BW_20:
160 if (sta->ht_cap.ht_supported)
161 add_sta_cmd.station_flags |=
162 cpu_to_le32(STA_FLG_FAT_EN_20MHZ);
163 break;
164 }
165
166 switch (sta->rx_nss) {
167 case 1:
168 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO);
169 break;
170 case 2:
171 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2);
172 break;
173 case 3 ... 8:
174 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3);
175 break;
176 }
177
178 switch (sta->smps_mode) {
179 case IEEE80211_SMPS_AUTOMATIC:
180 case IEEE80211_SMPS_NUM_MODES:
181 WARN_ON(1);
182 break;
183 case IEEE80211_SMPS_STATIC:
184 /* override NSS */
185 add_sta_cmd.station_flags &= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK);
186 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO);
187 break;
188 case IEEE80211_SMPS_DYNAMIC:
189 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_RTS_MIMO_PROT);
190 break;
191 case IEEE80211_SMPS_OFF:
192 /* nothing */
193 break;
194 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100195
196 if (sta->ht_cap.ht_supported) {
197 add_sta_cmd.station_flags_msk |=
198 cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK |
199 STA_FLG_AGG_MPDU_DENS_MSK);
200
201 mpdu_dens = sta->ht_cap.ampdu_density;
202 }
203
204 if (sta->vht_cap.vht_supported) {
205 agg_size = sta->vht_cap.cap &
206 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
207 agg_size >>=
208 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
209 } else if (sta->ht_cap.ht_supported) {
210 agg_size = sta->ht_cap.ampdu_factor;
211 }
212
213 add_sta_cmd.station_flags |=
214 cpu_to_le32(agg_size << STA_FLG_MAX_AGG_SIZE_SHIFT);
215 add_sta_cmd.station_flags |=
216 cpu_to_le32(mpdu_dens << STA_FLG_AGG_MPDU_DENS_SHIFT);
Johannes Berg6ea29ce2016-12-01 16:25:30 +0100217 if (mvm_sta->associated)
218 add_sta_cmd.assoc_id = cpu_to_le16(sta->aid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100219
Johannes Berg65e25482016-04-13 14:24:22 +0200220 if (sta->wme) {
221 add_sta_cmd.modify_mask |= STA_MODIFY_UAPSD_ACS;
222
223 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
Emmanuel Grumbachc80eb572017-01-12 15:43:57 +0200224 add_sta_cmd.uapsd_acs |= BIT(AC_BK);
Johannes Berg65e25482016-04-13 14:24:22 +0200225 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
Emmanuel Grumbachc80eb572017-01-12 15:43:57 +0200226 add_sta_cmd.uapsd_acs |= BIT(AC_BE);
Johannes Berg65e25482016-04-13 14:24:22 +0200227 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
Emmanuel Grumbachc80eb572017-01-12 15:43:57 +0200228 add_sta_cmd.uapsd_acs |= BIT(AC_VI);
Johannes Berg65e25482016-04-13 14:24:22 +0200229 if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
Emmanuel Grumbachc80eb572017-01-12 15:43:57 +0200230 add_sta_cmd.uapsd_acs |= BIT(AC_VO);
231 add_sta_cmd.uapsd_acs |= add_sta_cmd.uapsd_acs << 4;
Emmanuel Grumbache71ca5e2017-02-08 14:53:32 +0200232 add_sta_cmd.sp_length = sta->max_sp ? sta->max_sp * 2 : 128;
Johannes Berg65e25482016-04-13 14:24:22 +0200233 }
234
Johannes Berg8ca151b2013-01-24 14:25:36 +0100235 status = ADD_STA_SUCCESS;
Sara Sharon854c5702016-01-26 13:17:47 +0200236 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
237 iwl_mvm_add_sta_cmd_size(mvm),
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300238 &add_sta_cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100239 if (ret)
240 return ret;
241
Sara Sharon837c4da2016-01-07 16:50:45 +0200242 switch (status & IWL_ADD_STA_STATUS_MASK) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100243 case ADD_STA_SUCCESS:
244 IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n");
245 break;
246 default:
247 ret = -EIO;
248 IWL_ERR(mvm, "ADD_STA failed\n");
249 break;
250 }
251
252 return ret;
253}
254
Sara Sharon10b2b202016-03-20 16:23:41 +0200255static void iwl_mvm_rx_agg_session_expired(unsigned long data)
256{
257 struct iwl_mvm_baid_data __rcu **rcu_ptr = (void *)data;
258 struct iwl_mvm_baid_data *ba_data;
259 struct ieee80211_sta *sta;
260 struct iwl_mvm_sta *mvm_sta;
261 unsigned long timeout;
262
263 rcu_read_lock();
264
265 ba_data = rcu_dereference(*rcu_ptr);
266
267 if (WARN_ON(!ba_data))
268 goto unlock;
269
270 if (!ba_data->timeout)
271 goto unlock;
272
273 timeout = ba_data->last_rx + TU_TO_JIFFIES(ba_data->timeout * 2);
274 if (time_is_after_jiffies(timeout)) {
275 mod_timer(&ba_data->session_timer, timeout);
276 goto unlock;
277 }
278
279 /* Timer expired */
280 sta = rcu_dereference(ba_data->mvm->fw_id_to_mac_id[ba_data->sta_id]);
Emmanuel Grumbach61dd8a82017-06-12 15:10:09 +0300281
282 /*
283 * sta should be valid unless the following happens:
284 * The firmware asserts which triggers a reconfig flow, but
285 * the reconfig fails before we set the pointer to sta into
286 * the fw_id_to_mac_id pointer table. Mac80211 can't stop
287 * A-MDPU and hence the timer continues to run. Then, the
288 * timer expires and sta is NULL.
289 */
290 if (!sta)
291 goto unlock;
292
Sara Sharon10b2b202016-03-20 16:23:41 +0200293 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Naftali Goldstein20fc6902017-07-11 10:07:32 +0300294 ieee80211_rx_ba_timer_expired(mvm_sta->vif,
295 sta->addr, ba_data->tid);
Sara Sharon10b2b202016-03-20 16:23:41 +0200296unlock:
297 rcu_read_unlock();
298}
299
Liad Kaufman9794c642015-08-19 17:34:28 +0300300/* Disable aggregations for a bitmap of TIDs for a given station */
301static int iwl_mvm_invalidate_sta_queue(struct iwl_mvm *mvm, int queue,
302 unsigned long disable_agg_tids,
303 bool remove_queue)
304{
305 struct iwl_mvm_add_sta_cmd cmd = {};
306 struct ieee80211_sta *sta;
307 struct iwl_mvm_sta *mvmsta;
308 u32 status;
309 u8 sta_id;
310 int ret;
311
Sara Sharonbb497012016-09-29 14:52:40 +0300312 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
313 return -EINVAL;
314
Liad Kaufman9794c642015-08-19 17:34:28 +0300315 spin_lock_bh(&mvm->queue_info_lock);
316 sta_id = mvm->queue_info[queue].ra_sta_id;
317 spin_unlock_bh(&mvm->queue_info_lock);
318
319 rcu_read_lock();
320
321 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
322
323 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
324 rcu_read_unlock();
325 return -EINVAL;
326 }
327
328 mvmsta = iwl_mvm_sta_from_mac80211(sta);
329
330 mvmsta->tid_disable_agg |= disable_agg_tids;
331
332 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
333 cmd.sta_id = mvmsta->sta_id;
334 cmd.add_modify = STA_MODE_MODIFY;
335 cmd.modify_mask = STA_MODIFY_QUEUES;
336 if (disable_agg_tids)
337 cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX;
338 if (remove_queue)
339 cmd.modify_mask |= STA_MODIFY_QUEUE_REMOVAL;
340 cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk);
341 cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg);
342
343 rcu_read_unlock();
344
345 /* Notify FW of queue removal from the STA queues */
346 status = ADD_STA_SUCCESS;
347 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
348 iwl_mvm_add_sta_cmd_size(mvm),
349 &cmd, &status);
350
351 return ret;
352}
353
Liad Kaufman42db09c2016-05-02 14:01:14 +0300354static int iwl_mvm_get_queue_agg_tids(struct iwl_mvm *mvm, int queue)
355{
356 struct ieee80211_sta *sta;
357 struct iwl_mvm_sta *mvmsta;
358 unsigned long tid_bitmap;
359 unsigned long agg_tids = 0;
Sharon Dvir806911d2017-05-21 12:09:49 +0300360 u8 sta_id;
Liad Kaufman42db09c2016-05-02 14:01:14 +0300361 int tid;
362
363 lockdep_assert_held(&mvm->mutex);
364
Sara Sharonbb497012016-09-29 14:52:40 +0300365 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
366 return -EINVAL;
367
Liad Kaufman42db09c2016-05-02 14:01:14 +0300368 spin_lock_bh(&mvm->queue_info_lock);
369 sta_id = mvm->queue_info[queue].ra_sta_id;
370 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
371 spin_unlock_bh(&mvm->queue_info_lock);
372
373 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
374 lockdep_is_held(&mvm->mutex));
375
376 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
377 return -EINVAL;
378
379 mvmsta = iwl_mvm_sta_from_mac80211(sta);
380
381 spin_lock_bh(&mvmsta->lock);
382 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
383 if (mvmsta->tid_data[tid].state == IWL_AGG_ON)
384 agg_tids |= BIT(tid);
385 }
386 spin_unlock_bh(&mvmsta->lock);
387
388 return agg_tids;
389}
390
Liad Kaufman9794c642015-08-19 17:34:28 +0300391/*
392 * Remove a queue from a station's resources.
393 * Note that this only marks as free. It DOESN'T delete a BA agreement, and
394 * doesn't disable the queue
395 */
396static int iwl_mvm_remove_sta_queue_marking(struct iwl_mvm *mvm, int queue)
397{
398 struct ieee80211_sta *sta;
399 struct iwl_mvm_sta *mvmsta;
400 unsigned long tid_bitmap;
401 unsigned long disable_agg_tids = 0;
402 u8 sta_id;
403 int tid;
404
405 lockdep_assert_held(&mvm->mutex);
406
Sara Sharonbb497012016-09-29 14:52:40 +0300407 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
408 return -EINVAL;
409
Liad Kaufman9794c642015-08-19 17:34:28 +0300410 spin_lock_bh(&mvm->queue_info_lock);
411 sta_id = mvm->queue_info[queue].ra_sta_id;
412 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
413 spin_unlock_bh(&mvm->queue_info_lock);
414
415 rcu_read_lock();
416
417 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
418
419 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) {
420 rcu_read_unlock();
421 return 0;
422 }
423
424 mvmsta = iwl_mvm_sta_from_mac80211(sta);
425
426 spin_lock_bh(&mvmsta->lock);
Liad Kaufman42db09c2016-05-02 14:01:14 +0300427 /* Unmap MAC queues and TIDs from this queue */
Liad Kaufman9794c642015-08-19 17:34:28 +0300428 for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
Liad Kaufman9794c642015-08-19 17:34:28 +0300429 if (mvmsta->tid_data[tid].state == IWL_AGG_ON)
430 disable_agg_tids |= BIT(tid);
Sara Sharon6862fce2017-02-22 19:34:17 +0200431 mvmsta->tid_data[tid].txq_id = IWL_MVM_INVALID_QUEUE;
Liad Kaufman9794c642015-08-19 17:34:28 +0300432 }
Liad Kaufman9794c642015-08-19 17:34:28 +0300433
Liad Kaufman42db09c2016-05-02 14:01:14 +0300434 mvmsta->tfd_queue_msk &= ~BIT(queue); /* Don't use this queue anymore */
Liad Kaufman9794c642015-08-19 17:34:28 +0300435 spin_unlock_bh(&mvmsta->lock);
436
437 rcu_read_unlock();
438
Liad Kaufman9794c642015-08-19 17:34:28 +0300439 return disable_agg_tids;
440}
441
Sara Sharon01796ff2016-11-16 17:04:36 +0200442static int iwl_mvm_free_inactive_queue(struct iwl_mvm *mvm, int queue,
443 bool same_sta)
444{
445 struct iwl_mvm_sta *mvmsta;
446 u8 txq_curr_ac, sta_id, tid;
447 unsigned long disable_agg_tids = 0;
448 int ret;
449
450 lockdep_assert_held(&mvm->mutex);
451
Sara Sharonbb497012016-09-29 14:52:40 +0300452 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
453 return -EINVAL;
454
Sara Sharon01796ff2016-11-16 17:04:36 +0200455 spin_lock_bh(&mvm->queue_info_lock);
456 txq_curr_ac = mvm->queue_info[queue].mac80211_ac;
457 sta_id = mvm->queue_info[queue].ra_sta_id;
458 tid = mvm->queue_info[queue].txq_tid;
459 spin_unlock_bh(&mvm->queue_info_lock);
460
461 mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id);
Sharon Dvire3df1e42017-02-21 10:41:31 +0200462 if (WARN_ON(!mvmsta))
463 return -EINVAL;
Sara Sharon01796ff2016-11-16 17:04:36 +0200464
465 disable_agg_tids = iwl_mvm_remove_sta_queue_marking(mvm, queue);
466 /* Disable the queue */
467 if (disable_agg_tids)
468 iwl_mvm_invalidate_sta_queue(mvm, queue,
469 disable_agg_tids, false);
470
471 ret = iwl_mvm_disable_txq(mvm, queue,
472 mvmsta->vif->hw_queue[txq_curr_ac],
473 tid, 0);
474 if (ret) {
475 /* Re-mark the inactive queue as inactive */
476 spin_lock_bh(&mvm->queue_info_lock);
477 mvm->queue_info[queue].status = IWL_MVM_QUEUE_INACTIVE;
478 spin_unlock_bh(&mvm->queue_info_lock);
479 IWL_ERR(mvm,
480 "Failed to free inactive queue %d (ret=%d)\n",
481 queue, ret);
482
483 return ret;
484 }
485
486 /* If TXQ is allocated to another STA, update removal in FW */
487 if (!same_sta)
488 iwl_mvm_invalidate_sta_queue(mvm, queue, 0, true);
489
490 return 0;
491}
492
Liad Kaufman42db09c2016-05-02 14:01:14 +0300493static int iwl_mvm_get_shared_queue(struct iwl_mvm *mvm,
494 unsigned long tfd_queue_mask, u8 ac)
495{
496 int queue = 0;
497 u8 ac_to_queue[IEEE80211_NUM_ACS];
498 int i;
499
500 lockdep_assert_held(&mvm->queue_info_lock);
Sara Sharonbb497012016-09-29 14:52:40 +0300501 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
502 return -EINVAL;
Liad Kaufman42db09c2016-05-02 14:01:14 +0300503
504 memset(&ac_to_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(ac_to_queue));
505
506 /* See what ACs the existing queues for this STA have */
507 for_each_set_bit(i, &tfd_queue_mask, IWL_MVM_DQA_MAX_DATA_QUEUE) {
508 /* Only DATA queues can be shared */
509 if (i < IWL_MVM_DQA_MIN_DATA_QUEUE &&
510 i != IWL_MVM_DQA_BSS_CLIENT_QUEUE)
511 continue;
512
Liad Kaufman9f9af3d2015-12-23 16:03:46 +0200513 /* Don't try and take queues being reconfigured */
514 if (mvm->queue_info[queue].status ==
515 IWL_MVM_QUEUE_RECONFIGURING)
516 continue;
517
Liad Kaufman42db09c2016-05-02 14:01:14 +0300518 ac_to_queue[mvm->queue_info[i].mac80211_ac] = i;
519 }
520
521 /*
522 * The queue to share is chosen only from DATA queues as follows (in
523 * descending priority):
524 * 1. An AC_BE queue
525 * 2. Same AC queue
526 * 3. Highest AC queue that is lower than new AC
527 * 4. Any existing AC (there always is at least 1 DATA queue)
528 */
529
530 /* Priority 1: An AC_BE queue */
531 if (ac_to_queue[IEEE80211_AC_BE] != IEEE80211_INVAL_HW_QUEUE)
532 queue = ac_to_queue[IEEE80211_AC_BE];
533 /* Priority 2: Same AC queue */
534 else if (ac_to_queue[ac] != IEEE80211_INVAL_HW_QUEUE)
535 queue = ac_to_queue[ac];
536 /* Priority 3a: If new AC is VO and VI exists - use VI */
537 else if (ac == IEEE80211_AC_VO &&
538 ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE)
539 queue = ac_to_queue[IEEE80211_AC_VI];
540 /* Priority 3b: No BE so only AC less than the new one is BK */
541 else if (ac_to_queue[IEEE80211_AC_BK] != IEEE80211_INVAL_HW_QUEUE)
542 queue = ac_to_queue[IEEE80211_AC_BK];
543 /* Priority 4a: No BE nor BK - use VI if exists */
544 else if (ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE)
545 queue = ac_to_queue[IEEE80211_AC_VI];
546 /* Priority 4b: No BE, BK nor VI - use VO if exists */
547 else if (ac_to_queue[IEEE80211_AC_VO] != IEEE80211_INVAL_HW_QUEUE)
548 queue = ac_to_queue[IEEE80211_AC_VO];
549
550 /* Make sure queue found (or not) is legal */
Liad Kaufman9f9af3d2015-12-23 16:03:46 +0200551 if (!iwl_mvm_is_dqa_data_queue(mvm, queue) &&
552 !iwl_mvm_is_dqa_mgmt_queue(mvm, queue) &&
553 (queue != IWL_MVM_DQA_BSS_CLIENT_QUEUE)) {
Liad Kaufman42db09c2016-05-02 14:01:14 +0300554 IWL_ERR(mvm, "No DATA queues available to share\n");
Liad Kaufman9f9af3d2015-12-23 16:03:46 +0200555 return -ENOSPC;
556 }
557
558 /* Make sure the queue isn't in the middle of being reconfigured */
559 if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_RECONFIGURING) {
560 IWL_ERR(mvm,
561 "TXQ %d is in the middle of re-config - try again\n",
562 queue);
563 return -EBUSY;
Liad Kaufman42db09c2016-05-02 14:01:14 +0300564 }
565
566 return queue;
567}
568
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200569/*
Liad Kaufman9f9af3d2015-12-23 16:03:46 +0200570 * If a given queue has a higher AC than the TID stream that is being compared
571 * to, the queue needs to be redirected to the lower AC. This function does that
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200572 * in such a case, otherwise - if no redirection required - it does nothing,
573 * unless the %force param is true.
574 */
Liad Kaufman9f9af3d2015-12-23 16:03:46 +0200575int iwl_mvm_scd_queue_redirect(struct iwl_mvm *mvm, int queue, int tid,
576 int ac, int ssn, unsigned int wdg_timeout,
577 bool force)
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200578{
579 struct iwl_scd_txq_cfg_cmd cmd = {
580 .scd_queue = queue,
Liad Kaufmanf7c692d2016-03-08 10:41:32 +0200581 .action = SCD_CFG_DISABLE_QUEUE,
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200582 };
583 bool shared_queue;
584 unsigned long mq;
585 int ret;
586
Sara Sharonbb497012016-09-29 14:52:40 +0300587 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
588 return -EINVAL;
589
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200590 /*
591 * If the AC is lower than current one - FIFO needs to be redirected to
592 * the lowest one of the streams in the queue. Check if this is needed
593 * here.
594 * Notice that the enum ieee80211_ac_numbers is "flipped", so BK is with
595 * value 3 and VO with value 0, so to check if ac X is lower than ac Y
596 * we need to check if the numerical value of X is LARGER than of Y.
597 */
598 spin_lock_bh(&mvm->queue_info_lock);
599 if (ac <= mvm->queue_info[queue].mac80211_ac && !force) {
600 spin_unlock_bh(&mvm->queue_info_lock);
601
602 IWL_DEBUG_TX_QUEUES(mvm,
603 "No redirection needed on TXQ #%d\n",
604 queue);
605 return 0;
606 }
607
608 cmd.sta_id = mvm->queue_info[queue].ra_sta_id;
609 cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[mvm->queue_info[queue].mac80211_ac];
Liad Kaufmanedbe9612016-02-02 15:43:32 +0200610 cmd.tid = mvm->queue_info[queue].txq_tid;
Sara Sharon34e10862017-02-23 13:15:07 +0200611 mq = mvm->hw_queue_to_mac80211[queue];
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200612 shared_queue = (mvm->queue_info[queue].hw_queue_refcount > 1);
613 spin_unlock_bh(&mvm->queue_info_lock);
614
Liad Kaufman9f9af3d2015-12-23 16:03:46 +0200615 IWL_DEBUG_TX_QUEUES(mvm, "Redirecting TXQ #%d to FIFO #%d\n",
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200616 queue, iwl_mvm_ac_to_tx_fifo[ac]);
617
618 /* Stop MAC queues and wait for this queue to empty */
619 iwl_mvm_stop_mac_queues(mvm, mq);
Sara Sharona1a57872017-03-05 11:38:58 +0200620 ret = iwl_trans_wait_tx_queues_empty(mvm->trans, BIT(queue));
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200621 if (ret) {
622 IWL_ERR(mvm, "Error draining queue %d before reconfig\n",
623 queue);
624 ret = -EIO;
625 goto out;
626 }
627
628 /* Before redirecting the queue we need to de-activate it */
629 iwl_trans_txq_disable(mvm->trans, queue, false);
630 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd);
631 if (ret)
632 IWL_ERR(mvm, "Failed SCD disable TXQ %d (ret=%d)\n", queue,
633 ret);
634
635 /* Make sure the SCD wrptr is correctly set before reconfiguring */
Sara Sharonca3b9c62016-06-30 16:14:02 +0300636 iwl_trans_txq_enable_cfg(mvm->trans, queue, ssn, NULL, wdg_timeout);
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200637
Liad Kaufmanedbe9612016-02-02 15:43:32 +0200638 /* Update the TID "owner" of the queue */
639 spin_lock_bh(&mvm->queue_info_lock);
640 mvm->queue_info[queue].txq_tid = tid;
641 spin_unlock_bh(&mvm->queue_info_lock);
642
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200643 /* TODO: Work-around SCD bug when moving back by multiples of 0x40 */
644
645 /* Redirect to lower AC */
646 iwl_mvm_reconfig_scd(mvm, queue, iwl_mvm_ac_to_tx_fifo[ac],
Sara Sharon0ec9257b2017-10-16 09:45:10 +0300647 cmd.sta_id, tid, IWL_FRAME_LIMIT, ssn);
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200648
649 /* Update AC marking of the queue */
650 spin_lock_bh(&mvm->queue_info_lock);
651 mvm->queue_info[queue].mac80211_ac = ac;
652 spin_unlock_bh(&mvm->queue_info_lock);
653
654 /*
655 * Mark queue as shared in transport if shared
656 * Note this has to be done after queue enablement because enablement
657 * can also set this value, and there is no indication there to shared
658 * queues
659 */
660 if (shared_queue)
661 iwl_trans_txq_set_shared_mode(mvm->trans, queue, true);
662
663out:
664 /* Continue using the MAC queues */
665 iwl_mvm_start_mac_queues(mvm, mq);
666
667 return ret;
668}
669
Sara Sharon310181e2017-01-17 14:27:48 +0200670static int iwl_mvm_sta_alloc_queue_tvqm(struct iwl_mvm *mvm,
671 struct ieee80211_sta *sta, u8 ac,
672 int tid)
673{
674 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
675 unsigned int wdg_timeout =
676 iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
677 u8 mac_queue = mvmsta->vif->hw_queue[ac];
678 int queue = -1;
679
680 lockdep_assert_held(&mvm->mutex);
681
682 IWL_DEBUG_TX_QUEUES(mvm,
683 "Allocating queue for sta %d on tid %d\n",
684 mvmsta->sta_id, tid);
685 queue = iwl_mvm_tvqm_enable_txq(mvm, mac_queue, mvmsta->sta_id, tid,
686 wdg_timeout);
687 if (queue < 0)
688 return queue;
689
690 IWL_DEBUG_TX_QUEUES(mvm, "Allocated queue is %d\n", queue);
691
692 spin_lock_bh(&mvmsta->lock);
693 mvmsta->tid_data[tid].txq_id = queue;
694 mvmsta->tid_data[tid].is_tid_active = true;
Sara Sharon310181e2017-01-17 14:27:48 +0200695 spin_unlock_bh(&mvmsta->lock);
696
Sara Sharon310181e2017-01-17 14:27:48 +0200697 return 0;
698}
699
Liad Kaufman24afba72015-07-28 18:56:08 +0300700static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm,
701 struct ieee80211_sta *sta, u8 ac, int tid,
702 struct ieee80211_hdr *hdr)
703{
704 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
705 struct iwl_trans_txq_scd_cfg cfg = {
Emmanuel Grumbachcf6c6ea2017-06-13 13:18:48 +0300706 .fifo = iwl_mvm_mac_ac_to_tx_fifo(mvm, ac),
Liad Kaufman24afba72015-07-28 18:56:08 +0300707 .sta_id = mvmsta->sta_id,
708 .tid = tid,
709 .frame_limit = IWL_FRAME_LIMIT,
710 };
711 unsigned int wdg_timeout =
712 iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
713 u8 mac_queue = mvmsta->vif->hw_queue[ac];
714 int queue = -1;
Sara Sharon01796ff2016-11-16 17:04:36 +0200715 bool using_inactive_queue = false, same_sta = false;
Liad Kaufman9794c642015-08-19 17:34:28 +0300716 unsigned long disable_agg_tids = 0;
717 enum iwl_mvm_agg_state queue_state;
Emmanuel Grumbachdcfbd672017-05-07 15:00:31 +0300718 bool shared_queue = false, inc_ssn;
Liad Kaufman24afba72015-07-28 18:56:08 +0300719 int ssn;
Liad Kaufman42db09c2016-05-02 14:01:14 +0300720 unsigned long tfd_queue_mask;
Liad Kaufmancf961e12015-08-13 19:16:08 +0300721 int ret;
Liad Kaufman24afba72015-07-28 18:56:08 +0300722
723 lockdep_assert_held(&mvm->mutex);
724
Sara Sharon310181e2017-01-17 14:27:48 +0200725 if (iwl_mvm_has_new_tx_api(mvm))
726 return iwl_mvm_sta_alloc_queue_tvqm(mvm, sta, ac, tid);
727
Liad Kaufman42db09c2016-05-02 14:01:14 +0300728 spin_lock_bh(&mvmsta->lock);
729 tfd_queue_mask = mvmsta->tfd_queue_msk;
730 spin_unlock_bh(&mvmsta->lock);
731
Liad Kaufmand2515a92016-03-23 16:31:08 +0200732 spin_lock_bh(&mvm->queue_info_lock);
Liad Kaufman24afba72015-07-28 18:56:08 +0300733
734 /*
735 * Non-QoS, QoS NDP and MGMT frames should go to a MGMT queue, if one
736 * exists
737 */
738 if (!ieee80211_is_data_qos(hdr->frame_control) ||
739 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
Liad Kaufman9794c642015-08-19 17:34:28 +0300740 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
741 IWL_MVM_DQA_MIN_MGMT_QUEUE,
Liad Kaufman24afba72015-07-28 18:56:08 +0300742 IWL_MVM_DQA_MAX_MGMT_QUEUE);
743 if (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE)
744 IWL_DEBUG_TX_QUEUES(mvm, "Found free MGMT queue #%d\n",
745 queue);
746
747 /* If no such queue is found, we'll use a DATA queue instead */
748 }
749
Liad Kaufman9794c642015-08-19 17:34:28 +0300750 if ((queue < 0 && mvmsta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) &&
751 (mvm->queue_info[mvmsta->reserved_queue].status ==
752 IWL_MVM_QUEUE_RESERVED ||
753 mvm->queue_info[mvmsta->reserved_queue].status ==
754 IWL_MVM_QUEUE_INACTIVE)) {
Liad Kaufman24afba72015-07-28 18:56:08 +0300755 queue = mvmsta->reserved_queue;
Liad Kaufman9794c642015-08-19 17:34:28 +0300756 mvm->queue_info[queue].reserved = true;
Liad Kaufman24afba72015-07-28 18:56:08 +0300757 IWL_DEBUG_TX_QUEUES(mvm, "Using reserved queue #%d\n", queue);
758 }
759
760 if (queue < 0)
Liad Kaufman9794c642015-08-19 17:34:28 +0300761 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
762 IWL_MVM_DQA_MIN_DATA_QUEUE,
Liad Kaufman24afba72015-07-28 18:56:08 +0300763 IWL_MVM_DQA_MAX_DATA_QUEUE);
Liad Kaufmancf961e12015-08-13 19:16:08 +0300764
765 /*
Liad Kaufman9794c642015-08-19 17:34:28 +0300766 * Check if this queue is already allocated but inactive.
767 * In such a case, we'll need to first free this queue before enabling
768 * it again, so we'll mark it as reserved to make sure no new traffic
769 * arrives on it
770 */
771 if (queue > 0 &&
772 mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) {
773 mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED;
774 using_inactive_queue = true;
Sara Sharon01796ff2016-11-16 17:04:36 +0200775 same_sta = mvm->queue_info[queue].ra_sta_id == mvmsta->sta_id;
Liad Kaufman9794c642015-08-19 17:34:28 +0300776 IWL_DEBUG_TX_QUEUES(mvm,
777 "Re-assigning TXQ %d: sta_id=%d, tid=%d\n",
778 queue, mvmsta->sta_id, tid);
779 }
780
Liad Kaufman42db09c2016-05-02 14:01:14 +0300781 /* No free queue - we'll have to share */
782 if (queue <= 0) {
783 queue = iwl_mvm_get_shared_queue(mvm, tfd_queue_mask, ac);
784 if (queue > 0) {
785 shared_queue = true;
786 mvm->queue_info[queue].status = IWL_MVM_QUEUE_SHARED;
787 }
788 }
789
Liad Kaufman9794c642015-08-19 17:34:28 +0300790 /*
Liad Kaufmancf961e12015-08-13 19:16:08 +0300791 * Mark TXQ as ready, even though it hasn't been fully configured yet,
792 * to make sure no one else takes it.
793 * This will allow avoiding re-acquiring the lock at the end of the
794 * configuration. On error we'll mark it back as free.
795 */
Liad Kaufman42db09c2016-05-02 14:01:14 +0300796 if ((queue > 0) && !shared_queue)
Liad Kaufmancf961e12015-08-13 19:16:08 +0300797 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
Liad Kaufman24afba72015-07-28 18:56:08 +0300798
Liad Kaufmand2515a92016-03-23 16:31:08 +0200799 spin_unlock_bh(&mvm->queue_info_lock);
Liad Kaufman24afba72015-07-28 18:56:08 +0300800
Liad Kaufman42db09c2016-05-02 14:01:14 +0300801 /* This shouldn't happen - out of queues */
802 if (WARN_ON(queue <= 0)) {
803 IWL_ERR(mvm, "No available queues for tid %d on sta_id %d\n",
804 tid, cfg.sta_id);
Liad Kaufman9f9af3d2015-12-23 16:03:46 +0200805 return queue;
Liad Kaufman42db09c2016-05-02 14:01:14 +0300806 }
Liad Kaufman24afba72015-07-28 18:56:08 +0300807
808 /*
809 * Actual en/disablement of aggregations is through the ADD_STA HCMD,
810 * but for configuring the SCD to send A-MPDUs we need to mark the queue
811 * as aggregatable.
812 * Mark all DATA queues as allowing to be aggregated at some point
813 */
Liad Kaufmand5216a22015-08-09 15:50:51 +0300814 cfg.aggregate = (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
815 queue == IWL_MVM_DQA_BSS_CLIENT_QUEUE);
Liad Kaufman24afba72015-07-28 18:56:08 +0300816
Liad Kaufman9794c642015-08-19 17:34:28 +0300817 /*
818 * If this queue was previously inactive (idle) - we need to free it
819 * first
820 */
821 if (using_inactive_queue) {
Sara Sharon01796ff2016-11-16 17:04:36 +0200822 ret = iwl_mvm_free_inactive_queue(mvm, queue, same_sta);
823 if (ret)
Liad Kaufman9794c642015-08-19 17:34:28 +0300824 return ret;
Liad Kaufman9794c642015-08-19 17:34:28 +0300825 }
826
Liad Kaufman42db09c2016-05-02 14:01:14 +0300827 IWL_DEBUG_TX_QUEUES(mvm,
828 "Allocating %squeue #%d to sta %d on tid %d\n",
829 shared_queue ? "shared " : "", queue,
830 mvmsta->sta_id, tid);
831
832 if (shared_queue) {
833 /* Disable any open aggs on this queue */
834 disable_agg_tids = iwl_mvm_get_queue_agg_tids(mvm, queue);
835
836 if (disable_agg_tids) {
837 IWL_DEBUG_TX_QUEUES(mvm, "Disabling aggs on queue %d\n",
838 queue);
839 iwl_mvm_invalidate_sta_queue(mvm, queue,
840 disable_agg_tids, false);
841 }
Liad Kaufman42db09c2016-05-02 14:01:14 +0300842 }
Liad Kaufman24afba72015-07-28 18:56:08 +0300843
844 ssn = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
Emmanuel Grumbachdcfbd672017-05-07 15:00:31 +0300845 inc_ssn = iwl_mvm_enable_txq(mvm, queue, mac_queue,
846 ssn, &cfg, wdg_timeout);
847 if (inc_ssn) {
848 ssn = (ssn + 1) & IEEE80211_SCTL_SEQ;
849 le16_add_cpu(&hdr->seq_ctrl, 0x10);
850 }
Liad Kaufman24afba72015-07-28 18:56:08 +0300851
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200852 /*
853 * Mark queue as shared in transport if shared
854 * Note this has to be done after queue enablement because enablement
855 * can also set this value, and there is no indication there to shared
856 * queues
857 */
858 if (shared_queue)
859 iwl_trans_txq_set_shared_mode(mvm->trans, queue, true);
860
Liad Kaufman24afba72015-07-28 18:56:08 +0300861 spin_lock_bh(&mvmsta->lock);
Emmanuel Grumbachdcfbd672017-05-07 15:00:31 +0300862 /*
863 * This looks racy, but it is not. We have only one packet for
864 * this ra/tid in our Tx path since we stop the Qdisc when we
865 * need to allocate a new TFD queue.
866 */
867 if (inc_ssn)
868 mvmsta->tid_data[tid].seq_number += 0x10;
Liad Kaufman24afba72015-07-28 18:56:08 +0300869 mvmsta->tid_data[tid].txq_id = queue;
Liad Kaufman9794c642015-08-19 17:34:28 +0300870 mvmsta->tid_data[tid].is_tid_active = true;
Liad Kaufman24afba72015-07-28 18:56:08 +0300871 mvmsta->tfd_queue_msk |= BIT(queue);
Liad Kaufman9794c642015-08-19 17:34:28 +0300872 queue_state = mvmsta->tid_data[tid].state;
Liad Kaufman24afba72015-07-28 18:56:08 +0300873
874 if (mvmsta->reserved_queue == queue)
875 mvmsta->reserved_queue = IEEE80211_INVAL_HW_QUEUE;
876 spin_unlock_bh(&mvmsta->lock);
877
Liad Kaufman42db09c2016-05-02 14:01:14 +0300878 if (!shared_queue) {
879 ret = iwl_mvm_sta_send_to_fw(mvm, sta, true, STA_MODIFY_QUEUES);
880 if (ret)
881 goto out_err;
Liad Kaufmancf961e12015-08-13 19:16:08 +0300882
Liad Kaufman42db09c2016-05-02 14:01:14 +0300883 /* If we need to re-enable aggregations... */
884 if (queue_state == IWL_AGG_ON) {
885 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
886 if (ret)
887 goto out_err;
888 }
Liad Kaufman58f2cc52015-09-30 16:44:28 +0200889 } else {
890 /* Redirect queue, if needed */
891 ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid, ac, ssn,
892 wdg_timeout, false);
893 if (ret)
894 goto out_err;
Liad Kaufman42db09c2016-05-02 14:01:14 +0300895 }
Liad Kaufman9794c642015-08-19 17:34:28 +0300896
Liad Kaufman42db09c2016-05-02 14:01:14 +0300897 return 0;
Liad Kaufmancf961e12015-08-13 19:16:08 +0300898
899out_err:
900 iwl_mvm_disable_txq(mvm, queue, mac_queue, tid, 0);
901
902 return ret;
Liad Kaufman24afba72015-07-28 18:56:08 +0300903}
904
Liad Kaufman19aefa42016-03-08 14:29:51 +0200905static void iwl_mvm_change_queue_owner(struct iwl_mvm *mvm, int queue)
906{
907 struct iwl_scd_txq_cfg_cmd cmd = {
908 .scd_queue = queue,
909 .action = SCD_CFG_UPDATE_QUEUE_TID,
910 };
Liad Kaufman19aefa42016-03-08 14:29:51 +0200911 int tid;
912 unsigned long tid_bitmap;
913 int ret;
914
915 lockdep_assert_held(&mvm->mutex);
916
Sara Sharonbb497012016-09-29 14:52:40 +0300917 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
918 return;
919
Liad Kaufman19aefa42016-03-08 14:29:51 +0200920 spin_lock_bh(&mvm->queue_info_lock);
Liad Kaufman19aefa42016-03-08 14:29:51 +0200921 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
922 spin_unlock_bh(&mvm->queue_info_lock);
923
924 if (WARN(!tid_bitmap, "TXQ %d has no tids assigned to it\n", queue))
925 return;
926
927 /* Find any TID for queue */
928 tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1);
929 cmd.tid = tid;
930 cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
931
932 ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd);
Liad Kaufman341ca402016-09-18 14:51:59 +0300933 if (ret) {
Liad Kaufman19aefa42016-03-08 14:29:51 +0200934 IWL_ERR(mvm, "Failed to update owner of TXQ %d (ret=%d)\n",
935 queue, ret);
Liad Kaufman341ca402016-09-18 14:51:59 +0300936 return;
937 }
938
939 spin_lock_bh(&mvm->queue_info_lock);
940 mvm->queue_info[queue].txq_tid = tid;
941 spin_unlock_bh(&mvm->queue_info_lock);
942 IWL_DEBUG_TX_QUEUES(mvm, "Changed TXQ %d ownership to tid %d\n",
943 queue, tid);
Liad Kaufman19aefa42016-03-08 14:29:51 +0200944}
945
Liad Kaufman9f9af3d2015-12-23 16:03:46 +0200946static void iwl_mvm_unshare_queue(struct iwl_mvm *mvm, int queue)
947{
948 struct ieee80211_sta *sta;
949 struct iwl_mvm_sta *mvmsta;
Sharon Dvir806911d2017-05-21 12:09:49 +0300950 u8 sta_id;
Liad Kaufman9f9af3d2015-12-23 16:03:46 +0200951 int tid = -1;
952 unsigned long tid_bitmap;
953 unsigned int wdg_timeout;
954 int ssn;
955 int ret = true;
956
Sara Sharonbb497012016-09-29 14:52:40 +0300957 /* queue sharing is disabled on new TX path */
958 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
959 return;
960
Liad Kaufman9f9af3d2015-12-23 16:03:46 +0200961 lockdep_assert_held(&mvm->mutex);
962
963 spin_lock_bh(&mvm->queue_info_lock);
964 sta_id = mvm->queue_info[queue].ra_sta_id;
965 tid_bitmap = mvm->queue_info[queue].tid_bitmap;
966 spin_unlock_bh(&mvm->queue_info_lock);
967
968 /* Find TID for queue, and make sure it is the only one on the queue */
969 tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1);
970 if (tid_bitmap != BIT(tid)) {
971 IWL_ERR(mvm, "Failed to unshare q %d, active tids=0x%lx\n",
972 queue, tid_bitmap);
973 return;
974 }
975
976 IWL_DEBUG_TX_QUEUES(mvm, "Unsharing TXQ %d, keeping tid %d\n", queue,
977 tid);
978
979 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
980 lockdep_is_held(&mvm->mutex));
981
982 if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta)))
983 return;
984
985 mvmsta = iwl_mvm_sta_from_mac80211(sta);
986 wdg_timeout = iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
987
988 ssn = IEEE80211_SEQ_TO_SN(mvmsta->tid_data[tid].seq_number);
989
990 ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid,
991 tid_to_mac80211_ac[tid], ssn,
992 wdg_timeout, true);
993 if (ret) {
994 IWL_ERR(mvm, "Failed to redirect TXQ %d\n", queue);
995 return;
996 }
997
998 /* If aggs should be turned back on - do it */
999 if (mvmsta->tid_data[tid].state == IWL_AGG_ON) {
Emmanuel Grumbach9cd70e82016-09-20 13:40:33 +03001000 struct iwl_mvm_add_sta_cmd cmd = {0};
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02001001
1002 mvmsta->tid_disable_agg &= ~BIT(tid);
1003
1004 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
1005 cmd.sta_id = mvmsta->sta_id;
1006 cmd.add_modify = STA_MODE_MODIFY;
1007 cmd.modify_mask = STA_MODIFY_TID_DISABLE_TX;
1008 cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk);
1009 cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg);
1010
1011 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
1012 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
1013 if (!ret) {
1014 IWL_DEBUG_TX_QUEUES(mvm,
1015 "TXQ #%d is now aggregated again\n",
1016 queue);
1017
1018 /* Mark queue intenally as aggregating again */
1019 iwl_trans_txq_set_shared_mode(mvm->trans, queue, false);
1020 }
1021 }
1022
1023 spin_lock_bh(&mvm->queue_info_lock);
1024 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
1025 spin_unlock_bh(&mvm->queue_info_lock);
1026}
1027
Liad Kaufman24afba72015-07-28 18:56:08 +03001028static inline u8 iwl_mvm_tid_to_ac_queue(int tid)
1029{
1030 if (tid == IWL_MAX_TID_COUNT)
1031 return IEEE80211_AC_VO; /* MGMT */
1032
1033 return tid_to_mac80211_ac[tid];
1034}
1035
1036static void iwl_mvm_tx_deferred_stream(struct iwl_mvm *mvm,
1037 struct ieee80211_sta *sta, int tid)
1038{
1039 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1040 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
1041 struct sk_buff *skb;
1042 struct ieee80211_hdr *hdr;
1043 struct sk_buff_head deferred_tx;
1044 u8 mac_queue;
1045 bool no_queue = false; /* Marks if there is a problem with the queue */
1046 u8 ac;
1047
1048 lockdep_assert_held(&mvm->mutex);
1049
1050 skb = skb_peek(&tid_data->deferred_tx_frames);
1051 if (!skb)
1052 return;
1053 hdr = (void *)skb->data;
1054
1055 ac = iwl_mvm_tid_to_ac_queue(tid);
1056 mac_queue = IEEE80211_SKB_CB(skb)->hw_queue;
1057
Sara Sharon6862fce2017-02-22 19:34:17 +02001058 if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE &&
Liad Kaufman24afba72015-07-28 18:56:08 +03001059 iwl_mvm_sta_alloc_queue(mvm, sta, ac, tid, hdr)) {
1060 IWL_ERR(mvm,
1061 "Can't alloc TXQ for sta %d tid %d - dropping frame\n",
1062 mvmsta->sta_id, tid);
1063
1064 /*
1065 * Mark queue as problematic so later the deferred traffic is
1066 * freed, as we can do nothing with it
1067 */
1068 no_queue = true;
1069 }
1070
1071 __skb_queue_head_init(&deferred_tx);
1072
Liad Kaufmand2515a92016-03-23 16:31:08 +02001073 /* Disable bottom-halves when entering TX path */
1074 local_bh_disable();
Liad Kaufman24afba72015-07-28 18:56:08 +03001075 spin_lock(&mvmsta->lock);
1076 skb_queue_splice_init(&tid_data->deferred_tx_frames, &deferred_tx);
Liad Kaufmanad5de732016-09-27 16:01:10 +03001077 mvmsta->deferred_traffic_tid_map &= ~BIT(tid);
Liad Kaufman24afba72015-07-28 18:56:08 +03001078 spin_unlock(&mvmsta->lock);
1079
Liad Kaufman24afba72015-07-28 18:56:08 +03001080 while ((skb = __skb_dequeue(&deferred_tx)))
1081 if (no_queue || iwl_mvm_tx_skb(mvm, skb, sta))
1082 ieee80211_free_txskb(mvm->hw, skb);
1083 local_bh_enable();
1084
1085 /* Wake queue */
1086 iwl_mvm_start_mac_queues(mvm, BIT(mac_queue));
1087}
1088
1089void iwl_mvm_add_new_dqa_stream_wk(struct work_struct *wk)
1090{
1091 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm,
1092 add_stream_wk);
1093 struct ieee80211_sta *sta;
1094 struct iwl_mvm_sta *mvmsta;
1095 unsigned long deferred_tid_traffic;
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02001096 int queue, sta_id, tid;
Liad Kaufman24afba72015-07-28 18:56:08 +03001097
Liad Kaufman9794c642015-08-19 17:34:28 +03001098 /* Check inactivity of queues */
1099 iwl_mvm_inactivity_check(mvm);
1100
Liad Kaufman24afba72015-07-28 18:56:08 +03001101 mutex_lock(&mvm->mutex);
1102
Sara Sharon34e10862017-02-23 13:15:07 +02001103 /* No queue reconfiguration in TVQM mode */
1104 if (iwl_mvm_has_new_tx_api(mvm))
1105 goto alloc_queues;
1106
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02001107 /* Reconfigure queues requiring reconfiguation */
Sara Sharon34e10862017-02-23 13:15:07 +02001108 for (queue = 0; queue < ARRAY_SIZE(mvm->queue_info); queue++) {
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02001109 bool reconfig;
Liad Kaufman19aefa42016-03-08 14:29:51 +02001110 bool change_owner;
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02001111
1112 spin_lock_bh(&mvm->queue_info_lock);
1113 reconfig = (mvm->queue_info[queue].status ==
1114 IWL_MVM_QUEUE_RECONFIGURING);
Liad Kaufman19aefa42016-03-08 14:29:51 +02001115
1116 /*
1117 * We need to take into account a situation in which a TXQ was
1118 * allocated to TID x, and then turned shared by adding TIDs y
1119 * and z. If TID x becomes inactive and is removed from the TXQ,
1120 * ownership must be given to one of the remaining TIDs.
1121 * This is mainly because if TID x continues - a new queue can't
1122 * be allocated for it as long as it is an owner of another TXQ.
1123 */
1124 change_owner = !(mvm->queue_info[queue].tid_bitmap &
1125 BIT(mvm->queue_info[queue].txq_tid)) &&
1126 (mvm->queue_info[queue].status ==
1127 IWL_MVM_QUEUE_SHARED);
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02001128 spin_unlock_bh(&mvm->queue_info_lock);
1129
1130 if (reconfig)
1131 iwl_mvm_unshare_queue(mvm, queue);
Liad Kaufman19aefa42016-03-08 14:29:51 +02001132 else if (change_owner)
1133 iwl_mvm_change_queue_owner(mvm, queue);
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02001134 }
1135
Sara Sharon34e10862017-02-23 13:15:07 +02001136alloc_queues:
Liad Kaufman24afba72015-07-28 18:56:08 +03001137 /* Go over all stations with deferred traffic */
1138 for_each_set_bit(sta_id, mvm->sta_deferred_frames,
1139 IWL_MVM_STATION_COUNT) {
1140 clear_bit(sta_id, mvm->sta_deferred_frames);
1141 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1142 lockdep_is_held(&mvm->mutex));
1143 if (IS_ERR_OR_NULL(sta))
1144 continue;
1145
1146 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1147 deferred_tid_traffic = mvmsta->deferred_traffic_tid_map;
1148
1149 for_each_set_bit(tid, &deferred_tid_traffic,
1150 IWL_MAX_TID_COUNT + 1)
1151 iwl_mvm_tx_deferred_stream(mvm, sta, tid);
1152 }
1153
1154 mutex_unlock(&mvm->mutex);
1155}
1156
1157static int iwl_mvm_reserve_sta_stream(struct iwl_mvm *mvm,
Liad Kaufmand5216a22015-08-09 15:50:51 +03001158 struct ieee80211_sta *sta,
1159 enum nl80211_iftype vif_type)
Liad Kaufman24afba72015-07-28 18:56:08 +03001160{
1161 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
1162 int queue;
Sara Sharon01796ff2016-11-16 17:04:36 +02001163 bool using_inactive_queue = false, same_sta = false;
Liad Kaufman24afba72015-07-28 18:56:08 +03001164
Sara Sharon396952e2017-02-22 19:40:55 +02001165 /* queue reserving is disabled on new TX path */
1166 if (WARN_ON(iwl_mvm_has_new_tx_api(mvm)))
1167 return 0;
1168
Liad Kaufman9794c642015-08-19 17:34:28 +03001169 /*
1170 * Check for inactive queues, so we don't reach a situation where we
1171 * can't add a STA due to a shortage in queues that doesn't really exist
1172 */
1173 iwl_mvm_inactivity_check(mvm);
1174
Liad Kaufman24afba72015-07-28 18:56:08 +03001175 spin_lock_bh(&mvm->queue_info_lock);
1176
1177 /* Make sure we have free resources for this STA */
Liad Kaufmand5216a22015-08-09 15:50:51 +03001178 if (vif_type == NL80211_IFTYPE_STATION && !sta->tdls &&
1179 !mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].hw_queue_refcount &&
Liad Kaufmancf961e12015-08-13 19:16:08 +03001180 (mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].status ==
1181 IWL_MVM_QUEUE_FREE))
Liad Kaufmand5216a22015-08-09 15:50:51 +03001182 queue = IWL_MVM_DQA_BSS_CLIENT_QUEUE;
1183 else
Liad Kaufman9794c642015-08-19 17:34:28 +03001184 queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
1185 IWL_MVM_DQA_MIN_DATA_QUEUE,
Liad Kaufmand5216a22015-08-09 15:50:51 +03001186 IWL_MVM_DQA_MAX_DATA_QUEUE);
Liad Kaufman24afba72015-07-28 18:56:08 +03001187 if (queue < 0) {
1188 spin_unlock_bh(&mvm->queue_info_lock);
1189 IWL_ERR(mvm, "No available queues for new station\n");
1190 return -ENOSPC;
Sara Sharon01796ff2016-11-16 17:04:36 +02001191 } else if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) {
1192 /*
1193 * If this queue is already allocated but inactive we'll need to
1194 * first free this queue before enabling it again, we'll mark
1195 * it as reserved to make sure no new traffic arrives on it
1196 */
1197 using_inactive_queue = true;
1198 same_sta = mvm->queue_info[queue].ra_sta_id == mvmsta->sta_id;
Liad Kaufman24afba72015-07-28 18:56:08 +03001199 }
Liad Kaufmancf961e12015-08-13 19:16:08 +03001200 mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED;
Liad Kaufman24afba72015-07-28 18:56:08 +03001201
1202 spin_unlock_bh(&mvm->queue_info_lock);
1203
1204 mvmsta->reserved_queue = queue;
1205
Sara Sharon01796ff2016-11-16 17:04:36 +02001206 if (using_inactive_queue)
1207 iwl_mvm_free_inactive_queue(mvm, queue, same_sta);
1208
Liad Kaufman24afba72015-07-28 18:56:08 +03001209 IWL_DEBUG_TX_QUEUES(mvm, "Reserving data queue #%d for sta_id %d\n",
1210 queue, mvmsta->sta_id);
1211
1212 return 0;
1213}
1214
Liad Kaufman8d98ae62016-02-02 16:02:46 +02001215/*
1216 * In DQA mode, after a HW restart the queues should be allocated as before, in
1217 * order to avoid race conditions when there are shared queues. This function
1218 * does the re-mapping and queue allocation.
1219 *
1220 * Note that re-enabling aggregations isn't done in this function.
1221 */
1222static void iwl_mvm_realloc_queues_after_restart(struct iwl_mvm *mvm,
1223 struct iwl_mvm_sta *mvm_sta)
1224{
1225 unsigned int wdg_timeout =
1226 iwl_mvm_get_wd_timeout(mvm, mvm_sta->vif, false, false);
1227 int i;
1228 struct iwl_trans_txq_scd_cfg cfg = {
1229 .sta_id = mvm_sta->sta_id,
1230 .frame_limit = IWL_FRAME_LIMIT,
1231 };
1232
Johannes Berg03c902b2016-12-02 12:03:36 +01001233 /* Make sure reserved queue is still marked as such (if allocated) */
1234 if (mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE)
1235 mvm->queue_info[mvm_sta->reserved_queue].status =
1236 IWL_MVM_QUEUE_RESERVED;
Liad Kaufman8d98ae62016-02-02 16:02:46 +02001237
1238 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
1239 struct iwl_mvm_tid_data *tid_data = &mvm_sta->tid_data[i];
1240 int txq_id = tid_data->txq_id;
1241 int ac;
1242 u8 mac_queue;
1243
Sara Sharon6862fce2017-02-22 19:34:17 +02001244 if (txq_id == IWL_MVM_INVALID_QUEUE)
Liad Kaufman8d98ae62016-02-02 16:02:46 +02001245 continue;
1246
1247 skb_queue_head_init(&tid_data->deferred_tx_frames);
1248
1249 ac = tid_to_mac80211_ac[i];
1250 mac_queue = mvm_sta->vif->hw_queue[ac];
1251
Sara Sharon310181e2017-01-17 14:27:48 +02001252 if (iwl_mvm_has_new_tx_api(mvm)) {
1253 IWL_DEBUG_TX_QUEUES(mvm,
1254 "Re-mapping sta %d tid %d\n",
1255 mvm_sta->sta_id, i);
1256 txq_id = iwl_mvm_tvqm_enable_txq(mvm, mac_queue,
1257 mvm_sta->sta_id,
1258 i, wdg_timeout);
1259 tid_data->txq_id = txq_id;
Liad Kaufman5d390512017-10-17 16:26:00 +03001260
1261 /*
1262 * Since we don't set the seq number after reset, and HW
1263 * sets it now, FW reset will cause the seq num to start
1264 * at 0 again, so driver will need to update it
1265 * internally as well, so it keeps in sync with real val
1266 */
1267 tid_data->seq_number = 0;
Sara Sharon310181e2017-01-17 14:27:48 +02001268 } else {
1269 u16 seq = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
Liad Kaufman8d98ae62016-02-02 16:02:46 +02001270
Sara Sharon310181e2017-01-17 14:27:48 +02001271 cfg.tid = i;
Emmanuel Grumbachcf6c6ea2017-06-13 13:18:48 +03001272 cfg.fifo = iwl_mvm_mac_ac_to_tx_fifo(mvm, ac);
Sara Sharon310181e2017-01-17 14:27:48 +02001273 cfg.aggregate = (txq_id >= IWL_MVM_DQA_MIN_DATA_QUEUE ||
1274 txq_id ==
1275 IWL_MVM_DQA_BSS_CLIENT_QUEUE);
Liad Kaufman8d98ae62016-02-02 16:02:46 +02001276
Sara Sharon310181e2017-01-17 14:27:48 +02001277 IWL_DEBUG_TX_QUEUES(mvm,
1278 "Re-mapping sta %d tid %d to queue %d\n",
1279 mvm_sta->sta_id, i, txq_id);
1280
1281 iwl_mvm_enable_txq(mvm, txq_id, mac_queue, seq, &cfg,
1282 wdg_timeout);
Sara Sharon34e10862017-02-23 13:15:07 +02001283 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_READY;
Sara Sharon310181e2017-01-17 14:27:48 +02001284 }
Liad Kaufman8d98ae62016-02-02 16:02:46 +02001285 }
Liad Kaufman8d98ae62016-02-02 16:02:46 +02001286}
1287
Shaul Triebitz732d06e2017-07-10 19:58:10 +03001288static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm,
1289 struct iwl_mvm_int_sta *sta,
1290 const u8 *addr,
1291 u16 mac_id, u16 color)
1292{
1293 struct iwl_mvm_add_sta_cmd cmd;
1294 int ret;
Luca Coelho3f497de2017-09-02 11:05:22 +03001295 u32 status = ADD_STA_SUCCESS;
Shaul Triebitz732d06e2017-07-10 19:58:10 +03001296
1297 lockdep_assert_held(&mvm->mutex);
1298
1299 memset(&cmd, 0, sizeof(cmd));
1300 cmd.sta_id = sta->sta_id;
1301 cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id,
1302 color));
1303 if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
1304 cmd.station_type = sta->type;
1305
1306 if (!iwl_mvm_has_new_tx_api(mvm))
1307 cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk);
1308 cmd.tid_disable_tx = cpu_to_le16(0xffff);
1309
1310 if (addr)
1311 memcpy(cmd.addr, addr, ETH_ALEN);
1312
1313 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1314 iwl_mvm_add_sta_cmd_size(mvm),
1315 &cmd, &status);
1316 if (ret)
1317 return ret;
1318
1319 switch (status & IWL_ADD_STA_STATUS_MASK) {
1320 case ADD_STA_SUCCESS:
1321 IWL_DEBUG_INFO(mvm, "Internal station added.\n");
1322 return 0;
1323 default:
1324 ret = -EIO;
1325 IWL_ERR(mvm, "Add internal station failed, status=0x%x\n",
1326 status);
1327 break;
1328 }
1329 return ret;
1330}
1331
Johannes Berg8ca151b2013-01-24 14:25:36 +01001332int iwl_mvm_add_sta(struct iwl_mvm *mvm,
1333 struct ieee80211_vif *vif,
1334 struct ieee80211_sta *sta)
1335{
1336 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01001337 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Sara Sharona571f5f2015-12-07 12:50:58 +02001338 struct iwl_mvm_rxq_dup_data *dup_data;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001339 int i, ret, sta_id;
Shaul Triebitz732d06e2017-07-10 19:58:10 +03001340 bool sta_update = false;
1341 unsigned int sta_flags = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001342
1343 lockdep_assert_held(&mvm->mutex);
1344
1345 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
Eliad Pellerb92e6612014-01-23 17:58:23 +02001346 sta_id = iwl_mvm_find_free_sta_id(mvm,
1347 ieee80211_vif_type_p2p(vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +01001348 else
1349 sta_id = mvm_sta->sta_id;
1350
Sara Sharon0ae98812017-01-04 14:53:58 +02001351 if (sta_id == IWL_MVM_INVALID_STA)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001352 return -ENOSPC;
1353
1354 spin_lock_init(&mvm_sta->lock);
1355
Johannes Bergc8f54702017-06-19 23:50:31 +02001356 /* if this is a HW restart re-alloc existing queues */
1357 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
Shaul Triebitz732d06e2017-07-10 19:58:10 +03001358 struct iwl_mvm_int_sta tmp_sta = {
1359 .sta_id = sta_id,
1360 .type = mvm_sta->sta_type,
1361 };
1362
1363 /*
1364 * First add an empty station since allocating
1365 * a queue requires a valid station
1366 */
1367 ret = iwl_mvm_add_int_sta_common(mvm, &tmp_sta, sta->addr,
1368 mvmvif->id, mvmvif->color);
1369 if (ret)
1370 goto err;
1371
Liad Kaufman8d98ae62016-02-02 16:02:46 +02001372 iwl_mvm_realloc_queues_after_restart(mvm, mvm_sta);
Shaul Triebitz732d06e2017-07-10 19:58:10 +03001373 sta_update = true;
1374 sta_flags = iwl_mvm_has_new_tx_api(mvm) ? 0 : STA_MODIFY_QUEUES;
Liad Kaufman8d98ae62016-02-02 16:02:46 +02001375 goto update_fw;
1376 }
1377
Johannes Berg8ca151b2013-01-24 14:25:36 +01001378 mvm_sta->sta_id = sta_id;
1379 mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id,
1380 mvmvif->color);
1381 mvm_sta->vif = vif;
Liad Kaufmana58bb462017-05-28 14:20:04 +03001382 if (!mvm->trans->cfg->gen2)
1383 mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
1384 else
1385 mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_GEN2_DEF;
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +03001386 mvm_sta->tx_protection = 0;
1387 mvm_sta->tt_tx_protection = false;
Sara Sharonced19f22017-02-06 19:09:32 +02001388 mvm_sta->sta_type = sta->tdls ? IWL_STA_TDLS_LINK : IWL_STA_LINK;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001389
1390 /* HW restart, don't assume the memory has been zeroed */
Liad Kaufman69191af2015-09-01 18:50:22 +03001391 mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */
Johannes Berg8ca151b2013-01-24 14:25:36 +01001392 mvm_sta->tfd_queue_msk = 0;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001393
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001394 /* for HW restart - reset everything but the sequence number */
Liad Kaufman24afba72015-07-28 18:56:08 +03001395 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001396 u16 seq = mvm_sta->tid_data[i].seq_number;
1397 memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i]));
1398 mvm_sta->tid_data[i].seq_number = seq;
Liad Kaufman24afba72015-07-28 18:56:08 +03001399
Liad Kaufman24afba72015-07-28 18:56:08 +03001400 /*
1401 * Mark all queues for this STA as unallocated and defer TX
1402 * frames until the queue is allocated
1403 */
Sara Sharon6862fce2017-02-22 19:34:17 +02001404 mvm_sta->tid_data[i].txq_id = IWL_MVM_INVALID_QUEUE;
Liad Kaufman24afba72015-07-28 18:56:08 +03001405 skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001406 }
Liad Kaufman24afba72015-07-28 18:56:08 +03001407 mvm_sta->deferred_traffic_tid_map = 0;
Eyal Shapiraefed6642014-09-14 15:58:53 +03001408 mvm_sta->agg_tids = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001409
Sara Sharona571f5f2015-12-07 12:50:58 +02001410 if (iwl_mvm_has_new_rx_api(mvm) &&
1411 !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
Johannes Berg92c4dca2017-06-07 10:35:54 +02001412 int q;
1413
Sara Sharona571f5f2015-12-07 12:50:58 +02001414 dup_data = kcalloc(mvm->trans->num_rx_queues,
Johannes Berg92c4dca2017-06-07 10:35:54 +02001415 sizeof(*dup_data), GFP_KERNEL);
Sara Sharona571f5f2015-12-07 12:50:58 +02001416 if (!dup_data)
1417 return -ENOMEM;
Johannes Berg92c4dca2017-06-07 10:35:54 +02001418 /*
1419 * Initialize all the last_seq values to 0xffff which can never
1420 * compare equal to the frame's seq_ctrl in the check in
1421 * iwl_mvm_is_dup() since the lower 4 bits are the fragment
1422 * number and fragmented packets don't reach that function.
1423 *
1424 * This thus allows receiving a packet with seqno 0 and the
1425 * retry bit set as the very first packet on a new TID.
1426 */
1427 for (q = 0; q < mvm->trans->num_rx_queues; q++)
1428 memset(dup_data[q].last_seq, 0xff,
1429 sizeof(dup_data[q].last_seq));
Sara Sharona571f5f2015-12-07 12:50:58 +02001430 mvm_sta->dup_data = dup_data;
1431 }
1432
Johannes Bergc8f54702017-06-19 23:50:31 +02001433 if (!iwl_mvm_has_new_tx_api(mvm)) {
Liad Kaufmand5216a22015-08-09 15:50:51 +03001434 ret = iwl_mvm_reserve_sta_stream(mvm, sta,
1435 ieee80211_vif_type_p2p(vif));
Liad Kaufman24afba72015-07-28 18:56:08 +03001436 if (ret)
1437 goto err;
1438 }
1439
Liad Kaufman8d98ae62016-02-02 16:02:46 +02001440update_fw:
Shaul Triebitz732d06e2017-07-10 19:58:10 +03001441 ret = iwl_mvm_sta_send_to_fw(mvm, sta, sta_update, sta_flags);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001442 if (ret)
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001443 goto err;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001444
Johannes Berg9e848012014-08-04 14:33:42 +02001445 if (vif->type == NL80211_IFTYPE_STATION) {
1446 if (!sta->tdls) {
Sara Sharon0ae98812017-01-04 14:53:58 +02001447 WARN_ON(mvmvif->ap_sta_id != IWL_MVM_INVALID_STA);
Johannes Berg9e848012014-08-04 14:33:42 +02001448 mvmvif->ap_sta_id = sta_id;
1449 } else {
Sara Sharon0ae98812017-01-04 14:53:58 +02001450 WARN_ON(mvmvif->ap_sta_id == IWL_MVM_INVALID_STA);
Johannes Berg9e848012014-08-04 14:33:42 +02001451 }
1452 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001453
1454 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta);
1455
1456 return 0;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001457
1458err:
Arik Nemtsova0f6bf22014-09-21 19:10:04 +03001459 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001460}
1461
1462int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
1463 bool drain)
1464{
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001465 struct iwl_mvm_add_sta_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +01001466 int ret;
1467 u32 status;
1468
1469 lockdep_assert_held(&mvm->mutex);
1470
1471 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
1472 cmd.sta_id = mvmsta->sta_id;
1473 cmd.add_modify = STA_MODE_MODIFY;
1474 cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0;
1475 cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW);
1476
1477 status = ADD_STA_SUCCESS;
Sara Sharon854c5702016-01-26 13:17:47 +02001478 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1479 iwl_mvm_add_sta_cmd_size(mvm),
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001480 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001481 if (ret)
1482 return ret;
1483
Sara Sharon837c4da2016-01-07 16:50:45 +02001484 switch (status & IWL_ADD_STA_STATUS_MASK) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001485 case ADD_STA_SUCCESS:
1486 IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n",
1487 mvmsta->sta_id);
1488 break;
1489 default:
1490 ret = -EIO;
1491 IWL_ERR(mvm, "Couldn't drain frames for staid %d\n",
1492 mvmsta->sta_id);
1493 break;
1494 }
1495
1496 return ret;
1497}
1498
1499/*
1500 * Remove a station from the FW table. Before sending the command to remove
1501 * the station validate that the station is indeed known to the driver (sanity
1502 * only).
1503 */
1504static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id)
1505{
1506 struct ieee80211_sta *sta;
1507 struct iwl_mvm_rm_sta_cmd rm_sta_cmd = {
1508 .sta_id = sta_id,
1509 };
1510 int ret;
1511
1512 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1513 lockdep_is_held(&mvm->mutex));
1514
1515 /* Note: internal stations are marked as error values */
1516 if (!sta) {
1517 IWL_ERR(mvm, "Invalid station id\n");
1518 return -EINVAL;
1519 }
1520
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001521 ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001522 sizeof(rm_sta_cmd), &rm_sta_cmd);
1523 if (ret) {
1524 IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id);
1525 return ret;
1526 }
1527
1528 return 0;
1529}
1530
Liad Kaufman24afba72015-07-28 18:56:08 +03001531static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm,
1532 struct ieee80211_vif *vif,
1533 struct iwl_mvm_sta *mvm_sta)
1534{
1535 int ac;
1536 int i;
1537
1538 lockdep_assert_held(&mvm->mutex);
1539
1540 for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) {
Sara Sharon6862fce2017-02-22 19:34:17 +02001541 if (mvm_sta->tid_data[i].txq_id == IWL_MVM_INVALID_QUEUE)
Liad Kaufman24afba72015-07-28 18:56:08 +03001542 continue;
1543
1544 ac = iwl_mvm_tid_to_ac_queue(i);
1545 iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id,
1546 vif->hw_queue[ac], i, 0);
Sara Sharon6862fce2017-02-22 19:34:17 +02001547 mvm_sta->tid_data[i].txq_id = IWL_MVM_INVALID_QUEUE;
Liad Kaufman24afba72015-07-28 18:56:08 +03001548 }
1549}
1550
Sara Sharond6d517b2017-03-06 10:16:11 +02001551int iwl_mvm_wait_sta_queues_empty(struct iwl_mvm *mvm,
1552 struct iwl_mvm_sta *mvm_sta)
1553{
Sharon Dvirbec95222017-06-12 11:40:33 +03001554 int i;
Sara Sharond6d517b2017-03-06 10:16:11 +02001555
1556 for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) {
1557 u16 txq_id;
Sharon Dvirbec95222017-06-12 11:40:33 +03001558 int ret;
Sara Sharond6d517b2017-03-06 10:16:11 +02001559
1560 spin_lock_bh(&mvm_sta->lock);
1561 txq_id = mvm_sta->tid_data[i].txq_id;
1562 spin_unlock_bh(&mvm_sta->lock);
1563
1564 if (txq_id == IWL_MVM_INVALID_QUEUE)
1565 continue;
1566
1567 ret = iwl_trans_wait_txq_empty(mvm->trans, txq_id);
1568 if (ret)
Sharon Dvirbec95222017-06-12 11:40:33 +03001569 return ret;
Sara Sharond6d517b2017-03-06 10:16:11 +02001570 }
1571
Sharon Dvirbec95222017-06-12 11:40:33 +03001572 return 0;
Sara Sharond6d517b2017-03-06 10:16:11 +02001573}
1574
Johannes Berg8ca151b2013-01-24 14:25:36 +01001575int iwl_mvm_rm_sta(struct iwl_mvm *mvm,
1576 struct ieee80211_vif *vif,
1577 struct ieee80211_sta *sta)
1578{
1579 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01001580 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Sara Sharon94c3e612016-12-07 15:04:37 +02001581 u8 sta_id = mvm_sta->sta_id;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001582 int ret;
1583
1584 lockdep_assert_held(&mvm->mutex);
1585
Sara Sharona571f5f2015-12-07 12:50:58 +02001586 if (iwl_mvm_has_new_rx_api(mvm))
1587 kfree(mvm_sta->dup_data);
1588
Johannes Bergc8f54702017-06-19 23:50:31 +02001589 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
1590 if (ret)
1591 return ret;
Sara Sharond6d517b2017-03-06 10:16:11 +02001592
Johannes Bergc8f54702017-06-19 23:50:31 +02001593 /* flush its queues here since we are freeing mvm_sta */
1594 ret = iwl_mvm_flush_sta(mvm, mvm_sta, false, 0);
1595 if (ret)
1596 return ret;
1597 if (iwl_mvm_has_new_tx_api(mvm)) {
1598 ret = iwl_mvm_wait_sta_queues_empty(mvm, mvm_sta);
1599 } else {
1600 u32 q_mask = mvm_sta->tfd_queue_msk;
Emmanuel Grumbach80d85652013-02-19 15:32:42 +02001601
Johannes Bergc8f54702017-06-19 23:50:31 +02001602 ret = iwl_trans_wait_tx_queues_empty(mvm->trans,
1603 q_mask);
1604 }
1605 if (ret)
1606 return ret;
Liad Kaufman56214742016-09-22 15:14:08 +03001607
Johannes Bergc8f54702017-06-19 23:50:31 +02001608 ret = iwl_mvm_drain_sta(mvm, mvm_sta, false);
Liad Kaufmana0315dea2016-07-07 13:25:59 +03001609
Johannes Bergc8f54702017-06-19 23:50:31 +02001610 iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta);
Liad Kaufmana0315dea2016-07-07 13:25:59 +03001611
Johannes Bergc8f54702017-06-19 23:50:31 +02001612 /* If there is a TXQ still marked as reserved - free it */
1613 if (mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) {
1614 u8 reserved_txq = mvm_sta->reserved_queue;
1615 enum iwl_mvm_queue_status *status;
1616
1617 /*
1618 * If no traffic has gone through the reserved TXQ - it
1619 * is still marked as IWL_MVM_QUEUE_RESERVED, and
1620 * should be manually marked as free again
1621 */
1622 spin_lock_bh(&mvm->queue_info_lock);
1623 status = &mvm->queue_info[reserved_txq].status;
1624 if (WARN((*status != IWL_MVM_QUEUE_RESERVED) &&
1625 (*status != IWL_MVM_QUEUE_FREE),
1626 "sta_id %d reserved txq %d status %d",
1627 sta_id, reserved_txq, *status)) {
Liad Kaufmana0315dea2016-07-07 13:25:59 +03001628 spin_unlock_bh(&mvm->queue_info_lock);
Johannes Bergc8f54702017-06-19 23:50:31 +02001629 return -EINVAL;
Liad Kaufmana0315dea2016-07-07 13:25:59 +03001630 }
1631
Johannes Bergc8f54702017-06-19 23:50:31 +02001632 *status = IWL_MVM_QUEUE_FREE;
1633 spin_unlock_bh(&mvm->queue_info_lock);
1634 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001635
Johannes Bergc8f54702017-06-19 23:50:31 +02001636 if (vif->type == NL80211_IFTYPE_STATION &&
1637 mvmvif->ap_sta_id == sta_id) {
1638 /* if associated - we can't remove the AP STA now */
1639 if (vif->bss_conf.assoc)
1640 return ret;
Eliad Peller37577fe2013-12-05 17:19:39 +02001641
Johannes Bergc8f54702017-06-19 23:50:31 +02001642 /* unassoc - go ahead - remove the AP STA now */
1643 mvmvif->ap_sta_id = IWL_MVM_INVALID_STA;
1644
1645 /* clear d0i3_ap_sta_id if no longer relevant */
1646 if (mvm->d0i3_ap_sta_id == sta_id)
1647 mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001648 }
1649
1650 /*
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +03001651 * This shouldn't happen - the TDLS channel switch should be canceled
1652 * before the STA is removed.
1653 */
Sara Sharon94c3e612016-12-07 15:04:37 +02001654 if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == sta_id)) {
Sara Sharon0ae98812017-01-04 14:53:58 +02001655 mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA;
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +03001656 cancel_delayed_work(&mvm->tdls_cs.dwork);
1657 }
1658
1659 /*
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +03001660 * Make sure that the tx response code sees the station as -EBUSY and
1661 * calls the drain worker.
1662 */
1663 spin_lock_bh(&mvm_sta->lock);
Johannes Bergc8f54702017-06-19 23:50:31 +02001664 spin_unlock_bh(&mvm_sta->lock);
Sara Sharon94c3e612016-12-07 15:04:37 +02001665
Johannes Bergc8f54702017-06-19 23:50:31 +02001666 ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id);
1667 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001668
1669 return ret;
1670}
1671
1672int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm,
1673 struct ieee80211_vif *vif,
1674 u8 sta_id)
1675{
1676 int ret = iwl_mvm_rm_sta_common(mvm, sta_id);
1677
1678 lockdep_assert_held(&mvm->mutex);
1679
Monam Agarwalc531c772014-03-24 00:05:56 +05301680 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001681 return ret;
1682}
1683
Chaya Rachel Ivgi0e39eb02015-12-03 15:51:46 +02001684int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm,
1685 struct iwl_mvm_int_sta *sta,
Sara Sharonced19f22017-02-06 19:09:32 +02001686 u32 qmask, enum nl80211_iftype iftype,
1687 enum iwl_sta_type type)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001688{
1689 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
Eliad Pellerb92e6612014-01-23 17:58:23 +02001690 sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype);
Sara Sharon0ae98812017-01-04 14:53:58 +02001691 if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_INVALID_STA))
Johannes Berg8ca151b2013-01-24 14:25:36 +01001692 return -ENOSPC;
1693 }
1694
1695 sta->tfd_queue_msk = qmask;
Sara Sharonced19f22017-02-06 19:09:32 +02001696 sta->type = type;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001697
1698 /* put a non-NULL value so iterating over the stations won't stop */
1699 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL));
1700 return 0;
1701}
1702
Sara Sharon26d6c162017-01-03 12:00:19 +02001703void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm, struct iwl_mvm_int_sta *sta)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001704{
Monam Agarwalc531c772014-03-24 00:05:56 +05301705 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta->sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001706 memset(sta, 0, sizeof(struct iwl_mvm_int_sta));
Sara Sharon0ae98812017-01-04 14:53:58 +02001707 sta->sta_id = IWL_MVM_INVALID_STA;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001708}
1709
Sara Sharonc5a719e2016-11-15 10:20:48 +02001710static void iwl_mvm_enable_aux_queue(struct iwl_mvm *mvm)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001711{
Emmanuel Grumbach4cf677f2015-01-12 14:38:29 +02001712 unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ?
1713 mvm->cfg->base_params->wd_timeout :
1714 IWL_WATCHDOG_DISABLED;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001715
Sara Sharon310181e2017-01-17 14:27:48 +02001716 if (iwl_mvm_has_new_tx_api(mvm)) {
1717 int queue = iwl_mvm_tvqm_enable_txq(mvm, mvm->aux_queue,
1718 mvm->aux_sta.sta_id,
1719 IWL_MAX_TID_COUNT,
1720 wdg_timeout);
1721 mvm->aux_queue = queue;
Johannes Bergc8f54702017-06-19 23:50:31 +02001722 } else {
Liad Kaufman28d07932015-09-01 16:36:25 +03001723 struct iwl_trans_txq_scd_cfg cfg = {
1724 .fifo = IWL_MVM_TX_FIFO_MCAST,
1725 .sta_id = mvm->aux_sta.sta_id,
1726 .tid = IWL_MAX_TID_COUNT,
1727 .aggregate = false,
1728 .frame_limit = IWL_FRAME_LIMIT,
1729 };
1730
1731 iwl_mvm_enable_txq(mvm, mvm->aux_queue, mvm->aux_queue, 0, &cfg,
1732 wdg_timeout);
1733 }
Sara Sharonc5a719e2016-11-15 10:20:48 +02001734}
1735
1736int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm)
1737{
1738 int ret;
1739
1740 lockdep_assert_held(&mvm->mutex);
1741
1742 /* Allocate aux station and assign to it the aux queue */
1743 ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue),
Sara Sharonced19f22017-02-06 19:09:32 +02001744 NL80211_IFTYPE_UNSPECIFIED,
1745 IWL_STA_AUX_ACTIVITY);
Sara Sharonc5a719e2016-11-15 10:20:48 +02001746 if (ret)
1747 return ret;
1748
1749 /* Map Aux queue to fifo - needs to happen before adding Aux station */
1750 if (!iwl_mvm_has_new_tx_api(mvm))
1751 iwl_mvm_enable_aux_queue(mvm);
Liad Kaufman28d07932015-09-01 16:36:25 +03001752
Johannes Berg8ca151b2013-01-24 14:25:36 +01001753 ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL,
1754 MAC_INDEX_AUX, 0);
Sara Sharonc5a719e2016-11-15 10:20:48 +02001755 if (ret) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001756 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
Sara Sharonc5a719e2016-11-15 10:20:48 +02001757 return ret;
1758 }
1759
1760 /*
1761 * For a000 firmware and on we cannot add queue to a station unknown
1762 * to firmware so enable queue here - after the station was added
1763 */
1764 if (iwl_mvm_has_new_tx_api(mvm))
1765 iwl_mvm_enable_aux_queue(mvm);
1766
1767 return 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001768}
1769
Chaya Rachel Ivgi0e39eb02015-12-03 15:51:46 +02001770int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1771{
1772 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1773
1774 lockdep_assert_held(&mvm->mutex);
1775 return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr,
1776 mvmvif->id, 0);
1777}
1778
1779int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1780{
1781 int ret;
1782
1783 lockdep_assert_held(&mvm->mutex);
1784
1785 ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id);
1786 if (ret)
1787 IWL_WARN(mvm, "Failed sending remove station\n");
1788
1789 return ret;
1790}
1791
1792void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm)
1793{
1794 iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta);
1795}
1796
Johannes Berg712b24a2014-08-04 14:14:14 +02001797void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm)
1798{
1799 lockdep_assert_held(&mvm->mutex);
1800
1801 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
1802}
1803
Johannes Berg8ca151b2013-01-24 14:25:36 +01001804/*
1805 * Send the add station command for the vif's broadcast station.
1806 * Assumes that the station was already allocated.
1807 *
1808 * @mvm: the mvm component
1809 * @vif: the interface to which the broadcast station is added
1810 * @bsta: the broadcast station to add.
1811 */
Johannes Berg013290a2014-08-04 13:38:48 +02001812int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001813{
1814 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg013290a2014-08-04 13:38:48 +02001815 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
Johannes Berg5023d962013-07-31 14:07:43 +02001816 static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
Johannes Berga4243402014-01-20 23:46:38 +01001817 const u8 *baddr = _baddr;
Johannes Berg7daa7622017-02-24 12:02:22 +01001818 int queue;
Liad Kaufmandf88c082016-11-24 15:31:00 +02001819 int ret;
Sara Sharonc5a719e2016-11-15 10:20:48 +02001820 unsigned int wdg_timeout =
1821 iwl_mvm_get_wd_timeout(mvm, vif, false, false);
1822 struct iwl_trans_txq_scd_cfg cfg = {
1823 .fifo = IWL_MVM_TX_FIFO_VO,
1824 .sta_id = mvmvif->bcast_sta.sta_id,
1825 .tid = IWL_MAX_TID_COUNT,
1826 .aggregate = false,
1827 .frame_limit = IWL_FRAME_LIMIT,
1828 };
Johannes Berg8ca151b2013-01-24 14:25:36 +01001829
1830 lockdep_assert_held(&mvm->mutex);
1831
Johannes Bergc8f54702017-06-19 23:50:31 +02001832 if (!iwl_mvm_has_new_tx_api(mvm)) {
Liad Kaufman4d339982017-03-21 17:13:16 +02001833 if (vif->type == NL80211_IFTYPE_AP ||
1834 vif->type == NL80211_IFTYPE_ADHOC)
Sara Sharon49f71712017-01-09 12:07:16 +02001835 queue = mvm->probe_queue;
Liad Kaufmandf88c082016-11-24 15:31:00 +02001836 else if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
Sara Sharon49f71712017-01-09 12:07:16 +02001837 queue = mvm->p2p_dev_queue;
Liad Kaufmandf88c082016-11-24 15:31:00 +02001838 else if (WARN(1, "Missing required TXQ for adding bcast STA\n"))
Liad Kaufmande24f632015-08-04 15:19:18 +03001839 return -EINVAL;
1840
Liad Kaufmandf88c082016-11-24 15:31:00 +02001841 bsta->tfd_queue_msk |= BIT(queue);
Sara Sharonc5a719e2016-11-15 10:20:48 +02001842
Sara Sharon310181e2017-01-17 14:27:48 +02001843 iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[0], 0,
1844 &cfg, wdg_timeout);
Liad Kaufmande24f632015-08-04 15:19:18 +03001845 }
1846
Johannes Berg5023d962013-07-31 14:07:43 +02001847 if (vif->type == NL80211_IFTYPE_ADHOC)
1848 baddr = vif->bss_conf.bssid;
1849
Sara Sharon0ae98812017-01-04 14:53:58 +02001850 if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_INVALID_STA))
Johannes Berg8ca151b2013-01-24 14:25:36 +01001851 return -ENOSPC;
1852
Liad Kaufmandf88c082016-11-24 15:31:00 +02001853 ret = iwl_mvm_add_int_sta_common(mvm, bsta, baddr,
1854 mvmvif->id, mvmvif->color);
1855 if (ret)
1856 return ret;
1857
1858 /*
Sara Sharonc5a719e2016-11-15 10:20:48 +02001859 * For a000 firmware and on we cannot add queue to a station unknown
1860 * to firmware so enable queue here - after the station was added
Liad Kaufmandf88c082016-11-24 15:31:00 +02001861 */
Sara Sharon310181e2017-01-17 14:27:48 +02001862 if (iwl_mvm_has_new_tx_api(mvm)) {
Johannes Berg7daa7622017-02-24 12:02:22 +01001863 queue = iwl_mvm_tvqm_enable_txq(mvm, vif->hw_queue[0],
1864 bsta->sta_id,
1865 IWL_MAX_TID_COUNT,
1866 wdg_timeout);
1867
Luca Coelho7b758a12017-06-20 13:40:03 +03001868 if (vif->type == NL80211_IFTYPE_AP ||
1869 vif->type == NL80211_IFTYPE_ADHOC)
Sara Sharon310181e2017-01-17 14:27:48 +02001870 mvm->probe_queue = queue;
1871 else if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
1872 mvm->p2p_dev_queue = queue;
Sara Sharon310181e2017-01-17 14:27:48 +02001873 }
Liad Kaufmandf88c082016-11-24 15:31:00 +02001874
1875 return 0;
1876}
1877
1878static void iwl_mvm_free_bcast_sta_queues(struct iwl_mvm *mvm,
1879 struct ieee80211_vif *vif)
1880{
1881 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Mordechai Goodsteind167e812017-05-10 16:42:53 +03001882 int queue;
Liad Kaufmandf88c082016-11-24 15:31:00 +02001883
1884 lockdep_assert_held(&mvm->mutex);
1885
Sara Sharond49394a2017-03-05 13:01:08 +02001886 iwl_mvm_flush_sta(mvm, &mvmvif->bcast_sta, true, 0);
1887
Mordechai Goodsteind167e812017-05-10 16:42:53 +03001888 switch (vif->type) {
1889 case NL80211_IFTYPE_AP:
1890 case NL80211_IFTYPE_ADHOC:
1891 queue = mvm->probe_queue;
1892 break;
1893 case NL80211_IFTYPE_P2P_DEVICE:
1894 queue = mvm->p2p_dev_queue;
1895 break;
1896 default:
1897 WARN(1, "Can't free bcast queue on vif type %d\n",
1898 vif->type);
1899 return;
Liad Kaufmandf88c082016-11-24 15:31:00 +02001900 }
1901
Mordechai Goodsteind167e812017-05-10 16:42:53 +03001902 iwl_mvm_disable_txq(mvm, queue, vif->hw_queue[0], IWL_MAX_TID_COUNT, 0);
1903 if (iwl_mvm_has_new_tx_api(mvm))
1904 return;
1905
1906 WARN_ON(!(mvmvif->bcast_sta.tfd_queue_msk & BIT(queue)));
1907 mvmvif->bcast_sta.tfd_queue_msk &= ~BIT(queue);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001908}
1909
1910/* Send the FW a request to remove the station from it's internal data
1911 * structures, but DO NOT remove the entry from the local data structures. */
Johannes Berg013290a2014-08-04 13:38:48 +02001912int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001913{
Johannes Berg013290a2014-08-04 13:38:48 +02001914 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001915 int ret;
1916
1917 lockdep_assert_held(&mvm->mutex);
1918
Johannes Bergc8f54702017-06-19 23:50:31 +02001919 iwl_mvm_free_bcast_sta_queues(mvm, vif);
Liad Kaufmandf88c082016-11-24 15:31:00 +02001920
Johannes Berg013290a2014-08-04 13:38:48 +02001921 ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001922 if (ret)
1923 IWL_WARN(mvm, "Failed sending remove station\n");
1924 return ret;
1925}
1926
Johannes Berg013290a2014-08-04 13:38:48 +02001927int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1928{
1929 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg013290a2014-08-04 13:38:48 +02001930
1931 lockdep_assert_held(&mvm->mutex);
1932
Johannes Bergc8f54702017-06-19 23:50:31 +02001933 return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, 0,
Sara Sharonced19f22017-02-06 19:09:32 +02001934 ieee80211_vif_type_p2p(vif),
1935 IWL_STA_GENERAL_PURPOSE);
Johannes Berg013290a2014-08-04 13:38:48 +02001936}
1937
Johannes Berg8ca151b2013-01-24 14:25:36 +01001938/* Allocate a new station entry for the broadcast station to the given vif,
1939 * and send it to the FW.
1940 * Note that each P2P mac should have its own broadcast station.
1941 *
1942 * @mvm: the mvm component
1943 * @vif: the interface to which the broadcast station is added
1944 * @bsta: the broadcast station to add. */
Luca Coelhod1973582017-06-22 16:00:25 +03001945int iwl_mvm_add_p2p_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001946{
1947 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg013290a2014-08-04 13:38:48 +02001948 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001949 int ret;
1950
1951 lockdep_assert_held(&mvm->mutex);
1952
Johannes Berg013290a2014-08-04 13:38:48 +02001953 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001954 if (ret)
1955 return ret;
1956
Johannes Berg013290a2014-08-04 13:38:48 +02001957 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001958
1959 if (ret)
1960 iwl_mvm_dealloc_int_sta(mvm, bsta);
Johannes Berg013290a2014-08-04 13:38:48 +02001961
Johannes Berg8ca151b2013-01-24 14:25:36 +01001962 return ret;
1963}
1964
Johannes Berg013290a2014-08-04 13:38:48 +02001965void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1966{
1967 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1968
1969 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
1970}
1971
Johannes Berg8ca151b2013-01-24 14:25:36 +01001972/*
1973 * Send the FW a request to remove the station from it's internal data
1974 * structures, and in addition remove it from the local data structure.
1975 */
Luca Coelhod1973582017-06-22 16:00:25 +03001976int iwl_mvm_rm_p2p_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001977{
1978 int ret;
1979
1980 lockdep_assert_held(&mvm->mutex);
1981
Johannes Berg013290a2014-08-04 13:38:48 +02001982 ret = iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001983
Johannes Berg013290a2014-08-04 13:38:48 +02001984 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1985
Johannes Berg8ca151b2013-01-24 14:25:36 +01001986 return ret;
1987}
1988
Sara Sharon26d6c162017-01-03 12:00:19 +02001989/*
1990 * Allocate a new station entry for the multicast station to the given vif,
1991 * and send it to the FW.
1992 * Note that each AP/GO mac should have its own multicast station.
1993 *
1994 * @mvm: the mvm component
1995 * @vif: the interface to which the multicast station is added
1996 */
1997int iwl_mvm_add_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1998{
1999 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2000 struct iwl_mvm_int_sta *msta = &mvmvif->mcast_sta;
2001 static const u8 _maddr[] = {0x03, 0x00, 0x00, 0x00, 0x00, 0x00};
2002 const u8 *maddr = _maddr;
2003 struct iwl_trans_txq_scd_cfg cfg = {
2004 .fifo = IWL_MVM_TX_FIFO_MCAST,
2005 .sta_id = msta->sta_id,
2006 .tid = IWL_MAX_TID_COUNT,
2007 .aggregate = false,
2008 .frame_limit = IWL_FRAME_LIMIT,
2009 };
2010 unsigned int timeout = iwl_mvm_get_wd_timeout(mvm, vif, false, false);
2011 int ret;
2012
2013 lockdep_assert_held(&mvm->mutex);
2014
Liad Kaufmanee48b722017-03-21 17:13:16 +02002015 if (WARN_ON(vif->type != NL80211_IFTYPE_AP &&
2016 vif->type != NL80211_IFTYPE_ADHOC))
Sara Sharon26d6c162017-01-03 12:00:19 +02002017 return -ENOTSUPP;
2018
Sara Sharonced19f22017-02-06 19:09:32 +02002019 /*
2020 * While in previous FWs we had to exclude cab queue from TFD queue
2021 * mask, now it is needed as any other queue.
2022 */
2023 if (!iwl_mvm_has_new_tx_api(mvm) &&
2024 fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
2025 iwl_mvm_enable_txq(mvm, vif->cab_queue, vif->cab_queue, 0,
2026 &cfg, timeout);
2027 msta->tfd_queue_msk |= BIT(vif->cab_queue);
2028 }
Sara Sharon26d6c162017-01-03 12:00:19 +02002029 ret = iwl_mvm_add_int_sta_common(mvm, msta, maddr,
2030 mvmvif->id, mvmvif->color);
2031 if (ret) {
2032 iwl_mvm_dealloc_int_sta(mvm, msta);
2033 return ret;
2034 }
2035
2036 /*
2037 * Enable cab queue after the ADD_STA command is sent.
2038 * This is needed for a000 firmware which won't accept SCD_QUEUE_CFG
Sara Sharonced19f22017-02-06 19:09:32 +02002039 * command with unknown station id, and for FW that doesn't support
2040 * station API since the cab queue is not included in the
2041 * tfd_queue_mask.
Sara Sharon26d6c162017-01-03 12:00:19 +02002042 */
Sara Sharon310181e2017-01-17 14:27:48 +02002043 if (iwl_mvm_has_new_tx_api(mvm)) {
2044 int queue = iwl_mvm_tvqm_enable_txq(mvm, vif->cab_queue,
2045 msta->sta_id,
2046 IWL_MAX_TID_COUNT,
2047 timeout);
Sara Sharone2af3fa2017-02-22 19:35:10 +02002048 mvmvif->cab_queue = queue;
Sara Sharonced19f22017-02-06 19:09:32 +02002049 } else if (!fw_has_api(&mvm->fw->ucode_capa,
2050 IWL_UCODE_TLV_API_STA_TYPE)) {
Liad Kaufmanee48b722017-03-21 17:13:16 +02002051 /*
2052 * In IBSS, ieee80211_check_queues() sets the cab_queue to be
2053 * invalid, so make sure we use the queue we want.
2054 * Note that this is done here as we want to avoid making DQA
2055 * changes in mac80211 layer.
2056 */
2057 if (vif->type == NL80211_IFTYPE_ADHOC) {
2058 vif->cab_queue = IWL_MVM_DQA_GCAST_QUEUE;
2059 mvmvif->cab_queue = vif->cab_queue;
2060 }
Sara Sharon310181e2017-01-17 14:27:48 +02002061 iwl_mvm_enable_txq(mvm, vif->cab_queue, vif->cab_queue, 0,
2062 &cfg, timeout);
2063 }
Sara Sharon26d6c162017-01-03 12:00:19 +02002064
2065 return 0;
2066}
2067
2068/*
2069 * Send the FW a request to remove the station from it's internal data
2070 * structures, and in addition remove it from the local data structure.
2071 */
2072int iwl_mvm_rm_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2073{
2074 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2075 int ret;
2076
2077 lockdep_assert_held(&mvm->mutex);
2078
Sara Sharond49394a2017-03-05 13:01:08 +02002079 iwl_mvm_flush_sta(mvm, &mvmvif->mcast_sta, true, 0);
2080
Sara Sharone2af3fa2017-02-22 19:35:10 +02002081 iwl_mvm_disable_txq(mvm, mvmvif->cab_queue, vif->cab_queue,
Sara Sharon26d6c162017-01-03 12:00:19 +02002082 IWL_MAX_TID_COUNT, 0);
2083
2084 ret = iwl_mvm_rm_sta_common(mvm, mvmvif->mcast_sta.sta_id);
2085 if (ret)
2086 IWL_WARN(mvm, "Failed sending remove station\n");
2087
2088 return ret;
2089}
2090
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03002091#define IWL_MAX_RX_BA_SESSIONS 16
2092
Sara Sharonb915c102016-03-23 16:32:02 +02002093static void iwl_mvm_sync_rxq_del_ba(struct iwl_mvm *mvm, u8 baid)
Sara Sharon10b2b202016-03-20 16:23:41 +02002094{
Sara Sharonb915c102016-03-23 16:32:02 +02002095 struct iwl_mvm_delba_notif notif = {
2096 .metadata.type = IWL_MVM_RXQ_NOTIF_DEL_BA,
2097 .metadata.sync = 1,
2098 .delba.baid = baid,
Sara Sharon10b2b202016-03-20 16:23:41 +02002099 };
Sara Sharonb915c102016-03-23 16:32:02 +02002100 iwl_mvm_sync_rx_queues_internal(mvm, (void *)&notif, sizeof(notif));
2101};
Sara Sharon10b2b202016-03-20 16:23:41 +02002102
Sara Sharonb915c102016-03-23 16:32:02 +02002103static void iwl_mvm_free_reorder(struct iwl_mvm *mvm,
2104 struct iwl_mvm_baid_data *data)
2105{
2106 int i;
2107
2108 iwl_mvm_sync_rxq_del_ba(mvm, data->baid);
2109
2110 for (i = 0; i < mvm->trans->num_rx_queues; i++) {
2111 int j;
2112 struct iwl_mvm_reorder_buffer *reorder_buf =
2113 &data->reorder_buf[i];
Johannes Bergdfdddd92017-09-26 12:24:51 +02002114 struct iwl_mvm_reorder_buf_entry *entries =
2115 &data->entries[i * data->entries_per_queue];
Sara Sharonb915c102016-03-23 16:32:02 +02002116
Sara Sharon06904052016-02-28 20:28:17 +02002117 spin_lock_bh(&reorder_buf->lock);
2118 if (likely(!reorder_buf->num_stored)) {
2119 spin_unlock_bh(&reorder_buf->lock);
Sara Sharonb915c102016-03-23 16:32:02 +02002120 continue;
Sara Sharon06904052016-02-28 20:28:17 +02002121 }
Sara Sharonb915c102016-03-23 16:32:02 +02002122
2123 /*
2124 * This shouldn't happen in regular DELBA since the internal
2125 * delBA notification should trigger a release of all frames in
2126 * the reorder buffer.
2127 */
2128 WARN_ON(1);
2129
2130 for (j = 0; j < reorder_buf->buf_size; j++)
Johannes Bergdfdddd92017-09-26 12:24:51 +02002131 __skb_queue_purge(&entries[j].e.frames);
Sara Sharon06904052016-02-28 20:28:17 +02002132 /*
2133 * Prevent timer re-arm. This prevents a very far fetched case
2134 * where we timed out on the notification. There may be prior
2135 * RX frames pending in the RX queue before the notification
2136 * that might get processed between now and the actual deletion
2137 * and we would re-arm the timer although we are deleting the
2138 * reorder buffer.
2139 */
2140 reorder_buf->removed = true;
2141 spin_unlock_bh(&reorder_buf->lock);
2142 del_timer_sync(&reorder_buf->reorder_timer);
Sara Sharonb915c102016-03-23 16:32:02 +02002143 }
2144}
2145
2146static void iwl_mvm_init_reorder_buffer(struct iwl_mvm *mvm,
Sara Sharonb915c102016-03-23 16:32:02 +02002147 struct iwl_mvm_baid_data *data,
2148 u16 ssn, u8 buf_size)
2149{
2150 int i;
2151
2152 for (i = 0; i < mvm->trans->num_rx_queues; i++) {
2153 struct iwl_mvm_reorder_buffer *reorder_buf =
2154 &data->reorder_buf[i];
Johannes Bergdfdddd92017-09-26 12:24:51 +02002155 struct iwl_mvm_reorder_buf_entry *entries =
2156 &data->entries[i * data->entries_per_queue];
Sara Sharonb915c102016-03-23 16:32:02 +02002157 int j;
2158
2159 reorder_buf->num_stored = 0;
2160 reorder_buf->head_sn = ssn;
2161 reorder_buf->buf_size = buf_size;
Sara Sharon06904052016-02-28 20:28:17 +02002162 /* rx reorder timer */
2163 reorder_buf->reorder_timer.function =
2164 iwl_mvm_reorder_timer_expired;
2165 reorder_buf->reorder_timer.data = (unsigned long)reorder_buf;
2166 init_timer(&reorder_buf->reorder_timer);
2167 spin_lock_init(&reorder_buf->lock);
2168 reorder_buf->mvm = mvm;
Sara Sharonb915c102016-03-23 16:32:02 +02002169 reorder_buf->queue = i;
Sara Sharon5d43eab2017-02-02 12:51:39 +02002170 reorder_buf->valid = false;
Sara Sharonb915c102016-03-23 16:32:02 +02002171 for (j = 0; j < reorder_buf->buf_size; j++)
Johannes Bergdfdddd92017-09-26 12:24:51 +02002172 __skb_queue_head_init(&entries[j].e.frames);
Sara Sharonb915c102016-03-23 16:32:02 +02002173 }
Sara Sharon10b2b202016-03-20 16:23:41 +02002174}
2175
Johannes Berg8ca151b2013-01-24 14:25:36 +01002176int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
Sara Sharon10b2b202016-03-20 16:23:41 +02002177 int tid, u16 ssn, bool start, u8 buf_size, u16 timeout)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002178{
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01002179 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03002180 struct iwl_mvm_add_sta_cmd cmd = {};
Sara Sharon10b2b202016-03-20 16:23:41 +02002181 struct iwl_mvm_baid_data *baid_data = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002182 int ret;
2183 u32 status;
2184
2185 lockdep_assert_held(&mvm->mutex);
2186
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03002187 if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) {
2188 IWL_WARN(mvm, "Not enough RX BA SESSIONS\n");
2189 return -ENOSPC;
2190 }
2191
Sara Sharon10b2b202016-03-20 16:23:41 +02002192 if (iwl_mvm_has_new_rx_api(mvm) && start) {
Johannes Bergdfdddd92017-09-26 12:24:51 +02002193 u16 reorder_buf_size = buf_size * sizeof(baid_data->entries[0]);
2194
2195 /* sparse doesn't like the __align() so don't check */
2196#ifndef __CHECKER__
2197 /*
2198 * The division below will be OK if either the cache line size
2199 * can be divided by the entry size (ALIGN will round up) or if
2200 * if the entry size can be divided by the cache line size, in
2201 * which case the ALIGN() will do nothing.
2202 */
2203 BUILD_BUG_ON(SMP_CACHE_BYTES % sizeof(baid_data->entries[0]) &&
2204 sizeof(baid_data->entries[0]) % SMP_CACHE_BYTES);
2205#endif
2206
2207 /*
2208 * Upward align the reorder buffer size to fill an entire cache
2209 * line for each queue, to avoid sharing cache lines between
2210 * different queues.
2211 */
2212 reorder_buf_size = ALIGN(reorder_buf_size, SMP_CACHE_BYTES);
2213
Sara Sharon10b2b202016-03-20 16:23:41 +02002214 /*
2215 * Allocate here so if allocation fails we can bail out early
2216 * before starting the BA session in the firmware
2217 */
Sara Sharonb915c102016-03-23 16:32:02 +02002218 baid_data = kzalloc(sizeof(*baid_data) +
2219 mvm->trans->num_rx_queues *
Johannes Bergdfdddd92017-09-26 12:24:51 +02002220 reorder_buf_size,
Sara Sharonb915c102016-03-23 16:32:02 +02002221 GFP_KERNEL);
Sara Sharon10b2b202016-03-20 16:23:41 +02002222 if (!baid_data)
2223 return -ENOMEM;
Johannes Bergdfdddd92017-09-26 12:24:51 +02002224
2225 /*
2226 * This division is why we need the above BUILD_BUG_ON(),
2227 * if that doesn't hold then this will not be right.
2228 */
2229 baid_data->entries_per_queue =
2230 reorder_buf_size / sizeof(baid_data->entries[0]);
Sara Sharon10b2b202016-03-20 16:23:41 +02002231 }
2232
Johannes Berg8ca151b2013-01-24 14:25:36 +01002233 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
2234 cmd.sta_id = mvm_sta->sta_id;
2235 cmd.add_modify = STA_MODE_MODIFY;
Emmanuel Grumbach93a42662013-07-02 13:35:35 +03002236 if (start) {
2237 cmd.add_immediate_ba_tid = (u8) tid;
2238 cmd.add_immediate_ba_ssn = cpu_to_le16(ssn);
Sara Sharon854c5702016-01-26 13:17:47 +02002239 cmd.rx_ba_window = cpu_to_le16((u16)buf_size);
Emmanuel Grumbach93a42662013-07-02 13:35:35 +03002240 } else {
2241 cmd.remove_immediate_ba_tid = (u8) tid;
2242 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002243 cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID :
2244 STA_MODIFY_REMOVE_BA_TID;
2245
2246 status = ADD_STA_SUCCESS;
Sara Sharon854c5702016-01-26 13:17:47 +02002247 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
2248 iwl_mvm_add_sta_cmd_size(mvm),
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03002249 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002250 if (ret)
Sara Sharon10b2b202016-03-20 16:23:41 +02002251 goto out_free;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002252
Sara Sharon837c4da2016-01-07 16:50:45 +02002253 switch (status & IWL_ADD_STA_STATUS_MASK) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002254 case ADD_STA_SUCCESS:
Sara Sharon35263a02016-06-21 12:12:10 +03002255 IWL_DEBUG_HT(mvm, "RX BA Session %sed in fw\n",
2256 start ? "start" : "stopp");
Johannes Berg8ca151b2013-01-24 14:25:36 +01002257 break;
2258 case ADD_STA_IMMEDIATE_BA_FAILURE:
2259 IWL_WARN(mvm, "RX BA Session refused by fw\n");
2260 ret = -ENOSPC;
2261 break;
2262 default:
2263 ret = -EIO;
2264 IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n",
2265 start ? "start" : "stopp", status);
2266 break;
2267 }
2268
Sara Sharon10b2b202016-03-20 16:23:41 +02002269 if (ret)
2270 goto out_free;
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03002271
Sara Sharon10b2b202016-03-20 16:23:41 +02002272 if (start) {
2273 u8 baid;
2274
2275 mvm->rx_ba_sessions++;
2276
2277 if (!iwl_mvm_has_new_rx_api(mvm))
2278 return 0;
2279
2280 if (WARN_ON(!(status & IWL_ADD_STA_BAID_VALID_MASK))) {
2281 ret = -EINVAL;
2282 goto out_free;
2283 }
2284 baid = (u8)((status & IWL_ADD_STA_BAID_MASK) >>
2285 IWL_ADD_STA_BAID_SHIFT);
2286 baid_data->baid = baid;
2287 baid_data->timeout = timeout;
2288 baid_data->last_rx = jiffies;
Wei Yongjun72c240f2016-07-12 11:40:57 +00002289 setup_timer(&baid_data->session_timer,
2290 iwl_mvm_rx_agg_session_expired,
2291 (unsigned long)&mvm->baid_map[baid]);
Sara Sharon10b2b202016-03-20 16:23:41 +02002292 baid_data->mvm = mvm;
2293 baid_data->tid = tid;
2294 baid_data->sta_id = mvm_sta->sta_id;
2295
2296 mvm_sta->tid_to_baid[tid] = baid;
2297 if (timeout)
2298 mod_timer(&baid_data->session_timer,
2299 TU_TO_EXP_TIME(timeout * 2));
2300
Sara Sharon3f1c4c52017-10-02 12:07:59 +03002301 iwl_mvm_init_reorder_buffer(mvm, baid_data, ssn, buf_size);
Sara Sharon10b2b202016-03-20 16:23:41 +02002302 /*
2303 * protect the BA data with RCU to cover a case where our
2304 * internal RX sync mechanism will timeout (not that it's
2305 * supposed to happen) and we will free the session data while
2306 * RX is being processed in parallel
2307 */
Sara Sharon35263a02016-06-21 12:12:10 +03002308 IWL_DEBUG_HT(mvm, "Sta %d(%d) is assigned to BAID %d\n",
2309 mvm_sta->sta_id, tid, baid);
Sara Sharon10b2b202016-03-20 16:23:41 +02002310 WARN_ON(rcu_access_pointer(mvm->baid_map[baid]));
2311 rcu_assign_pointer(mvm->baid_map[baid], baid_data);
Sara Sharon60dec522016-06-21 14:14:08 +03002312 } else {
Sara Sharon10b2b202016-03-20 16:23:41 +02002313 u8 baid = mvm_sta->tid_to_baid[tid];
2314
Sara Sharon60dec522016-06-21 14:14:08 +03002315 if (mvm->rx_ba_sessions > 0)
2316 /* check that restart flow didn't zero the counter */
2317 mvm->rx_ba_sessions--;
Sara Sharon10b2b202016-03-20 16:23:41 +02002318 if (!iwl_mvm_has_new_rx_api(mvm))
2319 return 0;
2320
2321 if (WARN_ON(baid == IWL_RX_REORDER_DATA_INVALID_BAID))
2322 return -EINVAL;
2323
2324 baid_data = rcu_access_pointer(mvm->baid_map[baid]);
2325 if (WARN_ON(!baid_data))
2326 return -EINVAL;
2327
2328 /* synchronize all rx queues so we can safely delete */
Sara Sharonb915c102016-03-23 16:32:02 +02002329 iwl_mvm_free_reorder(mvm, baid_data);
Sara Sharon10b2b202016-03-20 16:23:41 +02002330 del_timer_sync(&baid_data->session_timer);
Sara Sharon10b2b202016-03-20 16:23:41 +02002331 RCU_INIT_POINTER(mvm->baid_map[baid], NULL);
2332 kfree_rcu(baid_data, rcu_head);
Sara Sharon35263a02016-06-21 12:12:10 +03002333 IWL_DEBUG_HT(mvm, "BAID %d is free\n", baid);
Sara Sharon10b2b202016-03-20 16:23:41 +02002334 }
2335 return 0;
2336
2337out_free:
2338 kfree(baid_data);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002339 return ret;
2340}
2341
Liad Kaufman9794c642015-08-19 17:34:28 +03002342int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
2343 int tid, u8 queue, bool start)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002344{
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01002345 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03002346 struct iwl_mvm_add_sta_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +01002347 int ret;
2348 u32 status;
2349
2350 lockdep_assert_held(&mvm->mutex);
2351
2352 if (start) {
2353 mvm_sta->tfd_queue_msk |= BIT(queue);
2354 mvm_sta->tid_disable_agg &= ~BIT(tid);
2355 } else {
Liad Kaufmancf961e12015-08-13 19:16:08 +03002356 /* In DQA-mode the queue isn't removed on agg termination */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002357 mvm_sta->tid_disable_agg |= BIT(tid);
2358 }
2359
2360 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
2361 cmd.sta_id = mvm_sta->sta_id;
2362 cmd.add_modify = STA_MODE_MODIFY;
Sara Sharonbb497012016-09-29 14:52:40 +03002363 if (!iwl_mvm_has_new_tx_api(mvm))
2364 cmd.modify_mask = STA_MODIFY_QUEUES;
2365 cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002366 cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk);
2367 cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg);
2368
2369 status = ADD_STA_SUCCESS;
Sara Sharon854c5702016-01-26 13:17:47 +02002370 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
2371 iwl_mvm_add_sta_cmd_size(mvm),
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03002372 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002373 if (ret)
2374 return ret;
2375
Sara Sharon837c4da2016-01-07 16:50:45 +02002376 switch (status & IWL_ADD_STA_STATUS_MASK) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002377 case ADD_STA_SUCCESS:
2378 break;
2379 default:
2380 ret = -EIO;
2381 IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n",
2382 start ? "start" : "stopp", status);
2383 break;
2384 }
2385
2386 return ret;
2387}
2388
Emmanuel Grumbachb797e3f2014-03-06 14:49:36 +02002389const u8 tid_to_mac80211_ac[] = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002390 IEEE80211_AC_BE,
2391 IEEE80211_AC_BK,
2392 IEEE80211_AC_BK,
2393 IEEE80211_AC_BE,
2394 IEEE80211_AC_VI,
2395 IEEE80211_AC_VI,
2396 IEEE80211_AC_VO,
2397 IEEE80211_AC_VO,
Liad Kaufman9794c642015-08-19 17:34:28 +03002398 IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */
Johannes Berg8ca151b2013-01-24 14:25:36 +01002399};
2400
Johannes Berg3e56ead2013-02-15 22:23:18 +01002401static const u8 tid_to_ucode_ac[] = {
2402 AC_BE,
2403 AC_BK,
2404 AC_BK,
2405 AC_BE,
2406 AC_VI,
2407 AC_VI,
2408 AC_VO,
2409 AC_VO,
2410};
2411
Johannes Berg8ca151b2013-01-24 14:25:36 +01002412int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2413 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
2414{
Johannes Berg5b577a92013-11-14 18:20:04 +01002415 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002416 struct iwl_mvm_tid_data *tid_data;
Liad Kaufmandd321622017-04-05 16:25:11 +03002417 u16 normalized_ssn;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002418 int txq_id;
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002419 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002420
2421 if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
2422 return -EINVAL;
2423
Naftali Goldsteinbd800e42017-08-28 11:51:05 +03002424 if (mvmsta->tid_data[tid].state != IWL_AGG_QUEUED &&
2425 mvmsta->tid_data[tid].state != IWL_AGG_OFF) {
2426 IWL_ERR(mvm,
2427 "Start AGG when state is not IWL_AGG_QUEUED or IWL_AGG_OFF %d!\n",
Johannes Berg8ca151b2013-01-24 14:25:36 +01002428 mvmsta->tid_data[tid].state);
2429 return -ENXIO;
2430 }
2431
2432 lockdep_assert_held(&mvm->mutex);
2433
Arik Nemtsovb2492502014-03-13 12:21:50 +02002434 spin_lock_bh(&mvmsta->lock);
2435
2436 /* possible race condition - we entered D0i3 while starting agg */
2437 if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) {
2438 spin_unlock_bh(&mvmsta->lock);
2439 IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n");
2440 return -EIO;
2441 }
2442
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02002443 spin_lock(&mvm->queue_info_lock);
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002444
Liad Kaufmancf961e12015-08-13 19:16:08 +03002445 /*
2446 * Note the possible cases:
2447 * 1. In DQA mode with an enabled TXQ - TXQ needs to become agg'ed
2448 * 2. Non-DQA mode: the TXQ hasn't yet been enabled, so find a free
2449 * one and mark it as reserved
2450 * 3. In DQA mode, but no traffic yet on this TID: same treatment as in
2451 * non-DQA mode, since the TXQ hasn't yet been allocated
Sara Sharon34e10862017-02-23 13:15:07 +02002452 * Don't support case 3 for new TX path as it is not expected to happen
2453 * and aggregation will be offloaded soon anyway
Liad Kaufmancf961e12015-08-13 19:16:08 +03002454 */
2455 txq_id = mvmsta->tid_data[tid].txq_id;
Sara Sharon34e10862017-02-23 13:15:07 +02002456 if (iwl_mvm_has_new_tx_api(mvm)) {
2457 if (txq_id == IWL_MVM_INVALID_QUEUE) {
2458 ret = -ENXIO;
2459 goto release_locks;
2460 }
Johannes Bergc8f54702017-06-19 23:50:31 +02002461 } else if (unlikely(mvm->queue_info[txq_id].status ==
Sara Sharon34e10862017-02-23 13:15:07 +02002462 IWL_MVM_QUEUE_SHARED)) {
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02002463 ret = -ENXIO;
2464 IWL_DEBUG_TX_QUEUES(mvm,
2465 "Can't start tid %d agg on shared queue!\n",
2466 tid);
2467 goto release_locks;
Johannes Bergc8f54702017-06-19 23:50:31 +02002468 } else if (mvm->queue_info[txq_id].status != IWL_MVM_QUEUE_READY) {
Liad Kaufman9794c642015-08-19 17:34:28 +03002469 txq_id = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id,
Johannes Bergc8f54702017-06-19 23:50:31 +02002470 IWL_MVM_DQA_MIN_DATA_QUEUE,
2471 IWL_MVM_DQA_MAX_DATA_QUEUE);
Liad Kaufmancf961e12015-08-13 19:16:08 +03002472 if (txq_id < 0) {
2473 ret = txq_id;
Liad Kaufmancf961e12015-08-13 19:16:08 +03002474 IWL_ERR(mvm, "Failed to allocate agg queue\n");
2475 goto release_locks;
2476 }
Sara Sharon01796ff2016-11-16 17:04:36 +02002477 /*
2478 * TXQ shouldn't be in inactive mode for non-DQA, so getting
2479 * an inactive queue from iwl_mvm_find_free_queue() is
2480 * certainly a bug
2481 */
2482 WARN_ON(mvm->queue_info[txq_id].status ==
2483 IWL_MVM_QUEUE_INACTIVE);
Liad Kaufmancf961e12015-08-13 19:16:08 +03002484
2485 /* TXQ hasn't yet been enabled, so mark it only as reserved */
2486 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_RESERVED;
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002487 }
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02002488
2489 spin_unlock(&mvm->queue_info_lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002490
Liad Kaufmancf961e12015-08-13 19:16:08 +03002491 IWL_DEBUG_TX_QUEUES(mvm,
2492 "AGG for tid %d will be on queue #%d\n",
2493 tid, txq_id);
2494
Johannes Berg8ca151b2013-01-24 14:25:36 +01002495 tid_data = &mvmsta->tid_data[tid];
Johannes Berg9a886582013-02-15 19:25:00 +01002496 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002497 tid_data->txq_id = txq_id;
2498 *ssn = tid_data->ssn;
2499
2500 IWL_DEBUG_TX_QUEUES(mvm,
2501 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
2502 mvmsta->sta_id, tid, txq_id, tid_data->ssn,
2503 tid_data->next_reclaimed);
2504
Liad Kaufmandd321622017-04-05 16:25:11 +03002505 /*
2506 * In A000 HW, the next_reclaimed index is only 8 bit, so we'll need
2507 * to align the wrap around of ssn so we compare relevant values.
2508 */
2509 normalized_ssn = tid_data->ssn;
2510 if (mvm->trans->cfg->gen2)
2511 normalized_ssn &= 0xff;
2512
2513 if (normalized_ssn == tid_data->next_reclaimed) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002514 tid_data->state = IWL_AGG_STARTING;
2515 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2516 } else {
2517 tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA;
2518 }
2519
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002520 ret = 0;
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02002521 goto out;
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002522
2523release_locks:
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02002524 spin_unlock(&mvm->queue_info_lock);
2525out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002526 spin_unlock_bh(&mvmsta->lock);
2527
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002528 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002529}
2530
2531int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
Emmanuel Grumbachbb81bb62015-10-26 16:00:29 +02002532 struct ieee80211_sta *sta, u16 tid, u8 buf_size,
2533 bool amsdu)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002534{
Johannes Berg5b577a92013-11-14 18:20:04 +01002535 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002536 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
Emmanuel Grumbach5d42e7b2015-03-19 20:04:51 +02002537 unsigned int wdg_timeout =
2538 iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false);
Emmanuel Grumbacheea76c32016-02-21 16:29:17 +02002539 int queue, ret;
Liad Kaufmancf961e12015-08-13 19:16:08 +03002540 bool alloc_queue = true;
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02002541 enum iwl_mvm_queue_status queue_status;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002542 u16 ssn;
2543
Emmanuel Grumbacheea76c32016-02-21 16:29:17 +02002544 struct iwl_trans_txq_scd_cfg cfg = {
2545 .sta_id = mvmsta->sta_id,
2546 .tid = tid,
2547 .frame_limit = buf_size,
2548 .aggregate = true,
2549 };
2550
Eyal Shapiraefed6642014-09-14 15:58:53 +03002551 BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE)
2552 != IWL_MAX_TID_COUNT);
2553
Johannes Berg8ca151b2013-01-24 14:25:36 +01002554 spin_lock_bh(&mvmsta->lock);
2555 ssn = tid_data->ssn;
2556 queue = tid_data->txq_id;
2557 tid_data->state = IWL_AGG_ON;
Eyal Shapiraefed6642014-09-14 15:58:53 +03002558 mvmsta->agg_tids |= BIT(tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002559 tid_data->ssn = 0xffff;
Emmanuel Grumbachbb81bb62015-10-26 16:00:29 +02002560 tid_data->amsdu_in_ampdu_allowed = amsdu;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002561 spin_unlock_bh(&mvmsta->lock);
2562
Sara Sharon34e10862017-02-23 13:15:07 +02002563 if (iwl_mvm_has_new_tx_api(mvm)) {
2564 /*
Sara Sharon0ec9257b2017-10-16 09:45:10 +03002565 * If there is no queue for this tid, iwl_mvm_sta_tx_agg_start()
2566 * would have failed, so if we are here there is no need to
2567 * allocate a queue.
2568 * However, if aggregation size is different than the default
2569 * size, the scheduler should be reconfigured.
2570 * We cannot do this with the new TX API, so return unsupported
2571 * for now, until it will be offloaded to firmware..
2572 * Note that if SCD default value changes - this condition
2573 * should be updated as well.
Sara Sharon34e10862017-02-23 13:15:07 +02002574 */
Sara Sharon0ec9257b2017-10-16 09:45:10 +03002575 if (buf_size < IWL_FRAME_LIMIT)
Sara Sharon34e10862017-02-23 13:15:07 +02002576 return -ENOTSUPP;
2577
2578 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
2579 if (ret)
2580 return -EIO;
2581 goto out;
2582 }
2583
Emmanuel Grumbacheea76c32016-02-21 16:29:17 +02002584 cfg.fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
Johannes Berg8ca151b2013-01-24 14:25:36 +01002585
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02002586 spin_lock_bh(&mvm->queue_info_lock);
2587 queue_status = mvm->queue_info[queue].status;
2588 spin_unlock_bh(&mvm->queue_info_lock);
2589
Johannes Bergc8f54702017-06-19 23:50:31 +02002590 /* Maybe there is no need to even alloc a queue... */
2591 if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_READY)
2592 alloc_queue = false;
Liad Kaufmancf961e12015-08-13 19:16:08 +03002593
Johannes Bergc8f54702017-06-19 23:50:31 +02002594 /*
2595 * Only reconfig the SCD for the queue if the window size has
2596 * changed from current (become smaller)
2597 */
Sara Sharon0ec9257b2017-10-16 09:45:10 +03002598 if (!alloc_queue && buf_size < IWL_FRAME_LIMIT) {
Liad Kaufmancf961e12015-08-13 19:16:08 +03002599 /*
Johannes Bergc8f54702017-06-19 23:50:31 +02002600 * If reconfiguring an existing queue, it first must be
2601 * drained
Liad Kaufmancf961e12015-08-13 19:16:08 +03002602 */
Johannes Bergc8f54702017-06-19 23:50:31 +02002603 ret = iwl_trans_wait_tx_queues_empty(mvm->trans,
2604 BIT(queue));
2605 if (ret) {
2606 IWL_ERR(mvm,
2607 "Error draining queue before reconfig\n");
2608 return ret;
2609 }
Liad Kaufmancf961e12015-08-13 19:16:08 +03002610
Johannes Bergc8f54702017-06-19 23:50:31 +02002611 ret = iwl_mvm_reconfig_scd(mvm, queue, cfg.fifo,
2612 mvmsta->sta_id, tid,
2613 buf_size, ssn);
2614 if (ret) {
2615 IWL_ERR(mvm,
2616 "Error reconfiguring TXQ #%d\n", queue);
2617 return ret;
Liad Kaufmancf961e12015-08-13 19:16:08 +03002618 }
2619 }
2620
2621 if (alloc_queue)
2622 iwl_mvm_enable_txq(mvm, queue,
2623 vif->hw_queue[tid_to_mac80211_ac[tid]], ssn,
2624 &cfg, wdg_timeout);
Andrei Otcheretianskifa7878e2015-05-05 09:28:16 +03002625
Liad Kaufman9f9af3d2015-12-23 16:03:46 +02002626 /* Send ADD_STA command to enable aggs only if the queue isn't shared */
2627 if (queue_status != IWL_MVM_QUEUE_SHARED) {
2628 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
2629 if (ret)
2630 return -EIO;
2631 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002632
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002633 /* No need to mark as reserved */
2634 spin_lock_bh(&mvm->queue_info_lock);
Liad Kaufmancf961e12015-08-13 19:16:08 +03002635 mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY;
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002636 spin_unlock_bh(&mvm->queue_info_lock);
2637
Sara Sharon34e10862017-02-23 13:15:07 +02002638out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002639 /*
2640 * Even though in theory the peer could have different
2641 * aggregation reorder buffer sizes for different sessions,
2642 * our ucode doesn't allow for that and has a global limit
2643 * for each station. Therefore, use the minimum of all the
2644 * aggregation sessions and our default value.
2645 */
2646 mvmsta->max_agg_bufsize =
2647 min(mvmsta->max_agg_bufsize, buf_size);
2648 mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize;
2649
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +03002650 IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n",
2651 sta->addr, tid);
2652
Eyal Shapira9e680942013-11-09 00:16:16 +02002653 return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002654}
2655
Sara Sharon34e10862017-02-23 13:15:07 +02002656static void iwl_mvm_unreserve_agg_queue(struct iwl_mvm *mvm,
2657 struct iwl_mvm_sta *mvmsta,
2658 u16 txq_id)
2659{
2660 if (iwl_mvm_has_new_tx_api(mvm))
2661 return;
2662
2663 spin_lock_bh(&mvm->queue_info_lock);
2664 /*
2665 * The TXQ is marked as reserved only if no traffic came through yet
2666 * This means no traffic has been sent on this TID (agg'd or not), so
2667 * we no longer have use for the queue. Since it hasn't even been
2668 * allocated through iwl_mvm_enable_txq, so we can just mark it back as
2669 * free.
2670 */
2671 if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED)
2672 mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE;
2673
2674 spin_unlock_bh(&mvm->queue_info_lock);
2675}
2676
Johannes Berg8ca151b2013-01-24 14:25:36 +01002677int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2678 struct ieee80211_sta *sta, u16 tid)
2679{
Johannes Berg5b577a92013-11-14 18:20:04 +01002680 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002681 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2682 u16 txq_id;
2683 int err;
2684
Emmanuel Grumbachf9aa8dd2013-03-04 09:11:08 +02002685 /*
2686 * If mac80211 is cleaning its state, then say that we finished since
2687 * our state has been cleared anyway.
2688 */
2689 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
2690 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2691 return 0;
2692 }
2693
Johannes Berg8ca151b2013-01-24 14:25:36 +01002694 spin_lock_bh(&mvmsta->lock);
2695
2696 txq_id = tid_data->txq_id;
2697
2698 IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n",
2699 mvmsta->sta_id, tid, txq_id, tid_data->state);
2700
Eyal Shapiraefed6642014-09-14 15:58:53 +03002701 mvmsta->agg_tids &= ~BIT(tid);
2702
Sara Sharon34e10862017-02-23 13:15:07 +02002703 iwl_mvm_unreserve_agg_queue(mvm, mvmsta, txq_id);
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002704
Johannes Berg8ca151b2013-01-24 14:25:36 +01002705 switch (tid_data->state) {
2706 case IWL_AGG_ON:
Johannes Berg9a886582013-02-15 19:25:00 +01002707 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002708
2709 IWL_DEBUG_TX_QUEUES(mvm,
2710 "ssn = %d, next_recl = %d\n",
2711 tid_data->ssn, tid_data->next_reclaimed);
2712
Johannes Berg8ca151b2013-01-24 14:25:36 +01002713 tid_data->ssn = 0xffff;
Johannes Bergf7f89e72014-08-05 15:24:44 +02002714 tid_data->state = IWL_AGG_OFF;
Johannes Bergf7f89e72014-08-05 15:24:44 +02002715 spin_unlock_bh(&mvmsta->lock);
2716
2717 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2718
2719 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
Johannes Bergf7f89e72014-08-05 15:24:44 +02002720 return 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002721 case IWL_AGG_STARTING:
2722 case IWL_EMPTYING_HW_QUEUE_ADDBA:
2723 /*
2724 * The agg session has been stopped before it was set up. This
2725 * can happen when the AddBA timer times out for example.
2726 */
2727
2728 /* No barriers since we are under mutex */
2729 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002730
2731 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
2732 tid_data->state = IWL_AGG_OFF;
2733 err = 0;
2734 break;
2735 default:
2736 IWL_ERR(mvm,
2737 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
2738 mvmsta->sta_id, tid, tid_data->state);
2739 IWL_ERR(mvm,
2740 "\ttid_data->txq_id = %d\n", tid_data->txq_id);
2741 err = -EINVAL;
2742 }
2743
2744 spin_unlock_bh(&mvmsta->lock);
2745
2746 return err;
2747}
2748
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02002749int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
2750 struct ieee80211_sta *sta, u16 tid)
2751{
Johannes Berg5b577a92013-11-14 18:20:04 +01002752 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02002753 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
2754 u16 txq_id;
Johannes Bergb6658ff2013-07-24 13:55:51 +02002755 enum iwl_mvm_agg_state old_state;
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02002756
2757 /*
2758 * First set the agg state to OFF to avoid calling
2759 * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
2760 */
2761 spin_lock_bh(&mvmsta->lock);
2762 txq_id = tid_data->txq_id;
2763 IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n",
2764 mvmsta->sta_id, tid, txq_id, tid_data->state);
Johannes Bergb6658ff2013-07-24 13:55:51 +02002765 old_state = tid_data->state;
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02002766 tid_data->state = IWL_AGG_OFF;
Eyal Shapiraefed6642014-09-14 15:58:53 +03002767 mvmsta->agg_tids &= ~BIT(tid);
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02002768 spin_unlock_bh(&mvmsta->lock);
2769
Sara Sharon34e10862017-02-23 13:15:07 +02002770 iwl_mvm_unreserve_agg_queue(mvm, mvmsta, txq_id);
Liad Kaufman4ecafae2015-07-14 13:36:18 +03002771
Johannes Bergb6658ff2013-07-24 13:55:51 +02002772 if (old_state >= IWL_AGG_ON) {
Emmanuel Grumbachfe92e322015-03-11 09:34:31 +02002773 iwl_mvm_drain_sta(mvm, mvmsta, true);
Sara Sharond6d517b2017-03-06 10:16:11 +02002774
Mordechai Goodsteind167e812017-05-10 16:42:53 +03002775 if (iwl_mvm_has_new_tx_api(mvm)) {
2776 if (iwl_mvm_flush_sta_tids(mvm, mvmsta->sta_id,
2777 BIT(tid), 0))
2778 IWL_ERR(mvm, "Couldn't flush the AGG queue\n");
Sara Sharond6d517b2017-03-06 10:16:11 +02002779 iwl_trans_wait_txq_empty(mvm->trans, txq_id);
Mordechai Goodsteind167e812017-05-10 16:42:53 +03002780 } else {
2781 if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0))
2782 IWL_ERR(mvm, "Couldn't flush the AGG queue\n");
Sara Sharond6d517b2017-03-06 10:16:11 +02002783 iwl_trans_wait_tx_queues_empty(mvm->trans, BIT(txq_id));
Mordechai Goodsteind167e812017-05-10 16:42:53 +03002784 }
Sara Sharond6d517b2017-03-06 10:16:11 +02002785
Emmanuel Grumbachfe92e322015-03-11 09:34:31 +02002786 iwl_mvm_drain_sta(mvm, mvmsta, false);
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02002787
Johannes Bergf7f89e72014-08-05 15:24:44 +02002788 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
Johannes Bergb6658ff2013-07-24 13:55:51 +02002789 }
2790
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02002791 return 0;
2792}
2793
Johannes Berg8ca151b2013-01-24 14:25:36 +01002794static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm)
2795{
Johannes Berg2dc2a152015-06-16 17:09:18 +02002796 int i, max = -1, max_offs = -1;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002797
2798 lockdep_assert_held(&mvm->mutex);
2799
Johannes Berg2dc2a152015-06-16 17:09:18 +02002800 /* Pick the unused key offset with the highest 'deleted'
2801 * counter. Every time a key is deleted, all the counters
2802 * are incremented and the one that was just deleted is
2803 * reset to zero. Thus, the highest counter is the one
2804 * that was deleted longest ago. Pick that one.
2805 */
2806 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
2807 if (test_bit(i, mvm->fw_key_table))
2808 continue;
2809 if (mvm->fw_key_deleted[i] > max) {
2810 max = mvm->fw_key_deleted[i];
2811 max_offs = i;
2812 }
2813 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002814
Johannes Berg2dc2a152015-06-16 17:09:18 +02002815 if (max_offs < 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002816 return STA_KEY_IDX_INVALID;
2817
Johannes Berg2dc2a152015-06-16 17:09:18 +02002818 return max_offs;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002819}
2820
Johannes Berg5f7a1842015-12-11 09:36:10 +01002821static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm,
2822 struct ieee80211_vif *vif,
2823 struct ieee80211_sta *sta)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002824{
Johannes Berg5b530e92014-12-23 16:00:17 +01002825 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002826
Johannes Berg5f7a1842015-12-11 09:36:10 +01002827 if (sta)
2828 return iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002829
2830 /*
2831 * The device expects GTKs for station interfaces to be
2832 * installed as GTKs for the AP station. If we have no
2833 * station ID, then use AP's station ID.
2834 */
2835 if (vif->type == NL80211_IFTYPE_STATION &&
Sara Sharon0ae98812017-01-04 14:53:58 +02002836 mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
Avri Altman9513c5e2015-10-19 16:29:11 +02002837 u8 sta_id = mvmvif->ap_sta_id;
2838
Emmanuel Grumbach7d6a1ab2016-05-15 10:20:29 +03002839 sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id],
2840 lockdep_is_held(&mvm->mutex));
2841
Avri Altman9513c5e2015-10-19 16:29:11 +02002842 /*
2843 * It is possible that the 'sta' parameter is NULL,
2844 * for example when a GTK is removed - the sta_id will then
2845 * be the AP ID, and no station was passed by mac80211.
2846 */
Emmanuel Grumbach7d6a1ab2016-05-15 10:20:29 +03002847 if (IS_ERR_OR_NULL(sta))
2848 return NULL;
2849
2850 return iwl_mvm_sta_from_mac80211(sta);
Avri Altman9513c5e2015-10-19 16:29:11 +02002851 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002852
Johannes Berg5f7a1842015-12-11 09:36:10 +01002853 return NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002854}
2855
2856static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm,
David Spinadel85aeb582017-03-30 19:43:53 +03002857 u32 sta_id,
Sara Sharon45c458b2016-11-09 15:43:26 +02002858 struct ieee80211_key_conf *key, bool mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02002859 u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags,
2860 u8 key_offset)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002861{
Sara Sharon45c458b2016-11-09 15:43:26 +02002862 union {
2863 struct iwl_mvm_add_sta_key_cmd_v1 cmd_v1;
2864 struct iwl_mvm_add_sta_key_cmd cmd;
2865 } u = {};
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03002866 __le16 key_flags;
Johannes Berg79920742014-11-03 15:43:04 +01002867 int ret;
2868 u32 status;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002869 u16 keyidx;
Sara Sharon45c458b2016-11-09 15:43:26 +02002870 u64 pn = 0;
2871 int i, size;
2872 bool new_api = fw_has_api(&mvm->fw->ucode_capa,
2873 IWL_UCODE_TLV_API_TKIP_MIC_KEYS);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002874
David Spinadel85aeb582017-03-30 19:43:53 +03002875 if (sta_id == IWL_MVM_INVALID_STA)
2876 return -EINVAL;
2877
Sara Sharon45c458b2016-11-09 15:43:26 +02002878 keyidx = (key->keyidx << STA_KEY_FLG_KEYID_POS) &
Johannes Berg8ca151b2013-01-24 14:25:36 +01002879 STA_KEY_FLG_KEYID_MSK;
2880 key_flags = cpu_to_le16(keyidx);
2881 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP);
2882
Sara Sharon45c458b2016-11-09 15:43:26 +02002883 switch (key->cipher) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01002884 case WLAN_CIPHER_SUITE_TKIP:
2885 key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP);
Sara Sharon45c458b2016-11-09 15:43:26 +02002886 if (new_api) {
2887 memcpy((void *)&u.cmd.tx_mic_key,
2888 &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
2889 IWL_MIC_KEY_SIZE);
2890
2891 memcpy((void *)&u.cmd.rx_mic_key,
2892 &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
2893 IWL_MIC_KEY_SIZE);
2894 pn = atomic64_read(&key->tx_pn);
2895
2896 } else {
2897 u.cmd_v1.tkip_rx_tsc_byte2 = tkip_iv32;
2898 for (i = 0; i < 5; i++)
2899 u.cmd_v1.tkip_rx_ttak[i] =
2900 cpu_to_le16(tkip_p1k[i]);
2901 }
2902 memcpy(u.cmd.common.key, key->key, key->keylen);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002903 break;
2904 case WLAN_CIPHER_SUITE_CCMP:
2905 key_flags |= cpu_to_le16(STA_KEY_FLG_CCM);
Sara Sharon45c458b2016-11-09 15:43:26 +02002906 memcpy(u.cmd.common.key, key->key, key->keylen);
2907 if (new_api)
2908 pn = atomic64_read(&key->tx_pn);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002909 break;
Johannes Bergba3943b2014-11-12 23:54:48 +01002910 case WLAN_CIPHER_SUITE_WEP104:
2911 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES);
John W. Linvilleaa0cb082015-01-12 16:18:11 -05002912 /* fall through */
Johannes Bergba3943b2014-11-12 23:54:48 +01002913 case WLAN_CIPHER_SUITE_WEP40:
2914 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP);
Sara Sharon45c458b2016-11-09 15:43:26 +02002915 memcpy(u.cmd.common.key + 3, key->key, key->keylen);
Johannes Bergba3943b2014-11-12 23:54:48 +01002916 break;
Ayala Beker2a53d162016-04-07 16:21:57 +03002917 case WLAN_CIPHER_SUITE_GCMP_256:
2918 key_flags |= cpu_to_le16(STA_KEY_FLG_KEY_32BYTES);
2919 /* fall through */
2920 case WLAN_CIPHER_SUITE_GCMP:
2921 key_flags |= cpu_to_le16(STA_KEY_FLG_GCMP);
Sara Sharon45c458b2016-11-09 15:43:26 +02002922 memcpy(u.cmd.common.key, key->key, key->keylen);
2923 if (new_api)
2924 pn = atomic64_read(&key->tx_pn);
Ayala Beker2a53d162016-04-07 16:21:57 +03002925 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002926 default:
Max Stepanove36e5432013-08-27 19:56:13 +03002927 key_flags |= cpu_to_le16(STA_KEY_FLG_EXT);
Sara Sharon45c458b2016-11-09 15:43:26 +02002928 memcpy(u.cmd.common.key, key->key, key->keylen);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002929 }
2930
Johannes Bergba3943b2014-11-12 23:54:48 +01002931 if (mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002932 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
2933
Sara Sharon45c458b2016-11-09 15:43:26 +02002934 u.cmd.common.key_offset = key_offset;
2935 u.cmd.common.key_flags = key_flags;
David Spinadel85aeb582017-03-30 19:43:53 +03002936 u.cmd.common.sta_id = sta_id;
Sara Sharon45c458b2016-11-09 15:43:26 +02002937
2938 if (new_api) {
2939 u.cmd.transmit_seq_cnt = cpu_to_le64(pn);
2940 size = sizeof(u.cmd);
2941 } else {
2942 size = sizeof(u.cmd_v1);
2943 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002944
2945 status = ADD_STA_SUCCESS;
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002946 if (cmd_flags & CMD_ASYNC)
Sara Sharon45c458b2016-11-09 15:43:26 +02002947 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC, size,
2948 &u.cmd);
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03002949 else
Sara Sharon45c458b2016-11-09 15:43:26 +02002950 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, size,
2951 &u.cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002952
2953 switch (status) {
2954 case ADD_STA_SUCCESS:
2955 IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n");
2956 break;
2957 default:
2958 ret = -EIO;
2959 IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n");
2960 break;
2961 }
2962
2963 return ret;
2964}
2965
2966static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm,
2967 struct ieee80211_key_conf *keyconf,
2968 u8 sta_id, bool remove_key)
2969{
2970 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {};
2971
2972 /* verify the key details match the required command's expectations */
Ayala Beker8e160ab2016-04-11 11:37:38 +03002973 if (WARN_ON((keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) ||
2974 (keyconf->keyidx != 4 && keyconf->keyidx != 5) ||
2975 (keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC &&
2976 keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_128 &&
2977 keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_256)))
2978 return -EINVAL;
2979
2980 if (WARN_ON(!iwl_mvm_has_new_rx_api(mvm) &&
2981 keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC))
Johannes Berg8ca151b2013-01-24 14:25:36 +01002982 return -EINVAL;
2983
2984 igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx);
2985 igtk_cmd.sta_id = cpu_to_le32(sta_id);
2986
2987 if (remove_key) {
2988 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID);
2989 } else {
2990 struct ieee80211_key_seq seq;
2991 const u8 *pn;
2992
Ayala Bekeraa950522016-06-01 00:28:09 +03002993 switch (keyconf->cipher) {
2994 case WLAN_CIPHER_SUITE_AES_CMAC:
2995 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_CCM);
2996 break;
Ayala Beker8e160ab2016-04-11 11:37:38 +03002997 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
2998 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
2999 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_GCMP);
3000 break;
Ayala Bekeraa950522016-06-01 00:28:09 +03003001 default:
3002 return -EINVAL;
3003 }
3004
Ayala Beker8e160ab2016-04-11 11:37:38 +03003005 memcpy(igtk_cmd.igtk, keyconf->key, keyconf->keylen);
3006 if (keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)
3007 igtk_cmd.ctrl_flags |=
3008 cpu_to_le32(STA_KEY_FLG_KEY_32BYTES);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003009 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
3010 pn = seq.aes_cmac.pn;
3011 igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) |
3012 ((u64) pn[4] << 8) |
3013 ((u64) pn[3] << 16) |
3014 ((u64) pn[2] << 24) |
3015 ((u64) pn[1] << 32) |
3016 ((u64) pn[0] << 40));
3017 }
3018
3019 IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n",
3020 remove_key ? "removing" : "installing",
3021 igtk_cmd.sta_id);
3022
Ayala Beker8e160ab2016-04-11 11:37:38 +03003023 if (!iwl_mvm_has_new_rx_api(mvm)) {
3024 struct iwl_mvm_mgmt_mcast_key_cmd_v1 igtk_cmd_v1 = {
3025 .ctrl_flags = igtk_cmd.ctrl_flags,
3026 .key_id = igtk_cmd.key_id,
3027 .sta_id = igtk_cmd.sta_id,
3028 .receive_seq_cnt = igtk_cmd.receive_seq_cnt
3029 };
3030
3031 memcpy(igtk_cmd_v1.igtk, igtk_cmd.igtk,
3032 ARRAY_SIZE(igtk_cmd_v1.igtk));
3033 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
3034 sizeof(igtk_cmd_v1), &igtk_cmd_v1);
3035 }
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03003036 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003037 sizeof(igtk_cmd), &igtk_cmd);
3038}
3039
3040
3041static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm,
3042 struct ieee80211_vif *vif,
3043 struct ieee80211_sta *sta)
3044{
Johannes Berg5b530e92014-12-23 16:00:17 +01003045 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003046
3047 if (sta)
3048 return sta->addr;
3049
3050 if (vif->type == NL80211_IFTYPE_STATION &&
Sara Sharon0ae98812017-01-04 14:53:58 +02003051 mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01003052 u8 sta_id = mvmvif->ap_sta_id;
3053 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
3054 lockdep_is_held(&mvm->mutex));
3055 return sta->addr;
3056 }
3057
3058
3059 return NULL;
3060}
3061
Johannes Berg2f6319d2014-11-12 23:39:56 +01003062static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
3063 struct ieee80211_vif *vif,
3064 struct ieee80211_sta *sta,
Johannes Bergba3943b2014-11-12 23:54:48 +01003065 struct ieee80211_key_conf *keyconf,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02003066 u8 key_offset,
Johannes Bergba3943b2014-11-12 23:54:48 +01003067 bool mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003068{
Johannes Berg8ca151b2013-01-24 14:25:36 +01003069 int ret;
Johannes Berg2f6319d2014-11-12 23:39:56 +01003070 const u8 *addr;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003071 struct ieee80211_key_seq seq;
3072 u16 p1k[5];
David Spinadel85aeb582017-03-30 19:43:53 +03003073 u32 sta_id;
3074
3075 if (sta) {
3076 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3077
3078 sta_id = mvm_sta->sta_id;
3079 } else if (vif->type == NL80211_IFTYPE_AP &&
3080 !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
3081 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3082
3083 sta_id = mvmvif->mcast_sta.sta_id;
3084 } else {
3085 IWL_ERR(mvm, "Failed to find station id\n");
3086 return -EINVAL;
3087 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01003088
Johannes Berg8ca151b2013-01-24 14:25:36 +01003089 switch (keyconf->cipher) {
3090 case WLAN_CIPHER_SUITE_TKIP:
David Spinadel85aeb582017-03-30 19:43:53 +03003091 if (vif->type == NL80211_IFTYPE_AP) {
3092 ret = -EINVAL;
3093 break;
3094 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01003095 addr = iwl_mvm_get_mac_addr(mvm, vif, sta);
3096 /* get phase 1 key from mac80211 */
3097 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
3098 ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k);
David Spinadel85aeb582017-03-30 19:43:53 +03003099 ret = iwl_mvm_send_sta_key(mvm, sta_id, keyconf, mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02003100 seq.tkip.iv32, p1k, 0, key_offset);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003101 break;
3102 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergba3943b2014-11-12 23:54:48 +01003103 case WLAN_CIPHER_SUITE_WEP40:
3104 case WLAN_CIPHER_SUITE_WEP104:
Ayala Beker2a53d162016-04-07 16:21:57 +03003105 case WLAN_CIPHER_SUITE_GCMP:
3106 case WLAN_CIPHER_SUITE_GCMP_256:
David Spinadel85aeb582017-03-30 19:43:53 +03003107 ret = iwl_mvm_send_sta_key(mvm, sta_id, keyconf, mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02003108 0, NULL, 0, key_offset);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003109 break;
3110 default:
David Spinadel85aeb582017-03-30 19:43:53 +03003111 ret = iwl_mvm_send_sta_key(mvm, sta_id, keyconf, mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02003112 0, NULL, 0, key_offset);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003113 }
3114
Johannes Berg8ca151b2013-01-24 14:25:36 +01003115 return ret;
3116}
3117
Johannes Berg2f6319d2014-11-12 23:39:56 +01003118static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id,
Johannes Bergba3943b2014-11-12 23:54:48 +01003119 struct ieee80211_key_conf *keyconf,
3120 bool mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003121{
Sara Sharon45c458b2016-11-09 15:43:26 +02003122 union {
3123 struct iwl_mvm_add_sta_key_cmd_v1 cmd_v1;
3124 struct iwl_mvm_add_sta_key_cmd cmd;
3125 } u = {};
3126 bool new_api = fw_has_api(&mvm->fw->ucode_capa,
3127 IWL_UCODE_TLV_API_TKIP_MIC_KEYS);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003128 __le16 key_flags;
Sara Sharon45c458b2016-11-09 15:43:26 +02003129 int ret, size;
Johannes Berg79920742014-11-03 15:43:04 +01003130 u32 status;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003131
David Spinadel85aeb582017-03-30 19:43:53 +03003132 if (sta_id == IWL_MVM_INVALID_STA)
3133 return -EINVAL;
3134
Emmanuel Grumbach8115efb2013-02-05 10:08:35 +02003135 key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
3136 STA_KEY_FLG_KEYID_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003137 key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP);
3138 key_flags |= cpu_to_le16(STA_KEY_NOT_VALID);
3139
Johannes Bergba3943b2014-11-12 23:54:48 +01003140 if (mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003141 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
3142
Sara Sharon45c458b2016-11-09 15:43:26 +02003143 /*
3144 * The fields assigned here are in the same location at the start
3145 * of the command, so we can do this union trick.
3146 */
3147 u.cmd.common.key_flags = key_flags;
3148 u.cmd.common.key_offset = keyconf->hw_key_idx;
3149 u.cmd.common.sta_id = sta_id;
3150
3151 size = new_api ? sizeof(u.cmd) : sizeof(u.cmd_v1);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003152
Johannes Berg8ca151b2013-01-24 14:25:36 +01003153 status = ADD_STA_SUCCESS;
Sara Sharon45c458b2016-11-09 15:43:26 +02003154 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, size, &u.cmd,
3155 &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003156
3157 switch (status) {
3158 case ADD_STA_SUCCESS:
3159 IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n");
3160 break;
3161 default:
3162 ret = -EIO;
3163 IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n");
3164 break;
3165 }
3166
3167 return ret;
3168}
3169
Johannes Berg2f6319d2014-11-12 23:39:56 +01003170int iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
3171 struct ieee80211_vif *vif,
3172 struct ieee80211_sta *sta,
3173 struct ieee80211_key_conf *keyconf,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02003174 u8 key_offset)
Johannes Berg2f6319d2014-11-12 23:39:56 +01003175{
Johannes Bergba3943b2014-11-12 23:54:48 +01003176 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
Johannes Berg5f7a1842015-12-11 09:36:10 +01003177 struct iwl_mvm_sta *mvm_sta;
David Spinadel85aeb582017-03-30 19:43:53 +03003178 u8 sta_id = IWL_MVM_INVALID_STA;
Johannes Berg2f6319d2014-11-12 23:39:56 +01003179 int ret;
Matti Gottlieb11828db2015-06-01 15:15:11 +03003180 static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0};
Johannes Berg2f6319d2014-11-12 23:39:56 +01003181
3182 lockdep_assert_held(&mvm->mutex);
3183
David Spinadel85aeb582017-03-30 19:43:53 +03003184 if (vif->type != NL80211_IFTYPE_AP ||
3185 keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
3186 /* Get the station id from the mvm local station table */
3187 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
3188 if (!mvm_sta) {
3189 IWL_ERR(mvm, "Failed to find station\n");
Johannes Berg2f6319d2014-11-12 23:39:56 +01003190 return -EINVAL;
3191 }
David Spinadel85aeb582017-03-30 19:43:53 +03003192 sta_id = mvm_sta->sta_id;
Johannes Berg2f6319d2014-11-12 23:39:56 +01003193
David Spinadel85aeb582017-03-30 19:43:53 +03003194 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3195 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3196 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) {
3197 ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id,
3198 false);
3199 goto end;
3200 }
3201
3202 /*
3203 * It is possible that the 'sta' parameter is NULL, and thus
3204 * there is a need to retrieve the sta from the local station
3205 * table.
3206 */
3207 if (!sta) {
3208 sta = rcu_dereference_protected(
3209 mvm->fw_id_to_mac_id[sta_id],
3210 lockdep_is_held(&mvm->mutex));
3211 if (IS_ERR_OR_NULL(sta)) {
3212 IWL_ERR(mvm, "Invalid station id\n");
3213 return -EINVAL;
3214 }
3215 }
3216
3217 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif))
3218 return -EINVAL;
3219 }
Johannes Berg2f6319d2014-11-12 23:39:56 +01003220
Luca Coelhod6ee54a2015-11-10 22:13:43 +02003221 /* If the key_offset is not pre-assigned, we need to find a
3222 * new offset to use. In normal cases, the offset is not
3223 * pre-assigned, but during HW_RESTART we want to reuse the
3224 * same indices, so we pass them when this function is called.
3225 *
3226 * In D3 entry, we need to hardcoded the indices (because the
3227 * firmware hardcodes the PTK offset to 0). In this case, we
3228 * need to make sure we don't overwrite the hw_key_idx in the
3229 * keyconf structure, because otherwise we cannot configure
3230 * the original ones back when resuming.
3231 */
3232 if (key_offset == STA_KEY_IDX_INVALID) {
3233 key_offset = iwl_mvm_set_fw_key_idx(mvm);
3234 if (key_offset == STA_KEY_IDX_INVALID)
Johannes Berg2f6319d2014-11-12 23:39:56 +01003235 return -ENOSPC;
Luca Coelhod6ee54a2015-11-10 22:13:43 +02003236 keyconf->hw_key_idx = key_offset;
Johannes Berg2f6319d2014-11-12 23:39:56 +01003237 }
3238
Luca Coelhod6ee54a2015-11-10 22:13:43 +02003239 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, key_offset, mcast);
Luca Coelho9c3deeb2015-11-11 01:06:17 +02003240 if (ret)
Johannes Bergba3943b2014-11-12 23:54:48 +01003241 goto end;
Johannes Bergba3943b2014-11-12 23:54:48 +01003242
3243 /*
3244 * For WEP, the same key is used for multicast and unicast. Upload it
3245 * again, using the same key offset, and now pointing the other one
3246 * to the same key slot (offset).
3247 * If this fails, remove the original as well.
3248 */
David Spinadel85aeb582017-03-30 19:43:53 +03003249 if ((keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3250 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) &&
3251 sta) {
Luca Coelhod6ee54a2015-11-10 22:13:43 +02003252 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf,
3253 key_offset, !mcast);
Johannes Bergba3943b2014-11-12 23:54:48 +01003254 if (ret) {
Johannes Bergba3943b2014-11-12 23:54:48 +01003255 __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
Luca Coelho9c3deeb2015-11-11 01:06:17 +02003256 goto end;
Johannes Bergba3943b2014-11-12 23:54:48 +01003257 }
3258 }
Johannes Berg2f6319d2014-11-12 23:39:56 +01003259
Luca Coelho9c3deeb2015-11-11 01:06:17 +02003260 __set_bit(key_offset, mvm->fw_key_table);
3261
Johannes Berg2f6319d2014-11-12 23:39:56 +01003262end:
3263 IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
3264 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
Matti Gottlieb11828db2015-06-01 15:15:11 +03003265 sta ? sta->addr : zero_addr, ret);
Johannes Berg2f6319d2014-11-12 23:39:56 +01003266 return ret;
3267}
3268
3269int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm,
3270 struct ieee80211_vif *vif,
3271 struct ieee80211_sta *sta,
3272 struct ieee80211_key_conf *keyconf)
3273{
Johannes Bergba3943b2014-11-12 23:54:48 +01003274 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
Johannes Berg5f7a1842015-12-11 09:36:10 +01003275 struct iwl_mvm_sta *mvm_sta;
Sara Sharon0ae98812017-01-04 14:53:58 +02003276 u8 sta_id = IWL_MVM_INVALID_STA;
Johannes Berg2dc2a152015-06-16 17:09:18 +02003277 int ret, i;
Johannes Berg2f6319d2014-11-12 23:39:56 +01003278
3279 lockdep_assert_held(&mvm->mutex);
3280
Johannes Berg5f7a1842015-12-11 09:36:10 +01003281 /* Get the station from the mvm local station table */
3282 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
Luca Coelho71793b7d2017-03-30 12:04:47 +03003283 if (mvm_sta)
3284 sta_id = mvm_sta->sta_id;
David Spinadel85aeb582017-03-30 19:43:53 +03003285 else if (!sta && vif->type == NL80211_IFTYPE_AP && mcast)
3286 sta_id = iwl_mvm_vif_from_mac80211(vif)->mcast_sta.sta_id;
3287
Johannes Berg2f6319d2014-11-12 23:39:56 +01003288
3289 IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n",
3290 keyconf->keyidx, sta_id);
3291
Luca Coelho71793b7d2017-03-30 12:04:47 +03003292 if (mvm_sta && (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
3293 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
3294 keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256))
Johannes Berg2f6319d2014-11-12 23:39:56 +01003295 return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true);
3296
3297 if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) {
3298 IWL_ERR(mvm, "offset %d not used in fw key table.\n",
3299 keyconf->hw_key_idx);
3300 return -ENOENT;
3301 }
3302
Johannes Berg2dc2a152015-06-16 17:09:18 +02003303 /* track which key was deleted last */
3304 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
3305 if (mvm->fw_key_deleted[i] < U8_MAX)
3306 mvm->fw_key_deleted[i]++;
3307 }
3308 mvm->fw_key_deleted[keyconf->hw_key_idx] = 0;
3309
David Spinadel85aeb582017-03-30 19:43:53 +03003310 if (sta && !mvm_sta) {
Johannes Berg2f6319d2014-11-12 23:39:56 +01003311 IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n");
3312 return 0;
3313 }
3314
Johannes Bergba3943b2014-11-12 23:54:48 +01003315 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
3316 if (ret)
3317 return ret;
3318
3319 /* delete WEP key twice to get rid of (now useless) offset */
3320 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
3321 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104)
3322 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast);
3323
3324 return ret;
Johannes Berg2f6319d2014-11-12 23:39:56 +01003325}
3326
Johannes Berg8ca151b2013-01-24 14:25:36 +01003327void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm,
3328 struct ieee80211_vif *vif,
3329 struct ieee80211_key_conf *keyconf,
3330 struct ieee80211_sta *sta, u32 iv32,
3331 u16 *phase1key)
3332{
Beni Levc3eb5362013-02-06 17:22:18 +02003333 struct iwl_mvm_sta *mvm_sta;
Johannes Bergba3943b2014-11-12 23:54:48 +01003334 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003335
Beni Levc3eb5362013-02-06 17:22:18 +02003336 rcu_read_lock();
3337
Johannes Berg5f7a1842015-12-11 09:36:10 +01003338 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
3339 if (WARN_ON_ONCE(!mvm_sta))
Emmanuel Grumbach12f17212015-12-20 14:48:08 +02003340 goto unlock;
David Spinadel85aeb582017-03-30 19:43:53 +03003341 iwl_mvm_send_sta_key(mvm, mvm_sta->sta_id, keyconf, mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02003342 iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx);
Emmanuel Grumbach12f17212015-12-20 14:48:08 +02003343
3344 unlock:
Beni Levc3eb5362013-02-06 17:22:18 +02003345 rcu_read_unlock();
Johannes Berg8ca151b2013-01-24 14:25:36 +01003346}
3347
Johannes Berg9cc40712013-02-15 22:47:48 +01003348void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm,
3349 struct ieee80211_sta *sta)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003350{
Johannes Berg5b577a92013-11-14 18:20:04 +01003351 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03003352 struct iwl_mvm_add_sta_cmd cmd = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01003353 .add_modify = STA_MODE_MODIFY,
Johannes Berg9cc40712013-02-15 22:47:48 +01003354 .sta_id = mvmsta->sta_id,
Emmanuel Grumbach5af01772013-06-09 12:59:24 +03003355 .station_flags_msk = cpu_to_le32(STA_FLG_PS),
Johannes Berg9cc40712013-02-15 22:47:48 +01003356 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
Johannes Berg8ca151b2013-01-24 14:25:36 +01003357 };
3358 int ret;
3359
Sara Sharon854c5702016-01-26 13:17:47 +02003360 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
3361 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003362 if (ret)
3363 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3364}
3365
Johannes Berg9cc40712013-02-15 22:47:48 +01003366void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm,
3367 struct ieee80211_sta *sta,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003368 enum ieee80211_frame_release_type reason,
Johannes Berg3e56ead2013-02-15 22:23:18 +01003369 u16 cnt, u16 tids, bool more_data,
Sara Sharon9a3fcf92017-03-14 09:50:35 +02003370 bool single_sta_queue)
Johannes Berg8ca151b2013-01-24 14:25:36 +01003371{
Johannes Berg5b577a92013-11-14 18:20:04 +01003372 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03003373 struct iwl_mvm_add_sta_cmd cmd = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01003374 .add_modify = STA_MODE_MODIFY,
Johannes Berg9cc40712013-02-15 22:47:48 +01003375 .sta_id = mvmsta->sta_id,
Johannes Berg8ca151b2013-01-24 14:25:36 +01003376 .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT,
3377 .sleep_tx_count = cpu_to_le16(cnt),
Johannes Berg9cc40712013-02-15 22:47:48 +01003378 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
Johannes Berg8ca151b2013-01-24 14:25:36 +01003379 };
Johannes Berg3e56ead2013-02-15 22:23:18 +01003380 int tid, ret;
3381 unsigned long _tids = tids;
Johannes Berg8ca151b2013-01-24 14:25:36 +01003382
Johannes Berg3e56ead2013-02-15 22:23:18 +01003383 /* convert TIDs to ACs - we don't support TSPEC so that's OK
3384 * Note that this field is reserved and unused by firmware not
3385 * supporting GO uAPSD, so it's safe to always do this.
3386 */
3387 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT)
3388 cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]);
3389
Sara Sharon9a3fcf92017-03-14 09:50:35 +02003390 /* If we're releasing frames from aggregation or dqa queues then check
3391 * if all the queues that we're releasing frames from, combined, have:
Johannes Berg3e56ead2013-02-15 22:23:18 +01003392 * - more frames than the service period, in which case more_data
3393 * needs to be set
3394 * - fewer than 'cnt' frames, in which case we need to adjust the
3395 * firmware command (but do that unconditionally)
3396 */
Sara Sharon9a3fcf92017-03-14 09:50:35 +02003397 if (single_sta_queue) {
Johannes Berg3e56ead2013-02-15 22:23:18 +01003398 int remaining = cnt;
Emmanuel Grumbach36be0eb2015-11-05 10:32:31 +02003399 int sleep_tx_count;
Johannes Berg3e56ead2013-02-15 22:23:18 +01003400
3401 spin_lock_bh(&mvmsta->lock);
3402 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) {
3403 struct iwl_mvm_tid_data *tid_data;
3404 u16 n_queued;
3405
3406 tid_data = &mvmsta->tid_data[tid];
Johannes Berg3e56ead2013-02-15 22:23:18 +01003407
Liad Kaufmandd321622017-04-05 16:25:11 +03003408 n_queued = iwl_mvm_tid_queued(mvm, tid_data);
Johannes Berg3e56ead2013-02-15 22:23:18 +01003409 if (n_queued > remaining) {
3410 more_data = true;
3411 remaining = 0;
3412 break;
3413 }
3414 remaining -= n_queued;
3415 }
Emmanuel Grumbach36be0eb2015-11-05 10:32:31 +02003416 sleep_tx_count = cnt - remaining;
3417 if (reason == IEEE80211_FRAME_RELEASE_UAPSD)
3418 mvmsta->sleep_tx_count = sleep_tx_count;
Johannes Berg3e56ead2013-02-15 22:23:18 +01003419 spin_unlock_bh(&mvmsta->lock);
3420
Emmanuel Grumbach36be0eb2015-11-05 10:32:31 +02003421 cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count);
Johannes Berg3e56ead2013-02-15 22:23:18 +01003422 if (WARN_ON(cnt - remaining == 0)) {
3423 ieee80211_sta_eosp(sta);
3424 return;
3425 }
3426 }
3427
3428 /* Note: this is ignored by firmware not supporting GO uAPSD */
3429 if (more_data)
Sara Sharonced19f22017-02-06 19:09:32 +02003430 cmd.sleep_state_flags |= STA_SLEEP_STATE_MOREDATA;
Johannes Berg3e56ead2013-02-15 22:23:18 +01003431
3432 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) {
3433 mvmsta->next_status_eosp = true;
Sara Sharonced19f22017-02-06 19:09:32 +02003434 cmd.sleep_state_flags |= STA_SLEEP_STATE_PS_POLL;
Johannes Berg3e56ead2013-02-15 22:23:18 +01003435 } else {
Sara Sharonced19f22017-02-06 19:09:32 +02003436 cmd.sleep_state_flags |= STA_SLEEP_STATE_UAPSD;
Johannes Berg3e56ead2013-02-15 22:23:18 +01003437 }
3438
Emmanuel Grumbach156f92f2015-11-24 14:55:18 +02003439 /* block the Tx queues until the FW updated the sleep Tx count */
3440 iwl_trans_block_txq_ptrs(mvm->trans, true);
3441
3442 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA,
3443 CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK,
Sara Sharon854c5702016-01-26 13:17:47 +02003444 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +01003445 if (ret)
3446 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3447}
Johannes Berg3e56ead2013-02-15 22:23:18 +01003448
Johannes Berg04168412015-06-23 21:22:09 +02003449void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm,
3450 struct iwl_rx_cmd_buffer *rxb)
Johannes Berg3e56ead2013-02-15 22:23:18 +01003451{
3452 struct iwl_rx_packet *pkt = rxb_addr(rxb);
3453 struct iwl_mvm_eosp_notification *notif = (void *)pkt->data;
3454 struct ieee80211_sta *sta;
3455 u32 sta_id = le32_to_cpu(notif->sta_id);
3456
3457 if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT))
Johannes Berg04168412015-06-23 21:22:09 +02003458 return;
Johannes Berg3e56ead2013-02-15 22:23:18 +01003459
3460 rcu_read_lock();
3461 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
3462 if (!IS_ERR_OR_NULL(sta))
3463 ieee80211_sta_eosp(sta);
3464 rcu_read_unlock();
Johannes Berg3e56ead2013-02-15 22:23:18 +01003465}
Andrei Otcheretianski09b0ce12014-05-25 17:07:38 +03003466
3467void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm,
3468 struct iwl_mvm_sta *mvmsta, bool disable)
3469{
3470 struct iwl_mvm_add_sta_cmd cmd = {
3471 .add_modify = STA_MODE_MODIFY,
3472 .sta_id = mvmsta->sta_id,
3473 .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0,
3474 .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX),
3475 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
3476 };
3477 int ret;
3478
Sara Sharon854c5702016-01-26 13:17:47 +02003479 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
3480 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
Andrei Otcheretianski09b0ce12014-05-25 17:07:38 +03003481 if (ret)
3482 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3483}
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03003484
3485void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm,
3486 struct ieee80211_sta *sta,
3487 bool disable)
3488{
3489 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3490
3491 spin_lock_bh(&mvm_sta->lock);
3492
3493 if (mvm_sta->disable_tx == disable) {
3494 spin_unlock_bh(&mvm_sta->lock);
3495 return;
3496 }
3497
3498 mvm_sta->disable_tx = disable;
3499
Johannes Bergc8f54702017-06-19 23:50:31 +02003500 /* Tell mac80211 to start/stop queuing tx for this station */
3501 ieee80211_sta_block_awake(mvm->hw, sta, disable);
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03003502
3503 iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable);
3504
3505 spin_unlock_bh(&mvm_sta->lock);
3506}
3507
Sara Sharonced19f22017-02-06 19:09:32 +02003508static void iwl_mvm_int_sta_modify_disable_tx(struct iwl_mvm *mvm,
3509 struct iwl_mvm_vif *mvmvif,
3510 struct iwl_mvm_int_sta *sta,
3511 bool disable)
3512{
3513 u32 id = FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color);
3514 struct iwl_mvm_add_sta_cmd cmd = {
3515 .add_modify = STA_MODE_MODIFY,
3516 .sta_id = sta->sta_id,
3517 .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0,
3518 .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX),
3519 .mac_id_n_color = cpu_to_le32(id),
3520 };
3521 int ret;
3522
3523 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, 0,
3524 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
3525 if (ret)
3526 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
3527}
3528
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03003529void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm,
3530 struct iwl_mvm_vif *mvmvif,
3531 bool disable)
3532{
3533 struct ieee80211_sta *sta;
3534 struct iwl_mvm_sta *mvm_sta;
3535 int i;
3536
3537 lockdep_assert_held(&mvm->mutex);
3538
3539 /* Block/unblock all the stations of the given mvmvif */
Sara Sharon0ae98812017-01-04 14:53:58 +02003540 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) {
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03003541 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
3542 lockdep_is_held(&mvm->mutex));
3543 if (IS_ERR_OR_NULL(sta))
3544 continue;
3545
3546 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
3547 if (mvm_sta->mac_id_n_color !=
3548 FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color))
3549 continue;
3550
3551 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable);
3552 }
Sara Sharonced19f22017-02-06 19:09:32 +02003553
3554 if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
3555 return;
3556
3557 /* Need to block/unblock also multicast station */
3558 if (mvmvif->mcast_sta.sta_id != IWL_MVM_INVALID_STA)
3559 iwl_mvm_int_sta_modify_disable_tx(mvm, mvmvif,
3560 &mvmvif->mcast_sta, disable);
3561
3562 /*
3563 * Only unblock the broadcast station (FW blocks it for immediate
3564 * quiet, not the driver)
3565 */
3566 if (!disable && mvmvif->bcast_sta.sta_id != IWL_MVM_INVALID_STA)
3567 iwl_mvm_int_sta_modify_disable_tx(mvm, mvmvif,
3568 &mvmvif->bcast_sta, disable);
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03003569}
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02003570
3571void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
3572{
3573 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
3574 struct iwl_mvm_sta *mvmsta;
3575
3576 rcu_read_lock();
3577
3578 mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id);
3579
3580 if (!WARN_ON(!mvmsta))
3581 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true);
3582
3583 rcu_read_unlock();
3584}
Liad Kaufmandd321622017-04-05 16:25:11 +03003585
3586u16 iwl_mvm_tid_queued(struct iwl_mvm *mvm, struct iwl_mvm_tid_data *tid_data)
3587{
3588 u16 sn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
3589
3590 /*
3591 * In A000 HW, the next_reclaimed index is only 8 bit, so we'll need
3592 * to align the wrap around of ssn so we compare relevant values.
3593 */
3594 if (mvm->trans->cfg->gen2)
3595 sn &= 0xff;
3596
3597 return ieee80211_sn_sub(sn, tid_data->next_reclaimed);
3598}