blob: 3f36a661ec964134ff5f6ffc3fabaec4f0b13131 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
Andrei Otcheretianskifa7878e2015-05-05 09:28:16 +03008 * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved.
9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Sara Sharon854c5702016-01-26 13:17:47 +020010 * Copyright(c) 2016 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * USA
25 *
26 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020027 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010028 *
29 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020030 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg8ca151b2013-01-24 14:25:36 +010031 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
Andrei Otcheretianskifa7878e2015-05-05 09:28:16 +030035 * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved.
36 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Sara Sharon854c5702016-01-26 13:17:47 +020037 * Copyright(c) 2016 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010038 * All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 *
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * * Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in
48 * the documentation and/or other materials provided with the
49 * distribution.
50 * * Neither the name Intel Corporation nor the names of its
51 * contributors may be used to endorse or promote products derived
52 * from this software without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 *
66 *****************************************************************************/
67#include <net/mac80211.h>
68
69#include "mvm.h"
70#include "sta.h"
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +030071#include "rs.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010072
Sara Sharon854c5702016-01-26 13:17:47 +020073/*
74 * New version of ADD_STA_sta command added new fields at the end of the
75 * structure, so sending the size of the relevant API's structure is enough to
76 * support both API versions.
77 */
78static inline int iwl_mvm_add_sta_cmd_size(struct iwl_mvm *mvm)
79{
80 return iwl_mvm_has_new_rx_api(mvm) ?
81 sizeof(struct iwl_mvm_add_sta_cmd) :
82 sizeof(struct iwl_mvm_add_sta_cmd_v7);
83}
84
Eliad Pellerb92e6612014-01-23 17:58:23 +020085static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm,
86 enum nl80211_iftype iftype)
Johannes Berg8ca151b2013-01-24 14:25:36 +010087{
88 int sta_id;
Eliad Pellerb92e6612014-01-23 17:58:23 +020089 u32 reserved_ids = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +010090
Eliad Pellerb92e6612014-01-23 17:58:23 +020091 BUILD_BUG_ON(IWL_MVM_STATION_COUNT > 32);
Johannes Berg8ca151b2013-01-24 14:25:36 +010092 WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status));
93
94 lockdep_assert_held(&mvm->mutex);
95
Eliad Pellerb92e6612014-01-23 17:58:23 +020096 /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */
97 if (iftype != NL80211_IFTYPE_STATION)
98 reserved_ids = BIT(0);
99
Johannes Berg8ca151b2013-01-24 14:25:36 +0100100 /* Don't take rcu_read_lock() since we are protected by mvm->mutex */
Eliad Pellerb92e6612014-01-23 17:58:23 +0200101 for (sta_id = 0; sta_id < IWL_MVM_STATION_COUNT; sta_id++) {
102 if (BIT(sta_id) & reserved_ids)
103 continue;
104
Johannes Berg8ca151b2013-01-24 14:25:36 +0100105 if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
106 lockdep_is_held(&mvm->mutex)))
107 return sta_id;
Eliad Pellerb92e6612014-01-23 17:58:23 +0200108 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100109 return IWL_MVM_STATION_COUNT;
110}
111
Johannes Berg7a453972013-02-12 13:10:44 +0100112/* send station add/update command to firmware */
113int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
Liad Kaufman24afba72015-07-28 18:56:08 +0300114 bool update, unsigned int flags)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100115{
Johannes Berg9d8ce6a2014-12-23 16:02:40 +0100116 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbach4b8265a2014-07-13 08:58:04 +0300117 struct iwl_mvm_add_sta_cmd add_sta_cmd = {
118 .sta_id = mvm_sta->sta_id,
119 .mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color),
120 .add_modify = update ? 1 : 0,
121 .station_flags_msk = cpu_to_le32(STA_FLG_FAT_EN_MSK |
122 STA_FLG_MIMO_EN_MSK),
Liad Kaufmancf0cda12015-09-24 10:44:12 +0200123 .tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg),
Emmanuel Grumbach4b8265a2014-07-13 08:58:04 +0300124 };
Johannes Berg8ca151b2013-01-24 14:25:36 +0100125 int ret;
126 u32 status;
127 u32 agg_size = 0, mpdu_dens = 0;
128
Liad Kaufman24afba72015-07-28 18:56:08 +0300129 if (!update || (flags & STA_MODIFY_QUEUES)) {
Johannes Berg7a453972013-02-12 13:10:44 +0100130 add_sta_cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk);
131 memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN);
Liad Kaufman24afba72015-07-28 18:56:08 +0300132
133 if (flags & STA_MODIFY_QUEUES)
134 add_sta_cmd.modify_mask |= STA_MODIFY_QUEUES;
Johannes Berg7a453972013-02-12 13:10:44 +0100135 }
Johannes Berg5bc5aaa2013-02-12 14:35:36 +0100136
137 switch (sta->bandwidth) {
138 case IEEE80211_STA_RX_BW_160:
139 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_160MHZ);
140 /* fall through */
141 case IEEE80211_STA_RX_BW_80:
142 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_80MHZ);
143 /* fall through */
144 case IEEE80211_STA_RX_BW_40:
145 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_40MHZ);
146 /* fall through */
147 case IEEE80211_STA_RX_BW_20:
148 if (sta->ht_cap.ht_supported)
149 add_sta_cmd.station_flags |=
150 cpu_to_le32(STA_FLG_FAT_EN_20MHZ);
151 break;
152 }
153
154 switch (sta->rx_nss) {
155 case 1:
156 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO);
157 break;
158 case 2:
159 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2);
160 break;
161 case 3 ... 8:
162 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3);
163 break;
164 }
165
166 switch (sta->smps_mode) {
167 case IEEE80211_SMPS_AUTOMATIC:
168 case IEEE80211_SMPS_NUM_MODES:
169 WARN_ON(1);
170 break;
171 case IEEE80211_SMPS_STATIC:
172 /* override NSS */
173 add_sta_cmd.station_flags &= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK);
174 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO);
175 break;
176 case IEEE80211_SMPS_DYNAMIC:
177 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_RTS_MIMO_PROT);
178 break;
179 case IEEE80211_SMPS_OFF:
180 /* nothing */
181 break;
182 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100183
184 if (sta->ht_cap.ht_supported) {
185 add_sta_cmd.station_flags_msk |=
186 cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK |
187 STA_FLG_AGG_MPDU_DENS_MSK);
188
189 mpdu_dens = sta->ht_cap.ampdu_density;
190 }
191
192 if (sta->vht_cap.vht_supported) {
193 agg_size = sta->vht_cap.cap &
194 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
195 agg_size >>=
196 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
197 } else if (sta->ht_cap.ht_supported) {
198 agg_size = sta->ht_cap.ampdu_factor;
199 }
200
201 add_sta_cmd.station_flags |=
202 cpu_to_le32(agg_size << STA_FLG_MAX_AGG_SIZE_SHIFT);
203 add_sta_cmd.station_flags |=
204 cpu_to_le32(mpdu_dens << STA_FLG_AGG_MPDU_DENS_SHIFT);
205
206 status = ADD_STA_SUCCESS;
Sara Sharon854c5702016-01-26 13:17:47 +0200207 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
208 iwl_mvm_add_sta_cmd_size(mvm),
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300209 &add_sta_cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100210 if (ret)
211 return ret;
212
Sara Sharon837c4da2016-01-07 16:50:45 +0200213 switch (status & IWL_ADD_STA_STATUS_MASK) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100214 case ADD_STA_SUCCESS:
215 IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n");
216 break;
217 default:
218 ret = -EIO;
219 IWL_ERR(mvm, "ADD_STA failed\n");
220 break;
221 }
222
223 return ret;
224}
225
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300226static int iwl_mvm_tdls_sta_init(struct iwl_mvm *mvm,
227 struct ieee80211_sta *sta)
228{
229 unsigned long used_hw_queues;
230 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbach5d42e7b2015-03-19 20:04:51 +0200231 unsigned int wdg_timeout =
232 iwl_mvm_get_wd_timeout(mvm, NULL, true, false);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300233 u32 ac;
234
235 lockdep_assert_held(&mvm->mutex);
236
237 used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, NULL);
238
239 /* Find available queues, and allocate them to the ACs */
240 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
241 u8 queue = find_first_zero_bit(&used_hw_queues,
242 mvm->first_agg_queue);
243
244 if (queue >= mvm->first_agg_queue) {
245 IWL_ERR(mvm, "Failed to allocate STA queue\n");
246 return -EBUSY;
247 }
248
249 __set_bit(queue, &used_hw_queues);
250 mvmsta->hw_queue[ac] = queue;
251 }
252
253 /* Found a place for all queues - enable them */
254 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
255 iwl_mvm_enable_ac_txq(mvm, mvmsta->hw_queue[ac],
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300256 mvmsta->hw_queue[ac],
Liad Kaufman5c1156e2015-07-22 17:59:53 +0300257 iwl_mvm_ac_to_tx_fifo[ac], 0,
258 wdg_timeout);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300259 mvmsta->tfd_queue_msk |= BIT(mvmsta->hw_queue[ac]);
260 }
261
262 return 0;
263}
264
265static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm *mvm,
266 struct ieee80211_sta *sta)
267{
268 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
269 unsigned long sta_msk;
270 int i;
271
272 lockdep_assert_held(&mvm->mutex);
273
274 /* disable the TDLS STA-specific queues */
275 sta_msk = mvmsta->tfd_queue_msk;
Emmanuel Grumbacha4ca3ed2015-01-20 17:07:10 +0200276 for_each_set_bit(i, &sta_msk, sizeof(sta_msk) * BITS_PER_BYTE)
Arik Nemtsov06ecdba2015-10-12 14:47:11 +0300277 iwl_mvm_disable_txq(mvm, i, i, IWL_MAX_TID_COUNT, 0);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300278}
279
Liad Kaufman24afba72015-07-28 18:56:08 +0300280static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm,
281 struct ieee80211_sta *sta, u8 ac, int tid,
282 struct ieee80211_hdr *hdr)
283{
284 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
285 struct iwl_trans_txq_scd_cfg cfg = {
286 .fifo = iwl_mvm_ac_to_tx_fifo[ac],
287 .sta_id = mvmsta->sta_id,
288 .tid = tid,
289 .frame_limit = IWL_FRAME_LIMIT,
290 };
291 unsigned int wdg_timeout =
292 iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false);
293 u8 mac_queue = mvmsta->vif->hw_queue[ac];
294 int queue = -1;
295 int ssn;
296
297 lockdep_assert_held(&mvm->mutex);
298
299 spin_lock(&mvm->queue_info_lock);
300
301 /*
302 * Non-QoS, QoS NDP and MGMT frames should go to a MGMT queue, if one
303 * exists
304 */
305 if (!ieee80211_is_data_qos(hdr->frame_control) ||
306 ieee80211_is_qos_nullfunc(hdr->frame_control)) {
307 queue = iwl_mvm_find_free_queue(mvm, IWL_MVM_DQA_MIN_MGMT_QUEUE,
308 IWL_MVM_DQA_MAX_MGMT_QUEUE);
309 if (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE)
310 IWL_DEBUG_TX_QUEUES(mvm, "Found free MGMT queue #%d\n",
311 queue);
312
313 /* If no such queue is found, we'll use a DATA queue instead */
314 }
315
316 if (queue < 0 && mvmsta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) {
317 queue = mvmsta->reserved_queue;
318 IWL_DEBUG_TX_QUEUES(mvm, "Using reserved queue #%d\n", queue);
319 }
320
321 if (queue < 0)
322 queue = iwl_mvm_find_free_queue(mvm, IWL_MVM_DQA_MIN_DATA_QUEUE,
323 IWL_MVM_DQA_MAX_DATA_QUEUE);
324 if (queue >= 0)
325 mvm->queue_info[queue].setup_reserved = false;
326
327 spin_unlock(&mvm->queue_info_lock);
328
329 /* TODO: support shared queues for same RA */
330 if (queue < 0)
331 return -ENOSPC;
332
333 /*
334 * Actual en/disablement of aggregations is through the ADD_STA HCMD,
335 * but for configuring the SCD to send A-MPDUs we need to mark the queue
336 * as aggregatable.
337 * Mark all DATA queues as allowing to be aggregated at some point
338 */
339 cfg.aggregate = (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE);
340
341 IWL_DEBUG_TX_QUEUES(mvm, "Allocating queue #%d to sta %d on tid %d\n",
342 queue, mvmsta->sta_id, tid);
343
344 ssn = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl));
345 iwl_mvm_enable_txq(mvm, queue, mac_queue, ssn, &cfg,
346 wdg_timeout);
347
348 spin_lock_bh(&mvmsta->lock);
349 mvmsta->tid_data[tid].txq_id = queue;
350 mvmsta->tfd_queue_msk |= BIT(queue);
351
352 if (mvmsta->reserved_queue == queue)
353 mvmsta->reserved_queue = IEEE80211_INVAL_HW_QUEUE;
354 spin_unlock_bh(&mvmsta->lock);
355
356 return iwl_mvm_sta_send_to_fw(mvm, sta, true, STA_MODIFY_QUEUES);
357}
358
359static inline u8 iwl_mvm_tid_to_ac_queue(int tid)
360{
361 if (tid == IWL_MAX_TID_COUNT)
362 return IEEE80211_AC_VO; /* MGMT */
363
364 return tid_to_mac80211_ac[tid];
365}
366
367static void iwl_mvm_tx_deferred_stream(struct iwl_mvm *mvm,
368 struct ieee80211_sta *sta, int tid)
369{
370 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
371 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
372 struct sk_buff *skb;
373 struct ieee80211_hdr *hdr;
374 struct sk_buff_head deferred_tx;
375 u8 mac_queue;
376 bool no_queue = false; /* Marks if there is a problem with the queue */
377 u8 ac;
378
379 lockdep_assert_held(&mvm->mutex);
380
381 skb = skb_peek(&tid_data->deferred_tx_frames);
382 if (!skb)
383 return;
384 hdr = (void *)skb->data;
385
386 ac = iwl_mvm_tid_to_ac_queue(tid);
387 mac_queue = IEEE80211_SKB_CB(skb)->hw_queue;
388
389 if (tid_data->txq_id == IEEE80211_INVAL_HW_QUEUE &&
390 iwl_mvm_sta_alloc_queue(mvm, sta, ac, tid, hdr)) {
391 IWL_ERR(mvm,
392 "Can't alloc TXQ for sta %d tid %d - dropping frame\n",
393 mvmsta->sta_id, tid);
394
395 /*
396 * Mark queue as problematic so later the deferred traffic is
397 * freed, as we can do nothing with it
398 */
399 no_queue = true;
400 }
401
402 __skb_queue_head_init(&deferred_tx);
403
404 spin_lock(&mvmsta->lock);
405 skb_queue_splice_init(&tid_data->deferred_tx_frames, &deferred_tx);
406 spin_unlock(&mvmsta->lock);
407
408 /* Disable bottom-halves when entering TX path */
409 local_bh_disable();
410 while ((skb = __skb_dequeue(&deferred_tx)))
411 if (no_queue || iwl_mvm_tx_skb(mvm, skb, sta))
412 ieee80211_free_txskb(mvm->hw, skb);
413 local_bh_enable();
414
415 /* Wake queue */
416 iwl_mvm_start_mac_queues(mvm, BIT(mac_queue));
417}
418
419void iwl_mvm_add_new_dqa_stream_wk(struct work_struct *wk)
420{
421 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm,
422 add_stream_wk);
423 struct ieee80211_sta *sta;
424 struct iwl_mvm_sta *mvmsta;
425 unsigned long deferred_tid_traffic;
426 int sta_id, tid;
427
428 mutex_lock(&mvm->mutex);
429
430 /* Go over all stations with deferred traffic */
431 for_each_set_bit(sta_id, mvm->sta_deferred_frames,
432 IWL_MVM_STATION_COUNT) {
433 clear_bit(sta_id, mvm->sta_deferred_frames);
434 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
435 lockdep_is_held(&mvm->mutex));
436 if (IS_ERR_OR_NULL(sta))
437 continue;
438
439 mvmsta = iwl_mvm_sta_from_mac80211(sta);
440 deferred_tid_traffic = mvmsta->deferred_traffic_tid_map;
441
442 for_each_set_bit(tid, &deferred_tid_traffic,
443 IWL_MAX_TID_COUNT + 1)
444 iwl_mvm_tx_deferred_stream(mvm, sta, tid);
445 }
446
447 mutex_unlock(&mvm->mutex);
448}
449
450static int iwl_mvm_reserve_sta_stream(struct iwl_mvm *mvm,
451 struct ieee80211_sta *sta)
452{
453 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
454 int queue;
455
456 spin_lock_bh(&mvm->queue_info_lock);
457
458 /* Make sure we have free resources for this STA */
459 queue = iwl_mvm_find_free_queue(mvm, IWL_MVM_DQA_MIN_DATA_QUEUE,
460 IWL_MVM_DQA_MAX_DATA_QUEUE);
461 if (queue < 0) {
462 spin_unlock_bh(&mvm->queue_info_lock);
463 IWL_ERR(mvm, "No available queues for new station\n");
464 return -ENOSPC;
465 }
466 mvm->queue_info[queue].setup_reserved = true;
467
468 spin_unlock_bh(&mvm->queue_info_lock);
469
470 mvmsta->reserved_queue = queue;
471
472 IWL_DEBUG_TX_QUEUES(mvm, "Reserving data queue #%d for sta_id %d\n",
473 queue, mvmsta->sta_id);
474
475 return 0;
476}
477
Johannes Berg8ca151b2013-01-24 14:25:36 +0100478int iwl_mvm_add_sta(struct iwl_mvm *mvm,
479 struct ieee80211_vif *vif,
480 struct ieee80211_sta *sta)
481{
482 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +0100483 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Sara Sharona571f5f2015-12-07 12:50:58 +0200484 struct iwl_mvm_rxq_dup_data *dup_data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100485 int i, ret, sta_id;
486
487 lockdep_assert_held(&mvm->mutex);
488
489 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
Eliad Pellerb92e6612014-01-23 17:58:23 +0200490 sta_id = iwl_mvm_find_free_sta_id(mvm,
491 ieee80211_vif_type_p2p(vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100492 else
493 sta_id = mvm_sta->sta_id;
494
Johannes Berg36f46312015-03-10 20:32:08 +0100495 if (sta_id == IWL_MVM_STATION_COUNT)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100496 return -ENOSPC;
497
498 spin_lock_init(&mvm_sta->lock);
499
500 mvm_sta->sta_id = sta_id;
501 mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id,
502 mvmvif->color);
503 mvm_sta->vif = vif;
504 mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300505 mvm_sta->tx_protection = 0;
506 mvm_sta->tt_tx_protection = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100507
508 /* HW restart, don't assume the memory has been zeroed */
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +0300509 atomic_set(&mvm->pending_frames[sta_id], 0);
Liad Kaufman69191af2015-09-01 18:50:22 +0300510 mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100511 mvm_sta->tfd_queue_msk = 0;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300512
513 /* allocate new queues for a TDLS station */
514 if (sta->tdls) {
515 ret = iwl_mvm_tdls_sta_init(mvm, sta);
516 if (ret)
517 return ret;
Liad Kaufman24afba72015-07-28 18:56:08 +0300518 } else if (!iwl_mvm_is_dqa_supported(mvm)) {
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300519 for (i = 0; i < IEEE80211_NUM_ACS; i++)
520 if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE)
521 mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]);
522 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100523
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200524 /* for HW restart - reset everything but the sequence number */
Liad Kaufman24afba72015-07-28 18:56:08 +0300525 for (i = 0; i <= IWL_MAX_TID_COUNT; i++) {
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200526 u16 seq = mvm_sta->tid_data[i].seq_number;
527 memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i]));
528 mvm_sta->tid_data[i].seq_number = seq;
Liad Kaufman24afba72015-07-28 18:56:08 +0300529
530 if (!iwl_mvm_is_dqa_supported(mvm))
531 continue;
532
533 /*
534 * Mark all queues for this STA as unallocated and defer TX
535 * frames until the queue is allocated
536 */
537 mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE;
538 skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames);
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200539 }
Liad Kaufman24afba72015-07-28 18:56:08 +0300540 mvm_sta->deferred_traffic_tid_map = 0;
Eyal Shapiraefed6642014-09-14 15:58:53 +0300541 mvm_sta->agg_tids = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100542
Sara Sharona571f5f2015-12-07 12:50:58 +0200543 if (iwl_mvm_has_new_rx_api(mvm) &&
544 !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
545 dup_data = kcalloc(mvm->trans->num_rx_queues,
546 sizeof(*dup_data),
547 GFP_KERNEL);
548 if (!dup_data)
549 return -ENOMEM;
550 mvm_sta->dup_data = dup_data;
551 }
552
Liad Kaufman24afba72015-07-28 18:56:08 +0300553 if (iwl_mvm_is_dqa_supported(mvm)) {
554 ret = iwl_mvm_reserve_sta_stream(mvm, sta);
555 if (ret)
556 goto err;
557 }
558
559 ret = iwl_mvm_sta_send_to_fw(mvm, sta, false, 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100560 if (ret)
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300561 goto err;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100562
Johannes Berg9e848012014-08-04 14:33:42 +0200563 if (vif->type == NL80211_IFTYPE_STATION) {
564 if (!sta->tdls) {
565 WARN_ON(mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT);
566 mvmvif->ap_sta_id = sta_id;
567 } else {
568 WARN_ON(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT);
569 }
570 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100571
572 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta);
573
574 return 0;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300575
576err:
577 iwl_mvm_tdls_sta_deinit(mvm, sta);
578 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100579}
580
Johannes Berg7a453972013-02-12 13:10:44 +0100581int iwl_mvm_update_sta(struct iwl_mvm *mvm,
582 struct ieee80211_vif *vif,
583 struct ieee80211_sta *sta)
584{
Liad Kaufman24afba72015-07-28 18:56:08 +0300585 return iwl_mvm_sta_send_to_fw(mvm, sta, true, 0);
Johannes Berg7a453972013-02-12 13:10:44 +0100586}
587
Johannes Berg8ca151b2013-01-24 14:25:36 +0100588int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
589 bool drain)
590{
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300591 struct iwl_mvm_add_sta_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100592 int ret;
593 u32 status;
594
595 lockdep_assert_held(&mvm->mutex);
596
597 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
598 cmd.sta_id = mvmsta->sta_id;
599 cmd.add_modify = STA_MODE_MODIFY;
600 cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0;
601 cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW);
602
603 status = ADD_STA_SUCCESS;
Sara Sharon854c5702016-01-26 13:17:47 +0200604 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
605 iwl_mvm_add_sta_cmd_size(mvm),
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300606 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100607 if (ret)
608 return ret;
609
Sara Sharon837c4da2016-01-07 16:50:45 +0200610 switch (status & IWL_ADD_STA_STATUS_MASK) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100611 case ADD_STA_SUCCESS:
612 IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n",
613 mvmsta->sta_id);
614 break;
615 default:
616 ret = -EIO;
617 IWL_ERR(mvm, "Couldn't drain frames for staid %d\n",
618 mvmsta->sta_id);
619 break;
620 }
621
622 return ret;
623}
624
625/*
626 * Remove a station from the FW table. Before sending the command to remove
627 * the station validate that the station is indeed known to the driver (sanity
628 * only).
629 */
630static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id)
631{
632 struct ieee80211_sta *sta;
633 struct iwl_mvm_rm_sta_cmd rm_sta_cmd = {
634 .sta_id = sta_id,
635 };
636 int ret;
637
638 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
639 lockdep_is_held(&mvm->mutex));
640
641 /* Note: internal stations are marked as error values */
642 if (!sta) {
643 IWL_ERR(mvm, "Invalid station id\n");
644 return -EINVAL;
645 }
646
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300647 ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100648 sizeof(rm_sta_cmd), &rm_sta_cmd);
649 if (ret) {
650 IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id);
651 return ret;
652 }
653
654 return 0;
655}
656
657void iwl_mvm_sta_drained_wk(struct work_struct *wk)
658{
659 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk);
660 u8 sta_id;
661
662 /*
663 * The mutex is needed because of the SYNC cmd, but not only: if the
664 * work would run concurrently with iwl_mvm_rm_sta, it would run before
665 * iwl_mvm_rm_sta sets the station as busy, and exit. Then
666 * iwl_mvm_rm_sta would set the station as busy, and nobody will clean
667 * that later.
668 */
669 mutex_lock(&mvm->mutex);
670
671 for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) {
672 int ret;
673 struct ieee80211_sta *sta =
674 rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
675 lockdep_is_held(&mvm->mutex));
676
Johannes Berg1ddbbb02013-12-04 22:39:17 +0100677 /*
678 * This station is in use or RCU-removed; the latter happens in
679 * managed mode, where mac80211 removes the station before we
680 * can remove it from firmware (we can only do that after the
681 * MAC is marked unassociated), and possibly while the deauth
682 * frame to disconnect from the AP is still queued. Then, the
683 * station pointer is -ENOENT when the last skb is reclaimed.
684 */
685 if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100686 continue;
687
688 if (PTR_ERR(sta) == -EINVAL) {
689 IWL_ERR(mvm, "Drained sta %d, but it is internal?\n",
690 sta_id);
691 continue;
692 }
693
694 if (!sta) {
695 IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n",
696 sta_id);
697 continue;
698 }
699
700 WARN_ON(PTR_ERR(sta) != -EBUSY);
701 /* This station was removed and we waited until it got drained,
702 * we can now proceed and remove it.
703 */
704 ret = iwl_mvm_rm_sta_common(mvm, sta_id);
705 if (ret) {
706 IWL_ERR(mvm,
707 "Couldn't remove sta %d after it was drained\n",
708 sta_id);
709 continue;
710 }
Monam Agarwalc531c772014-03-24 00:05:56 +0530711 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100712 clear_bit(sta_id, mvm->sta_drained);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300713
714 if (mvm->tfd_drained[sta_id]) {
715 unsigned long i, msk = mvm->tfd_drained[sta_id];
716
Emmanuel Grumbacha4ca3ed2015-01-20 17:07:10 +0200717 for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE)
Arik Nemtsov06ecdba2015-10-12 14:47:11 +0300718 iwl_mvm_disable_txq(mvm, i, i,
719 IWL_MAX_TID_COUNT, 0);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300720
721 mvm->tfd_drained[sta_id] = 0;
722 IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n",
723 sta_id, msk);
724 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100725 }
726
727 mutex_unlock(&mvm->mutex);
728}
729
Liad Kaufman24afba72015-07-28 18:56:08 +0300730static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm,
731 struct ieee80211_vif *vif,
732 struct iwl_mvm_sta *mvm_sta)
733{
734 int ac;
735 int i;
736
737 lockdep_assert_held(&mvm->mutex);
738
739 for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) {
740 if (mvm_sta->tid_data[i].txq_id == IEEE80211_INVAL_HW_QUEUE)
741 continue;
742
743 ac = iwl_mvm_tid_to_ac_queue(i);
744 iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id,
745 vif->hw_queue[ac], i, 0);
746 mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE;
747 }
748}
749
Johannes Berg8ca151b2013-01-24 14:25:36 +0100750int iwl_mvm_rm_sta(struct iwl_mvm *mvm,
751 struct ieee80211_vif *vif,
752 struct ieee80211_sta *sta)
753{
754 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +0100755 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100756 int ret;
757
758 lockdep_assert_held(&mvm->mutex);
759
Sara Sharona571f5f2015-12-07 12:50:58 +0200760 if (iwl_mvm_has_new_rx_api(mvm))
761 kfree(mvm_sta->dup_data);
762
Johannes Berg8ca151b2013-01-24 14:25:36 +0100763 if (vif->type == NL80211_IFTYPE_STATION &&
764 mvmvif->ap_sta_id == mvm_sta->sta_id) {
Emmanuel Grumbachfe92e322015-03-11 09:34:31 +0200765 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
766 if (ret)
767 return ret;
Emmanuel Grumbach80d85652013-02-19 15:32:42 +0200768 /* flush its queues here since we are freeing mvm_sta */
Luca Coelho5888a402015-10-06 09:54:57 +0300769 ret = iwl_mvm_flush_tx_path(mvm, mvm_sta->tfd_queue_msk, 0);
Emmanuel Grumbachfe92e322015-03-11 09:34:31 +0200770 if (ret)
771 return ret;
772 ret = iwl_trans_wait_tx_queue_empty(mvm->trans,
773 mvm_sta->tfd_queue_msk);
774 if (ret)
775 return ret;
776 ret = iwl_mvm_drain_sta(mvm, mvm_sta, false);
Emmanuel Grumbach80d85652013-02-19 15:32:42 +0200777
Liad Kaufman24afba72015-07-28 18:56:08 +0300778 /* If DQA is supported - the queues can be disabled now */
779 if (iwl_mvm_is_dqa_supported(mvm))
780 iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta);
781
Johannes Berg8ca151b2013-01-24 14:25:36 +0100782 /* if we are associated - we can't remove the AP STA now */
783 if (vif->bss_conf.assoc)
784 return ret;
785
786 /* unassoc - go ahead - remove the AP STA now */
787 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
Eliad Peller37577fe2013-12-05 17:19:39 +0200788
789 /* clear d0i3_ap_sta_id if no longer relevant */
790 if (mvm->d0i3_ap_sta_id == mvm_sta->sta_id)
791 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100792 }
793
794 /*
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +0300795 * This shouldn't happen - the TDLS channel switch should be canceled
796 * before the STA is removed.
797 */
798 if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == mvm_sta->sta_id)) {
799 mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT;
800 cancel_delayed_work(&mvm->tdls_cs.dwork);
801 }
802
803 /*
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +0300804 * Make sure that the tx response code sees the station as -EBUSY and
805 * calls the drain worker.
806 */
807 spin_lock_bh(&mvm_sta->lock);
808 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +0100809 * There are frames pending on the AC queues for this station.
810 * We need to wait until all the frames are drained...
811 */
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +0300812 if (atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100813 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
814 ERR_PTR(-EBUSY));
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +0300815 spin_unlock_bh(&mvm_sta->lock);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300816
817 /* disable TDLS sta queues on drain complete */
818 if (sta->tdls) {
819 mvm->tfd_drained[mvm_sta->sta_id] =
820 mvm_sta->tfd_queue_msk;
821 IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n",
822 mvm_sta->sta_id);
823 }
824
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +0300825 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100826 } else {
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +0300827 spin_unlock_bh(&mvm_sta->lock);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300828
829 if (sta->tdls)
830 iwl_mvm_tdls_sta_deinit(mvm, sta);
831
Johannes Berg8ca151b2013-01-24 14:25:36 +0100832 ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id);
Monam Agarwalc531c772014-03-24 00:05:56 +0530833 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100834 }
835
836 return ret;
837}
838
839int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm,
840 struct ieee80211_vif *vif,
841 u8 sta_id)
842{
843 int ret = iwl_mvm_rm_sta_common(mvm, sta_id);
844
845 lockdep_assert_held(&mvm->mutex);
846
Monam Agarwalc531c772014-03-24 00:05:56 +0530847 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100848 return ret;
849}
850
Chaya Rachel Ivgi0e39eb02015-12-03 15:51:46 +0200851int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm,
852 struct iwl_mvm_int_sta *sta,
853 u32 qmask, enum nl80211_iftype iftype)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100854{
855 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
Eliad Pellerb92e6612014-01-23 17:58:23 +0200856 sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100857 if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_STATION_COUNT))
858 return -ENOSPC;
859 }
860
861 sta->tfd_queue_msk = qmask;
862
863 /* put a non-NULL value so iterating over the stations won't stop */
864 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL));
865 return 0;
866}
867
Johannes Berg712b24a2014-08-04 14:14:14 +0200868static void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm,
869 struct iwl_mvm_int_sta *sta)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100870{
Monam Agarwalc531c772014-03-24 00:05:56 +0530871 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta->sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100872 memset(sta, 0, sizeof(struct iwl_mvm_int_sta));
873 sta->sta_id = IWL_MVM_STATION_COUNT;
874}
875
876static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm,
877 struct iwl_mvm_int_sta *sta,
878 const u8 *addr,
879 u16 mac_id, u16 color)
880{
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300881 struct iwl_mvm_add_sta_cmd cmd;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100882 int ret;
883 u32 status;
884
885 lockdep_assert_held(&mvm->mutex);
886
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300887 memset(&cmd, 0, sizeof(cmd));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100888 cmd.sta_id = sta->sta_id;
889 cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id,
890 color));
891
892 cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk);
Liad Kaufmancf0cda12015-09-24 10:44:12 +0200893 cmd.tid_disable_tx = cpu_to_le16(0xffff);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100894
895 if (addr)
896 memcpy(cmd.addr, addr, ETH_ALEN);
897
Sara Sharon854c5702016-01-26 13:17:47 +0200898 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
899 iwl_mvm_add_sta_cmd_size(mvm),
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300900 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100901 if (ret)
902 return ret;
903
Sara Sharon837c4da2016-01-07 16:50:45 +0200904 switch (status & IWL_ADD_STA_STATUS_MASK) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100905 case ADD_STA_SUCCESS:
906 IWL_DEBUG_INFO(mvm, "Internal station added.\n");
907 return 0;
908 default:
909 ret = -EIO;
910 IWL_ERR(mvm, "Add internal station failed, status=0x%x\n",
911 status);
912 break;
913 }
914 return ret;
915}
916
917int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm)
918{
Emmanuel Grumbach4cf677f2015-01-12 14:38:29 +0200919 unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ?
920 mvm->cfg->base_params->wd_timeout :
921 IWL_WATCHDOG_DISABLED;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100922 int ret;
923
924 lockdep_assert_held(&mvm->mutex);
925
Ariej Marjieh7da91b02014-07-07 12:09:40 +0300926 /* Map Aux queue to fifo - needs to happen before adding Aux station */
Liad Kaufman4ecafae2015-07-14 13:36:18 +0300927 iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue,
Liad Kaufman5c1156e2015-07-22 17:59:53 +0300928 IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout);
Ariej Marjieh7da91b02014-07-07 12:09:40 +0300929
930 /* Allocate aux station and assign to it the aux queue */
931 ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue),
Eliad Pellerb92e6612014-01-23 17:58:23 +0200932 NL80211_IFTYPE_UNSPECIFIED);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100933 if (ret)
934 return ret;
935
936 ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL,
937 MAC_INDEX_AUX, 0);
938
939 if (ret)
940 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
941 return ret;
942}
943
Chaya Rachel Ivgi0e39eb02015-12-03 15:51:46 +0200944int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
945{
946 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
947
948 lockdep_assert_held(&mvm->mutex);
949 return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr,
950 mvmvif->id, 0);
951}
952
953int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
954{
955 int ret;
956
957 lockdep_assert_held(&mvm->mutex);
958
959 ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id);
960 if (ret)
961 IWL_WARN(mvm, "Failed sending remove station\n");
962
963 return ret;
964}
965
966void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm)
967{
968 iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta);
969}
970
Johannes Berg712b24a2014-08-04 14:14:14 +0200971void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm)
972{
973 lockdep_assert_held(&mvm->mutex);
974
975 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
976}
977
Johannes Berg8ca151b2013-01-24 14:25:36 +0100978/*
979 * Send the add station command for the vif's broadcast station.
980 * Assumes that the station was already allocated.
981 *
982 * @mvm: the mvm component
983 * @vif: the interface to which the broadcast station is added
984 * @bsta: the broadcast station to add.
985 */
Johannes Berg013290a2014-08-04 13:38:48 +0200986int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100987{
988 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg013290a2014-08-04 13:38:48 +0200989 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
Johannes Berg5023d962013-07-31 14:07:43 +0200990 static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
Johannes Berga4243402014-01-20 23:46:38 +0100991 const u8 *baddr = _baddr;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100992
993 lockdep_assert_held(&mvm->mutex);
994
Johannes Berg5023d962013-07-31 14:07:43 +0200995 if (vif->type == NL80211_IFTYPE_ADHOC)
996 baddr = vif->bss_conf.bssid;
997
Johannes Berg8ca151b2013-01-24 14:25:36 +0100998 if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_STATION_COUNT))
999 return -ENOSPC;
1000
1001 return iwl_mvm_add_int_sta_common(mvm, bsta, baddr,
1002 mvmvif->id, mvmvif->color);
1003}
1004
1005/* Send the FW a request to remove the station from it's internal data
1006 * structures, but DO NOT remove the entry from the local data structures. */
Johannes Berg013290a2014-08-04 13:38:48 +02001007int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001008{
Johannes Berg013290a2014-08-04 13:38:48 +02001009 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001010 int ret;
1011
1012 lockdep_assert_held(&mvm->mutex);
1013
Johannes Berg013290a2014-08-04 13:38:48 +02001014 ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001015 if (ret)
1016 IWL_WARN(mvm, "Failed sending remove station\n");
1017 return ret;
1018}
1019
Johannes Berg013290a2014-08-04 13:38:48 +02001020int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1021{
1022 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1023 u32 qmask;
1024
1025 lockdep_assert_held(&mvm->mutex);
1026
Arik Nemtsovd92b732e2014-09-21 19:00:42 +03001027 qmask = iwl_mvm_mac_get_queues_mask(vif);
Johannes Berg013290a2014-08-04 13:38:48 +02001028
1029 /*
1030 * The firmware defines the TFD queue mask to only be relevant
1031 * for *unicast* queues, so the multicast (CAB) queue shouldn't
1032 * be included.
1033 */
1034 if (vif->type == NL80211_IFTYPE_AP)
1035 qmask &= ~BIT(vif->cab_queue);
1036
1037 return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask,
1038 ieee80211_vif_type_p2p(vif));
1039}
1040
Johannes Berg8ca151b2013-01-24 14:25:36 +01001041/* Allocate a new station entry for the broadcast station to the given vif,
1042 * and send it to the FW.
1043 * Note that each P2P mac should have its own broadcast station.
1044 *
1045 * @mvm: the mvm component
1046 * @vif: the interface to which the broadcast station is added
1047 * @bsta: the broadcast station to add. */
Johannes Berg013290a2014-08-04 13:38:48 +02001048int iwl_mvm_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001049{
1050 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg013290a2014-08-04 13:38:48 +02001051 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001052 int ret;
1053
1054 lockdep_assert_held(&mvm->mutex);
1055
Johannes Berg013290a2014-08-04 13:38:48 +02001056 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001057 if (ret)
1058 return ret;
1059
Johannes Berg013290a2014-08-04 13:38:48 +02001060 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001061
1062 if (ret)
1063 iwl_mvm_dealloc_int_sta(mvm, bsta);
Johannes Berg013290a2014-08-04 13:38:48 +02001064
Johannes Berg8ca151b2013-01-24 14:25:36 +01001065 return ret;
1066}
1067
Johannes Berg013290a2014-08-04 13:38:48 +02001068void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1069{
1070 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1071
1072 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
1073}
1074
Johannes Berg8ca151b2013-01-24 14:25:36 +01001075/*
1076 * Send the FW a request to remove the station from it's internal data
1077 * structures, and in addition remove it from the local data structure.
1078 */
Johannes Berg013290a2014-08-04 13:38:48 +02001079int iwl_mvm_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001080{
1081 int ret;
1082
1083 lockdep_assert_held(&mvm->mutex);
1084
Johannes Berg013290a2014-08-04 13:38:48 +02001085 ret = iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001086
Johannes Berg013290a2014-08-04 13:38:48 +02001087 iwl_mvm_dealloc_bcast_sta(mvm, vif);
1088
Johannes Berg8ca151b2013-01-24 14:25:36 +01001089 return ret;
1090}
1091
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03001092#define IWL_MAX_RX_BA_SESSIONS 16
1093
Johannes Berg8ca151b2013-01-24 14:25:36 +01001094int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
Sara Sharon854c5702016-01-26 13:17:47 +02001095 int tid, u16 ssn, bool start, u8 buf_size)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001096{
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01001097 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001098 struct iwl_mvm_add_sta_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +01001099 int ret;
1100 u32 status;
1101
1102 lockdep_assert_held(&mvm->mutex);
1103
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03001104 if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) {
1105 IWL_WARN(mvm, "Not enough RX BA SESSIONS\n");
1106 return -ENOSPC;
1107 }
1108
Johannes Berg8ca151b2013-01-24 14:25:36 +01001109 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
1110 cmd.sta_id = mvm_sta->sta_id;
1111 cmd.add_modify = STA_MODE_MODIFY;
Emmanuel Grumbach93a42662013-07-02 13:35:35 +03001112 if (start) {
1113 cmd.add_immediate_ba_tid = (u8) tid;
1114 cmd.add_immediate_ba_ssn = cpu_to_le16(ssn);
Sara Sharon854c5702016-01-26 13:17:47 +02001115 cmd.rx_ba_window = cpu_to_le16((u16)buf_size);
Emmanuel Grumbach93a42662013-07-02 13:35:35 +03001116 } else {
1117 cmd.remove_immediate_ba_tid = (u8) tid;
1118 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001119 cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID :
1120 STA_MODIFY_REMOVE_BA_TID;
1121
1122 status = ADD_STA_SUCCESS;
Sara Sharon854c5702016-01-26 13:17:47 +02001123 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1124 iwl_mvm_add_sta_cmd_size(mvm),
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001125 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001126 if (ret)
1127 return ret;
1128
Sara Sharon837c4da2016-01-07 16:50:45 +02001129 switch (status & IWL_ADD_STA_STATUS_MASK) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001130 case ADD_STA_SUCCESS:
1131 IWL_DEBUG_INFO(mvm, "RX BA Session %sed in fw\n",
1132 start ? "start" : "stopp");
1133 break;
1134 case ADD_STA_IMMEDIATE_BA_FAILURE:
1135 IWL_WARN(mvm, "RX BA Session refused by fw\n");
1136 ret = -ENOSPC;
1137 break;
1138 default:
1139 ret = -EIO;
1140 IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n",
1141 start ? "start" : "stopp", status);
1142 break;
1143 }
1144
Emmanuel Grumbach113a0442013-07-02 14:16:38 +03001145 if (!ret) {
1146 if (start)
1147 mvm->rx_ba_sessions++;
1148 else if (mvm->rx_ba_sessions > 0)
1149 /* check that restart flow didn't zero the counter */
1150 mvm->rx_ba_sessions--;
1151 }
1152
Johannes Berg8ca151b2013-01-24 14:25:36 +01001153 return ret;
1154}
1155
1156static int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
1157 int tid, u8 queue, bool start)
1158{
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01001159 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001160 struct iwl_mvm_add_sta_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +01001161 int ret;
1162 u32 status;
1163
1164 lockdep_assert_held(&mvm->mutex);
1165
1166 if (start) {
1167 mvm_sta->tfd_queue_msk |= BIT(queue);
1168 mvm_sta->tid_disable_agg &= ~BIT(tid);
1169 } else {
1170 mvm_sta->tfd_queue_msk &= ~BIT(queue);
1171 mvm_sta->tid_disable_agg |= BIT(tid);
1172 }
1173
1174 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
1175 cmd.sta_id = mvm_sta->sta_id;
1176 cmd.add_modify = STA_MODE_MODIFY;
1177 cmd.modify_mask = STA_MODIFY_QUEUES | STA_MODIFY_TID_DISABLE_TX;
1178 cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk);
1179 cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg);
1180
1181 status = ADD_STA_SUCCESS;
Sara Sharon854c5702016-01-26 13:17:47 +02001182 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA,
1183 iwl_mvm_add_sta_cmd_size(mvm),
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001184 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001185 if (ret)
1186 return ret;
1187
Sara Sharon837c4da2016-01-07 16:50:45 +02001188 switch (status & IWL_ADD_STA_STATUS_MASK) {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001189 case ADD_STA_SUCCESS:
1190 break;
1191 default:
1192 ret = -EIO;
1193 IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n",
1194 start ? "start" : "stopp", status);
1195 break;
1196 }
1197
1198 return ret;
1199}
1200
Emmanuel Grumbachb797e3f2014-03-06 14:49:36 +02001201const u8 tid_to_mac80211_ac[] = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001202 IEEE80211_AC_BE,
1203 IEEE80211_AC_BK,
1204 IEEE80211_AC_BK,
1205 IEEE80211_AC_BE,
1206 IEEE80211_AC_VI,
1207 IEEE80211_AC_VI,
1208 IEEE80211_AC_VO,
1209 IEEE80211_AC_VO,
1210};
1211
Johannes Berg3e56ead2013-02-15 22:23:18 +01001212static const u8 tid_to_ucode_ac[] = {
1213 AC_BE,
1214 AC_BK,
1215 AC_BK,
1216 AC_BE,
1217 AC_VI,
1218 AC_VI,
1219 AC_VO,
1220 AC_VO,
1221};
1222
Johannes Berg8ca151b2013-01-24 14:25:36 +01001223int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1224 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
1225{
Johannes Berg5b577a92013-11-14 18:20:04 +01001226 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001227 struct iwl_mvm_tid_data *tid_data;
1228 int txq_id;
Liad Kaufman4ecafae2015-07-14 13:36:18 +03001229 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001230
1231 if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
1232 return -EINVAL;
1233
1234 if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) {
1235 IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n",
1236 mvmsta->tid_data[tid].state);
1237 return -ENXIO;
1238 }
1239
1240 lockdep_assert_held(&mvm->mutex);
1241
Arik Nemtsovb2492502014-03-13 12:21:50 +02001242 spin_lock_bh(&mvmsta->lock);
1243
1244 /* possible race condition - we entered D0i3 while starting agg */
1245 if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) {
1246 spin_unlock_bh(&mvmsta->lock);
1247 IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n");
1248 return -EIO;
1249 }
1250
Liad Kaufman4ecafae2015-07-14 13:36:18 +03001251 spin_lock_bh(&mvm->queue_info_lock);
1252
1253 txq_id = iwl_mvm_find_free_queue(mvm, mvm->first_agg_queue,
1254 mvm->last_agg_queue);
1255 if (txq_id < 0) {
1256 ret = txq_id;
1257 spin_unlock_bh(&mvm->queue_info_lock);
1258 IWL_ERR(mvm, "Failed to allocate agg queue\n");
1259 goto release_locks;
1260 }
1261 mvm->queue_info[txq_id].setup_reserved = true;
1262 spin_unlock_bh(&mvm->queue_info_lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001263
Johannes Berg8ca151b2013-01-24 14:25:36 +01001264 tid_data = &mvmsta->tid_data[tid];
Johannes Berg9a886582013-02-15 19:25:00 +01001265 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001266 tid_data->txq_id = txq_id;
1267 *ssn = tid_data->ssn;
1268
1269 IWL_DEBUG_TX_QUEUES(mvm,
1270 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
1271 mvmsta->sta_id, tid, txq_id, tid_data->ssn,
1272 tid_data->next_reclaimed);
1273
1274 if (tid_data->ssn == tid_data->next_reclaimed) {
1275 tid_data->state = IWL_AGG_STARTING;
1276 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1277 } else {
1278 tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA;
1279 }
1280
Liad Kaufman4ecafae2015-07-14 13:36:18 +03001281 ret = 0;
1282
1283release_locks:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001284 spin_unlock_bh(&mvmsta->lock);
1285
Liad Kaufman4ecafae2015-07-14 13:36:18 +03001286 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001287}
1288
1289int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
Emmanuel Grumbachbb81bb62015-10-26 16:00:29 +02001290 struct ieee80211_sta *sta, u16 tid, u8 buf_size,
1291 bool amsdu)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001292{
Johannes Berg5b577a92013-11-14 18:20:04 +01001293 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001294 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
Emmanuel Grumbach5d42e7b2015-03-19 20:04:51 +02001295 unsigned int wdg_timeout =
1296 iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false);
Emmanuel Grumbacheea76c32016-02-21 16:29:17 +02001297 int queue, ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001298 u16 ssn;
1299
Emmanuel Grumbacheea76c32016-02-21 16:29:17 +02001300 struct iwl_trans_txq_scd_cfg cfg = {
1301 .sta_id = mvmsta->sta_id,
1302 .tid = tid,
1303 .frame_limit = buf_size,
1304 .aggregate = true,
1305 };
1306
Eyal Shapiraefed6642014-09-14 15:58:53 +03001307 BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE)
1308 != IWL_MAX_TID_COUNT);
1309
Johannes Berg8ca151b2013-01-24 14:25:36 +01001310 buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
1311
1312 spin_lock_bh(&mvmsta->lock);
1313 ssn = tid_data->ssn;
1314 queue = tid_data->txq_id;
1315 tid_data->state = IWL_AGG_ON;
Eyal Shapiraefed6642014-09-14 15:58:53 +03001316 mvmsta->agg_tids |= BIT(tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001317 tid_data->ssn = 0xffff;
Emmanuel Grumbachbb81bb62015-10-26 16:00:29 +02001318 tid_data->amsdu_in_ampdu_allowed = amsdu;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001319 spin_unlock_bh(&mvmsta->lock);
1320
Emmanuel Grumbacheea76c32016-02-21 16:29:17 +02001321 cfg.fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
Johannes Berg8ca151b2013-01-24 14:25:36 +01001322
Emmanuel Grumbacheea76c32016-02-21 16:29:17 +02001323 iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[tid_to_mac80211_ac[tid]],
1324 ssn, &cfg, wdg_timeout);
Andrei Otcheretianskifa7878e2015-05-05 09:28:16 +03001325
Johannes Berg8ca151b2013-01-24 14:25:36 +01001326 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
1327 if (ret)
1328 return -EIO;
1329
Liad Kaufman4ecafae2015-07-14 13:36:18 +03001330 /* No need to mark as reserved */
1331 spin_lock_bh(&mvm->queue_info_lock);
1332 mvm->queue_info[queue].setup_reserved = false;
1333 spin_unlock_bh(&mvm->queue_info_lock);
1334
Johannes Berg8ca151b2013-01-24 14:25:36 +01001335 /*
1336 * Even though in theory the peer could have different
1337 * aggregation reorder buffer sizes for different sessions,
1338 * our ucode doesn't allow for that and has a global limit
1339 * for each station. Therefore, use the minimum of all the
1340 * aggregation sessions and our default value.
1341 */
1342 mvmsta->max_agg_bufsize =
1343 min(mvmsta->max_agg_bufsize, buf_size);
1344 mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize;
1345
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +03001346 IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n",
1347 sta->addr, tid);
1348
Eyal Shapira9e680942013-11-09 00:16:16 +02001349 return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001350}
1351
1352int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1353 struct ieee80211_sta *sta, u16 tid)
1354{
Johannes Berg5b577a92013-11-14 18:20:04 +01001355 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001356 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
1357 u16 txq_id;
1358 int err;
1359
Emmanuel Grumbachf9aa8dd2013-03-04 09:11:08 +02001360
1361 /*
1362 * If mac80211 is cleaning its state, then say that we finished since
1363 * our state has been cleared anyway.
1364 */
1365 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1366 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1367 return 0;
1368 }
1369
Johannes Berg8ca151b2013-01-24 14:25:36 +01001370 spin_lock_bh(&mvmsta->lock);
1371
1372 txq_id = tid_data->txq_id;
1373
1374 IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n",
1375 mvmsta->sta_id, tid, txq_id, tid_data->state);
1376
Eyal Shapiraefed6642014-09-14 15:58:53 +03001377 mvmsta->agg_tids &= ~BIT(tid);
1378
Liad Kaufman4ecafae2015-07-14 13:36:18 +03001379 /* No need to mark as reserved anymore */
1380 spin_lock_bh(&mvm->queue_info_lock);
1381 mvm->queue_info[txq_id].setup_reserved = false;
1382 spin_unlock_bh(&mvm->queue_info_lock);
1383
Johannes Berg8ca151b2013-01-24 14:25:36 +01001384 switch (tid_data->state) {
1385 case IWL_AGG_ON:
Johannes Berg9a886582013-02-15 19:25:00 +01001386 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001387
1388 IWL_DEBUG_TX_QUEUES(mvm,
1389 "ssn = %d, next_recl = %d\n",
1390 tid_data->ssn, tid_data->next_reclaimed);
1391
1392 /* There are still packets for this RA / TID in the HW */
1393 if (tid_data->ssn != tid_data->next_reclaimed) {
1394 tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA;
1395 err = 0;
1396 break;
1397 }
1398
1399 tid_data->ssn = 0xffff;
Johannes Bergf7f89e72014-08-05 15:24:44 +02001400 tid_data->state = IWL_AGG_OFF;
Johannes Bergf7f89e72014-08-05 15:24:44 +02001401 spin_unlock_bh(&mvmsta->lock);
1402
1403 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1404
1405 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
1406
Liad Kaufman4ecafae2015-07-14 13:36:18 +03001407 iwl_mvm_disable_txq(mvm, txq_id,
1408 vif->hw_queue[tid_to_mac80211_ac[tid]], tid,
1409 0);
Johannes Bergf7f89e72014-08-05 15:24:44 +02001410 return 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001411 case IWL_AGG_STARTING:
1412 case IWL_EMPTYING_HW_QUEUE_ADDBA:
1413 /*
1414 * The agg session has been stopped before it was set up. This
1415 * can happen when the AddBA timer times out for example.
1416 */
1417
1418 /* No barriers since we are under mutex */
1419 lockdep_assert_held(&mvm->mutex);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001420
1421 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1422 tid_data->state = IWL_AGG_OFF;
1423 err = 0;
1424 break;
1425 default:
1426 IWL_ERR(mvm,
1427 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
1428 mvmsta->sta_id, tid, tid_data->state);
1429 IWL_ERR(mvm,
1430 "\ttid_data->txq_id = %d\n", tid_data->txq_id);
1431 err = -EINVAL;
1432 }
1433
1434 spin_unlock_bh(&mvmsta->lock);
1435
1436 return err;
1437}
1438
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02001439int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1440 struct ieee80211_sta *sta, u16 tid)
1441{
Johannes Berg5b577a92013-11-14 18:20:04 +01001442 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02001443 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
1444 u16 txq_id;
Johannes Bergb6658ff2013-07-24 13:55:51 +02001445 enum iwl_mvm_agg_state old_state;
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02001446
1447 /*
1448 * First set the agg state to OFF to avoid calling
1449 * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
1450 */
1451 spin_lock_bh(&mvmsta->lock);
1452 txq_id = tid_data->txq_id;
1453 IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n",
1454 mvmsta->sta_id, tid, txq_id, tid_data->state);
Johannes Bergb6658ff2013-07-24 13:55:51 +02001455 old_state = tid_data->state;
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02001456 tid_data->state = IWL_AGG_OFF;
Eyal Shapiraefed6642014-09-14 15:58:53 +03001457 mvmsta->agg_tids &= ~BIT(tid);
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02001458 spin_unlock_bh(&mvmsta->lock);
1459
Liad Kaufman4ecafae2015-07-14 13:36:18 +03001460 /* No need to mark as reserved */
1461 spin_lock_bh(&mvm->queue_info_lock);
1462 mvm->queue_info[txq_id].setup_reserved = false;
1463 spin_unlock_bh(&mvm->queue_info_lock);
1464
Johannes Bergb6658ff2013-07-24 13:55:51 +02001465 if (old_state >= IWL_AGG_ON) {
Emmanuel Grumbachfe92e322015-03-11 09:34:31 +02001466 iwl_mvm_drain_sta(mvm, mvmsta, true);
Luca Coelho5888a402015-10-06 09:54:57 +03001467 if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0))
Johannes Bergb6658ff2013-07-24 13:55:51 +02001468 IWL_ERR(mvm, "Couldn't flush the AGG queue\n");
Emmanuel Grumbachfe92e322015-03-11 09:34:31 +02001469 iwl_trans_wait_tx_queue_empty(mvm->trans,
1470 mvmsta->tfd_queue_msk);
1471 iwl_mvm_drain_sta(mvm, mvmsta, false);
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02001472
Johannes Bergf7f89e72014-08-05 15:24:44 +02001473 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
1474
Liad Kaufman4ecafae2015-07-14 13:36:18 +03001475 iwl_mvm_disable_txq(mvm, tid_data->txq_id,
1476 vif->hw_queue[tid_to_mac80211_ac[tid]], tid,
1477 0);
Johannes Bergb6658ff2013-07-24 13:55:51 +02001478 }
1479
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02001480 return 0;
1481}
1482
Johannes Berg8ca151b2013-01-24 14:25:36 +01001483static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm)
1484{
Johannes Berg2dc2a152015-06-16 17:09:18 +02001485 int i, max = -1, max_offs = -1;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001486
1487 lockdep_assert_held(&mvm->mutex);
1488
Johannes Berg2dc2a152015-06-16 17:09:18 +02001489 /* Pick the unused key offset with the highest 'deleted'
1490 * counter. Every time a key is deleted, all the counters
1491 * are incremented and the one that was just deleted is
1492 * reset to zero. Thus, the highest counter is the one
1493 * that was deleted longest ago. Pick that one.
1494 */
1495 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
1496 if (test_bit(i, mvm->fw_key_table))
1497 continue;
1498 if (mvm->fw_key_deleted[i] > max) {
1499 max = mvm->fw_key_deleted[i];
1500 max_offs = i;
1501 }
1502 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001503
Johannes Berg2dc2a152015-06-16 17:09:18 +02001504 if (max_offs < 0)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001505 return STA_KEY_IDX_INVALID;
1506
Johannes Berg2dc2a152015-06-16 17:09:18 +02001507 return max_offs;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001508}
1509
Johannes Berg5f7a1842015-12-11 09:36:10 +01001510static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm,
1511 struct ieee80211_vif *vif,
1512 struct ieee80211_sta *sta)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001513{
Johannes Berg5b530e92014-12-23 16:00:17 +01001514 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001515
Johannes Berg5f7a1842015-12-11 09:36:10 +01001516 if (sta)
1517 return iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001518
1519 /*
1520 * The device expects GTKs for station interfaces to be
1521 * installed as GTKs for the AP station. If we have no
1522 * station ID, then use AP's station ID.
1523 */
1524 if (vif->type == NL80211_IFTYPE_STATION &&
Avri Altman9513c5e2015-10-19 16:29:11 +02001525 mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1526 u8 sta_id = mvmvif->ap_sta_id;
1527
Emmanuel Grumbach12f17212015-12-20 14:48:08 +02001528 sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id],
1529 lockdep_is_held(&mvm->mutex));
Avri Altman9513c5e2015-10-19 16:29:11 +02001530 /*
1531 * It is possible that the 'sta' parameter is NULL,
1532 * for example when a GTK is removed - the sta_id will then
1533 * be the AP ID, and no station was passed by mac80211.
1534 */
1535 if (IS_ERR_OR_NULL(sta))
Johannes Berg5f7a1842015-12-11 09:36:10 +01001536 return NULL;
Avri Altman9513c5e2015-10-19 16:29:11 +02001537
Johannes Berg5f7a1842015-12-11 09:36:10 +01001538 return iwl_mvm_sta_from_mac80211(sta);
Avri Altman9513c5e2015-10-19 16:29:11 +02001539 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01001540
Johannes Berg5f7a1842015-12-11 09:36:10 +01001541 return NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001542}
1543
1544static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm,
1545 struct iwl_mvm_sta *mvm_sta,
Johannes Bergba3943b2014-11-12 23:54:48 +01001546 struct ieee80211_key_conf *keyconf, bool mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02001547 u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags,
1548 u8 key_offset)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001549{
Max Stepanov5a258aa2013-04-07 09:11:21 +03001550 struct iwl_mvm_add_sta_key_cmd cmd = {};
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001551 __le16 key_flags;
Johannes Berg79920742014-11-03 15:43:04 +01001552 int ret;
1553 u32 status;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001554 u16 keyidx;
1555 int i;
Johannes Berg2f6319d2014-11-12 23:39:56 +01001556 u8 sta_id = mvm_sta->sta_id;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001557
1558 keyidx = (keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
1559 STA_KEY_FLG_KEYID_MSK;
1560 key_flags = cpu_to_le16(keyidx);
1561 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP);
1562
1563 switch (keyconf->cipher) {
1564 case WLAN_CIPHER_SUITE_TKIP:
1565 key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP);
Max Stepanov5a258aa2013-04-07 09:11:21 +03001566 cmd.tkip_rx_tsc_byte2 = tkip_iv32;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001567 for (i = 0; i < 5; i++)
Max Stepanov5a258aa2013-04-07 09:11:21 +03001568 cmd.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]);
1569 memcpy(cmd.key, keyconf->key, keyconf->keylen);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001570 break;
1571 case WLAN_CIPHER_SUITE_CCMP:
1572 key_flags |= cpu_to_le16(STA_KEY_FLG_CCM);
Max Stepanov5a258aa2013-04-07 09:11:21 +03001573 memcpy(cmd.key, keyconf->key, keyconf->keylen);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001574 break;
Johannes Bergba3943b2014-11-12 23:54:48 +01001575 case WLAN_CIPHER_SUITE_WEP104:
1576 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES);
John W. Linvilleaa0cb082015-01-12 16:18:11 -05001577 /* fall through */
Johannes Bergba3943b2014-11-12 23:54:48 +01001578 case WLAN_CIPHER_SUITE_WEP40:
1579 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP);
1580 memcpy(cmd.key + 3, keyconf->key, keyconf->keylen);
1581 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001582 default:
Max Stepanove36e5432013-08-27 19:56:13 +03001583 key_flags |= cpu_to_le16(STA_KEY_FLG_EXT);
1584 memcpy(cmd.key, keyconf->key, keyconf->keylen);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001585 }
1586
Johannes Bergba3943b2014-11-12 23:54:48 +01001587 if (mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001588 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
1589
Luca Coelhod6ee54a2015-11-10 22:13:43 +02001590 cmd.key_offset = key_offset;
Max Stepanov5a258aa2013-04-07 09:11:21 +03001591 cmd.key_flags = key_flags;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001592 cmd.sta_id = sta_id;
1593
1594 status = ADD_STA_SUCCESS;
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001595 if (cmd_flags & CMD_ASYNC)
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001596 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC,
1597 sizeof(cmd), &cmd);
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001598 else
1599 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd),
1600 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001601
1602 switch (status) {
1603 case ADD_STA_SUCCESS:
1604 IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n");
1605 break;
1606 default:
1607 ret = -EIO;
1608 IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n");
1609 break;
1610 }
1611
1612 return ret;
1613}
1614
1615static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm,
1616 struct ieee80211_key_conf *keyconf,
1617 u8 sta_id, bool remove_key)
1618{
1619 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {};
1620
1621 /* verify the key details match the required command's expectations */
1622 if (WARN_ON((keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC) ||
1623 (keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) ||
1624 (keyconf->keyidx != 4 && keyconf->keyidx != 5)))
1625 return -EINVAL;
1626
1627 igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx);
1628 igtk_cmd.sta_id = cpu_to_le32(sta_id);
1629
1630 if (remove_key) {
1631 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID);
1632 } else {
1633 struct ieee80211_key_seq seq;
1634 const u8 *pn;
1635
1636 memcpy(igtk_cmd.IGTK, keyconf->key, keyconf->keylen);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001637 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
1638 pn = seq.aes_cmac.pn;
1639 igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) |
1640 ((u64) pn[4] << 8) |
1641 ((u64) pn[3] << 16) |
1642 ((u64) pn[2] << 24) |
1643 ((u64) pn[1] << 32) |
1644 ((u64) pn[0] << 40));
1645 }
1646
1647 IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n",
1648 remove_key ? "removing" : "installing",
1649 igtk_cmd.sta_id);
1650
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001651 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001652 sizeof(igtk_cmd), &igtk_cmd);
1653}
1654
1655
1656static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm,
1657 struct ieee80211_vif *vif,
1658 struct ieee80211_sta *sta)
1659{
Johannes Berg5b530e92014-12-23 16:00:17 +01001660 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001661
1662 if (sta)
1663 return sta->addr;
1664
1665 if (vif->type == NL80211_IFTYPE_STATION &&
1666 mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1667 u8 sta_id = mvmvif->ap_sta_id;
1668 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1669 lockdep_is_held(&mvm->mutex));
1670 return sta->addr;
1671 }
1672
1673
1674 return NULL;
1675}
1676
Johannes Berg2f6319d2014-11-12 23:39:56 +01001677static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
1678 struct ieee80211_vif *vif,
1679 struct ieee80211_sta *sta,
Johannes Bergba3943b2014-11-12 23:54:48 +01001680 struct ieee80211_key_conf *keyconf,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02001681 u8 key_offset,
Johannes Bergba3943b2014-11-12 23:54:48 +01001682 bool mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001683{
Johannes Berg2f6319d2014-11-12 23:39:56 +01001684 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001685 int ret;
Johannes Berg2f6319d2014-11-12 23:39:56 +01001686 const u8 *addr;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001687 struct ieee80211_key_seq seq;
1688 u16 p1k[5];
1689
Johannes Berg8ca151b2013-01-24 14:25:36 +01001690 switch (keyconf->cipher) {
1691 case WLAN_CIPHER_SUITE_TKIP:
1692 addr = iwl_mvm_get_mac_addr(mvm, vif, sta);
1693 /* get phase 1 key from mac80211 */
1694 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
1695 ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k);
Johannes Bergba3943b2014-11-12 23:54:48 +01001696 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02001697 seq.tkip.iv32, p1k, 0, key_offset);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001698 break;
1699 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergba3943b2014-11-12 23:54:48 +01001700 case WLAN_CIPHER_SUITE_WEP40:
1701 case WLAN_CIPHER_SUITE_WEP104:
1702 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02001703 0, NULL, 0, key_offset);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001704 break;
1705 default:
Johannes Bergba3943b2014-11-12 23:54:48 +01001706 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02001707 0, NULL, 0, key_offset);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001708 }
1709
Johannes Berg8ca151b2013-01-24 14:25:36 +01001710 return ret;
1711}
1712
Johannes Berg2f6319d2014-11-12 23:39:56 +01001713static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id,
Johannes Bergba3943b2014-11-12 23:54:48 +01001714 struct ieee80211_key_conf *keyconf,
1715 bool mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001716{
Max Stepanov5a258aa2013-04-07 09:11:21 +03001717 struct iwl_mvm_add_sta_key_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +01001718 __le16 key_flags;
Johannes Berg79920742014-11-03 15:43:04 +01001719 int ret;
1720 u32 status;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001721
Emmanuel Grumbach8115efb2013-02-05 10:08:35 +02001722 key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
1723 STA_KEY_FLG_KEYID_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001724 key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP);
1725 key_flags |= cpu_to_le16(STA_KEY_NOT_VALID);
1726
Johannes Bergba3943b2014-11-12 23:54:48 +01001727 if (mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001728 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
1729
Max Stepanov5a258aa2013-04-07 09:11:21 +03001730 cmd.key_flags = key_flags;
1731 cmd.key_offset = keyconf->hw_key_idx;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001732 cmd.sta_id = sta_id;
1733
Johannes Berg8ca151b2013-01-24 14:25:36 +01001734 status = ADD_STA_SUCCESS;
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001735 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd),
1736 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001737
1738 switch (status) {
1739 case ADD_STA_SUCCESS:
1740 IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n");
1741 break;
1742 default:
1743 ret = -EIO;
1744 IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n");
1745 break;
1746 }
1747
1748 return ret;
1749}
1750
Johannes Berg2f6319d2014-11-12 23:39:56 +01001751int iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
1752 struct ieee80211_vif *vif,
1753 struct ieee80211_sta *sta,
1754 struct ieee80211_key_conf *keyconf,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02001755 u8 key_offset)
Johannes Berg2f6319d2014-11-12 23:39:56 +01001756{
Johannes Bergba3943b2014-11-12 23:54:48 +01001757 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
Johannes Berg5f7a1842015-12-11 09:36:10 +01001758 struct iwl_mvm_sta *mvm_sta;
Johannes Berg2f6319d2014-11-12 23:39:56 +01001759 u8 sta_id;
1760 int ret;
Matti Gottlieb11828db2015-06-01 15:15:11 +03001761 static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0};
Johannes Berg2f6319d2014-11-12 23:39:56 +01001762
1763 lockdep_assert_held(&mvm->mutex);
1764
1765 /* Get the station id from the mvm local station table */
Johannes Berg5f7a1842015-12-11 09:36:10 +01001766 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
1767 if (!mvm_sta) {
1768 IWL_ERR(mvm, "Failed to find station\n");
Johannes Berg2f6319d2014-11-12 23:39:56 +01001769 return -EINVAL;
1770 }
Johannes Berg5f7a1842015-12-11 09:36:10 +01001771 sta_id = mvm_sta->sta_id;
Johannes Berg2f6319d2014-11-12 23:39:56 +01001772
1773 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
1774 ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false);
1775 goto end;
1776 }
1777
1778 /*
1779 * It is possible that the 'sta' parameter is NULL, and thus
1780 * there is a need to retrieve the sta from the local station table.
1781 */
1782 if (!sta) {
1783 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1784 lockdep_is_held(&mvm->mutex));
1785 if (IS_ERR_OR_NULL(sta)) {
1786 IWL_ERR(mvm, "Invalid station id\n");
1787 return -EINVAL;
1788 }
1789 }
1790
1791 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif))
1792 return -EINVAL;
1793
Luca Coelhod6ee54a2015-11-10 22:13:43 +02001794 /* If the key_offset is not pre-assigned, we need to find a
1795 * new offset to use. In normal cases, the offset is not
1796 * pre-assigned, but during HW_RESTART we want to reuse the
1797 * same indices, so we pass them when this function is called.
1798 *
1799 * In D3 entry, we need to hardcoded the indices (because the
1800 * firmware hardcodes the PTK offset to 0). In this case, we
1801 * need to make sure we don't overwrite the hw_key_idx in the
1802 * keyconf structure, because otherwise we cannot configure
1803 * the original ones back when resuming.
1804 */
1805 if (key_offset == STA_KEY_IDX_INVALID) {
1806 key_offset = iwl_mvm_set_fw_key_idx(mvm);
1807 if (key_offset == STA_KEY_IDX_INVALID)
Johannes Berg2f6319d2014-11-12 23:39:56 +01001808 return -ENOSPC;
Luca Coelhod6ee54a2015-11-10 22:13:43 +02001809 keyconf->hw_key_idx = key_offset;
Johannes Berg2f6319d2014-11-12 23:39:56 +01001810 }
1811
Luca Coelhod6ee54a2015-11-10 22:13:43 +02001812 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, key_offset, mcast);
Luca Coelho9c3deeb2015-11-11 01:06:17 +02001813 if (ret)
Johannes Bergba3943b2014-11-12 23:54:48 +01001814 goto end;
Johannes Bergba3943b2014-11-12 23:54:48 +01001815
1816 /*
1817 * For WEP, the same key is used for multicast and unicast. Upload it
1818 * again, using the same key offset, and now pointing the other one
1819 * to the same key slot (offset).
1820 * If this fails, remove the original as well.
1821 */
1822 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
1823 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) {
Luca Coelhod6ee54a2015-11-10 22:13:43 +02001824 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf,
1825 key_offset, !mcast);
Johannes Bergba3943b2014-11-12 23:54:48 +01001826 if (ret) {
Johannes Bergba3943b2014-11-12 23:54:48 +01001827 __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
Luca Coelho9c3deeb2015-11-11 01:06:17 +02001828 goto end;
Johannes Bergba3943b2014-11-12 23:54:48 +01001829 }
1830 }
Johannes Berg2f6319d2014-11-12 23:39:56 +01001831
Luca Coelho9c3deeb2015-11-11 01:06:17 +02001832 __set_bit(key_offset, mvm->fw_key_table);
1833
Johannes Berg2f6319d2014-11-12 23:39:56 +01001834end:
1835 IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
1836 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
Matti Gottlieb11828db2015-06-01 15:15:11 +03001837 sta ? sta->addr : zero_addr, ret);
Johannes Berg2f6319d2014-11-12 23:39:56 +01001838 return ret;
1839}
1840
1841int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm,
1842 struct ieee80211_vif *vif,
1843 struct ieee80211_sta *sta,
1844 struct ieee80211_key_conf *keyconf)
1845{
Johannes Bergba3943b2014-11-12 23:54:48 +01001846 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
Johannes Berg5f7a1842015-12-11 09:36:10 +01001847 struct iwl_mvm_sta *mvm_sta;
1848 u8 sta_id = IWL_MVM_STATION_COUNT;
Johannes Berg2dc2a152015-06-16 17:09:18 +02001849 int ret, i;
Johannes Berg2f6319d2014-11-12 23:39:56 +01001850
1851 lockdep_assert_held(&mvm->mutex);
1852
Johannes Berg5f7a1842015-12-11 09:36:10 +01001853 /* Get the station from the mvm local station table */
1854 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
Johannes Berg2f6319d2014-11-12 23:39:56 +01001855
1856 IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n",
1857 keyconf->keyidx, sta_id);
1858
1859 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1860 return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true);
1861
1862 if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) {
1863 IWL_ERR(mvm, "offset %d not used in fw key table.\n",
1864 keyconf->hw_key_idx);
1865 return -ENOENT;
1866 }
1867
Johannes Berg2dc2a152015-06-16 17:09:18 +02001868 /* track which key was deleted last */
1869 for (i = 0; i < STA_KEY_MAX_NUM; i++) {
1870 if (mvm->fw_key_deleted[i] < U8_MAX)
1871 mvm->fw_key_deleted[i]++;
1872 }
1873 mvm->fw_key_deleted[keyconf->hw_key_idx] = 0;
1874
Johannes Berg5f7a1842015-12-11 09:36:10 +01001875 if (!mvm_sta) {
Johannes Berg2f6319d2014-11-12 23:39:56 +01001876 IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n");
1877 return 0;
1878 }
1879
Johannes Berg5f7a1842015-12-11 09:36:10 +01001880 sta_id = mvm_sta->sta_id;
1881
Johannes Bergba3943b2014-11-12 23:54:48 +01001882 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
1883 if (ret)
1884 return ret;
1885
1886 /* delete WEP key twice to get rid of (now useless) offset */
1887 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
1888 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104)
1889 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast);
1890
1891 return ret;
Johannes Berg2f6319d2014-11-12 23:39:56 +01001892}
1893
Johannes Berg8ca151b2013-01-24 14:25:36 +01001894void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm,
1895 struct ieee80211_vif *vif,
1896 struct ieee80211_key_conf *keyconf,
1897 struct ieee80211_sta *sta, u32 iv32,
1898 u16 *phase1key)
1899{
Beni Levc3eb5362013-02-06 17:22:18 +02001900 struct iwl_mvm_sta *mvm_sta;
Johannes Bergba3943b2014-11-12 23:54:48 +01001901 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001902
Beni Levc3eb5362013-02-06 17:22:18 +02001903 rcu_read_lock();
1904
Johannes Berg5f7a1842015-12-11 09:36:10 +01001905 mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta);
1906 if (WARN_ON_ONCE(!mvm_sta))
Emmanuel Grumbach12f17212015-12-20 14:48:08 +02001907 goto unlock;
Johannes Bergba3943b2014-11-12 23:54:48 +01001908 iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
Luca Coelhod6ee54a2015-11-10 22:13:43 +02001909 iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx);
Emmanuel Grumbach12f17212015-12-20 14:48:08 +02001910
1911 unlock:
Beni Levc3eb5362013-02-06 17:22:18 +02001912 rcu_read_unlock();
Johannes Berg8ca151b2013-01-24 14:25:36 +01001913}
1914
Johannes Berg9cc40712013-02-15 22:47:48 +01001915void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm,
1916 struct ieee80211_sta *sta)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001917{
Johannes Berg5b577a92013-11-14 18:20:04 +01001918 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001919 struct iwl_mvm_add_sta_cmd cmd = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001920 .add_modify = STA_MODE_MODIFY,
Johannes Berg9cc40712013-02-15 22:47:48 +01001921 .sta_id = mvmsta->sta_id,
Emmanuel Grumbach5af01772013-06-09 12:59:24 +03001922 .station_flags_msk = cpu_to_le32(STA_FLG_PS),
Johannes Berg9cc40712013-02-15 22:47:48 +01001923 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
Johannes Berg8ca151b2013-01-24 14:25:36 +01001924 };
1925 int ret;
1926
Sara Sharon854c5702016-01-26 13:17:47 +02001927 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
1928 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001929 if (ret)
1930 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
1931}
1932
Johannes Berg9cc40712013-02-15 22:47:48 +01001933void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm,
1934 struct ieee80211_sta *sta,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001935 enum ieee80211_frame_release_type reason,
Johannes Berg3e56ead2013-02-15 22:23:18 +01001936 u16 cnt, u16 tids, bool more_data,
1937 bool agg)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001938{
Johannes Berg5b577a92013-11-14 18:20:04 +01001939 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001940 struct iwl_mvm_add_sta_cmd cmd = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001941 .add_modify = STA_MODE_MODIFY,
Johannes Berg9cc40712013-02-15 22:47:48 +01001942 .sta_id = mvmsta->sta_id,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001943 .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT,
1944 .sleep_tx_count = cpu_to_le16(cnt),
Johannes Berg9cc40712013-02-15 22:47:48 +01001945 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
Johannes Berg8ca151b2013-01-24 14:25:36 +01001946 };
Johannes Berg3e56ead2013-02-15 22:23:18 +01001947 int tid, ret;
1948 unsigned long _tids = tids;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001949
Johannes Berg3e56ead2013-02-15 22:23:18 +01001950 /* convert TIDs to ACs - we don't support TSPEC so that's OK
1951 * Note that this field is reserved and unused by firmware not
1952 * supporting GO uAPSD, so it's safe to always do this.
1953 */
1954 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT)
1955 cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]);
1956
1957 /* If we're releasing frames from aggregation queues then check if the
1958 * all queues combined that we're releasing frames from have
1959 * - more frames than the service period, in which case more_data
1960 * needs to be set
1961 * - fewer than 'cnt' frames, in which case we need to adjust the
1962 * firmware command (but do that unconditionally)
1963 */
1964 if (agg) {
1965 int remaining = cnt;
Emmanuel Grumbach36be0eb2015-11-05 10:32:31 +02001966 int sleep_tx_count;
Johannes Berg3e56ead2013-02-15 22:23:18 +01001967
1968 spin_lock_bh(&mvmsta->lock);
1969 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) {
1970 struct iwl_mvm_tid_data *tid_data;
1971 u16 n_queued;
1972
1973 tid_data = &mvmsta->tid_data[tid];
1974 if (WARN(tid_data->state != IWL_AGG_ON &&
1975 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA,
1976 "TID %d state is %d\n",
1977 tid, tid_data->state)) {
1978 spin_unlock_bh(&mvmsta->lock);
1979 ieee80211_sta_eosp(sta);
1980 return;
1981 }
1982
1983 n_queued = iwl_mvm_tid_queued(tid_data);
1984 if (n_queued > remaining) {
1985 more_data = true;
1986 remaining = 0;
1987 break;
1988 }
1989 remaining -= n_queued;
1990 }
Emmanuel Grumbach36be0eb2015-11-05 10:32:31 +02001991 sleep_tx_count = cnt - remaining;
1992 if (reason == IEEE80211_FRAME_RELEASE_UAPSD)
1993 mvmsta->sleep_tx_count = sleep_tx_count;
Johannes Berg3e56ead2013-02-15 22:23:18 +01001994 spin_unlock_bh(&mvmsta->lock);
1995
Emmanuel Grumbach36be0eb2015-11-05 10:32:31 +02001996 cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count);
Johannes Berg3e56ead2013-02-15 22:23:18 +01001997 if (WARN_ON(cnt - remaining == 0)) {
1998 ieee80211_sta_eosp(sta);
1999 return;
2000 }
2001 }
2002
2003 /* Note: this is ignored by firmware not supporting GO uAPSD */
2004 if (more_data)
2005 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA);
2006
2007 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) {
2008 mvmsta->next_status_eosp = true;
2009 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL);
2010 } else {
2011 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD);
2012 }
2013
Emmanuel Grumbach156f92f2015-11-24 14:55:18 +02002014 /* block the Tx queues until the FW updated the sleep Tx count */
2015 iwl_trans_block_txq_ptrs(mvm->trans, true);
2016
2017 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA,
2018 CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK,
Sara Sharon854c5702016-01-26 13:17:47 +02002019 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002020 if (ret)
2021 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
2022}
Johannes Berg3e56ead2013-02-15 22:23:18 +01002023
Johannes Berg04168412015-06-23 21:22:09 +02002024void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm,
2025 struct iwl_rx_cmd_buffer *rxb)
Johannes Berg3e56ead2013-02-15 22:23:18 +01002026{
2027 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2028 struct iwl_mvm_eosp_notification *notif = (void *)pkt->data;
2029 struct ieee80211_sta *sta;
2030 u32 sta_id = le32_to_cpu(notif->sta_id);
2031
2032 if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT))
Johannes Berg04168412015-06-23 21:22:09 +02002033 return;
Johannes Berg3e56ead2013-02-15 22:23:18 +01002034
2035 rcu_read_lock();
2036 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
2037 if (!IS_ERR_OR_NULL(sta))
2038 ieee80211_sta_eosp(sta);
2039 rcu_read_unlock();
Johannes Berg3e56ead2013-02-15 22:23:18 +01002040}
Andrei Otcheretianski09b0ce12014-05-25 17:07:38 +03002041
2042void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm,
2043 struct iwl_mvm_sta *mvmsta, bool disable)
2044{
2045 struct iwl_mvm_add_sta_cmd cmd = {
2046 .add_modify = STA_MODE_MODIFY,
2047 .sta_id = mvmsta->sta_id,
2048 .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0,
2049 .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX),
2050 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
2051 };
2052 int ret;
2053
Sara Sharon854c5702016-01-26 13:17:47 +02002054 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC,
2055 iwl_mvm_add_sta_cmd_size(mvm), &cmd);
Andrei Otcheretianski09b0ce12014-05-25 17:07:38 +03002056 if (ret)
2057 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
2058}
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03002059
2060void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm,
2061 struct ieee80211_sta *sta,
2062 bool disable)
2063{
2064 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2065
2066 spin_lock_bh(&mvm_sta->lock);
2067
2068 if (mvm_sta->disable_tx == disable) {
2069 spin_unlock_bh(&mvm_sta->lock);
2070 return;
2071 }
2072
2073 mvm_sta->disable_tx = disable;
2074
2075 /*
Sara Sharon0d365ae2015-03-31 12:24:05 +03002076 * Tell mac80211 to start/stop queuing tx for this station,
2077 * but don't stop queuing if there are still pending frames
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03002078 * for this station.
2079 */
2080 if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id]))
2081 ieee80211_sta_block_awake(mvm->hw, sta, disable);
2082
2083 iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable);
2084
2085 spin_unlock_bh(&mvm_sta->lock);
2086}
2087
2088void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm,
2089 struct iwl_mvm_vif *mvmvif,
2090 bool disable)
2091{
2092 struct ieee80211_sta *sta;
2093 struct iwl_mvm_sta *mvm_sta;
2094 int i;
2095
2096 lockdep_assert_held(&mvm->mutex);
2097
2098 /* Block/unblock all the stations of the given mvmvif */
2099 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
2100 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
2101 lockdep_is_held(&mvm->mutex));
2102 if (IS_ERR_OR_NULL(sta))
2103 continue;
2104
2105 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
2106 if (mvm_sta->mac_id_n_color !=
2107 FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color))
2108 continue;
2109
2110 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable);
2111 }
2112}
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02002113
2114void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
2115{
2116 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
2117 struct iwl_mvm_sta *mvmsta;
2118
2119 rcu_read_lock();
2120
2121 mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id);
2122
2123 if (!WARN_ON(!mvmsta))
2124 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true);
2125
2126 rcu_read_unlock();
2127}