blob: 5c23cddaaae34ea26a4722f9dbdc192e3e218ab5 [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 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +02009 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020026 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010027 *
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020034 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +020035 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010036 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
47 * distribution.
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *
64 *****************************************************************************/
65#include <net/mac80211.h>
66
67#include "mvm.h"
68#include "sta.h"
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +030069#include "rs.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010070
Eliad Pellerb92e6612014-01-23 17:58:23 +020071static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm,
72 enum nl80211_iftype iftype)
Johannes Berg8ca151b2013-01-24 14:25:36 +010073{
74 int sta_id;
Eliad Pellerb92e6612014-01-23 17:58:23 +020075 u32 reserved_ids = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +010076
Eliad Pellerb92e6612014-01-23 17:58:23 +020077 BUILD_BUG_ON(IWL_MVM_STATION_COUNT > 32);
Johannes Berg8ca151b2013-01-24 14:25:36 +010078 WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status));
79
80 lockdep_assert_held(&mvm->mutex);
81
Eliad Pellerb92e6612014-01-23 17:58:23 +020082 /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */
83 if (iftype != NL80211_IFTYPE_STATION)
84 reserved_ids = BIT(0);
85
Johannes Berg8ca151b2013-01-24 14:25:36 +010086 /* Don't take rcu_read_lock() since we are protected by mvm->mutex */
Eliad Pellerb92e6612014-01-23 17:58:23 +020087 for (sta_id = 0; sta_id < IWL_MVM_STATION_COUNT; sta_id++) {
88 if (BIT(sta_id) & reserved_ids)
89 continue;
90
Johannes Berg8ca151b2013-01-24 14:25:36 +010091 if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
92 lockdep_is_held(&mvm->mutex)))
93 return sta_id;
Eliad Pellerb92e6612014-01-23 17:58:23 +020094 }
Johannes Berg8ca151b2013-01-24 14:25:36 +010095 return IWL_MVM_STATION_COUNT;
96}
97
Johannes Berg7a453972013-02-12 13:10:44 +010098/* send station add/update command to firmware */
99int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
100 bool update)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100101{
Johannes Berg9d8ce6a2014-12-23 16:02:40 +0100102 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbach4b8265a2014-07-13 08:58:04 +0300103 struct iwl_mvm_add_sta_cmd add_sta_cmd = {
104 .sta_id = mvm_sta->sta_id,
105 .mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color),
106 .add_modify = update ? 1 : 0,
107 .station_flags_msk = cpu_to_le32(STA_FLG_FAT_EN_MSK |
108 STA_FLG_MIMO_EN_MSK),
109 };
Johannes Berg8ca151b2013-01-24 14:25:36 +0100110 int ret;
111 u32 status;
112 u32 agg_size = 0, mpdu_dens = 0;
113
Johannes Berg7a453972013-02-12 13:10:44 +0100114 if (!update) {
115 add_sta_cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk);
116 memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN);
117 }
Johannes Berg5bc5aaa2013-02-12 14:35:36 +0100118
119 switch (sta->bandwidth) {
120 case IEEE80211_STA_RX_BW_160:
121 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_160MHZ);
122 /* fall through */
123 case IEEE80211_STA_RX_BW_80:
124 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_80MHZ);
125 /* fall through */
126 case IEEE80211_STA_RX_BW_40:
127 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_40MHZ);
128 /* fall through */
129 case IEEE80211_STA_RX_BW_20:
130 if (sta->ht_cap.ht_supported)
131 add_sta_cmd.station_flags |=
132 cpu_to_le32(STA_FLG_FAT_EN_20MHZ);
133 break;
134 }
135
136 switch (sta->rx_nss) {
137 case 1:
138 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO);
139 break;
140 case 2:
141 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2);
142 break;
143 case 3 ... 8:
144 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3);
145 break;
146 }
147
148 switch (sta->smps_mode) {
149 case IEEE80211_SMPS_AUTOMATIC:
150 case IEEE80211_SMPS_NUM_MODES:
151 WARN_ON(1);
152 break;
153 case IEEE80211_SMPS_STATIC:
154 /* override NSS */
155 add_sta_cmd.station_flags &= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK);
156 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO);
157 break;
158 case IEEE80211_SMPS_DYNAMIC:
159 add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_RTS_MIMO_PROT);
160 break;
161 case IEEE80211_SMPS_OFF:
162 /* nothing */
163 break;
164 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100165
166 if (sta->ht_cap.ht_supported) {
167 add_sta_cmd.station_flags_msk |=
168 cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK |
169 STA_FLG_AGG_MPDU_DENS_MSK);
170
171 mpdu_dens = sta->ht_cap.ampdu_density;
172 }
173
174 if (sta->vht_cap.vht_supported) {
175 agg_size = sta->vht_cap.cap &
176 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
177 agg_size >>=
178 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT;
179 } else if (sta->ht_cap.ht_supported) {
180 agg_size = sta->ht_cap.ampdu_factor;
181 }
182
183 add_sta_cmd.station_flags |=
184 cpu_to_le32(agg_size << STA_FLG_MAX_AGG_SIZE_SHIFT);
185 add_sta_cmd.station_flags |=
186 cpu_to_le32(mpdu_dens << STA_FLG_AGG_MPDU_DENS_SHIFT);
187
188 status = ADD_STA_SUCCESS;
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300189 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, sizeof(add_sta_cmd),
190 &add_sta_cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100191 if (ret)
192 return ret;
193
194 switch (status) {
195 case ADD_STA_SUCCESS:
196 IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n");
197 break;
198 default:
199 ret = -EIO;
200 IWL_ERR(mvm, "ADD_STA failed\n");
201 break;
202 }
203
204 return ret;
205}
206
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300207static int iwl_mvm_tdls_sta_init(struct iwl_mvm *mvm,
208 struct ieee80211_sta *sta)
209{
210 unsigned long used_hw_queues;
211 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbach4cf677f2015-01-12 14:38:29 +0200212 unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ?
213 mvm->cfg->base_params->wd_timeout :
214 IWL_WATCHDOG_DISABLED;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300215 u32 ac;
216
217 lockdep_assert_held(&mvm->mutex);
218
219 used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, NULL);
220
221 /* Find available queues, and allocate them to the ACs */
222 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
223 u8 queue = find_first_zero_bit(&used_hw_queues,
224 mvm->first_agg_queue);
225
226 if (queue >= mvm->first_agg_queue) {
227 IWL_ERR(mvm, "Failed to allocate STA queue\n");
228 return -EBUSY;
229 }
230
231 __set_bit(queue, &used_hw_queues);
232 mvmsta->hw_queue[ac] = queue;
233 }
234
235 /* Found a place for all queues - enable them */
236 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
237 iwl_mvm_enable_ac_txq(mvm, mvmsta->hw_queue[ac],
Emmanuel Grumbach4cf677f2015-01-12 14:38:29 +0200238 iwl_mvm_ac_to_tx_fifo[ac], wdg_timeout);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300239 mvmsta->tfd_queue_msk |= BIT(mvmsta->hw_queue[ac]);
240 }
241
242 return 0;
243}
244
245static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm *mvm,
246 struct ieee80211_sta *sta)
247{
248 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
249 unsigned long sta_msk;
250 int i;
251
252 lockdep_assert_held(&mvm->mutex);
253
254 /* disable the TDLS STA-specific queues */
255 sta_msk = mvmsta->tfd_queue_msk;
Emmanuel Grumbacha4ca3ed2015-01-20 17:07:10 +0200256 for_each_set_bit(i, &sta_msk, sizeof(sta_msk) * BITS_PER_BYTE)
Emmanuel Grumbach0294d9e2015-01-05 16:52:55 +0200257 iwl_mvm_disable_txq(mvm, i, 0);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300258}
259
Johannes Berg8ca151b2013-01-24 14:25:36 +0100260int iwl_mvm_add_sta(struct iwl_mvm *mvm,
261 struct ieee80211_vif *vif,
262 struct ieee80211_sta *sta)
263{
264 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +0100265 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100266 int i, ret, sta_id;
267
268 lockdep_assert_held(&mvm->mutex);
269
270 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
Eliad Pellerb92e6612014-01-23 17:58:23 +0200271 sta_id = iwl_mvm_find_free_sta_id(mvm,
272 ieee80211_vif_type_p2p(vif));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100273 else
274 sta_id = mvm_sta->sta_id;
275
276 if (WARN_ON_ONCE(sta_id == IWL_MVM_STATION_COUNT))
277 return -ENOSPC;
278
279 spin_lock_init(&mvm_sta->lock);
280
281 mvm_sta->sta_id = sta_id;
282 mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id,
283 mvmvif->color);
284 mvm_sta->vif = vif;
285 mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300286 mvm_sta->tx_protection = 0;
287 mvm_sta->tt_tx_protection = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100288
289 /* HW restart, don't assume the memory has been zeroed */
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +0300290 atomic_set(&mvm->pending_frames[sta_id], 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100291 mvm_sta->tid_disable_agg = 0;
292 mvm_sta->tfd_queue_msk = 0;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300293
294 /* allocate new queues for a TDLS station */
295 if (sta->tdls) {
296 ret = iwl_mvm_tdls_sta_init(mvm, sta);
297 if (ret)
298 return ret;
299 } else {
300 for (i = 0; i < IEEE80211_NUM_ACS; i++)
301 if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE)
302 mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]);
303 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100304
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200305 /* for HW restart - reset everything but the sequence number */
306 for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
307 u16 seq = mvm_sta->tid_data[i].seq_number;
308 memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i]));
309 mvm_sta->tid_data[i].seq_number = seq;
310 }
Eyal Shapiraefed6642014-09-14 15:58:53 +0300311 mvm_sta->agg_tids = 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100312
Johannes Berg7a453972013-02-12 13:10:44 +0100313 ret = iwl_mvm_sta_send_to_fw(mvm, sta, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100314 if (ret)
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300315 goto err;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100316
Johannes Berg9e848012014-08-04 14:33:42 +0200317 if (vif->type == NL80211_IFTYPE_STATION) {
318 if (!sta->tdls) {
319 WARN_ON(mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT);
320 mvmvif->ap_sta_id = sta_id;
321 } else {
322 WARN_ON(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT);
323 }
324 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100325
326 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta);
327
328 return 0;
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300329
330err:
331 iwl_mvm_tdls_sta_deinit(mvm, sta);
332 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100333}
334
Johannes Berg7a453972013-02-12 13:10:44 +0100335int iwl_mvm_update_sta(struct iwl_mvm *mvm,
336 struct ieee80211_vif *vif,
337 struct ieee80211_sta *sta)
338{
339 return iwl_mvm_sta_send_to_fw(mvm, sta, true);
340}
341
Johannes Berg8ca151b2013-01-24 14:25:36 +0100342int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta,
343 bool drain)
344{
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300345 struct iwl_mvm_add_sta_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100346 int ret;
347 u32 status;
348
349 lockdep_assert_held(&mvm->mutex);
350
351 cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color);
352 cmd.sta_id = mvmsta->sta_id;
353 cmd.add_modify = STA_MODE_MODIFY;
354 cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0;
355 cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW);
356
357 status = ADD_STA_SUCCESS;
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300358 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, sizeof(cmd),
359 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100360 if (ret)
361 return ret;
362
363 switch (status) {
364 case ADD_STA_SUCCESS:
365 IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n",
366 mvmsta->sta_id);
367 break;
368 default:
369 ret = -EIO;
370 IWL_ERR(mvm, "Couldn't drain frames for staid %d\n",
371 mvmsta->sta_id);
372 break;
373 }
374
375 return ret;
376}
377
378/*
379 * Remove a station from the FW table. Before sending the command to remove
380 * the station validate that the station is indeed known to the driver (sanity
381 * only).
382 */
383static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id)
384{
385 struct ieee80211_sta *sta;
386 struct iwl_mvm_rm_sta_cmd rm_sta_cmd = {
387 .sta_id = sta_id,
388 };
389 int ret;
390
391 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
392 lockdep_is_held(&mvm->mutex));
393
394 /* Note: internal stations are marked as error values */
395 if (!sta) {
396 IWL_ERR(mvm, "Invalid station id\n");
397 return -EINVAL;
398 }
399
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300400 ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100401 sizeof(rm_sta_cmd), &rm_sta_cmd);
402 if (ret) {
403 IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id);
404 return ret;
405 }
406
407 return 0;
408}
409
410void iwl_mvm_sta_drained_wk(struct work_struct *wk)
411{
412 struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk);
413 u8 sta_id;
414
415 /*
416 * The mutex is needed because of the SYNC cmd, but not only: if the
417 * work would run concurrently with iwl_mvm_rm_sta, it would run before
418 * iwl_mvm_rm_sta sets the station as busy, and exit. Then
419 * iwl_mvm_rm_sta would set the station as busy, and nobody will clean
420 * that later.
421 */
422 mutex_lock(&mvm->mutex);
423
424 for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) {
425 int ret;
426 struct ieee80211_sta *sta =
427 rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
428 lockdep_is_held(&mvm->mutex));
429
Johannes Berg1ddbbb02013-12-04 22:39:17 +0100430 /*
431 * This station is in use or RCU-removed; the latter happens in
432 * managed mode, where mac80211 removes the station before we
433 * can remove it from firmware (we can only do that after the
434 * MAC is marked unassociated), and possibly while the deauth
435 * frame to disconnect from the AP is still queued. Then, the
436 * station pointer is -ENOENT when the last skb is reclaimed.
437 */
438 if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100439 continue;
440
441 if (PTR_ERR(sta) == -EINVAL) {
442 IWL_ERR(mvm, "Drained sta %d, but it is internal?\n",
443 sta_id);
444 continue;
445 }
446
447 if (!sta) {
448 IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n",
449 sta_id);
450 continue;
451 }
452
453 WARN_ON(PTR_ERR(sta) != -EBUSY);
454 /* This station was removed and we waited until it got drained,
455 * we can now proceed and remove it.
456 */
457 ret = iwl_mvm_rm_sta_common(mvm, sta_id);
458 if (ret) {
459 IWL_ERR(mvm,
460 "Couldn't remove sta %d after it was drained\n",
461 sta_id);
462 continue;
463 }
Monam Agarwalc531c772014-03-24 00:05:56 +0530464 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100465 clear_bit(sta_id, mvm->sta_drained);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300466
467 if (mvm->tfd_drained[sta_id]) {
468 unsigned long i, msk = mvm->tfd_drained[sta_id];
469
Emmanuel Grumbacha4ca3ed2015-01-20 17:07:10 +0200470 for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE)
Emmanuel Grumbach0294d9e2015-01-05 16:52:55 +0200471 iwl_mvm_disable_txq(mvm, i, 0);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300472
473 mvm->tfd_drained[sta_id] = 0;
474 IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n",
475 sta_id, msk);
476 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100477 }
478
479 mutex_unlock(&mvm->mutex);
480}
481
482int iwl_mvm_rm_sta(struct iwl_mvm *mvm,
483 struct ieee80211_vif *vif,
484 struct ieee80211_sta *sta)
485{
486 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg9d8ce6a2014-12-23 16:02:40 +0100487 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100488 int ret;
489
490 lockdep_assert_held(&mvm->mutex);
491
492 if (vif->type == NL80211_IFTYPE_STATION &&
493 mvmvif->ap_sta_id == mvm_sta->sta_id) {
Emmanuel Grumbach80d85652013-02-19 15:32:42 +0200494 /* flush its queues here since we are freeing mvm_sta */
495 ret = iwl_mvm_flush_tx_path(mvm, mvm_sta->tfd_queue_msk, true);
496
Johannes Berg8ca151b2013-01-24 14:25:36 +0100497 /* if we are associated - we can't remove the AP STA now */
498 if (vif->bss_conf.assoc)
499 return ret;
500
501 /* unassoc - go ahead - remove the AP STA now */
502 mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT;
Eliad Peller37577fe2013-12-05 17:19:39 +0200503
504 /* clear d0i3_ap_sta_id if no longer relevant */
505 if (mvm->d0i3_ap_sta_id == mvm_sta->sta_id)
506 mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100507 }
508
509 /*
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +0300510 * This shouldn't happen - the TDLS channel switch should be canceled
511 * before the STA is removed.
512 */
513 if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == mvm_sta->sta_id)) {
514 mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT;
515 cancel_delayed_work(&mvm->tdls_cs.dwork);
516 }
517
518 /*
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +0300519 * Make sure that the tx response code sees the station as -EBUSY and
520 * calls the drain worker.
521 */
522 spin_lock_bh(&mvm_sta->lock);
523 /*
Johannes Berg8ca151b2013-01-24 14:25:36 +0100524 * There are frames pending on the AC queues for this station.
525 * We need to wait until all the frames are drained...
526 */
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +0300527 if (atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100528 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id],
529 ERR_PTR(-EBUSY));
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +0300530 spin_unlock_bh(&mvm_sta->lock);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300531
532 /* disable TDLS sta queues on drain complete */
533 if (sta->tdls) {
534 mvm->tfd_drained[mvm_sta->sta_id] =
535 mvm_sta->tfd_queue_msk;
536 IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n",
537 mvm_sta->sta_id);
538 }
539
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +0300540 ret = iwl_mvm_drain_sta(mvm, mvm_sta, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100541 } else {
Emmanuel Grumbache3d4bc82013-05-07 14:08:24 +0300542 spin_unlock_bh(&mvm_sta->lock);
Arik Nemtsova0f6bf22014-09-21 19:10:04 +0300543
544 if (sta->tdls)
545 iwl_mvm_tdls_sta_deinit(mvm, sta);
546
Johannes Berg8ca151b2013-01-24 14:25:36 +0100547 ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id);
Monam Agarwalc531c772014-03-24 00:05:56 +0530548 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100549 }
550
551 return ret;
552}
553
554int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm,
555 struct ieee80211_vif *vif,
556 u8 sta_id)
557{
558 int ret = iwl_mvm_rm_sta_common(mvm, sta_id);
559
560 lockdep_assert_held(&mvm->mutex);
561
Monam Agarwalc531c772014-03-24 00:05:56 +0530562 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100563 return ret;
564}
565
Johannes Berg712b24a2014-08-04 14:14:14 +0200566static int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm,
567 struct iwl_mvm_int_sta *sta,
568 u32 qmask, enum nl80211_iftype iftype)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100569{
570 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
Eliad Pellerb92e6612014-01-23 17:58:23 +0200571 sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100572 if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_STATION_COUNT))
573 return -ENOSPC;
574 }
575
576 sta->tfd_queue_msk = qmask;
577
578 /* put a non-NULL value so iterating over the stations won't stop */
579 rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL));
580 return 0;
581}
582
Johannes Berg712b24a2014-08-04 14:14:14 +0200583static void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm,
584 struct iwl_mvm_int_sta *sta)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100585{
Monam Agarwalc531c772014-03-24 00:05:56 +0530586 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta->sta_id], NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100587 memset(sta, 0, sizeof(struct iwl_mvm_int_sta));
588 sta->sta_id = IWL_MVM_STATION_COUNT;
589}
590
591static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm,
592 struct iwl_mvm_int_sta *sta,
593 const u8 *addr,
594 u16 mac_id, u16 color)
595{
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300596 struct iwl_mvm_add_sta_cmd cmd;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100597 int ret;
598 u32 status;
599
600 lockdep_assert_held(&mvm->mutex);
601
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300602 memset(&cmd, 0, sizeof(cmd));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100603 cmd.sta_id = sta->sta_id;
604 cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id,
605 color));
606
607 cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk);
608
609 if (addr)
610 memcpy(cmd.addr, addr, ETH_ALEN);
611
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300612 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, sizeof(cmd),
613 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100614 if (ret)
615 return ret;
616
617 switch (status) {
618 case ADD_STA_SUCCESS:
619 IWL_DEBUG_INFO(mvm, "Internal station added.\n");
620 return 0;
621 default:
622 ret = -EIO;
623 IWL_ERR(mvm, "Add internal station failed, status=0x%x\n",
624 status);
625 break;
626 }
627 return ret;
628}
629
630int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm)
631{
Emmanuel Grumbach4cf677f2015-01-12 14:38:29 +0200632 unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ?
633 mvm->cfg->base_params->wd_timeout :
634 IWL_WATCHDOG_DISABLED;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100635 int ret;
636
637 lockdep_assert_held(&mvm->mutex);
638
Ariej Marjieh7da91b02014-07-07 12:09:40 +0300639 /* Map Aux queue to fifo - needs to happen before adding Aux station */
Avri Altman3edf8ff2014-07-30 11:41:01 +0300640 iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue,
Emmanuel Grumbach4cf677f2015-01-12 14:38:29 +0200641 IWL_MVM_TX_FIFO_MCAST, wdg_timeout);
Ariej Marjieh7da91b02014-07-07 12:09:40 +0300642
643 /* Allocate aux station and assign to it the aux queue */
644 ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue),
Eliad Pellerb92e6612014-01-23 17:58:23 +0200645 NL80211_IFTYPE_UNSPECIFIED);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100646 if (ret)
647 return ret;
648
649 ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL,
650 MAC_INDEX_AUX, 0);
651
652 if (ret)
653 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
654 return ret;
655}
656
Johannes Berg712b24a2014-08-04 14:14:14 +0200657void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm)
658{
659 lockdep_assert_held(&mvm->mutex);
660
661 iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta);
662}
663
Johannes Berg8ca151b2013-01-24 14:25:36 +0100664/*
665 * Send the add station command for the vif's broadcast station.
666 * Assumes that the station was already allocated.
667 *
668 * @mvm: the mvm component
669 * @vif: the interface to which the broadcast station is added
670 * @bsta: the broadcast station to add.
671 */
Johannes Berg013290a2014-08-04 13:38:48 +0200672int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100673{
674 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg013290a2014-08-04 13:38:48 +0200675 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
Johannes Berg5023d962013-07-31 14:07:43 +0200676 static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
Johannes Berga4243402014-01-20 23:46:38 +0100677 const u8 *baddr = _baddr;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100678
679 lockdep_assert_held(&mvm->mutex);
680
Johannes Berg5023d962013-07-31 14:07:43 +0200681 if (vif->type == NL80211_IFTYPE_ADHOC)
682 baddr = vif->bss_conf.bssid;
683
Johannes Berg8ca151b2013-01-24 14:25:36 +0100684 if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_STATION_COUNT))
685 return -ENOSPC;
686
687 return iwl_mvm_add_int_sta_common(mvm, bsta, baddr,
688 mvmvif->id, mvmvif->color);
689}
690
691/* Send the FW a request to remove the station from it's internal data
692 * structures, but DO NOT remove the entry from the local data structures. */
Johannes Berg013290a2014-08-04 13:38:48 +0200693int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100694{
Johannes Berg013290a2014-08-04 13:38:48 +0200695 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100696 int ret;
697
698 lockdep_assert_held(&mvm->mutex);
699
Johannes Berg013290a2014-08-04 13:38:48 +0200700 ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100701 if (ret)
702 IWL_WARN(mvm, "Failed sending remove station\n");
703 return ret;
704}
705
Johannes Berg013290a2014-08-04 13:38:48 +0200706int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
707{
708 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
709 u32 qmask;
710
711 lockdep_assert_held(&mvm->mutex);
712
Arik Nemtsovd92b732e2014-09-21 19:00:42 +0300713 qmask = iwl_mvm_mac_get_queues_mask(vif);
Johannes Berg013290a2014-08-04 13:38:48 +0200714
715 /*
716 * The firmware defines the TFD queue mask to only be relevant
717 * for *unicast* queues, so the multicast (CAB) queue shouldn't
718 * be included.
719 */
720 if (vif->type == NL80211_IFTYPE_AP)
721 qmask &= ~BIT(vif->cab_queue);
722
723 return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask,
724 ieee80211_vif_type_p2p(vif));
725}
726
Johannes Berg8ca151b2013-01-24 14:25:36 +0100727/* Allocate a new station entry for the broadcast station to the given vif,
728 * and send it to the FW.
729 * Note that each P2P mac should have its own broadcast station.
730 *
731 * @mvm: the mvm component
732 * @vif: the interface to which the broadcast station is added
733 * @bsta: the broadcast station to add. */
Johannes Berg013290a2014-08-04 13:38:48 +0200734int iwl_mvm_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100735{
736 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg013290a2014-08-04 13:38:48 +0200737 struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100738 int ret;
739
740 lockdep_assert_held(&mvm->mutex);
741
Johannes Berg013290a2014-08-04 13:38:48 +0200742 ret = iwl_mvm_alloc_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100743 if (ret)
744 return ret;
745
Johannes Berg013290a2014-08-04 13:38:48 +0200746 ret = iwl_mvm_send_add_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100747
748 if (ret)
749 iwl_mvm_dealloc_int_sta(mvm, bsta);
Johannes Berg013290a2014-08-04 13:38:48 +0200750
Johannes Berg8ca151b2013-01-24 14:25:36 +0100751 return ret;
752}
753
Johannes Berg013290a2014-08-04 13:38:48 +0200754void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
755{
756 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
757
758 iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta);
759}
760
Johannes Berg8ca151b2013-01-24 14:25:36 +0100761/*
762 * Send the FW a request to remove the station from it's internal data
763 * structures, and in addition remove it from the local data structure.
764 */
Johannes Berg013290a2014-08-04 13:38:48 +0200765int iwl_mvm_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100766{
767 int ret;
768
769 lockdep_assert_held(&mvm->mutex);
770
Johannes Berg013290a2014-08-04 13:38:48 +0200771 ret = iwl_mvm_send_rm_bcast_sta(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100772
Johannes Berg013290a2014-08-04 13:38:48 +0200773 iwl_mvm_dealloc_bcast_sta(mvm, vif);
774
Johannes Berg8ca151b2013-01-24 14:25:36 +0100775 return ret;
776}
777
Emmanuel Grumbach113a0442013-07-02 14:16:38 +0300778#define IWL_MAX_RX_BA_SESSIONS 16
779
Johannes Berg8ca151b2013-01-24 14:25:36 +0100780int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
781 int tid, u16 ssn, bool start)
782{
Johannes Berg9d8ce6a2014-12-23 16:02:40 +0100783 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300784 struct iwl_mvm_add_sta_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100785 int ret;
786 u32 status;
787
788 lockdep_assert_held(&mvm->mutex);
789
Emmanuel Grumbach113a0442013-07-02 14:16:38 +0300790 if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) {
791 IWL_WARN(mvm, "Not enough RX BA SESSIONS\n");
792 return -ENOSPC;
793 }
794
Johannes Berg8ca151b2013-01-24 14:25:36 +0100795 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
796 cmd.sta_id = mvm_sta->sta_id;
797 cmd.add_modify = STA_MODE_MODIFY;
Emmanuel Grumbach93a42662013-07-02 13:35:35 +0300798 if (start) {
799 cmd.add_immediate_ba_tid = (u8) tid;
800 cmd.add_immediate_ba_ssn = cpu_to_le16(ssn);
801 } else {
802 cmd.remove_immediate_ba_tid = (u8) tid;
803 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100804 cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID :
805 STA_MODIFY_REMOVE_BA_TID;
806
807 status = ADD_STA_SUCCESS;
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300808 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, sizeof(cmd),
809 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100810 if (ret)
811 return ret;
812
813 switch (status) {
814 case ADD_STA_SUCCESS:
815 IWL_DEBUG_INFO(mvm, "RX BA Session %sed in fw\n",
816 start ? "start" : "stopp");
817 break;
818 case ADD_STA_IMMEDIATE_BA_FAILURE:
819 IWL_WARN(mvm, "RX BA Session refused by fw\n");
820 ret = -ENOSPC;
821 break;
822 default:
823 ret = -EIO;
824 IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n",
825 start ? "start" : "stopp", status);
826 break;
827 }
828
Emmanuel Grumbach113a0442013-07-02 14:16:38 +0300829 if (!ret) {
830 if (start)
831 mvm->rx_ba_sessions++;
832 else if (mvm->rx_ba_sessions > 0)
833 /* check that restart flow didn't zero the counter */
834 mvm->rx_ba_sessions--;
835 }
836
Johannes Berg8ca151b2013-01-24 14:25:36 +0100837 return ret;
838}
839
840static int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta,
841 int tid, u8 queue, bool start)
842{
Johannes Berg9d8ce6a2014-12-23 16:02:40 +0100843 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300844 struct iwl_mvm_add_sta_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100845 int ret;
846 u32 status;
847
848 lockdep_assert_held(&mvm->mutex);
849
850 if (start) {
851 mvm_sta->tfd_queue_msk |= BIT(queue);
852 mvm_sta->tid_disable_agg &= ~BIT(tid);
853 } else {
854 mvm_sta->tfd_queue_msk &= ~BIT(queue);
855 mvm_sta->tid_disable_agg |= BIT(tid);
856 }
857
858 cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color);
859 cmd.sta_id = mvm_sta->sta_id;
860 cmd.add_modify = STA_MODE_MODIFY;
861 cmd.modify_mask = STA_MODIFY_QUEUES | STA_MODIFY_TID_DISABLE_TX;
862 cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk);
863 cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg);
864
865 status = ADD_STA_SUCCESS;
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +0300866 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, sizeof(cmd),
867 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100868 if (ret)
869 return ret;
870
871 switch (status) {
872 case ADD_STA_SUCCESS:
873 break;
874 default:
875 ret = -EIO;
876 IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n",
877 start ? "start" : "stopp", status);
878 break;
879 }
880
881 return ret;
882}
883
Emmanuel Grumbachb797e3f2014-03-06 14:49:36 +0200884const u8 tid_to_mac80211_ac[] = {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100885 IEEE80211_AC_BE,
886 IEEE80211_AC_BK,
887 IEEE80211_AC_BK,
888 IEEE80211_AC_BE,
889 IEEE80211_AC_VI,
890 IEEE80211_AC_VI,
891 IEEE80211_AC_VO,
892 IEEE80211_AC_VO,
893};
894
Johannes Berg3e56ead2013-02-15 22:23:18 +0100895static const u8 tid_to_ucode_ac[] = {
896 AC_BE,
897 AC_BK,
898 AC_BK,
899 AC_BE,
900 AC_VI,
901 AC_VI,
902 AC_VO,
903 AC_VO,
904};
905
Johannes Berg8ca151b2013-01-24 14:25:36 +0100906int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
907 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
908{
Johannes Berg5b577a92013-11-14 18:20:04 +0100909 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100910 struct iwl_mvm_tid_data *tid_data;
911 int txq_id;
912
913 if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT))
914 return -EINVAL;
915
916 if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) {
917 IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n",
918 mvmsta->tid_data[tid].state);
919 return -ENXIO;
920 }
921
922 lockdep_assert_held(&mvm->mutex);
923
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200924 for (txq_id = mvm->first_agg_queue;
925 txq_id <= mvm->last_agg_queue; txq_id++)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100926 if (mvm->queue_to_mac80211[txq_id] ==
927 IWL_INVALID_MAC80211_QUEUE)
928 break;
929
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200930 if (txq_id > mvm->last_agg_queue) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100931 IWL_ERR(mvm, "Failed to allocate agg queue\n");
932 return -EIO;
933 }
934
Arik Nemtsovb2492502014-03-13 12:21:50 +0200935 spin_lock_bh(&mvmsta->lock);
936
937 /* possible race condition - we entered D0i3 while starting agg */
938 if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) {
939 spin_unlock_bh(&mvmsta->lock);
940 IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n");
941 return -EIO;
942 }
943
Johannes Berg8ca151b2013-01-24 14:25:36 +0100944 /* the new tx queue is still connected to the same mac80211 queue */
Johannes Berg3e56ead2013-02-15 22:23:18 +0100945 mvm->queue_to_mac80211[txq_id] = vif->hw_queue[tid_to_mac80211_ac[tid]];
Johannes Berg8ca151b2013-01-24 14:25:36 +0100946
Johannes Berg8ca151b2013-01-24 14:25:36 +0100947 tid_data = &mvmsta->tid_data[tid];
Johannes Berg9a886582013-02-15 19:25:00 +0100948 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100949 tid_data->txq_id = txq_id;
950 *ssn = tid_data->ssn;
951
952 IWL_DEBUG_TX_QUEUES(mvm,
953 "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n",
954 mvmsta->sta_id, tid, txq_id, tid_data->ssn,
955 tid_data->next_reclaimed);
956
957 if (tid_data->ssn == tid_data->next_reclaimed) {
958 tid_data->state = IWL_AGG_STARTING;
959 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
960 } else {
961 tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA;
962 }
963
964 spin_unlock_bh(&mvmsta->lock);
965
966 return 0;
967}
968
969int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
970 struct ieee80211_sta *sta, u16 tid, u8 buf_size)
971{
Johannes Berg5b577a92013-11-14 18:20:04 +0100972 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100973 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
Emmanuel Grumbach4cf677f2015-01-12 14:38:29 +0200974 unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ?
975 mvm->cfg->base_params->wd_timeout :
976 IWL_WATCHDOG_DISABLED;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100977 int queue, fifo, ret;
978 u16 ssn;
979
Eyal Shapiraefed6642014-09-14 15:58:53 +0300980 BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE)
981 != IWL_MAX_TID_COUNT);
982
Johannes Berg8ca151b2013-01-24 14:25:36 +0100983 buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
984
985 spin_lock_bh(&mvmsta->lock);
986 ssn = tid_data->ssn;
987 queue = tid_data->txq_id;
988 tid_data->state = IWL_AGG_ON;
Eyal Shapiraefed6642014-09-14 15:58:53 +0300989 mvmsta->agg_tids |= BIT(tid);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100990 tid_data->ssn = 0xffff;
991 spin_unlock_bh(&mvmsta->lock);
992
Johannes Berg3e56ead2013-02-15 22:23:18 +0100993 fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]];
Johannes Berg8ca151b2013-01-24 14:25:36 +0100994
995 ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true);
996 if (ret)
997 return -EIO;
998
Avri Altman3edf8ff2014-07-30 11:41:01 +0300999 iwl_mvm_enable_agg_txq(mvm, queue, fifo, mvmsta->sta_id, tid,
Emmanuel Grumbach4cf677f2015-01-12 14:38:29 +02001000 buf_size, ssn, wdg_timeout);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001001
1002 /*
1003 * Even though in theory the peer could have different
1004 * aggregation reorder buffer sizes for different sessions,
1005 * our ucode doesn't allow for that and has a global limit
1006 * for each station. Therefore, use the minimum of all the
1007 * aggregation sessions and our default value.
1008 */
1009 mvmsta->max_agg_bufsize =
1010 min(mvmsta->max_agg_bufsize, buf_size);
1011 mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize;
1012
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +03001013 IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n",
1014 sta->addr, tid);
1015
Eyal Shapira9e680942013-11-09 00:16:16 +02001016 return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001017}
1018
1019int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1020 struct ieee80211_sta *sta, u16 tid)
1021{
Johannes Berg5b577a92013-11-14 18:20:04 +01001022 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001023 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
1024 u16 txq_id;
1025 int err;
1026
Emmanuel Grumbachf9aa8dd2013-03-04 09:11:08 +02001027
1028 /*
1029 * If mac80211 is cleaning its state, then say that we finished since
1030 * our state has been cleared anyway.
1031 */
1032 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1033 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1034 return 0;
1035 }
1036
Johannes Berg8ca151b2013-01-24 14:25:36 +01001037 spin_lock_bh(&mvmsta->lock);
1038
1039 txq_id = tid_data->txq_id;
1040
1041 IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n",
1042 mvmsta->sta_id, tid, txq_id, tid_data->state);
1043
Eyal Shapiraefed6642014-09-14 15:58:53 +03001044 mvmsta->agg_tids &= ~BIT(tid);
1045
Johannes Berg8ca151b2013-01-24 14:25:36 +01001046 switch (tid_data->state) {
1047 case IWL_AGG_ON:
Johannes Berg9a886582013-02-15 19:25:00 +01001048 tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001049
1050 IWL_DEBUG_TX_QUEUES(mvm,
1051 "ssn = %d, next_recl = %d\n",
1052 tid_data->ssn, tid_data->next_reclaimed);
1053
1054 /* There are still packets for this RA / TID in the HW */
1055 if (tid_data->ssn != tid_data->next_reclaimed) {
1056 tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA;
1057 err = 0;
1058 break;
1059 }
1060
1061 tid_data->ssn = 0xffff;
Johannes Bergf7f89e72014-08-05 15:24:44 +02001062 tid_data->state = IWL_AGG_OFF;
1063 mvm->queue_to_mac80211[txq_id] = IWL_INVALID_MAC80211_QUEUE;
1064 spin_unlock_bh(&mvmsta->lock);
1065
1066 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1067
1068 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
1069
Emmanuel Grumbach0294d9e2015-01-05 16:52:55 +02001070 iwl_mvm_disable_txq(mvm, txq_id, 0);
Johannes Bergf7f89e72014-08-05 15:24:44 +02001071 return 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001072 case IWL_AGG_STARTING:
1073 case IWL_EMPTYING_HW_QUEUE_ADDBA:
1074 /*
1075 * The agg session has been stopped before it was set up. This
1076 * can happen when the AddBA timer times out for example.
1077 */
1078
1079 /* No barriers since we are under mutex */
1080 lockdep_assert_held(&mvm->mutex);
1081 mvm->queue_to_mac80211[txq_id] = IWL_INVALID_MAC80211_QUEUE;
1082
1083 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1084 tid_data->state = IWL_AGG_OFF;
1085 err = 0;
1086 break;
1087 default:
1088 IWL_ERR(mvm,
1089 "Stopping AGG while state not ON or starting for %d on %d (%d)\n",
1090 mvmsta->sta_id, tid, tid_data->state);
1091 IWL_ERR(mvm,
1092 "\ttid_data->txq_id = %d\n", tid_data->txq_id);
1093 err = -EINVAL;
1094 }
1095
1096 spin_unlock_bh(&mvmsta->lock);
1097
1098 return err;
1099}
1100
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02001101int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1102 struct ieee80211_sta *sta, u16 tid)
1103{
Johannes Berg5b577a92013-11-14 18:20:04 +01001104 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02001105 struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
1106 u16 txq_id;
Johannes Bergb6658ff2013-07-24 13:55:51 +02001107 enum iwl_mvm_agg_state old_state;
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02001108
1109 /*
1110 * First set the agg state to OFF to avoid calling
1111 * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty.
1112 */
1113 spin_lock_bh(&mvmsta->lock);
1114 txq_id = tid_data->txq_id;
1115 IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n",
1116 mvmsta->sta_id, tid, txq_id, tid_data->state);
Johannes Bergb6658ff2013-07-24 13:55:51 +02001117 old_state = tid_data->state;
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02001118 tid_data->state = IWL_AGG_OFF;
Eyal Shapiraefed6642014-09-14 15:58:53 +03001119 mvmsta->agg_tids &= ~BIT(tid);
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02001120 spin_unlock_bh(&mvmsta->lock);
1121
Johannes Bergb6658ff2013-07-24 13:55:51 +02001122 if (old_state >= IWL_AGG_ON) {
1123 if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), true))
1124 IWL_ERR(mvm, "Couldn't flush the AGG queue\n");
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02001125
Johannes Bergf7f89e72014-08-05 15:24:44 +02001126 iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false);
1127
Emmanuel Grumbach0294d9e2015-01-05 16:52:55 +02001128 iwl_mvm_disable_txq(mvm, tid_data->txq_id, 0);
Johannes Bergb6658ff2013-07-24 13:55:51 +02001129 }
1130
Emmanuel Grumbache3d9e7c2013-02-19 16:13:53 +02001131 mvm->queue_to_mac80211[tid_data->txq_id] =
1132 IWL_INVALID_MAC80211_QUEUE;
1133
1134 return 0;
1135}
1136
Johannes Berg8ca151b2013-01-24 14:25:36 +01001137static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm)
1138{
1139 int i;
1140
1141 lockdep_assert_held(&mvm->mutex);
1142
1143 i = find_first_zero_bit(mvm->fw_key_table, STA_KEY_MAX_NUM);
1144
1145 if (i == STA_KEY_MAX_NUM)
1146 return STA_KEY_IDX_INVALID;
1147
1148 __set_bit(i, mvm->fw_key_table);
1149
1150 return i;
1151}
1152
1153static u8 iwl_mvm_get_key_sta_id(struct ieee80211_vif *vif,
1154 struct ieee80211_sta *sta)
1155{
Johannes Berg5b530e92014-12-23 16:00:17 +01001156 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001157
1158 if (sta) {
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01001159 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001160
1161 return mvm_sta->sta_id;
1162 }
1163
1164 /*
1165 * The device expects GTKs for station interfaces to be
1166 * installed as GTKs for the AP station. If we have no
1167 * station ID, then use AP's station ID.
1168 */
1169 if (vif->type == NL80211_IFTYPE_STATION &&
1170 mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT)
1171 return mvmvif->ap_sta_id;
1172
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02001173 return IWL_MVM_STATION_COUNT;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001174}
1175
1176static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm,
1177 struct iwl_mvm_sta *mvm_sta,
Johannes Bergba3943b2014-11-12 23:54:48 +01001178 struct ieee80211_key_conf *keyconf, bool mcast,
Johannes Berg2f6319d2014-11-12 23:39:56 +01001179 u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001180{
Max Stepanov5a258aa2013-04-07 09:11:21 +03001181 struct iwl_mvm_add_sta_key_cmd cmd = {};
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001182 __le16 key_flags;
Johannes Berg79920742014-11-03 15:43:04 +01001183 int ret;
1184 u32 status;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001185 u16 keyidx;
1186 int i;
Johannes Berg2f6319d2014-11-12 23:39:56 +01001187 u8 sta_id = mvm_sta->sta_id;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001188
1189 keyidx = (keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
1190 STA_KEY_FLG_KEYID_MSK;
1191 key_flags = cpu_to_le16(keyidx);
1192 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP);
1193
1194 switch (keyconf->cipher) {
1195 case WLAN_CIPHER_SUITE_TKIP:
1196 key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP);
Max Stepanov5a258aa2013-04-07 09:11:21 +03001197 cmd.tkip_rx_tsc_byte2 = tkip_iv32;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001198 for (i = 0; i < 5; i++)
Max Stepanov5a258aa2013-04-07 09:11:21 +03001199 cmd.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]);
1200 memcpy(cmd.key, keyconf->key, keyconf->keylen);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001201 break;
1202 case WLAN_CIPHER_SUITE_CCMP:
1203 key_flags |= cpu_to_le16(STA_KEY_FLG_CCM);
Max Stepanov5a258aa2013-04-07 09:11:21 +03001204 memcpy(cmd.key, keyconf->key, keyconf->keylen);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001205 break;
Johannes Bergba3943b2014-11-12 23:54:48 +01001206 case WLAN_CIPHER_SUITE_WEP104:
1207 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES);
John W. Linvilleaa0cb082015-01-12 16:18:11 -05001208 /* fall through */
Johannes Bergba3943b2014-11-12 23:54:48 +01001209 case WLAN_CIPHER_SUITE_WEP40:
1210 key_flags |= cpu_to_le16(STA_KEY_FLG_WEP);
1211 memcpy(cmd.key + 3, keyconf->key, keyconf->keylen);
1212 break;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001213 default:
Max Stepanove36e5432013-08-27 19:56:13 +03001214 key_flags |= cpu_to_le16(STA_KEY_FLG_EXT);
1215 memcpy(cmd.key, keyconf->key, keyconf->keylen);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001216 }
1217
Johannes Bergba3943b2014-11-12 23:54:48 +01001218 if (mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001219 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
1220
Max Stepanov5a258aa2013-04-07 09:11:21 +03001221 cmd.key_offset = keyconf->hw_key_idx;
1222 cmd.key_flags = key_flags;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001223 cmd.sta_id = sta_id;
1224
1225 status = ADD_STA_SUCCESS;
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001226 if (cmd_flags & CMD_ASYNC)
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001227 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC,
1228 sizeof(cmd), &cmd);
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001229 else
1230 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd),
1231 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001232
1233 switch (status) {
1234 case ADD_STA_SUCCESS:
1235 IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n");
1236 break;
1237 default:
1238 ret = -EIO;
1239 IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n");
1240 break;
1241 }
1242
1243 return ret;
1244}
1245
1246static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm,
1247 struct ieee80211_key_conf *keyconf,
1248 u8 sta_id, bool remove_key)
1249{
1250 struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {};
1251
1252 /* verify the key details match the required command's expectations */
1253 if (WARN_ON((keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC) ||
1254 (keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) ||
1255 (keyconf->keyidx != 4 && keyconf->keyidx != 5)))
1256 return -EINVAL;
1257
1258 igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx);
1259 igtk_cmd.sta_id = cpu_to_le32(sta_id);
1260
1261 if (remove_key) {
1262 igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID);
1263 } else {
1264 struct ieee80211_key_seq seq;
1265 const u8 *pn;
1266
1267 memcpy(igtk_cmd.IGTK, keyconf->key, keyconf->keylen);
1268 ieee80211_aes_cmac_calculate_k1_k2(keyconf,
1269 igtk_cmd.K1, igtk_cmd.K2);
1270 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
1271 pn = seq.aes_cmac.pn;
1272 igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) |
1273 ((u64) pn[4] << 8) |
1274 ((u64) pn[3] << 16) |
1275 ((u64) pn[2] << 24) |
1276 ((u64) pn[1] << 32) |
1277 ((u64) pn[0] << 40));
1278 }
1279
1280 IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n",
1281 remove_key ? "removing" : "installing",
1282 igtk_cmd.sta_id);
1283
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001284 return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001285 sizeof(igtk_cmd), &igtk_cmd);
1286}
1287
1288
1289static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm,
1290 struct ieee80211_vif *vif,
1291 struct ieee80211_sta *sta)
1292{
Johannes Berg5b530e92014-12-23 16:00:17 +01001293 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001294
1295 if (sta)
1296 return sta->addr;
1297
1298 if (vif->type == NL80211_IFTYPE_STATION &&
1299 mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) {
1300 u8 sta_id = mvmvif->ap_sta_id;
1301 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1302 lockdep_is_held(&mvm->mutex));
1303 return sta->addr;
1304 }
1305
1306
1307 return NULL;
1308}
1309
Johannes Berg2f6319d2014-11-12 23:39:56 +01001310static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
1311 struct ieee80211_vif *vif,
1312 struct ieee80211_sta *sta,
Johannes Bergba3943b2014-11-12 23:54:48 +01001313 struct ieee80211_key_conf *keyconf,
1314 bool mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001315{
Johannes Berg2f6319d2014-11-12 23:39:56 +01001316 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001317 int ret;
Johannes Berg2f6319d2014-11-12 23:39:56 +01001318 const u8 *addr;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001319 struct ieee80211_key_seq seq;
1320 u16 p1k[5];
1321
Johannes Berg8ca151b2013-01-24 14:25:36 +01001322 switch (keyconf->cipher) {
1323 case WLAN_CIPHER_SUITE_TKIP:
1324 addr = iwl_mvm_get_mac_addr(mvm, vif, sta);
1325 /* get phase 1 key from mac80211 */
1326 ieee80211_get_key_rx_seq(keyconf, 0, &seq);
1327 ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k);
Johannes Bergba3943b2014-11-12 23:54:48 +01001328 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001329 seq.tkip.iv32, p1k, 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001330 break;
1331 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergba3943b2014-11-12 23:54:48 +01001332 case WLAN_CIPHER_SUITE_WEP40:
1333 case WLAN_CIPHER_SUITE_WEP104:
1334 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001335 0, NULL, 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001336 break;
1337 default:
Johannes Bergba3943b2014-11-12 23:54:48 +01001338 ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
Johannes Berg2f6319d2014-11-12 23:39:56 +01001339 0, NULL, 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001340 }
1341
Johannes Berg8ca151b2013-01-24 14:25:36 +01001342 return ret;
1343}
1344
Johannes Berg2f6319d2014-11-12 23:39:56 +01001345static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id,
Johannes Bergba3943b2014-11-12 23:54:48 +01001346 struct ieee80211_key_conf *keyconf,
1347 bool mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001348{
Max Stepanov5a258aa2013-04-07 09:11:21 +03001349 struct iwl_mvm_add_sta_key_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +01001350 __le16 key_flags;
Johannes Berg79920742014-11-03 15:43:04 +01001351 int ret;
1352 u32 status;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001353
Emmanuel Grumbach8115efb2013-02-05 10:08:35 +02001354 key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) &
1355 STA_KEY_FLG_KEYID_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001356 key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP);
1357 key_flags |= cpu_to_le16(STA_KEY_NOT_VALID);
1358
Johannes Bergba3943b2014-11-12 23:54:48 +01001359 if (mcast)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001360 key_flags |= cpu_to_le16(STA_KEY_MULTICAST);
1361
Max Stepanov5a258aa2013-04-07 09:11:21 +03001362 cmd.key_flags = key_flags;
1363 cmd.key_offset = keyconf->hw_key_idx;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001364 cmd.sta_id = sta_id;
1365
Johannes Berg8ca151b2013-01-24 14:25:36 +01001366 status = ADD_STA_SUCCESS;
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001367 ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd),
1368 &cmd, &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001369
1370 switch (status) {
1371 case ADD_STA_SUCCESS:
1372 IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n");
1373 break;
1374 default:
1375 ret = -EIO;
1376 IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n");
1377 break;
1378 }
1379
1380 return ret;
1381}
1382
Johannes Berg2f6319d2014-11-12 23:39:56 +01001383int iwl_mvm_set_sta_key(struct iwl_mvm *mvm,
1384 struct ieee80211_vif *vif,
1385 struct ieee80211_sta *sta,
1386 struct ieee80211_key_conf *keyconf,
1387 bool have_key_offset)
1388{
Johannes Bergba3943b2014-11-12 23:54:48 +01001389 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
Johannes Berg2f6319d2014-11-12 23:39:56 +01001390 u8 sta_id;
1391 int ret;
1392
1393 lockdep_assert_held(&mvm->mutex);
1394
1395 /* Get the station id from the mvm local station table */
1396 sta_id = iwl_mvm_get_key_sta_id(vif, sta);
1397 if (sta_id == IWL_MVM_STATION_COUNT) {
1398 IWL_ERR(mvm, "Failed to find station id\n");
1399 return -EINVAL;
1400 }
1401
1402 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC) {
1403 ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false);
1404 goto end;
1405 }
1406
1407 /*
1408 * It is possible that the 'sta' parameter is NULL, and thus
1409 * there is a need to retrieve the sta from the local station table.
1410 */
1411 if (!sta) {
1412 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1413 lockdep_is_held(&mvm->mutex));
1414 if (IS_ERR_OR_NULL(sta)) {
1415 IWL_ERR(mvm, "Invalid station id\n");
1416 return -EINVAL;
1417 }
1418 }
1419
1420 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif))
1421 return -EINVAL;
1422
1423 if (!have_key_offset) {
1424 /*
1425 * The D3 firmware hardcodes the PTK offset to 0, so we have to
1426 * configure it there. As a result, this workaround exists to
1427 * let the caller set the key offset (hw_key_idx), see d3.c.
1428 */
1429 keyconf->hw_key_idx = iwl_mvm_set_fw_key_idx(mvm);
1430 if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID)
1431 return -ENOSPC;
1432 }
1433
Johannes Bergba3943b2014-11-12 23:54:48 +01001434 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, mcast);
1435 if (ret) {
Johannes Berg2f6319d2014-11-12 23:39:56 +01001436 __clear_bit(keyconf->hw_key_idx, mvm->fw_key_table);
Johannes Bergba3943b2014-11-12 23:54:48 +01001437 goto end;
1438 }
1439
1440 /*
1441 * For WEP, the same key is used for multicast and unicast. Upload it
1442 * again, using the same key offset, and now pointing the other one
1443 * to the same key slot (offset).
1444 * If this fails, remove the original as well.
1445 */
1446 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
1447 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) {
1448 ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, !mcast);
1449 if (ret) {
1450 __clear_bit(keyconf->hw_key_idx, mvm->fw_key_table);
1451 __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
1452 }
1453 }
Johannes Berg2f6319d2014-11-12 23:39:56 +01001454
1455end:
1456 IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
1457 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
1458 sta->addr, ret);
1459 return ret;
1460}
1461
1462int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm,
1463 struct ieee80211_vif *vif,
1464 struct ieee80211_sta *sta,
1465 struct ieee80211_key_conf *keyconf)
1466{
Johannes Bergba3943b2014-11-12 23:54:48 +01001467 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
Johannes Berg2f6319d2014-11-12 23:39:56 +01001468 u8 sta_id;
Johannes Bergba3943b2014-11-12 23:54:48 +01001469 int ret;
Johannes Berg2f6319d2014-11-12 23:39:56 +01001470
1471 lockdep_assert_held(&mvm->mutex);
1472
1473 /* Get the station id from the mvm local station table */
1474 sta_id = iwl_mvm_get_key_sta_id(vif, sta);
1475
1476 IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n",
1477 keyconf->keyidx, sta_id);
1478
1479 if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC)
1480 return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true);
1481
1482 if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) {
1483 IWL_ERR(mvm, "offset %d not used in fw key table.\n",
1484 keyconf->hw_key_idx);
1485 return -ENOENT;
1486 }
1487
1488 if (sta_id == IWL_MVM_STATION_COUNT) {
1489 IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n");
1490 return 0;
1491 }
1492
1493 /*
1494 * It is possible that the 'sta' parameter is NULL, and thus
1495 * there is a need to retrieve the sta from the local station table,
1496 * for example when a GTK is removed (where the sta_id will then be
1497 * the AP ID, and no station was passed by mac80211.)
1498 */
1499 if (!sta) {
1500 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id],
1501 lockdep_is_held(&mvm->mutex));
1502 if (!sta) {
1503 IWL_ERR(mvm, "Invalid station id\n");
1504 return -EINVAL;
1505 }
1506 }
1507
1508 if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif))
1509 return -EINVAL;
1510
Johannes Bergba3943b2014-11-12 23:54:48 +01001511 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast);
1512 if (ret)
1513 return ret;
1514
1515 /* delete WEP key twice to get rid of (now useless) offset */
1516 if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 ||
1517 keyconf->cipher == WLAN_CIPHER_SUITE_WEP104)
1518 ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast);
1519
1520 return ret;
Johannes Berg2f6319d2014-11-12 23:39:56 +01001521}
1522
Johannes Berg8ca151b2013-01-24 14:25:36 +01001523void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm,
1524 struct ieee80211_vif *vif,
1525 struct ieee80211_key_conf *keyconf,
1526 struct ieee80211_sta *sta, u32 iv32,
1527 u16 *phase1key)
1528{
Beni Levc3eb5362013-02-06 17:22:18 +02001529 struct iwl_mvm_sta *mvm_sta;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001530 u8 sta_id = iwl_mvm_get_key_sta_id(vif, sta);
Johannes Bergba3943b2014-11-12 23:54:48 +01001531 bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001532
Emmanuel Grumbach881acd82013-03-19 16:16:00 +02001533 if (WARN_ON_ONCE(sta_id == IWL_MVM_STATION_COUNT))
Johannes Berg8ca151b2013-01-24 14:25:36 +01001534 return;
1535
Beni Levc3eb5362013-02-06 17:22:18 +02001536 rcu_read_lock();
1537
1538 if (!sta) {
1539 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1540 if (WARN_ON(IS_ERR_OR_NULL(sta))) {
1541 rcu_read_unlock();
1542 return;
1543 }
1544 }
1545
Johannes Berg2f6319d2014-11-12 23:39:56 +01001546 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
Johannes Bergba3943b2014-11-12 23:54:48 +01001547 iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001548 iv32, phase1key, CMD_ASYNC);
Beni Levc3eb5362013-02-06 17:22:18 +02001549 rcu_read_unlock();
Johannes Berg8ca151b2013-01-24 14:25:36 +01001550}
1551
Johannes Berg9cc40712013-02-15 22:47:48 +01001552void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm,
1553 struct ieee80211_sta *sta)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001554{
Johannes Berg5b577a92013-11-14 18:20:04 +01001555 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001556 struct iwl_mvm_add_sta_cmd cmd = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001557 .add_modify = STA_MODE_MODIFY,
Johannes Berg9cc40712013-02-15 22:47:48 +01001558 .sta_id = mvmsta->sta_id,
Emmanuel Grumbach5af01772013-06-09 12:59:24 +03001559 .station_flags_msk = cpu_to_le32(STA_FLG_PS),
Johannes Berg9cc40712013-02-15 22:47:48 +01001560 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
Johannes Berg8ca151b2013-01-24 14:25:36 +01001561 };
1562 int ret;
1563
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001564 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, sizeof(cmd), &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001565 if (ret)
1566 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
1567}
1568
Johannes Berg9cc40712013-02-15 22:47:48 +01001569void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm,
1570 struct ieee80211_sta *sta,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001571 enum ieee80211_frame_release_type reason,
Johannes Berg3e56ead2013-02-15 22:23:18 +01001572 u16 cnt, u16 tids, bool more_data,
1573 bool agg)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001574{
Johannes Berg5b577a92013-11-14 18:20:04 +01001575 struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta);
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001576 struct iwl_mvm_add_sta_cmd cmd = {
Johannes Berg8ca151b2013-01-24 14:25:36 +01001577 .add_modify = STA_MODE_MODIFY,
Johannes Berg9cc40712013-02-15 22:47:48 +01001578 .sta_id = mvmsta->sta_id,
Johannes Berg8ca151b2013-01-24 14:25:36 +01001579 .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT,
1580 .sleep_tx_count = cpu_to_le16(cnt),
Johannes Berg9cc40712013-02-15 22:47:48 +01001581 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
Johannes Berg8ca151b2013-01-24 14:25:36 +01001582 };
Johannes Berg3e56ead2013-02-15 22:23:18 +01001583 int tid, ret;
1584 unsigned long _tids = tids;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001585
Johannes Berg3e56ead2013-02-15 22:23:18 +01001586 /* convert TIDs to ACs - we don't support TSPEC so that's OK
1587 * Note that this field is reserved and unused by firmware not
1588 * supporting GO uAPSD, so it's safe to always do this.
1589 */
1590 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT)
1591 cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]);
1592
1593 /* If we're releasing frames from aggregation queues then check if the
1594 * all queues combined that we're releasing frames from have
1595 * - more frames than the service period, in which case more_data
1596 * needs to be set
1597 * - fewer than 'cnt' frames, in which case we need to adjust the
1598 * firmware command (but do that unconditionally)
1599 */
1600 if (agg) {
1601 int remaining = cnt;
1602
1603 spin_lock_bh(&mvmsta->lock);
1604 for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) {
1605 struct iwl_mvm_tid_data *tid_data;
1606 u16 n_queued;
1607
1608 tid_data = &mvmsta->tid_data[tid];
1609 if (WARN(tid_data->state != IWL_AGG_ON &&
1610 tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA,
1611 "TID %d state is %d\n",
1612 tid, tid_data->state)) {
1613 spin_unlock_bh(&mvmsta->lock);
1614 ieee80211_sta_eosp(sta);
1615 return;
1616 }
1617
1618 n_queued = iwl_mvm_tid_queued(tid_data);
1619 if (n_queued > remaining) {
1620 more_data = true;
1621 remaining = 0;
1622 break;
1623 }
1624 remaining -= n_queued;
1625 }
1626 spin_unlock_bh(&mvmsta->lock);
1627
1628 cmd.sleep_tx_count = cpu_to_le16(cnt - remaining);
1629 if (WARN_ON(cnt - remaining == 0)) {
1630 ieee80211_sta_eosp(sta);
1631 return;
1632 }
1633 }
1634
1635 /* Note: this is ignored by firmware not supporting GO uAPSD */
1636 if (more_data)
1637 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA);
1638
1639 if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) {
1640 mvmsta->next_status_eosp = true;
1641 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL);
1642 } else {
1643 cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD);
1644 }
1645
Emmanuel Grumbachf9dc0002014-03-30 09:53:27 +03001646 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, sizeof(cmd), &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001647 if (ret)
1648 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
1649}
Johannes Berg3e56ead2013-02-15 22:23:18 +01001650
1651int iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm,
1652 struct iwl_rx_cmd_buffer *rxb,
1653 struct iwl_device_cmd *cmd)
1654{
1655 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1656 struct iwl_mvm_eosp_notification *notif = (void *)pkt->data;
1657 struct ieee80211_sta *sta;
1658 u32 sta_id = le32_to_cpu(notif->sta_id);
1659
1660 if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT))
1661 return 0;
1662
1663 rcu_read_lock();
1664 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1665 if (!IS_ERR_OR_NULL(sta))
1666 ieee80211_sta_eosp(sta);
1667 rcu_read_unlock();
1668
1669 return 0;
1670}
Andrei Otcheretianski09b0ce12014-05-25 17:07:38 +03001671
1672void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm,
1673 struct iwl_mvm_sta *mvmsta, bool disable)
1674{
1675 struct iwl_mvm_add_sta_cmd cmd = {
1676 .add_modify = STA_MODE_MODIFY,
1677 .sta_id = mvmsta->sta_id,
1678 .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0,
1679 .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX),
1680 .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color),
1681 };
1682 int ret;
1683
1684 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_DISABLE_STA_TX))
1685 return;
1686
1687 ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, sizeof(cmd), &cmd);
1688 if (ret)
1689 IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret);
1690}
Andrei Otcheretianski003e52362014-05-25 17:24:22 +03001691
1692void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm,
1693 struct ieee80211_sta *sta,
1694 bool disable)
1695{
1696 struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1697
1698 spin_lock_bh(&mvm_sta->lock);
1699
1700 if (mvm_sta->disable_tx == disable) {
1701 spin_unlock_bh(&mvm_sta->lock);
1702 return;
1703 }
1704
1705 mvm_sta->disable_tx = disable;
1706
1707 /*
1708 * Tell mac80211 to start/stop queueing tx for this station,
1709 * but don't stop queueing if there are still pending frames
1710 * for this station.
1711 */
1712 if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id]))
1713 ieee80211_sta_block_awake(mvm->hw, sta, disable);
1714
1715 iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable);
1716
1717 spin_unlock_bh(&mvm_sta->lock);
1718}
1719
1720void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm,
1721 struct iwl_mvm_vif *mvmvif,
1722 bool disable)
1723{
1724 struct ieee80211_sta *sta;
1725 struct iwl_mvm_sta *mvm_sta;
1726 int i;
1727
1728 lockdep_assert_held(&mvm->mutex);
1729
1730 /* Block/unblock all the stations of the given mvmvif */
1731 for (i = 0; i < IWL_MVM_STATION_COUNT; i++) {
1732 sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
1733 lockdep_is_held(&mvm->mutex));
1734 if (IS_ERR_OR_NULL(sta))
1735 continue;
1736
1737 mvm_sta = iwl_mvm_sta_from_mac80211(sta);
1738 if (mvm_sta->mac_id_n_color !=
1739 FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color))
1740 continue;
1741
1742 iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable);
1743 }
1744}
Luciano Coelhodc88b4b2014-11-10 11:10:14 +02001745
1746void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
1747{
1748 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1749 struct iwl_mvm_sta *mvmsta;
1750
1751 rcu_read_lock();
1752
1753 mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id);
1754
1755 if (!WARN_ON(!mvmsta))
1756 iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true);
1757
1758 rcu_read_unlock();
1759}